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