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