Mercurial > hg > octave-shane
changeset 3292:ad0d250ebd7e
[project @ 1999-10-14 22:52:28 by jwe]
author | jwe |
---|---|
date | Thu, 14 Oct 1999 22:52:28 +0000 |
parents | 029fac81ac65 |
children | 58950f032a06 |
files | src/ChangeLog src/parse.y |
diffstat | 2 files changed, 64 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +1999-10-14 John W. Eaton <jwe@bevo.che.wisc.edu> + + * parse.y (fold (tree_unary_expression *)): New function. + (make_prefix_op, make_postfix_op): Use it. + 1999-10-13 John W. Eaton <jwe@bevo.che.wisc.edu> * Makefile.in (oct-gperf.h): Ask for ANSI-C output from gperf
--- a/src/parse.y +++ b/src/parse.y @@ -1556,7 +1556,7 @@ { tree_expression *retval = e; - unwind_protect::begin_frame ("fold"); + unwind_protect::begin_frame ("fold_binary_expression"); unwind_protect_int (error_state); @@ -1596,7 +1596,56 @@ } } - unwind_protect::run_frame ("fold"); + unwind_protect::run_frame ("fold_binary_expression"); + + return retval; +} + +static tree_expression * +fold (tree_unary_expression *e) +{ + tree_expression *retval = e; + + unwind_protect::begin_frame ("fold_unary_expression"); + + unwind_protect_int (error_state); + + unwind_protect_bool (buffer_error_messages); + buffer_error_messages = true; + + unwind_protect::add (clear_global_error_variable, 0); + + tree_expression *op = e->operand (); + + if (op->is_constant ()) + { + octave_value tmp = e->rvalue (); + + if (! error_state) + { + tree_constant *tc_retval = new tree_constant (tmp); + + ostrstream buf; + + tree_print_code tpc (buf); + + e->accept (tpc); + + buf << ends; + + char *s = buf.str (); + + tc_retval->stash_original_text (s); + + delete [] s; + + delete e; + + retval = tc_retval; + } + } + + unwind_protect::run_frame ("fold_unary_expression"); return retval; } @@ -1882,9 +1931,10 @@ int l = tok_val->line (); int c = tok_val->column (); - // XXX FIXME XXX -- what about constant folding here? - - return new tree_prefix_expression (op1, l, c, t); + tree_prefix_expression *e + = new tree_prefix_expression (op1, l, c, t); + + return fold (e); } // Build a postfix expression. @@ -1920,9 +1970,10 @@ int l = tok_val->line (); int c = tok_val->column (); - // XXX FIXME XXX -- what about constant folding here? - - return new tree_postfix_expression (op1, l, c, t); + tree_postfix_expression *e + = new tree_postfix_expression (op1, l, c, t); + + return fold (e); } // Build an unwind-protect command.