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