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