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