changeset 18355:9ca314e79956

Allow to call superclass constructor without arguments. * ov-classdef.cc (octave_classdef_superclass_ref::function_value): New method. * pt-funcall.h (tree_funcall::rvalue): Move definition to C++. * pt-funcall.cc (tree_funcall::rvalue): Moved from header. If the result of the function call is a single function object, re-index the function to yield the proper result it required (similar logic as in pt-id.cc).
author Michael Goffioul <michael.goffioul@gmail.com>
date Thu, 23 Jan 2014 21:24:43 -0500
parents c9b284dd28c6
children 7f87b13b3b3d
files libinterp/octave-value/ov-classdef.cc libinterp/parse-tree/pt-funcall.cc libinterp/parse-tree/pt-funcall.h
diffstat 3 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc	Thu Jan 23 14:40:35 2014 -0800
+++ b/libinterp/octave-value/ov-classdef.cc	Thu Jan 23 21:24:43 2014 -0500
@@ -1040,6 +1040,8 @@
 
   ~octave_classdef_superclass_ref (void) { }
 
+  octave_function* function_value (bool = false) { return this; }
+
   octave_value_list
   subsref (const std::string& type,
            const std::list<octave_value_list>& idx,
--- a/libinterp/parse-tree/pt-funcall.cc	Thu Jan 23 14:40:35 2014 -0800
+++ b/libinterp/parse-tree/pt-funcall.cc	Thu Jan 23 21:24:43 2014 -0500
@@ -81,3 +81,31 @@
 {
   tw.visit_funcall (*this);
 }
+
+octave_value_list
+tree_funcall::rvalue (int nargout)
+{
+  octave_value_list retval;
+
+  retval = feval (fcn.function_value (), args, nargout);
+
+  if (retval.length () == 1 && retval(0).is_function ())
+    {
+      // The return object is a function. We may need to re-index it using the
+      // same logic as for identifier. This is primarily used for superclass
+      // references in classdef.
+
+      octave_value val = retval(0);
+      octave_function *f = val.function_value (true);
+
+      if (f && ! (is_postfix_indexed ()
+                  && f->is_postfix_index_handled (postfix_index ())))
+        {
+          octave_value_list tmp_args;
+
+          retval = val.do_multi_index_op (nargout, tmp_args);
+        }
+    }
+
+  return retval;
+}
--- a/libinterp/parse-tree/pt-funcall.h	Thu Jan 23 14:40:35 2014 -0800
+++ b/libinterp/parse-tree/pt-funcall.h	Thu Jan 23 21:24:43 2014 -0500
@@ -71,10 +71,7 @@
     return retval;
   }
 
-  octave_value_list rvalue (int nargout)
-  {
-    return feval (fcn.function_value (), args, nargout);
-  }
+  octave_value_list rvalue (int nargout);
 
   octave_value function (void) const { return fcn; }