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