# HG changeset patch # User John W. Eaton # Date 1317242721 14400 # Node ID 2a8dcb5b3a0097ffaa2b39404d24a098b7d99721 # Parent 32980cbf23382092c5979b4715991961467444ef 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. diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/oct-parse.yy --- a/src/oct-parse.yy Wed Sep 28 10:57:18 2011 -0500 +++ b/src/oct-parse.yy Wed Sep 28 16:45:21 2011 -0400 @@ -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); diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov-base.h --- a/src/ov-base.h Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov-base.h Wed Sep 28 16:45:21 2011 -0400 @@ -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; } diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov-class.cc --- a/src/ov-class.cc Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov-class.cc Wed Sep 28 16:45:21 2011 -0400 @@ -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 ())); } diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov-class.h --- a/src/ov-class.h Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov-class.h Wed Sep 28 16:45:21 2011 -0400 @@ -94,6 +94,12 @@ const std::list& idx, int nargout); + octave_value_list + do_multi_index_op (int nargout, const octave_value_list& idx) + { + return subsref ("(", std::list (1, idx), nargout); + } + static octave_value numeric_conv (const Cell& val, const std::string& type); diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov-fcn.h --- a/src/ov-fcn.h Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov-fcn.h Wed Sep 28 16:45:21 2011 -0400 @@ -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; } diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov-usr-fcn.cc --- a/src/ov-usr-fcn.cc Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov-usr-fcn.cc Wed Sep 28 16:45:21 2011 -0400 @@ -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 ()) diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov-usr-fcn.h --- a/src/ov-usr-fcn.h Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov-usr-fcn.h Wed Sep 28 16:45:21 2011 -0400 @@ -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; diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/ov.h --- a/src/ov.h Wed Sep 28 10:57:18 2011 -0500 +++ b/src/ov.h Wed Sep 28 16:45:21 2011 -0400 @@ -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 (); } diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/pt-fcn-handle.cc --- a/src/pt-fcn-handle.cc Wed Sep 28 10:57:18 2011 -0500 +++ b/src/pt-fcn-handle.cc Wed Sep 28 16:45:21 2011 -0400 @@ -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 ()); diff -r 32980cbf2338 -r 2a8dcb5b3a00 src/variables.cc --- a/src/variables.cc Wed Sep 28 10:57:18 2011 -0500 +++ b/src/variables.cc Wed Sep 28 16:45:21 2011 -0400 @@ -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; }