ASTContext.h revision 87ec9c257c99b4136af6c7f5be5a2d486906ba84
1//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- 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 ASTContext interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 15#define LLVM_CLANG_AST_ASTCONTEXT_H 16 17#include "clang/Basic/AddressSpaces.h" 18#include "clang/Basic/IdentifierTable.h" 19#include "clang/Basic/LangOptions.h" 20#include "clang/Basic/OperatorKinds.h" 21#include "clang/Basic/PartialDiagnostic.h" 22#include "clang/Basic/VersionTuple.h" 23#include "clang/AST/Decl.h" 24#include "clang/AST/NestedNameSpecifier.h" 25#include "clang/AST/PrettyPrinter.h" 26#include "clang/AST/TemplateName.h" 27#include "clang/AST/Type.h" 28#include "clang/AST/CanonicalType.h" 29#include "clang/AST/UsuallyTinyPtrVector.h" 30#include "llvm/ADT/DenseMap.h" 31#include "llvm/ADT/FoldingSet.h" 32#include "llvm/ADT/IntrusiveRefCntPtr.h" 33#include "llvm/ADT/OwningPtr.h" 34#include "llvm/ADT/SmallPtrSet.h" 35#include "llvm/Support/Allocator.h" 36#include <vector> 37 38namespace llvm { 39 struct fltSemantics; 40} 41 42namespace clang { 43 class FileManager; 44 class ASTRecordLayout; 45 class BlockExpr; 46 class CharUnits; 47 class DiagnosticsEngine; 48 class Expr; 49 class ExternalASTSource; 50 class ASTMutationListener; 51 class IdentifierTable; 52 class SelectorTable; 53 class SourceManager; 54 class TargetInfo; 55 class CXXABI; 56 // Decls 57 class DeclContext; 58 class CXXMethodDecl; 59 class CXXRecordDecl; 60 class Decl; 61 class FieldDecl; 62 class MangleContext; 63 class ObjCIvarDecl; 64 class ObjCIvarRefExpr; 65 class ObjCPropertyDecl; 66 class ParmVarDecl; 67 class RecordDecl; 68 class StoredDeclsMap; 69 class TagDecl; 70 class TemplateTemplateParmDecl; 71 class TemplateTypeParmDecl; 72 class TranslationUnitDecl; 73 class TypeDecl; 74 class TypedefNameDecl; 75 class UsingDecl; 76 class UsingShadowDecl; 77 class UnresolvedSetIterator; 78 79 namespace Builtin { class Context; } 80 81/// ASTContext - This class holds long-lived AST nodes (such as types and 82/// decls) that can be referred to throughout the semantic analysis of a file. 83class ASTContext : public llvm::RefCountedBase<ASTContext> { 84 ASTContext &this_() { return *this; } 85 86 mutable std::vector<Type*> Types; 87 mutable llvm::FoldingSet<ExtQuals> ExtQualNodes; 88 mutable llvm::FoldingSet<ComplexType> ComplexTypes; 89 mutable llvm::FoldingSet<PointerType> PointerTypes; 90 mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes; 91 mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes; 92 mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes; 93 mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes; 94 mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes; 95 mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes; 96 mutable std::vector<VariableArrayType*> VariableArrayTypes; 97 mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes; 98 mutable llvm::FoldingSet<DependentSizedExtVectorType> 99 DependentSizedExtVectorTypes; 100 mutable llvm::FoldingSet<VectorType> VectorTypes; 101 mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes; 102 mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&> 103 FunctionProtoTypes; 104 mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes; 105 mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes; 106 mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes; 107 mutable llvm::FoldingSet<SubstTemplateTypeParmType> 108 SubstTemplateTypeParmTypes; 109 mutable llvm::FoldingSet<SubstTemplateTypeParmPackType> 110 SubstTemplateTypeParmPackTypes; 111 mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&> 112 TemplateSpecializationTypes; 113 mutable llvm::FoldingSet<ParenType> ParenTypes; 114 mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes; 115 mutable llvm::FoldingSet<DependentNameType> DependentNameTypes; 116 mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType, 117 ASTContext&> 118 DependentTemplateSpecializationTypes; 119 llvm::FoldingSet<PackExpansionType> PackExpansionTypes; 120 mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes; 121 mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes; 122 mutable llvm::FoldingSet<AutoType> AutoTypes; 123 mutable llvm::FoldingSet<AtomicType> AtomicTypes; 124 llvm::FoldingSet<AttributedType> AttributedTypes; 125 126 mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames; 127 mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames; 128 mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage> 129 SubstTemplateTemplateParms; 130 mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage, 131 ASTContext&> 132 SubstTemplateTemplateParmPacks; 133 134 /// \brief The set of nested name specifiers. 135 /// 136 /// This set is managed by the NestedNameSpecifier class. 137 mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers; 138 mutable NestedNameSpecifier *GlobalNestedNameSpecifier; 139 friend class NestedNameSpecifier; 140 141 /// ASTRecordLayouts - A cache mapping from RecordDecls to ASTRecordLayouts. 142 /// This is lazily created. This is intentionally not serialized. 143 mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> 144 ASTRecordLayouts; 145 mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> 146 ObjCLayouts; 147 148 /// KeyFunctions - A cache mapping from CXXRecordDecls to key functions. 149 llvm::DenseMap<const CXXRecordDecl*, const CXXMethodDecl*> KeyFunctions; 150 151 /// \brief Mapping from ObjCContainers to their ObjCImplementations. 152 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; 153 154 /// \brief Mapping from ObjCMethod to its duplicate declaration in the same 155 /// interface. 156 llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls; 157 158 /// \brief Mapping from __block VarDecls to their copy initialization expr. 159 llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits; 160 161 /// \brief Mapping from class scope functions specialization to their 162 /// template patterns. 163 llvm::DenseMap<const FunctionDecl*, FunctionDecl*> 164 ClassScopeSpecializationPattern; 165 166 /// \brief Representation of a "canonical" template template parameter that 167 /// is used in canonical template names. 168 class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { 169 TemplateTemplateParmDecl *Parm; 170 171 public: 172 CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm) 173 : Parm(Parm) { } 174 175 TemplateTemplateParmDecl *getParam() const { return Parm; } 176 177 void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); } 178 179 static void Profile(llvm::FoldingSetNodeID &ID, 180 TemplateTemplateParmDecl *Parm); 181 }; 182 mutable llvm::FoldingSet<CanonicalTemplateTemplateParm> 183 CanonTemplateTemplateParms; 184 185 TemplateTemplateParmDecl * 186 getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const; 187 188 /// \brief The typedef for the __int128_t type. 189 mutable TypedefDecl *Int128Decl; 190 191 /// \brief The typedef for the __uint128_t type. 192 mutable TypedefDecl *UInt128Decl; 193 194 /// BuiltinVaListType - built-in va list type. 195 /// This is initially null and set by Sema::LazilyCreateBuiltin when 196 /// a builtin that takes a valist is encountered. 197 QualType BuiltinVaListType; 198 199 /// \brief The typedef for the predefined 'id' type. 200 mutable TypedefDecl *ObjCIdDecl; 201 202 /// \brief The typedef for the predefined 'SEL' type. 203 mutable TypedefDecl *ObjCSelDecl; 204 205 QualType ObjCProtoType; 206 207 /// \brief The typedef for the predefined 'Class' type. 208 mutable TypedefDecl *ObjCClassDecl; 209 210 // Typedefs which may be provided defining the structure of Objective-C 211 // pseudo-builtins 212 QualType ObjCIdRedefinitionType; 213 QualType ObjCClassRedefinitionType; 214 QualType ObjCSelRedefinitionType; 215 216 QualType ObjCConstantStringType; 217 mutable RecordDecl *CFConstantStringTypeDecl; 218 219 /// \brief The typedef declaration for the Objective-C "instancetype" type. 220 TypedefDecl *ObjCInstanceTypeDecl; 221 222 /// \brief The type for the C FILE type. 223 TypeDecl *FILEDecl; 224 225 /// \brief The type for the C jmp_buf type. 226 TypeDecl *jmp_bufDecl; 227 228 /// \brief The type for the C sigjmp_buf type. 229 TypeDecl *sigjmp_bufDecl; 230 231 /// \brief Type for the Block descriptor for Blocks CodeGen. 232 /// 233 /// Since this is only used for generation of debug info, it is not 234 /// serialized. 235 mutable RecordDecl *BlockDescriptorType; 236 237 /// \brief Type for the Block descriptor for Blocks CodeGen. 238 /// 239 /// Since this is only used for generation of debug info, it is not 240 /// serialized. 241 mutable RecordDecl *BlockDescriptorExtendedType; 242 243 /// \brief Declaration for the CUDA cudaConfigureCall function. 244 FunctionDecl *cudaConfigureCallDecl; 245 246 TypeSourceInfo NullTypeSourceInfo; 247 248 /// \brief Keeps track of all declaration attributes. 249 /// 250 /// Since so few decls have attrs, we keep them in a hash map instead of 251 /// wasting space in the Decl class. 252 llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs; 253 254 /// \brief Keeps track of the static data member templates from which 255 /// static data members of class template specializations were instantiated. 256 /// 257 /// This data structure stores the mapping from instantiations of static 258 /// data members to the static data member representations within the 259 /// class template from which they were instantiated along with the kind 260 /// of instantiation or specialization (a TemplateSpecializationKind - 1). 261 /// 262 /// Given the following example: 263 /// 264 /// \code 265 /// template<typename T> 266 /// struct X { 267 /// static T value; 268 /// }; 269 /// 270 /// template<typename T> 271 /// T X<T>::value = T(17); 272 /// 273 /// int *x = &X<int>::value; 274 /// \endcode 275 /// 276 /// This mapping will contain an entry that maps from the VarDecl for 277 /// X<int>::value to the corresponding VarDecl for X<T>::value (within the 278 /// class template X) and will be marked TSK_ImplicitInstantiation. 279 llvm::DenseMap<const VarDecl *, MemberSpecializationInfo *> 280 InstantiatedFromStaticDataMember; 281 282 /// \brief Keeps track of the declaration from which a UsingDecl was 283 /// created during instantiation. The source declaration is always 284 /// a UsingDecl, an UnresolvedUsingValueDecl, or an 285 /// UnresolvedUsingTypenameDecl. 286 /// 287 /// For example: 288 /// \code 289 /// template<typename T> 290 /// struct A { 291 /// void f(); 292 /// }; 293 /// 294 /// template<typename T> 295 /// struct B : A<T> { 296 /// using A<T>::f; 297 /// }; 298 /// 299 /// template struct B<int>; 300 /// \endcode 301 /// 302 /// This mapping will contain an entry that maps from the UsingDecl in 303 /// B<int> to the UnresolvedUsingDecl in B<T>. 304 llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl; 305 306 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*> 307 InstantiatedFromUsingShadowDecl; 308 309 llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl; 310 311 /// \brief Mapping that stores the methods overridden by a given C++ 312 /// member function. 313 /// 314 /// Since most C++ member functions aren't virtual and therefore 315 /// don't override anything, we store the overridden functions in 316 /// this map on the side rather than within the CXXMethodDecl structure. 317 typedef UsuallyTinyPtrVector<const CXXMethodDecl> CXXMethodVector; 318 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods; 319 320 /// \brief Mapping that stores parameterIndex values for ParmVarDecls 321 /// when that value exceeds the bitfield size of 322 /// ParmVarDeclBits.ParameterIndex. 323 typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable; 324 ParameterIndexTable ParamIndices; 325 326 TranslationUnitDecl *TUDecl; 327 328 /// SourceMgr - The associated SourceManager object. 329 SourceManager &SourceMgr; 330 331 /// LangOpts - The language options used to create the AST associated with 332 /// this ASTContext object. 333 LangOptions &LangOpts; 334 335 /// \brief The allocator used to create AST objects. 336 /// 337 /// AST objects are never destructed; rather, all memory associated with the 338 /// AST objects will be released when the ASTContext itself is destroyed. 339 mutable llvm::BumpPtrAllocator BumpAlloc; 340 341 /// \brief Allocator for partial diagnostics. 342 PartialDiagnostic::StorageAllocator DiagAllocator; 343 344 /// \brief The current C++ ABI. 345 llvm::OwningPtr<CXXABI> ABI; 346 CXXABI *createCXXABI(const TargetInfo &T); 347 348 /// \brief The logical -> physical address space map. 349 const LangAS::Map *AddrSpaceMap; 350 351 friend class ASTDeclReader; 352 friend class ASTReader; 353 friend class ASTWriter; 354 355 const TargetInfo *Target; 356 clang::PrintingPolicy PrintingPolicy; 357 358public: 359 IdentifierTable &Idents; 360 SelectorTable &Selectors; 361 Builtin::Context &BuiltinInfo; 362 mutable DeclarationNameTable DeclarationNames; 363 llvm::OwningPtr<ExternalASTSource> ExternalSource; 364 ASTMutationListener *Listener; 365 366 clang::PrintingPolicy getPrintingPolicy() const { return PrintingPolicy; } 367 368 void setPrintingPolicy(clang::PrintingPolicy Policy) { 369 PrintingPolicy = Policy; 370 } 371 372 SourceManager& getSourceManager() { return SourceMgr; } 373 const SourceManager& getSourceManager() const { return SourceMgr; } 374 void *Allocate(unsigned Size, unsigned Align = 8) const { 375 return BumpAlloc.Allocate(Size, Align); 376 } 377 void Deallocate(void *Ptr) const { } 378 379 /// Return the total amount of physical memory allocated for representing 380 /// AST nodes and type information. 381 size_t getASTAllocatedMemory() const { 382 return BumpAlloc.getTotalMemory(); 383 } 384 /// Return the total memory used for various side tables. 385 size_t getSideTableAllocatedMemory() const; 386 387 PartialDiagnostic::StorageAllocator &getDiagAllocator() { 388 return DiagAllocator; 389 } 390 391 const TargetInfo &getTargetInfo() const { return *Target; } 392 393 const LangOptions& getLangOptions() const { return LangOpts; } 394 395 DiagnosticsEngine &getDiagnostics() const; 396 397 FullSourceLoc getFullLoc(SourceLocation Loc) const { 398 return FullSourceLoc(Loc,SourceMgr); 399 } 400 401 /// \brief Retrieve the attributes for the given declaration. 402 AttrVec& getDeclAttrs(const Decl *D); 403 404 /// \brief Erase the attributes corresponding to the given declaration. 405 void eraseDeclAttrs(const Decl *D); 406 407 /// \brief If this variable is an instantiated static data member of a 408 /// class template specialization, returns the templated static data member 409 /// from which it was instantiated. 410 MemberSpecializationInfo *getInstantiatedFromStaticDataMember( 411 const VarDecl *Var); 412 413 FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD); 414 415 void setClassScopeSpecializationPattern(FunctionDecl *FD, 416 FunctionDecl *Pattern); 417 418 /// \brief Note that the static data member \p Inst is an instantiation of 419 /// the static data member template \p Tmpl of a class template. 420 void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 421 TemplateSpecializationKind TSK, 422 SourceLocation PointOfInstantiation = SourceLocation()); 423 424 /// \brief If the given using decl is an instantiation of a 425 /// (possibly unresolved) using decl from a template instantiation, 426 /// return it. 427 NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst); 428 429 /// \brief Remember that the using decl \p Inst is an instantiation 430 /// of the using decl \p Pattern of a class template. 431 void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern); 432 433 void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 434 UsingShadowDecl *Pattern); 435 UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); 436 437 FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field); 438 439 void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl); 440 441 /// ZeroBitfieldFollowsNonBitfield - return 'true" if 'FD' is a zero-length 442 /// bitfield which follows the non-bitfield 'LastFD'. 443 bool ZeroBitfieldFollowsNonBitfield(const FieldDecl *FD, 444 const FieldDecl *LastFD) const; 445 446 /// ZeroBitfieldFollowsBitfield - return 'true" if 'FD' is a zero-length 447 /// bitfield which follows the bitfield 'LastFD'. 448 bool ZeroBitfieldFollowsBitfield(const FieldDecl *FD, 449 const FieldDecl *LastFD) const; 450 451 /// BitfieldFollowsBitfield - return 'true" if 'FD' is a 452 /// bitfield which follows the bitfield 'LastFD'. 453 bool BitfieldFollowsBitfield(const FieldDecl *FD, 454 const FieldDecl *LastFD) const; 455 456 /// NonBitfieldFollowsBitfield - return 'true" if 'FD' is not a 457 /// bitfield which follows the bitfield 'LastFD'. 458 bool NonBitfieldFollowsBitfield(const FieldDecl *FD, 459 const FieldDecl *LastFD) const; 460 461 /// BitfieldFollowsNonBitfield - return 'true" if 'FD' is a 462 /// bitfield which follows the none bitfield 'LastFD'. 463 bool BitfieldFollowsNonBitfield(const FieldDecl *FD, 464 const FieldDecl *LastFD) const; 465 466 // Access to the set of methods overridden by the given C++ method. 467 typedef CXXMethodVector::iterator overridden_cxx_method_iterator; 468 overridden_cxx_method_iterator 469 overridden_methods_begin(const CXXMethodDecl *Method) const; 470 471 overridden_cxx_method_iterator 472 overridden_methods_end(const CXXMethodDecl *Method) const; 473 474 unsigned overridden_methods_size(const CXXMethodDecl *Method) const; 475 476 /// \brief Note that the given C++ \p Method overrides the given \p 477 /// Overridden method. 478 void addOverriddenMethod(const CXXMethodDecl *Method, 479 const CXXMethodDecl *Overridden); 480 481 TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } 482 483 484 // Builtin Types. 485 CanQualType VoidTy; 486 CanQualType BoolTy; 487 CanQualType CharTy; 488 CanQualType WCharTy; // [C++ 3.9.1p5], integer type in C99. 489 CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99. 490 CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99. 491 CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty; 492 CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 493 CanQualType UnsignedLongLongTy, UnsignedInt128Ty; 494 CanQualType FloatTy, DoubleTy, LongDoubleTy; 495 CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON 496 CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 497 CanQualType VoidPtrTy, NullPtrTy; 498 CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy; 499 CanQualType PseudoObjectTy, ARCUnbridgedCastTy; 500 CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; 501 502 // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. 503 mutable QualType AutoDeductTy; // Deduction against 'auto'. 504 mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'. 505 506 ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo *t, 507 IdentifierTable &idents, SelectorTable &sels, 508 Builtin::Context &builtins, 509 unsigned size_reserve, 510 bool DelayInitialization = false); 511 512 ~ASTContext(); 513 514 /// \brief Attach an external AST source to the AST context. 515 /// 516 /// The external AST source provides the ability to load parts of 517 /// the abstract syntax tree as needed from some external storage, 518 /// e.g., a precompiled header. 519 void setExternalSource(llvm::OwningPtr<ExternalASTSource> &Source); 520 521 /// \brief Retrieve a pointer to the external AST source associated 522 /// with this AST context, if any. 523 ExternalASTSource *getExternalSource() const { return ExternalSource.get(); } 524 525 /// \brief Attach an AST mutation listener to the AST context. 526 /// 527 /// The AST mutation listener provides the ability to track modifications to 528 /// the abstract syntax tree entities committed after they were initially 529 /// created. 530 void setASTMutationListener(ASTMutationListener *Listener) { 531 this->Listener = Listener; 532 } 533 534 /// \brief Retrieve a pointer to the AST mutation listener associated 535 /// with this AST context, if any. 536 ASTMutationListener *getASTMutationListener() const { return Listener; } 537 538 void PrintStats() const; 539 const std::vector<Type*>& getTypes() const { return Types; } 540 541 /// \brief Retrieve the declaration for the 128-bit signed integer type. 542 TypedefDecl *getInt128Decl() const; 543 544 /// \brief Retrieve the declaration for the 128-bit unsigned integer type. 545 TypedefDecl *getUInt128Decl() const; 546 547 //===--------------------------------------------------------------------===// 548 // Type Constructors 549 //===--------------------------------------------------------------------===// 550 551private: 552 /// getExtQualType - Return a type with extended qualifiers. 553 QualType getExtQualType(const Type *Base, Qualifiers Quals) const; 554 555 QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const; 556 557public: 558 /// getAddSpaceQualType - Return the uniqued reference to the type for an 559 /// address space qualified type with the specified type and address space. 560 /// The resulting type has a union of the qualifiers from T and the address 561 /// space. If T already has an address space specifier, it is silently 562 /// replaced. 563 QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const; 564 565 /// getObjCGCQualType - Returns the uniqued reference to the type for an 566 /// objc gc qualified type. The retulting type has a union of the qualifiers 567 /// from T and the gc attribute. 568 QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const; 569 570 /// getRestrictType - Returns the uniqued reference to the type for a 571 /// 'restrict' qualified type. The resulting type has a union of the 572 /// qualifiers from T and 'restrict'. 573 QualType getRestrictType(QualType T) const { 574 return T.withFastQualifiers(Qualifiers::Restrict); 575 } 576 577 /// getVolatileType - Returns the uniqued reference to the type for a 578 /// 'volatile' qualified type. The resulting type has a union of the 579 /// qualifiers from T and 'volatile'. 580 QualType getVolatileType(QualType T) const { 581 return T.withFastQualifiers(Qualifiers::Volatile); 582 } 583 584 /// getConstType - Returns the uniqued reference to the type for a 585 /// 'const' qualified type. The resulting type has a union of the 586 /// qualifiers from T and 'const'. 587 /// 588 /// It can be reasonably expected that this will always be 589 /// equivalent to calling T.withConst(). 590 QualType getConstType(QualType T) const { return T.withConst(); } 591 592 /// adjustFunctionType - Change the ExtInfo on a function type. 593 const FunctionType *adjustFunctionType(const FunctionType *Fn, 594 FunctionType::ExtInfo EInfo); 595 596 /// getComplexType - Return the uniqued reference to the type for a complex 597 /// number with the specified element type. 598 QualType getComplexType(QualType T) const; 599 CanQualType getComplexType(CanQualType T) const { 600 return CanQualType::CreateUnsafe(getComplexType((QualType) T)); 601 } 602 603 /// getPointerType - Return the uniqued reference to the type for a pointer to 604 /// the specified type. 605 QualType getPointerType(QualType T) const; 606 CanQualType getPointerType(CanQualType T) const { 607 return CanQualType::CreateUnsafe(getPointerType((QualType) T)); 608 } 609 610 /// getAtomicType - Return the uniqued reference to the atomic type for 611 /// the specified type. 612 QualType getAtomicType(QualType T) const; 613 614 /// getBlockPointerType - Return the uniqued reference to the type for a block 615 /// of the specified type. 616 QualType getBlockPointerType(QualType T) const; 617 618 /// This gets the struct used to keep track of the descriptor for pointer to 619 /// blocks. 620 QualType getBlockDescriptorType() const; 621 622 /// This gets the struct used to keep track of the extended descriptor for 623 /// pointer to blocks. 624 QualType getBlockDescriptorExtendedType() const; 625 626 void setcudaConfigureCallDecl(FunctionDecl *FD) { 627 cudaConfigureCallDecl = FD; 628 } 629 FunctionDecl *getcudaConfigureCallDecl() { 630 return cudaConfigureCallDecl; 631 } 632 633 /// This builds the struct used for __block variables. 634 QualType BuildByRefType(StringRef DeclName, QualType Ty) const; 635 636 /// Returns true iff we need copy/dispose helpers for the given type. 637 bool BlockRequiresCopying(QualType Ty) const; 638 639 /// getLValueReferenceType - Return the uniqued reference to the type for an 640 /// lvalue reference to the specified type. 641 QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true) 642 const; 643 644 /// getRValueReferenceType - Return the uniqued reference to the type for an 645 /// rvalue reference to the specified type. 646 QualType getRValueReferenceType(QualType T) const; 647 648 /// getMemberPointerType - Return the uniqued reference to the type for a 649 /// member pointer to the specified type in the specified class. The class 650 /// is a Type because it could be a dependent name. 651 QualType getMemberPointerType(QualType T, const Type *Cls) const; 652 653 /// getVariableArrayType - Returns a non-unique reference to the type for a 654 /// variable array of the specified element type. 655 QualType getVariableArrayType(QualType EltTy, Expr *NumElts, 656 ArrayType::ArraySizeModifier ASM, 657 unsigned IndexTypeQuals, 658 SourceRange Brackets) const; 659 660 /// getDependentSizedArrayType - Returns a non-unique reference to 661 /// the type for a dependently-sized array of the specified element 662 /// type. FIXME: We will need these to be uniqued, or at least 663 /// comparable, at some point. 664 QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, 665 ArrayType::ArraySizeModifier ASM, 666 unsigned IndexTypeQuals, 667 SourceRange Brackets) const; 668 669 /// getIncompleteArrayType - Returns a unique reference to the type for a 670 /// incomplete array of the specified element type. 671 QualType getIncompleteArrayType(QualType EltTy, 672 ArrayType::ArraySizeModifier ASM, 673 unsigned IndexTypeQuals) const; 674 675 /// getConstantArrayType - Return the unique reference to the type for a 676 /// constant array of the specified element type. 677 QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, 678 ArrayType::ArraySizeModifier ASM, 679 unsigned IndexTypeQuals) const; 680 681 /// getVariableArrayDecayedType - Returns a vla type where known sizes 682 /// are replaced with [*]. 683 QualType getVariableArrayDecayedType(QualType Ty) const; 684 685 /// getVectorType - Return the unique reference to a vector type of 686 /// the specified element type and size. VectorType must be a built-in type. 687 QualType getVectorType(QualType VectorType, unsigned NumElts, 688 VectorType::VectorKind VecKind) const; 689 690 /// getExtVectorType - Return the unique reference to an extended vector type 691 /// of the specified element type and size. VectorType must be a built-in 692 /// type. 693 QualType getExtVectorType(QualType VectorType, unsigned NumElts) const; 694 695 /// getDependentSizedExtVectorType - Returns a non-unique reference to 696 /// the type for a dependently-sized vector of the specified element 697 /// type. FIXME: We will need these to be uniqued, or at least 698 /// comparable, at some point. 699 QualType getDependentSizedExtVectorType(QualType VectorType, 700 Expr *SizeExpr, 701 SourceLocation AttrLoc) const; 702 703 /// getFunctionNoProtoType - Return a K&R style C function type like 'int()'. 704 /// 705 QualType getFunctionNoProtoType(QualType ResultTy, 706 const FunctionType::ExtInfo &Info) const; 707 708 QualType getFunctionNoProtoType(QualType ResultTy) const { 709 return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo()); 710 } 711 712 /// getFunctionType - Return a normal function type with a typed 713 /// argument list. 714 QualType getFunctionType(QualType ResultTy, 715 const QualType *Args, unsigned NumArgs, 716 const FunctionProtoType::ExtProtoInfo &EPI) const; 717 718 /// getTypeDeclType - Return the unique reference to the type for 719 /// the specified type declaration. 720 QualType getTypeDeclType(const TypeDecl *Decl, 721 const TypeDecl *PrevDecl = 0) const { 722 assert(Decl && "Passed null for Decl param"); 723 if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 724 725 if (PrevDecl) { 726 assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 727 Decl->TypeForDecl = PrevDecl->TypeForDecl; 728 return QualType(PrevDecl->TypeForDecl, 0); 729 } 730 731 return getTypeDeclTypeSlow(Decl); 732 } 733 734 /// getTypedefType - Return the unique reference to the type for the 735 /// specified typedef-name decl. 736 QualType getTypedefType(const TypedefNameDecl *Decl, 737 QualType Canon = QualType()) const; 738 739 QualType getRecordType(const RecordDecl *Decl) const; 740 741 QualType getEnumType(const EnumDecl *Decl) const; 742 743 QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; 744 745 QualType getAttributedType(AttributedType::Kind attrKind, 746 QualType modifiedType, 747 QualType equivalentType); 748 749 QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, 750 QualType Replacement) const; 751 QualType getSubstTemplateTypeParmPackType( 752 const TemplateTypeParmType *Replaced, 753 const TemplateArgument &ArgPack); 754 755 QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, 756 bool ParameterPack, 757 TemplateTypeParmDecl *ParmDecl = 0) const; 758 759 QualType getTemplateSpecializationType(TemplateName T, 760 const TemplateArgument *Args, 761 unsigned NumArgs, 762 QualType Canon = QualType()) const; 763 764 QualType getCanonicalTemplateSpecializationType(TemplateName T, 765 const TemplateArgument *Args, 766 unsigned NumArgs) const; 767 768 QualType getTemplateSpecializationType(TemplateName T, 769 const TemplateArgumentListInfo &Args, 770 QualType Canon = QualType()) const; 771 772 TypeSourceInfo * 773 getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc, 774 const TemplateArgumentListInfo &Args, 775 QualType Canon = QualType()) const; 776 777 QualType getParenType(QualType NamedType) const; 778 779 QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 780 NestedNameSpecifier *NNS, 781 QualType NamedType) const; 782 QualType getDependentNameType(ElaboratedTypeKeyword Keyword, 783 NestedNameSpecifier *NNS, 784 const IdentifierInfo *Name, 785 QualType Canon = QualType()) const; 786 787 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 788 NestedNameSpecifier *NNS, 789 const IdentifierInfo *Name, 790 const TemplateArgumentListInfo &Args) const; 791 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 792 NestedNameSpecifier *NNS, 793 const IdentifierInfo *Name, 794 unsigned NumArgs, 795 const TemplateArgument *Args) const; 796 797 QualType getPackExpansionType(QualType Pattern, 798 llvm::Optional<unsigned> NumExpansions); 799 800 QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl) const; 801 802 QualType getObjCObjectType(QualType Base, 803 ObjCProtocolDecl * const *Protocols, 804 unsigned NumProtocols) const; 805 806 /// getObjCObjectPointerType - Return a ObjCObjectPointerType type 807 /// for the given ObjCObjectType. 808 QualType getObjCObjectPointerType(QualType OIT) const; 809 810 /// getTypeOfType - GCC extension. 811 QualType getTypeOfExprType(Expr *e) const; 812 QualType getTypeOfType(QualType t) const; 813 814 /// getDecltypeType - C++0x decltype. 815 QualType getDecltypeType(Expr *e) const; 816 817 /// getUnaryTransformType - unary type transforms 818 QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, 819 UnaryTransformType::UTTKind UKind) const; 820 821 /// getAutoType - C++0x deduced auto type. 822 QualType getAutoType(QualType DeducedType) const; 823 824 /// getAutoDeductType - C++0x deduction pattern for 'auto' type. 825 QualType getAutoDeductType() const; 826 827 /// getAutoRRefDeductType - C++0x deduction pattern for 'auto &&' type. 828 QualType getAutoRRefDeductType() const; 829 830 /// getTagDeclType - Return the unique reference to the type for the 831 /// specified TagDecl (struct/union/class/enum) decl. 832 QualType getTagDeclType(const TagDecl *Decl) const; 833 834 /// getSizeType - Return the unique type for "size_t" (C99 7.17), defined 835 /// in <stddef.h>. The sizeof operator requires this (C99 6.5.3.4p4). 836 CanQualType getSizeType() const; 837 838 /// getIntMaxType - Return the unique type for "intmax_t" (C99 7.18.1.5), 839 /// defined in <stdint.h>. 840 CanQualType getIntMaxType() const; 841 842 /// getUIntMaxType - Return the unique type for "uintmax_t" (C99 7.18.1.5), 843 /// defined in <stdint.h>. 844 CanQualType getUIntMaxType() const; 845 846 /// getWCharType - In C++, this returns the unique wchar_t type. In C99, this 847 /// returns a type compatible with the type defined in <stddef.h> as defined 848 /// by the target. 849 QualType getWCharType() const { return WCharTy; } 850 851 /// getSignedWCharType - Return the type of "signed wchar_t". 852 /// Used when in C++, as a GCC extension. 853 QualType getSignedWCharType() const; 854 855 /// getUnsignedWCharType - Return the type of "unsigned wchar_t". 856 /// Used when in C++, as a GCC extension. 857 QualType getUnsignedWCharType() const; 858 859 /// getPointerDiffType - Return the unique type for "ptrdiff_t" (C99 7.17) 860 /// defined in <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 861 QualType getPointerDiffType() const; 862 863 // getCFConstantStringType - Return the C structure type used to represent 864 // constant CFStrings. 865 QualType getCFConstantStringType() const; 866 867 /// Get the structure type used to representation CFStrings, or NULL 868 /// if it hasn't yet been built. 869 QualType getRawCFConstantStringType() const { 870 if (CFConstantStringTypeDecl) 871 return getTagDeclType(CFConstantStringTypeDecl); 872 return QualType(); 873 } 874 void setCFConstantStringType(QualType T); 875 876 // This setter/getter represents the ObjC type for an NSConstantString. 877 void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl); 878 QualType getObjCConstantStringInterface() const { 879 return ObjCConstantStringType; 880 } 881 882 /// \brief Retrieve the type that 'id' has been defined to, which may be 883 /// different from the built-in 'id' if 'id' has been typedef'd. 884 QualType getObjCIdRedefinitionType() const { 885 if (ObjCIdRedefinitionType.isNull()) 886 return getObjCIdType(); 887 return ObjCIdRedefinitionType; 888 } 889 890 /// \brief Set the user-written type that redefines 'id'. 891 void setObjCIdRedefinitionType(QualType RedefType) { 892 ObjCIdRedefinitionType = RedefType; 893 } 894 895 /// \brief Retrieve the type that 'Class' has been defined to, which may be 896 /// different from the built-in 'Class' if 'Class' has been typedef'd. 897 QualType getObjCClassRedefinitionType() const { 898 if (ObjCClassRedefinitionType.isNull()) 899 return getObjCClassType(); 900 return ObjCClassRedefinitionType; 901 } 902 903 /// \brief Set the user-written type that redefines 'SEL'. 904 void setObjCClassRedefinitionType(QualType RedefType) { 905 ObjCClassRedefinitionType = RedefType; 906 } 907 908 /// \brief Retrieve the type that 'SEL' has been defined to, which may be 909 /// different from the built-in 'SEL' if 'SEL' has been typedef'd. 910 QualType getObjCSelRedefinitionType() const { 911 if (ObjCSelRedefinitionType.isNull()) 912 return getObjCSelType(); 913 return ObjCSelRedefinitionType; 914 } 915 916 917 /// \brief Set the user-written type that redefines 'SEL'. 918 void setObjCSelRedefinitionType(QualType RedefType) { 919 ObjCSelRedefinitionType = RedefType; 920 } 921 922 /// \brief Retrieve the Objective-C "instancetype" type, if already known; 923 /// otherwise, returns a NULL type; 924 QualType getObjCInstanceType() { 925 return getTypeDeclType(getObjCInstanceTypeDecl()); 926 } 927 928 /// \brief Retrieve the typedef declaration corresponding to the Objective-C 929 /// "instancetype" type. 930 TypedefDecl *getObjCInstanceTypeDecl(); 931 932 /// \brief Set the type for the C FILE type. 933 void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } 934 935 /// \brief Retrieve the C FILE type. 936 QualType getFILEType() const { 937 if (FILEDecl) 938 return getTypeDeclType(FILEDecl); 939 return QualType(); 940 } 941 942 /// \brief Set the type for the C jmp_buf type. 943 void setjmp_bufDecl(TypeDecl *jmp_bufDecl) { 944 this->jmp_bufDecl = jmp_bufDecl; 945 } 946 947 /// \brief Retrieve the C jmp_buf type. 948 QualType getjmp_bufType() const { 949 if (jmp_bufDecl) 950 return getTypeDeclType(jmp_bufDecl); 951 return QualType(); 952 } 953 954 /// \brief Set the type for the C sigjmp_buf type. 955 void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) { 956 this->sigjmp_bufDecl = sigjmp_bufDecl; 957 } 958 959 /// \brief Retrieve the C sigjmp_buf type. 960 QualType getsigjmp_bufType() const { 961 if (sigjmp_bufDecl) 962 return getTypeDeclType(sigjmp_bufDecl); 963 return QualType(); 964 } 965 966 /// \brief The result type of logical operations, '<', '>', '!=', etc. 967 QualType getLogicalOperationType() const { 968 return getLangOptions().CPlusPlus ? BoolTy : IntTy; 969 } 970 971 /// getObjCEncodingForType - Emit the ObjC type encoding for the 972 /// given type into \arg S. If \arg NameFields is specified then 973 /// record field names are also encoded. 974 void getObjCEncodingForType(QualType t, std::string &S, 975 const FieldDecl *Field=0) const; 976 977 void getLegacyIntegralTypeEncoding(QualType &t) const; 978 979 // Put the string version of type qualifiers into S. 980 void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 981 std::string &S) const; 982 983 /// getObjCEncodingForFunctionDecl - Returns the encoded type for this 984 /// function. This is in the same format as Objective-C method encodings. 985 /// 986 /// \returns true if an error occurred (e.g., because one of the parameter 987 /// types is incomplete), false otherwise. 988 bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S); 989 990 /// getObjCEncodingForMethodDecl - Return the encoded type for this method 991 /// declaration. 992 /// 993 /// \returns true if an error occurred (e.g., because one of the parameter 994 /// types is incomplete), false otherwise. 995 bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S) 996 const; 997 998 /// getObjCEncodingForBlock - Return the encoded type for this block 999 /// declaration. 1000 std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const; 1001 1002 /// getObjCEncodingForPropertyDecl - Return the encoded type for 1003 /// this method declaration. If non-NULL, Container must be either 1004 /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should 1005 /// only be NULL when getting encodings for protocol properties. 1006 void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 1007 const Decl *Container, 1008 std::string &S) const; 1009 1010 bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 1011 ObjCProtocolDecl *rProto) const; 1012 1013 /// getObjCEncodingTypeSize returns size of type for objective-c encoding 1014 /// purpose in characters. 1015 CharUnits getObjCEncodingTypeSize(QualType t) const; 1016 1017 /// \brief Retrieve the typedef corresponding to the predefined 'id' type 1018 /// in Objective-C. 1019 TypedefDecl *getObjCIdDecl() const; 1020 1021 /// This setter/getter represents the ObjC 'id' type. It is setup lazily, by 1022 /// Sema. id is always a (typedef for a) pointer type, a pointer to a struct. 1023 QualType getObjCIdType() const { 1024 return getTypeDeclType(getObjCIdDecl()); 1025 } 1026 1027 /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type 1028 /// in Objective-C. 1029 TypedefDecl *getObjCSelDecl() const; 1030 1031 /// \brief Retrieve the type that corresponds to the predefined Objective-C 1032 /// 'SEL' type. 1033 QualType getObjCSelType() const { 1034 return getTypeDeclType(getObjCSelDecl()); 1035 } 1036 1037 void setObjCProtoType(QualType QT); 1038 QualType getObjCProtoType() const { return ObjCProtoType; } 1039 1040 /// \brief Retrieve the typedef declaration corresponding to the predefined 1041 /// Objective-C 'Class' type. 1042 TypedefDecl *getObjCClassDecl() const; 1043 1044 /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by 1045 /// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a 1046 /// struct. 1047 QualType getObjCClassType() const { 1048 return getTypeDeclType(getObjCClassDecl()); 1049 } 1050 1051 void setBuiltinVaListType(QualType T); 1052 QualType getBuiltinVaListType() const { return BuiltinVaListType; } 1053 1054 /// getCVRQualifiedType - Returns a type with additional const, 1055 /// volatile, or restrict qualifiers. 1056 QualType getCVRQualifiedType(QualType T, unsigned CVR) const { 1057 return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); 1058 } 1059 1060 /// getQualifiedType - Returns a type with additional qualifiers. 1061 QualType getQualifiedType(QualType T, Qualifiers Qs) const { 1062 if (!Qs.hasNonFastQualifiers()) 1063 return T.withFastQualifiers(Qs.getFastQualifiers()); 1064 QualifierCollector Qc(Qs); 1065 const Type *Ptr = Qc.strip(T); 1066 return getExtQualType(Ptr, Qc); 1067 } 1068 1069 /// getQualifiedType - Returns a type with additional qualifiers. 1070 QualType getQualifiedType(const Type *T, Qualifiers Qs) const { 1071 if (!Qs.hasNonFastQualifiers()) 1072 return QualType(T, Qs.getFastQualifiers()); 1073 return getExtQualType(T, Qs); 1074 } 1075 1076 /// getLifetimeQualifiedType - Returns a type with the given 1077 /// lifetime qualifier. 1078 QualType getLifetimeQualifiedType(QualType type, 1079 Qualifiers::ObjCLifetime lifetime) { 1080 assert(type.getObjCLifetime() == Qualifiers::OCL_None); 1081 assert(lifetime != Qualifiers::OCL_None); 1082 1083 Qualifiers qs; 1084 qs.addObjCLifetime(lifetime); 1085 return getQualifiedType(type, qs); 1086 } 1087 1088 DeclarationNameInfo getNameForTemplate(TemplateName Name, 1089 SourceLocation NameLoc) const; 1090 1091 TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, 1092 UnresolvedSetIterator End) const; 1093 1094 TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, 1095 bool TemplateKeyword, 1096 TemplateDecl *Template) const; 1097 1098 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 1099 const IdentifierInfo *Name) const; 1100 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 1101 OverloadedOperatorKind Operator) const; 1102 TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 1103 TemplateName replacement) const; 1104 TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 1105 const TemplateArgument &ArgPack) const; 1106 1107 enum GetBuiltinTypeError { 1108 GE_None, //< No error 1109 GE_Missing_stdio, //< Missing a type from <stdio.h> 1110 GE_Missing_setjmp //< Missing a type from <setjmp.h> 1111 }; 1112 1113 /// GetBuiltinType - Return the type for the specified builtin. If 1114 /// IntegerConstantArgs is non-null, it is filled in with a bitmask of 1115 /// arguments to the builtin that are required to be integer constant 1116 /// expressions. 1117 QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, 1118 unsigned *IntegerConstantArgs = 0) const; 1119 1120private: 1121 CanQualType getFromTargetType(unsigned Type) const; 1122 1123 //===--------------------------------------------------------------------===// 1124 // Type Predicates. 1125 //===--------------------------------------------------------------------===// 1126 1127public: 1128 /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 1129 /// garbage collection attribute. 1130 /// 1131 Qualifiers::GC getObjCGCAttrKind(QualType Ty) const; 1132 1133 /// areCompatibleVectorTypes - Return true if the given vector types 1134 /// are of the same unqualified type or if they are equivalent to the same 1135 /// GCC vector type, ignoring whether they are target-specific (AltiVec or 1136 /// Neon) types. 1137 bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec); 1138 1139 /// isObjCNSObjectType - Return true if this is an NSObject object with 1140 /// its NSObject attribute set. 1141 static bool isObjCNSObjectType(QualType Ty) { 1142 return Ty->isObjCNSObjectType(); 1143 } 1144 1145 //===--------------------------------------------------------------------===// 1146 // Type Sizing and Analysis 1147 //===--------------------------------------------------------------------===// 1148 1149 /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 1150 /// scalar floating point type. 1151 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const; 1152 1153 /// getTypeInfo - Get the size and alignment of the specified complete type in 1154 /// bits. 1155 std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const; 1156 std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const { 1157 return getTypeInfo(T.getTypePtr()); 1158 } 1159 1160 /// getTypeSize - Return the size of the specified type, in bits. This method 1161 /// does not work on incomplete types. 1162 uint64_t getTypeSize(QualType T) const { 1163 return getTypeInfo(T).first; 1164 } 1165 uint64_t getTypeSize(const Type *T) const { 1166 return getTypeInfo(T).first; 1167 } 1168 1169 /// getCharWidth - Return the size of the character type, in bits 1170 uint64_t getCharWidth() const { 1171 return getTypeSize(CharTy); 1172 } 1173 1174 /// toCharUnitsFromBits - Convert a size in bits to a size in characters. 1175 CharUnits toCharUnitsFromBits(int64_t BitSize) const; 1176 1177 /// toBits - Convert a size in characters to a size in bits. 1178 int64_t toBits(CharUnits CharSize) const; 1179 1180 /// getTypeSizeInChars - Return the size of the specified type, in characters. 1181 /// This method does not work on incomplete types. 1182 CharUnits getTypeSizeInChars(QualType T) const; 1183 CharUnits getTypeSizeInChars(const Type *T) const; 1184 1185 /// getTypeAlign - Return the ABI-specified alignment of a type, in bits. 1186 /// This method does not work on incomplete types. 1187 unsigned getTypeAlign(QualType T) const { 1188 return getTypeInfo(T).second; 1189 } 1190 unsigned getTypeAlign(const Type *T) const { 1191 return getTypeInfo(T).second; 1192 } 1193 1194 /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 1195 /// characters. This method does not work on incomplete types. 1196 CharUnits getTypeAlignInChars(QualType T) const; 1197 CharUnits getTypeAlignInChars(const Type *T) const; 1198 1199 std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const; 1200 std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const; 1201 1202 /// getPreferredTypeAlign - Return the "preferred" alignment of the specified 1203 /// type for the current target in bits. This can be different than the ABI 1204 /// alignment in cases where it is beneficial for performance to overalign 1205 /// a data type. 1206 unsigned getPreferredTypeAlign(const Type *T) const; 1207 1208 /// getDeclAlign - Return a conservative estimate of the alignment of 1209 /// the specified decl. Note that bitfields do not have a valid alignment, so 1210 /// this method will assert on them. 1211 /// If @p RefAsPointee, references are treated like their underlying type 1212 /// (for alignof), else they're treated like pointers (for CodeGen). 1213 CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false) const; 1214 1215 /// getASTRecordLayout - Get or compute information about the layout of the 1216 /// specified record (struct/union/class), which indicates its size and field 1217 /// position information. 1218 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const; 1219 1220 /// getASTObjCInterfaceLayout - Get or compute information about the 1221 /// layout of the specified Objective-C interface. 1222 const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) 1223 const; 1224 1225 void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS) const; 1226 1227 /// getASTObjCImplementationLayout - Get or compute information about 1228 /// the layout of the specified Objective-C implementation. This may 1229 /// differ from the interface if synthesized ivars are present. 1230 const ASTRecordLayout & 1231 getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const; 1232 1233 /// getKeyFunction - Get the key function for the given record decl, or NULL 1234 /// if there isn't one. The key function is, according to the Itanium C++ ABI 1235 /// section 5.2.3: 1236 /// 1237 /// ...the first non-pure virtual function that is not inline at the point 1238 /// of class definition. 1239 const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD); 1240 1241 bool isNearlyEmpty(const CXXRecordDecl *RD) const; 1242 1243 MangleContext *createMangleContext(); 1244 1245 void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, 1246 SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; 1247 1248 unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; 1249 void CollectInheritedProtocols(const Decl *CDecl, 1250 llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); 1251 1252 //===--------------------------------------------------------------------===// 1253 // Type Operators 1254 //===--------------------------------------------------------------------===// 1255 1256 /// getCanonicalType - Return the canonical (structural) type corresponding to 1257 /// the specified potentially non-canonical type. The non-canonical version 1258 /// of a type may have many "decorated" versions of types. Decorators can 1259 /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed 1260 /// to be free of any of these, allowing two canonical types to be compared 1261 /// for exact equality with a simple pointer comparison. 1262 CanQualType getCanonicalType(QualType T) const { 1263 return CanQualType::CreateUnsafe(T.getCanonicalType()); 1264 } 1265 1266 const Type *getCanonicalType(const Type *T) const { 1267 return T->getCanonicalTypeInternal().getTypePtr(); 1268 } 1269 1270 /// getCanonicalParamType - Return the canonical parameter type 1271 /// corresponding to the specific potentially non-canonical one. 1272 /// Qualifiers are stripped off, functions are turned into function 1273 /// pointers, and arrays decay one level into pointers. 1274 CanQualType getCanonicalParamType(QualType T) const; 1275 1276 /// \brief Determine whether the given types are equivalent. 1277 bool hasSameType(QualType T1, QualType T2) const { 1278 return getCanonicalType(T1) == getCanonicalType(T2); 1279 } 1280 1281 /// \brief Returns this type as a completely-unqualified array type, 1282 /// capturing the qualifiers in Quals. This will remove the minimal amount of 1283 /// sugaring from the types, similar to the behavior of 1284 /// QualType::getUnqualifiedType(). 1285 /// 1286 /// \param T is the qualified type, which may be an ArrayType 1287 /// 1288 /// \param Quals will receive the full set of qualifiers that were 1289 /// applied to the array. 1290 /// 1291 /// \returns if this is an array type, the completely unqualified array type 1292 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). 1293 QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals); 1294 1295 /// \brief Determine whether the given types are equivalent after 1296 /// cvr-qualifiers have been removed. 1297 bool hasSameUnqualifiedType(QualType T1, QualType T2) const { 1298 return getCanonicalType(T1).getTypePtr() == 1299 getCanonicalType(T2).getTypePtr(); 1300 } 1301 1302 bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2); 1303 1304 /// \brief Retrieves the "canonical" nested name specifier for a 1305 /// given nested name specifier. 1306 /// 1307 /// The canonical nested name specifier is a nested name specifier 1308 /// that uniquely identifies a type or namespace within the type 1309 /// system. For example, given: 1310 /// 1311 /// \code 1312 /// namespace N { 1313 /// struct S { 1314 /// template<typename T> struct X { typename T* type; }; 1315 /// }; 1316 /// } 1317 /// 1318 /// template<typename T> struct Y { 1319 /// typename N::S::X<T>::type member; 1320 /// }; 1321 /// \endcode 1322 /// 1323 /// Here, the nested-name-specifier for N::S::X<T>:: will be 1324 /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined 1325 /// by declarations in the type system and the canonical type for 1326 /// the template type parameter 'T' is template-param-0-0. 1327 NestedNameSpecifier * 1328 getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const; 1329 1330 /// \brief Retrieves the default calling convention to use for 1331 /// C++ instance methods. 1332 CallingConv getDefaultMethodCallConv(); 1333 1334 /// \brief Retrieves the canonical representation of the given 1335 /// calling convention. 1336 CallingConv getCanonicalCallConv(CallingConv CC) const { 1337 if (!LangOpts.MRTD && CC == CC_C) 1338 return CC_Default; 1339 return CC; 1340 } 1341 1342 /// \brief Determines whether two calling conventions name the same 1343 /// calling convention. 1344 bool isSameCallConv(CallingConv lcc, CallingConv rcc) { 1345 return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc)); 1346 } 1347 1348 /// \brief Retrieves the "canonical" template name that refers to a 1349 /// given template. 1350 /// 1351 /// The canonical template name is the simplest expression that can 1352 /// be used to refer to a given template. For most templates, this 1353 /// expression is just the template declaration itself. For example, 1354 /// the template std::vector can be referred to via a variety of 1355 /// names---std::vector, ::std::vector, vector (if vector is in 1356 /// scope), etc.---but all of these names map down to the same 1357 /// TemplateDecl, which is used to form the canonical template name. 1358 /// 1359 /// Dependent template names are more interesting. Here, the 1360 /// template name could be something like T::template apply or 1361 /// std::allocator<T>::template rebind, where the nested name 1362 /// specifier itself is dependent. In this case, the canonical 1363 /// template name uses the shortest form of the dependent 1364 /// nested-name-specifier, which itself contains all canonical 1365 /// types, values, and templates. 1366 TemplateName getCanonicalTemplateName(TemplateName Name) const; 1367 1368 /// \brief Determine whether the given template names refer to the same 1369 /// template. 1370 bool hasSameTemplateName(TemplateName X, TemplateName Y); 1371 1372 /// \brief Retrieve the "canonical" template argument. 1373 /// 1374 /// The canonical template argument is the simplest template argument 1375 /// (which may be a type, value, expression, or declaration) that 1376 /// expresses the value of the argument. 1377 TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) 1378 const; 1379 1380 /// Type Query functions. If the type is an instance of the specified class, 1381 /// return the Type pointer for the underlying maximally pretty type. This 1382 /// is a member of ASTContext because this may need to do some amount of 1383 /// canonicalization, e.g. to move type qualifiers into the element type. 1384 const ArrayType *getAsArrayType(QualType T) const; 1385 const ConstantArrayType *getAsConstantArrayType(QualType T) const { 1386 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T)); 1387 } 1388 const VariableArrayType *getAsVariableArrayType(QualType T) const { 1389 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T)); 1390 } 1391 const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const { 1392 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T)); 1393 } 1394 const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) 1395 const { 1396 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T)); 1397 } 1398 1399 /// getBaseElementType - Returns the innermost element type of an array type. 1400 /// For example, will return "int" for int[m][n] 1401 QualType getBaseElementType(const ArrayType *VAT) const; 1402 1403 /// getBaseElementType - Returns the innermost element type of a type 1404 /// (which needn't actually be an array type). 1405 QualType getBaseElementType(QualType QT) const; 1406 1407 /// getConstantArrayElementCount - Returns number of constant array elements. 1408 uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const; 1409 1410 /// \brief Perform adjustment on the parameter type of a function. 1411 /// 1412 /// This routine adjusts the given parameter type @p T to the actual 1413 /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], 1414 /// C++ [dcl.fct]p3). The adjusted parameter type is returned. 1415 QualType getAdjustedParameterType(QualType T); 1416 1417 /// \brief Retrieve the parameter type as adjusted for use in the signature 1418 /// of a function, decaying array and function types and removing top-level 1419 /// cv-qualifiers. 1420 QualType getSignatureParameterType(QualType T); 1421 1422 /// getArrayDecayedType - Return the properly qualified result of decaying the 1423 /// specified array type to a pointer. This operation is non-trivial when 1424 /// handling typedefs etc. The canonical type of "T" must be an array type, 1425 /// this returns a pointer to a properly qualified element of the array. 1426 /// 1427 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 1428 QualType getArrayDecayedType(QualType T) const; 1429 1430 /// getPromotedIntegerType - Returns the type that Promotable will 1431 /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 1432 /// integer type. 1433 QualType getPromotedIntegerType(QualType PromotableType) const; 1434 1435 /// \brief Recurses in pointer/array types until it finds an objc retainable 1436 /// type and returns its ownership. 1437 Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const; 1438 1439 /// \brief Whether this is a promotable bitfield reference according 1440 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 1441 /// 1442 /// \returns the type this bit-field will promote to, or NULL if no 1443 /// promotion occurs. 1444 QualType isPromotableBitField(Expr *E) const; 1445 1446 /// getIntegerTypeOrder - Returns the highest ranked integer type: 1447 /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 1448 /// LHS < RHS, return -1. 1449 int getIntegerTypeOrder(QualType LHS, QualType RHS) const; 1450 1451 /// getFloatingTypeOrder - Compare the rank of the two specified floating 1452 /// point types, ignoring the domain of the type (i.e. 'double' == 1453 /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 1454 /// LHS < RHS, return -1. 1455 int getFloatingTypeOrder(QualType LHS, QualType RHS) const; 1456 1457 /// getFloatingTypeOfSizeWithinDomain - Returns a real floating 1458 /// point or a complex type (based on typeDomain/typeSize). 1459 /// 'typeDomain' is a real floating point or complex type. 1460 /// 'typeSize' is a real floating point or complex type. 1461 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 1462 QualType typeDomain) const; 1463 1464 unsigned getTargetAddressSpace(QualType T) const { 1465 return getTargetAddressSpace(T.getQualifiers()); 1466 } 1467 1468 unsigned getTargetAddressSpace(Qualifiers Q) const { 1469 return getTargetAddressSpace(Q.getAddressSpace()); 1470 } 1471 1472 unsigned getTargetAddressSpace(unsigned AS) const { 1473 if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count) 1474 return AS; 1475 else 1476 return (*AddrSpaceMap)[AS - LangAS::Offset]; 1477 } 1478 1479private: 1480 // Helper for integer ordering 1481 unsigned getIntegerRank(const Type *T) const; 1482 1483public: 1484 1485 //===--------------------------------------------------------------------===// 1486 // Type Compatibility Predicates 1487 //===--------------------------------------------------------------------===// 1488 1489 /// Compatibility predicates used to check assignment expressions. 1490 bool typesAreCompatible(QualType T1, QualType T2, 1491 bool CompareUnqualified = false); // C99 6.2.7p1 1492 1493 bool propertyTypesAreCompatible(QualType, QualType); 1494 bool typesAreBlockPointerCompatible(QualType, QualType); 1495 1496 bool isObjCIdType(QualType T) const { 1497 return T == getObjCIdType(); 1498 } 1499 bool isObjCClassType(QualType T) const { 1500 return T == getObjCClassType(); 1501 } 1502 bool isObjCSelType(QualType T) const { 1503 return T == getObjCSelType(); 1504 } 1505 bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS); 1506 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, 1507 bool ForCompare); 1508 1509 bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS); 1510 1511 // Check the safety of assignment from LHS to RHS 1512 bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 1513 const ObjCObjectPointerType *RHSOPT); 1514 bool canAssignObjCInterfaces(const ObjCObjectType *LHS, 1515 const ObjCObjectType *RHS); 1516 bool canAssignObjCInterfacesInBlockPointer( 1517 const ObjCObjectPointerType *LHSOPT, 1518 const ObjCObjectPointerType *RHSOPT, 1519 bool BlockReturnType); 1520 bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); 1521 QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, 1522 const ObjCObjectPointerType *RHSOPT); 1523 bool canBindObjCObjectType(QualType To, QualType From); 1524 1525 // Functions for calculating composite types 1526 QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, 1527 bool Unqualified = false, bool BlockReturnType = false); 1528 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, 1529 bool Unqualified = false); 1530 QualType mergeFunctionArgumentTypes(QualType, QualType, 1531 bool OfBlockPointer=false, 1532 bool Unqualified = false); 1533 QualType mergeTransparentUnionType(QualType, QualType, 1534 bool OfBlockPointer=false, 1535 bool Unqualified = false); 1536 1537 QualType mergeObjCGCQualifiers(QualType, QualType); 1538 1539 bool FunctionTypesMatchOnNSConsumedAttrs( 1540 const FunctionProtoType *FromFunctionType, 1541 const FunctionProtoType *ToFunctionType); 1542 1543 void ResetObjCLayout(const ObjCContainerDecl *CD) { 1544 ObjCLayouts[CD] = 0; 1545 } 1546 1547 //===--------------------------------------------------------------------===// 1548 // Integer Predicates 1549 //===--------------------------------------------------------------------===// 1550 1551 // The width of an integer, as defined in C99 6.2.6.2. This is the number 1552 // of bits in an integer type excluding any padding bits. 1553 unsigned getIntWidth(QualType T) const; 1554 1555 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding 1556 // unsigned integer type. This method takes a signed type, and returns the 1557 // corresponding unsigned integer type. 1558 QualType getCorrespondingUnsignedType(QualType T); 1559 1560 //===--------------------------------------------------------------------===// 1561 // Type Iterators. 1562 //===--------------------------------------------------------------------===// 1563 1564 typedef std::vector<Type*>::iterator type_iterator; 1565 typedef std::vector<Type*>::const_iterator const_type_iterator; 1566 1567 type_iterator types_begin() { return Types.begin(); } 1568 type_iterator types_end() { return Types.end(); } 1569 const_type_iterator types_begin() const { return Types.begin(); } 1570 const_type_iterator types_end() const { return Types.end(); } 1571 1572 //===--------------------------------------------------------------------===// 1573 // Integer Values 1574 //===--------------------------------------------------------------------===// 1575 1576 /// MakeIntValue - Make an APSInt of the appropriate width and 1577 /// signedness for the given \arg Value and integer \arg Type. 1578 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const { 1579 llvm::APSInt Res(getIntWidth(Type), 1580 !Type->isSignedIntegerOrEnumerationType()); 1581 Res = Value; 1582 return Res; 1583 } 1584 1585 /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 1586 ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D); 1587 /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 1588 ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); 1589 1590 /// \brief returns true if there is at lease one @implementation in TU. 1591 bool AnyObjCImplementation() { 1592 return !ObjCImpls.empty(); 1593 } 1594 1595 /// \brief Set the implementation of ObjCInterfaceDecl. 1596 void setObjCImplementation(ObjCInterfaceDecl *IFaceD, 1597 ObjCImplementationDecl *ImplD); 1598 /// \brief Set the implementation of ObjCCategoryDecl. 1599 void setObjCImplementation(ObjCCategoryDecl *CatD, 1600 ObjCCategoryImplDecl *ImplD); 1601 1602 /// \brief Get the duplicate declaration of a ObjCMethod in the same 1603 /// interface, or null if non exists. 1604 const ObjCMethodDecl *getObjCMethodRedeclaration( 1605 const ObjCMethodDecl *MD) const { 1606 llvm::DenseMap<const ObjCMethodDecl*, const ObjCMethodDecl*>::const_iterator 1607 I = ObjCMethodRedecls.find(MD); 1608 if (I == ObjCMethodRedecls.end()) 1609 return 0; 1610 return I->second; 1611 } 1612 1613 void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, 1614 const ObjCMethodDecl *Redecl) { 1615 ObjCMethodRedecls[MD] = Redecl; 1616 } 1617 1618 /// \brief Returns the objc interface that \arg ND belongs to if it is a 1619 /// objc method/property/ivar etc. that is part of an interface, 1620 /// otherwise returns null. 1621 ObjCInterfaceDecl *getObjContainingInterface(NamedDecl *ND) const; 1622 1623 /// \brief Set the copy inialization expression of a block var decl. 1624 void setBlockVarCopyInits(VarDecl*VD, Expr* Init); 1625 /// \brief Get the copy initialization expression of VarDecl,or NULL if 1626 /// none exists. 1627 Expr *getBlockVarCopyInits(const VarDecl*VD); 1628 1629 /// \brief Allocate an uninitialized TypeSourceInfo. 1630 /// 1631 /// The caller should initialize the memory held by TypeSourceInfo using 1632 /// the TypeLoc wrappers. 1633 /// 1634 /// \param T the type that will be the basis for type source info. This type 1635 /// should refer to how the declarator was written in source code, not to 1636 /// what type semantic analysis resolved the declarator to. 1637 /// 1638 /// \param Size the size of the type info to create, or 0 if the size 1639 /// should be calculated based on the type. 1640 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const; 1641 1642 /// \brief Allocate a TypeSourceInfo where all locations have been 1643 /// initialized to a given location, which defaults to the empty 1644 /// location. 1645 TypeSourceInfo * 1646 getTrivialTypeSourceInfo(QualType T, 1647 SourceLocation Loc = SourceLocation()) const; 1648 1649 TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; } 1650 1651 /// \brief Add a deallocation callback that will be invoked when the 1652 /// ASTContext is destroyed. 1653 /// 1654 /// \brief Callback A callback function that will be invoked on destruction. 1655 /// 1656 /// \brief Data Pointer data that will be provided to the callback function 1657 /// when it is called. 1658 void AddDeallocation(void (*Callback)(void*), void *Data); 1659 1660 GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD); 1661 GVALinkage GetGVALinkageForVariable(const VarDecl *VD); 1662 1663 /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH 1664 /// lazily, only when used; this is only relevant for function or file scoped 1665 /// var definitions. 1666 /// 1667 /// \returns true if the function/var must be CodeGen'ed/deserialized even if 1668 /// it is not used. 1669 bool DeclMustBeEmitted(const Decl *D); 1670 1671 1672 /// \brief Used by ParmVarDecl to store on the side the 1673 /// index of the parameter when it exceeds the size of the normal bitfield. 1674 void setParameterIndex(const ParmVarDecl *D, unsigned index); 1675 1676 /// \brief Used by ParmVarDecl to retrieve on the side the 1677 /// index of the parameter when it exceeds the size of the normal bitfield. 1678 unsigned getParameterIndex(const ParmVarDecl *D) const; 1679 1680 //===--------------------------------------------------------------------===// 1681 // Statistics 1682 //===--------------------------------------------------------------------===// 1683 1684 /// \brief The number of implicitly-declared default constructors. 1685 static unsigned NumImplicitDefaultConstructors; 1686 1687 /// \brief The number of implicitly-declared default constructors for 1688 /// which declarations were built. 1689 static unsigned NumImplicitDefaultConstructorsDeclared; 1690 1691 /// \brief The number of implicitly-declared copy constructors. 1692 static unsigned NumImplicitCopyConstructors; 1693 1694 /// \brief The number of implicitly-declared copy constructors for 1695 /// which declarations were built. 1696 static unsigned NumImplicitCopyConstructorsDeclared; 1697 1698 /// \brief The number of implicitly-declared move constructors. 1699 static unsigned NumImplicitMoveConstructors; 1700 1701 /// \brief The number of implicitly-declared move constructors for 1702 /// which declarations were built. 1703 static unsigned NumImplicitMoveConstructorsDeclared; 1704 1705 /// \brief The number of implicitly-declared copy assignment operators. 1706 static unsigned NumImplicitCopyAssignmentOperators; 1707 1708 /// \brief The number of implicitly-declared copy assignment operators for 1709 /// which declarations were built. 1710 static unsigned NumImplicitCopyAssignmentOperatorsDeclared; 1711 1712 /// \brief The number of implicitly-declared move assignment operators. 1713 static unsigned NumImplicitMoveAssignmentOperators; 1714 1715 /// \brief The number of implicitly-declared move assignment operators for 1716 /// which declarations were built. 1717 static unsigned NumImplicitMoveAssignmentOperatorsDeclared; 1718 1719 /// \brief The number of implicitly-declared destructors. 1720 static unsigned NumImplicitDestructors; 1721 1722 /// \brief The number of implicitly-declared destructors for which 1723 /// declarations were built. 1724 static unsigned NumImplicitDestructorsDeclared; 1725 1726private: 1727 ASTContext(const ASTContext&); // DO NOT IMPLEMENT 1728 void operator=(const ASTContext&); // DO NOT IMPLEMENT 1729 1730public: 1731 /// \brief Initialize built-in types. 1732 /// 1733 /// This routine may only be invoked once for a given ASTContext object. 1734 /// It is normally invoked by the ASTContext constructor. However, the 1735 /// constructor can be asked to delay initialization, which places the burden 1736 /// of calling this function on the user of that object. 1737 /// 1738 /// \param Target The target 1739 void InitBuiltinTypes(const TargetInfo &Target); 1740 1741private: 1742 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); 1743 1744 // Return the ObjC type encoding for a given type. 1745 void getObjCEncodingForTypeImpl(QualType t, std::string &S, 1746 bool ExpandPointedToStructures, 1747 bool ExpandStructures, 1748 const FieldDecl *Field, 1749 bool OutermostType = false, 1750 bool EncodingProperty = false, 1751 bool StructField = false) const; 1752 1753 // Adds the encoding of the structure's members. 1754 void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, 1755 const FieldDecl *Field, 1756 bool includeVBases = true) const; 1757 1758 const ASTRecordLayout & 1759 getObjCLayout(const ObjCInterfaceDecl *D, 1760 const ObjCImplementationDecl *Impl) const; 1761 1762private: 1763 /// \brief A set of deallocations that should be performed when the 1764 /// ASTContext is destroyed. 1765 SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations; 1766 1767 // FIXME: This currently contains the set of StoredDeclMaps used 1768 // by DeclContext objects. This probably should not be in ASTContext, 1769 // but we include it here so that ASTContext can quickly deallocate them. 1770 llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM; 1771 1772 /// \brief A counter used to uniquely identify "blocks". 1773 mutable unsigned int UniqueBlockByRefTypeID; 1774 1775 friend class DeclContext; 1776 friend class DeclarationNameTable; 1777 void ReleaseDeclContextMaps(); 1778}; 1779 1780/// @brief Utility function for constructing a nullary selector. 1781static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) { 1782 IdentifierInfo* II = &Ctx.Idents.get(name); 1783 return Ctx.Selectors.getSelector(0, &II); 1784} 1785 1786/// @brief Utility function for constructing an unary selector. 1787static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) { 1788 IdentifierInfo* II = &Ctx.Idents.get(name); 1789 return Ctx.Selectors.getSelector(1, &II); 1790} 1791 1792} // end namespace clang 1793 1794// operator new and delete aren't allowed inside namespaces. 1795// The throw specifications are mandated by the standard. 1796/// @brief Placement new for using the ASTContext's allocator. 1797/// 1798/// This placement form of operator new uses the ASTContext's allocator for 1799/// obtaining memory. It is a non-throwing new, which means that it returns 1800/// null on error. (If that is what the allocator does. The current does, so if 1801/// this ever changes, this operator will have to be changed, too.) 1802/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 1803/// @code 1804/// // Default alignment (8) 1805/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 1806/// // Specific alignment 1807/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments); 1808/// @endcode 1809/// Please note that you cannot use delete on the pointer; it must be 1810/// deallocated using an explicit destructor call followed by 1811/// @c Context.Deallocate(Ptr). 1812/// 1813/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 1814/// @param C The ASTContext that provides the allocator. 1815/// @param Alignment The alignment of the allocated memory (if the underlying 1816/// allocator supports it). 1817/// @return The allocated memory. Could be NULL. 1818inline void *operator new(size_t Bytes, const clang::ASTContext &C, 1819 size_t Alignment) throw () { 1820 return C.Allocate(Bytes, Alignment); 1821} 1822/// @brief Placement delete companion to the new above. 1823/// 1824/// This operator is just a companion to the new above. There is no way of 1825/// invoking it directly; see the new operator for more details. This operator 1826/// is called implicitly by the compiler if a placement new expression using 1827/// the ASTContext throws in the object constructor. 1828inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) 1829 throw () { 1830 C.Deallocate(Ptr); 1831} 1832 1833/// This placement form of operator new[] uses the ASTContext's allocator for 1834/// obtaining memory. It is a non-throwing new[], which means that it returns 1835/// null on error. 1836/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 1837/// @code 1838/// // Default alignment (8) 1839/// char *data = new (Context) char[10]; 1840/// // Specific alignment 1841/// char *data = new (Context, 4) char[10]; 1842/// @endcode 1843/// Please note that you cannot use delete on the pointer; it must be 1844/// deallocated using an explicit destructor call followed by 1845/// @c Context.Deallocate(Ptr). 1846/// 1847/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 1848/// @param C The ASTContext that provides the allocator. 1849/// @param Alignment The alignment of the allocated memory (if the underlying 1850/// allocator supports it). 1851/// @return The allocated memory. Could be NULL. 1852inline void *operator new[](size_t Bytes, const clang::ASTContext& C, 1853 size_t Alignment = 8) throw () { 1854 return C.Allocate(Bytes, Alignment); 1855} 1856 1857/// @brief Placement delete[] companion to the new[] above. 1858/// 1859/// This operator is just a companion to the new[] above. There is no way of 1860/// invoking it directly; see the new[] operator for more details. This operator 1861/// is called implicitly by the compiler if a placement new[] expression using 1862/// the ASTContext throws in the object constructor. 1863inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) 1864 throw () { 1865 C.Deallocate(Ptr); 1866} 1867 1868#endif 1869