Mercurial > hg > octave-nkf
changeset 13241:2a8dcb5b3a00
improve default indexing for objects
* ov-class.cc (octave_class::is_class_method): Also return true for
anonymous functions executing in the context of a class method or
constructor.
* ov-class.h (octave_class:do_multi_index_op): New function.
* ov-fcn.h (octave_function::is_private_function_of_class): Now const.
(octave_function::is_anonymous_function_of_class): New virtual function.
* ov-usr-fcn.h (octave_function::anonymous_function): New data member.
(octave_user_function::mark_as_anonymous_function): New function.
(octave_user_function::is_anonymous_function): New function.
(octave_user_function::is_anonymous_function_of_class): New function.
* ov-usr-fcn.cc (octave_user_function::octave_user_function):
Initialize anonymous_function data member.
(octave_user_function::profiler_name): Distinguish between inline and
anonymous functions.
(octave_user_function::do_multi_index_op): Use is_anonymous_function
instead of checking whether cmd_list is marked as an anonymous
function body.
* pt-fcn-handle.cc (tree_anon_fcn_handle::rvalue1): If parent function
is a class method or constructor, stash the dispatch type in the new
function. Mark the new function as anonymous, not inline.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 28 Sep 2011 16:45:21 -0400 |
parents | 32980cbf2338 |
children | 105c72254967 |
files | src/oct-parse.yy src/ov-base.h src/ov-class.cc src/ov-class.h src/ov-fcn.h src/ov-usr-fcn.cc src/ov-usr-fcn.h src/ov.h src/pt-fcn-handle.cc src/variables.cc |
diffstat | 10 files changed, 50 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -4185,7 +4185,9 @@ retval = feval (name, tmp_args, nargout); } } - else if (f_arg.is_function_handle () || f_arg.is_inline_function ()) + else if (f_arg.is_function_handle () + || f_arg.is_anonymous_function () + || f_arg.is_inline_function ()) { const octave_value_list tmp_args = get_feval_args (args);
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -427,6 +427,8 @@ virtual bool is_function_handle (void) const { return false; } + virtual bool is_anonymous_function (void) const { return false; } + virtual bool is_inline_function (void) const { return false; } virtual bool is_function (void) const { return false; }
--- a/src/ov-class.cc +++ b/src/ov-class.cc @@ -1686,6 +1686,7 @@ return (fcn && (fcn->is_class_method () || fcn->is_class_constructor () + || fcn->is_anonymous_function_of_class () || fcn->is_private_function_of_class (class_name ())) && find_parent_class (fcn->dispatch_class ())); }
--- a/src/ov-class.h +++ b/src/ov-class.h @@ -94,6 +94,12 @@ const std::list<octave_value_list>& idx, int nargout); + octave_value_list + do_multi_index_op (int nargout, const octave_value_list& idx) + { + return subsref ("(", std::list<octave_value_list> (1, idx), nargout); + } + static octave_value numeric_conv (const Cell& val, const std::string& type);
--- a/src/ov-fcn.h +++ b/src/ov-fcn.h @@ -103,9 +103,13 @@ bool is_private_function (void) const { return private_function; } - bool is_private_function_of_class (const std::string& nm) + bool is_private_function_of_class (const std::string& nm) const { return private_function && xdispatch_class == nm; } + virtual bool + is_anonymous_function_of_class (const std::string& = std::string ()) const + { return false; } + std::string dir_name (void) const { return my_dir_name; } void stash_dir_name (const std::string& dir) { my_dir_name = dir; }
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -187,8 +187,8 @@ system_fcn_file (false), call_depth (-1), num_named_args (param_list ? param_list->length () : 0), subfunction (false), inline_function (false), - class_constructor (false), class_method (false), - parent_scope (-1), local_scope (sid), + anonymous_function (false), class_constructor (false), + class_method (false), parent_scope (-1), local_scope (sid), curr_unwind_protect_frame (0) { if (cmd_list) @@ -229,6 +229,9 @@ std::ostringstream result; if (is_inline_function ()) + result << "inline@" << fcn_file_name () + << ":" << location_line << ":" << location_column; + else if (is_anonymous_function ()) result << "anonymous@" << fcn_file_name () << ":" << location_line << ":" << location_column; else if (is_subfunction ()) @@ -450,8 +453,7 @@ frame.protect_var (tree_evaluator::statement_context); tree_evaluator::statement_context = tree_evaluator::function; - bool special_expr = (is_inline_function () - || cmd_list->is_anon_function_body ()); + bool special_expr = (is_inline_function () || is_anonymous_function ()); BEGIN_PROFILER_BLOCK (profiler_name ())
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -263,6 +263,20 @@ bool is_inline_function (void) const { return inline_function; } + void mark_as_anonymous_function (void) { anonymous_function = true; } + + bool is_anonymous_function (void) const { return anonymous_function; } + + bool is_anonymous_function_of_class + (const std::string& cname = std::string ()) const + { + return anonymous_function + ? (cname.empty () + ? (! dispatch_class().empty ()) + : cname == dispatch_class ()) + : false; + } + void mark_as_class_constructor (void) { class_constructor = true; } bool is_class_constructor (const std::string& cname = std::string ()) const @@ -383,6 +397,9 @@ // TRUE means this is an inline function. bool inline_function; + // TRUE means this is an anonymous function. + bool anonymous_function; + // TRUE means this function is the constructor for class object. bool class_constructor;
--- a/src/ov.h +++ b/src/ov.h @@ -654,6 +654,9 @@ bool is_function_handle (void) const { return rep->is_function_handle (); } + bool is_anonymous_function (void) const + { return rep->is_anonymous_function (); } + bool is_inline_function (void) const { return rep->is_inline_function (); }
--- a/src/pt-fcn-handle.cc +++ b/src/pt-fcn-handle.cc @@ -124,9 +124,12 @@ parent_scope = curr_fcn->scope (); uf->stash_parent_fcn_scope (parent_scope); + + if (curr_fcn->is_class_method () || curr_fcn->is_class_constructor ()) + uf->stash_dispatch_class (curr_fcn->dispatch_class ()); } - uf->mark_as_inline_function (); + uf->mark_as_anonymous_function (); uf->stash_fcn_file_name (file_name); uf->stash_fcn_location (line (), column ());
--- a/src/variables.cc +++ b/src/variables.cc @@ -416,7 +416,9 @@ && var_ok && (type == "any" || type == "var") && (val.is_constant () || val.is_object () - || val.is_inline_function () || val.is_function_handle ())) + || val.is_function_handle () + || val.is_anonymous_function () + || val.is_inline_function ())) { retval = 1; }