[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 | // |
---|
| 7 | // Declaration.h -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[baf7fee] | 11 | // Last Modified By : Rob Schluntz |
---|
| 12 | // Last Modified On : Wed Dec 09 14:08:22 2015 |
---|
| 13 | // Update Count : 32 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 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" |
---|
[51b7345] | 24 | |
---|
[17cd4eb] | 25 | class Declaration { |
---|
| 26 | public: |
---|
[68cd1ce] | 27 | Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage ); |
---|
[0dd3a2f] | 28 | Declaration( const Declaration &other ); |
---|
| 29 | virtual ~Declaration(); |
---|
| 30 | |
---|
[5f2f2d7] | 31 | const std::string &get_name() const { return name; } |
---|
[0dd3a2f] | 32 | void set_name( std::string newValue ) { name = newValue; } |
---|
[68cd1ce] | 33 | DeclarationNode::StorageClass get_storageClass() const { return storageClass; } |
---|
| 34 | void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; } |
---|
[0dd3a2f] | 35 | LinkageSpec::Type get_linkage() const { return linkage; } |
---|
| 36 | void set_linkage( LinkageSpec::Type newValue ) { linkage = newValue; } |
---|
[1db21619] | 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; } |
---|
[0dd3a2f] | 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 ); |
---|
[17cd4eb] | 52 | private: |
---|
[0dd3a2f] | 53 | std::string name; |
---|
[68cd1ce] | 54 | DeclarationNode::StorageClass storageClass; |
---|
[0dd3a2f] | 55 | LinkageSpec::Type linkage; |
---|
[1db21619] | 56 | bool isInline, isNoreturn; |
---|
[0dd3a2f] | 57 | UniqueId uniqueId; |
---|
[51b7345] | 58 | }; |
---|
| 59 | |
---|
[17cd4eb] | 60 | class DeclarationWithType : public Declaration { |
---|
| 61 | public: |
---|
[68cd1ce] | 62 | DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage ); |
---|
[0dd3a2f] | 63 | DeclarationWithType( const DeclarationWithType &other ); |
---|
| 64 | virtual ~DeclarationWithType(); |
---|
[51b7345] | 65 | |
---|
[0dd3a2f] | 66 | std::string get_mangleName() const { return mangleName; } |
---|
| 67 | void set_mangleName( std::string newValue ) { mangleName = newValue; } |
---|
[17cd4eb] | 68 | |
---|
[0dd3a2f] | 69 | virtual DeclarationWithType *clone() const = 0; |
---|
| 70 | virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; |
---|
[17cd4eb] | 71 | |
---|
[0dd3a2f] | 72 | virtual Type *get_type() const = 0; |
---|
| 73 | virtual void set_type(Type *) = 0; |
---|
[17cd4eb] | 74 | private: |
---|
[0dd3a2f] | 75 | // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2 |
---|
| 76 | std::string mangleName; |
---|
[51b7345] | 77 | }; |
---|
| 78 | |
---|
[17cd4eb] | 79 | class ObjectDecl : public DeclarationWithType { |
---|
[0dd3a2f] | 80 | typedef DeclarationWithType Parent; |
---|
[17cd4eb] | 81 | public: |
---|
[1db21619] | 82 | ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline = false, bool isNoreturn = false ); |
---|
[0dd3a2f] | 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 ); } |
---|
[1db21619] | 96 | virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[0dd3a2f] | 97 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 98 | virtual void printShort( std::ostream &os, int indent = 0 ) const; |
---|
[17cd4eb] | 99 | private: |
---|
[0dd3a2f] | 100 | Type *type; |
---|
| 101 | Initializer *init; |
---|
| 102 | Expression *bitfieldWidth; |
---|
[51b7345] | 103 | }; |
---|
| 104 | |
---|
[17cd4eb] | 105 | class FunctionDecl : public DeclarationWithType { |
---|
[0dd3a2f] | 106 | typedef DeclarationWithType Parent; |
---|
[17cd4eb] | 107 | public: |
---|
[de62360d] | 108 | FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn ); |
---|
[0dd3a2f] | 109 | FunctionDecl( const FunctionDecl &other ); |
---|
| 110 | virtual ~FunctionDecl(); |
---|
[51b7345] | 111 | |
---|
[0dd3a2f] | 112 | Type *get_type() const; |
---|
| 113 | virtual void set_type(Type *); |
---|
[51b7345] | 114 | |
---|
[0dd3a2f] | 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; |
---|
[17cd4eb] | 127 | private: |
---|
[0dd3a2f] | 128 | FunctionType *type; |
---|
| 129 | CompoundStmt *statements; |
---|
| 130 | std::list< std::string > oldIdents; |
---|
| 131 | std::list< Declaration* > oldDecls; |
---|
[51b7345] | 132 | }; |
---|
| 133 | |
---|
[17cd4eb] | 134 | class NamedTypeDecl : public Declaration { |
---|
[0dd3a2f] | 135 | typedef Declaration Parent; |
---|
[17cd4eb] | 136 | public: |
---|
[68cd1ce] | 137 | NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ); |
---|
[0dd3a2f] | 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; |
---|
[17cd4eb] | 149 | protected: |
---|
[0dd3a2f] | 150 | virtual std::string typeString() const = 0; |
---|
[17cd4eb] | 151 | private: |
---|
[0dd3a2f] | 152 | Type *base; |
---|
| 153 | std::list< TypeDecl* > parameters; |
---|
| 154 | std::list< DeclarationWithType* > assertions; |
---|
[51b7345] | 155 | }; |
---|
| 156 | |
---|
[17cd4eb] | 157 | class TypeDecl : public NamedTypeDecl { |
---|
[0dd3a2f] | 158 | typedef NamedTypeDecl Parent; |
---|
[17cd4eb] | 159 | public: |
---|
[0dd3a2f] | 160 | enum Kind { Any, Dtype, Ftype }; |
---|
[51b7345] | 161 | |
---|
[68cd1ce] | 162 | TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind ); |
---|
[0dd3a2f] | 163 | TypeDecl( const TypeDecl &other ); |
---|
[17cd4eb] | 164 | |
---|
[0dd3a2f] | 165 | Kind get_kind() const { return kind; } |
---|
[51b7345] | 166 | |
---|
[0dd3a2f] | 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 ); } |
---|
[17cd4eb] | 170 | private: |
---|
[0dd3a2f] | 171 | virtual std::string typeString() const; |
---|
| 172 | Kind kind; |
---|
[51b7345] | 173 | }; |
---|
| 174 | |
---|
[17cd4eb] | 175 | class TypedefDecl : public NamedTypeDecl { |
---|
[0dd3a2f] | 176 | typedef NamedTypeDecl Parent; |
---|
[17cd4eb] | 177 | public: |
---|
[68cd1ce] | 178 | TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {} |
---|
[0dd3a2f] | 179 | TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} |
---|
[17cd4eb] | 180 | |
---|
[0dd3a2f] | 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 ); } |
---|
[17cd4eb] | 184 | private: |
---|
[0dd3a2f] | 185 | virtual std::string typeString() const; |
---|
[51b7345] | 186 | }; |
---|
| 187 | |
---|
[17cd4eb] | 188 | class AggregateDecl : public Declaration { |
---|
[0dd3a2f] | 189 | typedef Declaration Parent; |
---|
[17cd4eb] | 190 | public: |
---|
[0dd3a2f] | 191 | AggregateDecl( const std::string &name ); |
---|
| 192 | AggregateDecl( const AggregateDecl &other ); |
---|
| 193 | virtual ~AggregateDecl(); |
---|
[51b7345] | 194 | |
---|
[0dd3a2f] | 195 | std::list<Declaration*>& get_members() { return members; } |
---|
| 196 | std::list<TypeDecl*>& get_parameters() { return parameters; } |
---|
[17cd4eb] | 197 | |
---|
[0dd3a2f] | 198 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 199 | virtual void printShort( std::ostream &os, int indent = 0 ) const; |
---|
[17cd4eb] | 200 | protected: |
---|
[0dd3a2f] | 201 | virtual std::string typeString() const = 0; |
---|
[17cd4eb] | 202 | |
---|
| 203 | private: |
---|
[0dd3a2f] | 204 | std::list<Declaration*> members; |
---|
| 205 | std::list<TypeDecl*> parameters; |
---|
[51b7345] | 206 | }; |
---|
| 207 | |
---|
[17cd4eb] | 208 | class StructDecl : public AggregateDecl { |
---|
[0dd3a2f] | 209 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 210 | public: |
---|
[0dd3a2f] | 211 | StructDecl( const std::string &name ) : Parent( name ) {} |
---|
| 212 | StructDecl( const StructDecl &other ) : Parent( other ) {} |
---|
[17cd4eb] | 213 | |
---|
[0dd3a2f] | 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 ); } |
---|
[51b7345] | 217 | |
---|
[17cd4eb] | 218 | private: |
---|
[0dd3a2f] | 219 | virtual std::string typeString() const; |
---|
[51b7345] | 220 | }; |
---|
| 221 | |
---|
[17cd4eb] | 222 | class UnionDecl : public AggregateDecl { |
---|
[0dd3a2f] | 223 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 224 | public: |
---|
[0dd3a2f] | 225 | UnionDecl( const std::string &name ) : Parent( name ) {} |
---|
| 226 | UnionDecl( const UnionDecl &other ) : Parent( other ) {} |
---|
[17cd4eb] | 227 | |
---|
[0dd3a2f] | 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 ); } |
---|
[17cd4eb] | 231 | private: |
---|
[0dd3a2f] | 232 | virtual std::string typeString() const; |
---|
[51b7345] | 233 | }; |
---|
| 234 | |
---|
[17cd4eb] | 235 | class EnumDecl : public AggregateDecl { |
---|
[0dd3a2f] | 236 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 237 | public: |
---|
[0dd3a2f] | 238 | EnumDecl( const std::string &name ) : Parent( name ) {} |
---|
| 239 | EnumDecl( const EnumDecl &other ) : Parent( other ) {} |
---|
[17cd4eb] | 240 | |
---|
[0dd3a2f] | 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 ); } |
---|
[17cd4eb] | 244 | private: |
---|
[0dd3a2f] | 245 | virtual std::string typeString() const; |
---|
[51b7345] | 246 | }; |
---|
| 247 | |
---|
[17cd4eb] | 248 | class ContextDecl : public AggregateDecl { |
---|
[0dd3a2f] | 249 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 250 | public: |
---|
[0dd3a2f] | 251 | ContextDecl( const std::string &name ) : Parent( name ) {} |
---|
| 252 | ContextDecl( const ContextDecl &other ) : Parent( other ) {} |
---|
[17cd4eb] | 253 | |
---|
[0dd3a2f] | 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 ); } |
---|
[17cd4eb] | 257 | private: |
---|
[0dd3a2f] | 258 | virtual std::string typeString() const; |
---|
[51b7345] | 259 | }; |
---|
| 260 | |
---|
[baf7fee] | 261 | std::ostream & operator<<( std::ostream & out, Declaration * decl ); |
---|
| 262 | |
---|
[17cd4eb] | 263 | #endif // DECLARATION_H |
---|
[0dd3a2f] | 264 | |
---|
| 265 | // Local Variables: // |
---|
| 266 | // tab-width: 4 // |
---|
| 267 | // mode: c++ // |
---|
| 268 | // compile-command: "make install" // |
---|
| 269 | // End: // |
---|