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 |
|
48 typedef void (*eval_fcn) (tree_decl_elt &, bool); |
|
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; |
|
70 }; |
|
71 |
|
72 class |
|
73 tree_decl_init_list : public SLList<tree_decl_elt *> |
|
74 { |
|
75 public: |
|
76 |
|
77 tree_decl_init_list (void) |
|
78 : SLList<tree_decl_elt *> () { } |
|
79 |
|
80 tree_decl_init_list (tree_decl_elt *t) |
|
81 : SLList<tree_decl_elt *> () { append (t); } |
|
82 |
|
83 ~tree_decl_init_list (void) |
|
84 { |
|
85 while (! empty ()) |
|
86 { |
|
87 tree_decl_elt *t = remove_front (); |
|
88 delete t; |
|
89 } |
|
90 } |
|
91 |
|
92 void eval (tree_decl_elt::eval_fcn, bool); |
|
93 |
|
94 void accept (tree_walker& tw); |
|
95 }; |
|
96 |
|
97 // Base class for declaration commands -- global, static, etc. |
|
98 |
|
99 class |
|
100 tree_decl_command : public tree_command |
|
101 { |
|
102 public: |
|
103 |
|
104 tree_decl_command (const string& n, int l = -1, int c = -1) |
|
105 : tree_command (l, c), cmd_name (n), initialized (false), init_list (0) { } |
|
106 |
|
107 tree_decl_command (const string& n, tree_decl_init_list *t, |
|
108 int l = -1, int c = -1) |
|
109 : tree_command (l, c), cmd_name (n), initialized (false), init_list (t) { } |
|
110 |
|
111 ~tree_decl_command (void); |
|
112 |
|
113 tree_decl_init_list *initializer_list (void) { return init_list; } |
|
114 |
|
115 void accept (tree_walker& tw); |
|
116 |
|
117 string name (void) { return cmd_name; } |
|
118 |
|
119 protected: |
|
120 |
|
121 // The name of this command -- global, static, etc. |
|
122 string cmd_name; |
|
123 |
|
124 // TRUE if this command has been evaluated. |
|
125 bool initialized; |
|
126 |
|
127 // The list of variables or initializers in this declaration command. |
|
128 tree_decl_init_list *init_list; |
|
129 }; |
|
130 |
|
131 // Global. |
|
132 |
|
133 class |
|
134 tree_global_command : public tree_decl_command |
|
135 { |
|
136 public: |
|
137 |
|
138 tree_global_command (int l = -1, int c = -1) |
|
139 : tree_decl_command ("global", l, c) { } |
|
140 |
|
141 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) |
|
142 : tree_decl_command ("global", t, l, c) { } |
|
143 |
|
144 ~tree_global_command (void) { } |
|
145 |
|
146 void eval (void); |
|
147 }; |
|
148 |
|
149 // Static. |
|
150 |
|
151 class |
|
152 tree_static_command : public tree_decl_command |
|
153 { |
|
154 public: |
|
155 |
|
156 tree_static_command (int l = -1, int c = -1) |
|
157 : tree_decl_command ("static", l, c) { } |
|
158 |
|
159 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1) |
|
160 : tree_decl_command ("static", t, l, c) { } |
|
161 |
|
162 ~tree_static_command (void) { } |
|
163 |
|
164 void eval (void); |
|
165 }; |
|
166 |
|
167 #endif |
|
168 |
|
169 /* |
|
170 ;;; Local Variables: *** |
|
171 ;;; mode: C++ *** |
|
172 ;;; End: *** |
|
173 */ |