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