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