[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
|
---|
[5f2f2d7] | 11 | // Last Modified By : Peter A. Buhr
|
---|
[de62360d] | 12 | // Last Modified On : Sat Jun 13 09:10:31 2015
|
---|
| 13 | // Update Count : 25
|
---|
[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"
|
---|
[51b73452] | 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; }
|
---|
| 37 | UniqueId get_uniqueId() const { return uniqueId; }
|
---|
| 38 |
|
---|
| 39 | void fixUniqueId( void );
|
---|
| 40 | virtual Declaration *clone() const = 0;
|
---|
| 41 | virtual void accept( Visitor &v ) = 0;
|
---|
| 42 | virtual Declaration *acceptMutator( Mutator &m ) = 0;
|
---|
| 43 | virtual void print( std::ostream &os, int indent = 0 ) const = 0;
|
---|
| 44 | virtual void printShort( std::ostream &os, int indent = 0 ) const = 0;
|
---|
| 45 |
|
---|
| 46 | static void dumpIds( std::ostream &os );
|
---|
| 47 | static Declaration *declFromId( UniqueId id );
|
---|
[17cd4eb] | 48 | private:
|
---|
[0dd3a2f] | 49 | std::string name;
|
---|
[68cd1ce] | 50 | DeclarationNode::StorageClass storageClass;
|
---|
[0dd3a2f] | 51 | LinkageSpec::Type linkage;
|
---|
| 52 | UniqueId uniqueId;
|
---|
[51b73452] | 53 | };
|
---|
| 54 |
|
---|
[17cd4eb] | 55 | class DeclarationWithType : public Declaration {
|
---|
| 56 | public:
|
---|
[68cd1ce] | 57 | DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
|
---|
[0dd3a2f] | 58 | DeclarationWithType( const DeclarationWithType &other );
|
---|
| 59 | virtual ~DeclarationWithType();
|
---|
[51b73452] | 60 |
|
---|
[0dd3a2f] | 61 | std::string get_mangleName() const { return mangleName; }
|
---|
| 62 | void set_mangleName( std::string newValue ) { mangleName = newValue; }
|
---|
[17cd4eb] | 63 |
|
---|
[0dd3a2f] | 64 | virtual DeclarationWithType *clone() const = 0;
|
---|
| 65 | virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
|
---|
[17cd4eb] | 66 |
|
---|
[0dd3a2f] | 67 | virtual Type *get_type() const = 0;
|
---|
| 68 | virtual void set_type(Type *) = 0;
|
---|
[17cd4eb] | 69 | private:
|
---|
[0dd3a2f] | 70 | // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
|
---|
| 71 | std::string mangleName;
|
---|
[51b73452] | 72 | };
|
---|
| 73 |
|
---|
[17cd4eb] | 74 | class ObjectDecl : public DeclarationWithType {
|
---|
[0dd3a2f] | 75 | typedef DeclarationWithType Parent;
|
---|
[17cd4eb] | 76 | public:
|
---|
[68cd1ce] | 77 | ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init );
|
---|
[0dd3a2f] | 78 | ObjectDecl( const ObjectDecl &other );
|
---|
| 79 | virtual ~ObjectDecl();
|
---|
| 80 |
|
---|
| 81 | virtual Type *get_type() const { return type; }
|
---|
| 82 | virtual void set_type(Type *newType) { type = newType; }
|
---|
| 83 |
|
---|
| 84 | Initializer *get_init() const { return init; }
|
---|
| 85 | void set_init( Initializer *newValue ) { init = newValue; }
|
---|
| 86 | Expression *get_bitfieldWidth() const { return bitfieldWidth; }
|
---|
| 87 | void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
|
---|
| 88 |
|
---|
| 89 | virtual ObjectDecl *clone() const { return new ObjectDecl( *this ); }
|
---|
| 90 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 91 | virtual ObjectDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
| 92 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 93 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 94 | private:
|
---|
[0dd3a2f] | 95 | Type *type;
|
---|
| 96 | Initializer *init;
|
---|
| 97 | Expression *bitfieldWidth;
|
---|
[51b73452] | 98 | };
|
---|
| 99 |
|
---|
[17cd4eb] | 100 | class FunctionDecl : public DeclarationWithType {
|
---|
[0dd3a2f] | 101 | typedef DeclarationWithType Parent;
|
---|
[17cd4eb] | 102 | public:
|
---|
[de62360d] | 103 | FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn );
|
---|
[0dd3a2f] | 104 | FunctionDecl( const FunctionDecl &other );
|
---|
| 105 | virtual ~FunctionDecl();
|
---|
[51b73452] | 106 |
|
---|
[0dd3a2f] | 107 | Type *get_type() const;
|
---|
| 108 | virtual void set_type(Type *);
|
---|
[51b73452] | 109 |
|
---|
[0dd3a2f] | 110 | FunctionType *get_functionType() const { return type; }
|
---|
| 111 | void set_functionType( FunctionType *newValue ) { type = newValue; }
|
---|
| 112 | CompoundStmt *get_statements() const { return statements; }
|
---|
| 113 | void set_statements( CompoundStmt *newValue ) { statements = newValue; }
|
---|
[7c64920] | 114 | bool get_isInline() const { return isInline; }
|
---|
[de62360d] | 115 | bool get_isNoreturn() const { return isNoreturn; }
|
---|
[0dd3a2f] | 116 | std::list< std::string >& get_oldIdents() { return oldIdents; }
|
---|
| 117 | std::list< Declaration* >& get_oldDecls() { return oldDecls; }
|
---|
| 118 |
|
---|
| 119 | virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
|
---|
| 120 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 121 | virtual DeclarationWithType *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
| 122 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 123 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 124 | private:
|
---|
[0dd3a2f] | 125 | FunctionType *type;
|
---|
| 126 | CompoundStmt *statements;
|
---|
[de62360d] | 127 | bool isInline, isNoreturn;
|
---|
[0dd3a2f] | 128 | std::list< std::string > oldIdents;
|
---|
| 129 | std::list< Declaration* > oldDecls;
|
---|
[51b73452] | 130 | };
|
---|
| 131 |
|
---|
[17cd4eb] | 132 | class NamedTypeDecl : public Declaration {
|
---|
[0dd3a2f] | 133 | typedef Declaration Parent;
|
---|
[17cd4eb] | 134 | public:
|
---|
[68cd1ce] | 135 | NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
|
---|
[0dd3a2f] | 136 | NamedTypeDecl( const TypeDecl &other );
|
---|
| 137 | virtual ~NamedTypeDecl();
|
---|
| 138 |
|
---|
| 139 | Type *get_base() const { return base; }
|
---|
| 140 | void set_base( Type *newValue ) { base = newValue; }
|
---|
| 141 | std::list< TypeDecl* >& get_parameters() { return parameters; }
|
---|
| 142 | std::list< DeclarationWithType* >& get_assertions() { return assertions; }
|
---|
| 143 |
|
---|
| 144 | virtual NamedTypeDecl *clone() const = 0;
|
---|
| 145 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 146 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 147 | protected:
|
---|
[0dd3a2f] | 148 | virtual std::string typeString() const = 0;
|
---|
[17cd4eb] | 149 | private:
|
---|
[0dd3a2f] | 150 | Type *base;
|
---|
| 151 | std::list< TypeDecl* > parameters;
|
---|
| 152 | std::list< DeclarationWithType* > assertions;
|
---|
[51b73452] | 153 | };
|
---|
| 154 |
|
---|
[17cd4eb] | 155 | class TypeDecl : public NamedTypeDecl {
|
---|
[0dd3a2f] | 156 | typedef NamedTypeDecl Parent;
|
---|
[17cd4eb] | 157 | public:
|
---|
[0dd3a2f] | 158 | enum Kind { Any, Dtype, Ftype };
|
---|
[51b73452] | 159 |
|
---|
[68cd1ce] | 160 | TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
|
---|
[0dd3a2f] | 161 | TypeDecl( const TypeDecl &other );
|
---|
[17cd4eb] | 162 |
|
---|
[0dd3a2f] | 163 | Kind get_kind() const { return kind; }
|
---|
[51b73452] | 164 |
|
---|
[0dd3a2f] | 165 | virtual TypeDecl *clone() const { return new TypeDecl( *this ); }
|
---|
| 166 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 167 | virtual TypeDecl *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 168 | private:
|
---|
[0dd3a2f] | 169 | virtual std::string typeString() const;
|
---|
| 170 | Kind kind;
|
---|
[51b73452] | 171 | };
|
---|
| 172 |
|
---|
[17cd4eb] | 173 | class TypedefDecl : public NamedTypeDecl {
|
---|
[0dd3a2f] | 174 | typedef NamedTypeDecl Parent;
|
---|
[17cd4eb] | 175 | public:
|
---|
[68cd1ce] | 176 | TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
|
---|
[0dd3a2f] | 177 | TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 178 |
|
---|
[0dd3a2f] | 179 | virtual TypedefDecl *clone() const { return new TypedefDecl( *this ); }
|
---|
| 180 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 181 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 182 | private:
|
---|
[0dd3a2f] | 183 | virtual std::string typeString() const;
|
---|
[51b73452] | 184 | };
|
---|
| 185 |
|
---|
[17cd4eb] | 186 | class AggregateDecl : public Declaration {
|
---|
[0dd3a2f] | 187 | typedef Declaration Parent;
|
---|
[17cd4eb] | 188 | public:
|
---|
[0dd3a2f] | 189 | AggregateDecl( const std::string &name );
|
---|
| 190 | AggregateDecl( const AggregateDecl &other );
|
---|
| 191 | virtual ~AggregateDecl();
|
---|
[51b73452] | 192 |
|
---|
[0dd3a2f] | 193 | std::list<Declaration*>& get_members() { return members; }
|
---|
| 194 | std::list<TypeDecl*>& get_parameters() { return parameters; }
|
---|
[17cd4eb] | 195 |
|
---|
[0dd3a2f] | 196 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
---|
| 197 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
---|
[17cd4eb] | 198 | protected:
|
---|
[0dd3a2f] | 199 | virtual std::string typeString() const = 0;
|
---|
[17cd4eb] | 200 |
|
---|
| 201 | private:
|
---|
[0dd3a2f] | 202 | std::list<Declaration*> members;
|
---|
| 203 | std::list<TypeDecl*> parameters;
|
---|
[51b73452] | 204 | };
|
---|
| 205 |
|
---|
[17cd4eb] | 206 | class StructDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 207 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 208 | public:
|
---|
[0dd3a2f] | 209 | StructDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 210 | StructDecl( const StructDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 211 |
|
---|
[0dd3a2f] | 212 | virtual StructDecl *clone() const { return new StructDecl( *this ); }
|
---|
| 213 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 214 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[51b73452] | 215 |
|
---|
[17cd4eb] | 216 | private:
|
---|
[0dd3a2f] | 217 | virtual std::string typeString() const;
|
---|
[51b73452] | 218 | };
|
---|
| 219 |
|
---|
[17cd4eb] | 220 | class UnionDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 221 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 222 | public:
|
---|
[0dd3a2f] | 223 | UnionDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 224 | UnionDecl( const UnionDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 225 |
|
---|
[0dd3a2f] | 226 | virtual UnionDecl *clone() const { return new UnionDecl( *this ); }
|
---|
| 227 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 228 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 229 | private:
|
---|
[0dd3a2f] | 230 | virtual std::string typeString() const;
|
---|
[51b73452] | 231 | };
|
---|
| 232 |
|
---|
[17cd4eb] | 233 | class EnumDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 234 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 235 | public:
|
---|
[0dd3a2f] | 236 | EnumDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 237 | EnumDecl( const EnumDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 238 |
|
---|
[0dd3a2f] | 239 | virtual EnumDecl *clone() const { return new EnumDecl( *this ); }
|
---|
| 240 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 241 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 242 | private:
|
---|
[0dd3a2f] | 243 | virtual std::string typeString() const;
|
---|
[51b73452] | 244 | };
|
---|
| 245 |
|
---|
[17cd4eb] | 246 | class ContextDecl : public AggregateDecl {
|
---|
[0dd3a2f] | 247 | typedef AggregateDecl Parent;
|
---|
[17cd4eb] | 248 | public:
|
---|
[0dd3a2f] | 249 | ContextDecl( const std::string &name ) : Parent( name ) {}
|
---|
| 250 | ContextDecl( const ContextDecl &other ) : Parent( other ) {}
|
---|
[17cd4eb] | 251 |
|
---|
[0dd3a2f] | 252 | virtual ContextDecl *clone() const { return new ContextDecl( *this ); }
|
---|
| 253 | virtual void accept( Visitor &v ) { v.visit( this ); }
|
---|
| 254 | virtual Declaration *acceptMutator( Mutator &m ) { return m.mutate( this ); }
|
---|
[17cd4eb] | 255 | private:
|
---|
[0dd3a2f] | 256 | virtual std::string typeString() const;
|
---|
[51b73452] | 257 | };
|
---|
| 258 |
|
---|
[17cd4eb] | 259 | #endif // DECLARATION_H
|
---|
[0dd3a2f] | 260 |
|
---|
| 261 | // Local Variables: //
|
---|
| 262 | // tab-width: 4 //
|
---|
| 263 | // mode: c++ //
|
---|
| 264 | // compile-command: "make install" //
|
---|
| 265 | // End: //
|
---|