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