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