2982
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
2982
|
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. |
2982
|
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/>. |
2982
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_tree_decl_h) |
|
25 #define octave_tree_decl_h 1 |
|
26 |
|
27 class tree_expression; |
|
28 class tree_identifier; |
|
29 |
|
30 class tree_walker; |
|
31 |
|
32 #include <string> |
|
33 |
4219
|
34 #include "base-list.h" |
6215
|
35 #include "oct-lvalue.h" |
2982
|
36 #include "pt-cmd.h" |
6215
|
37 #include "pt-id.h" |
2982
|
38 |
|
39 // List of expressions that make up a declaration statement. |
|
40 |
|
41 class |
|
42 tree_decl_elt |
|
43 { |
|
44 public: |
|
45 |
2989
|
46 typedef void (*eval_fcn) (tree_decl_elt &); |
2982
|
47 |
|
48 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) |
|
49 : id (i), expr (e) { } |
|
50 |
|
51 ~tree_decl_elt (void); |
|
52 |
6215
|
53 bool eval (void); |
|
54 |
|
55 bool is_defined (void) { return id ? id->is_defined () : false; } |
|
56 |
|
57 void mark_as_formal_parameter (void) |
|
58 { |
|
59 if (id) |
|
60 id->mark_as_formal_parameter (); |
|
61 } |
|
62 |
|
63 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } |
|
64 |
|
65 octave_value rvalue (void) { return id ? id->rvalue () : octave_value (); } |
|
66 |
|
67 octave_value_list rvalue (int nargout) |
|
68 { |
|
69 return id ? id->rvalue (nargout) : octave_value_list (); |
|
70 } |
|
71 |
|
72 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } |
2982
|
73 |
|
74 tree_identifier *ident (void) { return id; } |
|
75 |
|
76 tree_expression *expression (void) { return expr; } |
|
77 |
5861
|
78 tree_decl_elt *dup (symbol_table *sym_tab); |
|
79 |
2982
|
80 void accept (tree_walker& tw); |
|
81 |
|
82 private: |
|
83 |
|
84 // An identifier to tag with the declared property. |
|
85 tree_identifier *id; |
|
86 |
|
87 // An initializer expression (may be zero); |
|
88 tree_expression *expr; |
2988
|
89 |
|
90 // No copying! |
|
91 |
|
92 tree_decl_elt (const tree_decl_elt&); |
|
93 |
|
94 tree_decl_elt& operator = (const tree_decl_elt&); |
2982
|
95 }; |
|
96 |
|
97 class |
4219
|
98 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982
|
99 { |
|
100 public: |
|
101 |
4219
|
102 tree_decl_init_list (void) { } |
2982
|
103 |
4219
|
104 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982
|
105 |
|
106 ~tree_decl_init_list (void) |
|
107 { |
4219
|
108 while (! empty ()) |
2982
|
109 { |
4219
|
110 iterator p = begin (); |
|
111 delete *p; |
|
112 erase (p); |
2982
|
113 } |
|
114 } |
|
115 |
2989
|
116 void eval (tree_decl_elt::eval_fcn); |
2982
|
117 |
5861
|
118 tree_decl_init_list *dup (symbol_table *sym_tab); |
|
119 |
2982
|
120 void accept (tree_walker& tw); |
2988
|
121 |
|
122 private: |
|
123 |
|
124 // No copying! |
|
125 |
|
126 tree_decl_init_list (const tree_decl_init_list&); |
|
127 |
|
128 tree_decl_init_list& operator = (const tree_decl_init_list&); |
2982
|
129 }; |
|
130 |
|
131 // Base class for declaration commands -- global, static, etc. |
|
132 |
|
133 class |
|
134 tree_decl_command : public tree_command |
|
135 { |
|
136 public: |
|
137 |
3523
|
138 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
2982
|
139 : tree_command (l, c), cmd_name (n), initialized (false), init_list (0) { } |
|
140 |
3523
|
141 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
2982
|
142 int l = -1, int c = -1) |
|
143 : tree_command (l, c), cmd_name (n), initialized (false), init_list (t) { } |
|
144 |
|
145 ~tree_decl_command (void); |
|
146 |
|
147 tree_decl_init_list *initializer_list (void) { return init_list; } |
|
148 |
|
149 void accept (tree_walker& tw); |
|
150 |
3523
|
151 std::string name (void) { return cmd_name; } |
2982
|
152 |
|
153 protected: |
|
154 |
|
155 // The name of this command -- global, static, etc. |
3523
|
156 std::string cmd_name; |
2982
|
157 |
|
158 // TRUE if this command has been evaluated. |
|
159 bool initialized; |
|
160 |
|
161 // The list of variables or initializers in this declaration command. |
|
162 tree_decl_init_list *init_list; |
2988
|
163 |
|
164 private: |
|
165 |
|
166 // No copying! |
|
167 |
|
168 tree_decl_command (const tree_decl_command&); |
|
169 |
|
170 tree_decl_command& operator = (const tree_decl_command&); |
2982
|
171 }; |
|
172 |
|
173 // Global. |
|
174 |
|
175 class |
|
176 tree_global_command : public tree_decl_command |
|
177 { |
|
178 public: |
|
179 |
|
180 tree_global_command (int l = -1, int c = -1) |
|
181 : tree_decl_command ("global", l, c) { } |
|
182 |
|
183 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) |
|
184 : tree_decl_command ("global", t, l, c) { } |
|
185 |
|
186 ~tree_global_command (void) { } |
|
187 |
|
188 void eval (void); |
2988
|
189 |
5861
|
190 tree_command *dup (symbol_table *sym_tab); |
|
191 |
2988
|
192 private: |
|
193 |
2989
|
194 static void do_init (tree_decl_elt& elt); |
|
195 |
2988
|
196 // No copying! |
|
197 |
|
198 tree_global_command (const tree_global_command&); |
|
199 |
|
200 tree_global_command& operator = (const tree_global_command&); |
2982
|
201 }; |
|
202 |
|
203 // Static. |
|
204 |
|
205 class |
|
206 tree_static_command : public tree_decl_command |
|
207 { |
|
208 public: |
|
209 |
|
210 tree_static_command (int l = -1, int c = -1) |
|
211 : tree_decl_command ("static", l, c) { } |
|
212 |
|
213 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1) |
|
214 : tree_decl_command ("static", t, l, c) { } |
|
215 |
|
216 ~tree_static_command (void) { } |
|
217 |
|
218 void eval (void); |
2988
|
219 |
5861
|
220 tree_command *dup (symbol_table *sym_tab); |
|
221 |
2988
|
222 private: |
|
223 |
2989
|
224 static void do_init (tree_decl_elt& elt); |
|
225 |
2988
|
226 // No copying! |
|
227 |
|
228 tree_static_command (const tree_static_command&); |
|
229 |
|
230 tree_static_command& operator = (const tree_static_command&); |
2982
|
231 }; |
|
232 |
|
233 #endif |
|
234 |
|
235 /* |
|
236 ;;; Local Variables: *** |
|
237 ;;; mode: C++ *** |
|
238 ;;; End: *** |
|
239 */ |