[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 |
---|
[0c730d9] | 11 | // Last Modified By : Henry Xue |
---|
| 12 | // Last Modified On : Tue Jul 20 04:10:50 2021 |
---|
| 13 | // Update Count : 160 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[ea6332d] | 18 | #include <cassert> // for assertf |
---|
| 19 | #include <iosfwd> // for ostream |
---|
| 20 | #include <list> // for list |
---|
[1690778] | 21 | #include <unordered_map> // for unordered_map |
---|
[ea6332d] | 22 | #include <string> // for string, operator+, allocator, to_string |
---|
| 23 | |
---|
| 24 | #include "BaseSyntaxNode.h" // for BaseSyntaxNode |
---|
| 25 | #include "Mutator.h" // for Mutator |
---|
[07de76b] | 26 | #include "LinkageSpec.h" // for Spec, Cforall |
---|
[ea6332d] | 27 | #include "SynTree.h" // for UniqueId |
---|
| 28 | #include "SynTree/Type.h" // for Type, Type::StorageClasses, Type::Fu... |
---|
| 29 | #include "Visitor.h" // for Visitor |
---|
| 30 | |
---|
| 31 | class AsmStmt; |
---|
| 32 | class Attribute; |
---|
| 33 | class CompoundStmt; |
---|
| 34 | class ConstantExpr; |
---|
| 35 | class Expression; |
---|
| 36 | class Initializer; |
---|
| 37 | class TypeDecl; |
---|
[51b7345] | 38 | |
---|
[294647b] | 39 | class Declaration : public BaseSyntaxNode { |
---|
[17cd4eb] | 40 | public: |
---|
[65cdc1e] | 41 | std::string name; |
---|
| 42 | LinkageSpec::Spec linkage; |
---|
| 43 | bool extension = false; |
---|
| 44 | |
---|
[07de76b] | 45 | Declaration( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ); |
---|
| 46 | Declaration( const Declaration & other ); |
---|
[0dd3a2f] | 47 | virtual ~Declaration(); |
---|
| 48 | |
---|
[07de76b] | 49 | const std::string & get_name() const { return name; } |
---|
[0dd3a2f] | 50 | void set_name( std::string newValue ) { name = newValue; } |
---|
[a7c90d4] | 51 | |
---|
[68fe077a] | 52 | Type::StorageClasses get_storageClasses() const { return storageClasses; } |
---|
[a7c90d4] | 53 | |
---|
[8b7ee09] | 54 | LinkageSpec::Spec get_linkage() const { return linkage; } |
---|
| 55 | void set_linkage( LinkageSpec::Spec newValue ) { linkage = newValue; } |
---|
[a7c90d4] | 56 | |
---|
[0dd3a2f] | 57 | UniqueId get_uniqueId() const { return uniqueId; } |
---|
[a7c90d4] | 58 | |
---|
[8e9cbb2] | 59 | bool get_extension() const { return extension; } |
---|
[07de76b] | 60 | Declaration * set_extension( bool exten ) { extension = exten; return this; } |
---|
[0dd3a2f] | 61 | |
---|
| 62 | void fixUniqueId( void ); |
---|
[07de76b] | 63 | virtual Declaration * clone() const override = 0; |
---|
[7870799] | 64 | virtual void accept( Visitor & v ) override = 0; |
---|
| 65 | virtual void accept( Visitor & v ) const override = 0; |
---|
[07de76b] | 66 | virtual Declaration * acceptMutator( Mutator & m ) override = 0; |
---|
| 67 | virtual void print( std::ostream & os, Indenter indent = {} ) const override = 0; |
---|
| 68 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const = 0; |
---|
[0dd3a2f] | 69 | |
---|
| 70 | UniqueId uniqueId; |
---|
[1f93c2c] | 71 | Type::StorageClasses storageClasses; |
---|
| 72 | private: |
---|
[51b7345] | 73 | }; |
---|
| 74 | |
---|
[17cd4eb] | 75 | class DeclarationWithType : public Declaration { |
---|
| 76 | public: |
---|
[65cdc1e] | 77 | // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2 |
---|
| 78 | std::string mangleName; |
---|
| 79 | // need to remember the scope level at which the variable was declared, so that shadowed identifiers can be accessed |
---|
| 80 | int scopeLevel = 0; |
---|
| 81 | |
---|
[07de76b] | 82 | Expression * asmName; |
---|
[65cdc1e] | 83 | std::list< Attribute * > attributes; |
---|
[3ed994e] | 84 | bool isDeleted = false; |
---|
[65cdc1e] | 85 | |
---|
[07de76b] | 86 | DeclarationWithType( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs ); |
---|
| 87 | DeclarationWithType( const DeclarationWithType & other ); |
---|
[0dd3a2f] | 88 | virtual ~DeclarationWithType(); |
---|
[51b7345] | 89 | |
---|
[0dd3a2f] | 90 | std::string get_mangleName() const { return mangleName; } |
---|
[58dd019] | 91 | DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; } |
---|
[17cd4eb] | 92 | |
---|
[f326f99] | 93 | std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); } |
---|
| 94 | |
---|
| 95 | int get_scopeLevel() const { return scopeLevel; } |
---|
[58dd019] | 96 | DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; } |
---|
| 97 | |
---|
[07de76b] | 98 | Expression * get_asmName() const { return asmName; } |
---|
| 99 | DeclarationWithType * set_asmName( Expression * newValue ) { asmName = newValue; return this; } |
---|
[f326f99] | 100 | |
---|
[f9cebb5] | 101 | std::list< Attribute * >& get_attributes() { return attributes; } |
---|
| 102 | const std::list< Attribute * >& get_attributes() const { return attributes; } |
---|
| 103 | |
---|
[ddfd945] | 104 | Type::FuncSpecifiers get_funcSpec() const { return fs; } |
---|
| 105 | //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; } |
---|
[dd020c0] | 106 | |
---|
[07de76b] | 107 | virtual DeclarationWithType * clone() const override = 0; |
---|
| 108 | virtual DeclarationWithType * acceptMutator( Mutator & m ) override = 0; |
---|
[17cd4eb] | 109 | |
---|
[9aaac6e9] | 110 | virtual Type * get_type() const = 0; |
---|
[0dd3a2f] | 111 | virtual void set_type(Type *) = 0; |
---|
[f9cebb5] | 112 | |
---|
[65cdc1e] | 113 | private: |
---|
[ddfd945] | 114 | Type::FuncSpecifiers fs; |
---|
[51b7345] | 115 | }; |
---|
| 116 | |
---|
[17cd4eb] | 117 | class ObjectDecl : public DeclarationWithType { |
---|
[0dd3a2f] | 118 | typedef DeclarationWithType Parent; |
---|
[17cd4eb] | 119 | public: |
---|
[07de76b] | 120 | Type * type; |
---|
[32fc0d6] | 121 | Initializer * init; |
---|
[07de76b] | 122 | Expression * bitfieldWidth; |
---|
[1e30df7] | 123 | bool enumInLine = false; |
---|
[65cdc1e] | 124 | |
---|
[07de76b] | 125 | ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression * bitfieldWidth, Type * type, Initializer * init, |
---|
[ddfd945] | 126 | const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); |
---|
[07de76b] | 127 | ObjectDecl( const ObjectDecl & other ); |
---|
[0dd3a2f] | 128 | virtual ~ObjectDecl(); |
---|
| 129 | |
---|
[e149f77] | 130 | virtual Type * get_type() const override { return type; } |
---|
[07de76b] | 131 | virtual void set_type(Type * newType) override { type = newType; } |
---|
[0dd3a2f] | 132 | |
---|
[07de76b] | 133 | Initializer * get_init() const { return init; } |
---|
| 134 | void set_init( Initializer * newValue ) { init = newValue; } |
---|
[58dd019] | 135 | |
---|
[07de76b] | 136 | Expression * get_bitfieldWidth() const { return bitfieldWidth; } |
---|
| 137 | void set_bitfieldWidth( Expression * newValue ) { bitfieldWidth = newValue; } |
---|
[0dd3a2f] | 138 | |
---|
[96f9ef5] | 139 | static ObjectDecl * newObject( const std::string & name, Type * type, Initializer * init ); |
---|
| 140 | |
---|
[07de76b] | 141 | virtual ObjectDecl * clone() const override { return new ObjectDecl( *this ); } |
---|
[7870799] | 142 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 143 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 144 | virtual DeclarationWithType * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 145 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 146 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[32fc0d6] | 147 | |
---|
| 148 | void checkAssignedValue() const; |
---|
[51b7345] | 149 | }; |
---|
| 150 | |
---|
[17cd4eb] | 151 | class FunctionDecl : public DeclarationWithType { |
---|
[0dd3a2f] | 152 | typedef DeclarationWithType Parent; |
---|
[17cd4eb] | 153 | public: |
---|
[07de76b] | 154 | FunctionType * type; |
---|
| 155 | CompoundStmt * statements; |
---|
[574894d] | 156 | std::list< Expression * > withExprs; |
---|
[65cdc1e] | 157 | |
---|
[07de76b] | 158 | FunctionDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType * type, CompoundStmt * statements, |
---|
[ddfd945] | 159 | const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); |
---|
[07de76b] | 160 | FunctionDecl( const FunctionDecl & other ); |
---|
[0dd3a2f] | 161 | virtual ~FunctionDecl(); |
---|
[51b7345] | 162 | |
---|
[e149f77] | 163 | virtual Type * get_type() const override { return type; } |
---|
| 164 | virtual void set_type(Type * t) override { type = strict_dynamic_cast< FunctionType* >( t ); } |
---|
[51b7345] | 165 | |
---|
[9aaac6e9] | 166 | FunctionType * get_functionType() const { return type; } |
---|
[07de76b] | 167 | void set_functionType( FunctionType * newValue ) { type = newValue; } |
---|
| 168 | CompoundStmt * get_statements() const { return statements; } |
---|
| 169 | void set_statements( CompoundStmt * newValue ) { statements = newValue; } |
---|
[76f7fc7] | 170 | bool has_body() const { return NULL != statements; } |
---|
[0dd3a2f] | 171 | |
---|
[75626a1] | 172 | static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements ); |
---|
| 173 | |
---|
[07de76b] | 174 | virtual FunctionDecl * clone() const override { return new FunctionDecl( *this ); } |
---|
[7870799] | 175 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 176 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 177 | virtual DeclarationWithType * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 178 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 179 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 180 | }; |
---|
| 181 | |
---|
[17cd4eb] | 182 | class NamedTypeDecl : public Declaration { |
---|
[0dd3a2f] | 183 | typedef Declaration Parent; |
---|
[17cd4eb] | 184 | public: |
---|
[07de76b] | 185 | Type * base; |
---|
| 186 | std::list< DeclarationWithType * > assertions; |
---|
[65cdc1e] | 187 | |
---|
[07de76b] | 188 | NamedTypeDecl( const std::string & name, Type::StorageClasses scs, Type * type ); |
---|
| 189 | NamedTypeDecl( const NamedTypeDecl & other ); |
---|
[0dd3a2f] | 190 | virtual ~NamedTypeDecl(); |
---|
| 191 | |
---|
[07de76b] | 192 | Type * get_base() const { return base; } |
---|
| 193 | void set_base( Type * newValue ) { base = newValue; } |
---|
| 194 | std::list< DeclarationWithType * >& get_assertions() { return assertions; } |
---|
[0dd3a2f] | 195 | |
---|
[312029a] | 196 | virtual const char * typeString() const = 0; |
---|
[e39241b] | 197 | |
---|
[07de76b] | 198 | virtual NamedTypeDecl * clone() const override = 0; |
---|
| 199 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 200 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 201 | }; |
---|
| 202 | |
---|
[17cd4eb] | 203 | class TypeDecl : public NamedTypeDecl { |
---|
[0dd3a2f] | 204 | typedef NamedTypeDecl Parent; |
---|
[17cd4eb] | 205 | public: |
---|
[6e50a6b] | 206 | enum Kind { Dtype, DStype, Otype, Ftype, Ttype, Dimension, NUMBER_OF_KINDS }; |
---|
[65cdc1e] | 207 | |
---|
[07de76b] | 208 | Kind kind; |
---|
[65cdc1e] | 209 | bool sized; |
---|
[07de76b] | 210 | Type * init; |
---|
[65cdc1e] | 211 | |
---|
[2c57025] | 212 | /// Data extracted from a type decl |
---|
| 213 | struct Data { |
---|
[07de76b] | 214 | Kind kind; |
---|
[2c57025] | 215 | bool isComplete; |
---|
[1f93c2c] | 216 | |
---|
[07de76b] | 217 | Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {} |
---|
| 218 | Data( const TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {} |
---|
[2c57025] | 219 | Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {} |
---|
[07de76b] | 220 | Data( const Data & d1, const Data & d2 ) |
---|
| 221 | : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} |
---|
[7a63486] | 222 | |
---|
[07de76b] | 223 | bool operator==( const Data & other ) const { return kind == other.kind && isComplete == other.isComplete; } |
---|
| 224 | bool operator!=( const Data & other ) const { return !(*this == other);} |
---|
[2c57025] | 225 | }; |
---|
[51b7345] | 226 | |
---|
[07de76b] | 227 | TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init = nullptr ); |
---|
| 228 | TypeDecl( const TypeDecl & other ); |
---|
[67cf18c] | 229 | virtual ~TypeDecl(); |
---|
[17cd4eb] | 230 | |
---|
[0dd3a2f] | 231 | Kind get_kind() const { return kind; } |
---|
[51b7345] | 232 | |
---|
[67cf18c] | 233 | Type * get_init() const { return init; } |
---|
| 234 | TypeDecl * set_init( Type * newValue ) { init = newValue; return this; } |
---|
| 235 | |
---|
[f0ecf9b] | 236 | bool isComplete() const { return sized; } |
---|
[2c57025] | 237 | bool get_sized() const { return sized; } |
---|
| 238 | TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; } |
---|
| 239 | |
---|
[312029a] | 240 | virtual const char * typeString() const override; |
---|
| 241 | virtual const char * genTypeString() const; |
---|
[e39241b] | 242 | |
---|
[07de76b] | 243 | virtual TypeDecl * clone() const override { return new TypeDecl( *this ); } |
---|
[7870799] | 244 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 245 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 246 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 247 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 248 | }; |
---|
| 249 | |
---|
[17cd4eb] | 250 | class TypedefDecl : public NamedTypeDecl { |
---|
[0dd3a2f] | 251 | typedef NamedTypeDecl Parent; |
---|
[17cd4eb] | 252 | public: |
---|
[07de76b] | 253 | TypedefDecl( const std::string & name, CodeLocation location, Type::StorageClasses scs, Type * type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) |
---|
[0b0f1dd] | 254 | : Parent( name, scs, type ) { set_linkage( spec ); this->location = location; } |
---|
| 255 | |
---|
[07de76b] | 256 | TypedefDecl( const TypedefDecl & other ) : Parent( other ) {} |
---|
[17cd4eb] | 257 | |
---|
[312029a] | 258 | virtual const char * typeString() const override; |
---|
[e39241b] | 259 | |
---|
[07de76b] | 260 | virtual TypedefDecl * clone() const override { return new TypedefDecl( *this ); } |
---|
[7870799] | 261 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 262 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 263 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[17cd4eb] | 264 | private: |
---|
[51b7345] | 265 | }; |
---|
| 266 | |
---|
[17cd4eb] | 267 | class AggregateDecl : public Declaration { |
---|
[0dd3a2f] | 268 | typedef Declaration Parent; |
---|
[17cd4eb] | 269 | public: |
---|
[312029a] | 270 | enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate }; |
---|
| 271 | static const char * aggrString( Aggregate aggr ); |
---|
| 272 | |
---|
[65cdc1e] | 273 | std::list<Declaration*> members; |
---|
| 274 | std::list<TypeDecl*> parameters; |
---|
| 275 | bool body; |
---|
| 276 | std::list< Attribute * > attributes; |
---|
[29f9e20] | 277 | AggregateDecl * parent = nullptr; |
---|
[65cdc1e] | 278 | |
---|
[07de76b] | 279 | AggregateDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ); |
---|
| 280 | AggregateDecl( const AggregateDecl & other ); |
---|
[0dd3a2f] | 281 | virtual ~AggregateDecl(); |
---|
[51b7345] | 282 | |
---|
[0dd3a2f] | 283 | std::list<Declaration*>& get_members() { return members; } |
---|
| 284 | std::list<TypeDecl*>& get_parameters() { return parameters; } |
---|
[17cd4eb] | 285 | |
---|
[c0aa336] | 286 | std::list< Attribute * >& get_attributes() { return attributes; } |
---|
| 287 | const std::list< Attribute * >& get_attributes() const { return attributes; } |
---|
| 288 | |
---|
[5d125e4] | 289 | bool has_body() const { return body; } |
---|
| 290 | AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } |
---|
| 291 | |
---|
[4559b34] | 292 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[07de76b] | 293 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[17cd4eb] | 294 | protected: |
---|
[312029a] | 295 | virtual const char * typeString() const = 0; |
---|
[51b7345] | 296 | }; |
---|
| 297 | |
---|
[17cd4eb] | 298 | class StructDecl : public AggregateDecl { |
---|
[0dd3a2f] | 299 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 300 | public: |
---|
[07de76b] | 301 | StructDecl( const std::string & name, Aggregate kind = Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {} |
---|
| 302 | StructDecl( const StructDecl & other ) : Parent( other ), kind( other.kind ) {} |
---|
[17cd4eb] | 303 | |
---|
[312029a] | 304 | bool is_coroutine() { return kind == Coroutine; } |
---|
[0c730d9] | 305 | bool is_exception() { return kind == Exception; } |
---|
[427854b] | 306 | bool is_generator() { return kind == Generator; } |
---|
| 307 | bool is_monitor () { return kind == Monitor ; } |
---|
| 308 | bool is_thread () { return kind == Thread ; } |
---|
[409433da] | 309 | |
---|
[69c5c00] | 310 | // Make a type instance of this declaration. |
---|
| 311 | StructInstType * makeInst( std::list< Expression * > const & parameters ); |
---|
| 312 | StructInstType * makeInst( std::list< Expression * > && parameters ); |
---|
| 313 | |
---|
[07de76b] | 314 | virtual StructDecl * clone() const override { return new StructDecl( *this ); } |
---|
[7870799] | 315 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 316 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 317 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[312029a] | 318 | Aggregate kind; |
---|
[712348a] | 319 | private: |
---|
[312029a] | 320 | virtual const char * typeString() const override; |
---|
[51b7345] | 321 | }; |
---|
| 322 | |
---|
[17cd4eb] | 323 | class UnionDecl : public AggregateDecl { |
---|
[0dd3a2f] | 324 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 325 | public: |
---|
[07de76b] | 326 | UnionDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {} |
---|
| 327 | UnionDecl( const UnionDecl & other ) : Parent( other ) {} |
---|
[17cd4eb] | 328 | |
---|
[07de76b] | 329 | virtual UnionDecl * clone() const override { return new UnionDecl( *this ); } |
---|
[7870799] | 330 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 331 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 332 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[17cd4eb] | 333 | private: |
---|
[312029a] | 334 | virtual const char * typeString() const override; |
---|
[51b7345] | 335 | }; |
---|
| 336 | |
---|
[17cd4eb] | 337 | class EnumDecl : public AggregateDecl { |
---|
[0dd3a2f] | 338 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 339 | public: |
---|
[b0d9ff7] | 340 | bool isTyped; |
---|
| 341 | Type * base; |
---|
[e4d7c1c] | 342 | enum EnumHiding { Visible, Hide } hide; |
---|
[b0d9ff7] | 343 | |
---|
[f135b50] | 344 | EnumDecl( const std::string & name, |
---|
| 345 | const std::list< Attribute * > & attributes = std::list< class Attribute * >(), |
---|
[b0d9ff7] | 346 | bool isTyped = false, LinkageSpec::Spec linkage = LinkageSpec::Cforall, |
---|
| 347 | Type * baseType = nullptr ) |
---|
[e4d7c1c] | 348 | : Parent( name, attributes, linkage ), isTyped(isTyped), base( baseType ) {} |
---|
[b0d9ff7] | 349 | EnumDecl( const EnumDecl & other ) |
---|
| 350 | : Parent( other ), isTyped( other.isTyped), base( other.base ) {} |
---|
[fc9153d] | 351 | bool valueOf( Declaration * enumerator, long long int & value ); |
---|
[07de76b] | 352 | virtual EnumDecl * clone() const override { return new EnumDecl( *this ); } |
---|
[7870799] | 353 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 354 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 355 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[b0d9ff7] | 356 | |
---|
| 357 | std::unordered_map< std::string, long long int > enumValues; // This attribute is unused |
---|
[4559b34] | 358 | virtual void print( std::ostream & os, Indenter indent = {} ) const override final; |
---|
[f135b50] | 359 | private: |
---|
| 360 | // std::unordered_map< std::string, long long int > enumValues; |
---|
[312029a] | 361 | virtual const char * typeString() const override; |
---|
[51b7345] | 362 | }; |
---|
| 363 | |
---|
[4040425] | 364 | class TraitDecl : public AggregateDecl { |
---|
[0dd3a2f] | 365 | typedef AggregateDecl Parent; |
---|
[17cd4eb] | 366 | public: |
---|
[07de76b] | 367 | TraitDecl( const std::string & name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) { |
---|
[c0aa336] | 368 | assertf( attributes.empty(), "attribute unsupported for traits" ); |
---|
| 369 | } |
---|
[07de76b] | 370 | TraitDecl( const TraitDecl & other ) : Parent( other ) {} |
---|
[17cd4eb] | 371 | |
---|
[07de76b] | 372 | virtual TraitDecl * clone() const override { return new TraitDecl( *this ); } |
---|
[7870799] | 373 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 374 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 375 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[17cd4eb] | 376 | private: |
---|
[312029a] | 377 | virtual const char * typeString() const override; |
---|
[51b7345] | 378 | }; |
---|
| 379 | |
---|
[e67991f] | 380 | class WithStmt : public Declaration { |
---|
| 381 | public: |
---|
| 382 | std::list< Expression * > exprs; |
---|
| 383 | Statement * stmt; |
---|
| 384 | |
---|
| 385 | WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); |
---|
| 386 | WithStmt( const WithStmt & other ); |
---|
| 387 | virtual ~WithStmt(); |
---|
| 388 | |
---|
| 389 | virtual WithStmt * clone() const override { return new WithStmt( *this ); } |
---|
| 390 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 391 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 392 | virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 393 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 394 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override { print(os, indent); } |
---|
| 395 | }; |
---|
| 396 | |
---|
[e994912] | 397 | class AsmDecl : public Declaration { |
---|
| 398 | public: |
---|
[07de76b] | 399 | AsmStmt * stmt; |
---|
[65cdc1e] | 400 | |
---|
[07de76b] | 401 | AsmDecl( AsmStmt * stmt ); |
---|
| 402 | AsmDecl( const AsmDecl & other ); |
---|
[e994912] | 403 | virtual ~AsmDecl(); |
---|
| 404 | |
---|
[07de76b] | 405 | AsmStmt * get_stmt() { return stmt; } |
---|
| 406 | void set_stmt( AsmStmt * newValue ) { stmt = newValue; } |
---|
[e994912] | 407 | |
---|
[07de76b] | 408 | virtual AsmDecl * clone() const override { return new AsmDecl( *this ); } |
---|
[7870799] | 409 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 410 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 411 | virtual AsmDecl * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 412 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 413 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[2d019af] | 414 | }; |
---|
| 415 | |
---|
| 416 | class DirectiveDecl : public Declaration { |
---|
| 417 | public: |
---|
| 418 | DirectiveStmt * stmt; |
---|
| 419 | |
---|
| 420 | DirectiveDecl( DirectiveStmt * stmt ); |
---|
| 421 | DirectiveDecl( const DirectiveDecl & other ); |
---|
| 422 | virtual ~DirectiveDecl(); |
---|
| 423 | |
---|
| 424 | DirectiveStmt * get_stmt() { return stmt; } |
---|
| 425 | void set_stmt( DirectiveStmt * newValue ) { stmt = newValue; } |
---|
| 426 | |
---|
| 427 | virtual DirectiveDecl * clone() const override { return new DirectiveDecl( *this ); } |
---|
| 428 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 429 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 430 | virtual DirectiveDecl * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 431 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 432 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[e994912] | 433 | }; |
---|
| 434 | |
---|
[f6e3e34] | 435 | class StaticAssertDecl : public Declaration { |
---|
| 436 | public: |
---|
| 437 | Expression * condition; |
---|
| 438 | ConstantExpr * message; // string literal |
---|
| 439 | |
---|
| 440 | StaticAssertDecl( Expression * condition, ConstantExpr * message ); |
---|
| 441 | StaticAssertDecl( const StaticAssertDecl & other ); |
---|
| 442 | virtual ~StaticAssertDecl(); |
---|
| 443 | |
---|
| 444 | virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } |
---|
[7870799] | 445 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 446 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[07de76b] | 447 | virtual StaticAssertDecl * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 448 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 449 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
[f6e3e34] | 450 | }; |
---|
| 451 | |
---|
[e874605] | 452 | |
---|
[71806e0] | 453 | class InlineMemberDecl : public DeclarationWithType { |
---|
[e874605] | 454 | typedef DeclarationWithType Parent; |
---|
| 455 | public: |
---|
| 456 | Type * type; |
---|
| 457 | |
---|
[71806e0] | 458 | InlineMemberDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Type * type, |
---|
[e874605] | 459 | const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); |
---|
[71806e0] | 460 | InlineMemberDecl( const InlineMemberDecl & other ); |
---|
| 461 | virtual ~InlineMemberDecl(); |
---|
[e874605] | 462 | |
---|
| 463 | virtual Type * get_type() const override { return type; } |
---|
| 464 | virtual void set_type(Type * newType) override { type = newType; } |
---|
| 465 | |
---|
[71806e0] | 466 | static InlineMemberDecl * newInlineMemberDecl( const std::string & name, Type * type ); |
---|
[e874605] | 467 | |
---|
[71806e0] | 468 | virtual InlineMemberDecl * clone() const override { return new InlineMemberDecl( *this ); } |
---|
[e874605] | 469 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 470 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 471 | virtual DeclarationWithType * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 472 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 473 | virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 474 | |
---|
| 475 | }; |
---|
| 476 | |
---|
[2c57025] | 477 | std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ); |
---|
[baf7fee] | 478 | |
---|
[0dd3a2f] | 479 | // Local Variables: // |
---|
| 480 | // tab-width: 4 // |
---|
| 481 | // mode: c++ // |
---|
| 482 | // compile-command: "make install" // |
---|
| 483 | // End: // |
---|