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