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