Mercurial > hg > octave-lojdl
changeset 9581:3d0d2bda3a0f
fix previous change, avoid duplicate loads of methods in descendant classes
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 27 Aug 2009 16:08:23 +0200 |
parents | 8bf27324a9d0 |
children | bdcfb756d721 |
files | src/ChangeLog src/load-path.cc src/load-path.h src/ov-class.cc src/ov-class.h src/symtab.cc src/symtab.h |
diffstat | 7 files changed, 62 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,19 @@ 2009-08-27 Jaroslav Hajek <highegg@gmail.com> - * src/ov-class.cc (get_current_method_class): Simplify. + * ov-class.cc (get_current_method_class): Simplify. + (octave_class::in_class_method): Don't rely on multiple copies of + methods. Don't declare as const. + (octave_class::octave_class (const Octave_map&, const std::string&, + const octave_value_list&)): + Call symbol_table::add_to_parent_map instead. + * ov-class.h (octave_class::in_class_method): Don't declare as const. + * symtab.h (symbol_table::parent_map): New field. + (symbol_table::add_to_parent_map): New method. + (symbol_table::load_class_method): Search also parent classes. + * load-path.h (load_path::parent_map, load_path::add_to_parent_map, + load_path::do_add_to_parent_map): Remove. + * load-path.cc (load_path::do_find_method): Don't search parent + classes. 2009-08-27 Jaroslav Hajek <highegg@gmail.com>
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -512,7 +512,6 @@ fcn_map.clear (); private_fcn_map.clear (); method_map.clear (); - parent_map.clear (); do_append (".", false); } @@ -1017,29 +1016,7 @@ const_fcn_map_iterator p = m.find (meth); - if (p == m.end ()) - { - // Look in parent classes. - - const_parent_map_iterator r = parent_map.find (class_name); - - if (r != parent_map.end ()) - { - const std::list<std::string>& plist = r->second; - std::list<std::string>::const_iterator it = plist.begin (); - - while (it != plist.end ()) - { - retval = do_find_method (*it, meth, dir_name, type); - - if (retval != "") - break; - - it++; - } - } - } - else + if (p != m.end ()) { const file_info_list_type& file_info_list = p->second; @@ -1598,13 +1575,6 @@ } void -load_path::do_add_to_parent_map (const std::string& classname, - const std::list<std::string>& parent_list) const -{ - parent_map[classname] = parent_list; -} - -void load_path::add_to_fcn_map (const dir_info& di, bool at_end) const { std::string dir_name = di.dir_name;
--- a/src/load-path.h +++ b/src/load-path.h @@ -38,7 +38,7 @@ protected: load_path (void) - : dir_info_list (), fcn_map (), method_map (), parent_map () { } + : dir_info_list (), fcn_map (), method_map () { } public: @@ -236,13 +236,6 @@ return instance_ok () ? instance->do_system_path () : std::string (); } - static void add_to_parent_map (const std::string& classname, - const std::list<std::string>& parent_list) - { - if (instance_ok ()) - instance->do_add_to_parent_map (classname, parent_list); - } - private: static const int M_FILE = 1; @@ -402,12 +395,6 @@ typedef method_map_type::const_iterator const_method_map_iterator; typedef method_map_type::iterator method_map_iterator; - // <CLASS_NAME, PARENT_LIST>> - typedef std::map<std::string, std::list<std::string> > parent_map_type; - - typedef parent_map_type::const_iterator const_parent_map_iterator; - typedef parent_map_type::iterator parent_map_iterator; - mutable dir_info_list_type dir_info_list; mutable fcn_map_type fcn_map; @@ -416,8 +403,6 @@ mutable method_map_type method_map; - mutable parent_map_type parent_map; - static load_path *instance; static hook_fcn_ptr add_hook; @@ -518,9 +503,6 @@ std::string do_get_command_line_path (void) const { return command_line_path; } - void do_add_to_parent_map (const std::string& classname, - const std::list<std::string>& parent_list) const; - void add_to_fcn_map (const dir_info& di, bool at_end) const; void add_to_private_fcn_map (const dir_info& di) const;
--- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -94,7 +94,7 @@ } if (! error_state) - load_path::add_to_parent_map (id, parent_list); + symbol_table::add_to_parent_map (id, parent_list); } octave_base_value * @@ -123,7 +123,8 @@ octave_function *fcn = octave_call_stack::current (); - retval = fcn->dispatch_class (); + if (fcn->is_class_method () || fcn->is_class_constructor ()) + retval = fcn->dispatch_class (); return retval; } @@ -1574,7 +1575,7 @@ } bool -octave_class::in_class_method (void) const +octave_class::in_class_method (void) { octave_function *fcn = octave_call_stack::current (); @@ -1582,7 +1583,7 @@ && (fcn->is_class_method () || fcn->is_class_constructor () || fcn->is_private_function_of_class (class_name ())) - && fcn->dispatch_class () == class_name ()); + && find_parent_class (fcn->dispatch_class ())); } octave_class::exemplar_info::exemplar_info (const octave_value& obj)
--- a/src/ov-class.h +++ b/src/ov-class.h @@ -196,7 +196,7 @@ std::string c_name; std::list<std::string> parent_list; - bool in_class_method (void) const; + bool in_class_method (void); int obsolete_copies;
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -57,6 +57,8 @@ std::map<std::string, std::set<std::string> > symbol_table::class_precedence_table; +std::map<std::string, std::list<std::string> > symbol_table::parent_map; + const symbol_table::scope_id symbol_table::xglobal_scope = 0; const symbol_table::scope_id symbol_table::xtop_scope = 1; @@ -376,6 +378,32 @@ class_methods[dispatch_type] = retval; } } + + if (retval.is_undefined ()) + { + // Search parent classes + + const_parent_map_iterator r = parent_map.find (dispatch_type); + + if (r != parent_map.end ()) + { + const std::list<std::string>& plist = r->second; + std::list<std::string>::const_iterator it = plist.begin (); + + while (it != plist.end ()) + { + retval = find_method (*it); + + if (retval.is_defined ()) + { + class_methods[dispatch_type] = retval; + break; + } + + it++; + } + } + } } return retval;
--- a/src/symtab.h +++ b/src/symtab.h @@ -1787,6 +1787,12 @@ static void stash_dir_name_for_subfunctions (scope_id scope, const std::string& dir_name); + static void add_to_parent_map (const std::string& classname, + const std::list<std::string>& parent_list) + { + parent_map[classname] = parent_list; + } + private: typedef std::map<std::string, symbol_record>::const_iterator table_const_iterator; @@ -1834,6 +1840,12 @@ typedef std::map<std::string, std::set<std::string> >::const_iterator class_precedence_table_const_iterator; typedef std::map<std::string, std::set<std::string> >::iterator class_precedence_table_iterator; + // Map from class names to parent class names. + static std::map<std::string, std::list<std::string> > parent_map; + + typedef std::map<std::string, std::list<std::string> >::const_iterator const_parent_map_iterator; + typedef std::map<std::string, std::list<std::string> >::iterator parent_map_iterator; + static const scope_id xglobal_scope; static const scope_id xtop_scope;