1 | /* |
---|
2 | * This file is part of the Cforall project |
---|
3 | * |
---|
4 | * $Id: Declaration.h,v 1.22 2005/08/29 20:59:25 rcbilson Exp $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef DECLARATION_H |
---|
9 | #define DECLARATION_H |
---|
10 | |
---|
11 | #include "SynTree.h" |
---|
12 | #include "Visitor.h" |
---|
13 | #include "Mutator.h" |
---|
14 | #include "Parser/LinkageSpec.h" |
---|
15 | |
---|
16 | |
---|
17 | class Declaration |
---|
18 | { |
---|
19 | public: |
---|
20 | enum StorageClass |
---|
21 | { |
---|
22 | NoStorageClass, |
---|
23 | Auto, |
---|
24 | Static, |
---|
25 | Extern, |
---|
26 | Register, |
---|
27 | Fortran |
---|
28 | }; |
---|
29 | |
---|
30 | Declaration( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); |
---|
31 | Declaration( const Declaration &other ); |
---|
32 | virtual ~Declaration(); |
---|
33 | |
---|
34 | std::string get_name() const { return name; } |
---|
35 | void set_name( std::string newValue ) { name = newValue; } |
---|
36 | StorageClass get_storageClass() const { return storageClass; } |
---|
37 | void set_storageClass( StorageClass newValue ) { storageClass = newValue; } |
---|
38 | LinkageSpec::Type get_linkage() const { return linkage; } |
---|
39 | void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; } |
---|
40 | UniqueId get_uniqueId() const { return uniqueId; } |
---|
41 | |
---|
42 | void fixUniqueId( void ); |
---|
43 | virtual Declaration *clone() const = 0; |
---|
44 | virtual void accept( Visitor &v ) = 0; |
---|
45 | virtual Declaration *acceptMutator( Mutator &m ) = 0; |
---|
46 | virtual void print( std::ostream &os, int indent = 0 ) const = 0; |
---|
47 | virtual void printShort( std::ostream &os, int indent = 0 ) const = 0; |
---|
48 | |
---|
49 | static const char* storageClassName[]; |
---|
50 | |
---|
51 | static void dumpIds( std::ostream &os ); |
---|
52 | static Declaration *declFromId( UniqueId id ); |
---|
53 | |
---|
54 | private: |
---|
55 | std::string name; |
---|
56 | StorageClass storageClass; |
---|
57 | LinkageSpec::Type linkage; |
---|
58 | UniqueId uniqueId; |
---|
59 | }; |
---|
60 | |
---|
61 | class DeclarationWithType : public Declaration |
---|
62 | { |
---|
63 | public: |
---|
64 | DeclarationWithType( const std::string &name, StorageClass sc, LinkageSpec::Type linkage ); |
---|
65 | DeclarationWithType( const DeclarationWithType &other ); |
---|
66 | virtual ~DeclarationWithType(); |
---|
67 | |
---|
68 | std::string get_mangleName() const { return mangleName; } |
---|
69 | void set_mangleName( std::string newValue ) { mangleName = newValue; } |
---|
70 | |
---|
71 | virtual DeclarationWithType *clone() const = 0; |
---|
72 | virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; |
---|
73 | |
---|
74 | virtual Type *get_type() const = 0; |
---|
75 | virtual void set_type(Type *) = 0; |
---|
76 | |
---|
77 | private: |
---|
78 | // this represents the type with all types and typedefs expanded |
---|
79 | // it is generated by SymTab::Validate::Pass2 |
---|
80 | std::string mangleName; |
---|
81 | }; |
---|
82 | |
---|
83 | class ObjectDecl : public DeclarationWithType |
---|
84 | { |
---|
85 | typedef DeclarationWithType Parent; |
---|
86 | |
---|
87 | public: |
---|
88 | ObjectDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init ); |
---|
89 | ObjectDecl( const ObjectDecl &other ); |
---|
90 | virtual ~ObjectDecl(); |
---|
91 | |
---|
92 | virtual Type *get_type() const { return type; } |
---|
93 | virtual void set_type(Type *newType) { type = newType; } |
---|
94 | |
---|
95 | Initializer *get_init() const { return init; } |
---|
96 | void set_init( Initializer *newValue ) { init = newValue; } |
---|
97 | Expression *get_bitfieldWidth() const { return bitfieldWidth; } |
---|
98 | void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; } |
---|
99 | |
---|
100 | virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); } |
---|
101 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
102 | virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
103 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
104 | virtual void printShort( std::ostream &os, int indent = 0 ) const; |
---|
105 | |
---|
106 | private: |
---|
107 | Type *type; |
---|
108 | Initializer *init; |
---|
109 | Expression *bitfieldWidth; |
---|
110 | }; |
---|
111 | |
---|
112 | class FunctionDecl : public DeclarationWithType |
---|
113 | { |
---|
114 | typedef DeclarationWithType Parent; |
---|
115 | |
---|
116 | public: |
---|
117 | FunctionDecl( const std::string &name, StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline ); |
---|
118 | FunctionDecl( const FunctionDecl &other ); |
---|
119 | virtual ~FunctionDecl(); |
---|
120 | |
---|
121 | Type *get_type() const; |
---|
122 | virtual void set_type(Type *); |
---|
123 | |
---|
124 | FunctionType *get_functionType() const { return type; } |
---|
125 | void set_functionType( FunctionType *newValue ) { type = newValue; } |
---|
126 | CompoundStmt *get_statements() const { return statements; } |
---|
127 | void set_statements( CompoundStmt *newValue ) { statements = newValue; } |
---|
128 | bool get_isInline() const { return isInline; } |
---|
129 | void set_isInline( bool newValue ) { isInline = newValue; } |
---|
130 | std::list< std::string >& get_oldIdents() { return oldIdents; } |
---|
131 | std::list< Declaration* >& get_oldDecls() { return oldDecls; } |
---|
132 | |
---|
133 | virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } |
---|
134 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
135 | virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
136 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
137 | virtual void printShort( std::ostream &os, int indent = 0 ) const; |
---|
138 | |
---|
139 | private: |
---|
140 | FunctionType *type; |
---|
141 | CompoundStmt *statements; |
---|
142 | bool isInline; |
---|
143 | std::list< std::string > oldIdents; |
---|
144 | std::list< Declaration* > oldDecls; |
---|
145 | }; |
---|
146 | |
---|
147 | class NamedTypeDecl : public Declaration |
---|
148 | { |
---|
149 | typedef Declaration Parent; |
---|
150 | |
---|
151 | public: |
---|
152 | NamedTypeDecl( const std::string &name, StorageClass sc, Type *type ); |
---|
153 | NamedTypeDecl( const TypeDecl &other ); |
---|
154 | virtual ~NamedTypeDecl(); |
---|
155 | |
---|
156 | Type *get_base() const { return base; } |
---|
157 | void set_base( Type *newValue ) { base = newValue; } |
---|
158 | std::list< TypeDecl* >& get_parameters() { return parameters; } |
---|
159 | std::list< DeclarationWithType* >& get_assertions() { return assertions; } |
---|
160 | |
---|
161 | virtual NamedTypeDecl *clone() const = 0; |
---|
162 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
163 | virtual void printShort( std::ostream &os, int indent = 0 ) const; |
---|
164 | |
---|
165 | protected: |
---|
166 | virtual std::string typeString() const = 0; |
---|
167 | |
---|
168 | private: |
---|
169 | Type *base; |
---|
170 | std::list< TypeDecl* > parameters; |
---|
171 | std::list< DeclarationWithType* > assertions; |
---|
172 | }; |
---|
173 | |
---|
174 | class TypeDecl : public NamedTypeDecl |
---|
175 | { |
---|
176 | typedef NamedTypeDecl Parent; |
---|
177 | |
---|
178 | public: |
---|
179 | enum Kind { Any, Dtype, Ftype }; |
---|
180 | |
---|
181 | TypeDecl( const std::string &name, StorageClass sc, Type *type, Kind kind ); |
---|
182 | TypeDecl( const TypeDecl &other ); |
---|
183 | |
---|
184 | Kind get_kind() const { return kind; } |
---|
185 | |
---|
186 | virtual TypeDecl *clone() const { return new TypeDecl( *this ); } |
---|
187 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
188 | virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
189 | |
---|
190 | private: |
---|
191 | virtual std::string typeString() const; |
---|
192 | Kind kind; |
---|
193 | }; |
---|
194 | |
---|
195 | class TypedefDecl : public NamedTypeDecl |
---|
196 | { |
---|
197 | typedef NamedTypeDecl Parent; |
---|
198 | |
---|
199 | public: |
---|
200 | TypedefDecl( const std::string &name, StorageClass sc, Type *type ) : Parent( name, sc, type ) {} |
---|
201 | TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} |
---|
202 | |
---|
203 | virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); } |
---|
204 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
205 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
206 | |
---|
207 | private: |
---|
208 | virtual std::string typeString() const; |
---|
209 | }; |
---|
210 | |
---|
211 | class AggregateDecl : public Declaration |
---|
212 | { |
---|
213 | typedef Declaration Parent; |
---|
214 | |
---|
215 | public: |
---|
216 | AggregateDecl( const std::string &name ); |
---|
217 | AggregateDecl( const AggregateDecl &other ); |
---|
218 | virtual ~AggregateDecl(); |
---|
219 | |
---|
220 | std::list<Declaration*>& get_members() { return members; } |
---|
221 | std::list<TypeDecl*>& get_parameters() { return parameters; } |
---|
222 | |
---|
223 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
224 | virtual void printShort( std::ostream &os, int indent = 0 ) const; |
---|
225 | |
---|
226 | protected: |
---|
227 | virtual std::string typeString() const = 0; |
---|
228 | |
---|
229 | private: |
---|
230 | std::list<Declaration*> members; |
---|
231 | std::list<TypeDecl*> parameters; |
---|
232 | }; |
---|
233 | |
---|
234 | class StructDecl : public AggregateDecl |
---|
235 | { |
---|
236 | typedef AggregateDecl Parent; |
---|
237 | |
---|
238 | public: |
---|
239 | StructDecl( const std::string &name ) : Parent( name ) {} |
---|
240 | StructDecl( const StructDecl &other ) : Parent( other ) {} |
---|
241 | |
---|
242 | virtual StructDecl *clone() const { return new StructDecl( *this ); } |
---|
243 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
244 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
245 | |
---|
246 | private: |
---|
247 | virtual std::string typeString() const; |
---|
248 | }; |
---|
249 | |
---|
250 | class UnionDecl : public AggregateDecl |
---|
251 | { |
---|
252 | typedef AggregateDecl Parent; |
---|
253 | |
---|
254 | public: |
---|
255 | UnionDecl( const std::string &name ) : Parent( name ) {} |
---|
256 | UnionDecl( const UnionDecl &other ) : Parent( other ) {} |
---|
257 | |
---|
258 | virtual UnionDecl *clone() const { return new UnionDecl( *this ); } |
---|
259 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
260 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
261 | |
---|
262 | private: |
---|
263 | virtual std::string typeString() const; |
---|
264 | }; |
---|
265 | |
---|
266 | class EnumDecl : public AggregateDecl |
---|
267 | { |
---|
268 | typedef AggregateDecl Parent; |
---|
269 | |
---|
270 | public: |
---|
271 | EnumDecl( const std::string &name ) : Parent( name ) {} |
---|
272 | EnumDecl( const EnumDecl &other ) : Parent( other ) {} |
---|
273 | |
---|
274 | virtual EnumDecl *clone() const { return new EnumDecl( *this ); } |
---|
275 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
276 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
277 | |
---|
278 | private: |
---|
279 | virtual std::string typeString() const; |
---|
280 | }; |
---|
281 | |
---|
282 | class ContextDecl : public AggregateDecl |
---|
283 | { |
---|
284 | typedef AggregateDecl Parent; |
---|
285 | |
---|
286 | public: |
---|
287 | ContextDecl( const std::string &name ) : Parent( name ) {} |
---|
288 | ContextDecl( const ContextDecl &other ) : Parent( other ) {} |
---|
289 | |
---|
290 | virtual ContextDecl *clone() const { return new ContextDecl( *this ); } |
---|
291 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
292 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
293 | |
---|
294 | private: |
---|
295 | virtual std::string typeString() const; |
---|
296 | }; |
---|
297 | |
---|
298 | |
---|
299 | |
---|
300 | #endif /* #ifndef DECLARATION_H */ |
---|