| 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
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Sat Jun 13 09:10:31 2015
|
|---|
| 13 | // Update Count : 25
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 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"
|
|---|
| 23 | #include "Parser/ParseNode.h"
|
|---|
| 24 |
|
|---|
| 25 | class Declaration {
|
|---|
| 26 | public:
|
|---|
| 27 | Declaration( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
|
|---|
| 28 | Declaration( const Declaration &other );
|
|---|
| 29 | virtual ~Declaration();
|
|---|
| 30 |
|
|---|
| 31 | const std::string &get_name() const { return name; }
|
|---|
| 32 | void set_name( std::string newValue ) { name = newValue; }
|
|---|
| 33 | DeclarationNode::StorageClass get_storageClass() const { return storageClass; }
|
|---|
| 34 | void set_storageClass( DeclarationNode::StorageClass newValue ) { storageClass = newValue; }
|
|---|
| 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 );
|
|---|
| 48 | private:
|
|---|
| 49 | std::string name;
|
|---|
| 50 | DeclarationNode::StorageClass storageClass;
|
|---|
| 51 | LinkageSpec::Type linkage;
|
|---|
| 52 | UniqueId uniqueId;
|
|---|
| 53 | };
|
|---|
| 54 |
|
|---|
| 55 | class DeclarationWithType : public Declaration {
|
|---|
| 56 | public:
|
|---|
| 57 | DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
|
|---|
| 58 | DeclarationWithType( const DeclarationWithType &other );
|
|---|
| 59 | virtual ~DeclarationWithType();
|
|---|
| 60 |
|
|---|
| 61 | std::string get_mangleName() const { return mangleName; }
|
|---|
| 62 | void set_mangleName( std::string newValue ) { mangleName = newValue; }
|
|---|
| 63 |
|
|---|
| 64 | virtual DeclarationWithType *clone() const = 0;
|
|---|
| 65 | virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
|
|---|
| 66 |
|
|---|
| 67 | virtual Type *get_type() const = 0;
|
|---|
| 68 | virtual void set_type(Type *) = 0;
|
|---|
| 69 | private:
|
|---|
| 70 | // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
|
|---|
| 71 | std::string mangleName;
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | class ObjectDecl : public DeclarationWithType {
|
|---|
| 75 | typedef DeclarationWithType Parent;
|
|---|
| 76 | public:
|
|---|
| 77 | ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init );
|
|---|
| 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;
|
|---|
| 94 | private:
|
|---|
| 95 | Type *type;
|
|---|
| 96 | Initializer *init;
|
|---|
| 97 | Expression *bitfieldWidth;
|
|---|
| 98 | };
|
|---|
| 99 |
|
|---|
| 100 | class FunctionDecl : public DeclarationWithType {
|
|---|
| 101 | typedef DeclarationWithType Parent;
|
|---|
| 102 | public:
|
|---|
| 103 | FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn );
|
|---|
| 104 | FunctionDecl( const FunctionDecl &other );
|
|---|
| 105 | virtual ~FunctionDecl();
|
|---|
| 106 |
|
|---|
| 107 | Type *get_type() const;
|
|---|
| 108 | virtual void set_type(Type *);
|
|---|
| 109 |
|
|---|
| 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; }
|
|---|
| 114 | bool get_isInline() const { return isInline; }
|
|---|
| 115 | bool get_isNoreturn() const { return isNoreturn; }
|
|---|
| 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;
|
|---|
| 124 | private:
|
|---|
| 125 | FunctionType *type;
|
|---|
| 126 | CompoundStmt *statements;
|
|---|
| 127 | bool isInline, isNoreturn;
|
|---|
| 128 | std::list< std::string > oldIdents;
|
|---|
| 129 | std::list< Declaration* > oldDecls;
|
|---|
| 130 | };
|
|---|
| 131 |
|
|---|
| 132 | class NamedTypeDecl : public Declaration {
|
|---|
| 133 | typedef Declaration Parent;
|
|---|
| 134 | public:
|
|---|
| 135 | NamedTypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type );
|
|---|
| 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;
|
|---|
| 147 | protected:
|
|---|
| 148 | virtual std::string typeString() const = 0;
|
|---|
| 149 | private:
|
|---|
| 150 | Type *base;
|
|---|
| 151 | std::list< TypeDecl* > parameters;
|
|---|
| 152 | std::list< DeclarationWithType* > assertions;
|
|---|
| 153 | };
|
|---|
| 154 |
|
|---|
| 155 | class TypeDecl : public NamedTypeDecl {
|
|---|
| 156 | typedef NamedTypeDecl Parent;
|
|---|
| 157 | public:
|
|---|
| 158 | enum Kind { Any, Dtype, Ftype };
|
|---|
| 159 |
|
|---|
| 160 | TypeDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type, Kind kind );
|
|---|
| 161 | TypeDecl( const TypeDecl &other );
|
|---|
| 162 |
|
|---|
| 163 | Kind get_kind() const { return kind; }
|
|---|
| 164 |
|
|---|
| 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 ); }
|
|---|
| 168 | private:
|
|---|
| 169 | virtual std::string typeString() const;
|
|---|
| 170 | Kind kind;
|
|---|
| 171 | };
|
|---|
| 172 |
|
|---|
| 173 | class TypedefDecl : public NamedTypeDecl {
|
|---|
| 174 | typedef NamedTypeDecl Parent;
|
|---|
| 175 | public:
|
|---|
| 176 | TypedefDecl( const std::string &name, DeclarationNode::StorageClass sc, Type *type ) : Parent( name, sc, type ) {}
|
|---|
| 177 | TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
|
|---|
| 178 |
|
|---|
| 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 ); }
|
|---|
| 182 | private:
|
|---|
| 183 | virtual std::string typeString() const;
|
|---|
| 184 | };
|
|---|
| 185 |
|
|---|
| 186 | class AggregateDecl : public Declaration {
|
|---|
| 187 | typedef Declaration Parent;
|
|---|
| 188 | public:
|
|---|
| 189 | AggregateDecl( const std::string &name );
|
|---|
| 190 | AggregateDecl( const AggregateDecl &other );
|
|---|
| 191 | virtual ~AggregateDecl();
|
|---|
| 192 |
|
|---|
| 193 | std::list<Declaration*>& get_members() { return members; }
|
|---|
| 194 | std::list<TypeDecl*>& get_parameters() { return parameters; }
|
|---|
| 195 |
|
|---|
| 196 | virtual void print( std::ostream &os, int indent = 0 ) const;
|
|---|
| 197 | virtual void printShort( std::ostream &os, int indent = 0 ) const;
|
|---|
| 198 | protected:
|
|---|
| 199 | virtual std::string typeString() const = 0;
|
|---|
| 200 |
|
|---|
| 201 | private:
|
|---|
| 202 | std::list<Declaration*> members;
|
|---|
| 203 | std::list<TypeDecl*> parameters;
|
|---|
| 204 | };
|
|---|
| 205 |
|
|---|
| 206 | class StructDecl : public AggregateDecl {
|
|---|
| 207 | typedef AggregateDecl Parent;
|
|---|
| 208 | public:
|
|---|
| 209 | StructDecl( const std::string &name ) : Parent( name ) {}
|
|---|
| 210 | StructDecl( const StructDecl &other ) : Parent( other ) {}
|
|---|
| 211 |
|
|---|
| 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 ); }
|
|---|
| 215 |
|
|---|
| 216 | private:
|
|---|
| 217 | virtual std::string typeString() const;
|
|---|
| 218 | };
|
|---|
| 219 |
|
|---|
| 220 | class UnionDecl : public AggregateDecl {
|
|---|
| 221 | typedef AggregateDecl Parent;
|
|---|
| 222 | public:
|
|---|
| 223 | UnionDecl( const std::string &name ) : Parent( name ) {}
|
|---|
| 224 | UnionDecl( const UnionDecl &other ) : Parent( other ) {}
|
|---|
| 225 |
|
|---|
| 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 ); }
|
|---|
| 229 | private:
|
|---|
| 230 | virtual std::string typeString() const;
|
|---|
| 231 | };
|
|---|
| 232 |
|
|---|
| 233 | class EnumDecl : public AggregateDecl {
|
|---|
| 234 | typedef AggregateDecl Parent;
|
|---|
| 235 | public:
|
|---|
| 236 | EnumDecl( const std::string &name ) : Parent( name ) {}
|
|---|
| 237 | EnumDecl( const EnumDecl &other ) : Parent( other ) {}
|
|---|
| 238 |
|
|---|
| 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 ); }
|
|---|
| 242 | private:
|
|---|
| 243 | virtual std::string typeString() const;
|
|---|
| 244 | };
|
|---|
| 245 |
|
|---|
| 246 | class ContextDecl : public AggregateDecl {
|
|---|
| 247 | typedef AggregateDecl Parent;
|
|---|
| 248 | public:
|
|---|
| 249 | ContextDecl( const std::string &name ) : Parent( name ) {}
|
|---|
| 250 | ContextDecl( const ContextDecl &other ) : Parent( other ) {}
|
|---|
| 251 |
|
|---|
| 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 ); }
|
|---|
| 255 | private:
|
|---|
| 256 | virtual std::string typeString() const;
|
|---|
| 257 | };
|
|---|
| 258 |
|
|---|
| 259 | #endif // DECLARATION_H
|
|---|
| 260 |
|
|---|
| 261 | // Local Variables: //
|
|---|
| 262 | // tab-width: 4 //
|
|---|
| 263 | // mode: c++ //
|
|---|
| 264 | // compile-command: "make install" //
|
|---|
| 265 | // End: //
|
|---|