# HG changeset patch # User Rik # Date 1588447466 25200 # Node ID e9126e73748a14f5fe49c6eb822c83bf27a84516 # Parent 18bd65ad4e7d943136f1334dcfd4f0308c5eb48f# Parent ae94e3fad6d45780cca585a23cd3cd601112291f maint: merge stable to default. diff -r 18bd65ad4e7d -r e9126e73748a libinterp/octave-value/cdef-class.cc --- a/libinterp/octave-value/cdef-class.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/octave-value/cdef-class.cc Sat May 02 12:24:26 2020 -0700 @@ -198,7 +198,6 @@ void visit_postfix_expression (tree_postfix_expression&) { } void visit_prefix_expression (tree_prefix_expression&) { } void visit_return_command (tree_return_command&) { } - void visit_return_list (tree_return_list&) { } void visit_try_catch_command (tree_try_catch_command&) { } void visit_unwind_protect_command (tree_unwind_protect_command&) { } void visit_while_command (tree_while_command&) { } diff -r 18bd65ad4e7d -r e9126e73748a libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/octave-value/ov-fcn-handle.cc Sat May 02 12:24:26 2020 -0700 @@ -1654,14 +1654,18 @@ if (f) { - octave::tree_parameter_list *p = f->parameter_list (); + os << "@"; - os << "@("; + // The parameter list should always be valid for anonymous + // functions, so we should always call accept for it, and it + // will print the parens for us. + + octave::tree_parameter_list *p = f->parameter_list (); if (p) p->accept (tpc); - os << ") "; + os << " "; octave::tree_statement_list *b = f->body (); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/oct-parse.yy --- a/libinterp/parse-tree/oct-parse.yy Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/oct-parse.yy Sat May 02 12:24:26 2020 -0700 @@ -1429,7 +1429,7 @@ ; param_list1 : // empty - { $$ = nullptr; } + { $$ = new octave::tree_parameter_list (octave::tree_parameter_list::in); } | param_list2 { $1->mark_as_formal_parameters (); @@ -1448,7 +1448,7 @@ ; param_list2 : param_list_elt - { $$ = new octave::tree_parameter_list ($1); } + { $$ = new octave::tree_parameter_list (octave::tree_parameter_list::in, $1); } | param_list2 ',' param_list_elt { YYUSE ($2); @@ -1475,13 +1475,14 @@ lexer.m_looking_at_return_list = false; - $$ = new octave::tree_parameter_list (); + $$ = new octave::tree_parameter_list (octave::tree_parameter_list::out); } | identifier { lexer.m_looking_at_return_list = false; - octave::tree_parameter_list *tmp = new octave::tree_parameter_list ($1); + octave::tree_parameter_list *tmp + = new octave::tree_parameter_list (octave::tree_parameter_list::out, $1); // Even though this parameter list can contain only // a single identifier, we still need to validate it @@ -1516,7 +1517,9 @@ ; return_list1 : identifier - { $$ = new octave::tree_parameter_list (new octave::tree_decl_elt ($1)); } + { + $$ = new octave::tree_parameter_list (octave::tree_parameter_list::out, new octave::tree_decl_elt ($1)); + } | return_list1 ',' identifier { YYUSE ($2); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-bp.cc --- a/libinterp/parse-tree/pt-bp.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-bp.cc Sat May 02 12:24:26 2020 -0700 @@ -267,12 +267,6 @@ } void - tree_breakpoint::visit_return_list (tree_return_list&) - { - panic_impossible (); - } - - void tree_breakpoint::visit_simple_assignment (tree_simple_assignment&) { panic_impossible (); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-bp.h --- a/libinterp/parse-tree/pt-bp.h Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-bp.h Sat May 02 12:24:26 2020 -0700 @@ -119,8 +119,6 @@ void visit_return_command (tree_return_command&); - void visit_return_list (tree_return_list&); - void visit_simple_assignment (tree_simple_assignment&); void visit_statement (tree_statement&); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-eval.cc Sat May 02 12:24:26 2020 -0700 @@ -2709,12 +2709,6 @@ } void - tree_evaluator::visit_return_list (tree_return_list&) - { - panic_impossible (); - } - - void tree_evaluator::visit_simple_assignment (tree_simple_assignment&) { panic_impossible (); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-eval.h --- a/libinterp/parse-tree/pt-eval.h Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-eval.h Sat May 02 12:24:26 2020 -0700 @@ -250,8 +250,6 @@ void visit_return_command (tree_return_command&); - void visit_return_list (tree_return_list&); - void visit_simple_assignment (tree_simple_assignment&); void visit_statement (tree_statement&); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-jit.cc --- a/libinterp/parse-tree/pt-jit.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-jit.cc Sat May 02 12:24:26 2020 -0700 @@ -776,12 +776,6 @@ } void - jit_convert::visit_return_list (tree_return_list&) - { - throw jit_fail_exception ("No visit_return_list implementation"); - } - - void jit_convert::visit_simple_assignment (tree_simple_assignment& tsa) { tree_expression *rhs = tsa.right_hand_side (); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-jit.h --- a/libinterp/parse-tree/pt-jit.h Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-jit.h Sat May 02 12:24:26 2020 -0700 @@ -142,8 +142,6 @@ void visit_return_command (tree_return_command&); - void visit_return_list (tree_return_list&); - void visit_simple_assignment (tree_simple_assignment&); void visit_statement (tree_statement&); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-misc.cc --- a/libinterp/parse-tree/pt-misc.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-misc.cc Sat May 02 12:24:26 2020 -0700 @@ -59,13 +59,16 @@ for (tree_decl_elt *elt : *this) retval.push_back (elt->name ()); + if (m_marked_for_varargs) + retval.push_back (varargs_symbol_name ()); + return retval; } tree_parameter_list * tree_parameter_list::dup (symbol_scope& scope) const { - tree_parameter_list *new_list = new tree_parameter_list (); + tree_parameter_list *new_list = new tree_parameter_list (m_in_or_out); new_list->m_marked_for_varargs = m_marked_for_varargs; @@ -74,16 +77,4 @@ return new_list; } - - // Return lists. - - tree_return_list::~tree_return_list (void) - { - while (! empty ()) - { - auto p = begin (); - delete *p; - erase (p); - } - } } diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-misc.h --- a/libinterp/parse-tree/pt-misc.h Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-misc.h Sat May 02 12:24:26 2020 -0700 @@ -52,14 +52,21 @@ out = 2 }; - tree_parameter_list (void) - : m_marked_for_varargs (0) { } + tree_parameter_list (in_or_out io) + : m_in_or_out (io), m_marked_for_varargs (0) + { } - tree_parameter_list (tree_decl_elt *t) - : m_marked_for_varargs (0) { append (t); } + tree_parameter_list (in_or_out io, tree_decl_elt *t) + : m_in_or_out (io), m_marked_for_varargs (0) + { + append (t); + } - tree_parameter_list (tree_identifier *id) - : m_marked_for_varargs (0) { append (new tree_decl_elt (id)); } + tree_parameter_list (in_or_out io, tree_identifier *id) + : m_in_or_out (io), m_marked_for_varargs (0) + { + append (new tree_decl_elt (id)); + } // No copying! @@ -79,8 +86,17 @@ bool varargs_only (void) { return (m_marked_for_varargs < 0); } + bool is_input_list (void) const { return m_in_or_out == in; } + + bool is_output_list (void) const { return m_in_or_out == out; } + std::list variable_names (void) const; + std::string varargs_symbol_name (void) const + { + return m_in_or_out == in ? "varargin" : "varargout"; + } + tree_parameter_list * dup (symbol_scope& scope) const; void accept (tree_walker& tw) @@ -90,32 +106,12 @@ private: - int m_marked_for_varargs; - }; - - // Return lists. Used to hold the right hand sides of multiple - // assignment expressions. - - class tree_return_list : public base_list - { - public: - - tree_return_list (void) { } + in_or_out m_in_or_out; - tree_return_list (tree_index_expression *t) { append (t); } - - // No copying! - - tree_return_list (const tree_return_list&) = delete; - - tree_return_list& operator = (const tree_return_list&) = delete; - - ~tree_return_list (void); - - void accept (tree_walker& tw) - { - tw.visit_return_list (*this); - } + // 1: takes varargs + // -1: takes varargs only + // 0: does not take varargs. + int m_marked_for_varargs; }; } diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-pr-code.cc --- a/libinterp/parse-tree/pt-pr-code.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-pr-code.cc Sat May 02 12:24:26 2020 -0700 @@ -44,15 +44,13 @@ print_parens (afh, "("); - m_os << "@("; + m_os << "@"; tree_parameter_list *param_list = afh.parameter_list (); if (param_list) param_list->accept (*this); - m_os << ") "; - print_fcn_handle_body (afh.expression ()); print_parens (afh, ")"); @@ -345,35 +343,10 @@ if (ret_list) { - bool takes_var_return = fcn.takes_var_return (); - - int len = ret_list->length (); - - if (len > 1 || takes_var_return) - { - m_os << '['; - m_nesting.push ('['); - } - ret_list->accept (*this); - if (takes_var_return) - { - if (len > 0) - m_os << ", "; - - m_os << "varargout"; - } - - if (len > 1 || takes_var_return) - { - m_nesting.pop (); - m_os << ']'; - } - m_os << " = "; } - std::string fcn_name = fcn.name (); m_os << (fcn_name.empty () ? "(empty)" : fcn_name) << ' '; @@ -381,31 +354,9 @@ tree_parameter_list *param_list = fcn.parameter_list (); if (param_list) - { - bool takes_varargs = fcn.takes_varargs (); - - int len = param_list->length (); - - if (len > 0 || takes_varargs) - { - m_os << '('; - m_nesting.push ('('); - } - - param_list->accept (*this); + param_list->accept (*this); - if (len > 0 || takes_varargs) - { - m_nesting.pop (); - m_os << ')'; - newline (); - } - } - else - { - m_os << "()"; - newline (); - } + newline (); } void @@ -737,6 +688,26 @@ void tree_print_code::visit_parameter_list (tree_parameter_list& lst) { + bool is_input_list = lst.is_input_list (); + + if (is_input_list) + { + m_os << '('; + m_nesting.push ('('); + } + else + { + int len = lst.length (); + if (lst.takes_varargs ()) + len++; + + if (len != 1) + { + m_os << '['; + m_nesting.push ('['); + } + } + auto p = lst.begin (); while (p != lst.end ()) @@ -753,7 +724,25 @@ } if (lst.takes_varargs ()) - m_os << "varargin"; + m_os << lst.varargs_symbol_name (); + + if (is_input_list) + { + m_nesting.pop (); + m_os << ')'; + } + else + { + int len = lst.length (); + if (lst.takes_varargs ()) + len++; + + if (len != 1) + { + m_nesting.pop (); + m_os << ']'; + } + } } void @@ -799,25 +788,6 @@ } void - tree_print_code::visit_return_list (tree_return_list& lst) - { - auto p = lst.begin (); - - while (p != lst.end ()) - { - tree_index_expression *elt = *p++; - - if (elt) - { - elt->accept (*this); - - if (p != lst.end ()) - m_os << ", "; - } - } - } - - void tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) { indent (); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-pr-code.h --- a/libinterp/parse-tree/pt-pr-code.h Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-pr-code.h Sat May 02 12:24:26 2020 -0700 @@ -128,8 +128,6 @@ void visit_return_command (tree_return_command&); - void visit_return_list (tree_return_list&); - void visit_simple_assignment (tree_simple_assignment&); void visit_statement (tree_statement&); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-walk.cc --- a/libinterp/parse-tree/pt-walk.cc Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-walk.cc Sat May 02 12:24:26 2020 -0700 @@ -386,19 +386,6 @@ // Nothing to do. } - void tree_walker::visit_return_list (tree_return_list& lst) - { - auto p = lst.begin (); - - while (p != lst.end ()) - { - tree_index_expression *elt = *p++; - - if (elt) - elt->accept (*this); - } - } - void tree_walker::visit_simple_assignment (tree_simple_assignment& expr) { tree_expression *lhs = expr.left_hand_side (); diff -r 18bd65ad4e7d -r e9126e73748a libinterp/parse-tree/pt-walk.h --- a/libinterp/parse-tree/pt-walk.h Thu Apr 30 11:54:21 2020 +0200 +++ b/libinterp/parse-tree/pt-walk.h Sat May 02 12:24:26 2020 -0700 @@ -72,7 +72,6 @@ class tree_postfix_expression; class tree_prefix_expression; class tree_return_command; - class tree_return_list; class tree_simple_assignment; class tree_statement; class tree_statement_list; @@ -185,8 +184,6 @@ virtual void visit_return_command (tree_return_command&); - virtual void visit_return_list (tree_return_list&); - virtual void visit_simple_assignment (tree_simple_assignment&); virtual void visit_statement (tree_statement&);