void bind_method(TypeMirror& class_, std::string method_name, R (ObjT::*f)(Args...)) { typedef LM::DelegateCallTarget<false, R, Args...> Target; class_.add_method( method_name, new Target( reinterpret_cast<typename Target::F>(f), class_.get_class_type())); }
void bind_constructor(TypeMirror& class_, std::string method_name, TypePack<Args...>) { static_assert(!boost::is_abstract<T>::value, "Cannot declare LikeMagic constructor on abstract class. To construct objects of this type, register a derived, concrete class and register its constructor."); auto target_new = new LM::ConstructorCallTarget<T, Args...>(false); class_.add_method(create_constructor_name("new", method_name), target_new); auto target_tmp = new LM::ConstructorCallTarget<T, Args...>(true); class_.add_method(create_constructor_name("tmp", method_name), target_tmp); }
void TypeSystemInstance::add_class(TypeIndex index, TypeMirror* class_ptr, TypeMirror& namespace_) { TypeIndex class_index = get_class_index(index); TypeInfo class_info = class_index.get_info(); TypeInfo ptr_to_nonconst = class_info.as_ptr_to_nonconst(); TypeInfo ptr_to_const = class_info.as_ptr_to_const(); TypeInfo ref_to_nonconst = class_info.as_ref_to_nonconst(); TypeInfo ref_to_const = class_info.as_ref_to_const(); TypeInfo const_value = class_info.as_const_value(); TypeInfo nonconst_value = class_info.as_nonconst_value(); // Add conversion to delegate type so that delegate call targets will work. add_conv(ref_to_nonconst.as_restricted(), TypId<LM::Delegate&>::restricted().get_info()); add_conv(ref_to_nonconst.as_restricted(), TypId<LM::Delegate const&>::restricted().get_info()); add_conv(ref_to_const.as_restricted(), TypId<LM::Delegate const&>::restricted().get_info()); add_conv(nonconst_value.as_restricted(), TypId<LM::Delegate&>::restricted().get_info()); add_conv(nonconst_value.as_restricted(), TypId<LM::Delegate const&>::restricted().get_info()); add_conv(const_value.as_restricted(), TypId<LM::Delegate const&>::restricted().get_info()); add_common_conversions(class_index); this->classes[class_index.get_id()] = class_ptr; auto deleter_target = new DeleterCallTarget(); class_ptr->add_method("delete", deleter_target); ExprPtr class_expr = create_expr(nullptr, class_index); // TODO: Create a "bool is_class_expr" field for expr. class_expr->set_disable_to_script(true); namespace_.add_method( class_ptr->get_class_name(), new LM::ExprTarget( class_expr)); }
void bind_array_field(TypeMirror& class_, std::string field_name, R(T::*f)[N]) { TypeIndex class_type = class_.get_class_type(); typedef LM::ArrayFieldSetterTarget<R> SetterTarget; auto setter = new SetterTarget(reinterpret_cast<typename SetterTarget::F>(f), class_type, N); class_.add_method("set_" + field_name, setter); typedef LM::ArrayFieldGetterTarget<R> GetterTarget; auto getter = new GetterTarget(reinterpret_cast<typename GetterTarget::F>(f), class_type, N); class_.add_method("get_" + field_name, getter); typedef LM::ArrayFieldReferenceTarget<R> RefferTarget; auto reffer = new RefferTarget(reinterpret_cast<typename RefferTarget::F>(f), class_type, N); class_.add_method("ref_" + field_name, reffer); }
void add_base(TypeMirror& class_, TypeMirror const& base_class) { class_.add_base(&base_class); add_conv<T*, Base*, Converter>("conv to base"); }
void bind_nonmember_op(TypeMirror& class_, std::string method_name, R (*f)(FirstArg, Args...)) { class_.add_method(method_name, new LM::ExtensionMethodCallTarget<R, FirstArg, Args...>(f)); }
void add_value(TypeMirror& namespace_, std::string name, T&& value) { ExprPtr expr = Term<T>::create(std::forward<T>(value)); CallTarget* target = create_expr_target(expr); namespace_.add_method(name, target); }
void bind_static_method(TypeMirror& class_, std::string method_name, void (*f)(Args...)) { typedef StaticMethodCallTarget_void<Args...> Target; class_.add_method(method_name, new Target(f)); }