Mercurial > octave
diff libinterp/interpfcn/symtab.cc @ 16048:10142aad4b9f classdef
Implement indirect method call: fun(obj, ...).
* libinterp/octave-value/ov-classdef.h (class cdef_manager): New class.
(cdef_method::cdef_method_rep::meta_subsref,
cdef_method::cdef_method_rep::meta_is_postfix_index_handled): New
methods.
* libinterp/octave-value/ov-classdef.cc (all_packages, all_classes):
Move static variables to class cdef_manager.
(lookup_class (std::string, bool, bool)): Move implementation to
method cdef_manager::do_find_class().
(lookup_package): Move implementation to method
cdef_manager::do_find_package().
(make_class): Use cdef_manager::register_class.
(make_package): Use cdef_manager::register_package and
cdef_manager::find_package.
(cdef_class::cdef_class_rep::meta_release): Use
cdef_manager::unregister_class.
(cdef_method::cdef_method_rep::meta_subsref): New method.
(class cdef_manager): New class.
* libinterp/interpfcn/symtab.cc
(symbol_table::fcn_info::fcn_info_rep::load_class_constructor):
Look for classdef constructor in normal m-files. Call
find_user_function() and check whether the result is a classdef
constructor. If it is, stash it as a constructor and restore the
previous value of function_on_path.
(symbol_table::fcn_info::fcn_info_rep::load_class_method): Look for
method in classdef system, using cdef_manager::find_method_symbol().
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 11 Feb 2013 15:20:00 -0500 |
parents | 049e8bbff782 |
children | 0259254a3ccc |
line wrap: on
line diff
--- a/libinterp/interpfcn/symtab.cc Mon Jan 28 21:56:01 2013 -0500 +++ b/libinterp/interpfcn/symtab.cc Mon Feb 11 15:20:00 2013 -0500 @@ -36,6 +36,7 @@ #include "dirfns.h" #include "input.h" #include "load-path.h" +#include "ov-classdef.h" #include "ov-fcn.h" #include "ov-usr-fcn.h" #include "pager.h" @@ -392,6 +393,31 @@ class_constructors[name] = retval; } } + else + { + // Classdef constructors can be defined anywhere in the path, not + // necessarily in @-folders. Look for a normal function and load it. + // If the loaded function is a classdef constructor, store it as such + // and restore function_on_path to its previous value. + + octave_value old_function_on_path = function_on_path; + + octave_value maybe_cdef_ctor = find_user_function (); + + if (maybe_cdef_ctor.is_defined ()) + { + octave_function *fcn = maybe_cdef_ctor.function_value (true); + + if (fcn && fcn->is_classdef_constructor ()) + { + retval = maybe_cdef_ctor; + + class_constructors[name] = retval; + + function_on_path = old_function_on_path; + } + } + } return retval; } @@ -406,43 +432,53 @@ retval = load_class_constructor (); else { - std::string dir_name; + octave_function *cm = cdef_manager::find_method_symbol (name, + dispatch_type); - std::string file_name = load_path::find_method (dispatch_type, name, - dir_name); + if (cm) + retval = octave_value (cm); - if (! file_name.empty ()) + if (! retval.is_defined ()) { - octave_function *fcn = load_fcn_from_file (file_name, dir_name, - dispatch_type); + std::string dir_name; - if (fcn) + std::string file_name = load_path::find_method (dispatch_type, name, + dir_name); + + if (! file_name.empty ()) { - retval = octave_value (fcn); + octave_function *fcn = load_fcn_from_file (file_name, dir_name, + dispatch_type); - class_methods[dispatch_type] = retval; - } - } + if (fcn) + { + retval = octave_value (fcn); - if (retval.is_undefined ()) - { - // Search parent classes + class_methods[dispatch_type] = retval; + } + } - const std::list<std::string>& plist = parent_classes (dispatch_type); - - std::list<std::string>::const_iterator it = plist.begin (); - - while (it != plist.end ()) + if (retval.is_undefined ()) { - retval = find_method (*it); + // Search parent classes - if (retval.is_defined ()) + const std::list<std::string>& plist = + parent_classes (dispatch_type); + + std::list<std::string>::const_iterator it = plist.begin (); + + while (it != plist.end ()) { - class_methods[dispatch_type] = retval; - break; + retval = find_method (*it); + + if (retval.is_defined ()) + { + class_methods[dispatch_type] = retval; + break; + } + + it++; } - - it++; } } }