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