# HG changeset patch # User jwe # Date 863453920 0 # Node ID a51926eab51aceb3cfd727451feebe5aba919166 # Parent 0a2551ec7004c301cf61b2fbc163e88350c3b8a1 [project @ 1997-05-12 16:18:39 by jwe] diff -r 0a2551ec7004 -r a51926eab51a src/pt-mvr-base.cc --- a/src/pt-mvr-base.cc Mon May 12 07:26:51 1997 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - -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 "error.h" -#include "oct-obj.h" -#include "ov.h" -#include "pt-mvr-base.h" - -// A base class for objects that can be return multiple values - -octave_value -tree_multi_val_ret::eval (bool /* print */) -{ - panic ("invalid evaluation of generic expression"); - return octave_value (); -} - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/ diff -r 0a2551ec7004 -r a51926eab51a src/pt-mvr-base.h --- a/src/pt-mvr-base.h Mon May 12 07:26:51 1997 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - -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 (octave_tree_mvr_h) -#define octave_tree_mvr_h 1 - -#if defined (__GNUG__) -#pragma interface -#endif - -class octave_value; -class octave_value_list; - -#include "pt-exp-base.h" - -// A base class for objects that can be return multiple values - -class -tree_multi_val_ret : public tree_expression -{ -public: - - tree_multi_val_ret (int l = -1, int c = -1) - : tree_expression (l, c) { } - - ~tree_multi_val_ret (void) { } - - bool is_multi_val_ret_expression (void) const - { return true; } - - octave_value eval (bool print = false); - - virtual octave_value_list - eval (bool print, int nargout, const octave_value_list& args) = 0; -}; - -#endif - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/ diff -r 0a2551ec7004 -r a51926eab51a src/pt-mvr.cc --- a/src/pt-mvr.cc Mon May 12 07:26:51 1997 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,369 +0,0 @@ -/* - -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 "str-vec.h" - -#include "error.h" -#include "oct-obj.h" -#include "pager.h" -#include "pt-const.h" -#include "pt-exp.h" -#include "pt-id.h" -#include "pt-indir.h" -#include "pt-misc.h" -#include "pt-mvr.h" -#include "pt-walk.h" - -// But first, some extra functions used by the tree classes. - -// Make sure that all arguments have values. - -static bool -all_args_defined (const octave_value_list& args) -{ - int nargin = args.length (); - - for (int i = 0; i < nargin; i++) - if (args(i).is_undefined ()) - return false; - - return true; -} - -// Used internally. - -octave_value -tree_oct_obj::eval (bool /* print */) -{ - return values(0); -} - -octave_value_list -tree_oct_obj::eval (bool, int, const octave_value_list&) -{ - return values; -} - -void -tree_oct_obj::accept (tree_walker& tw) -{ - tw.visit_oct_obj (*this); -} - -// Index expressions. - -tree_index_expression::tree_index_expression - (tree_identifier *i, int l = -1, int c = -1) - : tree_multi_val_ret (l, c), id (new tree_indirect_ref (i)), - list (0), arg_nm () -{ -} - -tree_index_expression::tree_index_expression - (tree_identifier *i, tree_argument_list *lst, int l = -1, int c = -1) - : tree_multi_val_ret (l, c), id (new tree_indirect_ref (i)), - list (lst), arg_nm () -{ - if (list) - arg_nm = list->get_arg_names (); -} - -tree_index_expression::~tree_index_expression (void) -{ - delete id; - delete list; -} - -string -tree_index_expression::name (void) const -{ - return id->name (); -} - -void -tree_index_expression::mark_for_possible_ans_assign (void) -{ - if (id) - id->mark_for_possible_ans_assign (); -} - -octave_value -tree_index_expression::eval (bool print) -{ - octave_value retval; - - if (error_state) - return retval; - - if (list) - { - // Extract the arguments into a simple vector. Don't pass null - // args. - - octave_value_list args = list->convert_to_const_vector (); - - args.stash_name_tags (arg_nm); - - if (error_state) - eval_error (); - else - { - if (all_args_defined (args)) - { - octave_value_list tmp = id->eval (print, 1, args); - - if (error_state) - eval_error (); - else if (tmp.length () > 0) - retval = tmp(0); - } - else - { - ::error ("undefined arguments found in index expression"); - eval_error (); - } - } - } - else - { - retval = id->eval (print); - - if (error_state) - eval_error (); - } - - return retval; -} - -octave_value_list -tree_index_expression::eval (bool print, int nargout, const octave_value_list&) -{ - octave_value_list retval; - - if (error_state) - return retval; - - if (list) - { - // Extract the arguments into a simple vector. Don't pass null - // args. - - octave_value_list tmp_args = list->convert_to_const_vector (); - - if (error_state) - eval_error (); - else - { - if (all_args_defined (tmp_args)) - { - retval = id->eval (print, nargout, tmp_args); - - if (error_state) - eval_error (); - } - else - { - ::error ("undefined arguments found in index expression"); - eval_error (); - } - } - } - else - { - octave_value_list tmp_args; - - retval = id->eval (print, nargout, tmp_args); - - if (error_state) - eval_error (); - } - - return retval; -} - -void -tree_index_expression::eval_error (void) -{ - if (error_state > 0) - { - int l = line (); - int c = column (); - const char *fmt; - if (l != -1 && c != -1) - { - if (list) - fmt = "evaluating index expression near line %d, column %d"; - else - fmt = "evaluating expression near line %d, column %d"; - - ::error (fmt, l, c); - } - else - { - if (list) - ::error ("evaluating index expression"); - else - ::error ("evaluating expression"); - } - } -} - -void -tree_index_expression::accept (tree_walker& tw) -{ - tw.visit_index_expression (*this); -} - -// Multi-valued assignmnt expressions. - -tree_multi_assignment_expression::~tree_multi_assignment_expression (void) -{ - if (! preserve) - delete lhs; - - delete rhs; -} - -octave_value -tree_multi_assignment_expression::eval (bool print) -{ - octave_value retval; - - if (error_state) - return retval; - - octave_value_list tmp_args; - octave_value_list result = eval (print, 1, tmp_args); - - if (result.length () > 0) - retval = result(0); - - return retval; -} - -octave_value_list -tree_multi_assignment_expression::eval (bool print, int nargout, - const octave_value_list&) -{ - if (error_state || ! rhs) - return octave_value_list (); - - nargout = lhs->length (); - octave_value_list tmp_args; - octave_value_list results = rhs->eval (false, nargout, tmp_args); - - if (error_state) - eval_error (); - - int ma_line = line (); - int ma_column = column (); - - if (results.length () > 0) - { - int i = 0; - - bool pad_after = false; - - for (Pix p = lhs->first (); p != 0; lhs->next (p)) - { - tree_index_expression *lhs_expr = lhs->operator () (p); - - if (i < nargout) - { - // XXX FIXME? XXX -- this is apparently the way Matlab - // works, but maybe we should have the option of - // skipping the assignment instead. - - tree_constant *tmp = 0; - if (results(i).is_undefined ()) - { - error ("element number %d undefined in return list", i+1); - eval_error (); - break; - } - else - tmp = new tree_constant (results(i)); - - tree_simple_assignment_expression tmp_expr - (lhs_expr, tmp, 1, 0, ma_line, ma_column); - - results(i) = tmp_expr.eval (); // May change - - if (error_state) - break; - - if (print && pad_after) - octave_stdout << "\n"; - - if (print) - results(i).print_with_name (octave_stdout, - lhs_expr->name (), 0); - - pad_after = true; - - i++; - } - else - { - tree_simple_assignment_expression tmp_expr - (lhs_expr, 0, 1, 0, ma_line, ma_column); - - tmp_expr.eval (); - } - } - - if (print && pad_after) - octave_stdout << "\n"; - } - - return results; -} - -void -tree_multi_assignment_expression::eval_error (void) -{ - if (error_state > 0) - ::error ("evaluating assignment expression near line %d, column %d", - line (), column ()); -} - -void -tree_multi_assignment_expression::accept (tree_walker& tw) -{ - tw.visit_multi_assignment_expression (*this); -} - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/ diff -r 0a2551ec7004 -r a51926eab51a src/pt-mvr.h --- a/src/pt-mvr.h Mon May 12 07:26:51 1997 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - -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 (octave_tree_mvr2_h) -#define octave_tree_mvr2_h 1 - -#if defined (__GNUG__) -#pragma interface -#endif - -class ostream; - -class tree_argument_list; -class tree_identifier; -class tree_index_expression; -class tree_indirect_ref; -class tree_return_list; - -class tree_walker; - -#include - -#include "str-vec.h" - -#include "pt-mvr-base.h" -#include "oct-obj.h" - -// Used internally. - -class -tree_oct_obj : public tree_multi_val_ret -{ -public: - - tree_oct_obj (int l = -1, int c = -1) : tree_multi_val_ret (l, c) { } - - tree_oct_obj (const octave_value_list& v, int l = -1, int c = -1) - : tree_multi_val_ret (l, c), values (v) { } - - ~tree_oct_obj (void) { } - - octave_value eval (bool print = false); - - octave_value_list - eval (bool print, int nargout, const octave_value_list& args); - - void accept (tree_walker& tw); - -private: - - const octave_value_list values; -}; - -// Index expressions. - -class -tree_index_expression : public tree_multi_val_ret -{ -public: - - tree_index_expression (int l = -1, int c = -1) - : tree_multi_val_ret (l, c), id (0), list (0) { } - - tree_index_expression (tree_identifier *i, int l = -1, int c = -1); - - tree_index_expression (tree_identifier *i, tree_argument_list *lst, - int l = -1, int c = -1); - - tree_index_expression (tree_indirect_ref *i, int l = -1, int c = -1) - : tree_multi_val_ret (l, c), id (i), list (0) { } - - tree_index_expression (tree_indirect_ref *i, tree_argument_list *lst, - int l = -1, int c = -1) - : tree_multi_val_ret (l, c), id (i), list (lst) { } - - ~tree_index_expression (void); - - bool is_index_expression (void) const - { return true; } - - tree_indirect_ref *ident (void) - { return id; } - - string name (void) const; - - tree_argument_list *arg_list (void) - { return list; } - - void mark_for_possible_ans_assign (void); - - octave_value eval (bool print = false); - - octave_value_list - eval (bool print, int nargout, const octave_value_list& args); - - void eval_error (void); - - void accept (tree_walker& tw); - -private: - - tree_indirect_ref *id; - - tree_argument_list *list; - - string_vector arg_nm; -}; - -// Multi-valued assignment expressions. - -class -tree_multi_assignment_expression : public tree_multi_val_ret -{ -public: - - tree_multi_assignment_expression (bool plhs = false, int l = -1, int c = -1) - : tree_multi_val_ret (l, c), preserve (plhs), lhs (0), rhs (0) { } - - tree_multi_assignment_expression (tree_return_list *lst, - tree_multi_val_ret *r, - bool plhs = false, - int l = -1, int c = -1) - : tree_multi_val_ret (l, c), preserve (plhs), lhs (lst), rhs (r) { } - - ~tree_multi_assignment_expression (void); - - octave_value eval (bool print = false); - - octave_value_list - eval (bool print, int nargout, const octave_value_list& args); - - bool is_assignment_expression (void) const - { return true; } - - void eval_error (void); - - tree_return_list *left_hand_side (void) { return lhs; } - - tree_multi_val_ret *right_hand_side (void) { return rhs; } - - void accept (tree_walker& tw); - -private: - - bool preserve; - tree_return_list *lhs; - tree_multi_val_ret *rhs; -}; - -#endif - -/* -;;; Local Variables: *** -;;; mode: C++ *** -;;; End: *** -*/