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