[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; } |
---|
[0dd3a2f] | 206 | bool get_isVarArgs() { return isVarArgs; } |
---|
| 207 | void set_isVarArgs( bool newValue ) { isVarArgs = newValue; } |
---|
| 208 | |
---|
| 209 | virtual FunctionType *clone() const { return new FunctionType( *this ); } |
---|
| 210 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 211 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 212 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 213 | private: |
---|
[0dd3a2f] | 214 | std::list<DeclarationWithType*> returnVals; |
---|
| 215 | std::list<DeclarationWithType*> parameters; |
---|
| 216 | |
---|
[839ccbb] | 217 | // Does the function accept a variable number of arguments following the arguments specified in the parameters list. |
---|
| 218 | // This could be because of |
---|
[0dd3a2f] | 219 | // - an ellipsis in a prototype declaration |
---|
| 220 | // - an unprototyped declaration |
---|
| 221 | bool isVarArgs; |
---|
[51b7345] | 222 | }; |
---|
| 223 | |
---|
[c8ffe20b] | 224 | class ReferenceToType : public Type { |
---|
| 225 | public: |
---|
[0dd3a2f] | 226 | ReferenceToType( const Type::Qualifiers &tq, const std::string &name ); |
---|
| 227 | ReferenceToType( const ReferenceToType &other ); |
---|
| 228 | virtual ~ReferenceToType(); |
---|
| 229 | |
---|
[5f2f2d7] | 230 | const std::string &get_name() const { return name; } |
---|
[0dd3a2f] | 231 | void set_name( std::string newValue ) { name = newValue; } |
---|
| 232 | std::list< Expression* >& get_parameters() { return parameters; } |
---|
[ae63a18] | 233 | |
---|
[0dd3a2f] | 234 | virtual ReferenceToType *clone() const = 0; |
---|
| 235 | virtual void accept( Visitor &v ) = 0; |
---|
| 236 | virtual Type *acceptMutator( Mutator &m ) = 0; |
---|
| 237 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 238 | protected: |
---|
[0dd3a2f] | 239 | virtual std::string typeString() const = 0; |
---|
| 240 | std::list< Expression* > parameters; |
---|
| 241 | std::string name; |
---|
[5d125e4] | 242 | private: |
---|
[51b7345] | 243 | }; |
---|
| 244 | |
---|
[c8ffe20b] | 245 | class StructInstType : public ReferenceToType { |
---|
[0dd3a2f] | 246 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 247 | public: |
---|
[0dd3a2f] | 248 | StructInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseStruct( 0 ) {} |
---|
[f006f01] | 249 | StructInstType( const Type::Qualifiers &tq, StructDecl * baseStruct ); |
---|
[0dd3a2f] | 250 | StructInstType( const StructInstType &other ) : Parent( other ), baseStruct( other.baseStruct ) {} |
---|
[51b7345] | 251 | |
---|
[0dd3a2f] | 252 | StructDecl *get_baseStruct() const { return baseStruct; } |
---|
| 253 | void set_baseStruct( StructDecl *newValue ) { baseStruct = newValue; } |
---|
[37a3b8f9] | 254 | |
---|
[ed94eac] | 255 | /// Accesses generic parameters of base struct (NULL if none such) |
---|
[839ccbb] | 256 | std::list<TypeDecl*> * get_baseParameters(); |
---|
[ae63a18] | 257 | |
---|
[37a3b8f9] | 258 | /// Looks up the members of this struct named "name" and places them into "foundDecls". |
---|
| 259 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
[0dd3a2f] | 260 | void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; |
---|
[51b7345] | 261 | |
---|
[0dd3a2f] | 262 | virtual StructInstType *clone() const { return new StructInstType( *this ); } |
---|
| 263 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 264 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[5d125e4] | 265 | |
---|
| 266 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 267 | private: |
---|
[0dd3a2f] | 268 | virtual std::string typeString() const; |
---|
[ae63a18] | 269 | |
---|
[0dd3a2f] | 270 | // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, |
---|
| 271 | // where the structure used in this type is actually defined |
---|
| 272 | StructDecl *baseStruct; |
---|
[51b7345] | 273 | }; |
---|
| 274 | |
---|
[c8ffe20b] | 275 | class UnionInstType : public ReferenceToType { |
---|
[0dd3a2f] | 276 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 277 | public: |
---|
[0dd3a2f] | 278 | UnionInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ), baseUnion( 0 ) {} |
---|
| 279 | UnionInstType( const UnionInstType &other ) : Parent( other ), baseUnion( other.baseUnion ) {} |
---|
| 280 | |
---|
| 281 | UnionDecl *get_baseUnion() const { return baseUnion; } |
---|
| 282 | void set_baseUnion( UnionDecl *newValue ) { baseUnion = newValue; } |
---|
[37a3b8f9] | 283 | |
---|
[ed94eac] | 284 | /// Accesses generic parameters of base union (NULL if none such) |
---|
[839ccbb] | 285 | std::list<TypeDecl*> * get_baseParameters(); |
---|
[ae63a18] | 286 | |
---|
[37a3b8f9] | 287 | /// looks up the members of this union named "name" and places them into "foundDecls" |
---|
| 288 | /// Clones declarations into "foundDecls", caller responsible for freeing |
---|
[0dd3a2f] | 289 | void lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const; |
---|
| 290 | |
---|
| 291 | virtual UnionInstType *clone() const { return new UnionInstType( *this ); } |
---|
| 292 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 293 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[5d125e4] | 294 | |
---|
| 295 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 296 | private: |
---|
[0dd3a2f] | 297 | virtual std::string typeString() const; |
---|
[ae63a18] | 298 | |
---|
[0dd3a2f] | 299 | // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, |
---|
| 300 | // where the union used in this type is actually defined |
---|
| 301 | UnionDecl *baseUnion; |
---|
[51b7345] | 302 | }; |
---|
| 303 | |
---|
[c8ffe20b] | 304 | class EnumInstType : public ReferenceToType { |
---|
[0dd3a2f] | 305 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 306 | public: |
---|
[0dd3a2f] | 307 | EnumInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} |
---|
| 308 | EnumInstType( const EnumInstType &other ) : Parent( other ) {} |
---|
[51b7345] | 309 | |
---|
[0dd3a2f] | 310 | virtual EnumInstType *clone() const { return new EnumInstType( *this ); } |
---|
| 311 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 312 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[c8ffe20b] | 313 | private: |
---|
[0dd3a2f] | 314 | virtual std::string typeString() const; |
---|
[51b7345] | 315 | }; |
---|
| 316 | |
---|
[4040425] | 317 | class TraitInstType : public ReferenceToType { |
---|
[0dd3a2f] | 318 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 319 | public: |
---|
[4040425] | 320 | TraitInstType( const Type::Qualifiers &tq, const std::string &name ) : Parent( tq, name ) {} |
---|
| 321 | TraitInstType( const TraitInstType &other ); |
---|
| 322 | ~TraitInstType(); |
---|
[51b7345] | 323 | |
---|
[0dd3a2f] | 324 | std::list< Declaration* >& get_members() { return members; } |
---|
[51b7345] | 325 | |
---|
[4040425] | 326 | virtual TraitInstType *clone() const { return new TraitInstType( *this ); } |
---|
[0dd3a2f] | 327 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 328 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[c8ffe20b] | 329 | private: |
---|
[0dd3a2f] | 330 | virtual std::string typeString() const; |
---|
[ae63a18] | 331 | |
---|
[0dd3a2f] | 332 | // this member is filled in by the validate pass, which instantiates the members of the correponding |
---|
| 333 | // aggregate with the actual type parameters specified for this use of the context |
---|
| 334 | std::list< Declaration* > members; |
---|
[51b7345] | 335 | }; |
---|
| 336 | |
---|
[c8ffe20b] | 337 | class TypeInstType : public ReferenceToType { |
---|
[0dd3a2f] | 338 | typedef ReferenceToType Parent; |
---|
[c8ffe20b] | 339 | public: |
---|
[0dd3a2f] | 340 | TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ); |
---|
| 341 | TypeInstType( const Type::Qualifiers &tq, const std::string &name, bool isFtype ); |
---|
[2c57025] | 342 | TypeInstType( const TypeInstType &other ); |
---|
[1e8b02f5] | 343 | ~TypeInstType(); |
---|
[0dd3a2f] | 344 | |
---|
| 345 | TypeDecl *get_baseType() const { return baseType; } |
---|
| 346 | void set_baseType( TypeDecl *newValue ); |
---|
| 347 | bool get_isFtype() const { return isFtype; } |
---|
| 348 | void set_isFtype( bool newValue ) { isFtype = newValue; } |
---|
[ae63a18] | 349 | |
---|
[0dd3a2f] | 350 | virtual TypeInstType *clone() const { return new TypeInstType( *this ); } |
---|
| 351 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 352 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 353 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 354 | private: |
---|
[0dd3a2f] | 355 | virtual std::string typeString() const; |
---|
| 356 | // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, |
---|
| 357 | // where the type used here is actually defined |
---|
| 358 | TypeDecl *baseType; |
---|
| 359 | bool isFtype; |
---|
[51b7345] | 360 | }; |
---|
| 361 | |
---|
[c8ffe20b] | 362 | class TupleType : public Type { |
---|
| 363 | public: |
---|
[6eb8948] | 364 | TupleType( const Type::Qualifiers &tq, const std::list< Type * > & types = std::list< Type * >() ); |
---|
[0dd3a2f] | 365 | TupleType( const TupleType& ); |
---|
| 366 | virtual ~TupleType(); |
---|
[51b7345] | 367 | |
---|
[0362d42] | 368 | typedef std::list<Type*> value_type; |
---|
| 369 | typedef value_type::iterator iterator; |
---|
| 370 | |
---|
[0dd3a2f] | 371 | std::list<Type*>& get_types() { return types; } |
---|
[906e24d] | 372 | virtual unsigned size() const { return types.size(); }; |
---|
[51b7345] | 373 | |
---|
[0362d42] | 374 | iterator begin() { return types.begin(); } |
---|
| 375 | iterator end() { return types.end(); } |
---|
| 376 | |
---|
[7933351] | 377 | virtual Type * getComponent( unsigned i ) { |
---|
| 378 | assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", i, size() ); |
---|
| 379 | return *(begin()+i); |
---|
| 380 | } |
---|
| 381 | |
---|
[0dd3a2f] | 382 | virtual TupleType *clone() const { return new TupleType( *this ); } |
---|
| 383 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 384 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 385 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 386 | private: |
---|
[0dd3a2f] | 387 | std::list<Type*> types; |
---|
[51b7345] | 388 | }; |
---|
| 389 | |
---|
[c8ffe20b] | 390 | class TypeofType : public Type { |
---|
| 391 | public: |
---|
[0dd3a2f] | 392 | TypeofType( const Type::Qualifiers &tq, Expression *expr ); |
---|
| 393 | TypeofType( const TypeofType& ); |
---|
| 394 | virtual ~TypeofType(); |
---|
[51b7345] | 395 | |
---|
[0dd3a2f] | 396 | Expression *get_expr() const { return expr; } |
---|
| 397 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
[51b7345] | 398 | |
---|
[0dd3a2f] | 399 | virtual TypeofType *clone() const { return new TypeofType( *this ); } |
---|
| 400 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 401 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 402 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 403 | private: |
---|
[0dd3a2f] | 404 | Expression *expr; |
---|
[51b7345] | 405 | }; |
---|
| 406 | |
---|
[c8ffe20b] | 407 | class AttrType : public Type { |
---|
| 408 | public: |
---|
[0dd3a2f] | 409 | AttrType( const Type::Qualifiers &tq, const std::string &name, Expression *expr ); |
---|
| 410 | AttrType( const Type::Qualifiers &tq, const std::string &name, Type *type ); |
---|
| 411 | AttrType( const AttrType& ); |
---|
| 412 | virtual ~AttrType(); |
---|
| 413 | |
---|
[5f2f2d7] | 414 | const std::string &get_name() const { return name; } |
---|
[0dd3a2f] | 415 | void set_name( const std::string &newValue ) { name = newValue; } |
---|
| 416 | Expression *get_expr() const { return expr; } |
---|
| 417 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
| 418 | Type *get_type() const { return type; } |
---|
| 419 | void set_type( Type *newValue ) { type = newValue; } |
---|
| 420 | bool get_isType() const { return isType; } |
---|
| 421 | void set_isType( bool newValue ) { isType = newValue; } |
---|
| 422 | |
---|
| 423 | virtual AttrType *clone() const { return new AttrType( *this ); } |
---|
| 424 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 425 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 426 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
[c8ffe20b] | 427 | private: |
---|
[0dd3a2f] | 428 | std::string name; |
---|
| 429 | Expression *expr; |
---|
| 430 | Type *type; |
---|
| 431 | bool isType; |
---|
[51b7345] | 432 | }; |
---|
| 433 | |
---|
[44b7088] | 434 | /// Represents the GCC built-in varargs type |
---|
| 435 | class VarArgsType : public Type { |
---|
[90c3b1c] | 436 | public: |
---|
[44b7088] | 437 | VarArgsType(); |
---|
[8f610e85] | 438 | VarArgsType( Type::Qualifiers tq ); |
---|
[44b7088] | 439 | |
---|
| 440 | virtual VarArgsType *clone() const { return new VarArgsType( *this ); } |
---|
| 441 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 442 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 443 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 444 | }; |
---|
| 445 | |
---|
[89e6ffc] | 446 | /// Represents a zero constant |
---|
| 447 | class ZeroType : public Type { |
---|
| 448 | public: |
---|
| 449 | ZeroType(); |
---|
| 450 | ZeroType( Type::Qualifiers tq ); |
---|
| 451 | |
---|
| 452 | virtual ZeroType *clone() const { return new ZeroType( *this ); } |
---|
| 453 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 454 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 455 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 456 | }; |
---|
| 457 | |
---|
| 458 | /// Represents a one constant |
---|
| 459 | class OneType : public Type { |
---|
| 460 | public: |
---|
| 461 | OneType(); |
---|
| 462 | OneType( Type::Qualifiers tq ); |
---|
| 463 | |
---|
| 464 | virtual OneType *clone() const { return new OneType( *this ); } |
---|
| 465 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 466 | virtual Type *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 467 | virtual void print( std::ostream &os, int indent = 0 ) const; |
---|
| 468 | }; |
---|
| 469 | |
---|
[aa8f9df] | 470 | inline Type::Qualifiers &Type::Qualifiers::operator&=( const Type::Qualifiers &other ) { |
---|
| 471 | isConst &= other.isConst; |
---|
| 472 | isVolatile &= other.isVolatile; |
---|
| 473 | isRestrict &= other.isRestrict; |
---|
| 474 | isLvalue &= other.isLvalue; |
---|
| 475 | isAtomic &= other.isAtomic; |
---|
| 476 | return *this; |
---|
| 477 | } |
---|
| 478 | |
---|
[c8ffe20b] | 479 | inline Type::Qualifiers &Type::Qualifiers::operator+=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 480 | isConst |= other.isConst; |
---|
| 481 | isVolatile |= other.isVolatile; |
---|
| 482 | isRestrict |= other.isRestrict; |
---|
| 483 | isLvalue |= other.isLvalue; |
---|
| 484 | isAtomic |= other.isAtomic; |
---|
| 485 | return *this; |
---|
[51b7345] | 486 | } |
---|
| 487 | |
---|
[c8ffe20b] | 488 | inline Type::Qualifiers &Type::Qualifiers::operator-=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 489 | if ( other.isConst ) isConst = 0; |
---|
| 490 | if ( other.isVolatile ) isVolatile = 0; |
---|
| 491 | if ( other.isRestrict ) isRestrict = 0; |
---|
| 492 | if ( other.isAtomic ) isAtomic = 0; |
---|
| 493 | return *this; |
---|
[51b7345] | 494 | } |
---|
| 495 | |
---|
[c8ffe20b] | 496 | inline Type::Qualifiers Type::Qualifiers::operator+( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 497 | Qualifiers q = other; |
---|
| 498 | q += *this; |
---|
| 499 | return q; |
---|
[51b7345] | 500 | } |
---|
| 501 | |
---|
[c8ffe20b] | 502 | inline bool Type::Qualifiers::operator==( const Qualifiers &other ) { |
---|
[0dd3a2f] | 503 | return isConst == other.isConst |
---|
| 504 | && isVolatile == other.isVolatile |
---|
[f6835e5] | 505 | // && isRestrict == other.isRestrict |
---|
| 506 | // && isLvalue == other.isLvalue |
---|
[0dd3a2f] | 507 | && isAtomic == other.isAtomic; |
---|
[51b7345] | 508 | } |
---|
| 509 | |
---|
[c8ffe20b] | 510 | inline bool Type::Qualifiers::operator!=( const Qualifiers &other ) { |
---|
[0dd3a2f] | 511 | return isConst != other.isConst |
---|
| 512 | || isVolatile != other.isVolatile |
---|
[f6835e5] | 513 | // || isRestrict != other.isRestrict |
---|
| 514 | // || isLvalue != other.isLvalue |
---|
[0dd3a2f] | 515 | || isAtomic != other.isAtomic; |
---|
[51b7345] | 516 | } |
---|
| 517 | |
---|
[c8ffe20b] | 518 | inline bool Type::Qualifiers::operator<=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 519 | return isConst <= other.isConst |
---|
| 520 | && isVolatile <= other.isVolatile |
---|
[f6835e5] | 521 | // && isRestrict <= other.isRestrict |
---|
| 522 | // && isLvalue >= other.isLvalue |
---|
[0dd3a2f] | 523 | && isAtomic == other.isAtomic; |
---|
[51b7345] | 524 | } |
---|
| 525 | |
---|
[c8ffe20b] | 526 | inline bool Type::Qualifiers::operator>=( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 527 | return isConst >= other.isConst |
---|
| 528 | && isVolatile >= other.isVolatile |
---|
[f6835e5] | 529 | // && isRestrict >= other.isRestrict |
---|
| 530 | // && isLvalue <= other.isLvalue |
---|
[0dd3a2f] | 531 | && isAtomic == other.isAtomic; |
---|
[51b7345] | 532 | } |
---|
| 533 | |
---|
[c8ffe20b] | 534 | inline bool Type::Qualifiers::operator<( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 535 | return operator!=( other ) && operator<=( other ); |
---|
[51b7345] | 536 | } |
---|
| 537 | |
---|
[c8ffe20b] | 538 | inline bool Type::Qualifiers::operator>( const Type::Qualifiers &other ) { |
---|
[0dd3a2f] | 539 | return operator!=( other ) && operator>=( other ); |
---|
[51b7345] | 540 | } |
---|
| 541 | |
---|
[3906301] | 542 | std::ostream & operator<<( std::ostream & out, const Type * type ); |
---|
[baf7fee] | 543 | |
---|
[c8ffe20b] | 544 | #endif // TYPE_H |
---|
[0dd3a2f] | 545 | |
---|
| 546 | // Local Variables: // |
---|
| 547 | // tab-width: 4 // |
---|
| 548 | // mode: c++ // |
---|
| 549 | // compile-command: "make install" // |
---|
| 550 | // End: // |
---|