[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 | // |
---|
[ae63a18] | 7 | // Type.h -- |
---|
[0dd3a2f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[65cdc1e] | 11 | // Last Modified By : Andrew Beach |
---|
| 12 | // Last Modified On : Wed Aug 9 14:25:00 2017 |
---|
| 13 | // Update Count : 152 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[138e29e] | 18 | #include "BaseSyntaxNode.h" |
---|
| 19 | #include "Mutator.h" |
---|
[51b7345] | 20 | #include "SynTree.h" |
---|
| 21 | #include "Visitor.h" |
---|
[6f95000] | 22 | #include <strings.h> // ffs |
---|
[51b7345] | 23 | |
---|
[138e29e] | 24 | class Type : public BaseSyntaxNode { |
---|
[c8ffe20b] | 25 | public: |
---|
[6f95000] | 26 | // Simulate inheritance because union does not allow it. |
---|
[615a096] | 27 | // Bug in g++-4.9 prevents static field in union |
---|
| 28 | //static const char * Names[]; |
---|
[6f95000] | 29 | #define BFCommon( BFType, N ) \ |
---|
[d6d747d] | 30 | bool operator[]( unsigned int i ) const { return val & (1 << i); } \ |
---|
| 31 | bool any() const { return val != 0; } \ |
---|
[6f95000] | 32 | void reset() { val = 0; } \ |
---|
| 33 | int ffs() { return ::ffs( val ) - 1; } \ |
---|
| 34 | BFType operator&=( BFType other ) { \ |
---|
| 35 | val &= other.val; return *this; \ |
---|
| 36 | } \ |
---|
| 37 | BFType operator&( BFType other ) const { \ |
---|
| 38 | BFType q = other; \ |
---|
| 39 | q &= *this; \ |
---|
| 40 | return q; \ |
---|
| 41 | } \ |
---|
| 42 | BFType operator|=( BFType other ) { \ |
---|
| 43 | val |= other.val; return *this; \ |
---|
| 44 | } \ |
---|
| 45 | BFType operator|( BFType other ) const { \ |
---|
| 46 | BFType q = other; \ |
---|
| 47 | q |= *this; \ |
---|
| 48 | return q; \ |
---|
| 49 | } \ |
---|
| 50 | BFType operator-=( BFType other ) { \ |
---|
| 51 | val &= ~other.val; return *this; \ |
---|
| 52 | } \ |
---|
[d6d747d] | 53 | void print( std::ostream & os ) const { \ |
---|
| 54 | if ( (*this).any() ) { \ |
---|
| 55 | for ( unsigned int i = 0; i < N; i += 1 ) { \ |
---|
| 56 | if ( (*this)[i] ) { \ |
---|
[615a096] | 57 | os << BFType##Names[i] << ' '; \ |
---|
[d6d747d] | 58 | } \ |
---|
| 59 | } \ |
---|
| 60 | } \ |
---|
| 61 | } |
---|
| 62 | |
---|
[68fe077a] | 63 | // enum must remain in the same order as the corresponding bit fields. |
---|
| 64 | |
---|
[ddfd945] | 65 | enum { Inline = 1 << 0, Noreturn = 1 << 1, Fortran = 1 << 2, NumFuncSpecifier = 3 }; |
---|
[615a096] | 66 | static const char * FuncSpecifiersNames[]; |
---|
[ddfd945] | 67 | union FuncSpecifiers { |
---|
| 68 | unsigned int val; |
---|
| 69 | struct { |
---|
| 70 | bool is_inline : 1; |
---|
| 71 | bool is_noreturn : 1; |
---|
| 72 | bool is_fortran : 1; |
---|
| 73 | }; |
---|
| 74 | FuncSpecifiers() : val( 0 ) {} |
---|
| 75 | FuncSpecifiers( unsigned int val ) : val( val ) {} |
---|
[615a096] | 76 | // equality (==, !=) works implicitly on first field "val", relational operations are undefined. |
---|
[6f95000] | 77 | BFCommon( FuncSpecifiers, NumFuncSpecifier ) |
---|
[ddfd945] | 78 | }; // FuncSpecifiers |
---|
| 79 | |
---|
[68fe077a] | 80 | enum { Extern = 1 << 0, Static = 1 << 1, Auto = 1 << 2, Register = 1 << 3, Threadlocal = 1 << 4, NumStorageClass = 5 }; |
---|
[615a096] | 81 | static const char * StorageClassesNames[]; |
---|
[68fe077a] | 82 | union StorageClasses { |
---|
| 83 | unsigned int val; |
---|
| 84 | struct { |
---|
| 85 | bool is_extern : 1; |
---|
| 86 | bool is_static : 1; |
---|
| 87 | bool is_auto : 1; |
---|
| 88 | bool is_register : 1; |
---|
| 89 | bool is_threadlocal : 1; |
---|
| 90 | }; |
---|
| 91 | |
---|
| 92 | StorageClasses() : val( 0 ) {} |
---|
| 93 | StorageClasses( unsigned int val ) : val( val ) {} |
---|
[615a096] | 94 | // equality (==, !=) works implicitly on first field "val", relational operations are undefined. |
---|
[6f95000] | 95 | BFCommon( StorageClasses, NumStorageClass ) |
---|
[68fe077a] | 96 | }; // StorageClasses |
---|
| 97 | |
---|
[bf4ac09] | 98 | enum { Const = 1 << 0, Restrict = 1 << 1, Volatile = 1 << 2, Lvalue = 1 << 3, Mutex = 1 << 4, Atomic = 1 << 5, NumTypeQualifier = 6 }; |
---|
[615a096] | 99 | static const char * QualifiersNames[]; |
---|
[bf4ac09] | 100 | union Qualifiers { |
---|
| 101 | enum { Mask = ~(Restrict | Lvalue) }; |
---|
| 102 | unsigned int val; |
---|
| 103 | struct { |
---|
[615a096] | 104 | bool is_const : 1; |
---|
| 105 | bool is_restrict : 1; |
---|
| 106 | bool is_volatile : 1; |
---|
| 107 | bool is_lvalue : 1; |
---|
| 108 | bool is_mutex : 1; |
---|
| 109 | bool is_atomic : 1; |
---|
[bf4ac09] | 110 | }; |
---|
[6e8bd43] | 111 | |
---|
[bf4ac09] | 112 | Qualifiers() : val( 0 ) {} |
---|
| 113 | Qualifiers( unsigned int val ) : val( val ) {} |
---|
[615a096] | 114 | // Complex comparisons provide implicit qualifier downcasting, e.g., T downcast to const T. |
---|
| 115 | bool operator==( Qualifiers other ) const { return (val & Mask) == (other.val & Mask); } |
---|
| 116 | bool operator!=( Qualifiers other ) const { return (val & Mask) != (other.val & Mask); } |
---|
[d6d747d] | 117 | bool operator<=( Qualifiers other ) const { |
---|
[e04b636] | 118 | return is_const <= other.is_const //Any non-const converts to const without cost |
---|
| 119 | && is_volatile <= other.is_volatile //Any non-volatile converts to volatile without cost |
---|
| 120 | && is_mutex >= other.is_mutex //Any mutex converts to non-mutex without cost |
---|
| 121 | && is_atomic == other.is_atomic; //No conversion from atomic to non atomic is free |
---|
[bf4ac09] | 122 | } |
---|
[6f95000] | 123 | bool operator<( Qualifiers other ) const { return *this != other && *this <= other; } |
---|
| 124 | bool operator>=( Qualifiers other ) const { return ! (*this < other); } |
---|
| 125 | bool operator>( Qualifiers other ) const { return *this != other && *this >= other; } |
---|
| 126 | BFCommon( Qualifiers, NumTypeQualifier ) |
---|
[bf4ac09] | 127 | }; // Qualifiers |
---|
[0dd3a2f] | 128 | |
---|
[65cdc1e] | 129 | typedef std::list<TypeDecl *> ForallList; |
---|
| 130 | |
---|
| 131 | Qualifiers tq; |
---|
| 132 | ForallList forall; |
---|
| 133 | std::list< Attribute * > attributes; |
---|
| 134 | |
---|
[f2e40a9f] | 135 | Type( const Qualifiers & tq, const std::list< Attribute * > & attributes ); |
---|
| 136 | Type( const Type & other ); |
---|
[0dd3a2f] | 137 | virtual ~Type(); |
---|
| 138 | |
---|
[f2e40a9f] | 139 | Qualifiers & get_qualifiers() { return tq; } |
---|
[615a096] | 140 | bool get_const() { return tq.is_const; } |
---|
| 141 | bool get_volatile() { return tq.is_volatile; } |
---|
| 142 | bool get_restrict() { return tq.is_restrict; } |
---|
| 143 | bool get_lvalue() { return tq.is_lvalue; } |
---|
| 144 | bool get_mutex() { return tq.is_mutex; } |
---|
| 145 | bool get_atomic() { return tq.is_atomic; } |
---|
| 146 | void set_const( bool newValue ) { tq.is_const = newValue; } |
---|
| 147 | void set_volatile( bool newValue ) { tq.is_volatile = newValue; } |
---|
| 148 | void set_restrict( bool newValue ) { tq.is_restrict = newValue; } |
---|
| 149 | void set_lvalue( bool newValue ) { tq.is_lvalue = newValue; } |
---|
| 150 | void set_mutex( bool newValue ) { tq.is_mutex = newValue; } |
---|
| 151 | void set_atomic( bool newValue ) { tq.is_atomic = newValue; } |
---|
[8c49c0e] | 152 | |
---|
| 153 | ForallList& get_forall() { return forall; } |
---|
[0dd3a2f] | 154 | |
---|
[c0aa336] | 155 | std::list< Attribute * >& get_attributes() { return attributes; } |
---|
| 156 | const std::list< Attribute * >& get_attributes() const { return attributes; } |
---|
| 157 | |
---|
[906e24d] | 158 | /// How many elemental types are represented by this type |
---|
| 159 | virtual unsigned size() const { return 1; }; |
---|
| 160 | virtual bool isVoid() const { return size() == 0; } |
---|
[7933351] | 161 | virtual Type * getComponent( unsigned i ) { assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i ); return this; } |
---|
[906e24d] | 162 | |
---|
[142cf5d] | 163 | /// return type without outer pointers and arrays |
---|
[6f95000] | 164 | Type *stripDeclarator(); |
---|
| 165 | |
---|
[4a9ccc3] | 166 | virtual bool isComplete() const { return true; } |
---|
| 167 | |
---|
[0dd3a2f] | 168 | virtual Type *clone() const = 0; |
---|
[f2e40a9f] | 169 | virtual void accept( Visitor & v ) = 0; |
---|
| 170 | virtual Type *acceptMutator( Mutator & m ) = 0; |
---|
| 171 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 172 | }; |
---|
| 173 | |
---|
[65cdc1e] | 174 | extern const Type::FuncSpecifiers noFuncSpecifiers; |
---|
| 175 | extern const Type::StorageClasses noStorageClasses; |
---|
| 176 | extern const Type::Qualifiers noQualifiers; // no qualifiers on constants |
---|
[4cb935e] | 177 | |
---|
[c8ffe20b] | 178 | class VoidType : public Type { |
---|
| 179 | public: |
---|
[f2e40a9f] | 180 | VoidType( const Type::Qualifiers & tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[51b7345] | 181 | |
---|
[906e24d] | 182 | virtual unsigned size() const { return 0; }; |
---|
[4a9ccc3] | 183 | virtual bool isComplete() const { return false; } |
---|
[906e24d] | 184 | |
---|
[0dd3a2f] | 185 | virtual VoidType *clone() const { return new VoidType( *this ); } |
---|
[f2e40a9f] | 186 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 187 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 188 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 189 | }; |
---|
| 190 | |
---|
[c8ffe20b] | 191 | class BasicType : public Type { |
---|
| 192 | public: |
---|
[ae63a18] | 193 | enum Kind { |
---|
[0dd3a2f] | 194 | Bool, |
---|
| 195 | Char, |
---|
| 196 | SignedChar, |
---|
| 197 | UnsignedChar, |
---|
| 198 | ShortSignedInt, |
---|
| 199 | ShortUnsignedInt, |
---|
| 200 | SignedInt, |
---|
| 201 | UnsignedInt, |
---|
| 202 | LongSignedInt, |
---|
| 203 | LongUnsignedInt, |
---|
| 204 | LongLongSignedInt, |
---|
| 205 | LongLongUnsignedInt, |
---|
| 206 | Float, |
---|
| 207 | Double, |
---|
| 208 | LongDouble, |
---|
| 209 | FloatComplex, |
---|
| 210 | DoubleComplex, |
---|
| 211 | LongDoubleComplex, |
---|
| 212 | FloatImaginary, |
---|
| 213 | DoubleImaginary, |
---|
| 214 | LongDoubleImaginary, |
---|
| 215 | NUMBER_OF_BASIC_TYPES |
---|
[65cdc1e] | 216 | } kind; |
---|
[0dd3a2f] | 217 | |
---|
[59db689] | 218 | static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind |
---|
[0dd3a2f] | 219 | |
---|
[f2e40a9f] | 220 | BasicType( const Type::Qualifiers & tq, Kind bt, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 221 | |
---|
| 222 | Kind get_kind() { return kind; } |
---|
| 223 | void set_kind( Kind newValue ) { kind = newValue; } |
---|
| 224 | |
---|
| 225 | virtual BasicType *clone() const { return new BasicType( *this ); } |
---|
[f2e40a9f] | 226 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 227 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 228 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[0dd3a2f] | 229 | |
---|
| 230 | bool isInteger() const; |
---|
[51b7345] | 231 | }; |
---|
| 232 | |
---|
[c8ffe20b] | 233 | class PointerType : public Type { |
---|
| 234 | public: |
---|
[65cdc1e] | 235 | Type *base; |
---|
| 236 | |
---|
| 237 | // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] ) |
---|
| 238 | Expression *dimension; |
---|
| 239 | bool isVarLen; |
---|
| 240 | bool isStatic; |
---|
| 241 | |
---|
[f2e40a9f] | 242 | PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 243 | PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 244 | PointerType( const PointerType& ); |
---|
| 245 | virtual ~PointerType(); |
---|
| 246 | |
---|
| 247 | Type *get_base() { return base; } |
---|
| 248 | void set_base( Type *newValue ) { base = newValue; } |
---|
| 249 | Expression *get_dimension() { return dimension; } |
---|
| 250 | void set_dimension( Expression *newValue ) { dimension = newValue; } |
---|
| 251 | bool get_isVarLen() { return isVarLen; } |
---|
| 252 | void set_isVarLen( bool newValue ) { isVarLen = newValue; } |
---|
| 253 | bool get_isStatic() { return isStatic; } |
---|
| 254 | void set_isStatic( bool newValue ) { isStatic = newValue; } |
---|
| 255 | |
---|
[ed8a0d2] | 256 | bool is_array() const { return isStatic || isVarLen || dimension; } |
---|
| 257 | |
---|
[0dd3a2f] | 258 | virtual PointerType *clone() const { return new PointerType( *this ); } |
---|
[f2e40a9f] | 259 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 260 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 261 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[65cdc1e] | 262 | }; |
---|
[ae63a18] | 263 | |
---|
[65cdc1e] | 264 | class ArrayType : public Type { |
---|
| 265 | public: |
---|
| 266 | Type *base; |
---|
[0dd3a2f] | 267 | Expression *dimension; |
---|
| 268 | bool isVarLen; |
---|
| 269 | bool isStatic; |
---|
[51b7345] | 270 | |
---|
[f2e40a9f] | 271 | ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 272 | ArrayType( const ArrayType& ); |
---|
| 273 | virtual ~ArrayType(); |
---|
| 274 | |
---|
| 275 | Type *get_base() { return base; } |
---|
| 276 | void set_base( Type *newValue ) { base = newValue; } |
---|
| 277 | Expression *get_dimension() { return dimension; } |
---|
| 278 | void set_dimension( Expression *newValue ) { dimension = newValue; } |
---|
| 279 | bool get_isVarLen() { return isVarLen; } |
---|
| 280 | void set_isVarLen( bool newValue ) { isVarLen = newValue; } |
---|
| 281 | bool get_isStatic() { return isStatic; } |
---|
| 282 | void set_isStatic( bool newValue ) { isStatic = newValue; } |
---|
| 283 | |
---|
[4a9ccc3] | 284 | virtual bool isComplete() const { return ! isVarLen; } |
---|
| 285 | |
---|
[0dd3a2f] | 286 | virtual ArrayType *clone() const { return new ArrayType( *this ); } |
---|
[f2e40a9f] | 287 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 288 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 289 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 290 | }; |
---|
| 291 | |
---|
[c8ffe20b] | 292 | class FunctionType : public Type { |
---|
| 293 | public: |
---|
[65cdc1e] | 294 | std::list<DeclarationWithType*> returnVals; |
---|
| 295 | std::list<DeclarationWithType*> parameters; |
---|
| 296 | |
---|
| 297 | // Does the function accept a variable number of arguments following the arguments specified in the parameters list. |
---|
| 298 | // This could be because of |
---|
| 299 | // - an ellipsis in a prototype declaration |
---|
| 300 | // - an unprototyped declaration |
---|
| 301 | bool isVarArgs; |
---|
| 302 | |
---|
[f2e40a9f] | 303 | FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 304 | FunctionType( const FunctionType& ); |
---|
| 305 | virtual ~FunctionType(); |
---|
| 306 | |
---|
[cf16f94] | 307 | std::list<DeclarationWithType*> & get_returnVals() { return returnVals; } |
---|
| 308 | std::list<DeclarationWithType*> & get_parameters() { return parameters; } |
---|
[8bf784a] | 309 | bool get_isVarArgs() const { return isVarArgs; } |
---|
[0dd3a2f] | 310 | void set_isVarArgs( bool newValue ) { isVarArgs = newValue; } |
---|
[8bf784a] | 311 | bool isTtype() const; |
---|
| 312 | |
---|
[0dd3a2f] | 313 | virtual FunctionType *clone() const { return new FunctionType( *this ); } |
---|
[f2e40a9f] | 314 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 315 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 316 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 317 | }; |
---|
| 318 | |
---|
[c8ffe20b] | 319 | class ReferenceToType : public Type { |
---|
| 320 | public: |
---|
[65cdc1e] | 321 | std::list< Expression* > parameters; |
---|
| 322 | std::string name; |
---|
| 323 | bool hoistType; |
---|
| 324 | |
---|
[f2e40a9f] | 325 | ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes ); |
---|
| 326 | ReferenceToType( const ReferenceToType & other ); |
---|
[0dd3a2f] | 327 | virtual ~ReferenceToType(); |
---|
| 328 | |
---|
[f2e40a9f] | 329 | const std::string & get_name() const { return name; } |
---|
[0dd3a2f] | 330 | void set_name( std::string newValue ) { name = newValue; } |
---|
| 331 | std::list< Expression* >& get_parameters() { return parameters; } |
---|
[43c89a7] | 332 | bool get_hoistType() const { return hoistType; } |
---|
| 333 | void set_hoistType( bool newValue ) { hoistType = newValue; } |
---|
[ae63a18] | 334 | |
---|
[0dd3a2f] | 335 | virtual ReferenceToType *clone() const = 0; |
---|
[f2e40a9f] | 336 | virtual void accept( Visitor & v ) = 0; |
---|
| 337 | virtual Type *acceptMutator( Mutator & m ) = 0; |
---|
| 338 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[6013bd7] | 339 | |
---|
[b3c36f4] | 340 | virtual void lookup( __attribute__((unused)) const std::string & name, __attribute__((unused)) std::list< Declaration* > & foundDecls ) const {} |
---|
[c8ffe20b] | 341 | protected: |
---|
[0dd3a2f] | 342 | virtual std::string typeString() const = 0; |
---|
[51b7345] | 343 | }; |
---|
| 344 | |
---|
[c8ffe20b] | 345 | class StructInstType : public ReferenceToType { |
---|
[0dd3a2f] | 346 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 347 | public: |
---|
[65cdc1e] | 348 | // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, |
---|
| 349 | // where the structure used in this type is actually defined |
---|
| 350 | StructDecl *baseStruct; |
---|
| 351 | |
---|
[f2e40a9f] | 352 | StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseStruct( 0 ) {} |
---|
| 353 | StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 354 | StructInstType( const StructInstType & other ) : Parent( other ), baseStruct( other.baseStruct ) {} |
---|
[51b7345] | 355 | |
---|
[0dd3a2f] | 356 | StructDecl *get_baseStruct() const { return baseStruct; } |
---|
| 357 | void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } |
---|
[37a3b8f9] | 358 | |
---|
[ed94eac] | 359 | /// Accesses generic parameters of base struct (NULL if none such) |
---|
[839ccbb] | 360 | std::list<TypeDecl*> * get_baseParameters(); |
---|
[ae63a18] | 361 | |
---|
[4a9ccc3] | 362 | virtual bool isComplete() const; |
---|
| 363 | |
---|
[37a3b8f9] | 364 | /// Looks up the members of this struct named "name" and places them into "foundDecls". |
---|
| 365 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
[f2e40a9f] | 366 | void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const; |
---|
[51b7345] | 367 | |
---|
[0dd3a2f] | 368 | virtual StructInstType *clone() const { return new StructInstType( *this ); } |
---|
[f2e40a9f] | 369 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 370 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
[5d125e4] | 371 | |
---|
[f2e40a9f] | 372 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[c8ffe20b] | 373 | private: |
---|
[0dd3a2f] | 374 | virtual std::string typeString() const; |
---|
[51b7345] | 375 | }; |
---|
| 376 | |
---|
[c8ffe20b] | 377 | class UnionInstType : public ReferenceToType { |
---|
[0dd3a2f] | 378 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 379 | public: |
---|
[65cdc1e] | 380 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, |
---|
| 381 | // where the union used in this type is actually defined |
---|
| 382 | UnionDecl *baseUnion; |
---|
| 383 | |
---|
[f2e40a9f] | 384 | UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseUnion( 0 ) {} |
---|
| 385 | UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 386 | UnionInstType( const UnionInstType & other ) : Parent( other ), baseUnion( other.baseUnion ) {} |
---|
[0dd3a2f] | 387 | |
---|
| 388 | UnionDecl *get_baseUnion() const { return baseUnion; } |
---|
[c0aa336] | 389 | void set_baseUnion( UnionDecl * newValue ) { baseUnion = newValue; } |
---|
[37a3b8f9] | 390 | |
---|
[ed94eac] | 391 | /// Accesses generic parameters of base union (NULL if none such) |
---|
[c0aa336] | 392 | std::list< TypeDecl * > * get_baseParameters(); |
---|
[ae63a18] | 393 | |
---|
[4a9ccc3] | 394 | virtual bool isComplete() const; |
---|
| 395 | |
---|
[37a3b8f9] | 396 | /// looks up the members of this union named "name" and places them into "foundDecls" |
---|
| 397 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
[f2e40a9f] | 398 | void lookup( const std::string & name, std::list< Declaration* > & foundDecls ) const; |
---|
[0dd3a2f] | 399 | |
---|
| 400 | virtual UnionInstType *clone() const { return new UnionInstType( *this ); } |
---|
[f2e40a9f] | 401 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 402 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
[5d125e4] | 403 | |
---|
[f2e40a9f] | 404 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[c8ffe20b] | 405 | private: |
---|
[0dd3a2f] | 406 | virtual std::string typeString() const; |
---|
[51b7345] | 407 | }; |
---|
| 408 | |
---|
[c8ffe20b] | 409 | class EnumInstType : public ReferenceToType { |
---|
[0dd3a2f] | 410 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 411 | public: |
---|
[65cdc1e] | 412 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, |
---|
| 413 | // where the union used in this type is actually defined |
---|
| 414 | EnumDecl *baseEnum = nullptr; |
---|
| 415 | |
---|
[f2e40a9f] | 416 | EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} |
---|
| 417 | EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 418 | EnumInstType( const EnumInstType & other ) : Parent( other ), baseEnum( other.baseEnum ) {} |
---|
[51b7345] | 419 | |
---|
[c0aa336] | 420 | EnumDecl *get_baseEnum() const { return baseEnum; } |
---|
| 421 | void set_baseEnum( EnumDecl *newValue ) { baseEnum = newValue; } |
---|
| 422 | |
---|
| 423 | virtual bool isComplete() const; |
---|
[4a9ccc3] | 424 | |
---|
[0dd3a2f] | 425 | virtual EnumInstType *clone() const { return new EnumInstType( *this ); } |
---|
[f2e40a9f] | 426 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 427 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
[c8ffe20b] | 428 | private: |
---|
[0dd3a2f] | 429 | virtual std::string typeString() const; |
---|
[51b7345] | 430 | }; |
---|
| 431 | |
---|
[4040425] | 432 | class TraitInstType : public ReferenceToType { |
---|
[0dd3a2f] | 433 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 434 | public: |
---|
[65cdc1e] | 435 | // this member is filled in by the validate pass, which instantiates the members of the correponding |
---|
| 436 | // aggregate with the actual type parameters specified for this use of the context |
---|
| 437 | std::list< Declaration* > members; |
---|
| 438 | |
---|
[f2e40a9f] | 439 | TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} |
---|
| 440 | TraitInstType( const TraitInstType & other ); |
---|
[4040425] | 441 | ~TraitInstType(); |
---|
[51b7345] | 442 | |
---|
[0dd3a2f] | 443 | std::list< Declaration* >& get_members() { return members; } |
---|
[51b7345] | 444 | |
---|
[4a9ccc3] | 445 | virtual bool isComplete() const; |
---|
| 446 | |
---|
[4040425] | 447 | virtual TraitInstType *clone() const { return new TraitInstType( *this ); } |
---|
[f2e40a9f] | 448 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 449 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
[c8ffe20b] | 450 | private: |
---|
[0dd3a2f] | 451 | virtual std::string typeString() const; |
---|
[51b7345] | 452 | }; |
---|
| 453 | |
---|
[c8ffe20b] | 454 | class TypeInstType : public ReferenceToType { |
---|
[0dd3a2f] | 455 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 456 | public: |
---|
[65cdc1e] | 457 | // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, |
---|
| 458 | // where the type used here is actually defined |
---|
| 459 | TypeDecl *baseType; |
---|
| 460 | bool isFtype; |
---|
| 461 | |
---|
[f2e40a9f] | 462 | TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 463 | TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 464 | TypeInstType( const TypeInstType & other ); |
---|
[1e8b02f5] | 465 | ~TypeInstType(); |
---|
[0dd3a2f] | 466 | |
---|
| 467 | TypeDecl *get_baseType() const { return baseType; } |
---|
| 468 | void set_baseType( TypeDecl *newValue ); |
---|
| 469 | bool get_isFtype() const { return isFtype; } |
---|
| 470 | void set_isFtype( bool newValue ) { isFtype = newValue; } |
---|
[ae63a18] | 471 | |
---|
[4a9ccc3] | 472 | virtual bool isComplete() const; |
---|
| 473 | |
---|
[0dd3a2f] | 474 | virtual TypeInstType *clone() const { return new TypeInstType( *this ); } |
---|
[f2e40a9f] | 475 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 476 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 477 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[c8ffe20b] | 478 | private: |
---|
[0dd3a2f] | 479 | virtual std::string typeString() const; |
---|
[51b7345] | 480 | }; |
---|
| 481 | |
---|
[c8ffe20b] | 482 | class TupleType : public Type { |
---|
| 483 | public: |
---|
[65cdc1e] | 484 | std::list<Type *> types; |
---|
| 485 | std::list<Declaration *> members; |
---|
| 486 | |
---|
[62423350] | 487 | TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 488 | TupleType( const TupleType& ); |
---|
| 489 | virtual ~TupleType(); |
---|
[51b7345] | 490 | |
---|
[0362d42] | 491 | typedef std::list<Type*> value_type; |
---|
| 492 | typedef value_type::iterator iterator; |
---|
| 493 | |
---|
[62423350] | 494 | std::list<Type *> & get_types() { return types; } |
---|
[906e24d] | 495 | virtual unsigned size() const { return types.size(); }; |
---|
[51b7345] | 496 | |
---|
[62423350] | 497 | // For now, this is entirely synthetic -- tuple types always have unnamed members. |
---|
| 498 | // Eventually, we may allow named tuples, in which case members should subsume types |
---|
| 499 | std::list<Declaration *> & get_members() { return members; } |
---|
| 500 | |
---|
[0362d42] | 501 | iterator begin() { return types.begin(); } |
---|
| 502 | iterator end() { return types.end(); } |
---|
| 503 | |
---|
[7933351] | 504 | virtual Type * getComponent( unsigned i ) { |
---|
| 505 | assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() ); |
---|
| 506 | return *(begin()+i); |
---|
| 507 | } |
---|
| 508 | |
---|
[4a9ccc3] | 509 | // virtual bool isComplete() const { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness |
---|
| 510 | |
---|
[0dd3a2f] | 511 | virtual TupleType *clone() const { return new TupleType( *this ); } |
---|
[f2e40a9f] | 512 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 513 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 514 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 515 | }; |
---|
| 516 | |
---|
[c8ffe20b] | 517 | class TypeofType : public Type { |
---|
| 518 | public: |
---|
[65cdc1e] | 519 | Expression *expr; |
---|
| 520 | |
---|
[f2e40a9f] | 521 | TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 522 | TypeofType( const TypeofType& ); |
---|
| 523 | virtual ~TypeofType(); |
---|
[51b7345] | 524 | |
---|
[0dd3a2f] | 525 | Expression *get_expr() const { return expr; } |
---|
| 526 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
[51b7345] | 527 | |
---|
[4a9ccc3] | 528 | virtual bool isComplete() const { assert( false ); return false; } |
---|
| 529 | |
---|
[0dd3a2f] | 530 | virtual TypeofType *clone() const { return new TypeofType( *this ); } |
---|
[f2e40a9f] | 531 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 532 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 533 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 534 | }; |
---|
| 535 | |
---|
[c8ffe20b] | 536 | class AttrType : public Type { |
---|
| 537 | public: |
---|
[65cdc1e] | 538 | std::string name; |
---|
| 539 | Expression *expr; |
---|
| 540 | Type *type; |
---|
| 541 | bool isType; |
---|
| 542 | |
---|
[f2e40a9f] | 543 | AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
| 544 | AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[0dd3a2f] | 545 | AttrType( const AttrType& ); |
---|
| 546 | virtual ~AttrType(); |
---|
| 547 | |
---|
[f2e40a9f] | 548 | const std::string & get_name() const { return name; } |
---|
| 549 | void set_name( const std::string & newValue ) { name = newValue; } |
---|
[0dd3a2f] | 550 | Expression *get_expr() const { return expr; } |
---|
| 551 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
| 552 | Type *get_type() const { return type; } |
---|
| 553 | void set_type( Type *newValue ) { type = newValue; } |
---|
| 554 | bool get_isType() const { return isType; } |
---|
| 555 | void set_isType( bool newValue ) { isType = newValue; } |
---|
| 556 | |
---|
[4a9ccc3] | 557 | virtual bool isComplete() const { assert( false ); } // xxx - not sure what to do here |
---|
| 558 | |
---|
[0dd3a2f] | 559 | virtual AttrType *clone() const { return new AttrType( *this ); } |
---|
[f2e40a9f] | 560 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 561 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 562 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[51b7345] | 563 | }; |
---|
| 564 | |
---|
[44b7088] | 565 | /// Represents the GCC built-in varargs type |
---|
| 566 | class VarArgsType : public Type { |
---|
[90c3b1c] | 567 | public: |
---|
[44b7088] | 568 | VarArgsType(); |
---|
[c0aa336] | 569 | VarArgsType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[44b7088] | 570 | |
---|
[4a9ccc3] | 571 | virtual bool isComplete() const{ return true; } // xxx - is this right? |
---|
| 572 | |
---|
[44b7088] | 573 | virtual VarArgsType *clone() const { return new VarArgsType( *this ); } |
---|
[f2e40a9f] | 574 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 575 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 576 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[44b7088] | 577 | }; |
---|
| 578 | |
---|
[89e6ffc] | 579 | /// Represents a zero constant |
---|
| 580 | class ZeroType : public Type { |
---|
| 581 | public: |
---|
| 582 | ZeroType(); |
---|
[c0aa336] | 583 | ZeroType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[89e6ffc] | 584 | |
---|
| 585 | virtual ZeroType *clone() const { return new ZeroType( *this ); } |
---|
[f2e40a9f] | 586 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 587 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 588 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[89e6ffc] | 589 | }; |
---|
| 590 | |
---|
| 591 | /// Represents a one constant |
---|
| 592 | class OneType : public Type { |
---|
| 593 | public: |
---|
| 594 | OneType(); |
---|
[c0aa336] | 595 | OneType( Type::Qualifiers tq, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); |
---|
[89e6ffc] | 596 | |
---|
| 597 | virtual OneType *clone() const { return new OneType( *this ); } |
---|
[f2e40a9f] | 598 | virtual void accept( Visitor & v ) { v.visit( this ); } |
---|
| 599 | virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } |
---|
| 600 | virtual void print( std::ostream & os, int indent = 0 ) const; |
---|
[89e6ffc] | 601 | }; |
---|
| 602 | |
---|
[3906301] | 603 | std::ostream & operator<<( std::ostream & out, const Type * type ); |
---|
[baf7fee] | 604 | |
---|
[0dd3a2f] | 605 | // Local Variables: // |
---|
| 606 | // tab-width: 4 // |
---|
| 607 | // mode: c++ // |
---|
| 608 | // compile-command: "make install" // |
---|
| 609 | // End: // |
---|