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