Mercurial > octave
changeset 28318:08229481b65f stable
print dynamic field names when printing parse tree
* pt-pr-code.cc (tree_print_code::visit_index_expression):
Handle dynamic field names.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 18 May 2020 12:32:17 -0400 |
parents | ac87763b1949 |
children | b81ff4104895 e10c25dd27f1 |
files | libinterp/parse-tree/pt-pr-code.cc |
diffstat | 1 files changed, 19 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-pr-code.cc Mon May 18 12:30:41 2020 -0400 +++ b/libinterp/parse-tree/pt-pr-code.cc Mon May 18 12:32: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, ")");