26 #if defined (HAVE_CONFIG_H)
67 const std::string& class_name)
87 put (
"SuperClasses",
to_ov (superclasses));
94 auto it = method_map.find (nm);
96 if (it == method_map.end ())
116 for (
int i = 0; i < super_classes.
numel (); i++)
167 {
return ctor_list; }
215 ctor_list.push_back (cls);
234 method_map[meth.
get_name ()] = meth;
254 if (! ret_list || ret_list->
size () != 1)
255 error (
"%s: invalid constructor output arguments",
258 std::string obj_name = ret_list->
front ()->
name ();
263 std::list<cdef_class> explicit_ctor_list
266 for (
const auto& cdef_cls : explicit_ctor_list)
269 std::cerr <<
"explicit superclass constructor: "
270 << cdef_cls.get_name () << std::endl;
273 implicit_ctor_list.remove (cdef_cls);
289 std::map<std::string,cdef_method> meths;
291 find_methods (meths,
false, include_ctor);
293 Cell c (meths.size (), 1);
297 for (
const auto& nm_mthd : meths)
298 c(idx++, 0) =
to_ov (nm_mthd.second);
303 std::map<std::string, cdef_method>
307 std::map<std::string, cdef_method> methods;
309 find_methods (methods, only_inherited, include_ctor);
323 for (it = method_map.begin (); it != method_map.end (); ++it)
325 if (include_ctor || ! it->second.is_constructor ())
327 std::string nm = it->second.get_name ();
329 if (meths.find (nm) == meths.end ())
340 meths[nm] = it->second;
349 for (
int i = 0; i < super_classes.
numel (); i++)
360 auto it = property_map.find (nm);
362 if (it != property_map.end ())
374 for (
int i = 0; i < super_classes.
numel (); i++)
390 property_map[prop.
get_name ()] = prop;
398 std::map<std::string,cdef_property> props;
402 Cell c (props.size (), 1);
406 for (
const auto& pname_prop : props)
407 c(idx++, 0) =
to_ov (pname_prop.second);
412 std::map<std::string, cdef_property>
415 std::map<std::string,cdef_property> props;
417 find_properties (props, mode);
429 for (it = property_map.begin (); it != property_map.end (); ++it)
431 std::string nm = it->second.get_name ();
433 if (props.find (nm) == props.end ())
444 props[nm] = it->second;
452 for (
int i = 0; i < super_classes.
numel (); i++)
469 for (
const auto& cls_fnmap : method_map)
471 if (! cls_fnmap.second.is_constructor ())
473 std::string nm = cls_fnmap.second.get_name ();
488 for (
const auto& pname_prop : property_map)
490 std::string nm = pname_prop.second.get_name ();
508 for (
int i = 0; i < super_classes.
numel (); i++)
519 std::set<std::string> names;
521 find_names (names,
false);
525 return v.
sort (
true);
545 for (
int i = 0; i < super_classes.
numel (); i++)
556 const std::list<octave_value_list>& idx,
569 std::cerr <<
"constructor" << std::endl;
580 std::cerr <<
"static method/property" << std::endl;
583 if (idx.front ().length () != 1)
584 error (
"invalid meta.class indexing");
586 std::string nm = idx.front ()(0).xstring_value (
"invalid meta.class indexing, expected a method or property name");
593 error (
"method '%s' is not static", nm.c_str ());
597 if (
type.length () > 1 && idx.size () > 1 &&
type[1] ==
'(')
599 args = *(++(idx.begin ()));
604 ? 1 : nargout),
true,
612 error (
"no such method or property '%s'", nm.c_str ());
615 error (
"property '%s' is not constant", nm.c_str ());
623 error (
"invalid meta.class indexing");
627 if (
type.length () > skip && idx.size () > skip && !
retval.empty ())
647 std::list<cdef_class> super_classes
650 for (
auto& cls : super_classes)
651 cls.initialize_object (obj);
653 for (
const auto& pname_prop : property_map)
655 if (! pname_prop.second.get (
"Dependent").bool_value ())
657 octave_value pvalue = pname_prop.second.get (
"DefaultValue");
660 obj.
put (pname_prop.first, pvalue);
676 for (
const auto& cls : implicit_ctor_list)
694 ctor_retval = ctor.
execute (ctor_args, 1,
true,
"constructor");
696 if (ctor_retval.
length () != 1)
697 error (
"%s: invalid number of output arguments for classdef constructor",
700 obj =
to_cdef (ctor_retval(0));
709 auto p = method_map.find (
name);
711 if (p == method_map.end ())
714 return p->second.get_function ();
733 error (
"cannot instantiate object for abstract class '%s'",
752 if (! empty_class.
ok ())
753 empty_class = cdm.
make_class (
"", std::list<cdef_class> ());
760 if (! empty_class.
ok ())
761 empty_class = cdm.
make_class (
"", std::list<cdef_class> ());
762 if (! empty_property.
ok ())
764 obj = empty_property;
770 if (! empty_class.
ok ())
771 empty_class = cdm.
make_class (
"", std::list<cdef_class> ());
772 if (! empty_method.
ok ())
780 if (! empty_package.
ok ())
817 std::string s = expr->
name ();
820 return std::string (
"public");
821 else if (s ==
"protected")
822 return std::string (
"protected");
823 else if (s ==
"private")
824 return std::string (
"private");
833 template <
typename T>
839 else if (t->expression ())
840 return t->expression ()->original_text ();
856 full_class_name = t->
package_name () +
'.' + full_class_name;
859 std::cerr <<
"class: " << full_class_name << std::endl;
874 std::list<cdef_class> slist;
880 std::string sclass_name = (scls)->
class_name ();
883 std::cerr <<
"superclass: " << sclass_name << std::endl;
889 error (
"'%s' cannot inherit from '%s', because it is sealed",
890 full_class_name.c_str (), sclass_name.c_str ());
892 slist.push_back (sclass);
918 std::string aname = attr->ident ()->name ();
922 std::cerr <<
"class attribute: " << aname <<
" = "
926 retval.put (aname, avalue);
938 std::map<std::string, octave_value> set_methods;
942 std::list<tree_classdef_methods_block *> mb_list = b->
methods_list ();
946 for (
auto& mb_p : mb_list)
948 std::map<std::string, octave_value> amap;
951 std::cerr <<
"method block" << std::endl;
956 if (mb_p->attribute_list ())
958 for (
auto& attr_p : *mb_p->attribute_list ())
960 std::string aname = attr_p->ident ()->name ();
964 std::cerr <<
"method attribute: " << aname <<
" = "
969 amap[aname] = avalue;
975 if (mb_p->element_list ())
977 for (
auto& mtd : *mb_p->element_list ())
980 std::string mprefix = mname.substr (0, 4);
982 if (mprefix ==
"get.")
985 else if (mprefix ==
"set.")
986 set_methods[mname.substr (4)]
993 std::cerr << (mname ==
class_name ?
"constructor"
995 <<
": " << mname << std::endl;
998 for (
auto& attrnm_val : amap)
999 meth.
put (attrnm_val.first, attrnm_val.second);
1001 retval.install_method (meth);
1016 std::list<std::string> external_methods
1017 = lp.
methods (full_class_name);
1019 for (
const auto& mtdnm : external_methods)
1025 && !
retval.find_method (mtdnm,
true).ok ())
1036 retval.install_method (meth);
1048 std::list<tree_classdef_properties_block *> pb_list
1051 for (
auto& pb_p : pb_list)
1053 std::map<std::string, octave_value> amap;
1056 std::cerr <<
"property block" << std::endl;
1061 if (pb_p->attribute_list ())
1063 for (
auto& attr_p : *pb_p->attribute_list ())
1065 std::string aname = attr_p->ident ()->name ();
1069 std::cerr <<
"property attribute: " << aname <<
" = "
1074 if (aname ==
"Access")
1076 amap[
"GetAccess"] = avalue;
1077 amap[
"SetAccess"] = avalue;
1080 amap[aname] = avalue;
1086 if (pb_p->element_list ())
1088 for (
auto& prop_p : *pb_p->element_list ())
1090 std::string prop_name = prop_p->ident ()->name ();
1095 std::cerr <<
"property: " << prop_p->ident ()->name ()
1105 std::cerr <<
"property default: "
1110 prop.
put (
"DefaultValue", pvalue);
1117 for (
auto& attrnm_val : amap)
1118 prop.
put (attrnm_val.first, attrnm_val.second);
1130 prop.
put (
"GetMethod", git->second);
1134 auto sit = set_methods.
find (prop_name);
1136 if (sit != set_methods.end ())
1139 prop.
put (
"SetMethod", sit->second);
1140 set_methods.erase (sit);
1143 retval.install_property (prop);
octave_idx_type numel(void) const
Number of elements in the array.
Array< octave_idx_type > find(octave_idx_type n=-1, bool backward=false) const
Find indices of (at most n) nonzero elements.
void add_method(T *obj, void(T::*method)(Params...), Args &&... args)
std::map< std::string, cdef_property > get_property_map(int mode)
std::map< std::string, cdef_method > get_method_map(bool only_inherited, bool include_ctor)
void delete_object(const cdef_object &obj)
cdef_property find_property(const std::string &nm)
void find_methods(std::map< std::string, cdef_method > &meths, bool only_inherited, bool include_ctor=false)
octave_value get_method(const std::string &name) const
void run_constructor(cdef_object &obj, const octave_value_list &args)
void find_names(std::set< std::string > &names, bool all)
void install_property(const cdef_property &prop)
void install_method(const cdef_method &meth)
Cell get_methods(bool include_ctor)
void load_all_methods(void)
std::map< std::string, cdef_method >::const_iterator method_const_iterator
octave_value_list meta_subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
std::list< cdef_class > implicit_ctor_list
void find_properties(std::map< std::string, cdef_property > &props, int mode=0)
std::map< std::string, cdef_property >::const_iterator property_const_iterator
string_vector get_names(void)
cdef_method find_method(const std::string &nm, bool local=false)
Cell get_properties(int mode)
void initialize_object(cdef_object &obj)
octave_value construct(const octave_value_list &args)
cdef_object construct_object(const octave_value_list &args)
octave_value get_method_function(const std::string &nm)
Cell get_methods(bool include_ctor=false)
cdef_class & operator=(const cdef_class &cls)
void delete_object(const cdef_object &obj)
static cdef_class make_meta_class(interpreter &interp, tree_classdef *t, bool is_at_folder=false)
Analyze the tree_classdef tree and transform it to a cdef_class.
bool is_meta_class(void) const
bool is_abstract(void) const
cdef_method find_method(const std::string &nm, bool local=false)
cdef_property find_property(const std::string &nm)
void initialize_object(cdef_object &obj)
octave_value construct(const octave_value_list &args)
std::map< std::string, cdef_property > get_property_map(int mode=property_normal)
cdef_class_rep * get_rep(void)
bool is_handle_class(void) const
std::string get_name(void) const
void run_constructor(cdef_object &obj, const octave_value_list &args)
cdef_object construct_object(const octave_value_list &args)
cdef_property make_property(const cdef_class &cls, const std::string &name, const octave_value &get_method=Matrix(), const std::string &get_access="public", const octave_value &set_method=Matrix(), const std::string &set_access="public")
const cdef_class & meta_package(void) const
void unregister_class(const cdef_class &cls)
cdef_package make_package(const std::string &nm, const std::string &parent="")
cdef_method make_method(const cdef_class &cls, const std::string &name, const octave_value &fcn, const std::string &m_access="public", bool is_static=false)
const cdef_class & meta_property(void) const
const cdef_class & meta_method(void) const
cdef_class make_class(const std::string &name, const std::list< cdef_class > &super_list=std::list< cdef_class >())
cdef_package find_package(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
const cdef_class & meta_class(void) const
bool is_defined_in_class(const std::string &cname) const
std::string get_name(void) const
octave_value_list execute(const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who="")
bool is_constructor(void) const
bool is_static(void) const
octave_value get_function(void) const
void put(const std::string &pname, const octave_value &val)
void mark_for_construction(const cdef_class &cls)
void put(const std::string &pname, const octave_value &val)
void set_class(const cdef_class &cls)
std::string class_name(void) const
octave_value get(const std::string &pname) const
void mark_as_constructed(void)
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="") const
bool is_constant(void) const
std::string get_name(void) const
void visit_decl_command(tree_decl_command &)
void visit_switch_case_list(tree_switch_case_list &)
void visit_simple_assignment(tree_simple_assignment &t)
void visit_simple_for_command(tree_simple_for_command &)
void visit_postfix_expression(tree_postfix_expression &)
void visit_if_command_list(tree_if_command_list &)
void visit_superclass_ref(tree_superclass_ref &t)
void visit_try_catch_command(tree_try_catch_command &)
void visit_octave_user_script(octave_user_script &)
void visit_statement(tree_statement &t)
ctor_analyzer(const std::string &ctor, const std::string &obj)
void visit_parameter_list(tree_parameter_list &)
void visit_do_until_command(tree_do_until_command &)
void visit_binary_expression(tree_binary_expression &)
void visit_octave_user_function(octave_user_function &)
std::list< cdef_class > get_constructor_list(void) const
void visit_complex_for_command(tree_complex_for_command &)
void visit_multi_assignment(tree_multi_assignment &t)
void visit_identifier(tree_identifier &)
void visit_prefix_expression(tree_prefix_expression &)
void visit_matrix(tree_matrix &)
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
~ctor_analyzer(void)=default
void visit_return_command(tree_return_command &)
void visit_argument_list(tree_argument_list &)
void visit_fcn_handle(tree_fcn_handle &)
void visit_continue_command(tree_continue_command &)
void visit_while_command(tree_while_command &)
ctor_analyzer(void)=delete
void visit_no_op_command(tree_no_op_command &)
void visit_colon_expression(tree_colon_expression &)
void visit_break_command(tree_break_command &)
void visit_switch_command(tree_switch_command &)
std::list< cdef_class > ctor_list
void visit_unwind_protect_command(tree_unwind_protect_command &)
void visit_constant(tree_constant &)
void visit_function_def(tree_function_def &)
void visit_if_clause(tree_if_clause &)
void visit_decl_elt(tree_decl_elt &)
void visit_cell(tree_cell &)
ctor_analyzer(const ctor_analyzer &)=delete
void visit_index_expression(tree_index_expression &t)
void visit_if_command(tree_if_command &)
void visit_decl_init_list(tree_decl_init_list &)
void visit_switch_case(tree_switch_case &)
load_path & get_load_path(void)
tree_evaluator & get_evaluator(void)
std::list< std::string > methods(const std::string &class_name, const std::string &pack_name="")
tree_expression * expression(void)
std::list< tree_classdef_methods_block * > methods_list(void)
std::list< tree_classdef_properties_block * > properties_list(void)
tree_classdef_superclass_list * superclass_list(void)
tree_identifier * ident(void)
tree_classdef_body * body(void)
tree_classdef_attribute_list * attribute_list(void)
std::string package_name(void) const
std::string doc_string(void) const
std::string name(void) const
void push_dummy_scope(const std::string &name)
virtual bool is_identifier(void) const
virtual std::string name(void) const
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
std::string name(void) const
tree_expression * expression(void)
tree_expression * right_hand_side(void)
tree_expression * right_hand_side(void)
void accept(tree_walker &tw)
bool is_expression(void) const
tree_expression * expression(void)
std::string method_name(void) const
std::string class_name(void) const
virtual void accept(tree_walker &tw)=0
std::string name(void) const
octave::tree_statement_list * body(void)
void stash_function_name(const std::string &s)
octave::tree_parameter_list * return_list(void)
octave_idx_type length(void) const
octave_value_list & prepend(const octave_value &val)
bool bool_value(bool warn=false) const
octave_user_function * user_function_value(bool silent=false) const
bool is_string(void) const
bool is_defined(void) const
Cell cell_value(void) const
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
string_vector & sort(bool make_uniq=false)
void error(const char *fmt,...)
#define panic_impossible()
std::list< cdef_class > lookup_classes(const Cell &cls_list)
void make_function_of_class(const std::string &class_name, const octave_value &fcn)
octave_value to_ov(const cdef_object &obj)
cdef_object to_cdef(const octave_value &val)
static octave_value compute_attribute_value(tree_evaluator &tw, tree_classdef_attribute *t)
cdef_class lookup_class(const std::string &name, bool error_if_not_found, bool load_if_not_found)
cdef_manager & __get_cdef_manager__(const std::string &who)
static octave_value make_fcn_handle(const octave_value &fcn, const std::string &meth_name, const std::string &class_name)
static std::string attribute_value_to_string(T *t, octave_value v)
std::string get_base_name(const std::string &nm)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval