Mercurial > octave
diff libinterp/parse-tree/pt-pr-code.cc @ 28257:ae94e3fad6d4 stable
fix printing of functions with varargin/varargout (bug #58279)
* pt-misc.h, pt-misc.cc (tree_parameter_list::m_in_or_out):
New data member.
(tree_parameter_list::varargs_symbol_name,
tree_parameter_list::is_input_list,
tree_parameter_list::is_output_list): New functions.
(tree_parameter_list::variable_names): Also include varargin or
varargout in the list.
(tree_parameter_list::dup): Pass m_in_or_out to tree_parameter_list
constructor.
* oct-parse.yy (opt_param_list): Don't create tree_parameter_list object
for empty lists that have no parens.
(param_list1): Always create a tree_parameter_list object.
* pt-pr-code.cc (tree_print_code::visit_octave_user_function_header):
Don't print input/output parameter lists here.
(tree_print_code::visit_anon_fcn_handle): Don't print parens for
parameter list here.
(tree_print_code::visit_parameter_list): Handle printing of all parts
of parameter lists here, including parens or brackets. For output
lists, skip brackets if there is a single element in the list,
including varargout.
* ov-fcn-handle.cc (octave_fcn_handle::print_raw): Don't print parens
for parameter list here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 May 2020 00:51:01 -0400 |
parents | 3241ede9806c |
children | 08229481b65f |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-pr-code.cc Thu Apr 30 23:51:30 2020 -0400 +++ b/libinterp/parse-tree/pt-pr-code.cc Fri May 01 00:51:01 2020 -0400 @@ -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