# HG changeset patch # User jwe # Date 863816449 0 # Node ID fc751d2a99fd46cf509fc598c580b39125da359d # Parent 35bd1b05cfbe506510dc80c782a65d4dd36e2cf6 [project @ 1997-05-16 21:00:48 by jwe] diff -r 35bd1b05cfbe -r fc751d2a99fd src/ChangeLog --- a/src/ChangeLog Fri May 16 09:19:12 1997 +0000 +++ b/src/ChangeLog Fri May 16 21:00:49 1997 +0000 @@ -1,5 +1,12 @@ Fri May 16 00:07:11 1997 John W. Eaton + * 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 diff -r 35bd1b05cfbe -r fc751d2a99fd src/Makefile.in --- a/src/Makefile.in Fri May 16 09:19:12 1997 +0000 +++ b/src/Makefile.in Fri May 16 21:00:49 1997 +0000 @@ -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 \ diff -r 35bd1b05cfbe -r fc751d2a99fd src/pt-arg-list.cc --- a/src/pt-arg-list.cc Fri May 16 09:19:12 1997 +0000 +++ b/src/pt-arg-list.cc Fri May 16 21:00:49 1997 +0000 @@ -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; diff -r 35bd1b05cfbe -r fc751d2a99fd src/pt-assign.cc --- a/src/pt-assign.cc Fri May 16 09:19:12 1997 +0000 +++ b/src/pt-assign.cc Fri May 16 21:00:49 1997 +0000 @@ -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 ()); diff -r 35bd1b05cfbe -r fc751d2a99fd src/pt-idx.cc --- a/src/pt-idx.cc Fri May 16 09:19:12 1997 +0000 +++ b/src/pt-idx.cc Fri May 16 21:00:49 1997 +0000 @@ -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) { diff -r 35bd1b05cfbe -r fc751d2a99fd src/pt-idx.h --- a/src/pt-idx.h Fri May 16 09:19:12 1997 +0000 +++ b/src/pt-idx.h Fri May 16 21:00:49 1997 +0000 @@ -55,6 +55,8 @@ bool is_index_expression (void) const { return true; } + string name (void) const; + tree_expression *expression (void) { return expr; } diff -r 35bd1b05cfbe -r fc751d2a99fd src/pt.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pt.cc Fri May 16 21:00:49 1997 +0000 @@ -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 +#endif + +#include + +#include +#include + +#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: *** +*/ diff -r 35bd1b05cfbe -r fc751d2a99fd src/pt.h --- a/src/pt.h Fri May 16 09:19:12 1997 +0000 +++ b/src/pt.h Fri May 16 21:00:49 1997 +0000 @@ -27,6 +27,10 @@ #pragma interface #endif +#include + +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