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