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