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 |
|
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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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" |
2982
|
35 #include "pt-cmd.h" |
|
36 |
|
37 // List of expressions that make up a declaration statement. |
|
38 |
|
39 class |
|
40 tree_decl_elt |
|
41 { |
|
42 public: |
|
43 |
2989
|
44 typedef void (*eval_fcn) (tree_decl_elt &); |
2982
|
45 |
|
46 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) |
|
47 : id (i), expr (e) { } |
|
48 |
|
49 ~tree_decl_elt (void); |
|
50 |
|
51 void eval (void); |
|
52 |
|
53 tree_identifier *ident (void) { return id; } |
|
54 |
|
55 tree_expression *expression (void) { return expr; } |
|
56 |
5861
|
57 tree_decl_elt *dup (symbol_table *sym_tab); |
|
58 |
2982
|
59 void accept (tree_walker& tw); |
|
60 |
|
61 private: |
|
62 |
|
63 // An identifier to tag with the declared property. |
|
64 tree_identifier *id; |
|
65 |
|
66 // An initializer expression (may be zero); |
|
67 tree_expression *expr; |
2988
|
68 |
|
69 // No copying! |
|
70 |
|
71 tree_decl_elt (const tree_decl_elt&); |
|
72 |
|
73 tree_decl_elt& operator = (const tree_decl_elt&); |
2982
|
74 }; |
|
75 |
|
76 class |
4219
|
77 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982
|
78 { |
|
79 public: |
|
80 |
4219
|
81 tree_decl_init_list (void) { } |
2982
|
82 |
4219
|
83 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982
|
84 |
|
85 ~tree_decl_init_list (void) |
|
86 { |
4219
|
87 while (! empty ()) |
2982
|
88 { |
4219
|
89 iterator p = begin (); |
|
90 delete *p; |
|
91 erase (p); |
2982
|
92 } |
|
93 } |
|
94 |
2989
|
95 void eval (tree_decl_elt::eval_fcn); |
2982
|
96 |
5861
|
97 tree_decl_init_list *dup (symbol_table *sym_tab); |
|
98 |
2982
|
99 void accept (tree_walker& tw); |
2988
|
100 |
|
101 private: |
|
102 |
|
103 // No copying! |
|
104 |
|
105 tree_decl_init_list (const tree_decl_init_list&); |
|
106 |
|
107 tree_decl_init_list& operator = (const tree_decl_init_list&); |
2982
|
108 }; |
|
109 |
|
110 // Base class for declaration commands -- global, static, etc. |
|
111 |
|
112 class |
|
113 tree_decl_command : public tree_command |
|
114 { |
|
115 public: |
|
116 |
3523
|
117 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
2982
|
118 : tree_command (l, c), cmd_name (n), initialized (false), init_list (0) { } |
|
119 |
3523
|
120 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
2982
|
121 int l = -1, int c = -1) |
|
122 : tree_command (l, c), cmd_name (n), initialized (false), init_list (t) { } |
|
123 |
|
124 ~tree_decl_command (void); |
|
125 |
|
126 tree_decl_init_list *initializer_list (void) { return init_list; } |
|
127 |
|
128 void accept (tree_walker& tw); |
|
129 |
3523
|
130 std::string name (void) { return cmd_name; } |
2982
|
131 |
|
132 protected: |
|
133 |
|
134 // The name of this command -- global, static, etc. |
3523
|
135 std::string cmd_name; |
2982
|
136 |
|
137 // TRUE if this command has been evaluated. |
|
138 bool initialized; |
|
139 |
|
140 // The list of variables or initializers in this declaration command. |
|
141 tree_decl_init_list *init_list; |
2988
|
142 |
|
143 private: |
|
144 |
|
145 // No copying! |
|
146 |
|
147 tree_decl_command (const tree_decl_command&); |
|
148 |
|
149 tree_decl_command& operator = (const tree_decl_command&); |
2982
|
150 }; |
|
151 |
|
152 // Global. |
|
153 |
|
154 class |
|
155 tree_global_command : public tree_decl_command |
|
156 { |
|
157 public: |
|
158 |
|
159 tree_global_command (int l = -1, int c = -1) |
|
160 : tree_decl_command ("global", l, c) { } |
|
161 |
|
162 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) |
|
163 : tree_decl_command ("global", t, l, c) { } |
|
164 |
|
165 ~tree_global_command (void) { } |
|
166 |
|
167 void eval (void); |
2988
|
168 |
5861
|
169 tree_command *dup (symbol_table *sym_tab); |
|
170 |
2988
|
171 private: |
|
172 |
2989
|
173 static void do_init (tree_decl_elt& elt); |
|
174 |
2988
|
175 // No copying! |
|
176 |
|
177 tree_global_command (const tree_global_command&); |
|
178 |
|
179 tree_global_command& operator = (const tree_global_command&); |
2982
|
180 }; |
|
181 |
|
182 // Static. |
|
183 |
|
184 class |
|
185 tree_static_command : public tree_decl_command |
|
186 { |
|
187 public: |
|
188 |
|
189 tree_static_command (int l = -1, int c = -1) |
|
190 : tree_decl_command ("static", l, c) { } |
|
191 |
|
192 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1) |
|
193 : tree_decl_command ("static", t, l, c) { } |
|
194 |
|
195 ~tree_static_command (void) { } |
|
196 |
|
197 void eval (void); |
2988
|
198 |
5861
|
199 tree_command *dup (symbol_table *sym_tab); |
|
200 |
2988
|
201 private: |
|
202 |
2989
|
203 static void do_init (tree_decl_elt& elt); |
|
204 |
2988
|
205 // No copying! |
|
206 |
|
207 tree_static_command (const tree_static_command&); |
|
208 |
|
209 tree_static_command& operator = (const tree_static_command&); |
2982
|
210 }; |
|
211 |
|
212 #endif |
|
213 |
|
214 /* |
|
215 ;;; Local Variables: *** |
|
216 ;;; mode: C++ *** |
|
217 ;;; End: *** |
|
218 */ |