2980
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_assign_h) |
|
24 #define octave_tree_assign_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
3503
|
30 #include <iostream> |
2980
|
31 #include <string> |
|
32 |
|
33 class tree_argument_list; |
|
34 class tree_walker; |
|
35 |
|
36 class octave_value; |
|
37 class octave_value_list; |
|
38 class octave_lvalue; |
|
39 |
|
40 #include "ov.h" |
|
41 #include "pt-exp.h" |
|
42 |
|
43 // Simple assignment expressions. |
|
44 |
|
45 class |
|
46 tree_simple_assignment : public tree_expression |
|
47 { |
|
48 public: |
|
49 |
|
50 tree_simple_assignment (bool plhs = false, int l = -1, int c = -1, |
3527
|
51 octave_value::assign_op t = octave_value::op_asn_eq) |
2980
|
52 : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), etype (t) { } |
|
53 |
|
54 tree_simple_assignment (tree_expression *le, tree_expression *re, |
|
55 bool plhs = false, int l = -1, int c = -1, |
3527
|
56 octave_value::assign_op t = octave_value::op_asn_eq) |
2980
|
57 : tree_expression (l, c), lhs (le), rhs (re), preserve (plhs), |
|
58 etype (t) { } |
|
59 |
|
60 ~tree_simple_assignment (void); |
|
61 |
|
62 bool rvalue_ok (void) const |
|
63 { return true; } |
|
64 |
|
65 octave_value rvalue (void); |
|
66 |
|
67 octave_value_list rvalue (int nargout); |
|
68 |
|
69 bool is_assignment_expression (void) const |
|
70 { return true; } |
|
71 |
|
72 void eval_error (void); |
|
73 |
3523
|
74 std::string oper (void) const; |
2980
|
75 |
|
76 tree_expression *left_hand_side (void) { return lhs; } |
|
77 |
|
78 tree_expression *right_hand_side (void) { return rhs; } |
|
79 |
|
80 void accept (tree_walker& tw); |
|
81 |
|
82 private: |
|
83 |
|
84 void do_assign (octave_lvalue& ult, const octave_value_list& args, |
|
85 const octave_value& rhs_val); |
|
86 |
|
87 void do_assign (octave_lvalue& ult, const octave_value& rhs_val); |
|
88 |
|
89 // The left hand side of the assignment. |
|
90 tree_expression *lhs; |
|
91 |
|
92 // The right hand side of the assignment. |
|
93 tree_expression *rhs; |
|
94 |
|
95 // True if we should not delete the lhs. |
|
96 bool preserve; |
|
97 |
|
98 // True if this is an assignment to the built-in variable ans. |
|
99 bool ans_ass; |
|
100 |
|
101 // The type of the expression. |
|
102 octave_value::assign_op etype; |
2988
|
103 |
|
104 // No copying! |
|
105 |
2989
|
106 tree_simple_assignment (const tree_simple_assignment&); |
2988
|
107 |
2989
|
108 tree_simple_assignment& operator = (const tree_simple_assignment&); |
2980
|
109 }; |
|
110 |
|
111 // Multi-valued assignment expressions. |
|
112 |
|
113 class |
|
114 tree_multi_assignment : public tree_expression |
|
115 { |
|
116 public: |
|
117 |
3208
|
118 tree_multi_assignment (bool plhs = false, int l = -1, int c = -1, |
3527
|
119 octave_value::assign_op t = octave_value::op_asn_eq) |
3208
|
120 : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), etype(t) { } |
2980
|
121 |
|
122 tree_multi_assignment (tree_argument_list *lst, tree_expression *r, |
3208
|
123 bool plhs = false, int l = -1, int c = -1, |
3527
|
124 octave_value::assign_op t = octave_value::op_asn_eq) |
3208
|
125 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), |
|
126 etype (t) { } |
2980
|
127 |
|
128 ~tree_multi_assignment (void); |
|
129 |
|
130 bool is_assignment_expression (void) const |
|
131 { return true; } |
|
132 |
|
133 bool rvalue_ok (void) const |
|
134 { return true; } |
|
135 |
|
136 octave_value rvalue (void); |
|
137 |
|
138 octave_value_list rvalue (int nargout); |
|
139 |
|
140 void eval_error (void); |
|
141 |
3523
|
142 std::string oper (void) const; |
3208
|
143 |
2980
|
144 tree_argument_list *left_hand_side (void) { return lhs; } |
|
145 |
|
146 tree_expression *right_hand_side (void) { return rhs; } |
|
147 |
|
148 void accept (tree_walker& tw); |
|
149 |
|
150 private: |
|
151 |
3208
|
152 // The left hand side of the assignment. |
2980
|
153 tree_argument_list *lhs; |
3208
|
154 |
|
155 // The right hand side of the assignment. |
2980
|
156 tree_expression *rhs; |
2988
|
157 |
3208
|
158 // True if we should not delete the lhs. |
|
159 bool preserve; |
|
160 |
|
161 // The type of the expression. |
|
162 octave_value::assign_op etype; |
|
163 |
2988
|
164 // No copying! |
|
165 |
2989
|
166 tree_multi_assignment (const tree_multi_assignment&); |
2988
|
167 |
2989
|
168 tree_multi_assignment& operator = (const tree_multi_assignment&); |
2980
|
169 }; |
|
170 |
|
171 #endif |
|
172 |
|
173 /* |
|
174 ;;; Local Variables: *** |
|
175 ;;; mode: C++ *** |
|
176 ;;; End: *** |
|
177 */ |