ASTContext.h revision 4dfd02a17c6d604c72e6936527c5e1c56d3ecb7a
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 /// ObjCClassType - another pseudo built-in typedef type (set by Sema). 196 QualType ObjCClassTypedefType; 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 /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by 972 /// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a 973 /// struct. 974 QualType getObjCClassType() const { return ObjCClassTypedefType; } 975 void setObjCClassType(QualType T); 976 977 void setBuiltinVaListType(QualType T); 978 QualType getBuiltinVaListType() const { return BuiltinVaListType; } 979 980 /// getCVRQualifiedType - Returns a type with additional const, 981 /// volatile, or restrict qualifiers. 982 QualType getCVRQualifiedType(QualType T, unsigned CVR) const { 983 return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); 984 } 985 986 /// getQualifiedType - Returns a type with additional qualifiers. 987 QualType getQualifiedType(QualType T, Qualifiers Qs) const { 988 if (!Qs.hasNonFastQualifiers()) 989 return T.withFastQualifiers(Qs.getFastQualifiers()); 990 QualifierCollector Qc(Qs); 991 const Type *Ptr = Qc.strip(T); 992 return getExtQualType(Ptr, Qc); 993 } 994 995 /// getQualifiedType - Returns a type with additional qualifiers. 996 QualType getQualifiedType(const Type *T, Qualifiers Qs) const { 997 if (!Qs.hasNonFastQualifiers()) 998 return QualType(T, Qs.getFastQualifiers()); 999 return getExtQualType(T, Qs); 1000 } 1001 1002 /// getLifetimeQualifiedType - Returns a type with the given 1003 /// lifetime qualifier. 1004 QualType getLifetimeQualifiedType(QualType type, 1005 Qualifiers::ObjCLifetime lifetime) { 1006 assert(type.getObjCLifetime() == Qualifiers::OCL_None); 1007 assert(lifetime != Qualifiers::OCL_None); 1008 1009 Qualifiers qs; 1010 qs.addObjCLifetime(lifetime); 1011 return getQualifiedType(type, qs); 1012 } 1013 1014 DeclarationNameInfo getNameForTemplate(TemplateName Name, 1015 SourceLocation NameLoc) const; 1016 1017 TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, 1018 UnresolvedSetIterator End) const; 1019 1020 TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, 1021 bool TemplateKeyword, 1022 TemplateDecl *Template) const; 1023 1024 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 1025 const IdentifierInfo *Name) const; 1026 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 1027 OverloadedOperatorKind Operator) const; 1028 TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 1029 TemplateName replacement) const; 1030 TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 1031 const TemplateArgument &ArgPack) const; 1032 1033 enum GetBuiltinTypeError { 1034 GE_None, //< No error 1035 GE_Missing_stdio, //< Missing a type from <stdio.h> 1036 GE_Missing_setjmp //< Missing a type from <setjmp.h> 1037 }; 1038 1039 /// GetBuiltinType - Return the type for the specified builtin. If 1040 /// IntegerConstantArgs is non-null, it is filled in with a bitmask of 1041 /// arguments to the builtin that are required to be integer constant 1042 /// expressions. 1043 QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, 1044 unsigned *IntegerConstantArgs = 0) const; 1045 1046private: 1047 CanQualType getFromTargetType(unsigned Type) const; 1048 1049 //===--------------------------------------------------------------------===// 1050 // Type Predicates. 1051 //===--------------------------------------------------------------------===// 1052 1053public: 1054 /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's 1055 /// garbage collection attribute. 1056 /// 1057 Qualifiers::GC getObjCGCAttrKind(QualType Ty) const; 1058 1059 /// areCompatibleVectorTypes - Return true if the given vector types 1060 /// are of the same unqualified type or if they are equivalent to the same 1061 /// GCC vector type, ignoring whether they are target-specific (AltiVec or 1062 /// Neon) types. 1063 bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec); 1064 1065 /// isObjCNSObjectType - Return true if this is an NSObject object with 1066 /// its NSObject attribute set. 1067 static bool isObjCNSObjectType(QualType Ty) { 1068 return Ty->isObjCNSObjectType(); 1069 } 1070 1071 //===--------------------------------------------------------------------===// 1072 // Type Sizing and Analysis 1073 //===--------------------------------------------------------------------===// 1074 1075 /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified 1076 /// scalar floating point type. 1077 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const; 1078 1079 /// getTypeInfo - Get the size and alignment of the specified complete type in 1080 /// bits. 1081 std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const; 1082 std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const { 1083 return getTypeInfo(T.getTypePtr()); 1084 } 1085 1086 /// getTypeSize - Return the size of the specified type, in bits. This method 1087 /// does not work on incomplete types. 1088 uint64_t getTypeSize(QualType T) const { 1089 return getTypeInfo(T).first; 1090 } 1091 uint64_t getTypeSize(const Type *T) const { 1092 return getTypeInfo(T).first; 1093 } 1094 1095 /// getCharWidth - Return the size of the character type, in bits 1096 uint64_t getCharWidth() const { 1097 return getTypeSize(CharTy); 1098 } 1099 1100 /// toCharUnitsFromBits - Convert a size in bits to a size in characters. 1101 CharUnits toCharUnitsFromBits(int64_t BitSize) const; 1102 1103 /// toBits - Convert a size in characters to a size in bits. 1104 int64_t toBits(CharUnits CharSize) const; 1105 1106 /// getTypeSizeInChars - Return the size of the specified type, in characters. 1107 /// This method does not work on incomplete types. 1108 CharUnits getTypeSizeInChars(QualType T) const; 1109 CharUnits getTypeSizeInChars(const Type *T) const; 1110 1111 /// getTypeAlign - Return the ABI-specified alignment of a type, in bits. 1112 /// This method does not work on incomplete types. 1113 unsigned getTypeAlign(QualType T) const { 1114 return getTypeInfo(T).second; 1115 } 1116 unsigned getTypeAlign(const Type *T) const { 1117 return getTypeInfo(T).second; 1118 } 1119 1120 /// getTypeAlignInChars - Return the ABI-specified alignment of a type, in 1121 /// characters. This method does not work on incomplete types. 1122 CharUnits getTypeAlignInChars(QualType T) const; 1123 CharUnits getTypeAlignInChars(const Type *T) const; 1124 1125 std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const; 1126 std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const; 1127 1128 /// getPreferredTypeAlign - Return the "preferred" alignment of the specified 1129 /// type for the current target in bits. This can be different than the ABI 1130 /// alignment in cases where it is beneficial for performance to overalign 1131 /// a data type. 1132 unsigned getPreferredTypeAlign(const Type *T) const; 1133 1134 /// getDeclAlign - Return a conservative estimate of the alignment of 1135 /// the specified decl. Note that bitfields do not have a valid alignment, so 1136 /// this method will assert on them. 1137 /// If @p RefAsPointee, references are treated like their underlying type 1138 /// (for alignof), else they're treated like pointers (for CodeGen). 1139 CharUnits getDeclAlign(const Decl *D, bool RefAsPointee = false) const; 1140 1141 /// getASTRecordLayout - Get or compute information about the layout of the 1142 /// specified record (struct/union/class), which indicates its size and field 1143 /// position information. 1144 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const; 1145 1146 /// getASTObjCInterfaceLayout - Get or compute information about the 1147 /// layout of the specified Objective-C interface. 1148 const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) 1149 const; 1150 1151 void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS) const; 1152 1153 /// getASTObjCImplementationLayout - Get or compute information about 1154 /// the layout of the specified Objective-C implementation. This may 1155 /// differ from the interface if synthesized ivars are present. 1156 const ASTRecordLayout & 1157 getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const; 1158 1159 /// getKeyFunction - Get the key function for the given record decl, or NULL 1160 /// if there isn't one. The key function is, according to the Itanium C++ ABI 1161 /// section 5.2.3: 1162 /// 1163 /// ...the first non-pure virtual function that is not inline at the point 1164 /// of class definition. 1165 const CXXMethodDecl *getKeyFunction(const CXXRecordDecl *RD); 1166 1167 bool isNearlyEmpty(const CXXRecordDecl *RD) const; 1168 1169 MangleContext *createMangleContext(); 1170 1171 void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, 1172 SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; 1173 1174 unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; 1175 void CollectInheritedProtocols(const Decl *CDecl, 1176 llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); 1177 1178 //===--------------------------------------------------------------------===// 1179 // Type Operators 1180 //===--------------------------------------------------------------------===// 1181 1182 /// getCanonicalType - Return the canonical (structural) type corresponding to 1183 /// the specified potentially non-canonical type. The non-canonical version 1184 /// of a type may have many "decorated" versions of types. Decorators can 1185 /// include typedefs, 'typeof' operators, etc. The returned type is guaranteed 1186 /// to be free of any of these, allowing two canonical types to be compared 1187 /// for exact equality with a simple pointer comparison. 1188 CanQualType getCanonicalType(QualType T) const { 1189 return CanQualType::CreateUnsafe(T.getCanonicalType()); 1190 } 1191 1192 const Type *getCanonicalType(const Type *T) const { 1193 return T->getCanonicalTypeInternal().getTypePtr(); 1194 } 1195 1196 /// getCanonicalParamType - Return the canonical parameter type 1197 /// corresponding to the specific potentially non-canonical one. 1198 /// Qualifiers are stripped off, functions are turned into function 1199 /// pointers, and arrays decay one level into pointers. 1200 CanQualType getCanonicalParamType(QualType T) const; 1201 1202 /// \brief Determine whether the given types are equivalent. 1203 bool hasSameType(QualType T1, QualType T2) { 1204 return getCanonicalType(T1) == getCanonicalType(T2); 1205 } 1206 1207 /// \brief Returns this type as a completely-unqualified array type, 1208 /// capturing the qualifiers in Quals. This will remove the minimal amount of 1209 /// sugaring from the types, similar to the behavior of 1210 /// QualType::getUnqualifiedType(). 1211 /// 1212 /// \param T is the qualified type, which may be an ArrayType 1213 /// 1214 /// \param Quals will receive the full set of qualifiers that were 1215 /// applied to the array. 1216 /// 1217 /// \returns if this is an array type, the completely unqualified array type 1218 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). 1219 QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals); 1220 1221 /// \brief Determine whether the given types are equivalent after 1222 /// cvr-qualifiers have been removed. 1223 bool hasSameUnqualifiedType(QualType T1, QualType T2) { 1224 return getCanonicalType(T1).getTypePtr() == 1225 getCanonicalType(T2).getTypePtr(); 1226 } 1227 1228 bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2); 1229 1230 /// \brief Retrieves the "canonical" nested name specifier for a 1231 /// given nested name specifier. 1232 /// 1233 /// The canonical nested name specifier is a nested name specifier 1234 /// that uniquely identifies a type or namespace within the type 1235 /// system. For example, given: 1236 /// 1237 /// \code 1238 /// namespace N { 1239 /// struct S { 1240 /// template<typename T> struct X { typename T* type; }; 1241 /// }; 1242 /// } 1243 /// 1244 /// template<typename T> struct Y { 1245 /// typename N::S::X<T>::type member; 1246 /// }; 1247 /// \endcode 1248 /// 1249 /// Here, the nested-name-specifier for N::S::X<T>:: will be 1250 /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined 1251 /// by declarations in the type system and the canonical type for 1252 /// the template type parameter 'T' is template-param-0-0. 1253 NestedNameSpecifier * 1254 getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const; 1255 1256 /// \brief Retrieves the default calling convention to use for 1257 /// C++ instance methods. 1258 CallingConv getDefaultMethodCallConv(); 1259 1260 /// \brief Retrieves the canonical representation of the given 1261 /// calling convention. 1262 CallingConv getCanonicalCallConv(CallingConv CC) const { 1263 if (!LangOpts.MRTD && CC == CC_C) 1264 return CC_Default; 1265 return CC; 1266 } 1267 1268 /// \brief Determines whether two calling conventions name the same 1269 /// calling convention. 1270 bool isSameCallConv(CallingConv lcc, CallingConv rcc) { 1271 return (getCanonicalCallConv(lcc) == getCanonicalCallConv(rcc)); 1272 } 1273 1274 /// \brief Retrieves the "canonical" template name that refers to a 1275 /// given template. 1276 /// 1277 /// The canonical template name is the simplest expression that can 1278 /// be used to refer to a given template. For most templates, this 1279 /// expression is just the template declaration itself. For example, 1280 /// the template std::vector can be referred to via a variety of 1281 /// names---std::vector, ::std::vector, vector (if vector is in 1282 /// scope), etc.---but all of these names map down to the same 1283 /// TemplateDecl, which is used to form the canonical template name. 1284 /// 1285 /// Dependent template names are more interesting. Here, the 1286 /// template name could be something like T::template apply or 1287 /// std::allocator<T>::template rebind, where the nested name 1288 /// specifier itself is dependent. In this case, the canonical 1289 /// template name uses the shortest form of the dependent 1290 /// nested-name-specifier, which itself contains all canonical 1291 /// types, values, and templates. 1292 TemplateName getCanonicalTemplateName(TemplateName Name) const; 1293 1294 /// \brief Determine whether the given template names refer to the same 1295 /// template. 1296 bool hasSameTemplateName(TemplateName X, TemplateName Y); 1297 1298 /// \brief Retrieve the "canonical" template argument. 1299 /// 1300 /// The canonical template argument is the simplest template argument 1301 /// (which may be a type, value, expression, or declaration) that 1302 /// expresses the value of the argument. 1303 TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) 1304 const; 1305 1306 /// Type Query functions. If the type is an instance of the specified class, 1307 /// return the Type pointer for the underlying maximally pretty type. This 1308 /// is a member of ASTContext because this may need to do some amount of 1309 /// canonicalization, e.g. to move type qualifiers into the element type. 1310 const ArrayType *getAsArrayType(QualType T) const; 1311 const ConstantArrayType *getAsConstantArrayType(QualType T) const { 1312 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T)); 1313 } 1314 const VariableArrayType *getAsVariableArrayType(QualType T) const { 1315 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T)); 1316 } 1317 const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const { 1318 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T)); 1319 } 1320 const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) 1321 const { 1322 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T)); 1323 } 1324 1325 /// getBaseElementType - Returns the innermost element type of an array type. 1326 /// For example, will return "int" for int[m][n] 1327 QualType getBaseElementType(const ArrayType *VAT) const; 1328 1329 /// getBaseElementType - Returns the innermost element type of a type 1330 /// (which needn't actually be an array type). 1331 QualType getBaseElementType(QualType QT) const; 1332 1333 /// getConstantArrayElementCount - Returns number of constant array elements. 1334 uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const; 1335 1336 /// \brief Perform adjustment on the parameter type of a function. 1337 /// 1338 /// This routine adjusts the given parameter type @p T to the actual 1339 /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], 1340 /// C++ [dcl.fct]p3). The adjusted parameter type is returned. 1341 QualType getAdjustedParameterType(QualType T); 1342 1343 /// \brief Retrieve the parameter type as adjusted for use in the signature 1344 /// of a function, decaying array and function types and removing top-level 1345 /// cv-qualifiers. 1346 QualType getSignatureParameterType(QualType T); 1347 1348 /// getArrayDecayedType - Return the properly qualified result of decaying the 1349 /// specified array type to a pointer. This operation is non-trivial when 1350 /// handling typedefs etc. The canonical type of "T" must be an array type, 1351 /// this returns a pointer to a properly qualified element of the array. 1352 /// 1353 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 1354 QualType getArrayDecayedType(QualType T) const; 1355 1356 /// getPromotedIntegerType - Returns the type that Promotable will 1357 /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable 1358 /// integer type. 1359 QualType getPromotedIntegerType(QualType PromotableType) const; 1360 1361 /// \brief Recurses in pointer/array types until it finds an objc retainable 1362 /// type and returns its ownership. 1363 Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const; 1364 1365 /// \brief Whether this is a promotable bitfield reference according 1366 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 1367 /// 1368 /// \returns the type this bit-field will promote to, or NULL if no 1369 /// promotion occurs. 1370 QualType isPromotableBitField(Expr *E) const; 1371 1372 /// getIntegerTypeOrder - Returns the highest ranked integer type: 1373 /// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If 1374 /// LHS < RHS, return -1. 1375 int getIntegerTypeOrder(QualType LHS, QualType RHS) const; 1376 1377 /// getFloatingTypeOrder - Compare the rank of the two specified floating 1378 /// point types, ignoring the domain of the type (i.e. 'double' == 1379 /// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If 1380 /// LHS < RHS, return -1. 1381 int getFloatingTypeOrder(QualType LHS, QualType RHS) const; 1382 1383 /// getFloatingTypeOfSizeWithinDomain - Returns a real floating 1384 /// point or a complex type (based on typeDomain/typeSize). 1385 /// 'typeDomain' is a real floating point or complex type. 1386 /// 'typeSize' is a real floating point or complex type. 1387 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 1388 QualType typeDomain) const; 1389 1390 unsigned getTargetAddressSpace(QualType T) const { 1391 return getTargetAddressSpace(T.getQualifiers()); 1392 } 1393 1394 unsigned getTargetAddressSpace(Qualifiers Q) const { 1395 return getTargetAddressSpace(Q.getAddressSpace()); 1396 } 1397 1398 unsigned getTargetAddressSpace(unsigned AS) const { 1399 if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count) 1400 return AS; 1401 else 1402 return AddrSpaceMap[AS - LangAS::Offset]; 1403 } 1404 1405private: 1406 // Helper for integer ordering 1407 unsigned getIntegerRank(const Type *T) const; 1408 1409public: 1410 1411 //===--------------------------------------------------------------------===// 1412 // Type Compatibility Predicates 1413 //===--------------------------------------------------------------------===// 1414 1415 /// Compatibility predicates used to check assignment expressions. 1416 bool typesAreCompatible(QualType T1, QualType T2, 1417 bool CompareUnqualified = false); // C99 6.2.7p1 1418 1419 bool propertyTypesAreCompatible(QualType, QualType); 1420 bool typesAreBlockPointerCompatible(QualType, QualType); 1421 1422 bool isObjCIdType(QualType T) const { 1423 return T == getObjCIdType(); 1424 } 1425 bool isObjCClassType(QualType T) const { 1426 return T == ObjCClassTypedefType; 1427 } 1428 bool isObjCSelType(QualType T) const { 1429 return T == ObjCSelTypedefType; 1430 } 1431 bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS); 1432 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, 1433 bool ForCompare); 1434 1435 bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS); 1436 1437 // Check the safety of assignment from LHS to RHS 1438 bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 1439 const ObjCObjectPointerType *RHSOPT); 1440 bool canAssignObjCInterfaces(const ObjCObjectType *LHS, 1441 const ObjCObjectType *RHS); 1442 bool canAssignObjCInterfacesInBlockPointer( 1443 const ObjCObjectPointerType *LHSOPT, 1444 const ObjCObjectPointerType *RHSOPT, 1445 bool BlockReturnType); 1446 bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); 1447 QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, 1448 const ObjCObjectPointerType *RHSOPT); 1449 bool canBindObjCObjectType(QualType To, QualType From); 1450 1451 // Functions for calculating composite types 1452 QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, 1453 bool Unqualified = false, bool BlockReturnType = false); 1454 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, 1455 bool Unqualified = false); 1456 QualType mergeFunctionArgumentTypes(QualType, QualType, 1457 bool OfBlockPointer=false, 1458 bool Unqualified = false); 1459 QualType mergeTransparentUnionType(QualType, QualType, 1460 bool OfBlockPointer=false, 1461 bool Unqualified = false); 1462 1463 QualType mergeObjCGCQualifiers(QualType, QualType); 1464 1465 void ResetObjCLayout(const ObjCContainerDecl *CD) { 1466 ObjCLayouts[CD] = 0; 1467 } 1468 1469 //===--------------------------------------------------------------------===// 1470 // Integer Predicates 1471 //===--------------------------------------------------------------------===// 1472 1473 // The width of an integer, as defined in C99 6.2.6.2. This is the number 1474 // of bits in an integer type excluding any padding bits. 1475 unsigned getIntWidth(QualType T) const; 1476 1477 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding 1478 // unsigned integer type. This method takes a signed type, and returns the 1479 // corresponding unsigned integer type. 1480 QualType getCorrespondingUnsignedType(QualType T); 1481 1482 //===--------------------------------------------------------------------===// 1483 // Type Iterators. 1484 //===--------------------------------------------------------------------===// 1485 1486 typedef std::vector<Type*>::iterator type_iterator; 1487 typedef std::vector<Type*>::const_iterator const_type_iterator; 1488 1489 type_iterator types_begin() { return Types.begin(); } 1490 type_iterator types_end() { return Types.end(); } 1491 const_type_iterator types_begin() const { return Types.begin(); } 1492 const_type_iterator types_end() const { return Types.end(); } 1493 1494 //===--------------------------------------------------------------------===// 1495 // Integer Values 1496 //===--------------------------------------------------------------------===// 1497 1498 /// MakeIntValue - Make an APSInt of the appropriate width and 1499 /// signedness for the given \arg Value and integer \arg Type. 1500 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const { 1501 llvm::APSInt Res(getIntWidth(Type), 1502 !Type->isSignedIntegerOrEnumerationType()); 1503 Res = Value; 1504 return Res; 1505 } 1506 1507 /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists. 1508 ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D); 1509 /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists. 1510 ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); 1511 1512 /// \brief returns true if there is at lease one @implementation in TU. 1513 bool AnyObjCImplementation() { 1514 return !ObjCImpls.empty(); 1515 } 1516 1517 /// \brief Set the implementation of ObjCInterfaceDecl. 1518 void setObjCImplementation(ObjCInterfaceDecl *IFaceD, 1519 ObjCImplementationDecl *ImplD); 1520 /// \brief Set the implementation of ObjCCategoryDecl. 1521 void setObjCImplementation(ObjCCategoryDecl *CatD, 1522 ObjCCategoryImplDecl *ImplD); 1523 1524 /// \brief Set the copy inialization expression of a block var decl. 1525 void setBlockVarCopyInits(VarDecl*VD, Expr* Init); 1526 /// \brief Get the copy initialization expression of VarDecl,or NULL if 1527 /// none exists. 1528 Expr *getBlockVarCopyInits(const VarDecl*VD); 1529 1530 /// \brief Allocate an uninitialized TypeSourceInfo. 1531 /// 1532 /// The caller should initialize the memory held by TypeSourceInfo using 1533 /// the TypeLoc wrappers. 1534 /// 1535 /// \param T the type that will be the basis for type source info. This type 1536 /// should refer to how the declarator was written in source code, not to 1537 /// what type semantic analysis resolved the declarator to. 1538 /// 1539 /// \param Size the size of the type info to create, or 0 if the size 1540 /// should be calculated based on the type. 1541 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const; 1542 1543 /// \brief Allocate a TypeSourceInfo where all locations have been 1544 /// initialized to a given location, which defaults to the empty 1545 /// location. 1546 TypeSourceInfo * 1547 getTrivialTypeSourceInfo(QualType T, 1548 SourceLocation Loc = SourceLocation()) const; 1549 1550 TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; } 1551 1552 /// \brief Add a deallocation callback that will be invoked when the 1553 /// ASTContext is destroyed. 1554 /// 1555 /// \brief Callback A callback function that will be invoked on destruction. 1556 /// 1557 /// \brief Data Pointer data that will be provided to the callback function 1558 /// when it is called. 1559 void AddDeallocation(void (*Callback)(void*), void *Data); 1560 1561 GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD); 1562 GVALinkage GetGVALinkageForVariable(const VarDecl *VD); 1563 1564 /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH 1565 /// lazily, only when used; this is only relevant for function or file scoped 1566 /// var definitions. 1567 /// 1568 /// \returns true if the function/var must be CodeGen'ed/deserialized even if 1569 /// it is not used. 1570 bool DeclMustBeEmitted(const Decl *D); 1571 1572 //===--------------------------------------------------------------------===// 1573 // Statistics 1574 //===--------------------------------------------------------------------===// 1575 1576 /// \brief The number of implicitly-declared default constructors. 1577 static unsigned NumImplicitDefaultConstructors; 1578 1579 /// \brief The number of implicitly-declared default constructors for 1580 /// which declarations were built. 1581 static unsigned NumImplicitDefaultConstructorsDeclared; 1582 1583 /// \brief The number of implicitly-declared copy constructors. 1584 static unsigned NumImplicitCopyConstructors; 1585 1586 /// \brief The number of implicitly-declared copy constructors for 1587 /// which declarations were built. 1588 static unsigned NumImplicitCopyConstructorsDeclared; 1589 1590 /// \brief The number of implicitly-declared move constructors. 1591 static unsigned NumImplicitMoveConstructors; 1592 1593 /// \brief The number of implicitly-declared move constructors for 1594 /// which declarations were built. 1595 static unsigned NumImplicitMoveConstructorsDeclared; 1596 1597 /// \brief The number of implicitly-declared copy assignment operators. 1598 static unsigned NumImplicitCopyAssignmentOperators; 1599 1600 /// \brief The number of implicitly-declared copy assignment operators for 1601 /// which declarations were built. 1602 static unsigned NumImplicitCopyAssignmentOperatorsDeclared; 1603 1604 /// \brief The number of implicitly-declared move assignment operators. 1605 static unsigned NumImplicitMoveAssignmentOperators; 1606 1607 /// \brief The number of implicitly-declared move assignment operators for 1608 /// which declarations were built. 1609 static unsigned NumImplicitMoveAssignmentOperatorsDeclared; 1610 1611 /// \brief The number of implicitly-declared destructors. 1612 static unsigned NumImplicitDestructors; 1613 1614 /// \brief The number of implicitly-declared destructors for which 1615 /// declarations were built. 1616 static unsigned NumImplicitDestructorsDeclared; 1617 1618private: 1619 ASTContext(const ASTContext&); // DO NOT IMPLEMENT 1620 void operator=(const ASTContext&); // DO NOT IMPLEMENT 1621 1622 void InitBuiltinTypes(); 1623 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); 1624 1625 // Return the ObjC type encoding for a given type. 1626 void getObjCEncodingForTypeImpl(QualType t, std::string &S, 1627 bool ExpandPointedToStructures, 1628 bool ExpandStructures, 1629 const FieldDecl *Field, 1630 bool OutermostType = false, 1631 bool EncodingProperty = false, 1632 bool StructField = false) const; 1633 1634 // Adds the encoding of the structure's members. 1635 void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, 1636 const FieldDecl *Field, 1637 bool includeVBases = true) const; 1638 1639 const ASTRecordLayout & 1640 getObjCLayout(const ObjCInterfaceDecl *D, 1641 const ObjCImplementationDecl *Impl) const; 1642 1643private: 1644 /// \brief A set of deallocations that should be performed when the 1645 /// ASTContext is destroyed. 1646 SmallVector<std::pair<void (*)(void*), void *>, 16> Deallocations; 1647 1648 // FIXME: This currently contains the set of StoredDeclMaps used 1649 // by DeclContext objects. This probably should not be in ASTContext, 1650 // but we include it here so that ASTContext can quickly deallocate them. 1651 llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM; 1652 1653 /// \brief A counter used to uniquely identify "blocks". 1654 mutable unsigned int UniqueBlockByRefTypeID; 1655 1656 friend class DeclContext; 1657 friend class DeclarationNameTable; 1658 void ReleaseDeclContextMaps(); 1659}; 1660 1661/// @brief Utility function for constructing a nullary selector. 1662static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) { 1663 IdentifierInfo* II = &Ctx.Idents.get(name); 1664 return Ctx.Selectors.getSelector(0, &II); 1665} 1666 1667/// @brief Utility function for constructing an unary selector. 1668static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) { 1669 IdentifierInfo* II = &Ctx.Idents.get(name); 1670 return Ctx.Selectors.getSelector(1, &II); 1671} 1672 1673} // end namespace clang 1674 1675// operator new and delete aren't allowed inside namespaces. 1676// The throw specifications are mandated by the standard. 1677/// @brief Placement new for using the ASTContext's allocator. 1678/// 1679/// This placement form of operator new uses the ASTContext's allocator for 1680/// obtaining memory. It is a non-throwing new, which means that it returns 1681/// null on error. (If that is what the allocator does. The current does, so if 1682/// this ever changes, this operator will have to be changed, too.) 1683/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 1684/// @code 1685/// // Default alignment (8) 1686/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 1687/// // Specific alignment 1688/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments); 1689/// @endcode 1690/// Please note that you cannot use delete on the pointer; it must be 1691/// deallocated using an explicit destructor call followed by 1692/// @c Context.Deallocate(Ptr). 1693/// 1694/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 1695/// @param C The ASTContext that provides the allocator. 1696/// @param Alignment The alignment of the allocated memory (if the underlying 1697/// allocator supports it). 1698/// @return The allocated memory. Could be NULL. 1699inline void *operator new(size_t Bytes, const clang::ASTContext &C, 1700 size_t Alignment) throw () { 1701 return C.Allocate(Bytes, Alignment); 1702} 1703/// @brief Placement delete companion to the new above. 1704/// 1705/// This operator is just a companion to the new above. There is no way of 1706/// invoking it directly; see the new operator for more details. This operator 1707/// is called implicitly by the compiler if a placement new expression using 1708/// the ASTContext throws in the object constructor. 1709inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) 1710 throw () { 1711 C.Deallocate(Ptr); 1712} 1713 1714/// This placement form of operator new[] uses the ASTContext's allocator for 1715/// obtaining memory. It is a non-throwing new[], which means that it returns 1716/// null on error. 1717/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 1718/// @code 1719/// // Default alignment (8) 1720/// char *data = new (Context) char[10]; 1721/// // Specific alignment 1722/// char *data = new (Context, 4) char[10]; 1723/// @endcode 1724/// Please note that you cannot use delete on the pointer; it must be 1725/// deallocated using an explicit destructor call followed by 1726/// @c Context.Deallocate(Ptr). 1727/// 1728/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 1729/// @param C The ASTContext that provides the allocator. 1730/// @param Alignment The alignment of the allocated memory (if the underlying 1731/// allocator supports it). 1732/// @return The allocated memory. Could be NULL. 1733inline void *operator new[](size_t Bytes, const clang::ASTContext& C, 1734 size_t Alignment = 8) throw () { 1735 return C.Allocate(Bytes, Alignment); 1736} 1737 1738/// @brief Placement delete[] companion to the new[] above. 1739/// 1740/// This operator is just a companion to the new[] above. There is no way of 1741/// invoking it directly; see the new[] operator for more details. This operator 1742/// is called implicitly by the compiler if a placement new[] expression using 1743/// the ASTContext throws in the object constructor. 1744inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) 1745 throw () { 1746 C.Deallocate(Ptr); 1747} 1748 1749#endif 1750