source: translator/SynTree/Declaration.h@ 643a2e1

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 643a2e1 was 17cd4eb, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

fixed restrict, fixed parameter copy, introduced name table for types, changed variable after to string

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