pt-assign.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_tree_assign_h)
00024 #define octave_tree_assign_h 1
00025 
00026 #include <iosfwd>
00027 #include <string>
00028 
00029 class tree_argument_list;
00030 class tree_walker;
00031 
00032 class octave_value;
00033 class octave_value_list;
00034 class octave_lvalue;
00035 
00036 #include "ov.h"
00037 #include "pt-exp.h"
00038 #include "symtab.h"
00039 
00040 // Simple assignment expressions.
00041 
00042 class
00043 tree_simple_assignment : public tree_expression
00044 {
00045 public:
00046 
00047   tree_simple_assignment (bool plhs = false, int l = -1, int c = -1,
00048                           octave_value::assign_op t = octave_value::op_asn_eq)
00049     : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), ans_ass (),
00050       etype (t), first_execution (true) { }
00051 
00052   tree_simple_assignment (tree_expression *le, tree_expression *re,
00053                           bool plhs = false, int l = -1, int c = -1,
00054                           octave_value::assign_op t = octave_value::op_asn_eq);
00055 
00056   ~tree_simple_assignment (void);
00057 
00058   bool has_magic_end (void) const { return (rhs && rhs->has_magic_end ()); }
00059 
00060   bool rvalue_ok (void) const { return true; }
00061 
00062   octave_value rvalue1 (int nargout = 1);
00063 
00064   octave_value_list rvalue (int nargout);
00065 
00066   bool is_assignment_expression (void) const { return true; }
00067 
00068   std::string oper (void) const;
00069 
00070   tree_expression *left_hand_side (void) { return lhs; }
00071 
00072   tree_expression *right_hand_side (void) { return rhs; }
00073 
00074   tree_expression *dup (symbol_table::scope_id scope,
00075                         symbol_table::context_id context) const;
00076 
00077   void accept (tree_walker& tw);
00078 
00079   octave_value::assign_op op_type (void) const { return etype; }
00080 
00081 private:
00082 
00083   void do_assign (octave_lvalue& ult, const octave_value_list& args,
00084                   const octave_value& rhs_val);
00085 
00086   void do_assign (octave_lvalue& ult, const octave_value& rhs_val);
00087 
00088   // The left hand side of the assignment.
00089   tree_expression *lhs;
00090 
00091   // The right hand side of the assignment.
00092   tree_expression *rhs;
00093 
00094   // True if we should not delete the lhs.
00095   bool preserve;
00096 
00097   // True if this is an assignment to the automatic variable ans.
00098   bool ans_ass;
00099 
00100   // The type of the expression.
00101   octave_value::assign_op etype;
00102 
00103   // true only on first rvalue() call.
00104   bool first_execution;
00105 
00106   // No copying!
00107 
00108   tree_simple_assignment (const tree_simple_assignment&);
00109 
00110   tree_simple_assignment& operator = (const tree_simple_assignment&);
00111 };
00112 
00113 // Multi-valued assignment expressions.
00114 
00115 class
00116 tree_multi_assignment : public tree_expression
00117 {
00118 public:
00119 
00120   tree_multi_assignment (bool plhs = false, int l = -1, int c = -1)
00121     : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs),
00122       first_execution (true) { }
00123 
00124   tree_multi_assignment (tree_argument_list *lst, tree_expression *r,
00125                          bool plhs = false, int l = -1, int c = -1);
00126 
00127   ~tree_multi_assignment (void);
00128 
00129   bool has_magic_end (void) const { return (rhs && rhs->has_magic_end ()); }
00130 
00131   bool is_assignment_expression (void) const { return true; }
00132 
00133   bool rvalue_ok (void) const { return true; }
00134 
00135   octave_value rvalue1 (int nargout = 1);
00136 
00137   octave_value_list rvalue (int nargout);
00138 
00139   std::string oper (void) const;
00140 
00141   tree_argument_list *left_hand_side (void) { return lhs; }
00142 
00143   tree_expression *right_hand_side (void) { return rhs; }
00144 
00145   tree_expression *dup (symbol_table::scope_id scope,
00146                         symbol_table::context_id context) const;
00147 
00148   void accept (tree_walker& tw);
00149 
00150   octave_value::assign_op op_type (void) const { return octave_value::op_asn_eq; }
00151 
00152 private:
00153 
00154   // The left hand side of the assignment.
00155   tree_argument_list *lhs;
00156 
00157   // The right hand side of the assignment.
00158   tree_expression *rhs;
00159 
00160   // True if we should not delete the lhs.
00161   bool preserve;
00162 
00163   // true only on first rvalue() call.
00164   bool first_execution;
00165 
00166   // No copying!
00167 
00168   tree_multi_assignment (const tree_multi_assignment&);
00169 
00170   tree_multi_assignment& operator = (const tree_multi_assignment&);
00171 };
00172 
00173 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines