source: src/SynTree/Declaration.h@ 3f414ef

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 3f414ef was a7c90d4, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

change StorageClass to bitset, support _Thread_local as separate storage-class

  • Property mode set to 100644
File size: 12.6 KB
RevLine 
[0dd3a2f]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//
[974906e2]7// Declaration.h --
[0dd3a2f]8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
[8e9cbb2]11// Last Modified By : Peter A. Buhr
[a7c90d4]12// Last Modified On : Tue Mar 7 07:40:42 2017
13// Update Count : 113
[0dd3a2f]14//
15
[51b73452]16#ifndef DECLARATION_H
17#define DECLARATION_H
18
[294647b]19#include <string>
20
21#include "BaseSyntaxNode.h"
[51b73452]22#include "Mutator.h"
[294647b]23#include "Visitor.h"
24#include "SynTree.h"
[51b73452]25#include "Parser/LinkageSpec.h"
[68cd1ce]26#include "Parser/ParseNode.h"
[51b73452]27
[294647b]28class Declaration : public BaseSyntaxNode {
[17cd4eb]29 public:
[a7c90d4]30 Declaration( const std::string &name, DeclarationNode::StorageClasses scs, LinkageSpec::Spec linkage );
[0dd3a2f]31 Declaration( const Declaration &other );
32 virtual ~Declaration();
33
[5f2f2d7]34 const std::string &get_name() const { return name; }
[0dd3a2f]35 void set_name( std::string newValue ) { name = newValue; }
[a7c90d4]36
37 DeclarationNode::StorageClasses get_storageClasses() const { return storageClasses; }
38
[8b7ee09]39 LinkageSpec::Spec get_linkage() const { return linkage; }
40 void set_linkage( LinkageSpec::Spec newValue ) { linkage = newValue; }
[a7c90d4]41
[0dd3a2f]42 UniqueId get_uniqueId() const { return uniqueId; }
[a7c90d4]43
[8e9cbb2]44 bool get_extension() const { return extension; }
45 Declaration *set_extension( bool exten ) { extension = exten; return this; }
[0dd3a2f]46
47 void fixUniqueId( void );
48 virtual Declaration *clone() const = 0;
49 virtual void accept( Visitor &v ) = 0;
50 virtual Declaration *acceptMutator( Mutator &m ) = 0;
51 virtual void print( std::ostream &os, int indent = 0 ) const = 0;
52 virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
53
54 static void dumpIds( std::ostream &os );
55 static Declaration *declFromId( UniqueId id );
[17cd4eb]56 private:
[0dd3a2f]57 std::string name;
[a7c90d4]58 DeclarationNode::StorageClasses storageClasses;
[8b7ee09]59 LinkageSpec::Spec linkage;
[0dd3a2f]60 UniqueId uniqueId;
[8e9cbb2]61 bool extension = false;
[51b73452]62};
63
[17cd4eb]64class DeclarationWithType : public Declaration {
65 public:
[a7c90d4]66 DeclarationWithType( const std::string &name, DeclarationNode::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, DeclarationNode::FuncSpecifiers fs );
[0dd3a2f]67 DeclarationWithType( const DeclarationWithType &other );
68 virtual ~DeclarationWithType();
[51b73452]69
[0dd3a2f]70 std::string get_mangleName() const { return mangleName; }
[58dd019]71 DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
[17cd4eb]72
[f326f99]73 std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
74
75 int get_scopeLevel() const { return scopeLevel; }
[58dd019]76 DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
77
78 ConstantExpr *get_asmName() const { return asmName; }
79 DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
[f326f99]80
[f9cebb5]81 std::list< Attribute * >& get_attributes() { return attributes; }
82 const std::list< Attribute * >& get_attributes() const { return attributes; }
83
[a7c90d4]84 DeclarationNode::FuncSpecifiers get_funcSpec() const { return fs; }
85 //void set_functionSpecifiers( DeclarationNode::FuncSpecifiers newValue ) { fs = newValue; }
[dd020c0]86
[0dd3a2f]87 virtual DeclarationWithType *clone() const = 0;
88 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
[17cd4eb]89
[0dd3a2f]90 virtual Type *get_type() const = 0;
91 virtual void set_type(Type *) = 0;
[17cd4eb]92 private:
[0dd3a2f]93 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
94 std::string mangleName;
[58dd019]95 // need to remember the scope level at which the variable was declared, so that shadowed identifiers can be accessed
[f326f99]96 int scopeLevel = 0;
[f9cebb5]97
[58dd019]98 ConstantExpr *asmName;
[f9cebb5]99 std::list< Attribute * > attributes;
[a7c90d4]100 DeclarationNode::FuncSpecifiers fs;
[51b73452]101};
102
[17cd4eb]103class ObjectDecl : public DeclarationWithType {
[0dd3a2f]104 typedef DeclarationWithType Parent;
[17cd4eb]105 public:
[a7c90d4]106 ObjectDecl( const std::string &name, DeclarationNode::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
107 const std::list< Attribute * > attributes = std::list< Attribute * >(), DeclarationNode::FuncSpecifiers fs = DeclarationNode::FuncSpecifiers() );
[0dd3a2f]108 ObjectDecl( const ObjectDecl &other );
109 virtual ~ObjectDecl();
110
111 virtual Type *get_type() const { return type; }
112 virtual void set_type(Type *newType) { type = newType; }
113
114 Initializer *get_init() const { return init; }
115 void set_init( Initializer *newValue ) { init = newValue; }
[58dd019]116
[0dd3a2f]117 Expression *get_bitfieldWidth() const { return bitfieldWidth; }
118 void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
119
120 virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
121 virtual void accept( Visitor &v ) { v.visit( this ); }
[1db21619]122 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[0dd3a2f]123 virtual void print( std::ostream &os, int indent = 0 ) const;
124 virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]125 private:
[0dd3a2f]126 Type *type;
127 Initializer *init;
128 Expression *bitfieldWidth;
[51b73452]129};
130
[17cd4eb]131class FunctionDecl : public DeclarationWithType {
[0dd3a2f]132 typedef DeclarationWithType Parent;
[17cd4eb]133 public:
[a7c90d4]134 FunctionDecl( const std::string &name, DeclarationNode::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
135 const std::list< Attribute * > attributes = std::list< Attribute * >(), DeclarationNode::FuncSpecifiers fs = DeclarationNode::FuncSpecifiers() );
[0dd3a2f]136 FunctionDecl( const FunctionDecl &other );
137 virtual ~FunctionDecl();
[51b73452]138
[0dd3a2f]139 Type *get_type() const;
140 virtual void set_type(Type *);
[51b73452]141
[0dd3a2f]142 FunctionType *get_functionType() const { return type; }
143 void set_functionType( FunctionType *newValue ) { type = newValue; }
144 CompoundStmt *get_statements() const { return statements; }
145 void set_statements( CompoundStmt *newValue ) { statements = newValue; }
146
147 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
148 virtual void accept( Visitor &v ) { v.visit( this ); }
149 virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
150 virtual void print( std::ostream &os, int indent = 0 ) const;
151 virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]152 private:
[0dd3a2f]153 FunctionType *type;
154 CompoundStmt *statements;
[51b73452]155};
156
[17cd4eb]157class NamedTypeDecl : public Declaration {
[0dd3a2f]158 typedef Declaration Parent;
[17cd4eb]159 public:
[a7c90d4]160 NamedTypeDecl( const std::string &name, DeclarationNode::StorageClasses scs, Type *type );
[46f6134]161 NamedTypeDecl( const NamedTypeDecl &other );
[0dd3a2f]162 virtual ~NamedTypeDecl();
163
164 Type *get_base() const { return base; }
165 void set_base( Type *newValue ) { base = newValue; }
166 std::list< TypeDecl* >& get_parameters() { return parameters; }
167 std::list< DeclarationWithType* >& get_assertions() { return assertions; }
168
169 virtual NamedTypeDecl *clone() const = 0;
170 virtual void print( std::ostream &os, int indent = 0 ) const;
171 virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]172 protected:
[0dd3a2f]173 virtual std::string typeString() const = 0;
[17cd4eb]174 private:
[0dd3a2f]175 Type *base;
176 std::list< TypeDecl* > parameters;
177 std::list< DeclarationWithType* > assertions;
[51b73452]178};
179
[17cd4eb]180class TypeDecl : public NamedTypeDecl {
[0dd3a2f]181 typedef NamedTypeDecl Parent;
[17cd4eb]182 public:
[8f60f0b]183 enum Kind { Any, Dtype, Ftype, Ttype };
[2c57025]184 /// Data extracted from a type decl
185 struct Data {
186 TypeDecl::Kind kind;
187 bool isComplete;
188 Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
189 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
190 Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
191 bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; }
192 bool operator!=(const Data & other) const { return !(*this == other);}
193 };
[51b73452]194
[a7c90d4]195 TypeDecl( const std::string &name, DeclarationNode::StorageClasses scs, Type *type, Kind kind );
[0dd3a2f]196 TypeDecl( const TypeDecl &other );
[17cd4eb]197
[0dd3a2f]198 Kind get_kind() const { return kind; }
[51b73452]199
[2c57025]200 bool isComplete() const { return kind == Any || sized; }
201 bool get_sized() const { return sized; }
202 TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; }
203
[0dd3a2f]204 virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
205 virtual void accept( Visitor &v ) { v.visit( this ); }
206 virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]207 private:
[0dd3a2f]208 virtual std::string typeString() const;
209 Kind kind;
[2c57025]210 bool sized;
[51b73452]211};
212
[17cd4eb]213class TypedefDecl : public NamedTypeDecl {
[0dd3a2f]214 typedef NamedTypeDecl Parent;
[17cd4eb]215 public:
[a7c90d4]216 TypedefDecl( const std::string &name, DeclarationNode::StorageClasses scs, Type *type ) : Parent( name, scs, type ) {}
[0dd3a2f]217 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
[17cd4eb]218
[0dd3a2f]219 virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
220 virtual void accept( Visitor &v ) { v.visit( this ); }
221 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]222 private:
[0dd3a2f]223 virtual std::string typeString() const;
[51b73452]224};
225
[17cd4eb]226class AggregateDecl : public Declaration {
[0dd3a2f]227 typedef Declaration Parent;
[17cd4eb]228 public:
[c0aa336]229 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >() );
[0dd3a2f]230 AggregateDecl( const AggregateDecl &other );
231 virtual ~AggregateDecl();
[51b73452]232
[0dd3a2f]233 std::list<Declaration*>& get_members() { return members; }
234 std::list<TypeDecl*>& get_parameters() { return parameters; }
[17cd4eb]235
[c0aa336]236 std::list< Attribute * >& get_attributes() { return attributes; }
237 const std::list< Attribute * >& get_attributes() const { return attributes; }
238
[5d125e4]239 bool has_body() const { return body; }
240 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
241
[0dd3a2f]242 virtual void print( std::ostream &os, int indent = 0 ) const;
243 virtual void printShort( std::ostream &os, int indent = 0 ) const;
[17cd4eb]244 protected:
[0dd3a2f]245 virtual std::string typeString() const = 0;
[17cd4eb]246
247 private:
[0dd3a2f]248 std::list<Declaration*> members;
249 std::list<TypeDecl*> parameters;
[5d125e4]250 bool body;
[c0aa336]251 std::list< Attribute * > attributes;
[51b73452]252};
253
[17cd4eb]254class StructDecl : public AggregateDecl {
[0dd3a2f]255 typedef AggregateDecl Parent;
[17cd4eb]256 public:
[c0aa336]257 StructDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >() ) : Parent( name, attributes ) {}
[0dd3a2f]258 StructDecl( const StructDecl &other ) : Parent( other ) {}
[17cd4eb]259
[0dd3a2f]260 virtual StructDecl *clone() const { return new StructDecl( *this ); }
261 virtual void accept( Visitor &v ) { v.visit( this ); }
262 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]263 private:
[0dd3a2f]264 virtual std::string typeString() const;
[51b73452]265};
266
[17cd4eb]267class UnionDecl : public AggregateDecl {
[0dd3a2f]268 typedef AggregateDecl Parent;
[17cd4eb]269 public:
[c0aa336]270 UnionDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >() ) : Parent( name, attributes ) {}
[0dd3a2f]271 UnionDecl( const UnionDecl &other ) : Parent( other ) {}
[17cd4eb]272
[0dd3a2f]273 virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
274 virtual void accept( Visitor &v ) { v.visit( this ); }
275 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]276 private:
[0dd3a2f]277 virtual std::string typeString() const;
[51b73452]278};
279
[17cd4eb]280class EnumDecl : public AggregateDecl {
[0dd3a2f]281 typedef AggregateDecl Parent;
[17cd4eb]282 public:
[c0aa336]283 EnumDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >() ) : Parent( name, attributes ) {}
[0dd3a2f]284 EnumDecl( const EnumDecl &other ) : Parent( other ) {}
[17cd4eb]285
[0dd3a2f]286 virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
287 virtual void accept( Visitor &v ) { v.visit( this ); }
288 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]289 private:
[0dd3a2f]290 virtual std::string typeString() const;
[51b73452]291};
292
[4040425]293class TraitDecl : public AggregateDecl {
[0dd3a2f]294 typedef AggregateDecl Parent;
[17cd4eb]295 public:
[c0aa336]296 TraitDecl( const std::string &name, const std::list< Attribute * > & attributes ) : Parent( name ) {
297 assertf( attributes.empty(), "attribute unsupported for traits" );
298 }
[4040425]299 TraitDecl( const TraitDecl &other ) : Parent( other ) {}
[17cd4eb]300
[4040425]301 virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
[0dd3a2f]302 virtual void accept( Visitor &v ) { v.visit( this ); }
303 virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[17cd4eb]304 private:
[0dd3a2f]305 virtual std::string typeString() const;
[51b73452]306};
307
[e994912]308class AsmDecl : public Declaration {
309 public:
310 AsmDecl( AsmStmt *stmt );
311 AsmDecl( const AsmDecl &other );
312 virtual ~AsmDecl();
313
314 AsmStmt *get_stmt() { return stmt; }
315 void set_stmt( AsmStmt *newValue ) { stmt = newValue; }
316
317 virtual AsmDecl *clone() const { return new AsmDecl( *this ); }
318 virtual void accept( Visitor &v ) { v.visit( this ); }
319 virtual AsmDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
320 virtual void print( std::ostream &os, int indent = 0 ) const;
321 virtual void printShort( std::ostream &os, int indent = 0 ) const;
322 private:
323 AsmStmt *stmt;
324};
325
[3906301]326std::ostream & operator<<( std::ostream & out, const Declaration * decl );
[2c57025]327std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data );
[baf7fee]328
[17cd4eb]329#endif // DECLARATION_H
[0dd3a2f]330
331// Local Variables: //
332// tab-width: 4 //
333// mode: c++ //
334// compile-command: "make install" //
335// End: //
Note: See TracBrowser for help on using the repository browser.