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 |
3503
|
26 #include <iostream> |
2980
|
27 #include <string> |
|
28 |
|
29 class tree_argument_list; |
|
30 class tree_walker; |
|
31 |
|
32 class octave_value; |
|
33 class octave_value_list; |
|
34 class octave_lvalue; |
|
35 |
|
36 #include "ov.h" |
|
37 #include "pt-exp.h" |
|
38 |
|
39 // Simple assignment expressions. |
|
40 |
|
41 class |
|
42 tree_simple_assignment : public tree_expression |
|
43 { |
|
44 public: |
|
45 |
|
46 tree_simple_assignment (bool plhs = false, int l = -1, int c = -1, |
3527
|
47 octave_value::assign_op t = octave_value::op_asn_eq) |
2980
|
48 : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), etype (t) { } |
|
49 |
|
50 tree_simple_assignment (tree_expression *le, tree_expression *re, |
|
51 bool plhs = false, int l = -1, int c = -1, |
3527
|
52 octave_value::assign_op t = octave_value::op_asn_eq) |
2980
|
53 : tree_expression (l, c), lhs (le), rhs (re), preserve (plhs), |
|
54 etype (t) { } |
|
55 |
|
56 ~tree_simple_assignment (void); |
|
57 |
4267
|
58 bool has_magic_end (void) const { return (rhs && rhs->has_magic_end ()); } |
|
59 |
3933
|
60 bool rvalue_ok (void) const { return true; } |
2980
|
61 |
|
62 octave_value rvalue (void); |
|
63 |
|
64 octave_value_list rvalue (int nargout); |
|
65 |
3933
|
66 bool is_assignment_expression (void) const { return true; } |
2980
|
67 |
|
68 void eval_error (void); |
|
69 |
3523
|
70 std::string oper (void) const; |
2980
|
71 |
|
72 tree_expression *left_hand_side (void) { return lhs; } |
|
73 |
|
74 tree_expression *right_hand_side (void) { return rhs; } |
|
75 |
|
76 void accept (tree_walker& tw); |
|
77 |
|
78 private: |
|
79 |
|
80 void do_assign (octave_lvalue& ult, const octave_value_list& args, |
|
81 const octave_value& rhs_val); |
|
82 |
|
83 void do_assign (octave_lvalue& ult, const octave_value& rhs_val); |
|
84 |
|
85 // The left hand side of the assignment. |
|
86 tree_expression *lhs; |
|
87 |
|
88 // The right hand side of the assignment. |
|
89 tree_expression *rhs; |
|
90 |
|
91 // True if we should not delete the lhs. |
|
92 bool preserve; |
|
93 |
|
94 // True if this is an assignment to the built-in variable ans. |
|
95 bool ans_ass; |
|
96 |
|
97 // The type of the expression. |
|
98 octave_value::assign_op etype; |
2988
|
99 |
|
100 // No copying! |
|
101 |
2989
|
102 tree_simple_assignment (const tree_simple_assignment&); |
2988
|
103 |
2989
|
104 tree_simple_assignment& operator = (const tree_simple_assignment&); |
2980
|
105 }; |
|
106 |
|
107 // Multi-valued assignment expressions. |
|
108 |
|
109 class |
|
110 tree_multi_assignment : public tree_expression |
|
111 { |
|
112 public: |
|
113 |
3208
|
114 tree_multi_assignment (bool plhs = false, int l = -1, int c = -1, |
3527
|
115 octave_value::assign_op t = octave_value::op_asn_eq) |
3208
|
116 : tree_expression (l, c), lhs (0), rhs (0), preserve (plhs), etype(t) { } |
2980
|
117 |
|
118 tree_multi_assignment (tree_argument_list *lst, tree_expression *r, |
3208
|
119 bool plhs = false, int l = -1, int c = -1, |
3527
|
120 octave_value::assign_op t = octave_value::op_asn_eq) |
3208
|
121 : tree_expression (l, c), lhs (lst), rhs (r), preserve (plhs), |
|
122 etype (t) { } |
2980
|
123 |
|
124 ~tree_multi_assignment (void); |
|
125 |
4267
|
126 bool has_magic_end (void) const { return (rhs && rhs->has_magic_end ()); } |
|
127 |
3933
|
128 bool is_assignment_expression (void) const { return true; } |
2980
|
129 |
3933
|
130 bool rvalue_ok (void) const { return true; } |
2980
|
131 |
|
132 octave_value rvalue (void); |
|
133 |
|
134 octave_value_list rvalue (int nargout); |
|
135 |
|
136 void eval_error (void); |
|
137 |
3523
|
138 std::string oper (void) const; |
3208
|
139 |
2980
|
140 tree_argument_list *left_hand_side (void) { return lhs; } |
|
141 |
|
142 tree_expression *right_hand_side (void) { return rhs; } |
|
143 |
|
144 void accept (tree_walker& tw); |
|
145 |
|
146 private: |
|
147 |
3208
|
148 // The left hand side of the assignment. |
2980
|
149 tree_argument_list *lhs; |
3208
|
150 |
|
151 // The right hand side of the assignment. |
2980
|
152 tree_expression *rhs; |
2988
|
153 |
3208
|
154 // True if we should not delete the lhs. |
|
155 bool preserve; |
|
156 |
|
157 // The type of the expression. |
|
158 octave_value::assign_op etype; |
|
159 |
2988
|
160 // No copying! |
|
161 |
2989
|
162 tree_multi_assignment (const tree_multi_assignment&); |
2988
|
163 |
2989
|
164 tree_multi_assignment& operator = (const tree_multi_assignment&); |
2980
|
165 }; |
|
166 |
|
167 #endif |
|
168 |
|
169 /* |
|
170 ;;; Local Variables: *** |
|
171 ;;; mode: C++ *** |
|
172 ;;; End: *** |
|
173 */ |