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