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