Mercurial > hg > octave-lyh
changeset 4676:c0aa75a64635
[project @ 2003-12-16 16:47:52 by jwe]
author | jwe |
---|---|
date | Tue, 16 Dec 2003 16:47:52 +0000 |
parents | f6d6335c08f6 |
children | e650670557f7 |
files | src/ChangeLog src/ov-base-mat.h src/pt-pr-code.cc src/pt-pr-code.h |
diffstat | 4 files changed, 81 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,20 @@ +2003-12-16 John W. Eaton <jwe@bevo.che.wisc.edu> + + * pt-pr-code.cc (tree_print_code::visit_complex_for_command, + tree_print_code::visit_octave_user_function_header, + tree_print_code::visit_matrix, tree_print_code::visit_cell, + tree_print_code::visit_multi_assignment): Keep track of nearest + [, {, or ( nesting level. + (tree_print_code::visit_index_expression): Likewise. Check nesting + level to decide how to print index. + (tree_print_code::reset): Also reset nesting level stack. + + * pt-pr-code.h (tree_print_code::nesting): New data member. + (tree_print_code::tree_print_code): Initialize it. + + * ov-base-mat.h (octave_base_matrix::octave_base_matrix (const MT&)): + If arg has no dimensions, resize to be 0x0. + 2003-12-15 John W. Eaton <jwe@bevo.che.wisc.edu> * oct-map.cc (Octave_map::assign): Use Octave_map::contents member
--- a/src/ov-base-mat.h +++ b/src/ov-base-mat.h @@ -56,7 +56,11 @@ : octave_base_value () { } octave_base_matrix (const MT& m) - : octave_base_value (), matrix (m) { } + : octave_base_value (), matrix (m) + { + if (matrix.ndims () == 0) + matrix.resize (dim_vector (0, 0)); + } octave_base_matrix (const octave_base_matrix& m) : octave_base_value (), matrix (m.matrix) { }
--- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -227,12 +227,14 @@ indent (); os << "for ["; + nesting.push ('['); tree_argument_list *lhs = cmd.left_hand_side (); if (lhs) lhs->accept (*this); + nesting.pop (); os << "] = "; tree_expression *expr = cmd.control_expr (); @@ -305,7 +307,10 @@ int len = ret_list->length (); if (len > 1 || takes_var_return) - os << "["; + { + os << "["; + nesting.push ('['); + } ret_list->accept (*this); @@ -318,7 +323,10 @@ } if (len > 1 || takes_var_return) - os << "]"; + { + nesting.pop (); + os << "]"; + } os << " = "; } @@ -336,7 +344,10 @@ int len = param_list->length (); if (len > 0 || takes_varargs) - os << "("; + { + os << "("; + nesting.push ('('); + } param_list->accept (*this); @@ -350,6 +361,7 @@ if (len > 0 || takes_varargs) { + nesting.pop (); os << ")"; newline (); } @@ -494,20 +506,38 @@ { case '(': { - os << " ("; + char nc = nesting.top (); + if ((nc == '[' || nc == '{') && expr.paren_count () == 0) + os << "("; + else + os << " ("; + nesting.push ('('); + tree_argument_list *l = *p_arg_lists; if (l) l->accept (*this); + + nesting.pop (); os << ")"; } break; case '{': { - os << " {"; + char nc = nesting.top (); + if ((nc == '[' || nc == '{') && expr.paren_count () == 0) + os << "{"; + else + os << " {"; + // We only care about whitespace inside [] and {} when we + // are defining matrix and cell objects, not when indexing. + nesting.push ('('); + tree_argument_list *l = *p_arg_lists; if (l) l->accept (*this); + + nesting.pop (); os << "}"; } break; @@ -539,6 +569,7 @@ print_parens (lst, "("); os << "["; + nesting.push ('['); tree_matrix::iterator p = lst.begin (); @@ -555,6 +586,7 @@ } } + nesting.pop (); os << "]"; print_parens (lst, ")"); @@ -568,6 +600,7 @@ print_parens (lst, "("); os << "{"; + nesting.push ('{'); tree_cell::iterator p = lst.begin (); @@ -584,6 +617,7 @@ } } + nesting.pop (); os << "}"; print_parens (lst, ")"); @@ -603,12 +637,18 @@ int len = lhs->length (); if (len > 1) - os << "["; + { + os << "["; + nesting.push ('['); + } lhs->accept (*this); if (len > 1) - os << "]"; + { + nesting.pop (); + os << "]"; + } } os << " " << expr.oper () << " "; @@ -1272,6 +1312,8 @@ { beginning_of_line = true; curr_print_indent_level = 0; + while (nesting.top () != 'n') + nesting.pop (); } void
--- a/src/pt-pr-code.h +++ b/src/pt-pr-code.h @@ -27,6 +27,7 @@ #pragma interface #endif +#include <stack> #include <string> #include "comment-list.h" @@ -44,8 +45,13 @@ tree_print_code (std::ostream& os_arg, const std::string& pfx = std::string (), bool pr_orig_txt = true) - : os (os_arg), prefix (pfx), print_original_text (pr_orig_txt), - curr_print_indent_level (0), beginning_of_line (true) { } + : os (os_arg), prefix (pfx), nesting (), + print_original_text (pr_orig_txt), + curr_print_indent_level (0), beginning_of_line (true) + { + // For "none". + nesting.push ('n'); + } ~tree_print_code (void) { } @@ -149,6 +155,8 @@ std::string prefix; + std::stack<char> nesting; + bool print_original_text; // Current indentation.