# HG changeset patch # User John W. Eaton # Date 1289380034 18000 # Node ID 64e7538db12a44ccf93b5210bb00f2bcb358bd88 # Parent 6eba18ec59b638d5b324edf82bd0cb948c45cba0 fix printing of newlines for anonymous function handle bodies diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2010-11-10 John W. Eaton + + Bug #31491. + + * pt-pr-code.cc, pt-pr-code.h (tree_print_code::print_fcn_handle_body): + New function. + * ov-fcn-handle (octave_fcn_handle::print_raw): Use it. + * pt-pr-code.cc (tree_print_code::visit_anon_fcn_handle): Likewise. + * pt-pr-code.h (tree_print_code::suppress_newline): Rename from + printing_newlines. Now int. Change all uses. + * pt-pr-code.cc (tree_print_code::newline): Only set + beginning_of_line if newline is printed. + 2010-11-10 John W. Eaton Bug #31567. diff --git a/src/ov-fcn-handle.cc b/src/ov-fcn-handle.cc --- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -1321,33 +1321,7 @@ os << ") "; - tree_statement_list *b = f->body (); - - if (b) - { - assert (b->length () == 1); - - tree_statement *s = b->front (); - - if (s) - { - if (s->is_expression ()) - { - tree_expression *e = s->expression (); - - if (e) - e->accept (tpc); - } - else - { - tree_command *c = s->command (); - - tpc.suspend_newline (); - c->accept (tpc); - tpc.resume_newline (); - } - } - } + tpc.print_fcn_handle_body (f->body ()); printed = true; } diff --git a/src/pt-pr-code.cc b/src/pt-pr-code.cc --- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -51,10 +51,7 @@ os << ") "; - tree_statement_list *body = afh.body (); - - if (body) - body->accept (*this); + print_fcn_handle_body (afh.body ()); print_parens (afh, ")"); } @@ -1150,6 +1147,40 @@ newline (); } +void +tree_print_code::print_fcn_handle_body (tree_statement_list *b) +{ + if (b) + { + assert (b->length () == 1); + + tree_statement *s = b->front (); + + if (s) + { + if (s->is_expression ()) + { + tree_expression *e = s->expression (); + + if (e) + { + suppress_newlines++; + e->accept (*this); + suppress_newlines--; + } + } + else + { + tree_command *c = s->command (); + + suppress_newlines++; + c->accept (*this); + suppress_newlines--; + } + } + } +} + // Each print_code() function should call this before printing // anything. // @@ -1160,17 +1191,14 @@ { assert (curr_print_indent_level >= 0); - if (printing_newlines) + if (beginning_of_line) { - if (beginning_of_line) - { - os << prefix; + os << prefix; - for (int i = 0; i < curr_print_indent_level; i++) - os << " "; + for (int i = 0; i < curr_print_indent_level; i++) + os << " "; - beginning_of_line = false; - } + beginning_of_line = false; } } @@ -1179,9 +1207,14 @@ void tree_print_code::newline (const char *alt_txt) { - os << (printing_newlines ? "\n" : alt_txt); + if (suppress_newlines) + os << alt_txt; + else + { + os << "\n"; - beginning_of_line = true; + beginning_of_line = true; + } } // For ressetting print_code state. diff --git a/src/pt-pr-code.h b/src/pt-pr-code.h --- a/src/pt-pr-code.h +++ b/src/pt-pr-code.h @@ -46,7 +46,7 @@ : os (os_arg), prefix (pfx), nesting (), print_original_text (pr_orig_txt), curr_print_indent_level (0), beginning_of_line (true), - printing_newlines (true) + suppress_newlines (0) { // For "none". nesting.push ('n'); @@ -140,9 +140,7 @@ void visit_do_until_command (tree_do_until_command&); - void suspend_newline (void) { printing_newlines = false; } - - void resume_newline (void) { printing_newlines = true; } + void print_fcn_handle_body (tree_statement_list *); private: @@ -160,8 +158,8 @@ // TRUE means we are at the beginning of a line. bool beginning_of_line; - // TRUE means we are printing newlines and indenting. - bool printing_newlines; + // Nonzero means we are not printing newlines and indenting. + int suppress_newlines; void do_decl_command (tree_decl_command& cmd);