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" |
7336
|
38 #include "symtab.h" |
2982
|
39 |
|
40 // List of expressions that make up a declaration statement. |
|
41 |
|
42 class |
|
43 tree_decl_elt |
|
44 { |
|
45 public: |
|
46 |
2989
|
47 typedef void (*eval_fcn) (tree_decl_elt &); |
2982
|
48 |
|
49 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) |
|
50 : id (i), expr (e) { } |
|
51 |
|
52 ~tree_decl_elt (void); |
|
53 |
6215
|
54 bool eval (void); |
|
55 |
|
56 bool is_defined (void) { return id ? id->is_defined () : false; } |
|
57 |
7336
|
58 bool is_variable (void) { return id ? id->is_variable () : false; } |
|
59 |
6215
|
60 void mark_as_formal_parameter (void) |
|
61 { |
|
62 if (id) |
|
63 id->mark_as_formal_parameter (); |
|
64 } |
|
65 |
|
66 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } |
|
67 |
|
68 octave_value rvalue (void) { return id ? id->rvalue () : octave_value (); } |
|
69 |
|
70 octave_value_list rvalue (int nargout) |
|
71 { |
|
72 return id ? id->rvalue (nargout) : octave_value_list (); |
|
73 } |
|
74 |
|
75 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } |
2982
|
76 |
|
77 tree_identifier *ident (void) { return id; } |
|
78 |
|
79 tree_expression *expression (void) { return expr; } |
|
80 |
7336
|
81 tree_decl_elt *dup (symbol_table::scope_id scope); |
5861
|
82 |
2982
|
83 void accept (tree_walker& tw); |
|
84 |
|
85 private: |
|
86 |
|
87 // An identifier to tag with the declared property. |
|
88 tree_identifier *id; |
|
89 |
|
90 // An initializer expression (may be zero); |
|
91 tree_expression *expr; |
2988
|
92 |
|
93 // No copying! |
|
94 |
|
95 tree_decl_elt (const tree_decl_elt&); |
|
96 |
|
97 tree_decl_elt& operator = (const tree_decl_elt&); |
2982
|
98 }; |
|
99 |
|
100 class |
4219
|
101 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982
|
102 { |
|
103 public: |
|
104 |
4219
|
105 tree_decl_init_list (void) { } |
2982
|
106 |
4219
|
107 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982
|
108 |
|
109 ~tree_decl_init_list (void) |
|
110 { |
4219
|
111 while (! empty ()) |
2982
|
112 { |
4219
|
113 iterator p = begin (); |
|
114 delete *p; |
|
115 erase (p); |
2982
|
116 } |
|
117 } |
|
118 |
2989
|
119 void eval (tree_decl_elt::eval_fcn); |
2982
|
120 |
7336
|
121 tree_decl_init_list *dup (symbol_table::scope_id scope); |
5861
|
122 |
2982
|
123 void accept (tree_walker& tw); |
2988
|
124 |
|
125 private: |
|
126 |
|
127 // No copying! |
|
128 |
|
129 tree_decl_init_list (const tree_decl_init_list&); |
|
130 |
|
131 tree_decl_init_list& operator = (const tree_decl_init_list&); |
2982
|
132 }; |
|
133 |
|
134 // Base class for declaration commands -- global, static, etc. |
|
135 |
|
136 class |
|
137 tree_decl_command : public tree_command |
|
138 { |
|
139 public: |
|
140 |
3523
|
141 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
7336
|
142 : tree_command (l, c), cmd_name (n), init_list (0) { } |
2982
|
143 |
3523
|
144 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
2982
|
145 int l = -1, int c = -1) |
7336
|
146 : tree_command (l, c), cmd_name (n), init_list (t) { } |
2982
|
147 |
|
148 ~tree_decl_command (void); |
|
149 |
|
150 tree_decl_init_list *initializer_list (void) { return init_list; } |
|
151 |
|
152 void accept (tree_walker& tw); |
|
153 |
3523
|
154 std::string name (void) { return cmd_name; } |
2982
|
155 |
|
156 protected: |
|
157 |
|
158 // The name of this command -- global, static, etc. |
3523
|
159 std::string cmd_name; |
2982
|
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 |
7336
|
190 tree_command *dup (symbol_table::scope_id scope); |
5861
|
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 |
7336
|
220 tree_command *dup (symbol_table::scope_id scope); |
5861
|
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 */ |