26 #if defined (HAVE_CONFIG_H)
67 const std::string& class_name)
87 put (
"SuperClasses",
to_ov (superclasses));
94 auto it = m_method_map.find (nm);
96 if (it == m_method_map.end ())
116 for (
int i = 0; i < super_classes.
numel (); i++)
137 :
tree_walker (), m_who (ctor), m_obj_name (obj) { }
167 {
return m_ctor_list; }
215 m_ctor_list.push_back (cls);
234 m_method_map[meth.
get_name ()] = meth;
254 if (! ret_list || ret_list->
size () != 1)
255 error (
"%s: invalid constructor output arguments",
258 std::string m_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 m_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);
324 for (it = m_method_map.begin (); it != m_method_map.end (); ++it)
326 if (include_ctor || ! it->second.is_constructor ())
328 std::string nm = it->second.get_name ();
330 if (meths.find (nm) == meths.end ())
341 meths[nm] = it->second;
350 for (
int i = 0; i < super_classes.
numel (); i++)
361 auto it = m_property_map.find (nm);
363 if (it != m_property_map.end ())
375 for (
int i = 0; i < super_classes.
numel (); i++)
391 m_property_map[prop.
get_name ()] = prop;
399 std::map<std::string, cdef_property> props;
403 Cell c (props.size (), 1);
407 for (
const auto& pname_prop : props)
408 c(idx++, 0) =
to_ov (pname_prop.second);
413 std::map<std::string, cdef_property>
416 std::map<std::string, cdef_property> props;
418 find_properties (props, mode);
430 for (it = m_property_map.begin (); it != m_property_map.end (); ++it)
432 std::string nm = it->second.get_name ();
434 if (props.find (nm) == props.end ())
445 props[nm] = it->second;
453 for (
int i = 0; i < super_classes.
numel (); i++)
470 for (
const auto& cls_fnmap : m_method_map)
472 if (! cls_fnmap.second.is_constructor ())
474 std::string nm = cls_fnmap.second.get_name ();
489 for (
const auto& pname_prop : m_property_map)
491 std::string nm = pname_prop.second.get_name ();
509 for (
int i = 0; i < super_classes.
numel (); i++)
520 std::set<std::string> names;
522 find_names (names,
false);
526 return v.
sort (
true);
546 for (
int i = 0; i < super_classes.
numel (); i++)
557 const std::list<octave_value_list>& idx,
560 std::size_t skip = 1;
570 std::cerr <<
"constructor" << std::endl;
581 std::cerr <<
"static method/property" << std::endl;
584 if (idx.front ().length () != 1)
585 error (
"invalid meta.class indexing");
587 std::string nm = idx.front ()(
588 0).xstring_value (
"invalid meta.class indexing, expected a method or property name");
595 error (
"method '%s' is not static", nm.c_str ());
599 if (type.length () > 1 && idx.size () > 1 && type[1] ==
'(')
601 args = *(++(idx.begin ()));
605 retval = meth.
execute (args, (type.length () > skip
606 ? 1 : nargout),
true,
614 error (
"no such method or property '%s'", nm.c_str ());
617 error (
"property '%s' is not constant", nm.c_str ());
619 retval(0) = prop.
get_value (
true,
"meta.class");
625 error (
"invalid meta.class indexing");
629 if (type.length () > skip && idx.size () > skip && ! retval.
empty ())
630 retval = retval(0).next_subsref (nargout, type, idx, skip);
648 std::list<cdef_class> super_classes
651 for (
auto& cls : super_classes)
652 cls.initialize_object (obj);
654 for (
const auto& pname_prop : m_property_map)
656 if (! pname_prop.second.get (
"Dependent").bool_value ())
658 octave_value pvalue = pname_prop.second.get (
"DefaultValue");
661 obj.
put (pname_prop.first, pvalue);
677 for (
const auto& cls : m_implicit_ctor_list)
695 ctor_retval = ctor.
execute (ctor_args, 1,
true,
"constructor");
697 if (ctor_retval.
length () != 1)
698 error (
"%s: invalid number of output arguments for classdef constructor",
701 obj =
to_cdef (ctor_retval(0));
710 auto p = m_method_map.find (name);
712 if (p == m_method_map.end ())
715 return p->second.get_function ();
734 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;
872 std::list<cdef_class> slist;
878 std::string sclass_name = (scls)->
class_name ();
881 std::cerr <<
"superclass: " << sclass_name << std::endl;
887 error (
"'%s' cannot inherit from '%s', because it is sealed",
888 full_class_name.c_str (), sclass_name.c_str ());
890 slist.push_back (sclass);
896 retval = cdm.
make_class (full_class_name, slist);
908 retval.
put (
"ContainingPackage",
to_ov (pack));
922 std::string aname = attr->ident ()->name ();
926 std::cerr <<
"class attribute: " << aname <<
" = "
930 retval.
put (aname, avalue);
942 std::map<std::string, octave_value> set_methods;
946 std::list<tree_classdef_methods_block *> mb_list = b->
methods_list ();
950 for (
auto& mb_p : mb_list)
952 std::map<std::string, octave_value> amap;
955 std::cerr <<
"method block" << std::endl;
960 if (mb_p->attribute_list ())
962 for (
auto& attr_p : *mb_p->attribute_list ())
964 std::string aname = attr_p->ident ()->name ();
968 std::cerr <<
"method attribute: " << aname <<
" = "
973 amap[aname] = avalue;
979 if (mb_p->element_list ())
981 for (
auto& mtd : *mb_p->element_list ())
984 std::string mprefix = mname.substr (0, 4);
986 if (mprefix ==
"get.")
989 else if (mprefix ==
"set.")
990 set_methods[mname.substr (4)]
997 std::cerr << (mname ==
class_name ?
"constructor"
999 <<
": " << mname << std::endl;
1009 for (
auto& attrnm_val : amap)
1010 meth.
put (attrnm_val.first, attrnm_val.second);
1027 std::list<std::string> external_methods
1028 = lp.
methods (full_class_name);
1030 for (
const auto& mtdnm : external_methods)
1059 std::list<tree_classdef_properties_block *> pb_list
1062 for (
auto& pb_p : pb_list)
1064 std::map<std::string, octave_value> amap;
1067 std::cerr <<
"property block" << std::endl;
1072 if (pb_p->attribute_list ())
1074 for (
auto& attr_p : *pb_p->attribute_list ())
1076 std::string aname = attr_p->ident ()->name ();
1080 std::cerr <<
"property attribute: " << aname <<
" = "
1085 if (aname ==
"Access")
1087 amap[
"GetAccess"] = avalue;
1088 amap[
"SetAccess"] = avalue;
1091 amap[aname] = avalue;
1097 if (pb_p->element_list ())
1099 for (
auto& prop_p : *pb_p->element_list ())
1101 std::string prop_name = prop_p->ident ()->name ();
1106 std::cerr <<
"property: " << prop_p->ident ()->name ()
1116 std::cerr <<
"property default: "
1121 prop.
put (
"DefaultValue", pvalue);
1134 for (
auto& attrnm_val : amap)
1135 prop.
put (attrnm_val.first, attrnm_val.second);
1147 prop.
put (
"GetMethod", git->second);
1151 auto sit = set_methods.
find (prop_name);
1153 if (sit != set_methods.end ())
1156 prop.
put (
"SetMethod", sit->second);
1157 set_methods.erase (sit);
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)
static octave_value compute_attribute_value(tree_evaluator &tw, tree_classdef_attribute *t)
cdef_object to_cdef(const octave_value &val)
std::list< cdef_class > lookup_classes(const Cell &cls_list)
cdef_class lookup_class(const std::string &name, bool error_if_not_found, bool load_if_not_found)
std::string get_base_name(const std::string &nm)
octave_value to_ov(const cdef_object &obj)
void make_function_of_class(const std::string &class_name, const octave_value &fcn)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_API Array< octave_idx_type > find(octave_idx_type n=-1, bool backward=false) const
Find indices of (at most n) nonzero elements.
std::size_t size(void) const
OCTINTERP_API void delete_object(const cdef_object &obj)
OCTINTERP_API std::map< std::string, cdef_property > get_property_map(int mode)
OCTINTERP_API void run_constructor(cdef_object &obj, const octave_value_list &args)
OCTINTERP_API octave_value_list meta_subsref(const std::string &type, const std::list< octave_value_list > &idx, int nargout)
OCTINTERP_API void install_property(const cdef_property &prop)
OCTINTERP_API std::map< std::string, cdef_method > get_method_map(bool only_inherited, bool include_ctor)
OCTINTERP_API cdef_property find_property(const std::string &nm)
std::list< cdef_class > m_implicit_ctor_list
OCTINTERP_API string_vector get_names(void)
OCTINTERP_API void install_method(const cdef_method &meth)
OCTINTERP_API void meta_release(void)
OCTINTERP_API octave_value construct(const octave_value_list &args)
std::map< std::string, cdef_property >::const_iterator property_const_iterator
std::map< std::string, cdef_method >::const_iterator method_const_iterator
OCTINTERP_API void load_all_methods(void)
OCTINTERP_API void find_names(std::set< std::string > &names, bool all)
OCTINTERP_API Cell get_properties(int mode)
OCTINTERP_API void find_methods(std::map< std::string, cdef_method > &meths, bool only_inherited, bool include_ctor=false)
OCTINTERP_API octave_value get_method(const std::string &name) const
OCTINTERP_API cdef_method find_method(const std::string &nm, bool local=false)
OCTINTERP_API void initialize_object(cdef_object &obj)
OCTINTERP_API void find_properties(std::map< std::string, cdef_property > &props, int mode=0)
OCTINTERP_API Cell get_methods(bool include_ctor)
OCTINTERP_API cdef_object construct_object(const octave_value_list &args)
OCTINTERP_API cdef_method find_method(const std::string &nm, bool local=false)
octave_value construct(const octave_value_list &args)
void install_property(const cdef_property &prop)
std::string get_name(void) const
void install_method(const cdef_method &meth)
void run_constructor(cdef_object &obj, const octave_value_list &args)
cdef_class_rep * get_rep(void)
bool is_meta_class(void) const
std::map< std::string, cdef_property > get_property_map(int mode=property_normal)
cdef_class & operator=(const cdef_class &cls)
bool is_abstract(void) const
void file_name(const std::string &nm)
void initialize_object(cdef_object &obj)
void delete_object(const cdef_object &obj)
void doc_string(const std::string &txt)
OCTINTERP_API octave_value get_method_function(const std::string &nm)
OCTINTERP_API cdef_property find_property(const std::string &nm)
bool is_handle_class(void) const
cdef_object construct_object(const octave_value_list &args)
Cell get_methods(bool include_ctor=false)
static OCTINTERP_API 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.
OCTINTERP_API cdef_class make_class(const std::string &name, const std::list< cdef_class > &super_list=std::list< cdef_class >())
OCTINTERP_API 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_method(void) const
const cdef_class & meta_property(void) const
OCTINTERP_API cdef_package make_package(const std::string &nm, const std::string &parent="")
OCTINTERP_API cdef_package find_package(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
void unregister_class(const cdef_class &cls)
const cdef_class & meta_package(void) const
const cdef_class & meta_class(void) const
OCTINTERP_API 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)
bool is_constructor(void) const
octave_value_list execute(const octave_value_list &args, int nargout, bool do_check_access=true, const std::string &who="")
bool is_defined_in_class(const std::string &cname) const
bool is_static(void) const
octave_value get_function(void) const
std::string get_name(void) const
void put(const std::string &pname, const octave_value &val)
void mark_for_construction(const cdef_class &cls)
void mark_as_constructed(void)
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
std::string get_name(void) const
bool is_constant(void) const
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="") const
void visit_cell(tree_cell &)
std::list< cdef_class > m_ctor_list
void visit_if_command_list(tree_if_command_list &)
void visit_index_expression(tree_index_expression &t)
void visit_while_command(tree_while_command &)
void visit_if_clause(tree_if_clause &)
ctor_analyzer(void)=delete
void visit_octave_user_script(octave_user_script &)
void visit_decl_init_list(tree_decl_init_list &)
void visit_constant(tree_constant &)
void visit_parameter_list(tree_parameter_list &)
void visit_binary_expression(tree_binary_expression &)
void visit_statement(tree_statement &t)
void visit_break_command(tree_break_command &)
void visit_anon_fcn_handle(tree_anon_fcn_handle &)
void visit_multi_assignment(tree_multi_assignment &t)
void visit_unwind_protect_command(tree_unwind_protect_command &)
void visit_no_op_command(tree_no_op_command &)
void visit_decl_command(tree_decl_command &)
void visit_argument_list(tree_argument_list &)
void visit_switch_case_list(tree_switch_case_list &)
void visit_octave_user_function(octave_user_function &)
ctor_analyzer(const std::string &ctor, const std::string &obj)
void visit_fcn_handle(tree_fcn_handle &)
void visit_simple_for_command(tree_simple_for_command &)
std::list< cdef_class > get_constructor_list(void) const
void visit_postfix_expression(tree_postfix_expression &)
void visit_continue_command(tree_continue_command &)
void visit_if_command(tree_if_command &)
ctor_analyzer(const ctor_analyzer &)=delete
void visit_switch_case(tree_switch_case &)
void visit_identifier(tree_identifier &)
void visit_superclass_ref(tree_superclass_ref &t)
void visit_switch_command(tree_switch_command &)
void visit_do_until_command(tree_do_until_command &)
void visit_decl_elt(tree_decl_elt &)
void visit_complex_for_command(tree_complex_for_command &)
void visit_matrix(tree_matrix &)
~ctor_analyzer(void)=default
void visit_return_command(tree_return_command &)
void visit_simple_assignment(tree_simple_assignment &t)
void visit_prefix_expression(tree_prefix_expression &)
void visit_function_def(tree_function_def &)
void visit_colon_expression(tree_colon_expression &)
void visit_try_catch_command(tree_try_catch_command &)
tree_evaluator & get_evaluator(void)
load_path & get_load_path(void)
std::list< std::string > methods(const std::string &class_name, const std::string &pack_name="")
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)
OCTINTERP_API octave_function * function_value(bool silent=false) const
bool bool_value(bool warn=false) const
bool is_string(void) const
bool is_defined(void) const
Cell cell_value(void) const
OCTINTERP_API octave_user_function * user_function_value(bool silent=false) const
std::string string_value(bool force=false) const
string_vector & sort(bool make_uniq=false)
tree_expression * expression(void)
std::list< tree_classdef_properties_block * > properties_list(void)
std::list< tree_classdef_methods_block * > methods_list(void)
tree_classdef_body * body(void)
tree_classdef_superclass_list * superclass_list(void)
tree_classdef_attribute_list * attribute_list(void)
std::string file_name(void) const
std::string doc_string(void) const
tree_identifier * ident(void)
std::string package_name(void) const
std::string name(void) const
void push_dummy_scope(const std::string &name)
virtual octave_value evaluate(tree_evaluator &tw, int nargout=1)=0
virtual std::string name(void) const
virtual bool is_identifier(void) const
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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
#define panic_impossible()
cdef_manager & __get_cdef_manager__(void)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))