[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
|
---|
[5d125e4] | 12 | // Last Modified On : Tue Jul 12 21:03:17 2016
|
---|
| 13 | // Update Count : 39
|
---|
[0dd3a2f] | 14 | //
|
---|
| 15 |
|
---|
[51b73452] | 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"
|
---|
[68cd1ce] | 23 | #include "Parser/ParseNode.h"
|
---|
[f326f99] | 24 | #include <string>
|
---|
[51b73452] | 25 |
|
---|
[17cd4eb] | 26 | class Declaration {
|
---|
| 27 | public:
|
---|
[68cd1ce] | 28 | Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
|
---|
[0dd3a2f] | 29 | Declaration( const Declaration &other );
|
---|
| 30 | virtual ~Declaration();
|
---|
| 31 |
|
---|
[5f2f2d7] | 32 | const std::string &get_name() const { return name; }
|
---|
[0dd3a2f] | 33 | void set_name( std::string newValue ) { name = newValue; }
|
---|
[68cd1ce] | 34 | DeclarationNode::StorageClass get_storageClass() const { return storageClass; }
|
---|
| 35 | void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; }
|
---|
[0dd3a2f] | 36 | LinkageSpec::Type get_linkage() const { return linkage; }
|
---|
| 37 | void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; }
|
---|
[1db21619] | 38 | bool get_isInline() const { return isInline; }
|
---|
| 39 | void set_isInline( bool newValue ) { isInline = newValue; }
|
---|
| 40 | bool get_isNoreturn() const { return isNoreturn; }
|
---|
| 41 | void set_isNoreturn( bool newValue ) { isNoreturn = newValue; }
|
---|
[0dd3a2f] | 42 | UniqueId get_uniqueId() const { return uniqueId; }
|
---|
[8e9cbb2] | 43 | bool get_extension() const { return extension; }
|
---|
| 44 | Declaration *set_extension( bool exten ) { extension = exten; return this; }
|
---|
[0dd3a2f] | 45 |
|
---|
| 46 | void fixUniqueId( void );
|
---|
| 47 | virtual Declaration *clone() const = 0;
|
---|
| 48 | virtual void accept( Visitor &v ) = 0;
|
---|
| 49 | virtual Declaration *acceptMutator( Mutator &m ) = 0;
|
---|
| 50 | virtual void print( std::ostream &os, int indent = 0 ) const = 0;
|
---|
| 51 | virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
|
---|
| 52 |
|
---|
| 53 | static void dumpIds( std::ostream &os );
|
---|
| 54 | static Declaration *declFromId( UniqueId id );
|
---|
[17cd4eb] | 55 | private:
|
---|
[0dd3a2f] | 56 | std::string name;
|
---|
[68cd1ce] | 57 | DeclarationNode::StorageClass storageClass;
|
---|
[0dd3a2f] | 58 | LinkageSpec::Type linkage;
|
---|
[1db21619] | 59 | bool isInline, isNoreturn;
|
---|
[0dd3a2f] | 60 | UniqueId uniqueId;
|
---|
[8e9cbb2] | 61 | bool extension = false;
|
---|
[51b73452] | 62 | };
|
---|
| 63 |
|
---|
[17cd4eb] | 64 | class DeclarationWithType : public Declaration {
|
---|
| 65 | public:
|
---|
[f9cebb5] | 66 | DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, const std::list< Attribute * > & attributes );
|
---|
[0dd3a2f] | 67 | DeclarationWithType( const DeclarationWithType &other );
|
---|
| 68 | virtual ~DeclarationWithType();
|
---|
[51b73452] | 69 |
|
---|
[0dd3a2f] | 70 | std::string get_mangleName() const { return mangleName; }
|
---|
| 71 | void set_mangleName( std::string newValue ) { mangleName = newValue; }
|
---|
[17cd4eb] | 72 |
|
---|
[f326f99] | 73 | std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
|
---|
| 74 |
|
---|
| 75 | int get_scopeLevel() const { return scopeLevel; }
|
---|
| 76 | void set_scopeLevel( int newValue ) { scopeLevel = newValue; }
|
---|
| 77 |
|
---|
[f9cebb5] | 78 | std::list< Attribute * >& get_attributes() { return attributes; }
|
---|
| 79 | const std::list< Attribute * >& get_attributes() const { return attributes; }
|
---|
| 80 |
|
---|
[0dd3a2f] | 81 | virtual DeclarationWithType *clone() const = 0;
|
---|
| 82 | virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
|
---|
[17cd4eb] | 83 |
|
---|
[0dd3a2f] | 84 | virtual Type *get_type() const = 0;
|
---|
| 85 | virtual void set_type(Type *) = 0;
|
---|
[17cd4eb] | 86 | private:
|
---|
[0dd3a2f] | 87 | // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
|
---|
| 88 | std::string mangleName;
|
---|
[f326f99] | 89 | // need to remember the scope level at which the variable was declared, so that
|
---|
| 90 | // shadowed identifiers can be accessed
|
---|
| 91 | int scopeLevel = 0;
|
---|
[f9cebb5] | 92 |
|
---|
| 93 | std::list< Attribute * > attributes;
|
---|
[51b73452] | 94 | };
|
---|
| 95 |
|
---|
[17cd4eb] | 96 | class ObjectDecl : public DeclarationWithType {
|
---|
[0dd3a2f] | 97 | typedef DeclarationWithType Parent;
|
---|
[17cd4eb] | 98 | public:
|
---|
[f9cebb5] | 99 | ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, const std::list< Attribute * > attributes = std::list< Attribute * >(), bool isInline = false, bool isNoreturn = false );
|
---|
[0dd3a2f] | 100 | ObjectDecl( const ObjectDecl &other );
|
---|
| 101 | virtual ~ObjectDecl();
|
---|
| 102 |
|
---|
| 103 | virtual Type *get_type() const { return type; }
|
---|
| 104 | virtual void set_type(Type *newType) { type = newType; }
|
---|
| 105 |
|
---|
| 106 | Initializer *get_init() const { return init; }
|
---|
| 107 | void set_init( Initializer *newValue ) { init = newValue; }
|
---|
| 108 | Expression *get_bitfieldWidth() const { return bitfieldWidth; }
|
---|
| 109 | void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
|
---|
| 110 |
|
---|
| 111 | virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
|
---|
| 112 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
[1db21619] | 113 | virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[0dd3a2f] | 114 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 115 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 116 | private:
|
---|
[0dd3a2f] | 117 | Type *type;
|
---|
| 118 | Initializer *init;
|
---|
| 119 | Expression *bitfieldWidth;
|
---|
[51b73452] | 120 | };
|
---|
| 121 |
|
---|
[17cd4eb] | 122 | class FunctionDecl : public DeclarationWithType {
|
---|
[0dd3a2f] | 123 | typedef DeclarationWithType Parent;
|
---|
[17cd4eb] | 124 | public:
|
---|
[7baed7d] | 125 | FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, const std::list< Attribute * > attributes = std::list< Attribute * >() );
|
---|
[0dd3a2f] | 126 | FunctionDecl( const FunctionDecl &other );
|
---|
| 127 | virtual ~FunctionDecl();
|
---|
[51b73452] | 128 |
|
---|
[0dd3a2f] | 129 | Type *get_type() const;
|
---|
| 130 | virtual void set_type(Type *);
|
---|
[51b73452] | 131 |
|
---|
[0dd3a2f] | 132 | FunctionType *get_functionType() const { return type; }
|
---|
| 133 | void set_functionType( FunctionType *newValue ) { type = newValue; }
|
---|
| 134 | CompoundStmt *get_statements() const { return statements; }
|
---|
| 135 | void set_statements( CompoundStmt *newValue ) { statements = newValue; }
|
---|
| 136 | std::list< std::string >& get_oldIdents() { return oldIdents; }
|
---|
| 137 | std::list< Declaration* >& get_oldDecls() { return oldDecls; }
|
---|
| 138 |
|
---|
| 139 | virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
|
---|
| 140 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 141 | virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
| 142 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 143 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 144 | private:
|
---|
[0dd3a2f] | 145 | FunctionType *type;
|
---|
| 146 | CompoundStmt *statements;
|
---|
| 147 | std::list< std::string > oldIdents;
|
---|
| 148 | std::list< Declaration* > oldDecls;
|
---|
[51b73452] | 149 | };
|
---|
| 150 |
|
---|
[17cd4eb] | 151 | class NamedTypeDecl : public Declaration {
|
---|
[0dd3a2f] | 152 | typedef Declaration Parent;
|
---|
[17cd4eb] | 153 | public:
|
---|
[68cd1ce] | 154 | NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
|
---|
[0dd3a2f] | 155 | NamedTypeDecl( const TypeDecl &other );
|
---|
| 156 | virtual ~NamedTypeDecl();
|
---|
| 157 |
|
---|
| 158 | Type *get_base() const { return base; }
|
---|
| 159 | void set_base( Type *newValue ) { base = newValue; }
|
---|
| 160 | std::list< TypeDecl* >& get_parameters() { return parameters; }
|
---|
| 161 | std::list< DeclarationWithType* >& get_assertions() { return assertions; }
|
---|
| 162 |
|
---|
| 163 | virtual NamedTypeDecl *clone() const = 0;
|
---|
| 164 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 165 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 166 | protected:
|
---|
[0dd3a2f] | 167 | virtual std::string typeString() const = 0;
|
---|
[17cd4eb] | 168 | private:
|
---|
[0dd3a2f] | 169 | Type *base;
|
---|
| 170 | std::list< TypeDecl* > parameters;
|
---|
| 171 | std::list< DeclarationWithType* > assertions;
|
---|
[51b73452] | 172 | };
|
---|
| 173 |
|
---|
[17cd4eb] | 174 | class TypeDecl : public NamedTypeDecl {
|
---|
[0dd3a2f] | 175 | typedef NamedTypeDecl Parent;
|
---|
[17cd4eb] | 176 | public:
|
---|
[0dd3a2f] | 177 | enum Kind { Any, Dtype, Ftype };
|
---|
[51b73452] | 178 |
|
---|
[68cd1ce] | 179 | TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
|
---|
[0dd3a2f] | 180 | TypeDecl( const TypeDecl &other );
|
---|
[17cd4eb] | 181 |
|
---|
[0dd3a2f] | 182 | Kind get_kind() const { return kind; }
|
---|
[51b73452] | 183 |
|
---|
[0dd3a2f] | 184 | virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
|
---|
| 185 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 186 | virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 187 | private:
|
---|
[0dd3a2f] | 188 | virtual std::string typeString() const;
|
---|
| 189 | Kind kind;
|
---|
[51b73452] | 190 | };
|
---|
| 191 |
|
---|
[17cd4eb] | 192 | class TypedefDecl : public NamedTypeDecl {
|
---|
[0dd3a2f] | 193 | typedef NamedTypeDecl Parent;
|
---|
[17cd4eb] | 194 | public:
|
---|
[68cd1ce] | 195 | TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
|
---|
[0dd3a2f] | 196 | TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 197 |
|
---|
[0dd3a2f] | 198 | virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
|
---|
| 199 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 200 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 201 | private:
|
---|
[0dd3a2f] | 202 | virtual std::string typeString() const;
|
---|
[51b73452] | 203 | };
|
---|
| 204 |
|
---|
[17cd4eb] | 205 | class AggregateDecl : public Declaration {
|
---|
[0dd3a2f] | 206 | typedef Declaration Parent;
|
---|
[17cd4eb] | 207 | public:
|
---|
[0dd3a2f] | 208 | AggregateDecl( const std::string &name );
|
---|
| 209 | AggregateDecl( const AggregateDecl &other );
|
---|
| 210 | virtual ~AggregateDecl();
|
---|
[51b73452] | 211 |
|
---|
[0dd3a2f] | 212 | std::list<Declaration*>& get_members() { return members; }
|
---|
| 213 | std::list<TypeDecl*>& get_parameters() { return parameters; }
|
---|
[17cd4eb] | 214 |
|
---|
[5d125e4] | 215 | bool has_body() const { return body; }
|
---|
| 216 | AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
|
---|
| 217 |
|
---|
[0dd3a2f] | 218 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 219 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 220 | protected:
|
---|
[0dd3a2f] | 221 | virtual std::string typeString() const = 0;
|
---|
[17cd4eb] | 222 |
|
---|
| 223 | private:
|
---|
[0dd3a2f] | 224 | std::list<Declaration*> members;
|
---|
| 225 | std::list<TypeDecl*> parameters;
|
---|
[5d125e4] | 226 | bool body;
|
---|
[51b73452] | 227 | };
|
---|
| 228 |
|
---|
[17cd4eb] | 229 | class StructDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 230 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 231 | public:
|
---|
[0dd3a2f] | 232 | StructDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 233 | StructDecl( const StructDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 234 |
|
---|
[0dd3a2f] | 235 | virtual StructDecl *clone() const { return new StructDecl( *this ); }
|
---|
| 236 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 237 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 238 | private:
|
---|
[0dd3a2f] | 239 | virtual std::string typeString() const;
|
---|
[51b73452] | 240 | };
|
---|
| 241 |
|
---|
[17cd4eb] | 242 | class UnionDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 243 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 244 | public:
|
---|
[0dd3a2f] | 245 | UnionDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 246 | UnionDecl( const UnionDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 247 |
|
---|
[0dd3a2f] | 248 | virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
|
---|
| 249 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 250 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 251 | private:
|
---|
[0dd3a2f] | 252 | virtual std::string typeString() const;
|
---|
[51b73452] | 253 | };
|
---|
| 254 |
|
---|
[17cd4eb] | 255 | class EnumDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 256 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 257 | public:
|
---|
[0dd3a2f] | 258 | EnumDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 259 | EnumDecl( const EnumDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 260 |
|
---|
[0dd3a2f] | 261 | virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
|
---|
| 262 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 263 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 264 | private:
|
---|
[0dd3a2f] | 265 | virtual std::string typeString() const;
|
---|
[51b73452] | 266 | };
|
---|
| 267 |
|
---|
[4040425] | 268 | class TraitDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 269 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 270 | public:
|
---|
[4040425] | 271 | TraitDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 272 | TraitDecl( const TraitDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 273 |
|
---|
[4040425] | 274 | virtual TraitDecl *clone() const { return new TraitDecl( *this ); }
|
---|
[0dd3a2f] | 275 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 276 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 277 | private:
|
---|
[0dd3a2f] | 278 | virtual std::string typeString() const;
|
---|
[51b73452] | 279 | };
|
---|
| 280 |
|
---|
[baf7fee] | 281 | std::ostream & operator<<( std::ostream & out, Declaration * decl );
|
---|
| 282 |
|
---|
[17cd4eb] | 283 | #endif // DECLARATION_H
|
---|
[0dd3a2f] | 284 |
|
---|
| 285 | // Local Variables: //
|
---|
| 286 | // tab-width: 4 //
|
---|
| 287 | // mode: c++ //
|
---|
| 288 | // compile-command: "make install" //
|
---|
| 289 | // End: //
|
---|