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