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