comparison libinterp/octave-value/ov-classdef.h @ 18288:b5be1a2aa5ab

Initial implementation for classdef methods in separate files. * libinterp/octave-value/ov-classdef.h (cdef_class::make_meta_class): New argument to tell whether the class is loaded from a @-folder. (cdef_method::cdef_method_rep::dispatch_type): New member used for external methods. (cdef_method::cdef_method_rep::cdef_method_rep): Initialize it. (cdef_method::cdef_method_rep::is_external, cdef_method::cdef_method_rep::mark_as_external): New methods, use it. (cdef_method::is_external, cdef_method::mark_as_external): Likewise. * libinterp/octave-value/ov-classdef.cc (is_dummy_method): New static method. (make_method): Use it to initialize "external" state of created method. (cdef_class::make_meta_class): New argument to know whether we're loading from a @-folder. Scan existing methods from load-path and create corresponding method entries in the class definition. (cdef_method::cdef_method_rep::check_method): Load external method if required. (cdef_method::cdef_method_rep::execute): Check error_state after calling check_method. * libinterp/parse-tree/pt-classdef.h (tree_classdef::make_meta_class): New argument to tell whether the class is loaded from a @-folder. * libinterp/parse-tree/pt-classdef.cc (tree_classdef::make_meta_class): Likewise. Pass new argument to cdef_class::make_meta_class. * libinterp/parse-tree/oct-parse.in.yy (parse_fcn_file): Pass new is_at_folder argument.
author Michael Goffioul <michael.goffioul@gmail.com>
date Sun, 12 Jan 2014 15:54:44 -0500
parents c4f5c781c3ca
children 122239398a03
comparison
equal deleted inserted replaced
18287:69990d5edcc2 18288:b5be1a2aa5ab
825 { return get_directory ().empty (); } 825 { return get_directory ().empty (); }
826 826
827 void delete_object (cdef_object obj) 827 void delete_object (cdef_object obj)
828 { get_rep ()->delete_object (obj); } 828 { get_rep ()->delete_object (obj); }
829 829
830 static cdef_class make_meta_class (tree_classdef* t); 830 static cdef_class make_meta_class (tree_classdef* t,
831 bool is_at_folder = false);
831 832
832 octave_function* get_method_function (const std::string& nm); 833 octave_function* get_method_function (const std::string& nm);
833 834
834 octave_function* get_constructor_function (void) 835 octave_function* get_constructor_function (void)
835 { return get_method_function (get_name ()); } 836 { return get_method_function (get_name ()); }
1017 1018
1018 class 1019 class
1019 cdef_method_rep : public cdef_meta_object_rep 1020 cdef_method_rep : public cdef_meta_object_rep
1020 { 1021 {
1021 public: 1022 public:
1022 cdef_method_rep (void) : cdef_meta_object_rep () { } 1023 cdef_method_rep (void)
1024 : cdef_meta_object_rep (), function (), dispatch_type ()
1025 { }
1023 1026
1024 cdef_object_rep* copy (void) const { return new cdef_method_rep(*this); } 1027 cdef_object_rep* copy (void) const { return new cdef_method_rep(*this); }
1025 1028
1026 bool is_method (void) const { return true; } 1029 bool is_method (void) const { return true; }
1027 1030
1034 octave_value get_function (void) const { return function; } 1037 octave_value get_function (void) const { return function; }
1035 1038
1036 void set_function (const octave_value& fcn) { function = fcn; } 1039 void set_function (const octave_value& fcn) { function = fcn; }
1037 1040
1038 bool check_access (void) const; 1041 bool check_access (void) const;
1042
1043 bool is_external (void) const { return ! dispatch_type.empty (); }
1044
1045 void mark_as_external (const std::string& dtype)
1046 { dispatch_type = dtype; }
1039 1047
1040 octave_value_list execute (const octave_value_list& args, int nargout, 1048 octave_value_list execute (const octave_value_list& args, int nargout,
1041 bool do_check_access = true, 1049 bool do_check_access = true,
1042 const std::string& who = std::string ()); 1050 const std::string& who = std::string ());
1043 1051
1055 bool meta_is_postfix_index_handled (char type) const 1063 bool meta_is_postfix_index_handled (char type) const
1056 { return (type == '(' || type == '.'); } 1064 { return (type == '(' || type == '.'); }
1057 1065
1058 private: 1066 private:
1059 cdef_method_rep (const cdef_method_rep& m) 1067 cdef_method_rep (const cdef_method_rep& m)
1060 : cdef_meta_object_rep (m), function (m.function) { } 1068 : cdef_meta_object_rep (m), function (m.function),
1069 dispatch_type (m.dispatch_type)
1070 { }
1061 1071
1062 void check_method (void); 1072 void check_method (void);
1063 1073
1064 cdef_method wrap (void) 1074 cdef_method wrap (void)
1065 { 1075 {
1067 return cdef_method (this); 1077 return cdef_method (this);
1068 } 1078 }
1069 1079
1070 private: 1080 private:
1071 octave_value function; 1081 octave_value function;
1082
1083 // When non-empty, the method is externally defined and this member
1084 // is used to cache the dispatch type to look for the method.
1085 std::string dispatch_type;
1072 }; 1086 };
1073 1087
1074 public: 1088 public:
1075 cdef_method (void) : cdef_meta_object () { } 1089 cdef_method (void) : cdef_meta_object () { }
1076 1090
1122 octave_value get_function (void) const 1136 octave_value get_function (void) const
1123 { return get_rep ()->get_function (); } 1137 { return get_rep ()->get_function (); }
1124 1138
1125 bool is_constructor (void) const 1139 bool is_constructor (void) const
1126 { return get_rep ()->is_constructor (); } 1140 { return get_rep ()->is_constructor (); }
1141
1142 bool is_external (void) const { return get_rep ()->is_external (); }
1143
1144 void mark_as_external (const std::string& dtype)
1145 { get_rep ()->mark_as_external (dtype); }
1127 1146
1128 private: 1147 private:
1129 cdef_method_rep* get_rep (void) 1148 cdef_method_rep* get_rep (void)
1130 { return dynamic_cast<cdef_method_rep *> (cdef_object::get_rep ()); } 1149 { return dynamic_cast<cdef_method_rep *> (cdef_object::get_rep ()); }
1131 1150