1327952Sdim//===- ASTContext.h - Context to hold long-lived AST nodes ------*- C++ -*-===// 2193326Sed// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6193326Sed// 7193326Sed//===----------------------------------------------------------------------===// 8327952Sdim// 9243830Sdim/// \file 10341825Sdim/// Defines the clang::ASTContext interface. 11327952Sdim// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 15193326Sed#define LLVM_CLANG_AST_ASTCONTEXT_H 16193326Sed 17344779Sdim#include "clang/AST/ASTContextAllocate.h" 18249423Sdim#include "clang/AST/ASTTypeTraits.h" 19249423Sdim#include "clang/AST/CanonicalType.h" 20249423Sdim#include "clang/AST/CommentCommandTraits.h" 21341825Sdim#include "clang/AST/ComparisonCategories.h" 22249423Sdim#include "clang/AST/Decl.h" 23327952Sdim#include "clang/AST/DeclBase.h" 24314564Sdim#include "clang/AST/DeclarationName.h" 25276479Sdim#include "clang/AST/ExternalASTSource.h" 26249423Sdim#include "clang/AST/NestedNameSpecifier.h" 27249423Sdim#include "clang/AST/PrettyPrinter.h" 28249423Sdim#include "clang/AST/RawCommentList.h" 29314564Sdim#include "clang/AST/TemplateBase.h" 30249423Sdim#include "clang/AST/TemplateName.h" 31249423Sdim#include "clang/AST/Type.h" 32221345Sdim#include "clang/Basic/AddressSpaces.h" 33344779Sdim#include "clang/Basic/AttrKinds.h" 34193326Sed#include "clang/Basic/IdentifierTable.h" 35327952Sdim#include "clang/Basic/LLVM.h" 36193326Sed#include "clang/Basic/LangOptions.h" 37314564Sdim#include "clang/Basic/Linkage.h" 38198893Srdivacky#include "clang/Basic/OperatorKinds.h" 39206084Srdivacky#include "clang/Basic/PartialDiagnostic.h" 40280031Sdim#include "clang/Basic/SanitizerBlacklist.h" 41314564Sdim#include "clang/Basic/SourceLocation.h" 42314564Sdim#include "clang/Basic/Specifiers.h" 43327952Sdim#include "clang/Basic/TargetInfo.h" 44321369Sdim#include "clang/Basic/XRayLists.h" 45314564Sdim#include "llvm/ADT/APSInt.h" 46314564Sdim#include "llvm/ADT/ArrayRef.h" 47193326Sed#include "llvm/ADT/DenseMap.h" 48193326Sed#include "llvm/ADT/FoldingSet.h" 49221345Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h" 50309124Sdim#include "llvm/ADT/MapVector.h" 51314564Sdim#include "llvm/ADT/None.h" 52314564Sdim#include "llvm/ADT/Optional.h" 53314564Sdim#include "llvm/ADT/PointerIntPair.h" 54314564Sdim#include "llvm/ADT/PointerUnion.h" 55314564Sdim#include "llvm/ADT/SmallVector.h" 56314564Sdim#include "llvm/ADT/StringMap.h" 57314564Sdim#include "llvm/ADT/StringRef.h" 58327952Sdim#include "llvm/ADT/TinyPtrVector.h" 59327952Sdim#include "llvm/ADT/Triple.h" 60327952Sdim#include "llvm/ADT/iterator_range.h" 61314564Sdim#include "llvm/Support/AlignOf.h" 62193326Sed#include "llvm/Support/Allocator.h" 63314564Sdim#include "llvm/Support/Casting.h" 64314564Sdim#include "llvm/Support/Compiler.h" 65314564Sdim#include <cassert> 66314564Sdim#include <cstddef> 67314564Sdim#include <cstdint> 68314564Sdim#include <iterator> 69276479Sdim#include <memory> 70314564Sdim#include <string> 71321369Sdim#include <type_traits> 72314564Sdim#include <utility> 73193326Sed#include <vector> 74193326Sed 75193326Sednamespace llvm { 76193326Sed 77314564Sdimstruct fltSemantics; 78314564Sdim 79327952Sdim} // namespace llvm 80314564Sdim 81193326Sednamespace clang { 82198092Srdivacky 83344779Sdimclass APFixedPoint; 84327952Sdimclass APValue; 85314564Sdimclass ASTMutationListener; 86314564Sdimclass ASTRecordLayout; 87314564Sdimclass AtomicExpr; 88314564Sdimclass BlockExpr; 89327952Sdimclass BuiltinTemplateDecl; 90314564Sdimclass CharUnits; 91360784Sdimclass ConceptDecl; 92314564Sdimclass CXXABI; 93327952Sdimclass CXXConstructorDecl; 94327952Sdimclass CXXMethodDecl; 95327952Sdimclass CXXRecordDecl; 96314564Sdimclass DiagnosticsEngine; 97314564Sdimclass Expr; 98344779Sdimclass FixedPointSemantics; 99360784Sdimclass GlobalDecl; 100327952Sdimclass MangleContext; 101314564Sdimclass MangleNumberingContext; 102314564Sdimclass MaterializeTemporaryExpr; 103327952Sdimclass MemberSpecializationInfo; 104327952Sdimclass Module; 105327952Sdimclass ObjCCategoryDecl; 106327952Sdimclass ObjCCategoryImplDecl; 107327952Sdimclass ObjCContainerDecl; 108327952Sdimclass ObjCImplDecl; 109327952Sdimclass ObjCImplementationDecl; 110327952Sdimclass ObjCInterfaceDecl; 111314564Sdimclass ObjCIvarDecl; 112327952Sdimclass ObjCMethodDecl; 113314564Sdimclass ObjCPropertyDecl; 114327952Sdimclass ObjCPropertyImplDecl; 115327952Sdimclass ObjCProtocolDecl; 116327952Sdimclass ObjCTypeParamDecl; 117360784Sdimstruct ParsedTargetAttr; 118327952Sdimclass Preprocessor; 119327952Sdimclass Stmt; 120327952Sdimclass StoredDeclsMap; 121360784Sdimclass TargetAttr; 122327952Sdimclass TemplateDecl; 123327952Sdimclass TemplateParameterList; 124327952Sdimclass TemplateTemplateParmDecl; 125327952Sdimclass TemplateTypeParmDecl; 126314564Sdimclass UnresolvedSetIterator; 127314564Sdimclass UsingShadowDecl; 128327952Sdimclass VarTemplateDecl; 129314564Sdimclass VTableContextBase; 130360784Sdimstruct BlockVarCopyInit; 131198092Srdivacky 132314564Sdimnamespace Builtin { 133239462Sdim 134327952Sdimclass Context; 135280031Sdim 136327952Sdim} // namespace Builtin 137314564Sdim 138314564Sdimenum BuiltinTemplateKind : int; 139314564Sdim 140314564Sdimnamespace comments { 141314564Sdim 142327952Sdimclass FullComment; 143314564Sdim 144327952Sdim} // namespace comments 145314564Sdim 146360784Sdimnamespace interp { 147360784Sdim 148360784Sdimclass Context; 149360784Sdim 150360784Sdim} // namespace interp 151360784Sdim 152360784Sdimnamespace serialization { 153360784Sdimtemplate <class> class AbstractTypeReader; 154360784Sdim} // namespace serialization 155360784Sdim 156314564Sdimstruct TypeInfo { 157327952Sdim uint64_t Width = 0; 158327952Sdim unsigned Align = 0; 159314564Sdim bool AlignIsRequired : 1; 160314564Sdim 161327952Sdim TypeInfo() : AlignIsRequired(false) {} 162314564Sdim TypeInfo(uint64_t Width, unsigned Align, bool AlignIsRequired) 163314564Sdim : Width(Width), Align(Align), AlignIsRequired(AlignIsRequired) {} 164314564Sdim}; 165314564Sdim 166341825Sdim/// Holds long-lived AST nodes (such as types and decls) that can be 167243830Sdim/// referred to throughout the semantic analysis of a file. 168234353Sdimclass ASTContext : public RefCountedBase<ASTContext> { 169327952Sdim friend class NestedNameSpecifier; 170210299Sed 171249423Sdim mutable SmallVector<Type *, 0> Types; 172218893Sdim mutable llvm::FoldingSet<ExtQuals> ExtQualNodes; 173218893Sdim mutable llvm::FoldingSet<ComplexType> ComplexTypes; 174218893Sdim mutable llvm::FoldingSet<PointerType> PointerTypes; 175276479Sdim mutable llvm::FoldingSet<AdjustedType> AdjustedTypes; 176218893Sdim mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes; 177218893Sdim mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes; 178218893Sdim mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes; 179218893Sdim mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes; 180360784Sdim mutable llvm::ContextualFoldingSet<ConstantArrayType, ASTContext &> 181360784Sdim ConstantArrayTypes; 182218893Sdim mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes; 183218893Sdim mutable std::vector<VariableArrayType*> VariableArrayTypes; 184218893Sdim mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes; 185218893Sdim mutable llvm::FoldingSet<DependentSizedExtVectorType> 186218893Sdim DependentSizedExtVectorTypes; 187327952Sdim mutable llvm::FoldingSet<DependentAddressSpaceType> 188327952Sdim DependentAddressSpaceTypes; 189218893Sdim mutable llvm::FoldingSet<VectorType> VectorTypes; 190341825Sdim mutable llvm::FoldingSet<DependentVectorType> DependentVectorTypes; 191218893Sdim mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes; 192221345Sdim mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&> 193221345Sdim FunctionProtoTypes; 194218893Sdim mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes; 195218893Sdim mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes; 196218893Sdim mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes; 197314564Sdim mutable llvm::FoldingSet<ObjCTypeParamType> ObjCTypeParamTypes; 198218893Sdim mutable llvm::FoldingSet<SubstTemplateTypeParmType> 199218893Sdim SubstTemplateTypeParmTypes; 200218893Sdim mutable llvm::FoldingSet<SubstTemplateTypeParmPackType> 201218893Sdim SubstTemplateTypeParmPackTypes; 202218893Sdim mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&> 203210299Sed TemplateSpecializationTypes; 204218893Sdim mutable llvm::FoldingSet<ParenType> ParenTypes; 205218893Sdim mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes; 206218893Sdim mutable llvm::FoldingSet<DependentNameType> DependentNameTypes; 207218893Sdim mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType, 208218893Sdim ASTContext&> 209210299Sed DependentTemplateSpecializationTypes; 210218893Sdim llvm::FoldingSet<PackExpansionType> PackExpansionTypes; 211218893Sdim mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes; 212218893Sdim mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes; 213309124Sdim mutable llvm::FoldingSet<DependentUnaryTransformType> 214309124Sdim DependentUnaryTransformTypes; 215360784Sdim mutable llvm::ContextualFoldingSet<AutoType, ASTContext&> AutoTypes; 216321369Sdim mutable llvm::FoldingSet<DeducedTemplateSpecializationType> 217321369Sdim DeducedTemplateSpecializationTypes; 218226633Sdim mutable llvm::FoldingSet<AtomicType> AtomicTypes; 219218893Sdim llvm::FoldingSet<AttributedType> AttributedTypes; 220296417Sdim mutable llvm::FoldingSet<PipeType> PipeTypes; 221193326Sed 222218893Sdim mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames; 223218893Sdim mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames; 224321369Sdim mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage> 225224145Sdim SubstTemplateTemplateParms; 226224145Sdim mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage, 227321369Sdim ASTContext&> 228218893Sdim SubstTemplateTemplateParmPacks; 229321369Sdim 230341825Sdim /// The set of nested name specifiers. 231193326Sed /// 232193326Sed /// This set is managed by the NestedNameSpecifier class. 233218893Sdim mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers; 234327952Sdim mutable NestedNameSpecifier *GlobalNestedNameSpecifier = nullptr; 235193326Sed 236341825Sdim /// A cache mapping from RecordDecls to ASTRecordLayouts. 237243830Sdim /// 238243830Sdim /// This is lazily created. This is intentionally not serialized. 239218893Sdim mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> 240218893Sdim ASTRecordLayouts; 241218893Sdim mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> 242218893Sdim ObjCLayouts; 243193326Sed 244341825Sdim /// A cache from types to size and alignment information. 245327952Sdim using TypeInfoMap = llvm::DenseMap<const Type *, struct TypeInfo>; 246234353Sdim mutable TypeInfoMap MemoizedTypeInfo; 247234353Sdim 248341825Sdim /// A cache from types to unadjusted alignment information. Only ARM and 249341825Sdim /// AArch64 targets need this information, keeping it separate prevents 250341825Sdim /// imposing overhead on TypeInfo size. 251341825Sdim using UnadjustedAlignMap = llvm::DenseMap<const Type *, unsigned>; 252341825Sdim mutable UnadjustedAlignMap MemoizedUnadjustedAlign; 253341825Sdim 254341825Sdim /// A cache mapping from CXXRecordDecls to key functions. 255261991Sdim llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions; 256321369Sdim 257341825Sdim /// Mapping from ObjCContainers to their ObjCImplementations. 258198092Srdivacky llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; 259321369Sdim 260341825Sdim /// Mapping from ObjCMethod to its duplicate declaration in the same 261226633Sdim /// interface. 262226633Sdim llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls; 263198092Srdivacky 264344779Sdim /// Mapping from __block VarDecls to BlockVarCopyInit. 265344779Sdim llvm::DenseMap<const VarDecl *, BlockVarCopyInit> BlockVarCopyInits; 266321369Sdim 267353358Sdim /// Used to cleanups APValues stored in the AST. 268353358Sdim mutable llvm::SmallVector<APValue *, 0> APValueCleanups; 269353358Sdim 270353358Sdim /// A cache mapping a string value to a StringLiteral object with the same 271353358Sdim /// value. 272353358Sdim /// 273353358Sdim /// This is lazily created. This is intentionally not serialized. 274353358Sdim mutable llvm::StringMap<StringLiteral *> StringLiteralCache; 275353358Sdim 276341825Sdim /// Representation of a "canonical" template template parameter that 277210299Sed /// is used in canonical template names. 278210299Sed class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { 279210299Sed TemplateTemplateParmDecl *Parm; 280321369Sdim 281210299Sed public: 282321369Sdim CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm) 283327952Sdim : Parm(Parm) {} 284321369Sdim 285210299Sed TemplateTemplateParmDecl *getParam() const { return Parm; } 286321369Sdim 287360784Sdim void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &C) { 288360784Sdim Profile(ID, C, Parm); 289360784Sdim } 290321369Sdim 291321369Sdim static void Profile(llvm::FoldingSetNodeID &ID, 292360784Sdim const ASTContext &C, 293210299Sed TemplateTemplateParmDecl *Parm); 294210299Sed }; 295360784Sdim mutable llvm::ContextualFoldingSet<CanonicalTemplateTemplateParm, 296360784Sdim const ASTContext&> 297218893Sdim CanonTemplateTemplateParms; 298321369Sdim 299218893Sdim TemplateTemplateParmDecl * 300218893Sdim getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const; 301210299Sed 302341825Sdim /// The typedef for the __int128_t type. 303327952Sdim mutable TypedefDecl *Int128Decl = nullptr; 304210299Sed 305341825Sdim /// The typedef for the __uint128_t type. 306327952Sdim mutable TypedefDecl *UInt128Decl = nullptr; 307261991Sdim 308341825Sdim /// The typedef for the target specific predefined 309239462Sdim /// __builtin_va_list type. 310327952Sdim mutable TypedefDecl *BuiltinVaListDecl = nullptr; 311194613Sed 312296417Sdim /// The typedef for the predefined \c __builtin_ms_va_list type. 313327952Sdim mutable TypedefDecl *BuiltinMSVaListDecl = nullptr; 314296417Sdim 315341825Sdim /// The typedef for the predefined \c id type. 316327952Sdim mutable TypedefDecl *ObjCIdDecl = nullptr; 317321369Sdim 318341825Sdim /// The typedef for the predefined \c SEL type. 319327952Sdim mutable TypedefDecl *ObjCSelDecl = nullptr; 320198092Srdivacky 321341825Sdim /// The typedef for the predefined \c Class type. 322327952Sdim mutable TypedefDecl *ObjCClassDecl = nullptr; 323234353Sdim 324341825Sdim /// The typedef for the predefined \c Protocol class in Objective-C. 325327952Sdim mutable ObjCInterfaceDecl *ObjCProtocolClassDecl = nullptr; 326321369Sdim 327341825Sdim /// The typedef for the predefined 'BOOL' type. 328327952Sdim mutable TypedefDecl *BOOLDecl = nullptr; 329234353Sdim 330226633Sdim // Typedefs which may be provided defining the structure of Objective-C 331226633Sdim // pseudo-builtins 332226633Sdim QualType ObjCIdRedefinitionType; 333226633Sdim QualType ObjCClassRedefinitionType; 334226633Sdim QualType ObjCSelRedefinitionType; 335198092Srdivacky 336309124Sdim /// The identifier 'bool'. 337309124Sdim mutable IdentifierInfo *BoolName = nullptr; 338309124Sdim 339288943Sdim /// The identifier 'NSObject'. 340344779Sdim mutable IdentifierInfo *NSObjectName = nullptr; 341288943Sdim 342288943Sdim /// The identifier 'NSCopying'. 343288943Sdim IdentifierInfo *NSCopyingName = nullptr; 344288943Sdim 345296417Sdim /// The identifier '__make_integer_seq'. 346296417Sdim mutable IdentifierInfo *MakeIntegerSeqName = nullptr; 347296417Sdim 348309124Sdim /// The identifier '__type_pack_element'. 349309124Sdim mutable IdentifierInfo *TypePackElementName = nullptr; 350309124Sdim 351193326Sed QualType ObjCConstantStringType; 352327952Sdim mutable RecordDecl *CFConstantStringTagDecl = nullptr; 353327952Sdim mutable TypedefDecl *CFConstantStringTypeDecl = nullptr; 354309124Sdim 355249423Sdim mutable QualType ObjCSuperType; 356321369Sdim 357234353Sdim QualType ObjCNSStringType; 358193326Sed 359341825Sdim /// The typedef declaration for the Objective-C "instancetype" type. 360327952Sdim TypedefDecl *ObjCInstanceTypeDecl = nullptr; 361321369Sdim 362341825Sdim /// The type for the C FILE type. 363327952Sdim TypeDecl *FILEDecl = nullptr; 364198092Srdivacky 365341825Sdim /// The type for the C jmp_buf type. 366327952Sdim TypeDecl *jmp_bufDecl = nullptr; 367198092Srdivacky 368341825Sdim /// The type for the C sigjmp_buf type. 369327952Sdim TypeDecl *sigjmp_bufDecl = nullptr; 370198092Srdivacky 371341825Sdim /// The type for the C ucontext_t type. 372327952Sdim TypeDecl *ucontext_tDecl = nullptr; 373227737Sdim 374341825Sdim /// Type for the Block descriptor for Blocks CodeGen. 375226633Sdim /// 376226633Sdim /// Since this is only used for generation of debug info, it is not 377226633Sdim /// serialized. 378327952Sdim mutable RecordDecl *BlockDescriptorType = nullptr; 379198398Srdivacky 380341825Sdim /// Type for the Block descriptor for Blocks CodeGen. 381226633Sdim /// 382226633Sdim /// Since this is only used for generation of debug info, it is not 383226633Sdim /// serialized. 384327952Sdim mutable RecordDecl *BlockDescriptorExtendedType = nullptr; 385198398Srdivacky 386341825Sdim /// Declaration for the CUDA cudaConfigureCall function. 387327952Sdim FunctionDecl *cudaConfigureCallDecl = nullptr; 388218893Sdim 389341825Sdim /// Keeps track of all declaration attributes. 390194613Sed /// 391194613Sed /// Since so few decls have attrs, we keep them in a hash map instead of 392194613Sed /// wasting space in the Decl class. 393212904Sdim llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs; 394198092Srdivacky 395341825Sdim /// A mapping from non-redeclarable declarations in modules that were 396261991Sdim /// merged with other declarations to the canonical declaration that they were 397261991Sdim /// merged into. 398261991Sdim llvm::DenseMap<Decl*, Decl*> MergedDecls; 399261991Sdim 400341825Sdim /// A mapping from a defining declaration to a list of modules (other 401288943Sdim /// than the owning module of the declaration) that contain merged 402288943Sdim /// definitions of that entity. 403288943Sdim llvm::DenseMap<NamedDecl*, llvm::TinyPtrVector<Module*>> MergedDefModules; 404288943Sdim 405341825Sdim /// Initializers for a module, in order. Each Decl will be either 406314564Sdim /// something that has a semantic effect on startup (such as a variable with 407314564Sdim /// a non-constant initializer), or an ImportDecl (which recursively triggers 408314564Sdim /// initialization of another module). 409314564Sdim struct PerModuleInitializers { 410314564Sdim llvm::SmallVector<Decl*, 4> Initializers; 411314564Sdim llvm::SmallVector<uint32_t, 4> LazyInitializers; 412314564Sdim 413314564Sdim void resolve(ASTContext &Ctx); 414314564Sdim }; 415314564Sdim llvm::DenseMap<Module*, PerModuleInitializers*> ModuleInitializers; 416314564Sdim 417327952Sdim ASTContext &this_() { return *this; } 418327952Sdim 419261991Sdimpublic: 420341825Sdim /// A type synonym for the TemplateOrInstantiation mapping. 421327952Sdim using TemplateOrSpecializationInfo = 422327952Sdim llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *>; 423261991Sdim 424261991Sdimprivate: 425327952Sdim friend class ASTDeclReader; 426327952Sdim friend class ASTReader; 427327952Sdim friend class ASTWriter; 428360784Sdim template <class> friend class serialization::AbstractTypeReader; 429327952Sdim friend class CXXRecordDecl; 430327952Sdim 431341825Sdim /// A mapping to contain the template or declaration that 432261991Sdim /// a variable declaration describes or was instantiated from, 433261991Sdim /// respectively. 434198092Srdivacky /// 435261991Sdim /// For non-templates, this value will be NULL. For variable 436261991Sdim /// declarations that describe a variable template, this will be a 437261991Sdim /// pointer to a VarTemplateDecl. For static data members 438261991Sdim /// of class template specializations, this will be the 439261991Sdim /// MemberSpecializationInfo referring to the member variable that was 440261991Sdim /// instantiated or specialized. Thus, the mapping will keep track of 441261991Sdim /// the static data member templates from which static data members of 442261991Sdim /// class template specializations were instantiated. 443198092Srdivacky /// 444198092Srdivacky /// Given the following example: 445198092Srdivacky /// 446198092Srdivacky /// \code 447198092Srdivacky /// template<typename T> 448198092Srdivacky /// struct X { 449198092Srdivacky /// static T value; 450198092Srdivacky /// }; 451198092Srdivacky /// 452198092Srdivacky /// template<typename T> 453198092Srdivacky /// T X<T>::value = T(17); 454198092Srdivacky /// 455198092Srdivacky /// int *x = &X<int>::value; 456198092Srdivacky /// \endcode 457198092Srdivacky /// 458198092Srdivacky /// This mapping will contain an entry that maps from the VarDecl for 459198092Srdivacky /// X<int>::value to the corresponding VarDecl for X<T>::value (within the 460198092Srdivacky /// class template X) and will be marked TSK_ImplicitInstantiation. 461261991Sdim llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo> 462261991Sdim TemplateOrInstantiation; 463198092Srdivacky 464341825Sdim /// Keeps track of the declaration from which a using declaration was 465243830Sdim /// created during instantiation. 466198092Srdivacky /// 467314564Sdim /// The source and target declarations are always a UsingDecl, an 468314564Sdim /// UnresolvedUsingValueDecl, or an UnresolvedUsingTypenameDecl. 469243830Sdim /// 470198092Srdivacky /// For example: 471198092Srdivacky /// \code 472198092Srdivacky /// template<typename T> 473198092Srdivacky /// struct A { 474198092Srdivacky /// void f(); 475198092Srdivacky /// }; 476198092Srdivacky /// 477198092Srdivacky /// template<typename T> 478198092Srdivacky /// struct B : A<T> { 479198092Srdivacky /// using A<T>::f; 480198092Srdivacky /// }; 481198092Srdivacky /// 482198092Srdivacky /// template struct B<int>; 483198092Srdivacky /// \endcode 484198092Srdivacky /// 485198092Srdivacky /// This mapping will contain an entry that maps from the UsingDecl in 486198092Srdivacky /// B<int> to the UnresolvedUsingDecl in B<T>. 487314564Sdim llvm::DenseMap<NamedDecl *, NamedDecl *> InstantiatedFromUsingDecl; 488198092Srdivacky 489200583Srdivacky llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*> 490200583Srdivacky InstantiatedFromUsingShadowDecl; 491200583Srdivacky 492198092Srdivacky llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl; 493198092Srdivacky 494341825Sdim /// Mapping that stores the methods overridden by a given C++ 495204643Srdivacky /// member function. 496204643Srdivacky /// 497204643Srdivacky /// Since most C++ member functions aren't virtual and therefore 498204643Srdivacky /// don't override anything, we store the overridden functions in 499204643Srdivacky /// this map on the side rather than within the CXXMethodDecl structure. 500327952Sdim using CXXMethodVector = llvm::TinyPtrVector<const CXXMethodDecl *>; 501204643Srdivacky llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods; 502204643Srdivacky 503341825Sdim /// Mapping from each declaration context to its corresponding 504261991Sdim /// mangling numbering context (used for constructs like lambdas which 505261991Sdim /// need to be consistently numbered for the mangler). 506314564Sdim llvm::DenseMap<const DeclContext *, std::unique_ptr<MangleNumberingContext>> 507261991Sdim MangleNumberingContexts; 508360784Sdim llvm::DenseMap<const Decl *, std::unique_ptr<MangleNumberingContext>> 509360784Sdim ExtraMangleNumberingContexts; 510249423Sdim 511341825Sdim /// Side-table of mangling numbers for declarations which rarely 512261991Sdim /// need them (like static local vars). 513309124Sdim llvm::MapVector<const NamedDecl *, unsigned> MangleNumbers; 514309124Sdim llvm::MapVector<const VarDecl *, unsigned> StaticLocalNumbers; 515249423Sdim 516341825Sdim /// Mapping that stores parameterIndex values for ParmVarDecls when 517243830Sdim /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex. 518327952Sdim using ParameterIndexTable = llvm::DenseMap<const VarDecl *, unsigned>; 519321369Sdim ParameterIndexTable ParamIndices; 520321369Sdim 521327952Sdim ImportDecl *FirstLocalImport = nullptr; 522327952Sdim ImportDecl *LastLocalImport = nullptr; 523321369Sdim 524193326Sed TranslationUnitDecl *TUDecl; 525327952Sdim mutable ExternCContextDecl *ExternCContext = nullptr; 526327952Sdim mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr; 527327952Sdim mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr; 528193326Sed 529341825Sdim /// The associated SourceManager object. 530193326Sed SourceManager &SourceMgr; 531198092Srdivacky 532341825Sdim /// The language options used to create the AST associated with 533193326Sed /// this ASTContext object. 534226633Sdim LangOptions &LangOpts; 535193326Sed 536341825Sdim /// Blacklist object that is used by sanitizers to decide which 537280031Sdim /// entities should not be instrumented. 538280031Sdim std::unique_ptr<SanitizerBlacklist> SanitizerBL; 539280031Sdim 540341825Sdim /// Function filtering mechanism to determine whether a given function 541321369Sdim /// should be imbued with the XRay "always" or "never" attributes. 542321369Sdim std::unique_ptr<XRayFunctionFilter> XRayFilter; 543321369Sdim 544341825Sdim /// The allocator used to create AST objects. 545212904Sdim /// 546212904Sdim /// AST objects are never destructed; rather, all memory associated with the 547212904Sdim /// AST objects will be released when the ASTContext itself is destroyed. 548218893Sdim mutable llvm::BumpPtrAllocator BumpAlloc; 549198092Srdivacky 550341825Sdim /// Allocator for partial diagnostics. 551206084Srdivacky PartialDiagnostic::StorageAllocator DiagAllocator; 552212904Sdim 553341825Sdim /// The current C++ ABI. 554276479Sdim std::unique_ptr<CXXABI> ABI; 555212904Sdim CXXABI *createCXXABI(const TargetInfo &T); 556218893Sdim 557341825Sdim /// The logical -> physical address space map. 558327952Sdim const LangASMap *AddrSpaceMap = nullptr; 559221345Sdim 560341825Sdim /// Address space map mangling must be used with language specific 561261991Sdim /// address spaces (e.g. OpenCL/CUDA) 562261991Sdim bool AddrSpaceMapMangling; 563261991Sdim 564327952Sdim const TargetInfo *Target = nullptr; 565327952Sdim const TargetInfo *AuxTarget = nullptr; 566226633Sdim clang::PrintingPolicy PrintingPolicy; 567360784Sdim std::unique_ptr<interp::Context> InterpContext; 568321369Sdim 569360784Sdim ast_type_traits::TraversalKind Traversal = ast_type_traits::TK_AsIs; 570360784Sdim 571198092Srdivackypublic: 572360784Sdim ast_type_traits::TraversalKind getTraversalKind() const { return Traversal; } 573360784Sdim void setTraversalKind(ast_type_traits::TraversalKind TK) { Traversal = TK; } 574360784Sdim 575360784Sdim const Expr *traverseIgnored(const Expr *E) const; 576360784Sdim Expr *traverseIgnored(Expr *E) const; 577360784Sdim ast_type_traits::DynTypedNode 578360784Sdim traverseIgnored(const ast_type_traits::DynTypedNode &N) const; 579360784Sdim 580193326Sed IdentifierTable &Idents; 581193326Sed SelectorTable &Selectors; 582194179Sed Builtin::Context &BuiltinInfo; 583218893Sdim mutable DeclarationNameTable DeclarationNames; 584276479Sdim IntrusiveRefCntPtr<ExternalASTSource> ExternalSource; 585327952Sdim ASTMutationListener *Listener = nullptr; 586193326Sed 587360784Sdim /// Returns the clang bytecode interpreter context. 588360784Sdim interp::Context &getInterpContext(); 589360784Sdim 590296417Sdim /// Container for either a single DynTypedNode or for an ArrayRef to 591296417Sdim /// DynTypedNode. For use with ParentMap. 592296417Sdim class DynTypedNodeList { 593327952Sdim using DynTypedNode = ast_type_traits::DynTypedNode; 594327952Sdim 595296417Sdim llvm::AlignedCharArrayUnion<ast_type_traits::DynTypedNode, 596296417Sdim ArrayRef<DynTypedNode>> Storage; 597296417Sdim bool IsSingleNode; 598296417Sdim 599296417Sdim public: 600296417Sdim DynTypedNodeList(const DynTypedNode &N) : IsSingleNode(true) { 601296417Sdim new (Storage.buffer) DynTypedNode(N); 602296417Sdim } 603327952Sdim 604296417Sdim DynTypedNodeList(ArrayRef<DynTypedNode> A) : IsSingleNode(false) { 605296417Sdim new (Storage.buffer) ArrayRef<DynTypedNode>(A); 606296417Sdim } 607296417Sdim 608296417Sdim const ast_type_traits::DynTypedNode *begin() const { 609296417Sdim if (!IsSingleNode) 610296417Sdim return reinterpret_cast<const ArrayRef<DynTypedNode> *>(Storage.buffer) 611296417Sdim ->begin(); 612296417Sdim return reinterpret_cast<const DynTypedNode *>(Storage.buffer); 613296417Sdim } 614296417Sdim 615296417Sdim const ast_type_traits::DynTypedNode *end() const { 616296417Sdim if (!IsSingleNode) 617296417Sdim return reinterpret_cast<const ArrayRef<DynTypedNode> *>(Storage.buffer) 618296417Sdim ->end(); 619296417Sdim return reinterpret_cast<const DynTypedNode *>(Storage.buffer) + 1; 620296417Sdim } 621296417Sdim 622296417Sdim size_t size() const { return end() - begin(); } 623296417Sdim bool empty() const { return begin() == end(); } 624314564Sdim 625296417Sdim const DynTypedNode &operator[](size_t N) const { 626296417Sdim assert(N < size() && "Out of bounds!"); 627296417Sdim return *(begin() + N); 628296417Sdim } 629296417Sdim }; 630296417Sdim 631344779Sdim // A traversal scope limits the parts of the AST visible to certain analyses. 632344779Sdim // RecursiveASTVisitor::TraverseAST will only visit reachable nodes, and 633344779Sdim // getParents() will only observe reachable parent edges. 634344779Sdim // 635344779Sdim // The scope is defined by a set of "top-level" declarations. 636344779Sdim // Initially, it is the entire TU: {getTranslationUnitDecl()}. 637344779Sdim // Changing the scope clears the parent cache, which is expensive to rebuild. 638344779Sdim std::vector<Decl *> getTraversalScope() const { return TraversalScope; } 639344779Sdim void setTraversalScope(const std::vector<Decl *> &); 640344779Sdim 641344779Sdim /// Returns the parents of the given node (within the traversal scope). 642249423Sdim /// 643249423Sdim /// Note that this will lazily compute the parents of all nodes 644249423Sdim /// and store them for later retrieval. Thus, the first call is O(n) 645249423Sdim /// in the number of AST nodes. 646249423Sdim /// 647249423Sdim /// Caveats and FIXMEs: 648249423Sdim /// Calculating the parent map over all AST nodes will need to load the 649249423Sdim /// full AST. This can be undesirable in the case where the full AST is 650249423Sdim /// expensive to create (for example, when using precompiled header 651249423Sdim /// preambles). Thus, there are good opportunities for optimization here. 652249423Sdim /// One idea is to walk the given node downwards, looking for references 653249423Sdim /// to declaration contexts - once a declaration context is found, compute 654249423Sdim /// the parent map for the declaration context; if that can satisfy the 655249423Sdim /// request, loading the whole AST can be avoided. Note that this is made 656249423Sdim /// more complex by statements in templates having multiple parents - those 657249423Sdim /// problems can be solved by building closure over the templated parts of 658249423Sdim /// the AST, which also avoids touching large parts of the AST. 659249423Sdim /// Additionally, we will want to add an interface to already give a hint 660249423Sdim /// where to search for the parents, for example when looking at a statement 661249423Sdim /// inside a certain function. 662249423Sdim /// 663249423Sdim /// 'NodeT' can be one of Decl, Stmt, Type, TypeLoc, 664249423Sdim /// NestedNameSpecifier or NestedNameSpecifierLoc. 665296417Sdim template <typename NodeT> DynTypedNodeList getParents(const NodeT &Node) { 666249423Sdim return getParents(ast_type_traits::DynTypedNode::create(Node)); 667249423Sdim } 668249423Sdim 669296417Sdim DynTypedNodeList getParents(const ast_type_traits::DynTypedNode &Node); 670249423Sdim 671243830Sdim const clang::PrintingPolicy &getPrintingPolicy() const { 672243830Sdim return PrintingPolicy; 673243830Sdim } 674198092Srdivacky 675243830Sdim void setPrintingPolicy(const clang::PrintingPolicy &Policy) { 676226633Sdim PrintingPolicy = Policy; 677226633Sdim } 678321369Sdim 679193326Sed SourceManager& getSourceManager() { return SourceMgr; } 680193326Sed const SourceManager& getSourceManager() const { return SourceMgr; } 681239462Sdim 682239462Sdim llvm::BumpPtrAllocator &getAllocator() const { 683239462Sdim return BumpAlloc; 684239462Sdim } 685239462Sdim 686261991Sdim void *Allocate(size_t Size, unsigned Align = 8) const { 687212904Sdim return BumpAlloc.Allocate(Size, Align); 688193326Sed } 689296417Sdim template <typename T> T *Allocate(size_t Num = 1) const { 690314564Sdim return static_cast<T *>(Allocate(Num * sizeof(T), alignof(T))); 691296417Sdim } 692327952Sdim void Deallocate(void *Ptr) const {} 693321369Sdim 694221345Sdim /// Return the total amount of physical memory allocated for representing 695221345Sdim /// AST nodes and type information. 696221345Sdim size_t getASTAllocatedMemory() const { 697221345Sdim return BumpAlloc.getTotalMemory(); 698221345Sdim } 699327952Sdim 700221345Sdim /// Return the total memory used for various side tables. 701221345Sdim size_t getSideTableAllocatedMemory() const; 702321369Sdim 703206084Srdivacky PartialDiagnostic::StorageAllocator &getDiagAllocator() { 704206084Srdivacky return DiagAllocator; 705206084Srdivacky } 706206084Srdivacky 707226633Sdim const TargetInfo &getTargetInfo() const { return *Target; } 708296417Sdim const TargetInfo *getAuxTargetInfo() const { return AuxTarget; } 709296417Sdim 710261991Sdim /// getIntTypeForBitwidth - 711261991Sdim /// sets integer QualTy according to specified details: 712261991Sdim /// bitwidth, signed/unsigned. 713261991Sdim /// Returns empty type if there is no appropriate target types. 714261991Sdim QualType getIntTypeForBitwidth(unsigned DestWidth, 715261991Sdim unsigned Signed) const; 716327952Sdim 717261991Sdim /// getRealTypeForBitwidth - 718261991Sdim /// sets floating point QualTy according to specified bitwidth. 719261991Sdim /// Returns empty type if there is no appropriate target types. 720261991Sdim QualType getRealTypeForBitwidth(unsigned DestWidth) const; 721261991Sdim 722261991Sdim bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const; 723321369Sdim 724234353Sdim const LangOptions& getLangOpts() const { return LangOpts; } 725198092Srdivacky 726280031Sdim const SanitizerBlacklist &getSanitizerBlacklist() const { 727280031Sdim return *SanitizerBL; 728280031Sdim } 729280031Sdim 730321369Sdim const XRayFunctionFilter &getXRayFilter() const { 731321369Sdim return *XRayFilter; 732321369Sdim } 733321369Sdim 734226633Sdim DiagnosticsEngine &getDiagnostics() const; 735218893Sdim 736198092Srdivacky FullSourceLoc getFullLoc(SourceLocation Loc) const { 737193326Sed return FullSourceLoc(Loc,SourceMgr); 738193326Sed } 739193326Sed 740341825Sdim /// All comments in this translation unit. 741239462Sdim RawCommentList Comments; 742239462Sdim 743341825Sdim /// True if comments are already loaded from ExternalASTSource. 744327952Sdim mutable bool CommentsLoaded = false; 745239462Sdim 746360784Sdim /// Mapping from declaration to directly attached comment. 747360784Sdim /// 748360784Sdim /// Raw comments are owned by Comments list. This mapping is populated 749360784Sdim /// lazily. 750360784Sdim mutable llvm::DenseMap<const Decl *, const RawComment *> DeclRawComments; 751239462Sdim 752360784Sdim /// Mapping from canonical declaration to the first redeclaration in chain 753360784Sdim /// that has a comment attached. 754239462Sdim /// 755239462Sdim /// Raw comments are owned by Comments list. This mapping is populated 756239462Sdim /// lazily. 757360784Sdim mutable llvm::DenseMap<const Decl *, const Decl *> RedeclChainComments; 758239462Sdim 759360784Sdim /// Keeps track of redeclaration chains that don't have any comment attached. 760360784Sdim /// Mapping from canonical declaration to redeclaration chain that has no 761360784Sdim /// comments attached to any redeclaration. Specifically it's mapping to 762360784Sdim /// the last redeclaration we've checked. 763360784Sdim /// 764360784Sdim /// Shall not contain declarations that have comments attached to any 765360784Sdim /// redeclaration in their chain. 766360784Sdim mutable llvm::DenseMap<const Decl *, const Decl *> CommentlessRedeclChains; 767360784Sdim 768341825Sdim /// Mapping from declarations to parsed comments attached to any 769239462Sdim /// redeclaration. 770239462Sdim mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments; 771239462Sdim 772360784Sdim /// Attaches \p Comment to \p OriginalD and to its redeclaration chain 773360784Sdim /// and removes the redeclaration chain from the set of commentless chains. 774360784Sdim /// 775360784Sdim /// Don't do anything if a comment has already been attached to \p OriginalD 776360784Sdim /// or its redeclaration chain. 777360784Sdim void cacheRawCommentForDecl(const Decl &OriginalD, 778360784Sdim const RawComment &Comment) const; 779360784Sdim 780360784Sdim /// \returns searches \p CommentsInFile for doc comment for \p D. 781360784Sdim /// 782360784Sdim /// \p RepresentativeLocForDecl is used as a location for searching doc 783360784Sdim /// comments. \p CommentsInFile is a mapping offset -> comment of files in the 784360784Sdim /// same file where \p RepresentativeLocForDecl is. 785360784Sdim RawComment *getRawCommentForDeclNoCacheImpl( 786360784Sdim const Decl *D, const SourceLocation RepresentativeLocForDecl, 787360784Sdim const std::map<unsigned, RawComment *> &CommentsInFile) const; 788360784Sdim 789341825Sdim /// Return the documentation comment attached to a given declaration, 790239462Sdim /// without looking into cache. 791239462Sdim RawComment *getRawCommentForDeclNoCache(const Decl *D) const; 792239462Sdim 793239462Sdimpublic: 794239462Sdim RawCommentList &getRawCommentList() { 795239462Sdim return Comments; 796239462Sdim } 797239462Sdim 798239462Sdim void addComment(const RawComment &RC) { 799243830Sdim assert(LangOpts.RetainCommentsFromSystemHeaders || 800243830Sdim !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin())); 801341825Sdim Comments.addComment(RC, LangOpts.CommentOpts, BumpAlloc); 802239462Sdim } 803239462Sdim 804341825Sdim /// Return the documentation comment attached to a given declaration. 805327952Sdim /// Returns nullptr if no comment is attached. 806239462Sdim /// 807327952Sdim /// \param OriginalDecl if not nullptr, is set to declaration AST node that 808327952Sdim /// had the comment, if the comment we found comes from a redeclaration. 809276479Sdim const RawComment * 810276479Sdim getRawCommentForAnyRedecl(const Decl *D, 811276479Sdim const Decl **OriginalDecl = nullptr) const; 812239462Sdim 813360784Sdim /// Searches existing comments for doc comments that should be attached to \p 814360784Sdim /// Decls. If any doc comment is found, it is parsed. 815360784Sdim /// 816360784Sdim /// Requirement: All \p Decls are in the same file. 817360784Sdim /// 818360784Sdim /// If the last comment in the file is already attached we assume 819360784Sdim /// there are not comments left to be attached to \p Decls. 820360784Sdim void attachCommentsToJustParsedDecls(ArrayRef<Decl *> Decls, 821360784Sdim const Preprocessor *PP); 822360784Sdim 823239462Sdim /// Return parsed documentation comment attached to a given declaration. 824327952Sdim /// Returns nullptr if no comment is attached. 825243830Sdim /// 826327952Sdim /// \param PP the Preprocessor used with this TU. Could be nullptr if 827243830Sdim /// preprocessor is not available. 828243830Sdim comments::FullComment *getCommentForDecl(const Decl *D, 829243830Sdim const Preprocessor *PP) const; 830261991Sdim 831261991Sdim /// Return parsed documentation comment attached to a given declaration. 832327952Sdim /// Returns nullptr if no comment is attached. Does not look at any 833261991Sdim /// redeclarations of the declaration. 834261991Sdim comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const; 835261991Sdim 836243830Sdim comments::FullComment *cloneFullComment(comments::FullComment *FC, 837243830Sdim const Decl *D) const; 838239462Sdim 839243830Sdimprivate: 840243830Sdim mutable comments::CommandTraits CommentCommandTraits; 841243830Sdim 842341825Sdim /// Iterator that visits import declarations. 843276479Sdim class import_iterator { 844327952Sdim ImportDecl *Import = nullptr; 845276479Sdim 846276479Sdim public: 847327952Sdim using value_type = ImportDecl *; 848327952Sdim using reference = ImportDecl *; 849327952Sdim using pointer = ImportDecl *; 850327952Sdim using difference_type = int; 851327952Sdim using iterator_category = std::forward_iterator_tag; 852276479Sdim 853327952Sdim import_iterator() = default; 854276479Sdim explicit import_iterator(ImportDecl *Import) : Import(Import) {} 855276479Sdim 856276479Sdim reference operator*() const { return Import; } 857276479Sdim pointer operator->() const { return Import; } 858276479Sdim 859276479Sdim import_iterator &operator++() { 860276479Sdim Import = ASTContext::getNextLocalImport(Import); 861276479Sdim return *this; 862276479Sdim } 863276479Sdim 864276479Sdim import_iterator operator++(int) { 865276479Sdim import_iterator Other(*this); 866276479Sdim ++(*this); 867276479Sdim return Other; 868276479Sdim } 869276479Sdim 870276479Sdim friend bool operator==(import_iterator X, import_iterator Y) { 871276479Sdim return X.Import == Y.Import; 872276479Sdim } 873276479Sdim 874276479Sdim friend bool operator!=(import_iterator X, import_iterator Y) { 875276479Sdim return X.Import != Y.Import; 876276479Sdim } 877276479Sdim }; 878276479Sdim 879243830Sdimpublic: 880243830Sdim comments::CommandTraits &getCommentCommandTraits() const { 881243830Sdim return CommentCommandTraits; 882243830Sdim } 883243830Sdim 884341825Sdim /// Retrieve the attributes for the given declaration. 885212904Sdim AttrVec& getDeclAttrs(const Decl *D); 886198092Srdivacky 887341825Sdim /// Erase the attributes corresponding to the given declaration. 888212904Sdim void eraseDeclAttrs(const Decl *D); 889198092Srdivacky 890341825Sdim /// If this variable is an instantiated static data member of a 891198092Srdivacky /// class template specialization, returns the templated static data member 892198092Srdivacky /// from which it was instantiated. 893261991Sdim // FIXME: Remove ? 894198112Srdivacky MemberSpecializationInfo *getInstantiatedFromStaticDataMember( 895198112Srdivacky const VarDecl *Var); 896198092Srdivacky 897261991Sdim TemplateOrSpecializationInfo 898261991Sdim getTemplateOrSpecializationInfo(const VarDecl *Var); 899261991Sdim 900341825Sdim /// Note that the static data member \p Inst is an instantiation of 901198092Srdivacky /// the static data member template \p Tmpl of a class template. 902198092Srdivacky void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 903210299Sed TemplateSpecializationKind TSK, 904210299Sed SourceLocation PointOfInstantiation = SourceLocation()); 905198092Srdivacky 906261991Sdim void setTemplateOrSpecializationInfo(VarDecl *Inst, 907261991Sdim TemplateOrSpecializationInfo TSI); 908261991Sdim 909341825Sdim /// If the given using decl \p Inst is an instantiation of a 910200583Srdivacky /// (possibly unresolved) using decl from a template instantiation, 911198092Srdivacky /// return it. 912314564Sdim NamedDecl *getInstantiatedFromUsingDecl(NamedDecl *Inst); 913198092Srdivacky 914341825Sdim /// Remember that the using decl \p Inst is an instantiation 915200583Srdivacky /// of the using decl \p Pattern of a class template. 916314564Sdim void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern); 917198092Srdivacky 918200583Srdivacky void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 919200583Srdivacky UsingShadowDecl *Pattern); 920200583Srdivacky UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); 921198092Srdivacky 922198092Srdivacky FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field); 923198092Srdivacky 924198092Srdivacky void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl); 925321369Sdim 926204643Srdivacky // Access to the set of methods overridden by the given C++ method. 927327952Sdim using overridden_cxx_method_iterator = CXXMethodVector::const_iterator; 928204643Srdivacky overridden_cxx_method_iterator 929204643Srdivacky overridden_methods_begin(const CXXMethodDecl *Method) const; 930204643Srdivacky 931204643Srdivacky overridden_cxx_method_iterator 932204643Srdivacky overridden_methods_end(const CXXMethodDecl *Method) const; 933204643Srdivacky 934210299Sed unsigned overridden_methods_size(const CXXMethodDecl *Method) const; 935327952Sdim 936327952Sdim using overridden_method_range = 937327952Sdim llvm::iterator_range<overridden_cxx_method_iterator>; 938327952Sdim 939309124Sdim overridden_method_range overridden_methods(const CXXMethodDecl *Method) const; 940210299Sed 941341825Sdim /// Note that the given C++ \p Method overrides the given \p 942204643Srdivacky /// Overridden method. 943321369Sdim void addOverriddenMethod(const CXXMethodDecl *Method, 944204643Srdivacky const CXXMethodDecl *Overridden); 945243830Sdim 946341825Sdim /// Return C++ or ObjC overridden methods for the given \p Method. 947243830Sdim /// 948243830Sdim /// An ObjC method is considered to override any method in the class's 949243830Sdim /// base classes, its protocols, or its categories' protocols, that has 950243830Sdim /// the same selector and is of the same kind (class or instance). 951243830Sdim /// A method in an implementation is not considered as overriding the same 952243830Sdim /// method in the interface or its categories. 953243830Sdim void getOverriddenMethods( 954243830Sdim const NamedDecl *Method, 955243830Sdim SmallVectorImpl<const NamedDecl *> &Overridden) const; 956321369Sdim 957341825Sdim /// Notify the AST context that a new import declaration has been 958234353Sdim /// parsed or implicitly created within this translation unit. 959234353Sdim void addedLocalImportDecl(ImportDecl *Import); 960234353Sdim 961234353Sdim static ImportDecl *getNextLocalImport(ImportDecl *Import) { 962234353Sdim return Import->NextLocalImport; 963234353Sdim } 964321369Sdim 965327952Sdim using import_range = llvm::iterator_range<import_iterator>; 966327952Sdim 967276479Sdim import_range local_imports() const { 968276479Sdim return import_range(import_iterator(FirstLocalImport), import_iterator()); 969234353Sdim } 970261991Sdim 971261991Sdim Decl *getPrimaryMergedDecl(Decl *D) { 972261991Sdim Decl *Result = MergedDecls.lookup(D); 973261991Sdim return Result ? Result : D; 974261991Sdim } 975261991Sdim void setPrimaryMergedDecl(Decl *D, Decl *Primary) { 976261991Sdim MergedDecls[D] = Primary; 977261991Sdim } 978261991Sdim 979341825Sdim /// Note that the definition \p ND has been merged into module \p M, 980288943Sdim /// and should be visible whenever \p M is visible. 981288943Sdim void mergeDefinitionIntoModule(NamedDecl *ND, Module *M, 982288943Sdim bool NotifyListeners = true); 983327952Sdim 984341825Sdim /// Clean up the merged definition list. Call this if you might have 985288943Sdim /// added duplicates into the list. 986288943Sdim void deduplicateMergedDefinitonsFor(NamedDecl *ND); 987288943Sdim 988341825Sdim /// Get the additional modules in which the definition \p Def has 989288943Sdim /// been merged. 990321369Sdim ArrayRef<Module*> getModulesWithMergedDefinition(const NamedDecl *Def) { 991344779Sdim auto MergedIt = 992344779Sdim MergedDefModules.find(cast<NamedDecl>(Def->getCanonicalDecl())); 993288943Sdim if (MergedIt == MergedDefModules.end()) 994288943Sdim return None; 995288943Sdim return MergedIt->second; 996288943Sdim } 997288943Sdim 998314564Sdim /// Add a declaration to the list of declarations that are initialized 999314564Sdim /// for a module. This will typically be a global variable (with internal 1000314564Sdim /// linkage) that runs module initializers, such as the iostream initializer, 1001314564Sdim /// or an ImportDecl nominating another module that has initializers. 1002314564Sdim void addModuleInitializer(Module *M, Decl *Init); 1003314564Sdim 1004314564Sdim void addLazyModuleInitializers(Module *M, ArrayRef<uint32_t> IDs); 1005314564Sdim 1006314564Sdim /// Get the initializations to perform when importing a module, if any. 1007314564Sdim ArrayRef<Decl*> getModuleInitializers(Module *M); 1008314564Sdim 1009193326Sed TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } 1010193326Sed 1011288943Sdim ExternCContextDecl *getExternCContextDecl() const; 1012296417Sdim BuiltinTemplateDecl *getMakeIntegerSeqDecl() const; 1013309124Sdim BuiltinTemplateDecl *getTypePackElementDecl() const; 1014198092Srdivacky 1015193326Sed // Builtin Types. 1016198893Srdivacky CanQualType VoidTy; 1017198893Srdivacky CanQualType BoolTy; 1018198893Srdivacky CanQualType CharTy; 1019261991Sdim CanQualType WCharTy; // [C++ 3.9.1p5]. 1020261991Sdim CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99. 1021239462Sdim CanQualType WIntTy; // [C99 7.24.1], integer type unchanged by default promotions. 1022341825Sdim CanQualType Char8Ty; // [C++20 proposal] 1023198893Srdivacky CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99. 1024198893Srdivacky CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99. 1025198893Srdivacky CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty; 1026198893Srdivacky CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 1027198893Srdivacky CanQualType UnsignedLongLongTy, UnsignedInt128Ty; 1028309124Sdim CanQualType FloatTy, DoubleTy, LongDoubleTy, Float128Ty; 1029341825Sdim CanQualType ShortAccumTy, AccumTy, 1030341825Sdim LongAccumTy; // ISO/IEC JTC1 SC22 WG14 N1169 Extension 1031341825Sdim CanQualType UnsignedShortAccumTy, UnsignedAccumTy, UnsignedLongAccumTy; 1032341825Sdim CanQualType ShortFractTy, FractTy, LongFractTy; 1033341825Sdim CanQualType UnsignedShortFractTy, UnsignedFractTy, UnsignedLongFractTy; 1034341825Sdim CanQualType SatShortAccumTy, SatAccumTy, SatLongAccumTy; 1035341825Sdim CanQualType SatUnsignedShortAccumTy, SatUnsignedAccumTy, 1036341825Sdim SatUnsignedLongAccumTy; 1037341825Sdim CanQualType SatShortFractTy, SatFractTy, SatLongFractTy; 1038341825Sdim CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy, 1039341825Sdim SatUnsignedLongFractTy; 1040226633Sdim CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON 1041327952Sdim CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 1042198893Srdivacky CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 1043309124Sdim CanQualType Float128ComplexTy; 1044198893Srdivacky CanQualType VoidPtrTy, NullPtrTy; 1045221345Sdim CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy; 1046243830Sdim CanQualType BuiltinFnTy; 1047234353Sdim CanQualType PseudoObjectTy, ARCUnbridgedCastTy; 1048199990Srdivacky CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; 1049234353Sdim CanQualType ObjCBuiltinBoolTy; 1050309124Sdim#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 1051309124Sdim CanQualType SingletonId; 1052309124Sdim#include "clang/Basic/OpenCLImageTypes.def" 1053296417Sdim CanQualType OCLSamplerTy, OCLEventTy, OCLClkEventTy; 1054321369Sdim CanQualType OCLQueueTy, OCLReserveIDTy; 1055296417Sdim CanQualType OMPArraySectionTy; 1056344779Sdim#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 1057344779Sdim CanQualType Id##Ty; 1058344779Sdim#include "clang/Basic/OpenCLExtensionTypes.def" 1059360784Sdim#define SVE_TYPE(Name, Id, SingletonId) \ 1060360784Sdim CanQualType SingletonId; 1061360784Sdim#include "clang/Basic/AArch64SVEACLETypes.def" 1062193326Sed 1063221345Sdim // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. 1064221345Sdim mutable QualType AutoDeductTy; // Deduction against 'auto'. 1065221345Sdim mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'. 1066221345Sdim 1067296417Sdim // Decl used to help define __builtin_va_list for some targets. 1068296417Sdim // The decl is built when constructing 'BuiltinVaListDecl'. 1069296417Sdim mutable Decl *VaListTagDecl; 1070239462Sdim 1071276479Sdim ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents, 1072276479Sdim SelectorTable &sels, Builtin::Context &builtins); 1073314564Sdim ASTContext(const ASTContext &) = delete; 1074314564Sdim ASTContext &operator=(const ASTContext &) = delete; 1075193326Sed ~ASTContext(); 1076193326Sed 1077341825Sdim /// Attach an external AST source to the AST context. 1078193326Sed /// 1079193326Sed /// The external AST source provides the ability to load parts of 1080193326Sed /// the abstract syntax tree as needed from some external storage, 1081193326Sed /// e.g., a precompiled header. 1082276479Sdim void setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source); 1083193326Sed 1084341825Sdim /// Retrieve a pointer to the external AST source associated 1085193326Sed /// with this AST context, if any. 1086276479Sdim ExternalASTSource *getExternalSource() const { 1087276479Sdim return ExternalSource.get(); 1088276479Sdim } 1089193326Sed 1090341825Sdim /// Attach an AST mutation listener to the AST context. 1091218893Sdim /// 1092218893Sdim /// The AST mutation listener provides the ability to track modifications to 1093218893Sdim /// the abstract syntax tree entities committed after they were initially 1094218893Sdim /// created. 1095218893Sdim void setASTMutationListener(ASTMutationListener *Listener) { 1096218893Sdim this->Listener = Listener; 1097218893Sdim } 1098218893Sdim 1099341825Sdim /// Retrieve a pointer to the AST mutation listener associated 1100218893Sdim /// with this AST context, if any. 1101218893Sdim ASTMutationListener *getASTMutationListener() const { return Listener; } 1102218893Sdim 1103193326Sed void PrintStats() const; 1104249423Sdim const SmallVectorImpl<Type *>& getTypes() const { return Types; } 1105193326Sed 1106296417Sdim BuiltinTemplateDecl *buildBuiltinTemplateDecl(BuiltinTemplateKind BTK, 1107296417Sdim const IdentifierInfo *II) const; 1108296417Sdim 1109341825Sdim /// Create a new implicit TU-level CXXRecordDecl or RecordDecl 1110276479Sdim /// declaration. 1111276479Sdim RecordDecl *buildImplicitRecord(StringRef Name, 1112276479Sdim RecordDecl::TagKind TK = TTK_Struct) const; 1113276479Sdim 1114341825Sdim /// Create a new implicit TU-level typedef declaration. 1115276479Sdim TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const; 1116276479Sdim 1117341825Sdim /// Retrieve the declaration for the 128-bit signed integer type. 1118226633Sdim TypedefDecl *getInt128Decl() const; 1119226633Sdim 1120341825Sdim /// Retrieve the declaration for the 128-bit unsigned integer type. 1121226633Sdim TypedefDecl *getUInt128Decl() const; 1122261991Sdim 1123193326Sed //===--------------------------------------------------------------------===// 1124193326Sed // Type Constructors 1125193326Sed //===--------------------------------------------------------------------===// 1126198092Srdivacky 1127198092Srdivackyprivate: 1128341825Sdim /// Return a type with extended qualifiers. 1129218893Sdim QualType getExtQualType(const Type *Base, Qualifiers Quals) const; 1130198092Srdivacky 1131218893Sdim QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const; 1132204962Srdivacky 1133314564Sdim QualType getPipeType(QualType T, bool ReadOnly) const; 1134314564Sdim 1135198092Srdivackypublic: 1136341825Sdim /// Return the uniqued reference to the type for an address space 1137243830Sdim /// qualified type with the specified type and address space. 1138243830Sdim /// 1139198092Srdivacky /// The resulting type has a union of the qualifiers from T and the address 1140198092Srdivacky /// space. If T already has an address space specifier, it is silently 1141193326Sed /// replaced. 1142327952Sdim QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const; 1143198092Srdivacky 1144341825Sdim /// Remove any existing address space on the type and returns the type 1145327952Sdim /// with qualifiers intact (or that's the idea anyway) 1146327952Sdim /// 1147327952Sdim /// The return type should be T with all prior qualifiers minus the address 1148327952Sdim /// space. 1149327952Sdim QualType removeAddrSpaceQualType(QualType T) const; 1150327952Sdim 1151341825Sdim /// Apply Objective-C protocol qualifiers to the given type. 1152314564Sdim /// \param allowOnPointerType specifies if we can apply protocol 1153314564Sdim /// qualifiers on ObjCObjectPointerType. It can be set to true when 1154341825Sdim /// constructing the canonical type of a Objective-C type parameter. 1155314564Sdim QualType applyObjCProtocolQualifiers(QualType type, 1156314564Sdim ArrayRef<ObjCProtocolDecl *> protocols, bool &hasError, 1157314564Sdim bool allowOnPointerType = false) const; 1158314564Sdim 1159341825Sdim /// Return the uniqued reference to the type for an Objective-C 1160243830Sdim /// gc-qualified type. 1161243830Sdim /// 1162341825Sdim /// The resulting type has a union of the qualifiers from T and the gc 1163243830Sdim /// attribute. 1164218893Sdim QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const; 1165198092Srdivacky 1166360784Sdim /// Remove the existing address space on the type if it is a pointer size 1167360784Sdim /// address space and return the type with qualifiers intact. 1168360784Sdim QualType removePtrSizeAddrSpace(QualType T) const; 1169360784Sdim 1170341825Sdim /// Return the uniqued reference to the type for a \c restrict 1171243830Sdim /// qualified type. 1172243830Sdim /// 1173243830Sdim /// The resulting type has a union of the qualifiers from \p T and 1174243830Sdim /// \c restrict. 1175218893Sdim QualType getRestrictType(QualType T) const { 1176198092Srdivacky return T.withFastQualifiers(Qualifiers::Restrict); 1177198092Srdivacky } 1178198092Srdivacky 1179341825Sdim /// Return the uniqued reference to the type for a \c volatile 1180243830Sdim /// qualified type. 1181243830Sdim /// 1182243830Sdim /// The resulting type has a union of the qualifiers from \p T and 1183243830Sdim /// \c volatile. 1184218893Sdim QualType getVolatileType(QualType T) const { 1185218893Sdim return T.withFastQualifiers(Qualifiers::Volatile); 1186218893Sdim } 1187198092Srdivacky 1188341825Sdim /// Return the uniqued reference to the type for a \c const 1189243830Sdim /// qualified type. 1190198092Srdivacky /// 1191243830Sdim /// The resulting type has a union of the qualifiers from \p T and \c const. 1192243830Sdim /// 1193243830Sdim /// It can be reasonably expected that this will always be equivalent to 1194243830Sdim /// calling T.withConst(). 1195218893Sdim QualType getConstType(QualType T) const { return T.withConst(); } 1196198092Srdivacky 1197341825Sdim /// Change the ExtInfo on a function type. 1198218893Sdim const FunctionType *adjustFunctionType(const FunctionType *Fn, 1199218893Sdim FunctionType::ExtInfo EInfo); 1200198092Srdivacky 1201296417Sdim /// Adjust the given function result type. 1202296417Sdim CanQualType getCanonicalFunctionResultType(QualType ResultType) const; 1203296417Sdim 1204341825Sdim /// Change the result type of a function type once it is deduced. 1205251662Sdim void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType); 1206251662Sdim 1207341825Sdim /// Get a function type and produce the equivalent function type with the 1208341825Sdim /// specified exception specification. Type sugar that can be present on a 1209341825Sdim /// declaration of a function with an exception specification is permitted 1210341825Sdim /// and preserved. Other type sugar (for instance, typedefs) is not. 1211341825Sdim QualType getFunctionTypeWithExceptionSpec( 1212341825Sdim QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI); 1213341825Sdim 1214341825Sdim /// Determine whether two function types are the same, ignoring 1215314564Sdim /// exception specifications in cases where they're part of the type. 1216314564Sdim bool hasSameFunctionTypeIgnoringExceptionSpec(QualType T, QualType U); 1217314564Sdim 1218341825Sdim /// Change the exception specification on a function once it is 1219280031Sdim /// delay-parsed, instantiated, or computed. 1220280031Sdim void adjustExceptionSpec(FunctionDecl *FD, 1221280031Sdim const FunctionProtoType::ExceptionSpecInfo &ESI, 1222280031Sdim bool AsWritten = false); 1223280031Sdim 1224360784Sdim /// Get a function type and produce the equivalent function type where 1225360784Sdim /// pointer size address spaces in the return type and parameter tyeps are 1226360784Sdim /// replaced with the default address space. 1227360784Sdim QualType getFunctionTypeWithoutPtrSizes(QualType T); 1228360784Sdim 1229360784Sdim /// Determine whether two function types are the same, ignoring pointer sizes 1230360784Sdim /// in the return type and parameter types. 1231360784Sdim bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U); 1232360784Sdim 1233341825Sdim /// Return the uniqued reference to the type for a complex 1234193326Sed /// number with the specified element type. 1235218893Sdim QualType getComplexType(QualType T) const; 1236218893Sdim CanQualType getComplexType(CanQualType T) const { 1237198893Srdivacky return CanQualType::CreateUnsafe(getComplexType((QualType) T)); 1238198893Srdivacky } 1239198092Srdivacky 1240341825Sdim /// Return the uniqued reference to the type for a pointer to 1241193326Sed /// the specified type. 1242218893Sdim QualType getPointerType(QualType T) const; 1243218893Sdim CanQualType getPointerType(CanQualType T) const { 1244198893Srdivacky return CanQualType::CreateUnsafe(getPointerType((QualType) T)); 1245198893Srdivacky } 1246193326Sed 1247341825Sdim /// Return the uniqued reference to a type adjusted from the original 1248276479Sdim /// type to a new type. 1249276479Sdim QualType getAdjustedType(QualType Orig, QualType New) const; 1250276479Sdim CanQualType getAdjustedType(CanQualType Orig, CanQualType New) const { 1251276479Sdim return CanQualType::CreateUnsafe( 1252276479Sdim getAdjustedType((QualType)Orig, (QualType)New)); 1253276479Sdim } 1254276479Sdim 1255341825Sdim /// Return the uniqued reference to the decayed version of the given 1256261991Sdim /// type. Can only be called on array and function types which decay to 1257261991Sdim /// pointer types. 1258261991Sdim QualType getDecayedType(QualType T) const; 1259261991Sdim CanQualType getDecayedType(CanQualType T) const { 1260261991Sdim return CanQualType::CreateUnsafe(getDecayedType((QualType) T)); 1261261991Sdim } 1262261991Sdim 1263341825Sdim /// Return the uniqued reference to the atomic type for the specified 1264243830Sdim /// type. 1265226633Sdim QualType getAtomicType(QualType T) const; 1266226633Sdim 1267341825Sdim /// Return the uniqued reference to the type for a block of the 1268243830Sdim /// specified type. 1269218893Sdim QualType getBlockPointerType(QualType T) const; 1270193326Sed 1271243830Sdim /// Gets the struct used to keep track of the descriptor for pointer to 1272198398Srdivacky /// blocks. 1273218893Sdim QualType getBlockDescriptorType() const; 1274198398Srdivacky 1275341825Sdim /// Return a read_only pipe type for the specified type. 1276314564Sdim QualType getReadPipeType(QualType T) const; 1277327952Sdim 1278341825Sdim /// Return a write_only pipe type for the specified type. 1279314564Sdim QualType getWritePipeType(QualType T) const; 1280296417Sdim 1281243830Sdim /// Gets the struct used to keep track of the extended descriptor for 1282198398Srdivacky /// pointer to blocks. 1283218893Sdim QualType getBlockDescriptorExtendedType() const; 1284198398Srdivacky 1285327952Sdim /// Map an AST Type to an OpenCLTypeKind enum value. 1286327952Sdim TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const; 1287327952Sdim 1288327952Sdim /// Get address space for OpenCL type. 1289327952Sdim LangAS getOpenCLTypeAddrSpace(const Type *T) const; 1290327952Sdim 1291218893Sdim void setcudaConfigureCallDecl(FunctionDecl *FD) { 1292218893Sdim cudaConfigureCallDecl = FD; 1293218893Sdim } 1294327952Sdim 1295218893Sdim FunctionDecl *getcudaConfigureCallDecl() { 1296218893Sdim return cudaConfigureCallDecl; 1297218893Sdim } 1298218893Sdim 1299198398Srdivacky /// Returns true iff we need copy/dispose helpers for the given type. 1300249423Sdim bool BlockRequiresCopying(QualType Ty, const VarDecl *D); 1301321369Sdim 1302341825Sdim /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout 1303341825Sdim /// is set to false in this case. If HasByrefExtendedLayout returns true, 1304341825Sdim /// byref variable has extended lifetime. 1305249423Sdim bool getByrefLifetime(QualType Ty, 1306249423Sdim Qualifiers::ObjCLifetime &Lifetime, 1307249423Sdim bool &HasByrefExtendedLayout) const; 1308321369Sdim 1309341825Sdim /// Return the uniqued reference to the type for an lvalue reference 1310243830Sdim /// to the specified type. 1311218893Sdim QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true) 1312218893Sdim const; 1313193326Sed 1314341825Sdim /// Return the uniqued reference to the type for an rvalue reference 1315243830Sdim /// to the specified type. 1316218893Sdim QualType getRValueReferenceType(QualType T) const; 1317193326Sed 1318341825Sdim /// Return the uniqued reference to the type for a member pointer to 1319243830Sdim /// the specified type in the specified class. 1320243830Sdim /// 1321243830Sdim /// The class \p Cls is a \c Type because it could be a dependent name. 1322218893Sdim QualType getMemberPointerType(QualType T, const Type *Cls) const; 1323193326Sed 1324341825Sdim /// Return a non-unique reference to the type for a variable array of 1325243830Sdim /// the specified element type. 1326193326Sed QualType getVariableArrayType(QualType EltTy, Expr *NumElts, 1327193326Sed ArrayType::ArraySizeModifier ASM, 1328218893Sdim unsigned IndexTypeQuals, 1329218893Sdim SourceRange Brackets) const; 1330198092Srdivacky 1331341825Sdim /// Return a non-unique reference to the type for a dependently-sized 1332243830Sdim /// array of the specified element type. 1333243830Sdim /// 1334243830Sdim /// FIXME: We will need these to be uniqued, or at least comparable, at some 1335243830Sdim /// point. 1336193326Sed QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, 1337193326Sed ArrayType::ArraySizeModifier ASM, 1338218893Sdim unsigned IndexTypeQuals, 1339218893Sdim SourceRange Brackets) const; 1340193326Sed 1341341825Sdim /// Return a unique reference to the type for an incomplete array of 1342243830Sdim /// the specified element type. 1343193326Sed QualType getIncompleteArrayType(QualType EltTy, 1344193326Sed ArrayType::ArraySizeModifier ASM, 1345218893Sdim unsigned IndexTypeQuals) const; 1346193326Sed 1347341825Sdim /// Return the unique reference to the type for a constant array of 1348243830Sdim /// the specified element type. 1349193326Sed QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, 1350360784Sdim const Expr *SizeExpr, 1351193326Sed ArrayType::ArraySizeModifier ASM, 1352218893Sdim unsigned IndexTypeQuals) const; 1353321369Sdim 1354353358Sdim /// Return a type for a constant array for a string literal of the 1355353358Sdim /// specified element type and length. 1356353358Sdim QualType getStringLiteralArrayType(QualType EltTy, unsigned Length) const; 1357353358Sdim 1358341825Sdim /// Returns a vla type where known sizes are replaced with [*]. 1359218893Sdim QualType getVariableArrayDecayedType(QualType Ty) const; 1360198092Srdivacky 1361341825Sdim /// Return the unique reference to a vector type of the specified 1362243830Sdim /// element type and size. 1363243830Sdim /// 1364243830Sdim /// \pre \p VectorType must be a built-in type. 1365203955Srdivacky QualType getVectorType(QualType VectorType, unsigned NumElts, 1366218893Sdim VectorType::VectorKind VecKind) const; 1367341825Sdim /// Return the unique reference to the type for a dependently sized vector of 1368341825Sdim /// the specified element type. 1369341825Sdim QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr, 1370341825Sdim SourceLocation AttrLoc, 1371341825Sdim VectorType::VectorKind VecKind) const; 1372193326Sed 1373341825Sdim /// Return the unique reference to an extended vector type 1374243830Sdim /// of the specified element type and size. 1375243830Sdim /// 1376243830Sdim /// \pre \p VectorType must be a built-in type. 1377218893Sdim QualType getExtVectorType(QualType VectorType, unsigned NumElts) const; 1378193326Sed 1379243830Sdim /// \pre Return a non-unique reference to the type for a dependently-sized 1380243830Sdim /// vector of the specified element type. 1381243830Sdim /// 1382243830Sdim /// FIXME: We will need these to be uniqued, or at least comparable, at some 1383243830Sdim /// point. 1384198092Srdivacky QualType getDependentSizedExtVectorType(QualType VectorType, 1385194613Sed Expr *SizeExpr, 1386218893Sdim SourceLocation AttrLoc) const; 1387194613Sed 1388327952Sdim QualType getDependentAddressSpaceType(QualType PointeeType, 1389327952Sdim Expr *AddrSpaceExpr, 1390327952Sdim SourceLocation AttrLoc) const; 1391327952Sdim 1392341825Sdim /// Return a K&R style C function type like 'int()'. 1393206084Srdivacky QualType getFunctionNoProtoType(QualType ResultTy, 1394218893Sdim const FunctionType::ExtInfo &Info) const; 1395193326Sed 1396218893Sdim QualType getFunctionNoProtoType(QualType ResultTy) const { 1397206084Srdivacky return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo()); 1398206084Srdivacky } 1399206084Srdivacky 1400341825Sdim /// Return a normal function type with a typed argument list. 1401249423Sdim QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args, 1402314564Sdim const FunctionProtoType::ExtProtoInfo &EPI) const { 1403314564Sdim return getFunctionTypeInternal(ResultTy, Args, EPI, false); 1404314564Sdim } 1405193326Sed 1406341825Sdim QualType adjustStringLiteralBaseType(QualType StrLTy) const; 1407341825Sdim 1408314564Sdimprivate: 1409341825Sdim /// Return a normal function type with a typed argument list. 1410314564Sdim QualType getFunctionTypeInternal(QualType ResultTy, ArrayRef<QualType> Args, 1411314564Sdim const FunctionProtoType::ExtProtoInfo &EPI, 1412314564Sdim bool OnlyWantCanonical) const; 1413314564Sdim 1414314564Sdimpublic: 1415341825Sdim /// Return the unique reference to the type for the specified type 1416243830Sdim /// declaration. 1417204962Srdivacky QualType getTypeDeclType(const TypeDecl *Decl, 1418276479Sdim const TypeDecl *PrevDecl = nullptr) const { 1419204962Srdivacky assert(Decl && "Passed null for Decl param"); 1420204962Srdivacky if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 1421193326Sed 1422204962Srdivacky if (PrevDecl) { 1423204962Srdivacky assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 1424204962Srdivacky Decl->TypeForDecl = PrevDecl->TypeForDecl; 1425204962Srdivacky return QualType(PrevDecl->TypeForDecl, 0); 1426204962Srdivacky } 1427204962Srdivacky 1428204962Srdivacky return getTypeDeclTypeSlow(Decl); 1429204962Srdivacky } 1430204962Srdivacky 1431341825Sdim /// Return the unique reference to the type for the specified 1432243830Sdim /// typedef-name decl. 1433221345Sdim QualType getTypedefType(const TypedefNameDecl *Decl, 1434221345Sdim QualType Canon = QualType()) const; 1435193326Sed 1436218893Sdim QualType getRecordType(const RecordDecl *Decl) const; 1437210299Sed 1438218893Sdim QualType getEnumType(const EnumDecl *Decl) const; 1439210299Sed 1440218893Sdim QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; 1441204962Srdivacky 1442344779Sdim QualType getAttributedType(attr::Kind attrKind, 1443218893Sdim QualType modifiedType, 1444218893Sdim QualType equivalentType); 1445218893Sdim 1446198398Srdivacky QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, 1447218893Sdim QualType Replacement) const; 1448218893Sdim QualType getSubstTemplateTypeParmPackType( 1449218893Sdim const TemplateTypeParmType *Replaced, 1450218893Sdim const TemplateArgument &ArgPack); 1451198398Srdivacky 1452276479Sdim QualType 1453276479Sdim getTemplateTypeParmType(unsigned Depth, unsigned Index, 1454276479Sdim bool ParameterPack, 1455276479Sdim TemplateTypeParmDecl *ParmDecl = nullptr) const; 1456193326Sed 1457193326Sed QualType getTemplateSpecializationType(TemplateName T, 1458309124Sdim ArrayRef<TemplateArgument> Args, 1459218893Sdim QualType Canon = QualType()) const; 1460193326Sed 1461309124Sdim QualType 1462309124Sdim getCanonicalTemplateSpecializationType(TemplateName T, 1463309124Sdim ArrayRef<TemplateArgument> Args) const; 1464210299Sed 1465198893Srdivacky QualType getTemplateSpecializationType(TemplateName T, 1466199990Srdivacky const TemplateArgumentListInfo &Args, 1467218893Sdim QualType Canon = QualType()) const; 1468198893Srdivacky 1469204962Srdivacky TypeSourceInfo * 1470204962Srdivacky getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc, 1471204962Srdivacky const TemplateArgumentListInfo &Args, 1472218893Sdim QualType Canon = QualType()) const; 1473204962Srdivacky 1474218893Sdim QualType getParenType(QualType NamedType) const; 1475218893Sdim 1476353358Sdim QualType getMacroQualifiedType(QualType UnderlyingTy, 1477353358Sdim const IdentifierInfo *MacroII) const; 1478353358Sdim 1479208600Srdivacky QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 1480341825Sdim NestedNameSpecifier *NNS, QualType NamedType, 1481341825Sdim TagDecl *OwnedTagDecl = nullptr) const; 1482206084Srdivacky QualType getDependentNameType(ElaboratedTypeKeyword Keyword, 1483206084Srdivacky NestedNameSpecifier *NNS, 1484206084Srdivacky const IdentifierInfo *Name, 1485218893Sdim QualType Canon = QualType()) const; 1486193326Sed 1487210299Sed QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 1488210299Sed NestedNameSpecifier *NNS, 1489210299Sed const IdentifierInfo *Name, 1490218893Sdim const TemplateArgumentListInfo &Args) const; 1491309124Sdim QualType getDependentTemplateSpecializationType( 1492309124Sdim ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, 1493309124Sdim const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args) const; 1494210299Sed 1495321369Sdim TemplateArgument getInjectedTemplateArg(NamedDecl *ParamDecl); 1496321369Sdim 1497314564Sdim /// Get a template argument list with one argument per template parameter 1498314564Sdim /// in a template parameter list, such as for the injected class name of 1499314564Sdim /// a class template. 1500314564Sdim void getInjectedTemplateArgs(const TemplateParameterList *Params, 1501314564Sdim SmallVectorImpl<TemplateArgument> &Args); 1502314564Sdim 1503218893Sdim QualType getPackExpansionType(QualType Pattern, 1504249423Sdim Optional<unsigned> NumExpansions); 1505198092Srdivacky 1506234353Sdim QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 1507276479Sdim ObjCInterfaceDecl *PrevDecl = nullptr) const; 1508218893Sdim 1509288943Sdim /// Legacy interface: cannot provide type arguments or __kindof. 1510208600Srdivacky QualType getObjCObjectType(QualType Base, 1511208600Srdivacky ObjCProtocolDecl * const *Protocols, 1512218893Sdim unsigned NumProtocols) const; 1513288943Sdim 1514288943Sdim QualType getObjCObjectType(QualType Base, 1515288943Sdim ArrayRef<QualType> typeArgs, 1516288943Sdim ArrayRef<ObjCProtocolDecl *> protocols, 1517288943Sdim bool isKindOf) const; 1518314564Sdim 1519314564Sdim QualType getObjCTypeParamType(const ObjCTypeParamDecl *Decl, 1520360784Sdim ArrayRef<ObjCProtocolDecl *> protocols) const; 1521321369Sdim 1522276479Sdim bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl); 1523327952Sdim 1524276479Sdim /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in 1525276479Sdim /// QT's qualified-id protocol list adopt all protocols in IDecl's list 1526276479Sdim /// of protocols. 1527276479Sdim bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT, 1528276479Sdim ObjCInterfaceDecl *IDecl); 1529198092Srdivacky 1530341825Sdim /// Return a ObjCObjectPointerType type for the given ObjCObjectType. 1531218893Sdim QualType getObjCObjectPointerType(QualType OIT) const; 1532208600Srdivacky 1533341825Sdim /// GCC extension. 1534218893Sdim QualType getTypeOfExprType(Expr *e) const; 1535218893Sdim QualType getTypeOfType(QualType t) const; 1536198092Srdivacky 1537341825Sdim /// C++11 decltype. 1538234353Sdim QualType getDecltypeType(Expr *e, QualType UnderlyingType) const; 1539198092Srdivacky 1540341825Sdim /// Unary type transforms 1541223017Sdim QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, 1542223017Sdim UnaryTransformType::UTTKind UKind) const; 1543223017Sdim 1544341825Sdim /// C++11 deduced auto type. 1545296417Sdim QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, 1546360784Sdim bool IsDependent, bool IsPack = false, 1547360784Sdim ConceptDecl *TypeConstraintConcept = nullptr, 1548360784Sdim ArrayRef<TemplateArgument> TypeConstraintArgs ={}) const; 1549218893Sdim 1550341825Sdim /// C++11 deduction pattern for 'auto' type. 1551221345Sdim QualType getAutoDeductType() const; 1552221345Sdim 1553341825Sdim /// C++11 deduction pattern for 'auto &&' type. 1554221345Sdim QualType getAutoRRefDeductType() const; 1555221345Sdim 1556341825Sdim /// C++17 deduced class template specialization type. 1557321369Sdim QualType getDeducedTemplateSpecializationType(TemplateName Template, 1558321369Sdim QualType DeducedType, 1559321369Sdim bool IsDependent) const; 1560321369Sdim 1561341825Sdim /// Return the unique reference to the type for the specified TagDecl 1562243830Sdim /// (struct/union/class/enum) decl. 1563218893Sdim QualType getTagDeclType(const TagDecl *Decl) const; 1564198092Srdivacky 1565341825Sdim /// Return the unique type for "size_t" (C99 7.17), defined in 1566243830Sdim /// <stddef.h>. 1567243830Sdim /// 1568243830Sdim /// The sizeof operator requires this (C99 6.5.3.4p4). 1569200583Srdivacky CanQualType getSizeType() const; 1570193326Sed 1571341825Sdim /// Return the unique signed counterpart of 1572321369Sdim /// the integer type corresponding to size_t. 1573321369Sdim CanQualType getSignedSizeType() const; 1574321369Sdim 1575341825Sdim /// Return the unique type for "intmax_t" (C99 7.18.1.5), defined in 1576243830Sdim /// <stdint.h>. 1577234353Sdim CanQualType getIntMaxType() const; 1578234353Sdim 1579341825Sdim /// Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in 1580243830Sdim /// <stdint.h>. 1581234353Sdim CanQualType getUIntMaxType() const; 1582234353Sdim 1583341825Sdim /// Return the unique wchar_t type available in C++ (and available as 1584261991Sdim /// __wchar_t as a Microsoft extension). 1585193326Sed QualType getWCharType() const { return WCharTy; } 1586193326Sed 1587341825Sdim /// Return the type of wide characters. In C++, this returns the 1588261991Sdim /// unique wchar_t type. In C99, this returns a type compatible with the type 1589261991Sdim /// defined in <stddef.h> as defined by the target. 1590261991Sdim QualType getWideCharType() const { return WideCharTy; } 1591261991Sdim 1592341825Sdim /// Return the type of "signed wchar_t". 1593243830Sdim /// 1594193326Sed /// Used when in C++, as a GCC extension. 1595193326Sed QualType getSignedWCharType() const; 1596193326Sed 1597341825Sdim /// Return the type of "unsigned wchar_t". 1598243830Sdim /// 1599193326Sed /// Used when in C++, as a GCC extension. 1600193326Sed QualType getUnsignedWCharType() const; 1601198092Srdivacky 1602341825Sdim /// In C99, this returns a type compatible with the type 1603239462Sdim /// defined in <stddef.h> as defined by the target. 1604239462Sdim QualType getWIntType() const { return WIntTy; } 1605239462Sdim 1606341825Sdim /// Return a type compatible with "intptr_t" (C99 7.18.1.4), 1607249423Sdim /// as defined by the target. 1608249423Sdim QualType getIntPtrType() const; 1609249423Sdim 1610341825Sdim /// Return a type compatible with "uintptr_t" (C99 7.18.1.4), 1611249423Sdim /// as defined by the target. 1612249423Sdim QualType getUIntPtrType() const; 1613249423Sdim 1614341825Sdim /// Return the unique type for "ptrdiff_t" (C99 7.17) defined in 1615243830Sdim /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 1616193326Sed QualType getPointerDiffType() const; 1617198092Srdivacky 1618341825Sdim /// Return the unique unsigned counterpart of "ptrdiff_t" 1619327952Sdim /// integer type. The standard (C11 7.21.6.1p7) refers to this type 1620327952Sdim /// in the definition of %tu format specifier. 1621327952Sdim QualType getUnsignedPointerDiffType() const; 1622327952Sdim 1623341825Sdim /// Return the unique type for "pid_t" defined in 1624243830Sdim /// <sys/types.h>. We need this to compute the correct type for vfork(). 1625243830Sdim QualType getProcessIDType() const; 1626243830Sdim 1627341825Sdim /// Return the C structure type used to represent constant CFStrings. 1628218893Sdim QualType getCFConstantStringType() const; 1629321369Sdim 1630341825Sdim /// Returns the C struct type for objc_super 1631249423Sdim QualType getObjCSuperType() const; 1632249423Sdim void setObjCSuperType(QualType ST) { ObjCSuperType = ST; } 1633321369Sdim 1634193326Sed /// Get the structure type used to representation CFStrings, or NULL 1635193326Sed /// if it hasn't yet been built. 1636218893Sdim QualType getRawCFConstantStringType() const { 1637193326Sed if (CFConstantStringTypeDecl) 1638309124Sdim return getTypedefType(CFConstantStringTypeDecl); 1639193326Sed return QualType(); 1640193326Sed } 1641193326Sed void setCFConstantStringType(QualType T); 1642309124Sdim TypedefDecl *getCFConstantStringDecl() const; 1643309124Sdim RecordDecl *getCFConstantStringTagDecl() const; 1644193326Sed 1645193326Sed // This setter/getter represents the ObjC type for an NSConstantString. 1646193326Sed void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl); 1647198092Srdivacky QualType getObjCConstantStringInterface() const { 1648198092Srdivacky return ObjCConstantStringType; 1649193326Sed } 1650193326Sed 1651234353Sdim QualType getObjCNSStringType() const { 1652234353Sdim return ObjCNSStringType; 1653234353Sdim } 1654321369Sdim 1655234353Sdim void setObjCNSStringType(QualType T) { 1656234353Sdim ObjCNSStringType = T; 1657234353Sdim } 1658321369Sdim 1659341825Sdim /// Retrieve the type that \c id has been defined to, which may be 1660243830Sdim /// different from the built-in \c id if \c id has been typedef'd. 1661226633Sdim QualType getObjCIdRedefinitionType() const { 1662226633Sdim if (ObjCIdRedefinitionType.isNull()) 1663226633Sdim return getObjCIdType(); 1664226633Sdim return ObjCIdRedefinitionType; 1665226633Sdim } 1666321369Sdim 1667341825Sdim /// Set the user-written type that redefines \c id. 1668226633Sdim void setObjCIdRedefinitionType(QualType RedefType) { 1669226633Sdim ObjCIdRedefinitionType = RedefType; 1670226633Sdim } 1671198092Srdivacky 1672341825Sdim /// Retrieve the type that \c Class has been defined to, which may be 1673243830Sdim /// different from the built-in \c Class if \c Class has been typedef'd. 1674226633Sdim QualType getObjCClassRedefinitionType() const { 1675226633Sdim if (ObjCClassRedefinitionType.isNull()) 1676226633Sdim return getObjCClassType(); 1677226633Sdim return ObjCClassRedefinitionType; 1678193326Sed } 1679321369Sdim 1680341825Sdim /// Set the user-written type that redefines 'SEL'. 1681226633Sdim void setObjCClassRedefinitionType(QualType RedefType) { 1682226633Sdim ObjCClassRedefinitionType = RedefType; 1683226633Sdim } 1684193326Sed 1685341825Sdim /// Retrieve the type that 'SEL' has been defined to, which may be 1686226633Sdim /// different from the built-in 'SEL' if 'SEL' has been typedef'd. 1687226633Sdim QualType getObjCSelRedefinitionType() const { 1688226633Sdim if (ObjCSelRedefinitionType.isNull()) 1689226633Sdim return getObjCSelType(); 1690226633Sdim return ObjCSelRedefinitionType; 1691226633Sdim } 1692321369Sdim 1693341825Sdim /// Set the user-written type that redefines 'SEL'. 1694226633Sdim void setObjCSelRedefinitionType(QualType RedefType) { 1695226633Sdim ObjCSelRedefinitionType = RedefType; 1696226633Sdim } 1697226633Sdim 1698288943Sdim /// Retrieve the identifier 'NSObject'. 1699344779Sdim IdentifierInfo *getNSObjectName() const { 1700288943Sdim if (!NSObjectName) { 1701288943Sdim NSObjectName = &Idents.get("NSObject"); 1702288943Sdim } 1703288943Sdim 1704288943Sdim return NSObjectName; 1705288943Sdim } 1706288943Sdim 1707288943Sdim /// Retrieve the identifier 'NSCopying'. 1708288943Sdim IdentifierInfo *getNSCopyingName() { 1709288943Sdim if (!NSCopyingName) { 1710288943Sdim NSCopyingName = &Idents.get("NSCopying"); 1711288943Sdim } 1712288943Sdim 1713288943Sdim return NSCopyingName; 1714288943Sdim } 1715288943Sdim 1716327952Sdim CanQualType getNSUIntegerType() const { 1717327952Sdim assert(Target && "Expected target to be initialized"); 1718327952Sdim const llvm::Triple &T = Target->getTriple(); 1719327952Sdim // Windows is LLP64 rather than LP64 1720327952Sdim if (T.isOSWindows() && T.isArch64Bit()) 1721327952Sdim return UnsignedLongLongTy; 1722327952Sdim return UnsignedLongTy; 1723327952Sdim } 1724327952Sdim 1725327952Sdim CanQualType getNSIntegerType() const { 1726327952Sdim assert(Target && "Expected target to be initialized"); 1727327952Sdim const llvm::Triple &T = Target->getTriple(); 1728327952Sdim // Windows is LLP64 rather than LP64 1729327952Sdim if (T.isOSWindows() && T.isArch64Bit()) 1730327952Sdim return LongLongTy; 1731327952Sdim return LongTy; 1732327952Sdim } 1733327952Sdim 1734309124Sdim /// Retrieve the identifier 'bool'. 1735309124Sdim IdentifierInfo *getBoolName() const { 1736309124Sdim if (!BoolName) 1737309124Sdim BoolName = &Idents.get("bool"); 1738309124Sdim return BoolName; 1739309124Sdim } 1740309124Sdim 1741296417Sdim IdentifierInfo *getMakeIntegerSeqName() const { 1742296417Sdim if (!MakeIntegerSeqName) 1743296417Sdim MakeIntegerSeqName = &Idents.get("__make_integer_seq"); 1744296417Sdim return MakeIntegerSeqName; 1745296417Sdim } 1746296417Sdim 1747309124Sdim IdentifierInfo *getTypePackElementName() const { 1748309124Sdim if (!TypePackElementName) 1749309124Sdim TypePackElementName = &Idents.get("__type_pack_element"); 1750309124Sdim return TypePackElementName; 1751309124Sdim } 1752309124Sdim 1753341825Sdim /// Retrieve the Objective-C "instancetype" type, if already known; 1754226633Sdim /// otherwise, returns a NULL type; 1755226633Sdim QualType getObjCInstanceType() { 1756226633Sdim return getTypeDeclType(getObjCInstanceTypeDecl()); 1757226633Sdim } 1758226633Sdim 1759341825Sdim /// Retrieve the typedef declaration corresponding to the Objective-C 1760226633Sdim /// "instancetype" type. 1761226633Sdim TypedefDecl *getObjCInstanceTypeDecl(); 1762321369Sdim 1763341825Sdim /// Set the type for the C FILE type. 1764198092Srdivacky void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } 1765198092Srdivacky 1766341825Sdim /// Retrieve the C FILE type. 1767218893Sdim QualType getFILEType() const { 1768198092Srdivacky if (FILEDecl) 1769198092Srdivacky return getTypeDeclType(FILEDecl); 1770198092Srdivacky return QualType(); 1771198092Srdivacky } 1772198092Srdivacky 1773341825Sdim /// Set the type for the C jmp_buf type. 1774198092Srdivacky void setjmp_bufDecl(TypeDecl *jmp_bufDecl) { 1775198092Srdivacky this->jmp_bufDecl = jmp_bufDecl; 1776198092Srdivacky } 1777198092Srdivacky 1778341825Sdim /// Retrieve the C jmp_buf type. 1779218893Sdim QualType getjmp_bufType() const { 1780198092Srdivacky if (jmp_bufDecl) 1781198092Srdivacky return getTypeDeclType(jmp_bufDecl); 1782198092Srdivacky return QualType(); 1783198092Srdivacky } 1784198092Srdivacky 1785341825Sdim /// Set the type for the C sigjmp_buf type. 1786198092Srdivacky void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) { 1787198092Srdivacky this->sigjmp_bufDecl = sigjmp_bufDecl; 1788198092Srdivacky } 1789198092Srdivacky 1790341825Sdim /// Retrieve the C sigjmp_buf type. 1791218893Sdim QualType getsigjmp_bufType() const { 1792198092Srdivacky if (sigjmp_bufDecl) 1793198092Srdivacky return getTypeDeclType(sigjmp_bufDecl); 1794198092Srdivacky return QualType(); 1795198092Srdivacky } 1796198092Srdivacky 1797341825Sdim /// Set the type for the C ucontext_t type. 1798227737Sdim void setucontext_tDecl(TypeDecl *ucontext_tDecl) { 1799227737Sdim this->ucontext_tDecl = ucontext_tDecl; 1800227737Sdim } 1801227737Sdim 1802341825Sdim /// Retrieve the C ucontext_t type. 1803227737Sdim QualType getucontext_tType() const { 1804227737Sdim if (ucontext_tDecl) 1805227737Sdim return getTypeDeclType(ucontext_tDecl); 1806227737Sdim return QualType(); 1807227737Sdim } 1808227737Sdim 1809341825Sdim /// The result type of logical operations, '<', '>', '!=', etc. 1810218893Sdim QualType getLogicalOperationType() const { 1811234353Sdim return getLangOpts().CPlusPlus ? BoolTy : IntTy; 1812218893Sdim } 1813218893Sdim 1814341825Sdim /// Emit the Objective-CC type encoding for the given type \p T into 1815243830Sdim /// \p S. 1816243830Sdim /// 1817243830Sdim /// If \p Field is specified then record field names are also encoded. 1818243830Sdim void getObjCEncodingForType(QualType T, std::string &S, 1819280031Sdim const FieldDecl *Field=nullptr, 1820280031Sdim QualType *NotEncodedT=nullptr) const; 1821193326Sed 1822341825Sdim /// Emit the Objective-C property type encoding for the given 1823276479Sdim /// type \p T into \p S. 1824276479Sdim void getObjCEncodingForPropertyType(QualType T, std::string &S) const; 1825276479Sdim 1826193326Sed void getLegacyIntegralTypeEncoding(QualType &t) const; 1827198092Srdivacky 1828341825Sdim /// Put the string version of the type qualifiers \p QT into \p S. 1829198092Srdivacky void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 1830193326Sed std::string &S) const; 1831198092Srdivacky 1832341825Sdim /// Emit the encoded type for the function \p Decl into \p S. 1833223017Sdim /// 1834243830Sdim /// This is in the same format as Objective-C method encodings. 1835243830Sdim /// 1836223017Sdim /// \returns true if an error occurred (e.g., because one of the parameter 1837223017Sdim /// types is incomplete), false otherwise. 1838314564Sdim std::string getObjCEncodingForFunctionDecl(const FunctionDecl *Decl) const; 1839218893Sdim 1840341825Sdim /// Emit the encoded type for the method declaration \p Decl into 1841243830Sdim /// \p S. 1842314564Sdim std::string getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, 1843314564Sdim bool Extended = false) const; 1844198092Srdivacky 1845341825Sdim /// Return the encoded type for this block declaration. 1846218893Sdim std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const; 1847321369Sdim 1848193326Sed /// getObjCEncodingForPropertyDecl - Return the encoded type for 1849193326Sed /// this method declaration. If non-NULL, Container must be either 1850193326Sed /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should 1851193326Sed /// only be NULL when getting encodings for protocol properties. 1852314564Sdim std::string getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 1853314564Sdim const Decl *Container) const; 1854198092Srdivacky 1855198092Srdivacky bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 1856218893Sdim ObjCProtocolDecl *rProto) const; 1857321369Sdim 1858276479Sdim ObjCPropertyImplDecl *getObjCPropertyImplDeclForPropertyDecl( 1859276479Sdim const ObjCPropertyDecl *PD, 1860276479Sdim const Decl *Container) const; 1861198092Srdivacky 1862341825Sdim /// Return the size of type \p T for Objective-C encoding purpose, 1863243830Sdim /// in characters. 1864243830Sdim CharUnits getObjCEncodingTypeSize(QualType T) const; 1865194613Sed 1866341825Sdim /// Retrieve the typedef corresponding to the predefined \c id type 1867226633Sdim /// in Objective-C. 1868226633Sdim TypedefDecl *getObjCIdDecl() const; 1869321369Sdim 1870341825Sdim /// Represents the Objective-CC \c id type. 1871243830Sdim /// 1872243830Sdim /// This is set up lazily, by Sema. \c id is always a (typedef for a) 1873243830Sdim /// pointer type, a pointer to a struct. 1874226633Sdim QualType getObjCIdType() const { 1875226633Sdim return getTypeDeclType(getObjCIdDecl()); 1876226633Sdim } 1877198092Srdivacky 1878341825Sdim /// Retrieve the typedef corresponding to the predefined 'SEL' type 1879226633Sdim /// in Objective-C. 1880226633Sdim TypedefDecl *getObjCSelDecl() const; 1881321369Sdim 1882341825Sdim /// Retrieve the type that corresponds to the predefined Objective-C 1883226633Sdim /// 'SEL' type. 1884321369Sdim QualType getObjCSelType() const { 1885226633Sdim return getTypeDeclType(getObjCSelDecl()); 1886226633Sdim } 1887198092Srdivacky 1888341825Sdim /// Retrieve the typedef declaration corresponding to the predefined 1889226633Sdim /// Objective-C 'Class' type. 1890226633Sdim TypedefDecl *getObjCClassDecl() const; 1891321369Sdim 1892341825Sdim /// Represents the Objective-C \c Class type. 1893243830Sdim /// 1894243830Sdim /// This is set up lazily, by Sema. \c Class is always a (typedef for a) 1895243830Sdim /// pointer type, a pointer to a struct. 1896321369Sdim QualType getObjCClassType() const { 1897226633Sdim return getTypeDeclType(getObjCClassDecl()); 1898226633Sdim } 1899198092Srdivacky 1900341825Sdim /// Retrieve the Objective-C class declaration corresponding to 1901243830Sdim /// the predefined \c Protocol class. 1902234353Sdim ObjCInterfaceDecl *getObjCProtocolDecl() const; 1903243830Sdim 1904341825Sdim /// Retrieve declaration of 'BOOL' typedef 1905243830Sdim TypedefDecl *getBOOLDecl() const { 1906243830Sdim return BOOLDecl; 1907243830Sdim } 1908243830Sdim 1909341825Sdim /// Save declaration of 'BOOL' typedef 1910243830Sdim void setBOOLDecl(TypedefDecl *TD) { 1911243830Sdim BOOLDecl = TD; 1912243830Sdim } 1913243830Sdim 1914341825Sdim /// type of 'BOOL' type. 1915243830Sdim QualType getBOOLType() const { 1916243830Sdim return getTypeDeclType(getBOOLDecl()); 1917243830Sdim } 1918321369Sdim 1919341825Sdim /// Retrieve the type of the Objective-C \c Protocol class. 1920234353Sdim QualType getObjCProtoType() const { 1921234353Sdim return getObjCInterfaceType(getObjCProtocolDecl()); 1922234353Sdim } 1923321369Sdim 1924341825Sdim /// Retrieve the C type declaration corresponding to the predefined 1925243830Sdim /// \c __builtin_va_list type. 1926239462Sdim TypedefDecl *getBuiltinVaListDecl() const; 1927193326Sed 1928341825Sdim /// Retrieve the type of the \c __builtin_va_list type. 1929239462Sdim QualType getBuiltinVaListType() const { 1930239462Sdim return getTypeDeclType(getBuiltinVaListDecl()); 1931239462Sdim } 1932239462Sdim 1933341825Sdim /// Retrieve the C type declaration corresponding to the predefined 1934243830Sdim /// \c __va_list_tag type used to help define the \c __builtin_va_list type 1935243830Sdim /// for some targets. 1936296417Sdim Decl *getVaListTagDecl() const; 1937239462Sdim 1938296417Sdim /// Retrieve the C type declaration corresponding to the predefined 1939296417Sdim /// \c __builtin_ms_va_list type. 1940296417Sdim TypedefDecl *getBuiltinMSVaListDecl() const; 1941296417Sdim 1942296417Sdim /// Retrieve the type of the \c __builtin_ms_va_list type. 1943296417Sdim QualType getBuiltinMSVaListType() const { 1944296417Sdim return getTypeDeclType(getBuiltinMSVaListDecl()); 1945296417Sdim } 1946296417Sdim 1947341825Sdim /// Return whether a declaration to a builtin is allowed to be 1948341825Sdim /// overloaded/redeclared. 1949341825Sdim bool canBuiltinBeRedeclared(const FunctionDecl *) const; 1950341825Sdim 1951341825Sdim /// Return a type with additional \c const, \c volatile, or 1952243830Sdim /// \c restrict qualifiers. 1953218893Sdim QualType getCVRQualifiedType(QualType T, unsigned CVR) const { 1954198092Srdivacky return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); 1955198092Srdivacky } 1956198092Srdivacky 1957341825Sdim /// Un-split a SplitQualType. 1958234353Sdim QualType getQualifiedType(SplitQualType split) const { 1959234353Sdim return getQualifiedType(split.Ty, split.Quals); 1960234353Sdim } 1961234353Sdim 1962341825Sdim /// Return a type with additional qualifiers. 1963218893Sdim QualType getQualifiedType(QualType T, Qualifiers Qs) const { 1964198092Srdivacky if (!Qs.hasNonFastQualifiers()) 1965198092Srdivacky return T.withFastQualifiers(Qs.getFastQualifiers()); 1966198092Srdivacky QualifierCollector Qc(Qs); 1967198092Srdivacky const Type *Ptr = Qc.strip(T); 1968198092Srdivacky return getExtQualType(Ptr, Qc); 1969198092Srdivacky } 1970198092Srdivacky 1971341825Sdim /// Return a type with additional qualifiers. 1972218893Sdim QualType getQualifiedType(const Type *T, Qualifiers Qs) const { 1973198092Srdivacky if (!Qs.hasNonFastQualifiers()) 1974198092Srdivacky return QualType(T, Qs.getFastQualifiers()); 1975198092Srdivacky return getExtQualType(T, Qs); 1976198092Srdivacky } 1977198092Srdivacky 1978341825Sdim /// Return a type with the given lifetime qualifier. 1979243830Sdim /// 1980243830Sdim /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None. 1981224145Sdim QualType getLifetimeQualifiedType(QualType type, 1982224145Sdim Qualifiers::ObjCLifetime lifetime) { 1983224145Sdim assert(type.getObjCLifetime() == Qualifiers::OCL_None); 1984224145Sdim assert(lifetime != Qualifiers::OCL_None); 1985224145Sdim 1986224145Sdim Qualifiers qs; 1987224145Sdim qs.addObjCLifetime(lifetime); 1988224145Sdim return getQualifiedType(type, qs); 1989224145Sdim } 1990321369Sdim 1991251662Sdim /// getUnqualifiedObjCPointerType - Returns version of 1992251662Sdim /// Objective-C pointer type with lifetime qualifier removed. 1993251662Sdim QualType getUnqualifiedObjCPointerType(QualType type) const { 1994251662Sdim if (!type.getTypePtr()->isObjCObjectPointerType() || 1995251662Sdim !type.getQualifiers().hasObjCLifetime()) 1996251662Sdim return type; 1997251662Sdim Qualifiers Qs = type.getQualifiers(); 1998251662Sdim Qs.removeObjCLifetime(); 1999251662Sdim return getQualifiedType(type.getUnqualifiedType(), Qs); 2000251662Sdim } 2001321369Sdim 2002341825Sdim unsigned char getFixedPointScale(QualType Ty) const; 2003341825Sdim unsigned char getFixedPointIBits(QualType Ty) const; 2004344779Sdim FixedPointSemantics getFixedPointSemantics(QualType Ty) const; 2005344779Sdim APFixedPoint getFixedPointMax(QualType Ty) const; 2006344779Sdim APFixedPoint getFixedPointMin(QualType Ty) const; 2007341825Sdim 2008212904Sdim DeclarationNameInfo getNameForTemplate(TemplateName Name, 2009218893Sdim SourceLocation NameLoc) const; 2010199990Srdivacky 2011202879Srdivacky TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, 2012218893Sdim UnresolvedSetIterator End) const; 2013353358Sdim TemplateName getAssumedTemplateName(DeclarationName Name) const; 2014200583Srdivacky 2015198092Srdivacky TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, 2016193326Sed bool TemplateKeyword, 2017218893Sdim TemplateDecl *Template) const; 2018193326Sed 2019198092Srdivacky TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 2020218893Sdim const IdentifierInfo *Name) const; 2021198893Srdivacky TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 2022218893Sdim OverloadedOperatorKind Operator) const; 2023224145Sdim TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 2024224145Sdim TemplateName replacement) const; 2025218893Sdim TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 2026218893Sdim const TemplateArgument &ArgPack) const; 2027321369Sdim 2028194179Sed enum GetBuiltinTypeError { 2029327952Sdim /// No error 2030327952Sdim GE_None, 2031327952Sdim 2032353358Sdim /// Missing a type 2033353358Sdim GE_Missing_type, 2034353358Sdim 2035327952Sdim /// Missing a type from <stdio.h> 2036327952Sdim GE_Missing_stdio, 2037327952Sdim 2038327952Sdim /// Missing a type from <setjmp.h> 2039327952Sdim GE_Missing_setjmp, 2040327952Sdim 2041327952Sdim /// Missing a type from <ucontext.h> 2042327952Sdim GE_Missing_ucontext 2043194179Sed }; 2044198092Srdivacky 2045341825Sdim /// Return the type for the specified builtin. 2046243830Sdim /// 2047243830Sdim /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of 2048218893Sdim /// arguments to the builtin that are required to be integer constant 2049218893Sdim /// expressions. 2050218893Sdim QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, 2051276479Sdim unsigned *IntegerConstantArgs = nullptr) const; 2052198092Srdivacky 2053341825Sdim /// Types and expressions required to build C++2a three-way comparisons 2054341825Sdim /// using operator<=>, including the values return by builtin <=> operators. 2055341825Sdim ComparisonCategories CompCategories; 2056341825Sdim 2057193326Sedprivate: 2058198893Srdivacky CanQualType getFromTargetType(unsigned Type) const; 2059280031Sdim TypeInfo getTypeInfoImpl(const Type *T) const; 2060193326Sed 2061193326Sed //===--------------------------------------------------------------------===// 2062193326Sed // Type Predicates. 2063193326Sed //===--------------------------------------------------------------------===// 2064198092Srdivacky 2065193326Sedpublic: 2066341825Sdim /// Return one of the GCNone, Weak or Strong Objective-C garbage 2067243830Sdim /// collection attributes. 2068218893Sdim Qualifiers::GC getObjCGCAttrKind(QualType Ty) const; 2069198092Srdivacky 2070341825Sdim /// Return true if the given vector types are of the same unqualified 2071243830Sdim /// type or if they are equivalent to the same GCC vector type. 2072243830Sdim /// 2073243830Sdim /// \note This ignores whether they are target-specific (AltiVec or Neon) 2074243830Sdim /// types. 2075212904Sdim bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec); 2076212904Sdim 2077360784Sdim /// Return true if the type has been explicitly qualified with ObjC ownership. 2078360784Sdim /// A type may be implicitly qualified with ownership under ObjC ARC, and in 2079360784Sdim /// some cases the compiler treats these differently. 2080360784Sdim bool hasDirectOwnershipQualifier(QualType Ty) const; 2081360784Sdim 2082341825Sdim /// Return true if this is an \c NSObject object with its \c NSObject 2083243830Sdim /// attribute set. 2084224145Sdim static bool isObjCNSObjectType(QualType Ty) { 2085224145Sdim return Ty->isObjCNSObjectType(); 2086224145Sdim } 2087198092Srdivacky 2088193326Sed //===--------------------------------------------------------------------===// 2089193326Sed // Type Sizing and Analysis 2090193326Sed //===--------------------------------------------------------------------===// 2091198092Srdivacky 2092341825Sdim /// Return the APFloat 'semantics' for the specified scalar floating 2093243830Sdim /// point type. 2094193326Sed const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const; 2095198092Srdivacky 2096341825Sdim /// Get the size and alignment of the specified complete type in bits. 2097280031Sdim TypeInfo getTypeInfo(const Type *T) const; 2098280031Sdim TypeInfo getTypeInfo(QualType T) const { return getTypeInfo(T.getTypePtr()); } 2099198092Srdivacky 2100341825Sdim /// Get default simd alignment of the specified complete type in bits. 2101288943Sdim unsigned getOpenMPDefaultSimdAlign(QualType T) const; 2102288943Sdim 2103341825Sdim /// Return the size of the specified (complete) type \p T, in bits. 2104280031Sdim uint64_t getTypeSize(QualType T) const { return getTypeInfo(T).Width; } 2105280031Sdim uint64_t getTypeSize(const Type *T) const { return getTypeInfo(T).Width; } 2106198092Srdivacky 2107341825Sdim /// Return the size of the character type, in bits. 2108218893Sdim uint64_t getCharWidth() const { 2109199990Srdivacky return getTypeSize(CharTy); 2110199990Srdivacky } 2111321369Sdim 2112341825Sdim /// Convert a size in bits to a size in characters. 2113218893Sdim CharUnits toCharUnitsFromBits(int64_t BitSize) const; 2114218893Sdim 2115341825Sdim /// Convert a size in characters to a size in bits. 2116218893Sdim int64_t toBits(CharUnits CharSize) const; 2117218893Sdim 2118341825Sdim /// Return the size of the specified (complete) type \p T, in 2119243830Sdim /// characters. 2120218893Sdim CharUnits getTypeSizeInChars(QualType T) const; 2121218893Sdim CharUnits getTypeSizeInChars(const Type *T) const; 2122199990Srdivacky 2123353358Sdim Optional<CharUnits> getTypeSizeInCharsIfKnown(QualType Ty) const { 2124353358Sdim if (Ty->isIncompleteType() || Ty->isDependentType()) 2125353358Sdim return None; 2126353358Sdim return getTypeSizeInChars(Ty); 2127353358Sdim } 2128353358Sdim 2129353358Sdim Optional<CharUnits> getTypeSizeInCharsIfKnown(const Type *Ty) const { 2130353358Sdim return getTypeSizeInCharsIfKnown(QualType(Ty, 0)); 2131353358Sdim } 2132353358Sdim 2133341825Sdim /// Return the ABI-specified alignment of a (complete) type \p T, in 2134243830Sdim /// bits. 2135280031Sdim unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; } 2136280031Sdim unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; } 2137198092Srdivacky 2138341825Sdim /// Return the ABI-specified natural alignment of a (complete) type \p T, 2139341825Sdim /// before alignment adjustments, in bits. 2140341825Sdim /// 2141341825Sdim /// This alignment is curently used only by ARM and AArch64 when passing 2142341825Sdim /// arguments of a composite type. 2143341825Sdim unsigned getTypeUnadjustedAlign(QualType T) const { 2144341825Sdim return getTypeUnadjustedAlign(T.getTypePtr()); 2145341825Sdim } 2146341825Sdim unsigned getTypeUnadjustedAlign(const Type *T) const; 2147341825Sdim 2148341825Sdim /// Return the ABI-specified alignment of a type, in bits, or 0 if 2149314564Sdim /// the type is incomplete and we cannot determine the alignment (for 2150314564Sdim /// example, from alignment attributes). 2151314564Sdim unsigned getTypeAlignIfKnown(QualType T) const; 2152314564Sdim 2153341825Sdim /// Return the ABI-specified alignment of a (complete) type \p T, in 2154243830Sdim /// characters. 2155218893Sdim CharUnits getTypeAlignInChars(QualType T) const; 2156218893Sdim CharUnits getTypeAlignInChars(const Type *T) const; 2157321369Sdim 2158341825Sdim /// getTypeUnadjustedAlignInChars - Return the ABI-specified alignment of a type, 2159341825Sdim /// in characters, before alignment adjustments. This method does not work on 2160341825Sdim /// incomplete types. 2161341825Sdim CharUnits getTypeUnadjustedAlignInChars(QualType T) const; 2162341825Sdim CharUnits getTypeUnadjustedAlignInChars(const Type *T) const; 2163341825Sdim 2164243830Sdim // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the 2165243830Sdim // type is a record, its data size is returned. 2166243830Sdim std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const; 2167203955Srdivacky 2168218893Sdim std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const; 2169218893Sdim std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const; 2170208600Srdivacky 2171341825Sdim /// Determine if the alignment the type has was required using an 2172280031Sdim /// alignment attribute. 2173280031Sdim bool isAlignmentRequired(const Type *T) const; 2174280031Sdim bool isAlignmentRequired(QualType T) const; 2175280031Sdim 2176341825Sdim /// Return the "preferred" alignment of the specified type \p T for 2177243830Sdim /// the current target, in bits. 2178243830Sdim /// 2179243830Sdim /// This can be different than the ABI alignment in cases where it is 2180243830Sdim /// beneficial for performance to overalign a data type. 2181218893Sdim unsigned getPreferredTypeAlign(const Type *T) const; 2182198092Srdivacky 2183341825Sdim /// Return the default alignment for __attribute__((aligned)) on 2184288943Sdim /// this target, to be used if no alignment value is specified. 2185314564Sdim unsigned getTargetDefaultAlignForAttributeAligned() const; 2186288943Sdim 2187341825Sdim /// Return the alignment in bits that should be given to a 2188251662Sdim /// global variable with type \p T. 2189251662Sdim unsigned getAlignOfGlobalVar(QualType T) const; 2190251662Sdim 2191341825Sdim /// Return the alignment in characters that should be given to a 2192251662Sdim /// global variable with type \p T. 2193251662Sdim CharUnits getAlignOfGlobalVarInChars(QualType T) const; 2194251662Sdim 2195341825Sdim /// Return a conservative estimate of the alignment of the specified 2196243830Sdim /// decl \p D. 2197243830Sdim /// 2198243830Sdim /// \pre \p D must not be a bitfield type, as bitfields do not have a valid 2199243830Sdim /// alignment. 2200243830Sdim /// 2201261991Sdim /// If \p ForAlignof, references are treated like their underlying type 2202261991Sdim /// and large arrays don't get any special treatment. If not \p ForAlignof 2203261991Sdim /// it computes the value expected by CodeGen: references are treated like 2204261991Sdim /// pointers and large arrays get extra alignment. 2205261991Sdim CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const; 2206198092Srdivacky 2207353358Sdim /// Return the alignment (in bytes) of the thrown exception object. This is 2208353358Sdim /// only meaningful for targets that allocate C++ exceptions in a system 2209353358Sdim /// runtime, such as those using the Itanium C++ ABI. 2210353358Sdim CharUnits getExnObjectAlignment() const { 2211353358Sdim return toCharUnitsFromBits(Target->getExnObjectAlignment()); 2212353358Sdim } 2213353358Sdim 2214341825Sdim /// Get or compute information about the layout of the specified 2215243830Sdim /// record (struct/union/class) \p D, which indicates its size and field 2216193326Sed /// position information. 2217218893Sdim const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const; 2218198092Srdivacky 2219341825Sdim /// Get or compute information about the layout of the specified 2220243830Sdim /// Objective-C interface. 2221218893Sdim const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) 2222218893Sdim const; 2223193326Sed 2224234353Sdim void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS, 2225234353Sdim bool Simple = false) const; 2226207619Srdivacky 2227341825Sdim /// Get or compute information about the layout of the specified 2228243830Sdim /// Objective-C implementation. 2229243830Sdim /// 2230243830Sdim /// This may differ from the interface if synthesized ivars are present. 2231193326Sed const ASTRecordLayout & 2232218893Sdim getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const; 2233193326Sed 2234341825Sdim /// Get our current best idea for the key function of the 2235327952Sdim /// given record decl, or nullptr if there isn't one. 2236200583Srdivacky /// 2237243830Sdim /// The key function is, according to the Itanium C++ ABI section 5.2.3: 2238249423Sdim /// ...the first non-pure virtual function that is not inline at the 2239249423Sdim /// point of class definition. 2240243830Sdim /// 2241249423Sdim /// Other ABIs use the same idea. However, the ARM C++ ABI ignores 2242249423Sdim /// virtual functions that are defined 'inline', which means that 2243249423Sdim /// the result of this computation can change. 2244249423Sdim const CXXMethodDecl *getCurrentKeyFunction(const CXXRecordDecl *RD); 2245200583Srdivacky 2246341825Sdim /// Observe that the given method cannot be a key function. 2247249423Sdim /// Checks the key-function cache for the method's class and clears it 2248249423Sdim /// if matches the given declaration. 2249249423Sdim /// 2250249423Sdim /// This is used in ABIs where out-of-line definitions marked 2251249423Sdim /// inline are not considered to be key functions. 2252249423Sdim /// 2253249423Sdim /// \param method should be the declaration from the class definition 2254249423Sdim void setNonKeyFunction(const CXXMethodDecl *method); 2255249423Sdim 2256288943Sdim /// Loading virtual member pointers using the virtual inheritance model 2257288943Sdim /// always results in an adjustment using the vbtable even if the index is 2258288943Sdim /// zero. 2259288943Sdim /// 2260288943Sdim /// This is usually OK because the first slot in the vbtable points 2261288943Sdim /// backwards to the top of the MDC. However, the MDC might be reusing a 2262288943Sdim /// vbptr from an nv-base. In this case, the first slot in the vbtable 2263288943Sdim /// points to the start of the nv-base which introduced the vbptr and *not* 2264288943Sdim /// the MDC. Modify the NonVirtualBaseAdjustment to account for this. 2265288943Sdim CharUnits getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const; 2266288943Sdim 2267234353Sdim /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits. 2268234353Sdim uint64_t getFieldOffset(const ValueDecl *FD) const; 2269234353Sdim 2270321369Sdim /// Get the offset of an ObjCIvarDecl in bits. 2271321369Sdim uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID, 2272321369Sdim const ObjCImplementationDecl *ID, 2273321369Sdim const ObjCIvarDecl *Ivar) const; 2274321369Sdim 2275218893Sdim bool isNearlyEmpty(const CXXRecordDecl *RD) const; 2276218893Sdim 2277276479Sdim VTableContextBase *getVTableContext(); 2278276479Sdim 2279353358Sdim /// If \p T is null pointer, assume the target in ASTContext. 2280353358Sdim MangleContext *createMangleContext(const TargetInfo *T = nullptr); 2281321369Sdim 2282212904Sdim void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, 2283226633Sdim SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; 2284321369Sdim 2285218893Sdim unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; 2286198893Srdivacky void CollectInheritedProtocols(const Decl *CDecl, 2287203955Srdivacky llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); 2288193326Sed 2289341825Sdim /// Return true if the specified type has unique object representations 2290327952Sdim /// according to (C++17 [meta.unary.prop]p9) 2291327952Sdim bool hasUniqueObjectRepresentations(QualType Ty) const; 2292327952Sdim 2293193326Sed //===--------------------------------------------------------------------===// 2294193326Sed // Type Operators 2295193326Sed //===--------------------------------------------------------------------===// 2296198092Srdivacky 2297341825Sdim /// Return the canonical (structural) type corresponding to the 2298243830Sdim /// specified potentially non-canonical type \p T. 2299243830Sdim /// 2300243830Sdim /// The non-canonical version of a type may have many "decorated" versions of 2301243830Sdim /// types. Decorators can include typedefs, 'typeof' operators, etc. The 2302243830Sdim /// returned type is guaranteed to be free of any of these, allowing two 2303243830Sdim /// canonical types to be compared for exact equality with a simple pointer 2304243830Sdim /// comparison. 2305218893Sdim CanQualType getCanonicalType(QualType T) const { 2306218893Sdim return CanQualType::CreateUnsafe(T.getCanonicalType()); 2307218893Sdim } 2308218893Sdim 2309218893Sdim const Type *getCanonicalType(const Type *T) const { 2310193326Sed return T->getCanonicalTypeInternal().getTypePtr(); 2311193326Sed } 2312193326Sed 2313341825Sdim /// Return the canonical parameter type corresponding to the specific 2314243830Sdim /// potentially non-canonical one. 2315243830Sdim /// 2316198398Srdivacky /// Qualifiers are stripped off, functions are turned into function 2317198398Srdivacky /// pointers, and arrays decay one level into pointers. 2318218893Sdim CanQualType getCanonicalParamType(QualType T) const; 2319198398Srdivacky 2320341825Sdim /// Determine whether the given types \p T1 and \p T2 are equivalent. 2321234353Sdim bool hasSameType(QualType T1, QualType T2) const { 2322193326Sed return getCanonicalType(T1) == getCanonicalType(T2); 2323193326Sed } 2324276479Sdim bool hasSameType(const Type *T1, const Type *T2) const { 2325276479Sdim return getCanonicalType(T1) == getCanonicalType(T2); 2326276479Sdim } 2327276479Sdim 2328341825Sdim /// Return this type as a completely-unqualified array type, 2329243830Sdim /// capturing the qualifiers in \p Quals. 2330201361Srdivacky /// 2331243830Sdim /// This will remove the minimal amount of sugaring from the types, similar 2332243830Sdim /// to the behavior of QualType::getUnqualifiedType(). 2333243830Sdim /// 2334202379Srdivacky /// \param T is the qualified type, which may be an ArrayType 2335201361Srdivacky /// 2336201361Srdivacky /// \param Quals will receive the full set of qualifiers that were 2337202379Srdivacky /// applied to the array. 2338201361Srdivacky /// 2339201361Srdivacky /// \returns if this is an array type, the completely unqualified array type 2340202379Srdivacky /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). 2341201361Srdivacky QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals); 2342201361Srdivacky 2343341825Sdim /// Determine whether the given types are equivalent after 2344193326Sed /// cvr-qualifiers have been removed. 2345234353Sdim bool hasSameUnqualifiedType(QualType T1, QualType T2) const { 2346218893Sdim return getCanonicalType(T1).getTypePtr() == 2347218893Sdim getCanonicalType(T2).getTypePtr(); 2348193326Sed } 2349193326Sed 2350288943Sdim bool hasSameNullabilityTypeQualifier(QualType SubT, QualType SuperT, 2351288943Sdim bool IsParam) const { 2352288943Sdim auto SubTnullability = SubT->getNullability(*this); 2353288943Sdim auto SuperTnullability = SuperT->getNullability(*this); 2354288943Sdim if (SubTnullability.hasValue() == SuperTnullability.hasValue()) { 2355288943Sdim // Neither has nullability; return true 2356288943Sdim if (!SubTnullability) 2357288943Sdim return true; 2358288943Sdim // Both have nullability qualifier. 2359288943Sdim if (*SubTnullability == *SuperTnullability || 2360288943Sdim *SubTnullability == NullabilityKind::Unspecified || 2361288943Sdim *SuperTnullability == NullabilityKind::Unspecified) 2362288943Sdim return true; 2363321369Sdim 2364288943Sdim if (IsParam) { 2365288943Sdim // Ok for the superclass method parameter to be "nonnull" and the subclass 2366288943Sdim // method parameter to be "nullable" 2367288943Sdim return (*SuperTnullability == NullabilityKind::NonNull && 2368288943Sdim *SubTnullability == NullabilityKind::Nullable); 2369288943Sdim } 2370288943Sdim else { 2371288943Sdim // For the return type, it's okay for the superclass method to specify 2372288943Sdim // "nullable" and the subclass method specify "nonnull" 2373288943Sdim return (*SuperTnullability == NullabilityKind::Nullable && 2374288943Sdim *SubTnullability == NullabilityKind::NonNull); 2375288943Sdim } 2376288943Sdim } 2377288943Sdim return true; 2378288943Sdim } 2379288943Sdim 2380261991Sdim bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, 2381261991Sdim const ObjCMethodDecl *MethodImp); 2382321369Sdim 2383341825Sdim bool UnwrapSimilarTypes(QualType &T1, QualType &T2); 2384341825Sdim bool UnwrapSimilarArrayTypes(QualType &T1, QualType &T2); 2385321369Sdim 2386341825Sdim /// Determine if two types are similar, according to the C++ rules. That is, 2387341825Sdim /// determine if they are the same other than qualifiers on the initial 2388341825Sdim /// sequence of pointer / pointer-to-member / array (and in Clang, object 2389341825Sdim /// pointer) types and their element types. 2390341825Sdim /// 2391341825Sdim /// Clang offers a number of qualifiers in addition to the C++ qualifiers; 2392341825Sdim /// those qualifiers are also ignored in the 'similarity' check. 2393341825Sdim bool hasSimilarType(QualType T1, QualType T2); 2394341825Sdim 2395341825Sdim /// Determine if two types are similar, ignoring only CVR qualifiers. 2396341825Sdim bool hasCvrSimilarType(QualType T1, QualType T2); 2397341825Sdim 2398341825Sdim /// Retrieves the "canonical" nested name specifier for a 2399193326Sed /// given nested name specifier. 2400193326Sed /// 2401193326Sed /// The canonical nested name specifier is a nested name specifier 2402193326Sed /// that uniquely identifies a type or namespace within the type 2403193326Sed /// system. For example, given: 2404193326Sed /// 2405193326Sed /// \code 2406193326Sed /// namespace N { 2407193326Sed /// struct S { 2408193326Sed /// template<typename T> struct X { typename T* type; }; 2409193326Sed /// }; 2410193326Sed /// } 2411193326Sed /// 2412193326Sed /// template<typename T> struct Y { 2413193326Sed /// typename N::S::X<T>::type member; 2414193326Sed /// }; 2415193326Sed /// \endcode 2416193326Sed /// 2417193326Sed /// Here, the nested-name-specifier for N::S::X<T>:: will be 2418193326Sed /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined 2419193326Sed /// by declarations in the type system and the canonical type for 2420193326Sed /// the template type parameter 'T' is template-param-0-0. 2421193326Sed NestedNameSpecifier * 2422218893Sdim getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const; 2423193326Sed 2424341825Sdim /// Retrieves the default calling convention for the current target. 2425327952Sdim CallingConv getDefaultCallingConvention(bool IsVariadic, 2426353358Sdim bool IsCXXMethod, 2427353358Sdim bool IsBuiltin = false) const; 2428218893Sdim 2429341825Sdim /// Retrieves the "canonical" template name that refers to a 2430193326Sed /// given template. 2431193326Sed /// 2432193326Sed /// The canonical template name is the simplest expression that can 2433193326Sed /// be used to refer to a given template. For most templates, this 2434193326Sed /// expression is just the template declaration itself. For example, 2435193326Sed /// the template std::vector can be referred to via a variety of 2436239462Sdim /// names---std::vector, \::std::vector, vector (if vector is in 2437193326Sed /// scope), etc.---but all of these names map down to the same 2438193326Sed /// TemplateDecl, which is used to form the canonical template name. 2439193326Sed /// 2440193326Sed /// Dependent template names are more interesting. Here, the 2441193326Sed /// template name could be something like T::template apply or 2442193326Sed /// std::allocator<T>::template rebind, where the nested name 2443193326Sed /// specifier itself is dependent. In this case, the canonical 2444193326Sed /// template name uses the shortest form of the dependent 2445193326Sed /// nested-name-specifier, which itself contains all canonical 2446193326Sed /// types, values, and templates. 2447218893Sdim TemplateName getCanonicalTemplateName(TemplateName Name) const; 2448193326Sed 2449341825Sdim /// Determine whether the given template names refer to the same 2450199482Srdivacky /// template. 2451199482Srdivacky bool hasSameTemplateName(TemplateName X, TemplateName Y); 2452321369Sdim 2453341825Sdim /// Retrieve the "canonical" template argument. 2454198092Srdivacky /// 2455198092Srdivacky /// The canonical template argument is the simplest template argument 2456198092Srdivacky /// (which may be a type, value, expression, or declaration) that 2457198092Srdivacky /// expresses the value of the argument. 2458218893Sdim TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) 2459218893Sdim const; 2460198092Srdivacky 2461193326Sed /// Type Query functions. If the type is an instance of the specified class, 2462193326Sed /// return the Type pointer for the underlying maximally pretty type. This 2463193326Sed /// is a member of ASTContext because this may need to do some amount of 2464193326Sed /// canonicalization, e.g. to move type qualifiers into the element type. 2465218893Sdim const ArrayType *getAsArrayType(QualType T) const; 2466218893Sdim const ConstantArrayType *getAsConstantArrayType(QualType T) const { 2467193326Sed return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T)); 2468193326Sed } 2469218893Sdim const VariableArrayType *getAsVariableArrayType(QualType T) const { 2470193326Sed return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T)); 2471193326Sed } 2472218893Sdim const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const { 2473193326Sed return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T)); 2474193326Sed } 2475218893Sdim const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) 2476218893Sdim const { 2477202379Srdivacky return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T)); 2478202379Srdivacky } 2479321369Sdim 2480341825Sdim /// Return the innermost element type of an array type. 2481243830Sdim /// 2482198092Srdivacky /// For example, will return "int" for int[m][n] 2483218893Sdim QualType getBaseElementType(const ArrayType *VAT) const; 2484198092Srdivacky 2485341825Sdim /// Return the innermost element type of a type (which needn't 2486243830Sdim /// actually be an array type). 2487218893Sdim QualType getBaseElementType(QualType QT) const; 2488198092Srdivacky 2489341825Sdim /// Return number of constant array elements. 2490198092Srdivacky uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const; 2491198092Srdivacky 2492341825Sdim /// Perform adjustment on the parameter type of a function. 2493224145Sdim /// 2494224145Sdim /// This routine adjusts the given parameter type @p T to the actual 2495224145Sdim /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], 2496224145Sdim /// C++ [dcl.fct]p3). The adjusted parameter type is returned. 2497239462Sdim QualType getAdjustedParameterType(QualType T) const; 2498321369Sdim 2499341825Sdim /// Retrieve the parameter type as adjusted for use in the signature 2500224145Sdim /// of a function, decaying array and function types and removing top-level 2501224145Sdim /// cv-qualifiers. 2502239462Sdim QualType getSignatureParameterType(QualType T) const; 2503321369Sdim 2504288943Sdim QualType getExceptionObjectType(QualType T) const; 2505321369Sdim 2506341825Sdim /// Return the properly qualified result of decaying the specified 2507243830Sdim /// array type to a pointer. 2508193326Sed /// 2509243830Sdim /// This operation is non-trivial when handling typedefs etc. The canonical 2510243830Sdim /// type of \p T must be an array type, this returns a pointer to a properly 2511243830Sdim /// qualified element of the array. 2512243830Sdim /// 2513193326Sed /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 2514218893Sdim QualType getArrayDecayedType(QualType T) const; 2515198092Srdivacky 2516341825Sdim /// Return the type that \p PromotableType will promote to: C99 2517243830Sdim /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type. 2518218893Sdim QualType getPromotedIntegerType(QualType PromotableType) const; 2519198092Srdivacky 2520341825Sdim /// Recurses in pointer/array types until it finds an Objective-C 2521243830Sdim /// retainable type and returns its ownership. 2522224145Sdim Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const; 2523224145Sdim 2524341825Sdim /// Whether this is a promotable bitfield reference according 2525198092Srdivacky /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 2526198092Srdivacky /// 2527198092Srdivacky /// \returns the type this bit-field will promote to, or NULL if no 2528198092Srdivacky /// promotion occurs. 2529218893Sdim QualType isPromotableBitField(Expr *E) const; 2530198092Srdivacky 2531341825Sdim /// Return the highest ranked integer type, see C99 6.3.1.8p1. 2532243830Sdim /// 2533243830Sdim /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If 2534243830Sdim /// \p LHS < \p RHS, return -1. 2535218893Sdim int getIntegerTypeOrder(QualType LHS, QualType RHS) const; 2536198092Srdivacky 2537341825Sdim /// Compare the rank of the two specified floating point types, 2538243830Sdim /// ignoring the domain of the type (i.e. 'double' == '_Complex double'). 2539243830Sdim /// 2540243830Sdim /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If 2541243830Sdim /// \p LHS < \p RHS, return -1. 2542218893Sdim int getFloatingTypeOrder(QualType LHS, QualType RHS) const; 2543193326Sed 2544353358Sdim /// Compare the rank of two floating point types as above, but compare equal 2545353358Sdim /// if both types have the same floating-point semantics on the target (i.e. 2546353358Sdim /// long double and double on AArch64 will return 0). 2547353358Sdim int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const; 2548353358Sdim 2549341825Sdim /// Return a real floating point or a complex type (based on 2550243830Sdim /// \p typeDomain/\p typeSize). 2551243830Sdim /// 2552243830Sdim /// \param typeDomain a real floating point or complex type. 2553243830Sdim /// \param typeSize a real floating point or complex type. 2554198092Srdivacky QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 2555193326Sed QualType typeDomain) const; 2556193326Sed 2557221345Sdim unsigned getTargetAddressSpace(QualType T) const { 2558221345Sdim return getTargetAddressSpace(T.getQualifiers()); 2559221345Sdim } 2560221345Sdim 2561221345Sdim unsigned getTargetAddressSpace(Qualifiers Q) const { 2562221345Sdim return getTargetAddressSpace(Q.getAddressSpace()); 2563221345Sdim } 2564221345Sdim 2565327952Sdim unsigned getTargetAddressSpace(LangAS AS) const; 2566221345Sdim 2567344779Sdim LangAS getLangASForBuiltinAddressSpace(unsigned AS) const; 2568344779Sdim 2569314564Sdim /// Get target-dependent integer value for null pointer which is used for 2570314564Sdim /// constant folding. 2571314564Sdim uint64_t getTargetNullPointerValue(QualType QT) const; 2572314564Sdim 2573327952Sdim bool addressSpaceMapManglingFor(LangAS AS) const { 2574327952Sdim return AddrSpaceMapMangling || isTargetAddressSpace(AS); 2575261991Sdim } 2576261991Sdim 2577193326Sedprivate: 2578193326Sed // Helper for integer ordering 2579218893Sdim unsigned getIntegerRank(const Type *T) const; 2580193326Sed 2581193326Sedpublic: 2582193326Sed //===--------------------------------------------------------------------===// 2583193326Sed // Type Compatibility Predicates 2584193326Sed //===--------------------------------------------------------------------===// 2585198092Srdivacky 2586193326Sed /// Compatibility predicates used to check assignment expressions. 2587321369Sdim bool typesAreCompatible(QualType T1, QualType T2, 2588212904Sdim bool CompareUnqualified = false); // C99 6.2.7p1 2589198092Srdivacky 2590321369Sdim bool propertyTypesAreCompatible(QualType, QualType); 2591321369Sdim bool typesAreBlockPointerCompatible(QualType, QualType); 2592205408Srdivacky 2593193326Sed bool isObjCIdType(QualType T) const { 2594226633Sdim return T == getObjCIdType(); 2595193326Sed } 2596327952Sdim 2597193326Sed bool isObjCClassType(QualType T) const { 2598226633Sdim return T == getObjCClassType(); 2599193326Sed } 2600327952Sdim 2601193326Sed bool isObjCSelType(QualType T) const { 2602226633Sdim return T == getObjCSelType(); 2603193326Sed } 2604327952Sdim 2605360784Sdim bool ObjCQualifiedIdTypesAreCompatible(const ObjCObjectPointerType *LHS, 2606360784Sdim const ObjCObjectPointerType *RHS, 2607198092Srdivacky bool ForCompare); 2608193326Sed 2609360784Sdim bool ObjCQualifiedClassTypesAreCompatible(const ObjCObjectPointerType *LHS, 2610360784Sdim const ObjCObjectPointerType *RHS); 2611321369Sdim 2612193326Sed // Check the safety of assignment from LHS to RHS 2613198092Srdivacky bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 2614198092Srdivacky const ObjCObjectPointerType *RHSOPT); 2615208600Srdivacky bool canAssignObjCInterfaces(const ObjCObjectType *LHS, 2616208600Srdivacky const ObjCObjectType *RHS); 2617205408Srdivacky bool canAssignObjCInterfacesInBlockPointer( 2618205408Srdivacky const ObjCObjectPointerType *LHSOPT, 2619221345Sdim const ObjCObjectPointerType *RHSOPT, 2620221345Sdim bool BlockReturnType); 2621193326Sed bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); 2622198893Srdivacky QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, 2623198893Srdivacky const ObjCObjectPointerType *RHSOPT); 2624212904Sdim bool canBindObjCObjectType(QualType To, QualType From); 2625212904Sdim 2626193326Sed // Functions for calculating composite types 2627212904Sdim QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, 2628221345Sdim bool Unqualified = false, bool BlockReturnType = false); 2629212904Sdim QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, 2630212904Sdim bool Unqualified = false); 2631276479Sdim QualType mergeFunctionParameterTypes(QualType, QualType, 2632276479Sdim bool OfBlockPointer = false, 2633276479Sdim bool Unqualified = false); 2634218893Sdim QualType mergeTransparentUnionType(QualType, QualType, 2635218893Sdim bool OfBlockPointer=false, 2636218893Sdim bool Unqualified = false); 2637321369Sdim 2638208600Srdivacky QualType mergeObjCGCQualifiers(QualType, QualType); 2639321369Sdim 2640327952Sdim /// This function merges the ExtParameterInfo lists of two functions. It 2641327952Sdim /// returns true if the lists are compatible. The merged list is returned in 2642327952Sdim /// NewParamInfos. 2643327952Sdim /// 2644327952Sdim /// \param FirstFnType The type of the first function. 2645327952Sdim /// 2646327952Sdim /// \param SecondFnType The type of the second function. 2647327952Sdim /// 2648327952Sdim /// \param CanUseFirst This flag is set to true if the first function's 2649327952Sdim /// ExtParameterInfo list can be used as the composite list of 2650327952Sdim /// ExtParameterInfo. 2651327952Sdim /// 2652327952Sdim /// \param CanUseSecond This flag is set to true if the second function's 2653327952Sdim /// ExtParameterInfo list can be used as the composite list of 2654327952Sdim /// ExtParameterInfo. 2655327952Sdim /// 2656327952Sdim /// \param NewParamInfos The composite list of ExtParameterInfo. The list is 2657327952Sdim /// empty if none of the flags are set. 2658327952Sdim /// 2659327952Sdim bool mergeExtParameterInfo( 2660327952Sdim const FunctionProtoType *FirstFnType, 2661327952Sdim const FunctionProtoType *SecondFnType, 2662327952Sdim bool &CanUseFirst, bool &CanUseSecond, 2663327952Sdim SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &NewParamInfos); 2664193326Sed 2665296417Sdim void ResetObjCLayout(const ObjCContainerDecl *CD); 2666198092Srdivacky 2667193326Sed //===--------------------------------------------------------------------===// 2668193326Sed // Integer Predicates 2669193326Sed //===--------------------------------------------------------------------===// 2670193326Sed 2671193326Sed // The width of an integer, as defined in C99 6.2.6.2. This is the number 2672193326Sed // of bits in an integer type excluding any padding bits. 2673218893Sdim unsigned getIntWidth(QualType T) const; 2674193326Sed 2675193326Sed // Per C99 6.2.5p6, for every signed integer type, there is a corresponding 2676193326Sed // unsigned integer type. This method takes a signed type, and returns the 2677193326Sed // corresponding unsigned integer type. 2678341825Sdim // With the introduction of fixed point types in ISO N1169, this method also 2679341825Sdim // accepts fixed point types and returns the corresponding unsigned type for 2680341825Sdim // a given fixed point type. 2681243830Sdim QualType getCorrespondingUnsignedType(QualType T) const; 2682193326Sed 2683341825Sdim // Per ISO N1169, this method accepts fixed point types and returns the 2684341825Sdim // corresponding saturated type for a given fixed point type. 2685341825Sdim QualType getCorrespondingSaturatedType(QualType Ty) const; 2686341825Sdim 2687353358Sdim // This method accepts fixed point types and returns the corresponding signed 2688353358Sdim // type. Unlike getCorrespondingUnsignedType(), this only accepts unsigned 2689353358Sdim // fixed point types because there are unsigned integer types like bool and 2690353358Sdim // char8_t that don't have signed equivalents. 2691353358Sdim QualType getCorrespondingSignedFixedPointType(QualType Ty) const; 2692353358Sdim 2693193326Sed //===--------------------------------------------------------------------===// 2694193326Sed // Integer Values 2695193326Sed //===--------------------------------------------------------------------===// 2696193326Sed 2697341825Sdim /// Make an APSInt of the appropriate width and signedness for the 2698243830Sdim /// given \p Value and integer \p Type. 2699218893Sdim llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const { 2700296417Sdim // If Type is a signed integer type larger than 64 bits, we need to be sure 2701296417Sdim // to sign extend Res appropriately. 2702296417Sdim llvm::APSInt Res(64, !Type->isSignedIntegerOrEnumerationType()); 2703193326Sed Res = Value; 2704296417Sdim unsigned Width = getIntWidth(Type); 2705296417Sdim if (Width != Res.getBitWidth()) 2706296417Sdim return Res.extOrTrunc(Width); 2707193326Sed return Res; 2708193326Sed } 2709193326Sed 2710234353Sdim bool isSentinelNullExpr(const Expr *E); 2711234353Sdim 2712341825Sdim /// Get the implementation of the ObjCInterfaceDecl \p D, or nullptr if 2713243830Sdim /// none exists. 2714198092Srdivacky ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D); 2715327952Sdim 2716341825Sdim /// Get the implementation of the ObjCCategoryDecl \p D, or nullptr if 2717243830Sdim /// none exists. 2718327952Sdim ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); 2719198092Srdivacky 2720341825Sdim /// Return true if there is at least one \@implementation in the TU. 2721218893Sdim bool AnyObjCImplementation() { 2722218893Sdim return !ObjCImpls.empty(); 2723218893Sdim } 2724218893Sdim 2725341825Sdim /// Set the implementation of ObjCInterfaceDecl. 2726198092Srdivacky void setObjCImplementation(ObjCInterfaceDecl *IFaceD, 2727198092Srdivacky ObjCImplementationDecl *ImplD); 2728327952Sdim 2729341825Sdim /// Set the implementation of ObjCCategoryDecl. 2730198092Srdivacky void setObjCImplementation(ObjCCategoryDecl *CatD, 2731198092Srdivacky ObjCCategoryImplDecl *ImplD); 2732226633Sdim 2733341825Sdim /// Get the duplicate declaration of a ObjCMethod in the same 2734243830Sdim /// interface, or null if none exists. 2735296417Sdim const ObjCMethodDecl * 2736296417Sdim getObjCMethodRedeclaration(const ObjCMethodDecl *MD) const; 2737226633Sdim 2738226633Sdim void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, 2739296417Sdim const ObjCMethodDecl *Redecl); 2740234353Sdim 2741341825Sdim /// Returns the Objective-C interface that \p ND belongs to if it is 2742243830Sdim /// an Objective-C method/property/ivar etc. that is part of an interface, 2743234353Sdim /// otherwise returns null. 2744249423Sdim const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const; 2745321369Sdim 2746353358Sdim /// Set the copy initialization expression of a block var decl. \p CanThrow 2747344779Sdim /// indicates whether the copy expression can throw or not. 2748344779Sdim void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow); 2749327952Sdim 2750341825Sdim /// Get the copy initialization expression of the VarDecl \p VD, or 2751327952Sdim /// nullptr if none exists. 2752344779Sdim BlockVarCopyInit getBlockVarCopyInit(const VarDecl* VD) const; 2753198092Srdivacky 2754341825Sdim /// Allocate an uninitialized TypeSourceInfo. 2755198092Srdivacky /// 2756200583Srdivacky /// The caller should initialize the memory held by TypeSourceInfo using 2757198092Srdivacky /// the TypeLoc wrappers. 2758198092Srdivacky /// 2759198092Srdivacky /// \param T the type that will be the basis for type source info. This type 2760198092Srdivacky /// should refer to how the declarator was written in source code, not to 2761198092Srdivacky /// what type semantic analysis resolved the declarator to. 2762198398Srdivacky /// 2763198398Srdivacky /// \param Size the size of the type info to create, or 0 if the size 2764198398Srdivacky /// should be calculated based on the type. 2765218893Sdim TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const; 2766198092Srdivacky 2767341825Sdim /// Allocate a TypeSourceInfo where all locations have been 2768198893Srdivacky /// initialized to a given location, which defaults to the empty 2769198893Srdivacky /// location. 2770200583Srdivacky TypeSourceInfo * 2771321369Sdim getTrivialTypeSourceInfo(QualType T, 2772218893Sdim SourceLocation Loc = SourceLocation()) const; 2773198893Srdivacky 2774341825Sdim /// Add a deallocation callback that will be invoked when the 2775208600Srdivacky /// ASTContext is destroyed. 2776208600Srdivacky /// 2777243830Sdim /// \param Callback A callback function that will be invoked on destruction. 2778208600Srdivacky /// 2779243830Sdim /// \param Data Pointer data that will be provided to the callback function 2780208600Srdivacky /// when it is called. 2781353358Sdim void AddDeallocation(void (*Callback)(void *), void *Data) const; 2782210299Sed 2783321369Sdim /// If T isn't trivially destructible, calls AddDeallocation to register it 2784321369Sdim /// for destruction. 2785353358Sdim template <typename T> void addDestruction(T *Ptr) const { 2786321369Sdim if (!std::is_trivially_destructible<T>::value) { 2787321369Sdim auto DestroyPtr = [](void *V) { static_cast<T *>(V)->~T(); }; 2788321369Sdim AddDeallocation(DestroyPtr, Ptr); 2789321369Sdim } 2790321369Sdim } 2791321369Sdim 2792276479Sdim GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const; 2793212904Sdim GVALinkage GetGVALinkageForVariable(const VarDecl *VD); 2794212904Sdim 2795341825Sdim /// Determines if the decl can be CodeGen'ed or deserialized from PCH 2796212904Sdim /// lazily, only when used; this is only relevant for function or file scoped 2797212904Sdim /// var definitions. 2798212904Sdim /// 2799212904Sdim /// \returns true if the function/var must be CodeGen'ed/deserialized even if 2800212904Sdim /// it is not used. 2801212904Sdim bool DeclMustBeEmitted(const Decl *D); 2802212904Sdim 2803341825Sdim /// Visits all versions of a multiversioned function with the passed 2804341825Sdim /// predicate. 2805341825Sdim void forEachMultiversionedFunctionVersion( 2806341825Sdim const FunctionDecl *FD, 2807341825Sdim llvm::function_ref<void(FunctionDecl *)> Pred) const; 2808341825Sdim 2809288943Sdim const CXXConstructorDecl * 2810288943Sdim getCopyConstructorForExceptionObject(CXXRecordDecl *RD); 2811288943Sdim 2812288943Sdim void addCopyConstructorForExceptionObject(CXXRecordDecl *RD, 2813288943Sdim CXXConstructorDecl *CD); 2814288943Sdim 2815296417Sdim void addTypedefNameForUnnamedTagDecl(TagDecl *TD, TypedefNameDecl *TND); 2816296417Sdim 2817296417Sdim TypedefNameDecl *getTypedefNameForUnnamedTagDecl(const TagDecl *TD); 2818296417Sdim 2819296417Sdim void addDeclaratorForUnnamedTagDecl(TagDecl *TD, DeclaratorDecl *DD); 2820296417Sdim 2821296417Sdim DeclaratorDecl *getDeclaratorForUnnamedTagDecl(const TagDecl *TD); 2822296417Sdim 2823261991Sdim void setManglingNumber(const NamedDecl *ND, unsigned Number); 2824261991Sdim unsigned getManglingNumber(const NamedDecl *ND) const; 2825249423Sdim 2826276479Sdim void setStaticLocalNumber(const VarDecl *VD, unsigned Number); 2827276479Sdim unsigned getStaticLocalNumber(const VarDecl *VD) const; 2828276479Sdim 2829341825Sdim /// Retrieve the context for computing mangling numbers in the given 2830261991Sdim /// DeclContext. 2831261991Sdim MangleNumberingContext &getManglingNumberContext(const DeclContext *DC); 2832360784Sdim enum NeedExtraManglingDecl_t { NeedExtraManglingDecl }; 2833360784Sdim MangleNumberingContext &getManglingNumberContext(NeedExtraManglingDecl_t, 2834360784Sdim const Decl *D); 2835261991Sdim 2836314564Sdim std::unique_ptr<MangleNumberingContext> createMangleNumberingContext() const; 2837261991Sdim 2838341825Sdim /// Used by ParmVarDecl to store on the side the 2839226633Sdim /// index of the parameter when it exceeds the size of the normal bitfield. 2840226633Sdim void setParameterIndex(const ParmVarDecl *D, unsigned index); 2841226633Sdim 2842341825Sdim /// Used by ParmVarDecl to retrieve on the side the 2843226633Sdim /// index of the parameter when it exceeds the size of the normal bitfield. 2844226633Sdim unsigned getParameterIndex(const ParmVarDecl *D) const; 2845261991Sdim 2846353358Sdim /// Return a string representing the human readable name for the specified 2847353358Sdim /// function declaration or file name. Used by SourceLocExpr and 2848353358Sdim /// PredefinedExpr to cache evaluated results. 2849353358Sdim StringLiteral *getPredefinedStringLiteralFromCache(StringRef Key) const; 2850353358Sdim 2851360784Sdim /// Parses the target attributes passed in, and returns only the ones that are 2852360784Sdim /// valid feature names. 2853360784Sdim ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const; 2854360784Sdim 2855360784Sdim void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap, 2856360784Sdim const FunctionDecl *) const; 2857360784Sdim void getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap, 2858360784Sdim GlobalDecl GD) const; 2859360784Sdim 2860210299Sed //===--------------------------------------------------------------------===// 2861210299Sed // Statistics 2862210299Sed //===--------------------------------------------------------------------===// 2863210299Sed 2864341825Sdim /// The number of implicitly-declared default constructors. 2865353358Sdim unsigned NumImplicitDefaultConstructors = 0; 2866321369Sdim 2867341825Sdim /// The number of implicitly-declared default constructors for 2868210299Sed /// which declarations were built. 2869353358Sdim unsigned NumImplicitDefaultConstructorsDeclared = 0; 2870210299Sed 2871341825Sdim /// The number of implicitly-declared copy constructors. 2872353358Sdim unsigned NumImplicitCopyConstructors = 0; 2873321369Sdim 2874341825Sdim /// The number of implicitly-declared copy constructors for 2875210299Sed /// which declarations were built. 2876353358Sdim unsigned NumImplicitCopyConstructorsDeclared = 0; 2877210299Sed 2878341825Sdim /// The number of implicitly-declared move constructors. 2879353358Sdim unsigned NumImplicitMoveConstructors = 0; 2880223017Sdim 2881341825Sdim /// The number of implicitly-declared move constructors for 2882223017Sdim /// which declarations were built. 2883353358Sdim unsigned NumImplicitMoveConstructorsDeclared = 0; 2884223017Sdim 2885341825Sdim /// The number of implicitly-declared copy assignment operators. 2886353358Sdim unsigned NumImplicitCopyAssignmentOperators = 0; 2887321369Sdim 2888341825Sdim /// The number of implicitly-declared copy assignment operators for 2889210299Sed /// which declarations were built. 2890353358Sdim unsigned NumImplicitCopyAssignmentOperatorsDeclared = 0; 2891210299Sed 2892341825Sdim /// The number of implicitly-declared move assignment operators. 2893353358Sdim unsigned NumImplicitMoveAssignmentOperators = 0; 2894321369Sdim 2895341825Sdim /// The number of implicitly-declared move assignment operators for 2896223017Sdim /// which declarations were built. 2897353358Sdim unsigned NumImplicitMoveAssignmentOperatorsDeclared = 0; 2898223017Sdim 2899341825Sdim /// The number of implicitly-declared destructors. 2900353358Sdim unsigned NumImplicitDestructors = 0; 2901321369Sdim 2902341825Sdim /// The number of implicitly-declared destructors for which 2903210299Sed /// declarations were built. 2904353358Sdim unsigned NumImplicitDestructorsDeclared = 0; 2905321369Sdim 2906226633Sdimpublic: 2907341825Sdim /// Initialize built-in types. 2908226633Sdim /// 2909226633Sdim /// This routine may only be invoked once for a given ASTContext object. 2910276479Sdim /// It is normally invoked after ASTContext construction. 2911226633Sdim /// 2912296417Sdim /// \param Target The target 2913296417Sdim void InitBuiltinTypes(const TargetInfo &Target, 2914296417Sdim const TargetInfo *AuxTarget = nullptr); 2915296417Sdim 2916226633Sdimprivate: 2917198893Srdivacky void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); 2918198092Srdivacky 2919353358Sdim class ObjCEncOptions { 2920353358Sdim unsigned Bits; 2921353358Sdim 2922353358Sdim ObjCEncOptions(unsigned Bits) : Bits(Bits) {} 2923353358Sdim 2924353358Sdim public: 2925353358Sdim ObjCEncOptions() : Bits(0) {} 2926353358Sdim ObjCEncOptions(const ObjCEncOptions &RHS) : Bits(RHS.Bits) {} 2927353358Sdim 2928353358Sdim#define OPT_LIST(V) \ 2929353358Sdim V(ExpandPointedToStructures, 0) \ 2930353358Sdim V(ExpandStructures, 1) \ 2931353358Sdim V(IsOutermostType, 2) \ 2932353358Sdim V(EncodingProperty, 3) \ 2933353358Sdim V(IsStructField, 4) \ 2934353358Sdim V(EncodeBlockParameters, 5) \ 2935353358Sdim V(EncodeClassNames, 6) \ 2936353358Sdim 2937353358Sdim#define V(N,I) ObjCEncOptions& set##N() { Bits |= 1 << I; return *this; } 2938353358SdimOPT_LIST(V) 2939353358Sdim#undef V 2940353358Sdim 2941353358Sdim#define V(N,I) bool N() const { return Bits & 1 << I; } 2942353358SdimOPT_LIST(V) 2943353358Sdim#undef V 2944353358Sdim 2945353358Sdim#undef OPT_LIST 2946353358Sdim 2947353358Sdim LLVM_NODISCARD ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const { 2948353358Sdim return Bits & Mask.Bits; 2949353358Sdim } 2950353358Sdim 2951353358Sdim LLVM_NODISCARD ObjCEncOptions forComponentType() const { 2952353358Sdim ObjCEncOptions Mask = ObjCEncOptions() 2953353358Sdim .setIsOutermostType() 2954353358Sdim .setIsStructField(); 2955353358Sdim return Bits & ~Mask.Bits; 2956353358Sdim } 2957353358Sdim }; 2958353358Sdim 2959243830Sdim // Return the Objective-C type encoding for a given type. 2960198092Srdivacky void getObjCEncodingForTypeImpl(QualType t, std::string &S, 2961353358Sdim ObjCEncOptions Options, 2962193326Sed const FieldDecl *Field, 2963353358Sdim QualType *NotEncodedT = nullptr) const; 2964223017Sdim 2965223017Sdim // Adds the encoding of the structure's members. 2966223017Sdim void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, 2967223017Sdim const FieldDecl *Field, 2968280031Sdim bool includeVBases = true, 2969280031Sdim QualType *NotEncodedT=nullptr) const; 2970327952Sdim 2971276479Sdimpublic: 2972234353Sdim // Adds the encoding of a method parameter or return type. 2973234353Sdim void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, 2974234353Sdim QualType T, std::string& S, 2975234353Sdim bool Extended) const; 2976234353Sdim 2977341825Sdim /// Returns true if this is an inline-initialized static data member 2978276479Sdim /// which is treated as a definition for MSVC compatibility. 2979276479Sdim bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const; 2980309124Sdim 2981309124Sdim enum class InlineVariableDefinitionKind { 2982327952Sdim /// Not an inline variable. 2983327952Sdim None, 2984327952Sdim 2985327952Sdim /// Weak definition of inline variable. 2986327952Sdim Weak, 2987327952Sdim 2988327952Sdim /// Weak for now, might become strong later in this TU. 2989327952Sdim WeakUnknown, 2990327952Sdim 2991327952Sdim /// Strong definition. 2992327952Sdim Strong 2993309124Sdim }; 2994327952Sdim 2995341825Sdim /// Determine whether a definition of this inline variable should 2996309124Sdim /// be treated as a weak or strong definition. For compatibility with 2997309124Sdim /// C++14 and before, for a constexpr static data member, if there is an 2998309124Sdim /// out-of-line declaration of the member, we may promote it from weak to 2999309124Sdim /// strong. 3000309124Sdim InlineVariableDefinitionKind 3001309124Sdim getInlineVariableDefinitionKind(const VarDecl *VD) const; 3002309124Sdim 3003276479Sdimprivate: 3004327952Sdim friend class DeclarationNameTable; 3005327952Sdim friend class DeclContext; 3006327952Sdim 3007218893Sdim const ASTRecordLayout & 3008218893Sdim getObjCLayout(const ObjCInterfaceDecl *D, 3009218893Sdim const ObjCImplementationDecl *Impl) const; 3010212904Sdim 3011341825Sdim /// A set of deallocations that should be performed when the 3012208600Srdivacky /// ASTContext is destroyed. 3013296417Sdim // FIXME: We really should have a better mechanism in the ASTContext to 3014296417Sdim // manage running destructors for types which do variable sized allocation 3015296417Sdim // within the AST. In some places we thread the AST bump pointer allocator 3016296417Sdim // into the datastructures which avoids this mess during deallocation but is 3017296417Sdim // wasteful of memory, and here we require a lot of error prone book keeping 3018296417Sdim // in order to track and run destructors while we're tearing things down. 3019327952Sdim using DeallocationFunctionsAndArguments = 3020327952Sdim llvm::SmallVector<std::pair<void (*)(void *), void *>, 16>; 3021353358Sdim mutable DeallocationFunctionsAndArguments Deallocations; 3022261991Sdim 3023203955Srdivacky // FIXME: This currently contains the set of StoredDeclMaps used 3024203955Srdivacky // by DeclContext objects. This probably should not be in ASTContext, 3025203955Srdivacky // but we include it here so that ASTContext can quickly deallocate them. 3026327952Sdim llvm::PointerIntPair<StoredDeclsMap *, 1> LastSDM; 3027210299Sed 3028344779Sdim std::vector<Decl *> TraversalScope; 3029344779Sdim class ParentMap; 3030360784Sdim std::map<ast_type_traits::TraversalKind, std::unique_ptr<ParentMap>> Parents; 3031276479Sdim 3032276479Sdim std::unique_ptr<VTableContextBase> VTContext; 3033280031Sdim 3034327952Sdim void ReleaseDeclContextMaps(); 3035327952Sdim 3036280031Sdimpublic: 3037280031Sdim enum PragmaSectionFlag : unsigned { 3038280031Sdim PSF_None = 0, 3039280031Sdim PSF_Read = 0x1, 3040280031Sdim PSF_Write = 0x2, 3041280031Sdim PSF_Execute = 0x4, 3042280031Sdim PSF_Implicit = 0x8, 3043280031Sdim PSF_Invalid = 0x80000000U, 3044280031Sdim }; 3045280031Sdim 3046280031Sdim struct SectionInfo { 3047280031Sdim DeclaratorDecl *Decl; 3048280031Sdim SourceLocation PragmaSectionLocation; 3049280031Sdim int SectionFlags; 3050314564Sdim 3051314564Sdim SectionInfo() = default; 3052280031Sdim SectionInfo(DeclaratorDecl *Decl, 3053280031Sdim SourceLocation PragmaSectionLocation, 3054280031Sdim int SectionFlags) 3055327952Sdim : Decl(Decl), PragmaSectionLocation(PragmaSectionLocation), 3056327952Sdim SectionFlags(SectionFlags) {} 3057280031Sdim }; 3058280031Sdim 3059280031Sdim llvm::StringMap<SectionInfo> SectionInfos; 3060193326Sed}; 3061249423Sdim 3062341825Sdim/// Utility function for constructing a nullary selector. 3063327952Sdiminline Selector GetNullarySelector(StringRef name, ASTContext &Ctx) { 3064198893Srdivacky IdentifierInfo* II = &Ctx.Idents.get(name); 3065198893Srdivacky return Ctx.Selectors.getSelector(0, &II); 3066198893Srdivacky} 3067193326Sed 3068341825Sdim/// Utility function for constructing an unary selector. 3069327952Sdiminline Selector GetUnarySelector(StringRef name, ASTContext &Ctx) { 3070198893Srdivacky IdentifierInfo* II = &Ctx.Idents.get(name); 3071198893Srdivacky return Ctx.Selectors.getSelector(1, &II); 3072198893Srdivacky} 3073198893Srdivacky 3074360784Sdimclass TraversalKindScope { 3075360784Sdim ASTContext &Ctx; 3076360784Sdim ast_type_traits::TraversalKind TK = ast_type_traits::TK_AsIs; 3077360784Sdim 3078360784Sdimpublic: 3079360784Sdim TraversalKindScope(ASTContext &Ctx, 3080360784Sdim llvm::Optional<ast_type_traits::TraversalKind> ScopeTK) 3081360784Sdim : Ctx(Ctx) { 3082360784Sdim TK = Ctx.getTraversalKind(); 3083360784Sdim if (ScopeTK) 3084360784Sdim Ctx.setTraversalKind(*ScopeTK); 3085360784Sdim } 3086360784Sdim 3087360784Sdim ~TraversalKindScope() { Ctx.setTraversalKind(TK); } 3088360784Sdim}; 3089360784Sdim 3090327952Sdim} // namespace clang 3091193326Sed 3092193326Sed// operator new and delete aren't allowed inside namespaces. 3093234353Sdim 3094341825Sdim/// Placement new for using the ASTContext's allocator. 3095193326Sed/// 3096193326Sed/// This placement form of operator new uses the ASTContext's allocator for 3097234353Sdim/// obtaining memory. 3098234353Sdim/// 3099344779Sdim/// IMPORTANT: These are also declared in clang/AST/ASTContextAllocate.h! 3100344779Sdim/// Any changes here need to also be made there. 3101234353Sdim/// 3102234353Sdim/// We intentionally avoid using a nothrow specification here so that the calls 3103234353Sdim/// to this operator will not perform a null check on the result -- the 3104234353Sdim/// underlying allocator never returns null pointers. 3105234353Sdim/// 3106193326Sed/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 3107193326Sed/// @code 3108205408Srdivacky/// // Default alignment (8) 3109193326Sed/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 3110193326Sed/// // Specific alignment 3111205408Srdivacky/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments); 3112193326Sed/// @endcode 3113280031Sdim/// Memory allocated through this placement new operator does not need to be 3114280031Sdim/// explicitly freed, as ASTContext will free all of this memory when it gets 3115280031Sdim/// destroyed. Please note that you cannot use delete on the pointer. 3116193326Sed/// 3117193326Sed/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 3118193326Sed/// @param C The ASTContext that provides the allocator. 3119193326Sed/// @param Alignment The alignment of the allocated memory (if the underlying 3120193326Sed/// allocator supports it). 3121327952Sdim/// @return The allocated memory. Could be nullptr. 3122218893Sdiminline void *operator new(size_t Bytes, const clang::ASTContext &C, 3123344779Sdim size_t Alignment /* = 8 */) { 3124193326Sed return C.Allocate(Bytes, Alignment); 3125193326Sed} 3126327952Sdim 3127341825Sdim/// Placement delete companion to the new above. 3128193326Sed/// 3129193326Sed/// This operator is just a companion to the new above. There is no way of 3130193326Sed/// invoking it directly; see the new operator for more details. This operator 3131193326Sed/// is called implicitly by the compiler if a placement new expression using 3132193326Sed/// the ASTContext throws in the object constructor. 3133234353Sdiminline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) { 3134193326Sed C.Deallocate(Ptr); 3135193326Sed} 3136193326Sed 3137193326Sed/// This placement form of operator new[] uses the ASTContext's allocator for 3138234353Sdim/// obtaining memory. 3139234353Sdim/// 3140234353Sdim/// We intentionally avoid using a nothrow specification here so that the calls 3141234353Sdim/// to this operator will not perform a null check on the result -- the 3142234353Sdim/// underlying allocator never returns null pointers. 3143234353Sdim/// 3144193326Sed/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 3145193326Sed/// @code 3146205408Srdivacky/// // Default alignment (8) 3147193326Sed/// char *data = new (Context) char[10]; 3148193326Sed/// // Specific alignment 3149205408Srdivacky/// char *data = new (Context, 4) char[10]; 3150193326Sed/// @endcode 3151280031Sdim/// Memory allocated through this placement new[] operator does not need to be 3152280031Sdim/// explicitly freed, as ASTContext will free all of this memory when it gets 3153280031Sdim/// destroyed. Please note that you cannot use delete on the pointer. 3154193326Sed/// 3155193326Sed/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 3156193326Sed/// @param C The ASTContext that provides the allocator. 3157193326Sed/// @param Alignment The alignment of the allocated memory (if the underlying 3158193326Sed/// allocator supports it). 3159327952Sdim/// @return The allocated memory. Could be nullptr. 3160218893Sdiminline void *operator new[](size_t Bytes, const clang::ASTContext& C, 3161344779Sdim size_t Alignment /* = 8 */) { 3162193326Sed return C.Allocate(Bytes, Alignment); 3163193326Sed} 3164193326Sed 3165341825Sdim/// Placement delete[] companion to the new[] above. 3166193326Sed/// 3167193326Sed/// This operator is just a companion to the new[] above. There is no way of 3168193326Sed/// invoking it directly; see the new[] operator for more details. This operator 3169193326Sed/// is called implicitly by the compiler if a placement new[] expression using 3170193326Sed/// the ASTContext throws in the object constructor. 3171234353Sdiminline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) { 3172193326Sed C.Deallocate(Ptr); 3173193326Sed} 3174193326Sed 3175341825Sdim/// Create the representation of a LazyGenerationalUpdatePtr. 3176276479Sdimtemplate <typename Owner, typename T, 3177276479Sdim void (clang::ExternalASTSource::*Update)(Owner)> 3178276479Sdimtypename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType 3179276479Sdim clang::LazyGenerationalUpdatePtr<Owner, T, Update>::makeValue( 3180276479Sdim const clang::ASTContext &Ctx, T Value) { 3181276479Sdim // Note, this is implemented here so that ExternalASTSource.h doesn't need to 3182276479Sdim // include ASTContext.h. We explicitly instantiate it for all relevant types 3183276479Sdim // in ASTContext.cpp. 3184276479Sdim if (auto *Source = Ctx.getExternalSource()) 3185276479Sdim return new (Ctx) LazyData(Source, Value); 3186276479Sdim return Value; 3187276479Sdim} 3188276479Sdim 3189314564Sdim#endif // LLVM_CLANG_AST_ASTCONTEXT_H 3190