Mercurial > hg > octave-nkf
changeset 4980:003bbf6c13d8
[project @ 2004-09-09 15:47:17 by jwe]
author | jwe |
---|---|
date | Thu, 09 Sep 2004 15:47:17 +0000 |
parents | ce4e3d39d05b |
children | 0e7d04102ccf |
files | src/ChangeLog src/ov-fcn-handle.cc src/pt-pr-code.cc src/pt-pr-code.h |
diffstat | 4 files changed, 132 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2004-09-09 John W. Eaton <jwe@octave.org> + + * pt-pr-code.h (tree_print_code::newline): New optional arg, alt_nl. + * pt-pr-code.cc (tree_print_code::newline): Use it if not printing + newlines. + (tree_print_code::visit_statement): If we printed ";", call + newline with optional arg set to "". + (tree_print_code::printing_newlines): New data member. + (tree_print_code::tree_print_code): Initialize it. + (tree_print_code::suspend_newline, tree_print_code::resume_newline): + New functions. + (tree_print_code::newline, tree_print_code::indent): Use it + + * ov-fcn-handle.cc (octave_fcn_handle::print_raw): + Print code for anonymous function handles. + 2004-09-08 John W. Eaton <jwe@octave.org> * ov-fcn-handle.cc (Ffunc2str, Ffunctions): Don't call substr(1)
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -36,7 +36,14 @@ #include "oct-map.h" #include "ov-base.h" #include "ov-fcn-handle.h" +#include "ov-usr-fcn.h" #include "pr-output.h" +#include "pt-pr-code.h" +#include "pt-misc.h" +#include "pt-stmt.h" +#include "pt-cmd.h" +#include "pt-exp.h" +#include "pt-assign.h" #include "variables.h" DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); @@ -94,8 +101,81 @@ void octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const { - octave_print_internal (os, nm, pr_as_read_syntax, - current_print_indent_level ()); + bool printed = false; + + if (nm == "@<anonymous>") + { + tree_print_code tpc (os); + + // FCN is const becuase this member function is, so we can't + // use it to call user_function_value, so we make a copy first. + + octave_value ftmp = fcn; + + octave_user_function *f = ftmp.user_function_value (); + + if (f) + { + tree_parameter_list *p = f->parameter_list (); + + os << "@("; + + if (p) + p->accept (tpc); + + 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) + { + if (e->is_assignment_expression ()) + { + // The parser builds an assignment to + // __retval__, and we don't want to + // display that part. + + tree_simple_assignment *tsa + = reinterpret_cast <tree_simple_assignment *> (e); + tree_expression *rhs = tsa->right_hand_side (); + + if (rhs) + rhs->accept (tpc); + } + else + e->accept (tpc); + } + } + else + { + tree_command *c = s->command (); + + tpc.suspend_newline (); + c->accept (tpc); + tpc.resume_newline (); + } + } + } + + printed = true; + } + } + + if (! printed) + octave_print_internal (os, nm, pr_as_read_syntax, + current_print_indent_level ()); } octave_value
--- a/src/pt-pr-code.cc +++ b/src/pt-pr-code.cc @@ -883,9 +883,12 @@ cmd->accept (*this); if (! stmt.print_result ()) - os << ";"; - - newline (); + { + os << ";"; + newline (" "); + } + else + newline (); } else { @@ -896,9 +899,12 @@ expr->accept (*this); if (! stmt.print_result ()) - os << ";"; - - newline (); + { + os << ";"; + newline (" "); + } + else + newline (); } } } @@ -1283,24 +1289,27 @@ tree_print_code::indent (void) { assert (curr_print_indent_level >= 0); - - if (beginning_of_line) - { - os << prefix; - for (int i = 0; i < curr_print_indent_level; i++) - os << " "; + if (printing_newlines) + { + if (beginning_of_line) + { + os << prefix; - beginning_of_line = false; + for (int i = 0; i < curr_print_indent_level; i++) + os << " "; + + beginning_of_line = false; + } } } // All print_code() functions should use this to print new lines. void -tree_print_code::newline (void) +tree_print_code::newline (const char *alt_txt) { - os << "\n"; + os << (printing_newlines ? "\n" : alt_txt); beginning_of_line = true; }
--- a/src/pt-pr-code.h +++ b/src/pt-pr-code.h @@ -47,7 +47,8 @@ bool pr_orig_txt = true) : os (os_arg), prefix (pfx), nesting (), print_original_text (pr_orig_txt), - curr_print_indent_level (0), beginning_of_line (true) + curr_print_indent_level (0), beginning_of_line (true), + printing_newlines (true) { // For "none". nesting.push ('n'); @@ -149,6 +150,10 @@ void visit_do_until_command (tree_do_until_command&); + void suspend_newline (void) { printing_newlines = false; } + + void resume_newline (void) { printing_newlines = true; } + private: std::ostream& os; @@ -165,13 +170,16 @@ // 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; + void reset_indent_level (void) { curr_print_indent_level = 0; } void increment_indent_level (void) { curr_print_indent_level += 2; } void decrement_indent_level (void) { curr_print_indent_level -= 2; } - void newline (void); + void newline (const char *alt_txt = ", "); void indent (void);