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