changeset 9692:126b49caba0d

smart splitting of index chains
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 05 Oct 2009 10:42:58 +0200
parents 318e0cdd31bd
children 1c19877799d3
files src/ChangeLog src/pt-idx.cc
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Oct 05 10:20:18 2009 +0200
+++ b/src/ChangeLog	Mon Oct 05 10:42:58 2009 +0200
@@ -1,3 +1,8 @@
+2009-10-05  Jaroslav Hajek  <highegg@gmail.com>
+
+	* pt-idx.cc (tree_index_expression::rvalue): When evaluating index
+	chain, split on chaining ()() and (){}.
+
 2009-10-05  Jaroslav Hajek  <highegg@gmail.com>
 
 	* pt-misc.cc (tree_argument_list::convert_to_const_vector):
--- a/src/pt-idx.cc	Mon Oct 05 10:20:18 2009 +0200
+++ b/src/pt-idx.cc	Mon Oct 05 10:42:58 2009 +0200
@@ -328,7 +328,14 @@
 	    {
 	      tree_argument_list *al = *p_args;
 
-	      if (al && al->has_magic_end ())
+              // In Matlab, () can only be followed by . In Octave, we do not
+              // enforce this for rvalue expressions, but we'll split the
+              // evaluation at this point. This will, hopefully, allow Octave's
+              // looser rules apply smoothly for Matlab overloaded subsref
+              // codes.
+              bool force_split = type[i-1] == '(' && type[i] != '.';
+
+	      if (force_split || (al && al->has_magic_end ()))
 		{
 		  // We have an expression like
 		  //
@@ -343,7 +350,7 @@
 		  const octave_value_list tmp_list
 		    = tmp.subsref (type.substr (tmpi, i - tmpi), idx, nargout);
 
-		  tmp = tmp_list(0);
+		  tmp = tmp_list.length () ? tmp_list(0) : octave_value ();
                   tmpi = i;
                   idx.clear ();