source: src/SynTree/Declaration.h@ 03e5d14

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 with_gc
Last change on this file since 03e5d14 was 03e5d14, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

add support for constructor/destructor attribute priority and set priority for library constructors to high

  • Property mode set to 100644
File size: 10.0 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Declaration.h --
8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Fri May 06 15:39:02 2016
13// Update Count : 33
14//
15
16#ifndef DECLARATION_H
17#define DECLARATION_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22#include "Parser/LinkageSpec.h"
23#include "Parser/ParseNode.h"
24
25class Declaration {
26 public:
27 Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
28 Declaration( const Declaration &other );
29 virtual ~Declaration();
30
31 const std::string &get_name() const { return name; }
32 void set_name( std::string newValue ) { name = newValue; }
33 DeclarationNode::StorageClass get_storageClass() const { return storageClass; }
34 void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; }
35 LinkageSpec::Type get_linkage() const { return linkage; }
36 void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
37 bool get_isInline() const { return isInline; }
38 void set_isInline( bool newValue ) { isInline = newValue; }
39 bool get_isNoreturn() const { return isNoreturn; }
40 void set_isNoreturn( bool newValue ) { isNoreturn = newValue; }
41 UniqueId get_uniqueId() const { return uniqueId; }
42
43 void fixUniqueId( void );
44 virtual Declaration *clone() const = 0;
45 virtual void accept( Visitor &v ) = 0;
46 virtual Declaration *acceptMutator( Mutator &m ) = 0;
47 virtual void print( std::ostream &os, int indent = 0 ) const = 0;
48 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
49
50 static void dumpIds( std::ostream &os );
51 static Declaration *declFromId( UniqueId id );
52 private:
53 std::string name;
54 DeclarationNode::StorageClass storageClass;
55 LinkageSpec::Type linkage;
56 bool isInline, isNoreturn;
57 UniqueId uniqueId;
58};
59
60class DeclarationWithType : public Declaration {
61 public:
62 DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
63 DeclarationWithType( const DeclarationWithType &other );
64 virtual ~DeclarationWithType();
65
66 std::string get_mangleName() const { return mangleName; }
67 void set_mangleName( std::string newValue ) { mangleName = newValue; }
68
69 virtual DeclarationWithType *clone() const = 0;
70 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
71
72 virtual Type *get_type() const = 0;
73 virtual void set_type(Type *) = 0;
74 private:
75 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
76 std::string mangleName;
77};
78
79class ObjectDecl : public DeclarationWithType {
80 typedef DeclarationWithType Parent;
81 public:
82 ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline = false, bool isNoreturn = false );
83 ObjectDecl( const ObjectDecl &other );
84 virtual ~ObjectDecl();
85
86 virtual Type *get_type() const { return type; }
87 virtual void set_type(Type *newType) { type = newType; }
88
89 Initializer *get_init() const { return init; }
90 void set_init( Initializer *newValue ) { init = newValue; }
91 Expression *get_bitfieldWidth() const { return bitfieldWidth; }
92 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
93
94 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
95 virtual void accept( Visitor &v ) { v.visit( this ); }
96 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
97 virtual void print( std::ostream &os, int indent = 0 ) const;
98 virtual void printShort( std::ostream &os, int indent = 0 ) const;
99 private:
100 Type *type;
101 Initializer *init;
102 Expression *bitfieldWidth;
103};
104
105class FunctionDecl : public DeclarationWithType {
106 typedef DeclarationWithType Parent;
107 public:
108 // temporary - merge this into general GCC attributes
109 struct Attribute {
110 enum Type {
111 NoAttribute, Constructor, Destructor,
112 } type;
113 enum Priority {
114 // priorities 0-100 are reserved by gcc, so it's okay to use 100 an exceptional case
115 Default = 100, High,
116 } priority;
117 Attribute(Type t = NoAttribute, Priority p = Default) : type(t), priority(p) {};
118 };
119
120 FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = Attribute() );
121 FunctionDecl( const FunctionDecl &other );
122 virtual ~FunctionDecl();
123
124 Type *get_type() const;
125 virtual void set_type(Type *);
126
127 FunctionType *get_functionType() const { return type; }
128 void set_functionType( FunctionType *newValue ) { type = newValue; }
129 CompoundStmt *get_statements() const { return statements; }
130 void set_statements( CompoundStmt *newValue ) { statements = newValue; }
131 std::list< std::string >& get_oldIdents() { return oldIdents; }
132 std::list< Declaration* >& get_oldDecls() { return oldDecls; }
133 Attribute get_attribute() const { return attribute; }
134 void set_attribute( Attribute newValue ) { attribute = newValue; }
135
136 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
137 virtual void accept( Visitor &v ) { v.visit( this ); }
138 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
139 virtual void print( std::ostream &os, int indent = 0 ) const;
140 virtual void printShort( std::ostream &os, int indent = 0 ) const;
141 private:
142 FunctionType *type;
143 CompoundStmt *statements;
144 std::list< std::string > oldIdents;
145 std::list< Declaration* > oldDecls;
146 Attribute attribute;
147};
148
149class NamedTypeDecl : public Declaration {
150 typedef Declaration Parent;
151 public:
152 NamedTypeDecl( const std::string &name, DeclarationNode::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 protected:
165 virtual std::string typeString() const = 0;
166 private:
167 Type *base;
168 std::list< TypeDecl* > parameters;
169 std::list< DeclarationWithType* > assertions;
170};
171
172class TypeDecl : public NamedTypeDecl {
173 typedef NamedTypeDecl Parent;
174 public:
175 enum Kind { Any, Dtype, Ftype };
176
177 TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
178 TypeDecl( const TypeDecl &other );
179
180 Kind get_kind() const { return kind; }
181
182 virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
183 virtual void accept( Visitor &v ) { v.visit( this ); }
184 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
185 private:
186 virtual std::string typeString() const;
187 Kind kind;
188};
189
190class TypedefDecl : public NamedTypeDecl {
191 typedef NamedTypeDecl Parent;
192 public:
193 TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
194 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
195
196 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
197 virtual void accept( Visitor &v ) { v.visit( this ); }
198 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
199 private:
200 virtual std::string typeString() const;
201};
202
203class AggregateDecl : public Declaration {
204 typedef Declaration Parent;
205 public:
206 AggregateDecl( const std::string &name );
207 AggregateDecl( const AggregateDecl &other );
208 virtual ~AggregateDecl();
209
210 std::list<Declaration*>& get_members() { return members; }
211 std::list<TypeDecl*>& get_parameters() { return parameters; }
212
213 virtual void print( std::ostream &os, int indent = 0 ) const;
214 virtual void printShort( std::ostream &os, int indent = 0 ) const;
215 protected:
216 virtual std::string typeString() const = 0;
217
218 private:
219 std::list<Declaration*> members;
220 std::list<TypeDecl*> parameters;
221};
222
223class StructDecl : public AggregateDecl {
224 typedef AggregateDecl Parent;
225 public:
226 StructDecl( const std::string &name ) : Parent( name ) {}
227 StructDecl( const StructDecl &other ) : Parent( other ) {}
228
229 virtual StructDecl *clone() const { return new StructDecl( *this ); }
230 virtual void accept( Visitor &v ) { v.visit( this ); }
231 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
232
233 private:
234 virtual std::string typeString() const;
235};
236
237class UnionDecl : public AggregateDecl {
238 typedef AggregateDecl Parent;
239 public:
240 UnionDecl( const std::string &name ) : Parent( name ) {}
241 UnionDecl( const UnionDecl &other ) : Parent( other ) {}
242
243 virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
244 virtual void accept( Visitor &v ) { v.visit( this ); }
245 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
246 private:
247 virtual std::string typeString() const;
248};
249
250class EnumDecl : public AggregateDecl {
251 typedef AggregateDecl Parent;
252 public:
253 EnumDecl( const std::string &name ) : Parent( name ) {}
254 EnumDecl( const EnumDecl &other ) : Parent( other ) {}
255
256 virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
257 virtual void accept( Visitor &v ) { v.visit( this ); }
258 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
259 private:
260 virtual std::string typeString() const;
261};
262
263class TraitDecl : public AggregateDecl {
264 typedef AggregateDecl Parent;
265 public:
266 TraitDecl( const std::string &name ) : Parent( name ) {}
267 TraitDecl( const TraitDecl &other ) : Parent( other ) {}
268
269 virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
270 virtual void accept( Visitor &v ) { v.visit( this ); }
271 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
272 private:
273 virtual std::string typeString() const;
274};
275
276std::ostream & operator<<( std::ostream & out, Declaration * decl );
277
278#endif // DECLARATION_H
279
280// Local Variables: //
281// tab-width: 4 //
282// mode: c++ //
283// compile-command: "make install" //
284// End: //
Note: See TracBrowser for help on using the repository browser.