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