Mercurial > hg > octave-terminal
changeset 2991:fc751d2a99fd
[project @ 1997-05-16 21:00:48 by jwe]
author | jwe |
---|---|
date | Fri, 16 May 1997 21:00:49 +0000 |
parents | 35bd1b05cfbe |
children | 53b38bf1d443 |
files | src/ChangeLog src/Makefile.in src/pt-arg-list.cc src/pt-assign.cc src/pt-idx.cc src/pt-idx.h src/pt.cc src/pt.h |
diffstat | 8 files changed, 98 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ Fri May 16 00:07:11 1997 John W. Eaton <jwe@bevo.che.wisc.edu> + * pt-idx.cc (tree_index_expression::name): New function. + + * pt.cc (tree::str_print_code): New file, new convenience function. + * pt-arg-list.cc (tree_argument_list::get_arg_names): Use it. + * pt-assign.cc (tree_simple_assignment::rvalue): Likewise. + (tree_multi_assignment::rvalue): Likewise. + * pt-colon.h (tree_colon_expression::save_base): New data memmber. (tree_colon_expression::preserve_base): New function. * parse.y (finish_colon_expression): When converting to a simple
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -70,7 +70,7 @@ ov-str-mat.h ov-bool-mat.h ov-bool.h ov-file.h ov.h \ ov-fcn.h ov-builtin.h ov-mapper.h ov-usr-fcn.h ov-typeinfo.h -PT_INCLUDES := pt-all.h pt-arg-list.h pt-assign.h pt-base.h \ +PT_INCLUDES := pt.h pt-all.h pt-arg-list.h pt-assign.h \ pt-binop.h pt-cmd.h pt-colon.h pt-const.h pt-decl.h \ pt-except.h pt-exp.h pt-id.h pt-idx.h pt-indir.h \ pt-jump.h pt-loop.h pt-mat.h pt-misc.h pt-plot.h \ @@ -111,7 +111,7 @@ ov-bool-mat.cc ov-bool.cc ov-file.cc ov.cc ov-fcn.cc \ ov-builtin.cc ov-mapper.cc ov-usr-fcn.cc ov-typeinfo.cc -PT_SRC := pt-arg-list.cc pt-assign.cc pt-binop.cc \ +PT_SRC := pt.cc pt-arg-list.cc pt-assign.cc pt-binop.cc \ pt-cmd.cc pt-colon.cc pt-const.cc pt-decl.cc pt-except.cc \ pt-exp.cc pt-id.cc pt-idx.cc pt-indir.cc pt-jump.cc \ pt-loop.cc pt-mat.cc pt-misc.cc pt-plot.cc pt-pr-code.cc \
--- a/src/pt-arg-list.cc +++ b/src/pt-arg-list.cc @@ -147,19 +147,7 @@ { tree_expression *elt = this->operator () (p); - strstream str_buf; - - tree_print_code pc_buf (str_buf); - - elt->accept (pc_buf); - - str_buf << ends; - - const char *s = str_buf.str (); - - retval(k++) = s; - - delete [] s; + retval(k++) = elt->str_print_code (); } return retval;
--- a/src/pt-assign.cc +++ b/src/pt-assign.cc @@ -40,7 +40,6 @@ #include "ov.h" #include "pt-arg-list.h" #include "pt-assign.h" -#include "pt-pr-code.h" #include "pt-walk.h" #include "utils.h" @@ -114,28 +113,15 @@ if (error_state) eval_error (); - else if (! Vprint_rhs_assign_val) + else { octave_value lhs_val = ult.value (); if (! error_state && print_result ()) { if (Vprint_rhs_assign_val) - { - ostrstream buf; - - tree_print_code tpc (buf); - - lhs->accept (tpc); - - buf << ends; - - const char *tag = buf.str (); - - rhs_val.print_with_name (octave_stdout, tag); - - delete [] tag; - } + rhs_val.print_with_name (octave_stdout, + lhs->str_print_code ()); else lhs_val.print_with_name (octave_stdout, lhs->name ()); @@ -271,22 +257,8 @@ if (! error_state && print_result ()) { if (Vprint_rhs_assign_val) - { - ostrstream buf; - - tree_print_code tpc (buf); - - lhs_elt->accept (tpc); - - buf << ends; - - const char *tag = buf.str (); - - tmp.print_with_name - (octave_stdout, tag); - - delete [] tag; - } + tmp.print_with_name (octave_stdout, + lhs_elt->str_print_code ()); else lhs_val.print_with_name (octave_stdout, lhs_elt->name ());
--- a/src/pt-idx.cc +++ b/src/pt-idx.cc @@ -44,6 +44,15 @@ delete list; } +// This is useful for printing the name of the variable in an indexed +// assignment. + +string +tree_index_expression::name (void) const +{ + return expr->name (); +} + octave_value_list tree_index_expression::rvalue (int nargout) {
--- a/src/pt-idx.h +++ b/src/pt-idx.h @@ -55,6 +55,8 @@ bool is_index_expression (void) const { return true; } + string name (void) const; + tree_expression *expression (void) { return expr; }
new file mode 100644 --- /dev/null +++ b/src/pt.cc @@ -0,0 +1,66 @@ +/* + +Copyright (C) 1996, 1997 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#if defined (__GNUG__) +#pragma implementation +#endif + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string> + +#include <iostream.h> +#include <strstream.h> + +#include "pt.h" +#include "pt-pr-code.h" + +// Hide the details of the string buffer so that we are less likely to +// create a memory leak. + +string +tree::str_print_code (void) +{ + ostrstream buf; + + tree_print_code tpc (buf); + + accept (tpc); + + buf << ends; + + const char *s = buf.str (); + + string retval = s; + + delete [] s; + + return retval; +} + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
--- a/src/pt.h +++ b/src/pt.h @@ -27,6 +27,10 @@ #pragma interface #endif +#include <string> + +class ostream; + class tree_walker; // Base class for the parse tree. @@ -52,6 +56,8 @@ virtual void accept (tree_walker& tw) = 0; + string str_print_code (void); + private: // The input line and column where we found the text that was