Type.h revision ad964b3c41f4fc5fb7e19a0ce28b200e137bab84
1//===--- Type.h - C Language Family Type Representation ---------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Type interface and subclasses. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_TYPE_H 15#define LLVM_CLANG_AST_TYPE_H 16 17#include "clang/Basic/Diagnostic.h" 18#include "llvm/Support/Casting.h" 19#include "llvm/ADT/APSInt.h" 20#include "llvm/ADT/FoldingSet.h" 21#include "llvm/ADT/PointerIntPair.h" 22#include "llvm/Bitcode/SerializationFwd.h" 23using llvm::isa; 24using llvm::cast; 25using llvm::cast_or_null; 26using llvm::dyn_cast; 27using llvm::dyn_cast_or_null; 28 29namespace clang { 30 class ASTContext; 31 class Type; 32 class TypedefDecl; 33 class TemplateDecl; 34 class TemplateTypeParmDecl; 35 class NonTypeTemplateParmDecl; 36 class TemplateTemplateParamDecl; 37 class TagDecl; 38 class RecordDecl; 39 class CXXRecordDecl; 40 class EnumDecl; 41 class FieldDecl; 42 class ObjCInterfaceDecl; 43 class ObjCProtocolDecl; 44 class ObjCMethodDecl; 45 class Expr; 46 class Stmt; 47 class SourceLocation; 48 class PointerLikeType; 49 class PointerType; 50 class BlockPointerType; 51 class ReferenceType; 52 class MemberPointerType; 53 class VectorType; 54 class ArrayType; 55 class ConstantArrayType; 56 class VariableArrayType; 57 class IncompleteArrayType; 58 class DependentSizedArrayType; 59 class RecordType; 60 class EnumType; 61 class ComplexType; 62 class TagType; 63 class TypedefType; 64 class TemplateTypeParmType; 65 class FunctionType; 66 class FunctionTypeProto; 67 class ExtVectorType; 68 class BuiltinType; 69 class ObjCInterfaceType; 70 class ObjCQualifiedIdType; 71 class ObjCQualifiedInterfaceType; 72 class StmtIteratorBase; 73 class ClassTemplateSpecializationType; 74 75/// QualType - For efficiency, we don't store CVR-qualified types as nodes on 76/// their own: instead each reference to a type stores the qualifiers. This 77/// greatly reduces the number of nodes we need to allocate for types (for 78/// example we only need one for 'int', 'const int', 'volatile int', 79/// 'const volatile int', etc). 80/// 81/// As an added efficiency bonus, instead of making this a pair, we just store 82/// the three bits we care about in the low bits of the pointer. To handle the 83/// packing/unpacking, we make QualType be a simple wrapper class that acts like 84/// a smart pointer. 85class QualType { 86 llvm::PointerIntPair<Type*, 3> Value; 87public: 88 enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ. 89 Const = 0x1, 90 Restrict = 0x2, 91 Volatile = 0x4, 92 CVRFlags = Const|Restrict|Volatile 93 }; 94 95 QualType() {} 96 97 QualType(const Type *Ptr, unsigned Quals) 98 : Value(const_cast<Type*>(Ptr), Quals) {} 99 100 unsigned getCVRQualifiers() const { return Value.getInt(); } 101 void setCVRQualifiers(unsigned Quals) { Value.setInt(Quals); } 102 Type *getTypePtr() const { return Value.getPointer(); } 103 104 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } 105 static QualType getFromOpaquePtr(void *Ptr) { 106 QualType T; 107 T.Value.setFromOpaqueValue(Ptr); 108 return T; 109 } 110 111 Type &operator*() const { 112 return *getTypePtr(); 113 } 114 115 Type *operator->() const { 116 return getTypePtr(); 117 } 118 119 /// isNull - Return true if this QualType doesn't point to a type yet. 120 bool isNull() const { 121 return getTypePtr() == 0; 122 } 123 124 bool isConstQualified() const { 125 return (getCVRQualifiers() & Const) ? true : false; 126 } 127 bool isVolatileQualified() const { 128 return (getCVRQualifiers() & Volatile) ? true : false; 129 } 130 bool isRestrictQualified() const { 131 return (getCVRQualifiers() & Restrict) ? true : false; 132 } 133 134 bool isConstant(ASTContext& Ctx) const; 135 136 /// addConst/addVolatile/addRestrict - add the specified type qual to this 137 /// QualType. 138 void addConst() { Value.setInt(Value.getInt() | Const); } 139 void addVolatile() { Value.setInt(Value.getInt() | Volatile); } 140 void addRestrict() { Value.setInt(Value.getInt() | Restrict); } 141 142 void removeConst() { Value.setInt(Value.getInt() & ~Const); } 143 void removeVolatile() { Value.setInt(Value.getInt() & ~Volatile); } 144 void removeRestrict() { Value.setInt(Value.getInt() & ~Restrict); } 145 146 QualType getQualifiedType(unsigned TQs) const { 147 return QualType(getTypePtr(), TQs); 148 } 149 QualType getWithAdditionalQualifiers(unsigned TQs) const { 150 return QualType(getTypePtr(), TQs|getCVRQualifiers()); 151 } 152 153 QualType withConst() const { return getWithAdditionalQualifiers(Const); } 154 QualType withVolatile() const { return getWithAdditionalQualifiers(Volatile);} 155 QualType withRestrict() const { return getWithAdditionalQualifiers(Restrict);} 156 157 QualType getUnqualifiedType() const; 158 bool isMoreQualifiedThan(QualType Other) const; 159 bool isAtLeastAsQualifiedAs(QualType Other) const; 160 QualType getNonReferenceType() const; 161 162 163 /// operator==/!= - Indicate whether the specified types and qualifiers are 164 /// identical. 165 bool operator==(const QualType &RHS) const { 166 return Value == RHS.Value; 167 } 168 bool operator!=(const QualType &RHS) const { 169 return Value != RHS.Value; 170 } 171 std::string getAsString() const { 172 std::string S; 173 getAsStringInternal(S); 174 return S; 175 } 176 void getAsStringInternal(std::string &Str) const; 177 178 void dump(const char *s) const; 179 void dump() const; 180 181 void Profile(llvm::FoldingSetNodeID &ID) const { 182 ID.AddPointer(getAsOpaquePtr()); 183 } 184 185public: 186 187 /// getAddressSpace - Return the address space of this type. 188 inline unsigned getAddressSpace() const; 189 190 /// Emit - Serialize a QualType to Bitcode. 191 void Emit(llvm::Serializer& S) const; 192 193 /// Read - Deserialize a QualType from Bitcode. 194 static QualType ReadVal(llvm::Deserializer& D); 195 196 void ReadBackpatch(llvm::Deserializer& D); 197}; 198 199} // end clang. 200 201namespace llvm { 202/// Implement simplify_type for QualType, so that we can dyn_cast from QualType 203/// to a specific Type class. 204template<> struct simplify_type<const ::clang::QualType> { 205 typedef ::clang::Type* SimpleType; 206 static SimpleType getSimplifiedValue(const ::clang::QualType &Val) { 207 return Val.getTypePtr(); 208 } 209}; 210template<> struct simplify_type< ::clang::QualType> 211 : public simplify_type<const ::clang::QualType> {}; 212 213} // end namespace llvm 214 215namespace clang { 216 217/// Type - This is the base class of the type hierarchy. A central concept 218/// with types is that each type always has a canonical type. A canonical type 219/// is the type with any typedef names stripped out of it or the types it 220/// references. For example, consider: 221/// 222/// typedef int foo; 223/// typedef foo* bar; 224/// 'int *' 'foo *' 'bar' 225/// 226/// There will be a Type object created for 'int'. Since int is canonical, its 227/// canonicaltype pointer points to itself. There is also a Type for 'foo' (a 228/// TypeNameType). Its CanonicalType pointer points to the 'int' Type. Next 229/// there is a PointerType that represents 'int*', which, like 'int', is 230/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical 231/// type is 'int*', and there is a TypeNameType for 'bar', whose canonical type 232/// is also 'int*'. 233/// 234/// Non-canonical types are useful for emitting diagnostics, without losing 235/// information about typedefs being used. Canonical types are useful for type 236/// comparisons (they allow by-pointer equality tests) and useful for reasoning 237/// about whether something has a particular form (e.g. is a function type), 238/// because they implicitly, recursively, strip all typedefs out of a type. 239/// 240/// Types, once created, are immutable. 241/// 242class Type { 243public: 244 enum TypeClass { 245 Builtin, Complex, Pointer, Reference, MemberPointer, 246 ConstantArray, VariableArray, IncompleteArray, DependentSizedArray, 247 Vector, ExtVector, 248 FunctionNoProto, FunctionProto, 249 TypeName, Tagged, ASQual, 250 TemplateTypeParm, ClassTemplateSpecialization, 251 ObjCInterface, ObjCQualifiedInterface, 252 ObjCQualifiedId, 253 TypeOfExp, TypeOfTyp, // GNU typeof extension. 254 BlockPointer, // C extension 255 FixedWidthInt 256 }; 257private: 258 QualType CanonicalType; 259 260 /// Dependent - Whether this type is a dependent type (C++ [temp.dep.type]). 261 bool Dependent : 1; 262 263 /// TypeClass bitfield - Enum that specifies what subclass this belongs to. 264 /// Note that this should stay at the end of the ivars for Type so that 265 /// subclasses can pack their bitfields into the same word. 266 unsigned TC : 5; 267 268protected: 269 // silence VC++ warning C4355: 'this' : used in base member initializer list 270 Type *this_() { return this; } 271 Type(TypeClass tc, QualType Canonical, bool dependent) 272 : CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical), 273 Dependent(dependent), TC(tc) {} 274 virtual ~Type() {} 275 virtual void Destroy(ASTContext& C); 276 friend class ASTContext; 277 278 void EmitTypeInternal(llvm::Serializer& S) const; 279 void ReadTypeInternal(llvm::Deserializer& D); 280 281public: 282 TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); } 283 284 bool isCanonical() const { return CanonicalType.getTypePtr() == this; } 285 286 /// Types are partitioned into 3 broad categories (C99 6.2.5p1): 287 /// object types, function types, and incomplete types. 288 289 /// isObjectType - types that fully describe objects. An object is a region 290 /// of memory that can be examined and stored into (H&S). 291 bool isObjectType() const; 292 293 /// isIncompleteType - Return true if this is an incomplete type. 294 /// A type that can describe objects, but which lacks information needed to 295 /// determine its size (e.g. void, or a fwd declared struct). Clients of this 296 /// routine will need to determine if the size is actually required. 297 bool isIncompleteType() const; 298 299 /// isIncompleteOrObjectType - Return true if this is an incomplete or object 300 /// type, in other words, not a function type. 301 bool isIncompleteOrObjectType() const { 302 return !isFunctionType(); 303 } 304 305 /// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10). 306 bool isPODType() const; 307 308 /// isVariablyModifiedType (C99 6.7.5.2p2) - Return true for variable array 309 /// types that have a non-constant expression. This does not include "[]". 310 bool isVariablyModifiedType() const; 311 312 /// Helper methods to distinguish type categories. All type predicates 313 /// operate on the canonical type, ignoring typedefs and qualifiers. 314 315 /// isIntegerType() does *not* include complex integers (a GCC extension). 316 /// isComplexIntegerType() can be used to test for complex integers. 317 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum) 318 bool isEnumeralType() const; 319 bool isBooleanType() const; 320 bool isCharType() const; 321 bool isWideCharType() const; 322 bool isIntegralType() const; 323 324 /// Floating point categories. 325 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double) 326 /// isComplexType() does *not* include complex integers (a GCC extension). 327 /// isComplexIntegerType() can be used to test for complex integers. 328 bool isComplexType() const; // C99 6.2.5p11 (complex) 329 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int. 330 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex) 331 bool isRealType() const; // C99 6.2.5p17 (real floating + integer) 332 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating) 333 bool isVoidType() const; // C99 6.2.5p19 334 bool isDerivedType() const; // C99 6.2.5p20 335 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers) 336 bool isAggregateType() const; 337 338 // Type Predicates: Check to see if this type is structurally the specified 339 // type, ignoring typedefs and qualifiers. 340 bool isFunctionType() const; 341 bool isPointerLikeType() const; // Pointer or Reference. 342 bool isPointerType() const; 343 bool isBlockPointerType() const; 344 bool isReferenceType() const; 345 bool isFunctionPointerType() const; 346 bool isMemberPointerType() const; 347 bool isMemberFunctionPointerType() const; 348 bool isArrayType() const; 349 bool isConstantArrayType() const; 350 bool isIncompleteArrayType() const; 351 bool isVariableArrayType() const; 352 bool isDependentSizedArrayType() const; 353 bool isRecordType() const; 354 bool isClassType() const; 355 bool isStructureType() const; 356 bool isUnionType() const; 357 bool isComplexIntegerType() const; // GCC _Complex integer type. 358 bool isVectorType() const; // GCC vector type. 359 bool isExtVectorType() const; // Extended vector type. 360 bool isObjCInterfaceType() const; // NSString or NSString<foo> 361 bool isObjCQualifiedInterfaceType() const; // NSString<foo> 362 bool isObjCQualifiedIdType() const; // id<foo> 363 bool isTemplateTypeParmType() const; // C++ template type parameter 364 365 /// isDependentType - Whether this type is a dependent type, meaning 366 /// that its definition somehow depends on a template parameter 367 /// (C++ [temp.dep.type]). 368 bool isDependentType() const { return Dependent; } 369 bool isOverloadType() const; // C++ overloaded function 370 371 // Type Checking Functions: Check to see if this type is structurally the 372 // specified type, ignoring typedefs and qualifiers, and return a pointer to 373 // the best type we can. 374 const BuiltinType *getAsBuiltinType() const; 375 const FunctionType *getAsFunctionType() const; 376 const FunctionTypeProto *getAsFunctionTypeProto() const; 377 const PointerLikeType *getAsPointerLikeType() const; // Pointer or Reference. 378 const PointerType *getAsPointerType() const; 379 const BlockPointerType *getAsBlockPointerType() const; 380 const ReferenceType *getAsReferenceType() const; 381 const MemberPointerType *getAsMemberPointerType() const; 382 const RecordType *getAsRecordType() const; 383 const RecordType *getAsStructureType() const; 384 /// NOTE: getAs*ArrayType are methods on ASTContext. 385 const TypedefType *getAsTypedefType() const; 386 const RecordType *getAsUnionType() const; 387 const EnumType *getAsEnumType() const; 388 const VectorType *getAsVectorType() const; // GCC vector type. 389 const ComplexType *getAsComplexType() const; 390 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type. 391 const ExtVectorType *getAsExtVectorType() const; // Extended vector type. 392 const ObjCInterfaceType *getAsObjCInterfaceType() const; 393 const ObjCQualifiedInterfaceType *getAsObjCQualifiedInterfaceType() const; 394 const ObjCQualifiedIdType *getAsObjCQualifiedIdType() const; 395 const TemplateTypeParmType *getAsTemplateTypeParmType() const; 396 397 const ClassTemplateSpecializationType * 398 getClassTemplateSpecializationType() const; 399 400 /// getAsPointerToObjCInterfaceType - If this is a pointer to an ObjC 401 /// interface, return the interface type, otherwise return null. 402 const ObjCInterfaceType *getAsPointerToObjCInterfaceType() const; 403 404 /// getArrayElementTypeNoTypeQual - If this is an array type, return the 405 /// element type of the array, potentially with type qualifiers missing. 406 /// This method should never be used when type qualifiers are meaningful. 407 const Type *getArrayElementTypeNoTypeQual() const; 408 409 /// getDesugaredType - Return the specified type with any "sugar" removed from 410 /// the type. This takes off typedefs, typeof's etc. If the outer level of 411 /// the type is already concrete, it returns it unmodified. This is similar 412 /// to getting the canonical type, but it doesn't remove *all* typedefs. For 413 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is 414 /// concrete. 415 QualType getDesugaredType() const; 416 417 /// More type predicates useful for type checking/promotion 418 bool isPromotableIntegerType() const; // C99 6.3.1.1p2 419 420 /// isSignedIntegerType - Return true if this is an integer type that is 421 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], 422 /// an enum decl which has a signed representation, or a vector of signed 423 /// integer element type. 424 bool isSignedIntegerType() const; 425 426 /// isUnsignedIntegerType - Return true if this is an integer type that is 427 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum 428 /// decl which has an unsigned representation, or a vector of unsigned integer 429 /// element type. 430 bool isUnsignedIntegerType() const; 431 432 /// isConstantSizeType - Return true if this is not a variable sized type, 433 /// according to the rules of C99 6.7.5p3. It is not legal to call this on 434 /// incomplete types. 435 bool isConstantSizeType() const; 436 437 QualType getCanonicalTypeInternal() const { return CanonicalType; } 438 void dump() const; 439 virtual void getAsStringInternal(std::string &InnerString) const = 0; 440 static bool classof(const Type *) { return true; } 441 442protected: 443 /// Emit - Emit a Type to bitcode. Used by ASTContext. 444 void Emit(llvm::Serializer& S) const; 445 446 /// Create - Construct a Type from bitcode. Used by ASTContext. 447 static void Create(ASTContext& Context, unsigned i, llvm::Deserializer& S); 448 449 /// EmitImpl - Subclasses must implement this method in order to 450 /// be serialized. 451 // FIXME: Make this abstract once implemented. 452 virtual void EmitImpl(llvm::Serializer& S) const { 453 assert (false && "Serializization for type not supported."); 454 } 455}; 456 457/// ASQualType - TR18037 (C embedded extensions) 6.2.5p26 458/// This supports address space qualified types. 459/// 460class ASQualType : public Type, public llvm::FoldingSetNode { 461 /// BaseType - This is the underlying type that this qualifies. All CVR 462 /// qualifiers are stored on the QualType that references this type, so we 463 /// can't have any here. 464 Type *BaseType; 465 /// Address Space ID - The address space ID this type is qualified with. 466 unsigned AddressSpace; 467 ASQualType(Type *Base, QualType CanonicalPtr, unsigned AddrSpace) : 468 Type(ASQual, CanonicalPtr, Base->isDependentType()), BaseType(Base), 469 AddressSpace(AddrSpace) { 470 } 471 friend class ASTContext; // ASTContext creates these. 472public: 473 Type *getBaseType() const { return BaseType; } 474 unsigned getAddressSpace() const { return AddressSpace; } 475 476 virtual void getAsStringInternal(std::string &InnerString) const; 477 478 void Profile(llvm::FoldingSetNodeID &ID) { 479 Profile(ID, getBaseType(), AddressSpace); 480 } 481 static void Profile(llvm::FoldingSetNodeID &ID, Type *Base, 482 unsigned AddrSpace) { 483 ID.AddPointer(Base); 484 ID.AddInteger(AddrSpace); 485 } 486 487 static bool classof(const Type *T) { return T->getTypeClass() == ASQual; } 488 static bool classof(const ASQualType *) { return true; } 489 490protected: 491 virtual void EmitImpl(llvm::Serializer& S) const; 492 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 493 friend class Type; 494}; 495 496 497/// BuiltinType - This class is used for builtin types like 'int'. Builtin 498/// types are always canonical and have a literal name field. 499class BuiltinType : public Type { 500public: 501 enum Kind { 502 Void, 503 504 Bool, // This is bool and/or _Bool. 505 Char_U, // This is 'char' for targets where char is unsigned. 506 UChar, // This is explicitly qualified unsigned char. 507 UShort, 508 UInt, 509 ULong, 510 ULongLong, 511 512 Char_S, // This is 'char' for targets where char is signed. 513 SChar, // This is explicitly qualified signed char. 514 WChar, // This is 'wchar_t' for C++. 515 Short, 516 Int, 517 Long, 518 LongLong, 519 520 Float, Double, LongDouble, 521 522 Overload, // This represents the type of an overloaded function declaration. 523 Dependent // This represents the type of a type-dependent expression. 524 }; 525private: 526 Kind TypeKind; 527public: 528 BuiltinType(Kind K) 529 : Type(Builtin, QualType(), /*Dependent=*/(K == Dependent)), 530 TypeKind(K) {} 531 532 Kind getKind() const { return TypeKind; } 533 const char *getName() const; 534 535 virtual void getAsStringInternal(std::string &InnerString) const; 536 537 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } 538 static bool classof(const BuiltinType *) { return true; } 539}; 540 541/// FixedWidthIntType - Used for arbitrary width types that we either don't 542/// want to or can't map to named integer types. These always have a lower 543/// integer rank than builtin types of the same width. 544class FixedWidthIntType : public Type { 545private: 546 unsigned Width; 547 bool Signed; 548public: 549 FixedWidthIntType(unsigned W, bool S) : Type(FixedWidthInt, QualType(), false), 550 Width(W), Signed(S) {} 551 552 unsigned getWidth() const { return Width; } 553 bool isSigned() const { return Signed; } 554 const char *getName() const; 555 556 virtual void getAsStringInternal(std::string &InnerString) const; 557 558 static bool classof(const Type *T) { return T->getTypeClass() == FixedWidthInt; } 559 static bool classof(const FixedWidthIntType *) { return true; } 560}; 561 562/// ComplexType - C99 6.2.5p11 - Complex values. This supports the C99 complex 563/// types (_Complex float etc) as well as the GCC integer complex extensions. 564/// 565class ComplexType : public Type, public llvm::FoldingSetNode { 566 QualType ElementType; 567 ComplexType(QualType Element, QualType CanonicalPtr) : 568 Type(Complex, CanonicalPtr, Element->isDependentType()), 569 ElementType(Element) { 570 } 571 friend class ASTContext; // ASTContext creates these. 572public: 573 QualType getElementType() const { return ElementType; } 574 575 virtual void getAsStringInternal(std::string &InnerString) const; 576 577 void Profile(llvm::FoldingSetNodeID &ID) { 578 Profile(ID, getElementType()); 579 } 580 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { 581 ID.AddPointer(Element.getAsOpaquePtr()); 582 } 583 584 static bool classof(const Type *T) { return T->getTypeClass() == Complex; } 585 static bool classof(const ComplexType *) { return true; } 586 587protected: 588 virtual void EmitImpl(llvm::Serializer& S) const; 589 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 590 friend class Type; 591}; 592 593/// PointerLikeType - Common base class for pointers and references. 594/// FIXME: Add more documentation on this classes design point. For example, 595/// should BlockPointerType inherit from it? Is the concept of a PointerLikeType 596/// in the C++ standard? 597/// 598class PointerLikeType : public Type { 599 QualType PointeeType; 600protected: 601 PointerLikeType(TypeClass K, QualType Pointee, QualType CanonicalPtr) : 602 Type(K, CanonicalPtr, Pointee->isDependentType()), PointeeType(Pointee) { 603 } 604public: 605 606 QualType getPointeeType() const { return PointeeType; } 607 608 static bool classof(const Type *T) { 609 return T->getTypeClass() == Pointer || T->getTypeClass() == Reference; 610 } 611 static bool classof(const PointerLikeType *) { return true; } 612}; 613 614/// PointerType - C99 6.7.5.1 - Pointer Declarators. 615/// 616class PointerType : public PointerLikeType, public llvm::FoldingSetNode { 617 PointerType(QualType Pointee, QualType CanonicalPtr) : 618 PointerLikeType(Pointer, Pointee, CanonicalPtr) { 619 } 620 friend class ASTContext; // ASTContext creates these. 621public: 622 623 virtual void getAsStringInternal(std::string &InnerString) const; 624 625 void Profile(llvm::FoldingSetNodeID &ID) { 626 Profile(ID, getPointeeType()); 627 } 628 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 629 ID.AddPointer(Pointee.getAsOpaquePtr()); 630 } 631 632 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } 633 static bool classof(const PointerType *) { return true; } 634 635protected: 636 virtual void EmitImpl(llvm::Serializer& S) const; 637 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 638 friend class Type; 639}; 640 641/// BlockPointerType - pointer to a block type. 642/// This type is to represent types syntactically represented as 643/// "void (^)(int)", etc. Pointee is required to always be a function type. 644/// FIXME: Should BlockPointerType inherit from PointerLikeType? It could 645/// simplfy some type checking code, however PointerLikeType doesn't appear 646/// to be used by the type checker. 647/// 648class BlockPointerType : public Type, public llvm::FoldingSetNode { 649 QualType PointeeType; // Block is some kind of pointer type 650 BlockPointerType(QualType Pointee, QualType CanonicalCls) : 651 Type(BlockPointer, CanonicalCls, Pointee->isDependentType()), 652 PointeeType(Pointee) { 653 } 654 friend class ASTContext; // ASTContext creates these. 655public: 656 657 // Get the pointee type. Pointee is required to always be a function type. 658 QualType getPointeeType() const { return PointeeType; } 659 660 virtual void getAsStringInternal(std::string &InnerString) const; 661 662 void Profile(llvm::FoldingSetNodeID &ID) { 663 Profile(ID, getPointeeType()); 664 } 665 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { 666 ID.AddPointer(Pointee.getAsOpaquePtr()); 667 } 668 669 static bool classof(const Type *T) { 670 return T->getTypeClass() == BlockPointer; 671 } 672 static bool classof(const BlockPointerType *) { return true; } 673 674 protected: 675 virtual void EmitImpl(llvm::Serializer& S) const; 676 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 677 friend class Type; 678}; 679 680/// ReferenceType - C++ 8.3.2 - Reference Declarators. 681/// 682class ReferenceType : public PointerLikeType, public llvm::FoldingSetNode { 683 ReferenceType(QualType Referencee, QualType CanonicalRef) : 684 PointerLikeType(Reference, Referencee, CanonicalRef) { 685 } 686 friend class ASTContext; // ASTContext creates these. 687public: 688 virtual void getAsStringInternal(std::string &InnerString) const; 689 690 void Profile(llvm::FoldingSetNodeID &ID) { 691 Profile(ID, getPointeeType()); 692 } 693 static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee) { 694 ID.AddPointer(Referencee.getAsOpaquePtr()); 695 } 696 697 static bool classof(const Type *T) { return T->getTypeClass() == Reference; } 698 static bool classof(const ReferenceType *) { return true; } 699 700protected: 701 virtual void EmitImpl(llvm::Serializer& S) const; 702 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 703 friend class Type; 704}; 705 706/// MemberPointerType - C++ 8.3.3 - Pointers to members 707/// 708class MemberPointerType : public Type, public llvm::FoldingSetNode { 709 QualType PointeeType; 710 /// The class of which the pointee is a member. Must ultimately be a 711 /// RecordType, but could be a typedef or a template parameter too. 712 const Type *Class; 713 714 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) : 715 Type(MemberPointer, CanonicalPtr, 716 Cls->isDependentType() || Pointee->isDependentType()), 717 PointeeType(Pointee), Class(Cls) { 718 } 719 friend class ASTContext; // ASTContext creates these. 720public: 721 722 QualType getPointeeType() const { return PointeeType; } 723 724 const Type *getClass() const { return Class; } 725 726 virtual void getAsStringInternal(std::string &InnerString) const; 727 728 void Profile(llvm::FoldingSetNodeID &ID) { 729 Profile(ID, getPointeeType(), getClass()); 730 } 731 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, 732 const Type *Class) { 733 ID.AddPointer(Pointee.getAsOpaquePtr()); 734 ID.AddPointer(Class); 735 } 736 737 static bool classof(const Type *T) { 738 return T->getTypeClass() == MemberPointer; 739 } 740 static bool classof(const MemberPointerType *) { return true; } 741 742protected: 743 virtual void EmitImpl(llvm::Serializer& S) const; 744 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 745 friend class Type; 746}; 747 748/// ArrayType - C99 6.7.5.2 - Array Declarators. 749/// 750class ArrayType : public Type, public llvm::FoldingSetNode { 751public: 752 /// ArraySizeModifier - Capture whether this is a normal array (e.g. int X[4]) 753 /// an array with a static size (e.g. int X[static 4]), or an array 754 /// with a star size (e.g. int X[*]). 755 /// 'static' is only allowed on function parameters. 756 enum ArraySizeModifier { 757 Normal, Static, Star 758 }; 759private: 760 /// ElementType - The element type of the array. 761 QualType ElementType; 762 763 // NOTE: VC++ treats enums as signed, avoid using the ArraySizeModifier enum 764 /// NOTE: These fields are packed into the bitfields space in the Type class. 765 unsigned SizeModifier : 2; 766 767 /// IndexTypeQuals - Capture qualifiers in declarations like: 768 /// 'int X[static restrict 4]'. For function parameters only. 769 unsigned IndexTypeQuals : 3; 770 771protected: 772 // C++ [temp.dep.type]p1: 773 // A type is dependent if it is... 774 // - an array type constructed from any dependent type or whose 775 // size is specified by a constant expression that is 776 // value-dependent, 777 ArrayType(TypeClass tc, QualType et, QualType can, 778 ArraySizeModifier sm, unsigned tq) 779 : Type(tc, can, et->isDependentType() || tc == DependentSizedArray), 780 ElementType(et), SizeModifier(sm), IndexTypeQuals(tq) {} 781 782 friend class ASTContext; // ASTContext creates these. 783public: 784 QualType getElementType() const { return ElementType; } 785 ArraySizeModifier getSizeModifier() const { 786 return ArraySizeModifier(SizeModifier); 787 } 788 unsigned getIndexTypeQualifier() const { return IndexTypeQuals; } 789 790 static bool classof(const Type *T) { 791 return T->getTypeClass() == ConstantArray || 792 T->getTypeClass() == VariableArray || 793 T->getTypeClass() == IncompleteArray || 794 T->getTypeClass() == DependentSizedArray; 795 } 796 static bool classof(const ArrayType *) { return true; } 797}; 798 799/// ConstantArrayType - This class represents C arrays with a specified constant 800/// size. For example 'int A[100]' has ConstantArrayType where the element type 801/// is 'int' and the size is 100. 802class ConstantArrayType : public ArrayType { 803 llvm::APInt Size; // Allows us to unique the type. 804 805 ConstantArrayType(QualType et, QualType can, llvm::APInt sz, 806 ArraySizeModifier sm, unsigned tq) 807 : ArrayType(ConstantArray, et, can, sm, tq), Size(sz) {} 808 friend class ASTContext; // ASTContext creates these. 809public: 810 const llvm::APInt &getSize() const { return Size; } 811 virtual void getAsStringInternal(std::string &InnerString) const; 812 813 void Profile(llvm::FoldingSetNodeID &ID) { 814 Profile(ID, getElementType(), getSize()); 815 } 816 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, 817 llvm::APInt ArraySize) { 818 ID.AddPointer(ET.getAsOpaquePtr()); 819 ID.AddInteger(ArraySize.getZExtValue()); 820 } 821 static bool classof(const Type *T) { 822 return T->getTypeClass() == ConstantArray; 823 } 824 static bool classof(const ConstantArrayType *) { return true; } 825 826protected: 827 virtual void EmitImpl(llvm::Serializer& S) const; 828 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 829 friend class Type; 830}; 831 832/// IncompleteArrayType - This class represents C arrays with an unspecified 833/// size. For example 'int A[]' has an IncompleteArrayType where the element 834/// type is 'int' and the size is unspecified. 835class IncompleteArrayType : public ArrayType { 836 IncompleteArrayType(QualType et, QualType can, 837 ArraySizeModifier sm, unsigned tq) 838 : ArrayType(IncompleteArray, et, can, sm, tq) {} 839 friend class ASTContext; // ASTContext creates these. 840public: 841 842 virtual void getAsStringInternal(std::string &InnerString) const; 843 844 static bool classof(const Type *T) { 845 return T->getTypeClass() == IncompleteArray; 846 } 847 static bool classof(const IncompleteArrayType *) { return true; } 848 849 friend class StmtIteratorBase; 850 851 void Profile(llvm::FoldingSetNodeID &ID) { 852 Profile(ID, getElementType()); 853 } 854 855 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET) { 856 ID.AddPointer(ET.getAsOpaquePtr()); 857 } 858 859protected: 860 virtual void EmitImpl(llvm::Serializer& S) const; 861 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 862 friend class Type; 863}; 864 865/// VariableArrayType - This class represents C arrays with a specified size 866/// which is not an integer-constant-expression. For example, 'int s[x+foo()]'. 867/// Since the size expression is an arbitrary expression, we store it as such. 868/// 869/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and 870/// should not be: two lexically equivalent variable array types could mean 871/// different things, for example, these variables do not have the same type 872/// dynamically: 873/// 874/// void foo(int x) { 875/// int Y[x]; 876/// ++x; 877/// int Z[x]; 878/// } 879/// 880class VariableArrayType : public ArrayType { 881 /// SizeExpr - An assignment expression. VLA's are only permitted within 882 /// a function block. 883 Stmt *SizeExpr; 884 885 VariableArrayType(QualType et, QualType can, Expr *e, 886 ArraySizeModifier sm, unsigned tq) 887 : ArrayType(VariableArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 888 friend class ASTContext; // ASTContext creates these. 889 virtual void Destroy(ASTContext& C); 890 891public: 892 Expr *getSizeExpr() const { 893 // We use C-style casts instead of cast<> here because we do not wish 894 // to have a dependency of Type.h on Stmt.h/Expr.h. 895 return (Expr*) SizeExpr; 896 } 897 898 virtual void getAsStringInternal(std::string &InnerString) const; 899 900 static bool classof(const Type *T) { 901 return T->getTypeClass() == VariableArray; 902 } 903 static bool classof(const VariableArrayType *) { return true; } 904 905 friend class StmtIteratorBase; 906 907 void Profile(llvm::FoldingSetNodeID &ID) { 908 assert (0 && "Cannnot unique VariableArrayTypes."); 909 } 910 911protected: 912 virtual void EmitImpl(llvm::Serializer& S) const; 913 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 914 friend class Type; 915}; 916 917/// DependentSizedArrayType - This type represents an array type in 918/// C++ whose size is a value-dependent expression. For example: 919/// @code 920/// template<typename T, int Size> 921/// class array { 922/// T data[Size]; 923/// }; 924/// @endcode 925/// For these types, we won't actually know what the array bound is 926/// until template instantiation occurs, at which point this will 927/// become either a ConstantArrayType or a VariableArrayType. 928class DependentSizedArrayType : public ArrayType { 929 /// SizeExpr - An assignment expression that will instantiate to the 930 /// size of the array. 931 Stmt *SizeExpr; 932 933 DependentSizedArrayType(QualType et, QualType can, Expr *e, 934 ArraySizeModifier sm, unsigned tq) 935 : ArrayType(DependentSizedArray, et, can, sm, tq), SizeExpr((Stmt*) e) {} 936 friend class ASTContext; // ASTContext creates these. 937 virtual void Destroy(ASTContext& C); 938 939public: 940 Expr *getSizeExpr() const { 941 // We use C-style casts instead of cast<> here because we do not wish 942 // to have a dependency of Type.h on Stmt.h/Expr.h. 943 return (Expr*) SizeExpr; 944 } 945 946 virtual void getAsStringInternal(std::string &InnerString) const; 947 948 static bool classof(const Type *T) { 949 return T->getTypeClass() == DependentSizedArray; 950 } 951 static bool classof(const DependentSizedArrayType *) { return true; } 952 953 friend class StmtIteratorBase; 954 955 void Profile(llvm::FoldingSetNodeID &ID) { 956 assert (0 && "Cannnot unique DependentSizedArrayTypes."); 957 } 958 959protected: 960 virtual void EmitImpl(llvm::Serializer& S) const; 961 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 962 friend class Type; 963}; 964 965/// VectorType - GCC generic vector type. This type is created using 966/// __attribute__((vector_size(n)), where "n" specifies the vector size in 967/// bytes. Since the constructor takes the number of vector elements, the 968/// client is responsible for converting the size into the number of elements. 969class VectorType : public Type, public llvm::FoldingSetNode { 970protected: 971 /// ElementType - The element type of the vector. 972 QualType ElementType; 973 974 /// NumElements - The number of elements in the vector. 975 unsigned NumElements; 976 977 VectorType(QualType vecType, unsigned nElements, QualType canonType) : 978 Type(Vector, canonType, vecType->isDependentType()), 979 ElementType(vecType), NumElements(nElements) {} 980 VectorType(TypeClass tc, QualType vecType, unsigned nElements, 981 QualType canonType) 982 : Type(tc, canonType, vecType->isDependentType()), ElementType(vecType), 983 NumElements(nElements) {} 984 friend class ASTContext; // ASTContext creates these. 985public: 986 987 QualType getElementType() const { return ElementType; } 988 unsigned getNumElements() const { return NumElements; } 989 990 virtual void getAsStringInternal(std::string &InnerString) const; 991 992 void Profile(llvm::FoldingSetNodeID &ID) { 993 Profile(ID, getElementType(), getNumElements(), getTypeClass()); 994 } 995 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, 996 unsigned NumElements, TypeClass TypeClass) { 997 ID.AddPointer(ElementType.getAsOpaquePtr()); 998 ID.AddInteger(NumElements); 999 ID.AddInteger(TypeClass); 1000 } 1001 static bool classof(const Type *T) { 1002 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; 1003 } 1004 static bool classof(const VectorType *) { return true; } 1005}; 1006 1007/// ExtVectorType - Extended vector type. This type is created using 1008/// __attribute__((ext_vector_type(n)), where "n" is the number of elements. 1009/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This 1010/// class enables syntactic extensions, like Vector Components for accessing 1011/// points, colors, and textures (modeled after OpenGL Shading Language). 1012class ExtVectorType : public VectorType { 1013 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) : 1014 VectorType(ExtVector, vecType, nElements, canonType) {} 1015 friend class ASTContext; // ASTContext creates these. 1016public: 1017 static int getPointAccessorIdx(char c) { 1018 switch (c) { 1019 default: return -1; 1020 case 'x': return 0; 1021 case 'y': return 1; 1022 case 'z': return 2; 1023 case 'w': return 3; 1024 } 1025 } 1026 static int getNumericAccessorIdx(char c) { 1027 switch (c) { 1028 default: return -1; 1029 case '0': return 0; 1030 case '1': return 1; 1031 case '2': return 2; 1032 case '3': return 3; 1033 case '4': return 4; 1034 case '5': return 5; 1035 case '6': return 6; 1036 case '7': return 7; 1037 case '8': return 8; 1038 case '9': return 9; 1039 case 'a': return 10; 1040 case 'b': return 11; 1041 case 'c': return 12; 1042 case 'd': return 13; 1043 case 'e': return 14; 1044 case 'f': return 15; 1045 } 1046 } 1047 1048 static int getAccessorIdx(char c) { 1049 if (int idx = getPointAccessorIdx(c)+1) return idx-1; 1050 return getNumericAccessorIdx(c); 1051 } 1052 1053 bool isAccessorWithinNumElements(char c) const { 1054 if (int idx = getAccessorIdx(c)+1) 1055 return unsigned(idx-1) < NumElements; 1056 return false; 1057 } 1058 virtual void getAsStringInternal(std::string &InnerString) const; 1059 1060 static bool classof(const Type *T) { 1061 return T->getTypeClass() == ExtVector; 1062 } 1063 static bool classof(const ExtVectorType *) { return true; } 1064}; 1065 1066/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base 1067/// class of FunctionTypeNoProto and FunctionTypeProto. 1068/// 1069class FunctionType : public Type { 1070 /// SubClassData - This field is owned by the subclass, put here to pack 1071 /// tightly with the ivars in Type. 1072 bool SubClassData : 1; 1073 1074 /// TypeQuals - Used only by FunctionTypeProto, put here to pack with the 1075 /// other bitfields. 1076 /// The qualifiers are part of FunctionTypeProto because... 1077 /// 1078 /// C++ 8.3.5p4: The return type, the parameter type list and the 1079 /// cv-qualifier-seq, [...], are part of the function type. 1080 /// 1081 unsigned TypeQuals : 3; 1082 1083 // The type returned by the function. 1084 QualType ResultType; 1085protected: 1086 FunctionType(TypeClass tc, QualType res, bool SubclassInfo, 1087 unsigned typeQuals, QualType Canonical, bool Dependent) 1088 : Type(tc, Canonical, Dependent), 1089 SubClassData(SubclassInfo), TypeQuals(typeQuals), ResultType(res) {} 1090 bool getSubClassData() const { return SubClassData; } 1091 unsigned getTypeQuals() const { return TypeQuals; } 1092public: 1093 1094 QualType getResultType() const { return ResultType; } 1095 1096 1097 static bool classof(const Type *T) { 1098 return T->getTypeClass() == FunctionNoProto || 1099 T->getTypeClass() == FunctionProto; 1100 } 1101 static bool classof(const FunctionType *) { return true; } 1102}; 1103 1104/// FunctionTypeNoProto - Represents a K&R-style 'int foo()' function, which has 1105/// no information available about its arguments. 1106class FunctionTypeNoProto : public FunctionType, public llvm::FoldingSetNode { 1107 FunctionTypeNoProto(QualType Result, QualType Canonical) 1108 : FunctionType(FunctionNoProto, Result, false, 0, Canonical, 1109 /*Dependent=*/false) {} 1110 friend class ASTContext; // ASTContext creates these. 1111public: 1112 // No additional state past what FunctionType provides. 1113 1114 virtual void getAsStringInternal(std::string &InnerString) const; 1115 1116 void Profile(llvm::FoldingSetNodeID &ID) { 1117 Profile(ID, getResultType()); 1118 } 1119 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType) { 1120 ID.AddPointer(ResultType.getAsOpaquePtr()); 1121 } 1122 1123 static bool classof(const Type *T) { 1124 return T->getTypeClass() == FunctionNoProto; 1125 } 1126 static bool classof(const FunctionTypeNoProto *) { return true; } 1127 1128protected: 1129 virtual void EmitImpl(llvm::Serializer& S) const; 1130 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 1131 friend class Type; 1132}; 1133 1134/// FunctionTypeProto - Represents a prototype with argument type info, e.g. 1135/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no 1136/// arguments, not as having a single void argument. 1137class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode { 1138 /// hasAnyDependentType - Determine whether there are any dependent 1139 /// types within the arguments passed in. 1140 static bool hasAnyDependentType(const QualType *ArgArray, unsigned numArgs) { 1141 for (unsigned Idx = 0; Idx < numArgs; ++Idx) 1142 if (ArgArray[Idx]->isDependentType()) 1143 return true; 1144 1145 return false; 1146 } 1147 1148 FunctionTypeProto(QualType Result, const QualType *ArgArray, unsigned numArgs, 1149 bool isVariadic, unsigned typeQuals, QualType Canonical) 1150 : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, 1151 (Result->isDependentType() || 1152 hasAnyDependentType(ArgArray, numArgs))), 1153 NumArgs(numArgs) { 1154 // Fill in the trailing argument array. 1155 QualType *ArgInfo = reinterpret_cast<QualType *>(this+1);; 1156 for (unsigned i = 0; i != numArgs; ++i) 1157 ArgInfo[i] = ArgArray[i]; 1158 } 1159 1160 /// NumArgs - The number of arguments this function has, not counting '...'. 1161 unsigned NumArgs; 1162 1163 /// ArgInfo - There is an variable size array after the class in memory that 1164 /// holds the argument types. 1165 1166 friend class ASTContext; // ASTContext creates these. 1167 1168public: 1169 unsigned getNumArgs() const { return NumArgs; } 1170 QualType getArgType(unsigned i) const { 1171 assert(i < NumArgs && "Invalid argument number!"); 1172 return arg_type_begin()[i]; 1173 } 1174 1175 bool isVariadic() const { return getSubClassData(); } 1176 unsigned getTypeQuals() const { return FunctionType::getTypeQuals(); } 1177 1178 typedef const QualType *arg_type_iterator; 1179 arg_type_iterator arg_type_begin() const { 1180 return reinterpret_cast<const QualType *>(this+1); 1181 } 1182 arg_type_iterator arg_type_end() const { return arg_type_begin()+NumArgs; } 1183 1184 virtual void getAsStringInternal(std::string &InnerString) const; 1185 1186 static bool classof(const Type *T) { 1187 return T->getTypeClass() == FunctionProto; 1188 } 1189 static bool classof(const FunctionTypeProto *) { return true; } 1190 1191 void Profile(llvm::FoldingSetNodeID &ID); 1192 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, 1193 arg_type_iterator ArgTys, unsigned NumArgs, 1194 bool isVariadic, unsigned TypeQuals); 1195 1196protected: 1197 virtual void EmitImpl(llvm::Serializer& S) const; 1198 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 1199 friend class Type; 1200}; 1201 1202 1203class TypedefType : public Type { 1204 TypedefDecl *Decl; 1205protected: 1206 TypedefType(TypeClass tc, TypedefDecl *D, QualType can) 1207 : Type(tc, can, can->isDependentType()), Decl(D) { 1208 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1209 } 1210 friend class ASTContext; // ASTContext creates these. 1211public: 1212 1213 TypedefDecl *getDecl() const { return Decl; } 1214 1215 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to 1216 /// potentially looking through *all* consecutive typedefs. This returns the 1217 /// sum of the type qualifiers, so if you have: 1218 /// typedef const int A; 1219 /// typedef volatile A B; 1220 /// looking through the typedefs for B will give you "const volatile A". 1221 QualType LookThroughTypedefs() const; 1222 1223 virtual void getAsStringInternal(std::string &InnerString) const; 1224 1225 static bool classof(const Type *T) { return T->getTypeClass() == TypeName; } 1226 static bool classof(const TypedefType *) { return true; } 1227 1228protected: 1229 virtual void EmitImpl(llvm::Serializer& S) const; 1230 static Type* CreateImpl(ASTContext& Context,llvm::Deserializer& D); 1231 friend class Type; 1232}; 1233 1234/// TypeOfExpr (GCC extension). 1235class TypeOfExpr : public Type { 1236 Expr *TOExpr; 1237 TypeOfExpr(Expr *E, QualType can); 1238 friend class ASTContext; // ASTContext creates these. 1239public: 1240 Expr *getUnderlyingExpr() const { return TOExpr; } 1241 1242 virtual void getAsStringInternal(std::string &InnerString) const; 1243 1244 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExp; } 1245 static bool classof(const TypeOfExpr *) { return true; } 1246 1247protected: 1248 virtual void EmitImpl(llvm::Serializer& S) const; 1249 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1250 friend class Type; 1251}; 1252 1253/// TypeOfType (GCC extension). 1254class TypeOfType : public Type { 1255 QualType TOType; 1256 TypeOfType(QualType T, QualType can) 1257 : Type(TypeOfTyp, can, T->isDependentType()), TOType(T) { 1258 assert(!isa<TypedefType>(can) && "Invalid canonical type"); 1259 } 1260 friend class ASTContext; // ASTContext creates these. 1261public: 1262 QualType getUnderlyingType() const { return TOType; } 1263 1264 virtual void getAsStringInternal(std::string &InnerString) const; 1265 1266 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfTyp; } 1267 static bool classof(const TypeOfType *) { return true; } 1268 1269protected: 1270 virtual void EmitImpl(llvm::Serializer& S) const; 1271 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1272 friend class Type; 1273}; 1274 1275class TagType : public Type { 1276 /// Stores the TagDecl associated with this type. The decl will 1277 /// point to the TagDecl that actually defines the entity (or is a 1278 /// definition in progress), if there is such a definition. The 1279 /// single-bit value will be non-zero when this tag is in the 1280 /// process of being defined. 1281 llvm::PointerIntPair<TagDecl *, 1> decl; 1282 friend class ASTContext; 1283 friend class TagDecl; 1284 1285protected: 1286 // FIXME: We'll need the user to pass in information about whether 1287 // this type is dependent or not, because we don't have enough 1288 // information to compute it here. 1289 TagType(TagDecl *D, QualType can) 1290 : Type(Tagged, can, /*Dependent=*/false), decl(D, 0) {} 1291 1292public: 1293 TagDecl *getDecl() const { return decl.getPointer(); } 1294 1295 /// @brief Determines whether this type is in the process of being 1296 /// defined. 1297 bool isBeingDefined() const { return decl.getInt(); } 1298 void setBeingDefined(bool Def) { decl.setInt(Def? 1 : 0); } 1299 1300 virtual void getAsStringInternal(std::string &InnerString) const; 1301 1302 static bool classof(const Type *T) { return T->getTypeClass() == Tagged; } 1303 static bool classof(const TagType *) { return true; } 1304 1305protected: 1306 virtual void EmitImpl(llvm::Serializer& S) const; 1307 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1308 friend class Type; 1309}; 1310 1311/// RecordType - This is a helper class that allows the use of isa/cast/dyncast 1312/// to detect TagType objects of structs/unions/classes. 1313class RecordType : public TagType { 1314protected: 1315 explicit RecordType(RecordDecl *D) 1316 : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { } 1317 friend class ASTContext; // ASTContext creates these. 1318public: 1319 1320 RecordDecl *getDecl() const { 1321 return reinterpret_cast<RecordDecl*>(TagType::getDecl()); 1322 } 1323 1324 // FIXME: This predicate is a helper to QualType/Type. It needs to 1325 // recursively check all fields for const-ness. If any field is declared 1326 // const, it needs to return false. 1327 bool hasConstFields() const { return false; } 1328 1329 // FIXME: RecordType needs to check when it is created that all fields are in 1330 // the same address space, and return that. 1331 unsigned getAddressSpace() const { return 0; } 1332 1333 static bool classof(const TagType *T); 1334 static bool classof(const Type *T) { 1335 return isa<TagType>(T) && classof(cast<TagType>(T)); 1336 } 1337 static bool classof(const RecordType *) { return true; } 1338}; 1339 1340/// CXXRecordType - This is a helper class that allows the use of 1341/// isa/cast/dyncast to detect TagType objects of C++ structs/unions/classes. 1342class CXXRecordType : public RecordType { 1343 explicit CXXRecordType(CXXRecordDecl *D) 1344 : RecordType(reinterpret_cast<RecordDecl*>(D)) { } 1345 friend class ASTContext; // ASTContext creates these. 1346public: 1347 1348 CXXRecordDecl *getDecl() const { 1349 return reinterpret_cast<CXXRecordDecl*>(RecordType::getDecl()); 1350 } 1351 1352 static bool classof(const TagType *T); 1353 static bool classof(const Type *T) { 1354 return isa<TagType>(T) && classof(cast<TagType>(T)); 1355 } 1356 static bool classof(const CXXRecordType *) { return true; } 1357}; 1358 1359/// EnumType - This is a helper class that allows the use of isa/cast/dyncast 1360/// to detect TagType objects of enums. 1361class EnumType : public TagType { 1362 explicit EnumType(EnumDecl *D) 1363 : TagType(reinterpret_cast<TagDecl*>(D), QualType()) { } 1364 friend class ASTContext; // ASTContext creates these. 1365public: 1366 1367 EnumDecl *getDecl() const { 1368 return reinterpret_cast<EnumDecl*>(TagType::getDecl()); 1369 } 1370 1371 static bool classof(const TagType *T); 1372 static bool classof(const Type *T) { 1373 return isa<TagType>(T) && classof(cast<TagType>(T)); 1374 } 1375 static bool classof(const EnumType *) { return true; } 1376}; 1377 1378class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { 1379 unsigned Depth : 16; 1380 unsigned Index : 16; 1381 IdentifierInfo *Name; 1382 1383 TemplateTypeParmType(unsigned D, unsigned I, IdentifierInfo *N, 1384 QualType Canon) 1385 : Type(TemplateTypeParm, Canon, /*Dependent=*/true), 1386 Depth(D), Index(I), Name(N) { } 1387 1388 TemplateTypeParmType(unsigned D, unsigned I) 1389 : Type(TemplateTypeParm, QualType(this, 0), /*Dependent=*/true), 1390 Depth(D), Index(I), Name(0) { } 1391 1392 friend class ASTContext; // ASTContext creates these 1393 1394public: 1395 unsigned getDepth() const { return Depth; } 1396 unsigned getIndex() const { return Index; } 1397 IdentifierInfo *getName() const { return Name; } 1398 1399 virtual void getAsStringInternal(std::string &InnerString) const; 1400 1401 void Profile(llvm::FoldingSetNodeID &ID) { 1402 Profile(ID, Depth, Index, Name); 1403 } 1404 1405 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, 1406 unsigned Index, IdentifierInfo *Name) { 1407 ID.AddInteger(Depth); 1408 ID.AddInteger(Index); 1409 ID.AddPointer(Name); 1410 } 1411 1412 static bool classof(const Type *T) { 1413 return T->getTypeClass() == TemplateTypeParm; 1414 } 1415 static bool classof(const TemplateTypeParmType *T) { return true; } 1416 1417protected: 1418 virtual void EmitImpl(llvm::Serializer& S) const; 1419 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1420 friend class Type; 1421}; 1422 1423/// \brief Represents the type of a class template specialization as 1424/// written in the source code. 1425/// 1426/// Class template specialization types represent the syntactic form 1427/// of a template-id that refers to a type, e.g., @c vector<int>. All 1428/// class template specialization types are syntactic sugar, whose 1429/// canonical type will point to some other type node that represents 1430/// the instantiation or class template specialization. For example, a 1431/// class template specialization type of @c vector<int> will refer to 1432/// a tag type for the instantiation 1433/// @c std::vector<int, std::allocator<int>>. 1434class ClassTemplateSpecializationType 1435 : public Type, public llvm::FoldingSetNode { 1436 1437 // FIXME: Do we want templates to have a representation in the type 1438 // system? It will probably help with dependent templates and 1439 // possibly with template-names preceded by a nested-name-specifier. 1440 TemplateDecl *Template; 1441 1442 unsigned NumArgs; 1443 1444 ClassTemplateSpecializationType(TemplateDecl *T, unsigned NumArgs, 1445 uintptr_t *Args, bool *ArgIsType, 1446 QualType Canon); 1447 1448 /// \brief Retrieve the number of packed words that precede the 1449 /// actual arguments. 1450 /// 1451 /// The flags that specify whether each argument is a type or an 1452 /// expression are packed into the 1453 /// ClassTemplateSpecializationType. This routine computes the 1454 /// number of pointer-sized words we need to store this information, 1455 /// based on the number of template arguments 1456 static unsigned getNumPackedWords(unsigned NumArgs) { 1457 const unsigned BitsPerWord = sizeof(uintptr_t) * 8; 1458 return NumArgs / BitsPerWord + (NumArgs % BitsPerWord > 0); 1459 } 1460 1461 /// \brief Pack the given boolean values into words. 1462 static void 1463 packBooleanValues(unsigned NumArgs, bool *Values, uintptr_t *Words); 1464 1465 virtual void Destroy(ASTContext& C); 1466 1467 friend class ASTContext; // ASTContext creates these 1468 1469public: 1470 /// \brief Retrieve the template that we are specializing. 1471 TemplateDecl *getTemplate() const { return Template; } 1472 1473 /// \briefe Retrieve the number of template arguments. 1474 unsigned getNumArgs() const { return NumArgs; } 1475 1476 /// \brief Retrieve a specific template argument as a type. 1477 /// \precondition @c isArgType(Arg) 1478 QualType getArgAsType(unsigned Arg) const { 1479 assert(isArgType(Arg) && "Argument is not a type"); 1480 return QualType::getFromOpaquePtr( 1481 reinterpret_cast<void *>(getArgAsOpaqueValue(Arg))); 1482 } 1483 1484 /// \brief Retrieve a specific template argument as an expression. 1485 /// \precondition @c !isArgType(Arg) 1486 Expr *getArgAsExpr(unsigned Arg) const { 1487 assert(!isArgType(Arg) && "Argument is not an expression"); 1488 return reinterpret_cast<Expr *>(getArgAsOpaqueValue(Arg)); 1489 } 1490 1491 /// \brief Retrieve the specified template argument as an opaque value. 1492 uintptr_t getArgAsOpaqueValue(unsigned Arg) const; 1493 1494 /// \brief Determine whether the given template argument is a type. 1495 bool isArgType(unsigned Arg) const; 1496 1497 virtual void getAsStringInternal(std::string &InnerString) const; 1498 1499 void Profile(llvm::FoldingSetNodeID &ID) { 1500 // Add the template 1501 ID.AddPointer(Template); 1502 1503 // Add the packed words describing what kind of template arguments 1504 // we have. 1505 // FIXME: Would like to be smarter about the profile of expressions, 1506 // so that we can combine expression nodes more effectively. 1507 uintptr_t *Data = reinterpret_cast<uintptr_t *>(this + 1); 1508 for (unsigned Packed = 0, NumPacked = getNumPackedWords(NumArgs); 1509 Packed != NumPacked; ++Packed) 1510 ID.AddInteger(Data[Packed]); 1511 1512 // Add the template arguments themselves. 1513 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) 1514 ID.AddInteger(getArgAsOpaqueValue(Arg)); 1515 } 1516 1517 static void Profile(llvm::FoldingSetNodeID &ID, TemplateDecl *T, 1518 unsigned NumArgs, uintptr_t *Args, bool *ArgIsType) { 1519 // Add the template 1520 ID.AddPointer(T); 1521 1522 // Add the packed words describing what kind of template arguments 1523 // we have. 1524 unsigned NumPackedWords = getNumPackedWords(NumArgs); 1525 unsigned NumPackedBytes = NumPackedWords * sizeof(uintptr_t); 1526 uintptr_t *PackedWords 1527 = reinterpret_cast<uintptr_t *>(alloca(NumPackedBytes)); 1528 packBooleanValues(NumArgs, ArgIsType, PackedWords); 1529 for (unsigned Packed = 0; Packed != NumPackedWords; ++Packed) 1530 ID.AddInteger(PackedWords[Packed]); 1531 1532 // Add the template arguments themselves. 1533 for (unsigned Arg = 0; Arg < NumArgs; ++Arg) 1534 ID.AddInteger(Args[Arg]); 1535 } 1536 1537 static bool classof(const Type *T) { 1538 return T->getTypeClass() == ClassTemplateSpecialization; 1539 } 1540 static bool classof(const ClassTemplateSpecializationType *T) { return true; } 1541 1542protected: 1543 virtual void EmitImpl(llvm::Serializer& S) const; 1544 static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D); 1545 friend class Type; 1546}; 1547 1548/// ObjCInterfaceType - Interfaces are the core concept in Objective-C for 1549/// object oriented design. They basically correspond to C++ classes. There 1550/// are two kinds of interface types, normal interfaces like "NSString" and 1551/// qualified interfaces, which are qualified with a protocol list like 1552/// "NSString<NSCopyable, NSAmazing>". Qualified interface types are instances 1553/// of ObjCQualifiedInterfaceType, which is a subclass of ObjCInterfaceType. 1554class ObjCInterfaceType : public Type { 1555 ObjCInterfaceDecl *Decl; 1556protected: 1557 ObjCInterfaceType(TypeClass tc, ObjCInterfaceDecl *D) : 1558 Type(tc, QualType(), /*Dependent=*/false), Decl(D) { } 1559 friend class ASTContext; // ASTContext creates these. 1560public: 1561 1562 ObjCInterfaceDecl *getDecl() const { return Decl; } 1563 1564 /// qual_iterator and friends: this provides access to the (potentially empty) 1565 /// list of protocols qualifying this interface. If this is an instance of 1566 /// ObjCQualifiedInterfaceType it returns the list, otherwise it returns an 1567 /// empty list if there are no qualifying protocols. 1568 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1569 inline qual_iterator qual_begin() const; 1570 inline qual_iterator qual_end() const; 1571 bool qual_empty() const { return getTypeClass() != ObjCQualifiedInterface; } 1572 1573 /// getNumProtocols - Return the number of qualifying protocols in this 1574 /// interface type, or 0 if there are none. 1575 inline unsigned getNumProtocols() const; 1576 1577 /// getProtocol - Return the specified qualifying protocol. 1578 inline ObjCProtocolDecl *getProtocol(unsigned i) const; 1579 1580 1581 virtual void getAsStringInternal(std::string &InnerString) const; 1582 static bool classof(const Type *T) { 1583 return T->getTypeClass() == ObjCInterface || 1584 T->getTypeClass() == ObjCQualifiedInterface; 1585 } 1586 static bool classof(const ObjCInterfaceType *) { return true; } 1587}; 1588 1589/// ObjCQualifiedInterfaceType - This class represents interface types 1590/// conforming to a list of protocols, such as INTF<Proto1, Proto2, Proto1>. 1591/// 1592/// Duplicate protocols are removed and protocol list is canonicalized to be in 1593/// alphabetical order. 1594class ObjCQualifiedInterfaceType : public ObjCInterfaceType, 1595 public llvm::FoldingSetNode { 1596 1597 // List of protocols for this protocol conforming object type 1598 // List is sorted on protocol name. No protocol is enterred more than once. 1599 llvm::SmallVector<ObjCProtocolDecl*, 4> Protocols; 1600 1601 ObjCQualifiedInterfaceType(ObjCInterfaceDecl *D, 1602 ObjCProtocolDecl **Protos, unsigned NumP) : 1603 ObjCInterfaceType(ObjCQualifiedInterface, D), 1604 Protocols(Protos, Protos+NumP) { } 1605 friend class ASTContext; // ASTContext creates these. 1606public: 1607 1608 ObjCProtocolDecl *getProtocol(unsigned i) const { 1609 return Protocols[i]; 1610 } 1611 unsigned getNumProtocols() const { 1612 return Protocols.size(); 1613 } 1614 1615 qual_iterator qual_begin() const { return Protocols.begin(); } 1616 qual_iterator qual_end() const { return Protocols.end(); } 1617 1618 virtual void getAsStringInternal(std::string &InnerString) const; 1619 1620 void Profile(llvm::FoldingSetNodeID &ID); 1621 static void Profile(llvm::FoldingSetNodeID &ID, 1622 const ObjCInterfaceDecl *Decl, 1623 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1624 1625 static bool classof(const Type *T) { 1626 return T->getTypeClass() == ObjCQualifiedInterface; 1627 } 1628 static bool classof(const ObjCQualifiedInterfaceType *) { return true; } 1629}; 1630 1631inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_begin() const { 1632 if (const ObjCQualifiedInterfaceType *QIT = 1633 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1634 return QIT->qual_begin(); 1635 return 0; 1636} 1637inline ObjCInterfaceType::qual_iterator ObjCInterfaceType::qual_end() const { 1638 if (const ObjCQualifiedInterfaceType *QIT = 1639 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1640 return QIT->qual_end(); 1641 return 0; 1642} 1643 1644/// getNumProtocols - Return the number of qualifying protocols in this 1645/// interface type, or 0 if there are none. 1646inline unsigned ObjCInterfaceType::getNumProtocols() const { 1647 if (const ObjCQualifiedInterfaceType *QIT = 1648 dyn_cast<ObjCQualifiedInterfaceType>(this)) 1649 return QIT->getNumProtocols(); 1650 return 0; 1651} 1652 1653/// getProtocol - Return the specified qualifying protocol. 1654inline ObjCProtocolDecl *ObjCInterfaceType::getProtocol(unsigned i) const { 1655 return cast<ObjCQualifiedInterfaceType>(this)->getProtocol(i); 1656} 1657 1658 1659 1660/// ObjCQualifiedIdType - to represent id<protocol-list>. 1661/// 1662/// Duplicate protocols are removed and protocol list is canonicalized to be in 1663/// alphabetical order. 1664class ObjCQualifiedIdType : public Type, 1665 public llvm::FoldingSetNode { 1666 // List of protocols for this protocol conforming 'id' type 1667 // List is sorted on protocol name. No protocol is enterred more than once. 1668 llvm::SmallVector<ObjCProtocolDecl*, 8> Protocols; 1669 1670 ObjCQualifiedIdType(ObjCProtocolDecl **Protos, unsigned NumP) 1671 : Type(ObjCQualifiedId, QualType()/*these are always canonical*/, 1672 /*Dependent=*/false), 1673 Protocols(Protos, Protos+NumP) { } 1674 friend class ASTContext; // ASTContext creates these. 1675public: 1676 1677 ObjCProtocolDecl *getProtocols(unsigned i) const { 1678 return Protocols[i]; 1679 } 1680 unsigned getNumProtocols() const { 1681 return Protocols.size(); 1682 } 1683 ObjCProtocolDecl **getReferencedProtocols() { 1684 return &Protocols[0]; 1685 } 1686 1687 typedef llvm::SmallVector<ObjCProtocolDecl*, 8>::const_iterator qual_iterator; 1688 qual_iterator qual_begin() const { return Protocols.begin(); } 1689 qual_iterator qual_end() const { return Protocols.end(); } 1690 1691 virtual void getAsStringInternal(std::string &InnerString) const; 1692 1693 void Profile(llvm::FoldingSetNodeID &ID); 1694 static void Profile(llvm::FoldingSetNodeID &ID, 1695 ObjCProtocolDecl **protocols, unsigned NumProtocols); 1696 1697 static bool classof(const Type *T) { 1698 return T->getTypeClass() == ObjCQualifiedId; 1699 } 1700 static bool classof(const ObjCQualifiedIdType *) { return true; } 1701 1702}; 1703 1704 1705// Inline function definitions. 1706 1707/// getUnqualifiedType - Return the type without any qualifiers. 1708inline QualType QualType::getUnqualifiedType() const { 1709 Type *TP = getTypePtr(); 1710 if (const ASQualType *ASQT = dyn_cast<ASQualType>(TP)) 1711 TP = ASQT->getBaseType(); 1712 return QualType(TP, 0); 1713} 1714 1715/// getAddressSpace - Return the address space of this type. 1716inline unsigned QualType::getAddressSpace() const { 1717 QualType CT = getTypePtr()->getCanonicalTypeInternal(); 1718 if (const ArrayType *AT = dyn_cast<ArrayType>(CT)) 1719 return AT->getElementType().getAddressSpace(); 1720 if (const RecordType *RT = dyn_cast<RecordType>(CT)) 1721 return RT->getAddressSpace(); 1722 if (const ASQualType *ASQT = dyn_cast<ASQualType>(CT)) 1723 return ASQT->getAddressSpace(); 1724 return 0; 1725} 1726 1727/// isMoreQualifiedThan - Determine whether this type is more 1728/// qualified than the Other type. For example, "const volatile int" 1729/// is more qualified than "const int", "volatile int", and 1730/// "int". However, it is not more qualified than "const volatile 1731/// int". 1732inline bool QualType::isMoreQualifiedThan(QualType Other) const { 1733 // FIXME: Handle address spaces 1734 unsigned MyQuals = this->getCVRQualifiers(); 1735 unsigned OtherQuals = Other.getCVRQualifiers(); 1736 assert(this->getAddressSpace() == 0 && "Address space not checked"); 1737 assert(Other.getAddressSpace() == 0 && "Address space not checked"); 1738 return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; 1739} 1740 1741/// isAtLeastAsQualifiedAs - Determine whether this type is at last 1742/// as qualified as the Other type. For example, "const volatile 1743/// int" is at least as qualified as "const int", "volatile int", 1744/// "int", and "const volatile int". 1745inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { 1746 // FIXME: Handle address spaces 1747 unsigned MyQuals = this->getCVRQualifiers(); 1748 unsigned OtherQuals = Other.getCVRQualifiers(); 1749 assert(this->getAddressSpace() == 0 && "Address space not checked"); 1750 assert(Other.getAddressSpace() == 0 && "Address space not checked"); 1751 return (MyQuals | OtherQuals) == MyQuals; 1752} 1753 1754/// getNonReferenceType - If Type is a reference type (e.g., const 1755/// int&), returns the type that the reference refers to ("const 1756/// int"). Otherwise, returns the type itself. This routine is used 1757/// throughout Sema to implement C++ 5p6: 1758/// 1759/// If an expression initially has the type "reference to T" (8.3.2, 1760/// 8.5.3), the type is adjusted to "T" prior to any further 1761/// analysis, the expression designates the object or function 1762/// denoted by the reference, and the expression is an lvalue. 1763inline QualType QualType::getNonReferenceType() const { 1764 if (const ReferenceType *RefType = (*this)->getAsReferenceType()) 1765 return RefType->getPointeeType(); 1766 else 1767 return *this; 1768} 1769 1770inline const TypedefType* Type::getAsTypedefType() const { 1771 return dyn_cast<TypedefType>(this); 1772} 1773inline const ObjCInterfaceType *Type::getAsPointerToObjCInterfaceType() const { 1774 if (const PointerType *PT = getAsPointerType()) 1775 return PT->getPointeeType()->getAsObjCInterfaceType(); 1776 return 0; 1777} 1778 1779// NOTE: All of these methods use "getUnqualifiedType" to strip off address 1780// space qualifiers if present. 1781inline bool Type::isFunctionType() const { 1782 return isa<FunctionType>(CanonicalType.getUnqualifiedType()); 1783} 1784inline bool Type::isPointerType() const { 1785 return isa<PointerType>(CanonicalType.getUnqualifiedType()); 1786} 1787inline bool Type::isBlockPointerType() const { 1788 return isa<BlockPointerType>(CanonicalType); 1789} 1790inline bool Type::isReferenceType() const { 1791 return isa<ReferenceType>(CanonicalType.getUnqualifiedType()); 1792} 1793inline bool Type::isPointerLikeType() const { 1794 return isa<PointerLikeType>(CanonicalType.getUnqualifiedType()); 1795} 1796inline bool Type::isFunctionPointerType() const { 1797 if (const PointerType* T = getAsPointerType()) 1798 return T->getPointeeType()->isFunctionType(); 1799 else 1800 return false; 1801} 1802inline bool Type::isMemberPointerType() const { 1803 return isa<MemberPointerType>(CanonicalType.getUnqualifiedType()); 1804} 1805inline bool Type::isMemberFunctionPointerType() const { 1806 if (const MemberPointerType* T = getAsMemberPointerType()) 1807 return T->getPointeeType()->isFunctionType(); 1808 else 1809 return false; 1810} 1811inline bool Type::isArrayType() const { 1812 return isa<ArrayType>(CanonicalType.getUnqualifiedType()); 1813} 1814inline bool Type::isConstantArrayType() const { 1815 return isa<ConstantArrayType>(CanonicalType.getUnqualifiedType()); 1816} 1817inline bool Type::isIncompleteArrayType() const { 1818 return isa<IncompleteArrayType>(CanonicalType.getUnqualifiedType()); 1819} 1820inline bool Type::isVariableArrayType() const { 1821 return isa<VariableArrayType>(CanonicalType.getUnqualifiedType()); 1822} 1823inline bool Type::isDependentSizedArrayType() const { 1824 return isa<DependentSizedArrayType>(CanonicalType.getUnqualifiedType()); 1825} 1826inline bool Type::isRecordType() const { 1827 return isa<RecordType>(CanonicalType.getUnqualifiedType()); 1828} 1829inline bool Type::isAnyComplexType() const { 1830 return isa<ComplexType>(CanonicalType.getUnqualifiedType()); 1831} 1832inline bool Type::isVectorType() const { 1833 return isa<VectorType>(CanonicalType.getUnqualifiedType()); 1834} 1835inline bool Type::isExtVectorType() const { 1836 return isa<ExtVectorType>(CanonicalType.getUnqualifiedType()); 1837} 1838inline bool Type::isObjCInterfaceType() const { 1839 return isa<ObjCInterfaceType>(CanonicalType.getUnqualifiedType()); 1840} 1841inline bool Type::isObjCQualifiedInterfaceType() const { 1842 return isa<ObjCQualifiedInterfaceType>(CanonicalType.getUnqualifiedType()); 1843} 1844inline bool Type::isObjCQualifiedIdType() const { 1845 return isa<ObjCQualifiedIdType>(CanonicalType.getUnqualifiedType()); 1846} 1847inline bool Type::isTemplateTypeParmType() const { 1848 return isa<TemplateTypeParmType>(CanonicalType.getUnqualifiedType()); 1849} 1850 1851inline bool Type::isOverloadType() const { 1852 if (const BuiltinType *BT = getAsBuiltinType()) 1853 return BT->getKind() == BuiltinType::Overload; 1854 else 1855 return false; 1856} 1857 1858/// Insertion operator for diagnostics. This allows sending QualType's into a 1859/// diagnostic with <<. 1860inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1861 QualType T) { 1862 DB.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), 1863 Diagnostic::ak_qualtype); 1864 return DB; 1865} 1866 1867} // end namespace clang 1868 1869#endif 1870