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