diff libinterp/parse-tree/pt-id.cc @ 15954:46ca8488de92 classdef

Re-engineer tree_expression postfix handling to make it more flexible. * libinterp/octave-value/ov-fcn.h (octave_function::is_postfix_index_handled): New method. * libinterp/parse-tree/oct-parse.yy (make_index_expression, make_indirect_ref): Set expression postfix index type. * libinterp/parse-tree/pt-exp.h (tree_expression::postfix_index): Remove field. (tree_expression::postfix_index_type): New field. (tree_expression::tree_expression): Initialize it. (tree_expression::copy_base): Copy it. (tree_expression::set_postfix_index, tree_expression::postfix_index): New methods. (tree_expression::mark_postfix_indexed): Remove method. (tree_expression::is_postfix_indexed): Use postfix_index_type field. * libinterp/parse-tree/pt-id.cc (tree_identifier::rvalue): Let the function object determine whether it can handle the first postfix index and call do_multi_index_op if it can't.
author Michael Goffioul <michael.goffioul@gmail.com>
date Tue, 15 Jan 2013 17:01:10 -0500
parents fb9dffe5fbfb
children 0259254a3ccc
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-id.cc
+++ b/libinterp/parse-tree/pt-id.cc
@@ -75,13 +75,19 @@
       //
       // If this identifier refers to a function, we need to know
       // whether it is indexed so that we can do the same thing
-      // for 'f' and 'f()'.  If the index is present, return the
-      // function object and let tree_index_expression::rvalue
-      // handle indexing.  Otherwise, arrange to call the function
-      // here, so that we don't return the function definition as
-      // a value.
+      // for 'f' and 'f()'.  If the index is present and the function
+      // object declares it can handle it, return the function object
+      // and let tree_index_expression::rvalue handle indexing.
+      // Otherwise, arrange to call the function here, so that we don't
+      // return the function definition as a value.
 
-      if (val.is_function () && ! is_postfix_indexed ())
+      octave_function *fcn = 0;
+
+      if (val.is_function ())
+        fcn = val.function_value (true);
+
+      if (fcn && ! (is_postfix_indexed ()
+                    && fcn->is_postfix_index_handled (postfix_index ())))
         {
           octave_value_list tmp_args;