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