source: src/SynTree/Declaration.h@ b762122

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 b762122 was 1db21619, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

add CFA flag, remove -p from cc1, typedef on functions become function declarations, move isInline/isNoreturn to Declaration, cleaned up label code

  • Property mode set to 100644
File size: 9.5 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 : Peter A. Buhr
12// Last Modified On : Mon Jul 13 18:15:59 2015
13// Update Count : 28
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 FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn );
109 FunctionDecl( const FunctionDecl &other );
110 virtual ~FunctionDecl();
111
112 Type *get_type() const;
113 virtual void set_type(Type *);
114
115 FunctionType *get_functionType() const { return type; }
116 void set_functionType( FunctionType *newValue ) { type = newValue; }
117 CompoundStmt *get_statements() const { return statements; }
118 void set_statements( CompoundStmt *newValue ) { statements = newValue; }
119 std::list< std::string >& get_oldIdents() { return oldIdents; }
120 std::list< Declaration* >& get_oldDecls() { return oldDecls; }
121
122 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
123 virtual void accept( Visitor &v ) { v.visit( this ); }
124 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
125 virtual void print( std::ostream &os, int indent = 0 ) const;
126 virtual void printShort( std::ostream &os, int indent = 0 ) const;
127 private:
128 FunctionType *type;
129 CompoundStmt *statements;
130 std::list< std::string > oldIdents;
131 std::list< Declaration* > oldDecls;
132};
133
134class NamedTypeDecl : public Declaration {
135 typedef Declaration Parent;
136 public:
137 NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
138 NamedTypeDecl( const TypeDecl &other );
139 virtual ~NamedTypeDecl();
140
141 Type *get_base() const { return base; }
142 void set_base( Type *newValue ) { base = newValue; }
143 std::list< TypeDecl* >& get_parameters() { return parameters; }
144 std::list< DeclarationWithType* >& get_assertions() { return assertions; }
145
146 virtual NamedTypeDecl *clone() const = 0;
147 virtual void print( std::ostream &os, int indent = 0 ) const;
148 virtual void printShort( std::ostream &os, int indent = 0 ) const;
149 protected:
150 virtual std::string typeString() const = 0;
151 private:
152 Type *base;
153 std::list< TypeDecl* > parameters;
154 std::list< DeclarationWithType* > assertions;
155};
156
157class TypeDecl : public NamedTypeDecl {
158 typedef NamedTypeDecl Parent;
159 public:
160 enum Kind { Any, Dtype, Ftype };
161
162 TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
163 TypeDecl( const TypeDecl &other );
164
165 Kind get_kind() const { return kind; }
166
167 virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
168 virtual void accept( Visitor &v ) { v.visit( this ); }
169 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
170 private:
171 virtual std::string typeString() const;
172 Kind kind;
173};
174
175class TypedefDecl : public NamedTypeDecl {
176 typedef NamedTypeDecl Parent;
177 public:
178 TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
179 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
180
181 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
182 virtual void accept( Visitor &v ) { v.visit( this ); }
183 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
184 private:
185 virtual std::string typeString() const;
186};
187
188class AggregateDecl : public Declaration {
189 typedef Declaration Parent;
190 public:
191 AggregateDecl( const std::string &name );
192 AggregateDecl( const AggregateDecl &other );
193 virtual ~AggregateDecl();
194
195 std::list<Declaration*>& get_members() { return members; }
196 std::list<TypeDecl*>& get_parameters() { return parameters; }
197
198 virtual void print( std::ostream &os, int indent = 0 ) const;
199 virtual void printShort( std::ostream &os, int indent = 0 ) const;
200 protected:
201 virtual std::string typeString() const = 0;
202
203 private:
204 std::list<Declaration*> members;
205 std::list<TypeDecl*> parameters;
206};
207
208class StructDecl : public AggregateDecl {
209 typedef AggregateDecl Parent;
210 public:
211 StructDecl( const std::string &name ) : Parent( name ) {}
212 StructDecl( const StructDecl &other ) : Parent( other ) {}
213
214 virtual StructDecl *clone() const { return new StructDecl( *this ); }
215 virtual void accept( Visitor &v ) { v.visit( this ); }
216 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
217
218 private:
219 virtual std::string typeString() const;
220};
221
222class UnionDecl : public AggregateDecl {
223 typedef AggregateDecl Parent;
224 public:
225 UnionDecl( const std::string &name ) : Parent( name ) {}
226 UnionDecl( const UnionDecl &other ) : Parent( other ) {}
227
228 virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
229 virtual void accept( Visitor &v ) { v.visit( this ); }
230 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
231 private:
232 virtual std::string typeString() const;
233};
234
235class EnumDecl : public AggregateDecl {
236 typedef AggregateDecl Parent;
237 public:
238 EnumDecl( const std::string &name ) : Parent( name ) {}
239 EnumDecl( const EnumDecl &other ) : Parent( other ) {}
240
241 virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
242 virtual void accept( Visitor &v ) { v.visit( this ); }
243 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
244 private:
245 virtual std::string typeString() const;
246};
247
248class ContextDecl : public AggregateDecl {
249 typedef AggregateDecl Parent;
250 public:
251 ContextDecl( const std::string &name ) : Parent( name ) {}
252 ContextDecl( const ContextDecl &other ) : Parent( other ) {}
253
254 virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
255 virtual void accept( Visitor &v ) { v.visit( this ); }
256 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
257 private:
258 virtual std::string typeString() const;
259};
260
261#endif // DECLARATION_H
262
263// Local Variables: //
264// tab-width: 4 //
265// mode: c++ //
266// compile-command: "make install" //
267// End: //
Note: See TracBrowser for help on using the repository browser.