changeset 28319:b81ff4104895

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Mon, 18 May 2020 12:42:17 -0400
parents 7a1736f89c6b (current diff) 08229481b65f (diff)
children d4cabdf30b4a
files
diffstat 3 files changed, 68 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-fcn-handle.cc	Mon May 18 09:14:33 2020 -0700
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Mon May 18 12:42:17 2020 -0400
@@ -2136,6 +2136,16 @@
 */
 
 /*
+%!test <*58389>
+%! s = "x";
+%! a.(s) = [e, pi];
+%! f = @(x) a.(s)(x);
+%! assert (f(1), e);
+%! assert (f(2), pi);
+%! assert (f([2,1]), [pi, e]);
+*/
+
+/*
 %!function r = __f (g, i)
 %!  r = g(i);
 %!endfunction
--- a/libinterp/parse-tree/pt-pr-code.cc	Mon May 18 09:14:33 2020 -0700
+++ b/libinterp/parse-tree/pt-pr-code.cc	Mon May 18 12:42:17 2020 -0400
@@ -483,11 +483,13 @@
     std::list<tree_argument_list *> arg_lists = expr.arg_lists ();
     std::string type_tags = expr.type_tags ();
     std::list<string_vector> arg_names = expr.arg_names ();
+    std::list<tree_expression *> dyn_fields = expr.dyn_fields ();
 
     int n = type_tags.length ();
 
     auto p_arg_lists = arg_lists.begin ();
     auto p_arg_names = arg_names.begin ();
+    auto p_dyn_fields = dyn_fields.begin ();
 
     for (int i = 0; i < n; i++)
       {
@@ -533,9 +535,22 @@
 
           case '.':
             {
-              string_vector nm = *p_arg_names;
-              assert (nm.numel () == 1);
-              m_os << '.' << nm(0);
+              std::string fn = (*p_arg_names)(0);
+              if (fn.empty ())
+                {
+                  tree_expression *df = *p_dyn_fields;
+
+                  if (df)
+                    {
+                      m_nesting.push ('(');
+                      m_os << "(";
+                      df->accept (*this);
+                      m_os << ")";
+                      m_nesting.pop ();
+                    }
+                }
+              else
+                m_os << '.' << fn;
             }
             break;
 
@@ -545,6 +560,7 @@
 
         p_arg_lists++;
         p_arg_names++;
+        p_dyn_fields++;
       }
 
     print_parens (expr, ")");
--- a/libinterp/parse-tree/pt-walk.cc	Mon May 18 09:14:33 2020 -0700
+++ b/libinterp/parse-tree/pt-walk.cc	Mon May 18 12:42:17 2020 -0400
@@ -285,16 +285,49 @@
     if (e)
       e->accept (*this);
 
-    std::list<tree_argument_list *> lst = expr.arg_lists ();
+    std::list<tree_argument_list *> arg_lists = expr.arg_lists ();
+    std::list<string_vector> arg_names = expr.arg_names ();
+    std::list<tree_expression *> dyn_fields = expr.dyn_fields ();
 
-    auto p = lst.begin ();
+    auto p_arg_lists = arg_lists.begin ();
+    auto p_arg_names = arg_names.begin ();
+    auto p_dyn_fields = dyn_fields.begin ();
+
+    std::string type_tags = expr.type_tags ();
+    int n = type_tags.length ();
 
-    while (p != lst.end ())
+    for (int i = 0; i < n; i++)
       {
-        tree_argument_list *elt = *p++;
+        switch (type_tags[i])
+          {
+          case '(':
+          case '{':
+            {
+              tree_argument_list *l = *p_arg_lists;
+              if (l)
+                l->accept (*this);
+            }
+            break;
 
-        if (elt)
-          elt->accept (*this);
+          case '.':
+            {
+              std::string fn = (*p_arg_names)(0);
+              if (fn.empty ())
+                {
+                  tree_expression *df = *p_dyn_fields;
+                  if (df)
+                    df->accept (*this);
+                }
+            }
+            break;
+
+          default:
+            panic_impossible ();
+          }
+
+        p_arg_lists++;
+        p_arg_names++;
+        p_dyn_fields++;
       }
   }