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