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