1193326Sed//===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9243830Sdim/// 10243830Sdim/// \file 11243830Sdim/// \brief Defines the clang::ASTContext interface. 12243830Sdim/// 13193326Sed//===----------------------------------------------------------------------===// 14193326Sed 15193326Sed#ifndef LLVM_CLANG_AST_ASTCONTEXT_H 16193326Sed#define LLVM_CLANG_AST_ASTCONTEXT_H 17193326Sed 18249423Sdim#include "clang/AST/ASTTypeTraits.h" 19249423Sdim#include "clang/AST/CanonicalType.h" 20249423Sdim#include "clang/AST/CommentCommandTraits.h" 21249423Sdim#include "clang/AST/Decl.h" 22249423Sdim#include "clang/AST/NestedNameSpecifier.h" 23249423Sdim#include "clang/AST/PrettyPrinter.h" 24249423Sdim#include "clang/AST/RawCommentList.h" 25249423Sdim#include "clang/AST/TemplateName.h" 26249423Sdim#include "clang/AST/Type.h" 27221345Sdim#include "clang/Basic/AddressSpaces.h" 28193326Sed#include "clang/Basic/IdentifierTable.h" 29193326Sed#include "clang/Basic/LangOptions.h" 30198893Srdivacky#include "clang/Basic/OperatorKinds.h" 31206084Srdivacky#include "clang/Basic/PartialDiagnostic.h" 32221345Sdim#include "clang/Basic/VersionTuple.h" 33193326Sed#include "llvm/ADT/DenseMap.h" 34193326Sed#include "llvm/ADT/FoldingSet.h" 35221345Sdim#include "llvm/ADT/IntrusiveRefCntPtr.h" 36193326Sed#include "llvm/ADT/OwningPtr.h" 37203955Srdivacky#include "llvm/ADT/SmallPtrSet.h" 38234353Sdim#include "llvm/ADT/TinyPtrVector.h" 39193326Sed#include "llvm/Support/Allocator.h" 40193326Sed#include <vector> 41193326Sed 42193326Sednamespace llvm { 43193326Sed struct fltSemantics; 44193326Sed} 45193326Sed 46193326Sednamespace clang { 47193326Sed class FileManager; 48263508Sdim class AtomicExpr; 49193326Sed class ASTRecordLayout; 50199482Srdivacky class BlockExpr; 51201361Srdivacky class CharUnits; 52226633Sdim class DiagnosticsEngine; 53193326Sed class Expr; 54193326Sed class ExternalASTSource; 55218893Sdim class ASTMutationListener; 56193326Sed class IdentifierTable; 57263508Sdim class MaterializeTemporaryExpr; 58193326Sed class SelectorTable; 59193326Sed class TargetInfo; 60212904Sdim class CXXABI; 61263508Sdim class MangleNumberingContext; 62193326Sed // Decls 63218893Sdim class MangleContext; 64198092Srdivacky class ObjCIvarDecl; 65193326Sed class ObjCPropertyDecl; 66249423Sdim class UnresolvedSetIterator; 67198092Srdivacky class UsingDecl; 68200583Srdivacky class UsingShadowDecl; 69198092Srdivacky 70194179Sed namespace Builtin { class Context; } 71198092Srdivacky 72239462Sdim namespace comments { 73239462Sdim class FullComment; 74239462Sdim } 75239462Sdim 76243830Sdim/// \brief Holds long-lived AST nodes (such as types and decls) that can be 77243830Sdim/// referred to throughout the semantic analysis of a file. 78234353Sdimclass ASTContext : public RefCountedBase<ASTContext> { 79210299Sed ASTContext &this_() { return *this; } 80210299Sed 81249423Sdim mutable SmallVector<Type *, 0> Types; 82218893Sdim mutable llvm::FoldingSet<ExtQuals> ExtQualNodes; 83218893Sdim mutable llvm::FoldingSet<ComplexType> ComplexTypes; 84218893Sdim mutable llvm::FoldingSet<PointerType> PointerTypes; 85263508Sdim mutable llvm::FoldingSet<DecayedType> DecayedTypes; 86218893Sdim mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes; 87218893Sdim mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes; 88218893Sdim mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes; 89218893Sdim mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes; 90218893Sdim mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes; 91218893Sdim mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes; 92218893Sdim mutable std::vector<VariableArrayType*> VariableArrayTypes; 93218893Sdim mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes; 94218893Sdim mutable llvm::FoldingSet<DependentSizedExtVectorType> 95218893Sdim DependentSizedExtVectorTypes; 96218893Sdim mutable llvm::FoldingSet<VectorType> VectorTypes; 97218893Sdim mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes; 98221345Sdim mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&> 99221345Sdim FunctionProtoTypes; 100218893Sdim mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes; 101218893Sdim mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes; 102218893Sdim mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes; 103218893Sdim mutable llvm::FoldingSet<SubstTemplateTypeParmType> 104218893Sdim SubstTemplateTypeParmTypes; 105218893Sdim mutable llvm::FoldingSet<SubstTemplateTypeParmPackType> 106218893Sdim SubstTemplateTypeParmPackTypes; 107218893Sdim mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&> 108210299Sed TemplateSpecializationTypes; 109218893Sdim mutable llvm::FoldingSet<ParenType> ParenTypes; 110218893Sdim mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes; 111218893Sdim mutable llvm::FoldingSet<DependentNameType> DependentNameTypes; 112218893Sdim mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType, 113218893Sdim ASTContext&> 114210299Sed DependentTemplateSpecializationTypes; 115218893Sdim llvm::FoldingSet<PackExpansionType> PackExpansionTypes; 116218893Sdim mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes; 117218893Sdim mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes; 118219077Sdim mutable llvm::FoldingSet<AutoType> AutoTypes; 119226633Sdim mutable llvm::FoldingSet<AtomicType> AtomicTypes; 120218893Sdim llvm::FoldingSet<AttributedType> AttributedTypes; 121193326Sed 122218893Sdim mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames; 123218893Sdim mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames; 124224145Sdim mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage> 125224145Sdim SubstTemplateTemplateParms; 126224145Sdim mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage, 127224145Sdim ASTContext&> 128218893Sdim SubstTemplateTemplateParmPacks; 129218893Sdim 130193326Sed /// \brief The set of nested name specifiers. 131193326Sed /// 132193326Sed /// This set is managed by the NestedNameSpecifier class. 133218893Sdim mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers; 134218893Sdim mutable NestedNameSpecifier *GlobalNestedNameSpecifier; 135193326Sed friend class NestedNameSpecifier; 136193326Sed 137243830Sdim /// \brief A cache mapping from RecordDecls to ASTRecordLayouts. 138243830Sdim /// 139243830Sdim /// This is lazily created. This is intentionally not serialized. 140218893Sdim mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*> 141218893Sdim ASTRecordLayouts; 142218893Sdim mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*> 143218893Sdim ObjCLayouts; 144193326Sed 145243830Sdim /// \brief A cache from types to size and alignment information. 146234353Sdim typedef llvm::DenseMap<const Type*, 147234353Sdim std::pair<uint64_t, unsigned> > TypeInfoMap; 148234353Sdim mutable TypeInfoMap MemoizedTypeInfo; 149234353Sdim 150243830Sdim /// \brief A cache mapping from CXXRecordDecls to key functions. 151263508Sdim llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions; 152200583Srdivacky 153198092Srdivacky /// \brief Mapping from ObjCContainers to their ObjCImplementations. 154198092Srdivacky llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls; 155226633Sdim 156226633Sdim /// \brief Mapping from ObjCMethod to its duplicate declaration in the same 157226633Sdim /// interface. 158226633Sdim llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls; 159198092Srdivacky 160218893Sdim /// \brief Mapping from __block VarDecls to their copy initialization expr. 161218893Sdim llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits; 162218893Sdim 163226633Sdim /// \brief Mapping from class scope functions specialization to their 164243830Sdim /// template patterns. 165226633Sdim llvm::DenseMap<const FunctionDecl*, FunctionDecl*> 166226633Sdim ClassScopeSpecializationPattern; 167226633Sdim 168263508Sdim /// \brief Mapping from materialized temporaries with static storage duration 169263508Sdim /// that appear in constant initializers to their evaluated values. 170263508Sdim llvm::DenseMap<const MaterializeTemporaryExpr*, APValue> 171263508Sdim MaterializedTemporaryValues; 172263508Sdim 173210299Sed /// \brief Representation of a "canonical" template template parameter that 174210299Sed /// is used in canonical template names. 175210299Sed class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode { 176210299Sed TemplateTemplateParmDecl *Parm; 177210299Sed 178210299Sed public: 179210299Sed CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm) 180210299Sed : Parm(Parm) { } 181210299Sed 182210299Sed TemplateTemplateParmDecl *getParam() const { return Parm; } 183210299Sed 184210299Sed void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); } 185210299Sed 186210299Sed static void Profile(llvm::FoldingSetNodeID &ID, 187210299Sed TemplateTemplateParmDecl *Parm); 188210299Sed }; 189218893Sdim mutable llvm::FoldingSet<CanonicalTemplateTemplateParm> 190218893Sdim CanonTemplateTemplateParms; 191210299Sed 192218893Sdim TemplateTemplateParmDecl * 193218893Sdim getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const; 194210299Sed 195226633Sdim /// \brief The typedef for the __int128_t type. 196226633Sdim mutable TypedefDecl *Int128Decl; 197210299Sed 198226633Sdim /// \brief The typedef for the __uint128_t type. 199226633Sdim mutable TypedefDecl *UInt128Decl; 200263508Sdim 201263508Sdim /// \brief The typedef for the __float128 stub type. 202263508Sdim mutable TypeDecl *Float128StubDecl; 203226633Sdim 204239462Sdim /// \brief The typedef for the target specific predefined 205239462Sdim /// __builtin_va_list type. 206239462Sdim mutable TypedefDecl *BuiltinVaListDecl; 207194613Sed 208243830Sdim /// \brief The typedef for the predefined \c id type. 209226633Sdim mutable TypedefDecl *ObjCIdDecl; 210226633Sdim 211243830Sdim /// \brief The typedef for the predefined \c SEL type. 212226633Sdim mutable TypedefDecl *ObjCSelDecl; 213198092Srdivacky 214243830Sdim /// \brief The typedef for the predefined \c Class type. 215226633Sdim mutable TypedefDecl *ObjCClassDecl; 216234353Sdim 217243830Sdim /// \brief The typedef for the predefined \c Protocol class in Objective-C. 218234353Sdim mutable ObjCInterfaceDecl *ObjCProtocolClassDecl; 219243830Sdim 220243830Sdim /// \brief The typedef for the predefined 'BOOL' type. 221243830Sdim mutable TypedefDecl *BOOLDecl; 222234353Sdim 223226633Sdim // Typedefs which may be provided defining the structure of Objective-C 224226633Sdim // pseudo-builtins 225226633Sdim QualType ObjCIdRedefinitionType; 226226633Sdim QualType ObjCClassRedefinitionType; 227226633Sdim QualType ObjCSelRedefinitionType; 228198092Srdivacky 229193326Sed QualType ObjCConstantStringType; 230218893Sdim mutable RecordDecl *CFConstantStringTypeDecl; 231234353Sdim 232249423Sdim mutable QualType ObjCSuperType; 233249423Sdim 234234353Sdim QualType ObjCNSStringType; 235193326Sed 236226633Sdim /// \brief The typedef declaration for the Objective-C "instancetype" type. 237226633Sdim TypedefDecl *ObjCInstanceTypeDecl; 238226633Sdim 239198092Srdivacky /// \brief The type for the C FILE type. 240198092Srdivacky TypeDecl *FILEDecl; 241198092Srdivacky 242198092Srdivacky /// \brief The type for the C jmp_buf type. 243198092Srdivacky TypeDecl *jmp_bufDecl; 244198092Srdivacky 245198092Srdivacky /// \brief The type for the C sigjmp_buf type. 246198092Srdivacky TypeDecl *sigjmp_bufDecl; 247198092Srdivacky 248227737Sdim /// \brief The type for the C ucontext_t type. 249227737Sdim TypeDecl *ucontext_tDecl; 250227737Sdim 251198398Srdivacky /// \brief Type for the Block descriptor for Blocks CodeGen. 252226633Sdim /// 253226633Sdim /// Since this is only used for generation of debug info, it is not 254226633Sdim /// serialized. 255218893Sdim mutable RecordDecl *BlockDescriptorType; 256198398Srdivacky 257198398Srdivacky /// \brief Type for the Block descriptor for Blocks CodeGen. 258226633Sdim /// 259226633Sdim /// Since this is only used for generation of debug info, it is not 260226633Sdim /// serialized. 261218893Sdim mutable RecordDecl *BlockDescriptorExtendedType; 262198398Srdivacky 263218893Sdim /// \brief Declaration for the CUDA cudaConfigureCall function. 264218893Sdim FunctionDecl *cudaConfigureCallDecl; 265218893Sdim 266210299Sed TypeSourceInfo NullTypeSourceInfo; 267210299Sed 268198092Srdivacky /// \brief Keeps track of all declaration attributes. 269194613Sed /// 270194613Sed /// Since so few decls have attrs, we keep them in a hash map instead of 271194613Sed /// wasting space in the Decl class. 272212904Sdim llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs; 273198092Srdivacky 274263508Sdim /// \brief A mapping from non-redeclarable declarations in modules that were 275263508Sdim /// merged with other declarations to the canonical declaration that they were 276263508Sdim /// merged into. 277263508Sdim llvm::DenseMap<Decl*, Decl*> MergedDecls; 278263508Sdim 279263508Sdimpublic: 280263508Sdim /// \brief A type synonym for the TemplateOrInstantiation mapping. 281263508Sdim typedef llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *> 282263508Sdim TemplateOrSpecializationInfo; 283263508Sdim 284263508Sdimprivate: 285263508Sdim 286263508Sdim /// \brief A mapping to contain the template or declaration that 287263508Sdim /// a variable declaration describes or was instantiated from, 288263508Sdim /// respectively. 289198092Srdivacky /// 290263508Sdim /// For non-templates, this value will be NULL. For variable 291263508Sdim /// declarations that describe a variable template, this will be a 292263508Sdim /// pointer to a VarTemplateDecl. For static data members 293263508Sdim /// of class template specializations, this will be the 294263508Sdim /// MemberSpecializationInfo referring to the member variable that was 295263508Sdim /// instantiated or specialized. Thus, the mapping will keep track of 296263508Sdim /// the static data member templates from which static data members of 297263508Sdim /// class template specializations were instantiated. 298198092Srdivacky /// 299198092Srdivacky /// Given the following example: 300198092Srdivacky /// 301198092Srdivacky /// \code 302198092Srdivacky /// template<typename T> 303198092Srdivacky /// struct X { 304198092Srdivacky /// static T value; 305198092Srdivacky /// }; 306198092Srdivacky /// 307198092Srdivacky /// template<typename T> 308198092Srdivacky /// T X<T>::value = T(17); 309198092Srdivacky /// 310198092Srdivacky /// int *x = &X<int>::value; 311198092Srdivacky /// \endcode 312198092Srdivacky /// 313198092Srdivacky /// This mapping will contain an entry that maps from the VarDecl for 314198092Srdivacky /// X<int>::value to the corresponding VarDecl for X<T>::value (within the 315198092Srdivacky /// class template X) and will be marked TSK_ImplicitInstantiation. 316263508Sdim llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo> 317263508Sdim TemplateOrInstantiation; 318198092Srdivacky 319200583Srdivacky /// \brief Keeps track of the declaration from which a UsingDecl was 320243830Sdim /// created during instantiation. 321198092Srdivacky /// 322243830Sdim /// The source declaration is always a UsingDecl, an UnresolvedUsingValueDecl, 323243830Sdim /// or an UnresolvedUsingTypenameDecl. 324243830Sdim /// 325198092Srdivacky /// For example: 326198092Srdivacky /// \code 327198092Srdivacky /// template<typename T> 328198092Srdivacky /// struct A { 329198092Srdivacky /// void f(); 330198092Srdivacky /// }; 331198092Srdivacky /// 332198092Srdivacky /// template<typename T> 333198092Srdivacky /// struct B : A<T> { 334198092Srdivacky /// using A<T>::f; 335198092Srdivacky /// }; 336198092Srdivacky /// 337198092Srdivacky /// template struct B<int>; 338198092Srdivacky /// \endcode 339198092Srdivacky /// 340198092Srdivacky /// This mapping will contain an entry that maps from the UsingDecl in 341198092Srdivacky /// B<int> to the UnresolvedUsingDecl in B<T>. 342200583Srdivacky llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl; 343198092Srdivacky 344200583Srdivacky llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*> 345200583Srdivacky InstantiatedFromUsingShadowDecl; 346200583Srdivacky 347198092Srdivacky llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl; 348198092Srdivacky 349204643Srdivacky /// \brief Mapping that stores the methods overridden by a given C++ 350204643Srdivacky /// member function. 351204643Srdivacky /// 352204643Srdivacky /// Since most C++ member functions aren't virtual and therefore 353204643Srdivacky /// don't override anything, we store the overridden functions in 354204643Srdivacky /// this map on the side rather than within the CXXMethodDecl structure. 355234353Sdim typedef llvm::TinyPtrVector<const CXXMethodDecl*> CXXMethodVector; 356204643Srdivacky llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods; 357204643Srdivacky 358263508Sdim /// \brief Mapping from each declaration context to its corresponding 359263508Sdim /// mangling numbering context (used for constructs like lambdas which 360263508Sdim /// need to be consistently numbered for the mangler). 361263508Sdim llvm::DenseMap<const DeclContext *, MangleNumberingContext *> 362263508Sdim MangleNumberingContexts; 363249423Sdim 364263508Sdim /// \brief Side-table of mangling numbers for declarations which rarely 365263508Sdim /// need them (like static local vars). 366263508Sdim llvm::DenseMap<const NamedDecl *, unsigned> MangleNumbers; 367249423Sdim 368243830Sdim /// \brief Mapping that stores parameterIndex values for ParmVarDecls when 369243830Sdim /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex. 370226633Sdim typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable; 371226633Sdim ParameterIndexTable ParamIndices; 372226633Sdim 373234353Sdim ImportDecl *FirstLocalImport; 374234353Sdim ImportDecl *LastLocalImport; 375234353Sdim 376193326Sed TranslationUnitDecl *TUDecl; 377193326Sed 378243830Sdim /// \brief The associated SourceManager object.a 379193326Sed SourceManager &SourceMgr; 380198092Srdivacky 381243830Sdim /// \brief The language options used to create the AST associated with 382193326Sed /// this ASTContext object. 383226633Sdim LangOptions &LangOpts; 384193326Sed 385212904Sdim /// \brief The allocator used to create AST objects. 386212904Sdim /// 387212904Sdim /// AST objects are never destructed; rather, all memory associated with the 388212904Sdim /// AST objects will be released when the ASTContext itself is destroyed. 389218893Sdim mutable llvm::BumpPtrAllocator BumpAlloc; 390198092Srdivacky 391206084Srdivacky /// \brief Allocator for partial diagnostics. 392206084Srdivacky PartialDiagnostic::StorageAllocator DiagAllocator; 393212904Sdim 394212904Sdim /// \brief The current C++ ABI. 395234353Sdim OwningPtr<CXXABI> ABI; 396212904Sdim CXXABI *createCXXABI(const TargetInfo &T); 397218893Sdim 398221345Sdim /// \brief The logical -> physical address space map. 399226633Sdim const LangAS::Map *AddrSpaceMap; 400221345Sdim 401263508Sdim /// \brief Address space map mangling must be used with language specific 402263508Sdim /// address spaces (e.g. OpenCL/CUDA) 403263508Sdim bool AddrSpaceMapMangling; 404263508Sdim 405218893Sdim friend class ASTDeclReader; 406226633Sdim friend class ASTReader; 407226633Sdim friend class ASTWriter; 408234353Sdim friend class CXXRecordDecl; 409234353Sdim 410226633Sdim const TargetInfo *Target; 411226633Sdim clang::PrintingPolicy PrintingPolicy; 412226633Sdim 413198092Srdivackypublic: 414193326Sed IdentifierTable &Idents; 415193326Sed SelectorTable &Selectors; 416194179Sed Builtin::Context &BuiltinInfo; 417218893Sdim mutable DeclarationNameTable DeclarationNames; 418234353Sdim OwningPtr<ExternalASTSource> ExternalSource; 419218893Sdim ASTMutationListener *Listener; 420193326Sed 421249423Sdim /// \brief Contains parents of a node. 422249423Sdim typedef llvm::SmallVector<ast_type_traits::DynTypedNode, 1> ParentVector; 423249423Sdim 424249423Sdim /// \brief Maps from a node to its parents. 425249423Sdim typedef llvm::DenseMap<const void *, ParentVector> ParentMap; 426249423Sdim 427249423Sdim /// \brief Returns the parents of the given node. 428249423Sdim /// 429249423Sdim /// Note that this will lazily compute the parents of all nodes 430249423Sdim /// and store them for later retrieval. Thus, the first call is O(n) 431249423Sdim /// in the number of AST nodes. 432249423Sdim /// 433249423Sdim /// Caveats and FIXMEs: 434249423Sdim /// Calculating the parent map over all AST nodes will need to load the 435249423Sdim /// full AST. This can be undesirable in the case where the full AST is 436249423Sdim /// expensive to create (for example, when using precompiled header 437249423Sdim /// preambles). Thus, there are good opportunities for optimization here. 438249423Sdim /// One idea is to walk the given node downwards, looking for references 439249423Sdim /// to declaration contexts - once a declaration context is found, compute 440249423Sdim /// the parent map for the declaration context; if that can satisfy the 441249423Sdim /// request, loading the whole AST can be avoided. Note that this is made 442249423Sdim /// more complex by statements in templates having multiple parents - those 443249423Sdim /// problems can be solved by building closure over the templated parts of 444249423Sdim /// the AST, which also avoids touching large parts of the AST. 445249423Sdim /// Additionally, we will want to add an interface to already give a hint 446249423Sdim /// where to search for the parents, for example when looking at a statement 447249423Sdim /// inside a certain function. 448249423Sdim /// 449249423Sdim /// 'NodeT' can be one of Decl, Stmt, Type, TypeLoc, 450249423Sdim /// NestedNameSpecifier or NestedNameSpecifierLoc. 451249423Sdim template <typename NodeT> 452249423Sdim ParentVector getParents(const NodeT &Node) { 453249423Sdim return getParents(ast_type_traits::DynTypedNode::create(Node)); 454249423Sdim } 455249423Sdim 456263508Sdim ParentVector getParents(const ast_type_traits::DynTypedNode &Node); 457249423Sdim 458243830Sdim const clang::PrintingPolicy &getPrintingPolicy() const { 459243830Sdim return PrintingPolicy; 460243830Sdim } 461198092Srdivacky 462243830Sdim void setPrintingPolicy(const clang::PrintingPolicy &Policy) { 463226633Sdim PrintingPolicy = Policy; 464226633Sdim } 465226633Sdim 466193326Sed SourceManager& getSourceManager() { return SourceMgr; } 467193326Sed const SourceManager& getSourceManager() const { return SourceMgr; } 468239462Sdim 469239462Sdim llvm::BumpPtrAllocator &getAllocator() const { 470239462Sdim return BumpAlloc; 471239462Sdim } 472239462Sdim 473263508Sdim void *Allocate(size_t Size, unsigned Align = 8) const { 474212904Sdim return BumpAlloc.Allocate(Size, Align); 475193326Sed } 476218893Sdim void Deallocate(void *Ptr) const { } 477206084Srdivacky 478221345Sdim /// Return the total amount of physical memory allocated for representing 479221345Sdim /// AST nodes and type information. 480221345Sdim size_t getASTAllocatedMemory() const { 481221345Sdim return BumpAlloc.getTotalMemory(); 482221345Sdim } 483221345Sdim /// Return the total memory used for various side tables. 484221345Sdim size_t getSideTableAllocatedMemory() const; 485221345Sdim 486206084Srdivacky PartialDiagnostic::StorageAllocator &getDiagAllocator() { 487206084Srdivacky return DiagAllocator; 488206084Srdivacky } 489206084Srdivacky 490226633Sdim const TargetInfo &getTargetInfo() const { return *Target; } 491226633Sdim 492263508Sdim /// getIntTypeForBitwidth - 493263508Sdim /// sets integer QualTy according to specified details: 494263508Sdim /// bitwidth, signed/unsigned. 495263508Sdim /// Returns empty type if there is no appropriate target types. 496263508Sdim QualType getIntTypeForBitwidth(unsigned DestWidth, 497263508Sdim unsigned Signed) const; 498263508Sdim /// getRealTypeForBitwidth - 499263508Sdim /// sets floating point QualTy according to specified bitwidth. 500263508Sdim /// Returns empty type if there is no appropriate target types. 501263508Sdim QualType getRealTypeForBitwidth(unsigned DestWidth) const; 502263508Sdim 503263508Sdim bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const; 504263508Sdim 505234353Sdim const LangOptions& getLangOpts() const { return LangOpts; } 506198092Srdivacky 507226633Sdim DiagnosticsEngine &getDiagnostics() const; 508218893Sdim 509198092Srdivacky FullSourceLoc getFullLoc(SourceLocation Loc) const { 510193326Sed return FullSourceLoc(Loc,SourceMgr); 511193326Sed } 512193326Sed 513239462Sdim /// \brief All comments in this translation unit. 514239462Sdim RawCommentList Comments; 515239462Sdim 516239462Sdim /// \brief True if comments are already loaded from ExternalASTSource. 517239462Sdim mutable bool CommentsLoaded; 518239462Sdim 519239462Sdim class RawCommentAndCacheFlags { 520239462Sdim public: 521239462Sdim enum Kind { 522239462Sdim /// We searched for a comment attached to the particular declaration, but 523239462Sdim /// didn't find any. 524239462Sdim /// 525239462Sdim /// getRaw() == 0. 526239462Sdim NoCommentInDecl = 0, 527239462Sdim 528239462Sdim /// We have found a comment attached to this particular declaration. 529239462Sdim /// 530239462Sdim /// getRaw() != 0. 531239462Sdim FromDecl, 532239462Sdim 533239462Sdim /// This declaration does not have an attached comment, and we have 534239462Sdim /// searched the redeclaration chain. 535239462Sdim /// 536239462Sdim /// If getRaw() == 0, the whole redeclaration chain does not have any 537239462Sdim /// comments. 538239462Sdim /// 539239462Sdim /// If getRaw() != 0, it is a comment propagated from other 540239462Sdim /// redeclaration. 541239462Sdim FromRedecl 542239462Sdim }; 543239462Sdim 544239462Sdim Kind getKind() const LLVM_READONLY { 545239462Sdim return Data.getInt(); 546239462Sdim } 547239462Sdim 548239462Sdim void setKind(Kind K) { 549239462Sdim Data.setInt(K); 550239462Sdim } 551239462Sdim 552239462Sdim const RawComment *getRaw() const LLVM_READONLY { 553239462Sdim return Data.getPointer(); 554239462Sdim } 555239462Sdim 556239462Sdim void setRaw(const RawComment *RC) { 557239462Sdim Data.setPointer(RC); 558239462Sdim } 559239462Sdim 560239462Sdim const Decl *getOriginalDecl() const LLVM_READONLY { 561239462Sdim return OriginalDecl; 562239462Sdim } 563239462Sdim 564239462Sdim void setOriginalDecl(const Decl *Orig) { 565239462Sdim OriginalDecl = Orig; 566239462Sdim } 567239462Sdim 568239462Sdim private: 569239462Sdim llvm::PointerIntPair<const RawComment *, 2, Kind> Data; 570239462Sdim const Decl *OriginalDecl; 571239462Sdim }; 572239462Sdim 573239462Sdim /// \brief Mapping from declarations to comments attached to any 574239462Sdim /// redeclaration. 575239462Sdim /// 576239462Sdim /// Raw comments are owned by Comments list. This mapping is populated 577239462Sdim /// lazily. 578239462Sdim mutable llvm::DenseMap<const Decl *, RawCommentAndCacheFlags> RedeclComments; 579239462Sdim 580239462Sdim /// \brief Mapping from declarations to parsed comments attached to any 581239462Sdim /// redeclaration. 582239462Sdim mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments; 583239462Sdim 584239462Sdim /// \brief Return the documentation comment attached to a given declaration, 585239462Sdim /// without looking into cache. 586239462Sdim RawComment *getRawCommentForDeclNoCache(const Decl *D) const; 587239462Sdim 588239462Sdimpublic: 589239462Sdim RawCommentList &getRawCommentList() { 590239462Sdim return Comments; 591239462Sdim } 592239462Sdim 593239462Sdim void addComment(const RawComment &RC) { 594243830Sdim assert(LangOpts.RetainCommentsFromSystemHeaders || 595243830Sdim !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin())); 596239462Sdim Comments.addComment(RC, BumpAlloc); 597239462Sdim } 598239462Sdim 599239462Sdim /// \brief Return the documentation comment attached to a given declaration. 600239462Sdim /// Returns NULL if no comment is attached. 601239462Sdim /// 602239462Sdim /// \param OriginalDecl if not NULL, is set to declaration AST node that had 603239462Sdim /// the comment, if the comment we found comes from a redeclaration. 604239462Sdim const RawComment *getRawCommentForAnyRedecl( 605239462Sdim const Decl *D, 606239462Sdim const Decl **OriginalDecl = NULL) const; 607239462Sdim 608239462Sdim /// Return parsed documentation comment attached to a given declaration. 609239462Sdim /// Returns NULL if no comment is attached. 610243830Sdim /// 611243830Sdim /// \param PP the Preprocessor used with this TU. Could be NULL if 612243830Sdim /// preprocessor is not available. 613243830Sdim comments::FullComment *getCommentForDecl(const Decl *D, 614243830Sdim const Preprocessor *PP) const; 615263508Sdim 616263508Sdim /// Return parsed documentation comment attached to a given declaration. 617263508Sdim /// Returns NULL if no comment is attached. Does not look at any 618263508Sdim /// redeclarations of the declaration. 619263508Sdim comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const; 620263508Sdim 621243830Sdim comments::FullComment *cloneFullComment(comments::FullComment *FC, 622243830Sdim const Decl *D) const; 623239462Sdim 624243830Sdimprivate: 625243830Sdim mutable comments::CommandTraits CommentCommandTraits; 626243830Sdim 627243830Sdimpublic: 628243830Sdim comments::CommandTraits &getCommentCommandTraits() const { 629243830Sdim return CommentCommandTraits; 630243830Sdim } 631243830Sdim 632194613Sed /// \brief Retrieve the attributes for the given declaration. 633212904Sdim AttrVec& getDeclAttrs(const Decl *D); 634198092Srdivacky 635194613Sed /// \brief Erase the attributes corresponding to the given declaration. 636212904Sdim void eraseDeclAttrs(const Decl *D); 637198092Srdivacky 638198092Srdivacky /// \brief If this variable is an instantiated static data member of a 639198092Srdivacky /// class template specialization, returns the templated static data member 640198092Srdivacky /// from which it was instantiated. 641263508Sdim // FIXME: Remove ? 642198112Srdivacky MemberSpecializationInfo *getInstantiatedFromStaticDataMember( 643198112Srdivacky const VarDecl *Var); 644198092Srdivacky 645263508Sdim TemplateOrSpecializationInfo 646263508Sdim getTemplateOrSpecializationInfo(const VarDecl *Var); 647263508Sdim 648226633Sdim FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD); 649226633Sdim 650226633Sdim void setClassScopeSpecializationPattern(FunctionDecl *FD, 651226633Sdim FunctionDecl *Pattern); 652226633Sdim 653198092Srdivacky /// \brief Note that the static data member \p Inst is an instantiation of 654198092Srdivacky /// the static data member template \p Tmpl of a class template. 655198092Srdivacky void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, 656210299Sed TemplateSpecializationKind TSK, 657210299Sed SourceLocation PointOfInstantiation = SourceLocation()); 658198092Srdivacky 659263508Sdim void setTemplateOrSpecializationInfo(VarDecl *Inst, 660263508Sdim TemplateOrSpecializationInfo TSI); 661263508Sdim 662243830Sdim /// \brief If the given using decl \p Inst is an instantiation of a 663200583Srdivacky /// (possibly unresolved) using decl from a template instantiation, 664198092Srdivacky /// return it. 665200583Srdivacky NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst); 666198092Srdivacky 667200583Srdivacky /// \brief Remember that the using decl \p Inst is an instantiation 668200583Srdivacky /// of the using decl \p Pattern of a class template. 669200583Srdivacky void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern); 670198092Srdivacky 671200583Srdivacky void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, 672200583Srdivacky UsingShadowDecl *Pattern); 673200583Srdivacky UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst); 674198092Srdivacky 675198092Srdivacky FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field); 676198092Srdivacky 677198092Srdivacky void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl); 678221345Sdim 679204643Srdivacky // Access to the set of methods overridden by the given C++ method. 680234353Sdim typedef CXXMethodVector::const_iterator overridden_cxx_method_iterator; 681204643Srdivacky overridden_cxx_method_iterator 682204643Srdivacky overridden_methods_begin(const CXXMethodDecl *Method) const; 683204643Srdivacky 684204643Srdivacky overridden_cxx_method_iterator 685204643Srdivacky overridden_methods_end(const CXXMethodDecl *Method) const; 686204643Srdivacky 687210299Sed unsigned overridden_methods_size(const CXXMethodDecl *Method) const; 688210299Sed 689204643Srdivacky /// \brief Note that the given C++ \p Method overrides the given \p 690204643Srdivacky /// Overridden method. 691204643Srdivacky void addOverriddenMethod(const CXXMethodDecl *Method, 692204643Srdivacky const CXXMethodDecl *Overridden); 693243830Sdim 694243830Sdim /// \brief Return C++ or ObjC overridden methods for the given \p Method. 695243830Sdim /// 696243830Sdim /// An ObjC method is considered to override any method in the class's 697243830Sdim /// base classes, its protocols, or its categories' protocols, that has 698243830Sdim /// the same selector and is of the same kind (class or instance). 699243830Sdim /// A method in an implementation is not considered as overriding the same 700243830Sdim /// method in the interface or its categories. 701243830Sdim void getOverriddenMethods( 702243830Sdim const NamedDecl *Method, 703243830Sdim SmallVectorImpl<const NamedDecl *> &Overridden) const; 704204643Srdivacky 705234353Sdim /// \brief Notify the AST context that a new import declaration has been 706234353Sdim /// parsed or implicitly created within this translation unit. 707234353Sdim void addedLocalImportDecl(ImportDecl *Import); 708234353Sdim 709234353Sdim static ImportDecl *getNextLocalImport(ImportDecl *Import) { 710234353Sdim return Import->NextLocalImport; 711234353Sdim } 712234353Sdim 713234353Sdim /// \brief Iterator that visits import declarations. 714234353Sdim class import_iterator { 715234353Sdim ImportDecl *Import; 716234353Sdim 717234353Sdim public: 718234353Sdim typedef ImportDecl *value_type; 719234353Sdim typedef ImportDecl *reference; 720234353Sdim typedef ImportDecl *pointer; 721234353Sdim typedef int difference_type; 722234353Sdim typedef std::forward_iterator_tag iterator_category; 723234353Sdim 724234353Sdim import_iterator() : Import() { } 725234353Sdim explicit import_iterator(ImportDecl *Import) : Import(Import) { } 726234353Sdim 727234353Sdim reference operator*() const { return Import; } 728234353Sdim pointer operator->() const { return Import; } 729234353Sdim 730234353Sdim import_iterator &operator++() { 731234353Sdim Import = ASTContext::getNextLocalImport(Import); 732234353Sdim return *this; 733234353Sdim } 734234353Sdim 735234353Sdim import_iterator operator++(int) { 736234353Sdim import_iterator Other(*this); 737234353Sdim ++(*this); 738234353Sdim return Other; 739234353Sdim } 740234353Sdim 741234353Sdim friend bool operator==(import_iterator X, import_iterator Y) { 742234353Sdim return X.Import == Y.Import; 743234353Sdim } 744234353Sdim 745234353Sdim friend bool operator!=(import_iterator X, import_iterator Y) { 746234353Sdim return X.Import != Y.Import; 747234353Sdim } 748234353Sdim }; 749234353Sdim 750234353Sdim import_iterator local_import_begin() const { 751234353Sdim return import_iterator(FirstLocalImport); 752234353Sdim } 753234353Sdim import_iterator local_import_end() const { return import_iterator(); } 754263508Sdim 755263508Sdim Decl *getPrimaryMergedDecl(Decl *D) { 756263508Sdim Decl *Result = MergedDecls.lookup(D); 757263508Sdim return Result ? Result : D; 758263508Sdim } 759263508Sdim void setPrimaryMergedDecl(Decl *D, Decl *Primary) { 760263508Sdim MergedDecls[D] = Primary; 761263508Sdim } 762263508Sdim 763193326Sed TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; } 764193326Sed 765198092Srdivacky 766193326Sed // Builtin Types. 767198893Srdivacky CanQualType VoidTy; 768198893Srdivacky CanQualType BoolTy; 769198893Srdivacky CanQualType CharTy; 770263508Sdim CanQualType WCharTy; // [C++ 3.9.1p5]. 771263508Sdim CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99. 772239462Sdim CanQualType WIntTy; // [C99 7.24.1], integer type unchanged by default promotions. 773198893Srdivacky CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99. 774198893Srdivacky CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99. 775198893Srdivacky CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty; 776198893Srdivacky CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy; 777198893Srdivacky CanQualType UnsignedLongLongTy, UnsignedInt128Ty; 778198893Srdivacky CanQualType FloatTy, DoubleTy, LongDoubleTy; 779226633Sdim CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON 780198893Srdivacky CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy; 781198893Srdivacky CanQualType VoidPtrTy, NullPtrTy; 782221345Sdim CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy; 783243830Sdim CanQualType BuiltinFnTy; 784234353Sdim CanQualType PseudoObjectTy, ARCUnbridgedCastTy; 785199990Srdivacky CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy; 786234353Sdim CanQualType ObjCBuiltinBoolTy; 787249423Sdim CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy; 788249423Sdim CanQualType OCLImage2dTy, OCLImage2dArrayTy; 789249423Sdim CanQualType OCLImage3dTy; 790249423Sdim CanQualType OCLSamplerTy, OCLEventTy; 791193326Sed 792221345Sdim // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand. 793221345Sdim mutable QualType AutoDeductTy; // Deduction against 'auto'. 794221345Sdim mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'. 795221345Sdim 796239462Sdim // Type used to help define __builtin_va_list for some targets. 797239462Sdim // The type is built when constructing 'BuiltinVaListDecl'. 798239462Sdim mutable QualType VaListTagTy; 799239462Sdim 800226633Sdim ASTContext(LangOptions& LOpts, SourceManager &SM, const TargetInfo *t, 801194179Sed IdentifierTable &idents, SelectorTable &sels, 802194179Sed Builtin::Context &builtins, 803226633Sdim unsigned size_reserve, 804226633Sdim bool DelayInitialization = false); 805193326Sed 806193326Sed ~ASTContext(); 807193326Sed 808193326Sed /// \brief Attach an external AST source to the AST context. 809193326Sed /// 810193326Sed /// The external AST source provides the ability to load parts of 811193326Sed /// the abstract syntax tree as needed from some external storage, 812193326Sed /// e.g., a precompiled header. 813234353Sdim void setExternalSource(OwningPtr<ExternalASTSource> &Source); 814193326Sed 815193326Sed /// \brief Retrieve a pointer to the external AST source associated 816193326Sed /// with this AST context, if any. 817193326Sed ExternalASTSource *getExternalSource() const { return ExternalSource.get(); } 818193326Sed 819218893Sdim /// \brief Attach an AST mutation listener to the AST context. 820218893Sdim /// 821218893Sdim /// The AST mutation listener provides the ability to track modifications to 822218893Sdim /// the abstract syntax tree entities committed after they were initially 823218893Sdim /// created. 824218893Sdim void setASTMutationListener(ASTMutationListener *Listener) { 825218893Sdim this->Listener = Listener; 826218893Sdim } 827218893Sdim 828218893Sdim /// \brief Retrieve a pointer to the AST mutation listener associated 829218893Sdim /// with this AST context, if any. 830218893Sdim ASTMutationListener *getASTMutationListener() const { return Listener; } 831218893Sdim 832193326Sed void PrintStats() const; 833249423Sdim const SmallVectorImpl<Type *>& getTypes() const { return Types; } 834193326Sed 835226633Sdim /// \brief Retrieve the declaration for the 128-bit signed integer type. 836226633Sdim TypedefDecl *getInt128Decl() const; 837226633Sdim 838226633Sdim /// \brief Retrieve the declaration for the 128-bit unsigned integer type. 839226633Sdim TypedefDecl *getUInt128Decl() const; 840263508Sdim 841263508Sdim /// \brief Retrieve the declaration for a 128-bit float stub type. 842263508Sdim TypeDecl *getFloat128StubType() const; 843226633Sdim 844193326Sed //===--------------------------------------------------------------------===// 845193326Sed // Type Constructors 846193326Sed //===--------------------------------------------------------------------===// 847198092Srdivacky 848198092Srdivackyprivate: 849243830Sdim /// \brief Return a type with extended qualifiers. 850218893Sdim QualType getExtQualType(const Type *Base, Qualifiers Quals) const; 851198092Srdivacky 852218893Sdim QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const; 853204962Srdivacky 854198092Srdivackypublic: 855243830Sdim /// \brief Return the uniqued reference to the type for an address space 856243830Sdim /// qualified type with the specified type and address space. 857243830Sdim /// 858198092Srdivacky /// The resulting type has a union of the qualifiers from T and the address 859198092Srdivacky /// space. If T already has an address space specifier, it is silently 860193326Sed /// replaced. 861218893Sdim QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const; 862198092Srdivacky 863243830Sdim /// \brief Return the uniqued reference to the type for an Objective-C 864243830Sdim /// gc-qualified type. 865243830Sdim /// 866243830Sdim /// The retulting type has a union of the qualifiers from T and the gc 867243830Sdim /// attribute. 868218893Sdim QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const; 869198092Srdivacky 870243830Sdim /// \brief Return the uniqued reference to the type for a \c restrict 871243830Sdim /// qualified type. 872243830Sdim /// 873243830Sdim /// The resulting type has a union of the qualifiers from \p T and 874243830Sdim /// \c restrict. 875218893Sdim QualType getRestrictType(QualType T) const { 876198092Srdivacky return T.withFastQualifiers(Qualifiers::Restrict); 877198092Srdivacky } 878198092Srdivacky 879243830Sdim /// \brief Return the uniqued reference to the type for a \c volatile 880243830Sdim /// qualified type. 881243830Sdim /// 882243830Sdim /// The resulting type has a union of the qualifiers from \p T and 883243830Sdim /// \c volatile. 884218893Sdim QualType getVolatileType(QualType T) const { 885218893Sdim return T.withFastQualifiers(Qualifiers::Volatile); 886218893Sdim } 887198092Srdivacky 888243830Sdim /// \brief Return the uniqued reference to the type for a \c const 889243830Sdim /// qualified type. 890198092Srdivacky /// 891243830Sdim /// The resulting type has a union of the qualifiers from \p T and \c const. 892243830Sdim /// 893243830Sdim /// It can be reasonably expected that this will always be equivalent to 894243830Sdim /// calling T.withConst(). 895218893Sdim QualType getConstType(QualType T) const { return T.withConst(); } 896198092Srdivacky 897243830Sdim /// \brief Change the ExtInfo on a function type. 898218893Sdim const FunctionType *adjustFunctionType(const FunctionType *Fn, 899218893Sdim FunctionType::ExtInfo EInfo); 900198092Srdivacky 901251662Sdim /// \brief Change the result type of a function type once it is deduced. 902251662Sdim void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType); 903251662Sdim 904243830Sdim /// \brief Return the uniqued reference to the type for a complex 905193326Sed /// number with the specified element type. 906218893Sdim QualType getComplexType(QualType T) const; 907218893Sdim CanQualType getComplexType(CanQualType T) const { 908198893Srdivacky return CanQualType::CreateUnsafe(getComplexType((QualType) T)); 909198893Srdivacky } 910198092Srdivacky 911243830Sdim /// \brief Return the uniqued reference to the type for a pointer to 912193326Sed /// the specified type. 913218893Sdim QualType getPointerType(QualType T) const; 914218893Sdim CanQualType getPointerType(CanQualType T) const { 915198893Srdivacky return CanQualType::CreateUnsafe(getPointerType((QualType) T)); 916198893Srdivacky } 917193326Sed 918263508Sdim /// \brief Return the uniqued reference to the decayed version of the given 919263508Sdim /// type. Can only be called on array and function types which decay to 920263508Sdim /// pointer types. 921263508Sdim QualType getDecayedType(QualType T) const; 922263508Sdim CanQualType getDecayedType(CanQualType T) const { 923263508Sdim return CanQualType::CreateUnsafe(getDecayedType((QualType) T)); 924263508Sdim } 925263508Sdim 926243830Sdim /// \brief Return the uniqued reference to the atomic type for the specified 927243830Sdim /// type. 928226633Sdim QualType getAtomicType(QualType T) const; 929226633Sdim 930243830Sdim /// \brief Return the uniqued reference to the type for a block of the 931243830Sdim /// specified type. 932218893Sdim QualType getBlockPointerType(QualType T) const; 933193326Sed 934243830Sdim /// Gets the struct used to keep track of the descriptor for pointer to 935198398Srdivacky /// blocks. 936218893Sdim QualType getBlockDescriptorType() const; 937198398Srdivacky 938243830Sdim /// Gets the struct used to keep track of the extended descriptor for 939198398Srdivacky /// pointer to blocks. 940218893Sdim QualType getBlockDescriptorExtendedType() const; 941198398Srdivacky 942218893Sdim void setcudaConfigureCallDecl(FunctionDecl *FD) { 943218893Sdim cudaConfigureCallDecl = FD; 944218893Sdim } 945218893Sdim FunctionDecl *getcudaConfigureCallDecl() { 946218893Sdim return cudaConfigureCallDecl; 947218893Sdim } 948218893Sdim 949198398Srdivacky /// Returns true iff we need copy/dispose helpers for the given type. 950249423Sdim bool BlockRequiresCopying(QualType Ty, const VarDecl *D); 951249423Sdim 952249423Sdim 953249423Sdim /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout is set 954249423Sdim /// to false in this case. If HasByrefExtendedLayout returns true, byref variable 955249423Sdim /// has extended lifetime. 956249423Sdim bool getByrefLifetime(QualType Ty, 957249423Sdim Qualifiers::ObjCLifetime &Lifetime, 958249423Sdim bool &HasByrefExtendedLayout) const; 959249423Sdim 960243830Sdim /// \brief Return the uniqued reference to the type for an lvalue reference 961243830Sdim /// to the specified type. 962218893Sdim QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true) 963218893Sdim const; 964193326Sed 965243830Sdim /// \brief Return the uniqued reference to the type for an rvalue reference 966243830Sdim /// to the specified type. 967218893Sdim QualType getRValueReferenceType(QualType T) const; 968193326Sed 969243830Sdim /// \brief Return the uniqued reference to the type for a member pointer to 970243830Sdim /// the specified type in the specified class. 971243830Sdim /// 972243830Sdim /// The class \p Cls is a \c Type because it could be a dependent name. 973218893Sdim QualType getMemberPointerType(QualType T, const Type *Cls) const; 974193326Sed 975243830Sdim /// \brief Return a non-unique reference to the type for a variable array of 976243830Sdim /// the specified element type. 977193326Sed QualType getVariableArrayType(QualType EltTy, Expr *NumElts, 978193326Sed ArrayType::ArraySizeModifier ASM, 979218893Sdim unsigned IndexTypeQuals, 980218893Sdim SourceRange Brackets) const; 981198092Srdivacky 982243830Sdim /// \brief Return a non-unique reference to the type for a dependently-sized 983243830Sdim /// array of the specified element type. 984243830Sdim /// 985243830Sdim /// FIXME: We will need these to be uniqued, or at least comparable, at some 986243830Sdim /// point. 987193326Sed QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, 988193326Sed ArrayType::ArraySizeModifier ASM, 989218893Sdim unsigned IndexTypeQuals, 990218893Sdim SourceRange Brackets) const; 991193326Sed 992243830Sdim /// \brief Return a unique reference to the type for an incomplete array of 993243830Sdim /// the specified element type. 994193326Sed QualType getIncompleteArrayType(QualType EltTy, 995193326Sed ArrayType::ArraySizeModifier ASM, 996218893Sdim unsigned IndexTypeQuals) const; 997193326Sed 998243830Sdim /// \brief Return the unique reference to the type for a constant array of 999243830Sdim /// the specified element type. 1000193326Sed QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, 1001193326Sed ArrayType::ArraySizeModifier ASM, 1002218893Sdim unsigned IndexTypeQuals) const; 1003218893Sdim 1004243830Sdim /// \brief Returns a vla type where known sizes are replaced with [*]. 1005218893Sdim QualType getVariableArrayDecayedType(QualType Ty) const; 1006198092Srdivacky 1007243830Sdim /// \brief Return the unique reference to a vector type of the specified 1008243830Sdim /// element type and size. 1009243830Sdim /// 1010243830Sdim /// \pre \p VectorType must be a built-in type. 1011203955Srdivacky QualType getVectorType(QualType VectorType, unsigned NumElts, 1012218893Sdim VectorType::VectorKind VecKind) const; 1013193326Sed 1014243830Sdim /// \brief Return the unique reference to an extended vector type 1015243830Sdim /// of the specified element type and size. 1016243830Sdim /// 1017243830Sdim /// \pre \p VectorType must be a built-in type. 1018218893Sdim QualType getExtVectorType(QualType VectorType, unsigned NumElts) const; 1019193326Sed 1020243830Sdim /// \pre Return a non-unique reference to the type for a dependently-sized 1021243830Sdim /// vector of the specified element type. 1022243830Sdim /// 1023243830Sdim /// FIXME: We will need these to be uniqued, or at least comparable, at some 1024243830Sdim /// point. 1025198092Srdivacky QualType getDependentSizedExtVectorType(QualType VectorType, 1026194613Sed Expr *SizeExpr, 1027218893Sdim SourceLocation AttrLoc) const; 1028194613Sed 1029243830Sdim /// \brief Return a K&R style C function type like 'int()'. 1030206084Srdivacky QualType getFunctionNoProtoType(QualType ResultTy, 1031218893Sdim const FunctionType::ExtInfo &Info) const; 1032193326Sed 1033218893Sdim QualType getFunctionNoProtoType(QualType ResultTy) const { 1034206084Srdivacky return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo()); 1035206084Srdivacky } 1036206084Srdivacky 1037243830Sdim /// \brief Return a normal function type with a typed argument list. 1038249423Sdim QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args, 1039218893Sdim const FunctionProtoType::ExtProtoInfo &EPI) const; 1040193326Sed 1041243830Sdim /// \brief Return the unique reference to the type for the specified type 1042243830Sdim /// declaration. 1043204962Srdivacky QualType getTypeDeclType(const TypeDecl *Decl, 1044218893Sdim const TypeDecl *PrevDecl = 0) const { 1045204962Srdivacky assert(Decl && "Passed null for Decl param"); 1046204962Srdivacky if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0); 1047193326Sed 1048204962Srdivacky if (PrevDecl) { 1049204962Srdivacky assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl"); 1050204962Srdivacky Decl->TypeForDecl = PrevDecl->TypeForDecl; 1051204962Srdivacky return QualType(PrevDecl->TypeForDecl, 0); 1052204962Srdivacky } 1053204962Srdivacky 1054204962Srdivacky return getTypeDeclTypeSlow(Decl); 1055204962Srdivacky } 1056204962Srdivacky 1057243830Sdim /// \brief Return the unique reference to the type for the specified 1058243830Sdim /// typedef-name decl. 1059221345Sdim QualType getTypedefType(const TypedefNameDecl *Decl, 1060221345Sdim QualType Canon = QualType()) const; 1061193326Sed 1062218893Sdim QualType getRecordType(const RecordDecl *Decl) const; 1063210299Sed 1064218893Sdim QualType getEnumType(const EnumDecl *Decl) const; 1065210299Sed 1066218893Sdim QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const; 1067204962Srdivacky 1068218893Sdim QualType getAttributedType(AttributedType::Kind attrKind, 1069218893Sdim QualType modifiedType, 1070218893Sdim QualType equivalentType); 1071218893Sdim 1072198398Srdivacky QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, 1073218893Sdim QualType Replacement) const; 1074218893Sdim QualType getSubstTemplateTypeParmPackType( 1075218893Sdim const TemplateTypeParmType *Replaced, 1076218893Sdim const TemplateArgument &ArgPack); 1077198398Srdivacky 1078198092Srdivacky QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, 1079194613Sed bool ParameterPack, 1080221345Sdim TemplateTypeParmDecl *ParmDecl = 0) const; 1081193326Sed 1082193326Sed QualType getTemplateSpecializationType(TemplateName T, 1083193326Sed const TemplateArgument *Args, 1084193326Sed unsigned NumArgs, 1085218893Sdim QualType Canon = QualType()) const; 1086193326Sed 1087210299Sed QualType getCanonicalTemplateSpecializationType(TemplateName T, 1088210299Sed const TemplateArgument *Args, 1089218893Sdim unsigned NumArgs) const; 1090210299Sed 1091198893Srdivacky QualType getTemplateSpecializationType(TemplateName T, 1092199990Srdivacky const TemplateArgumentListInfo &Args, 1093218893Sdim QualType Canon = QualType()) const; 1094198893Srdivacky 1095204962Srdivacky TypeSourceInfo * 1096204962Srdivacky getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc, 1097204962Srdivacky const TemplateArgumentListInfo &Args, 1098218893Sdim QualType Canon = QualType()) const; 1099204962Srdivacky 1100218893Sdim QualType getParenType(QualType NamedType) const; 1101218893Sdim 1102208600Srdivacky QualType getElaboratedType(ElaboratedTypeKeyword Keyword, 1103208600Srdivacky NestedNameSpecifier *NNS, 1104218893Sdim QualType NamedType) const; 1105206084Srdivacky QualType getDependentNameType(ElaboratedTypeKeyword Keyword, 1106206084Srdivacky NestedNameSpecifier *NNS, 1107206084Srdivacky const IdentifierInfo *Name, 1108218893Sdim QualType Canon = QualType()) const; 1109193326Sed 1110210299Sed QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 1111210299Sed NestedNameSpecifier *NNS, 1112210299Sed const IdentifierInfo *Name, 1113218893Sdim const TemplateArgumentListInfo &Args) const; 1114210299Sed QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, 1115210299Sed NestedNameSpecifier *NNS, 1116210299Sed const IdentifierInfo *Name, 1117210299Sed unsigned NumArgs, 1118218893Sdim const TemplateArgument *Args) const; 1119210299Sed 1120218893Sdim QualType getPackExpansionType(QualType Pattern, 1121249423Sdim Optional<unsigned> NumExpansions); 1122198092Srdivacky 1123234353Sdim QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, 1124234353Sdim ObjCInterfaceDecl *PrevDecl = 0) const; 1125218893Sdim 1126208600Srdivacky QualType getObjCObjectType(QualType Base, 1127208600Srdivacky ObjCProtocolDecl * const *Protocols, 1128218893Sdim unsigned NumProtocols) const; 1129198092Srdivacky 1130243830Sdim /// \brief Return a ObjCObjectPointerType type for the given ObjCObjectType. 1131218893Sdim QualType getObjCObjectPointerType(QualType OIT) const; 1132208600Srdivacky 1133243830Sdim /// \brief GCC extension. 1134218893Sdim QualType getTypeOfExprType(Expr *e) const; 1135218893Sdim QualType getTypeOfType(QualType t) const; 1136198092Srdivacky 1137243830Sdim /// \brief C++11 decltype. 1138234353Sdim QualType getDecltypeType(Expr *e, QualType UnderlyingType) const; 1139198092Srdivacky 1140243830Sdim /// \brief Unary type transforms 1141223017Sdim QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, 1142223017Sdim UnaryTransformType::UTTKind UKind) const; 1143223017Sdim 1144243830Sdim /// \brief C++11 deduced auto type. 1145251662Sdim QualType getAutoType(QualType DeducedType, bool IsDecltypeAuto, 1146263508Sdim bool IsDependent) const; 1147218893Sdim 1148243830Sdim /// \brief C++11 deduction pattern for 'auto' type. 1149221345Sdim QualType getAutoDeductType() const; 1150221345Sdim 1151243830Sdim /// \brief C++11 deduction pattern for 'auto &&' type. 1152221345Sdim QualType getAutoRRefDeductType() const; 1153221345Sdim 1154243830Sdim /// \brief Return the unique reference to the type for the specified TagDecl 1155243830Sdim /// (struct/union/class/enum) decl. 1156218893Sdim QualType getTagDeclType(const TagDecl *Decl) const; 1157198092Srdivacky 1158243830Sdim /// \brief Return the unique type for "size_t" (C99 7.17), defined in 1159243830Sdim /// <stddef.h>. 1160243830Sdim /// 1161243830Sdim /// The sizeof operator requires this (C99 6.5.3.4p4). 1162200583Srdivacky CanQualType getSizeType() const; 1163193326Sed 1164243830Sdim /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in 1165243830Sdim /// <stdint.h>. 1166234353Sdim CanQualType getIntMaxType() const; 1167234353Sdim 1168243830Sdim /// \brief Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in 1169243830Sdim /// <stdint.h>. 1170234353Sdim CanQualType getUIntMaxType() const; 1171234353Sdim 1172263508Sdim /// \brief Return the unique wchar_t type available in C++ (and available as 1173263508Sdim /// __wchar_t as a Microsoft extension). 1174193326Sed QualType getWCharType() const { return WCharTy; } 1175193326Sed 1176263508Sdim /// \brief Return the type of wide characters. In C++, this returns the 1177263508Sdim /// unique wchar_t type. In C99, this returns a type compatible with the type 1178263508Sdim /// defined in <stddef.h> as defined by the target. 1179263508Sdim QualType getWideCharType() const { return WideCharTy; } 1180263508Sdim 1181243830Sdim /// \brief Return the type of "signed wchar_t". 1182243830Sdim /// 1183193326Sed /// Used when in C++, as a GCC extension. 1184193326Sed QualType getSignedWCharType() const; 1185193326Sed 1186243830Sdim /// \brief Return the type of "unsigned wchar_t". 1187243830Sdim /// 1188193326Sed /// Used when in C++, as a GCC extension. 1189193326Sed QualType getUnsignedWCharType() const; 1190198092Srdivacky 1191243830Sdim /// \brief In C99, this returns a type compatible with the type 1192239462Sdim /// defined in <stddef.h> as defined by the target. 1193239462Sdim QualType getWIntType() const { return WIntTy; } 1194239462Sdim 1195249423Sdim /// \brief Return a type compatible with "intptr_t" (C99 7.18.1.4), 1196249423Sdim /// as defined by the target. 1197249423Sdim QualType getIntPtrType() const; 1198249423Sdim 1199249423Sdim /// \brief Return a type compatible with "uintptr_t" (C99 7.18.1.4), 1200249423Sdim /// as defined by the target. 1201249423Sdim QualType getUIntPtrType() const; 1202249423Sdim 1203243830Sdim /// \brief Return the unique type for "ptrdiff_t" (C99 7.17) defined in 1204243830Sdim /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9). 1205193326Sed QualType getPointerDiffType() const; 1206198092Srdivacky 1207243830Sdim /// \brief Return the unique type for "pid_t" defined in 1208243830Sdim /// <sys/types.h>. We need this to compute the correct type for vfork(). 1209243830Sdim QualType getProcessIDType() const; 1210243830Sdim 1211243830Sdim /// \brief Return the C structure type used to represent constant CFStrings. 1212218893Sdim QualType getCFConstantStringType() const; 1213249423Sdim 1214249423Sdim /// \brief Returns the C struct type for objc_super 1215249423Sdim QualType getObjCSuperType() const; 1216249423Sdim void setObjCSuperType(QualType ST) { ObjCSuperType = ST; } 1217249423Sdim 1218193326Sed /// Get the structure type used to representation CFStrings, or NULL 1219193326Sed /// if it hasn't yet been built. 1220218893Sdim QualType getRawCFConstantStringType() const { 1221193326Sed if (CFConstantStringTypeDecl) 1222193326Sed return getTagDeclType(CFConstantStringTypeDecl); 1223193326Sed return QualType(); 1224193326Sed } 1225193326Sed void setCFConstantStringType(QualType T); 1226193326Sed 1227193326Sed // This setter/getter represents the ObjC type for an NSConstantString. 1228193326Sed void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl); 1229198092Srdivacky QualType getObjCConstantStringInterface() const { 1230198092Srdivacky return ObjCConstantStringType; 1231193326Sed } 1232193326Sed 1233234353Sdim QualType getObjCNSStringType() const { 1234234353Sdim return ObjCNSStringType; 1235234353Sdim } 1236234353Sdim 1237234353Sdim void setObjCNSStringType(QualType T) { 1238234353Sdim ObjCNSStringType = T; 1239234353Sdim } 1240234353Sdim 1241243830Sdim /// \brief Retrieve the type that \c id has been defined to, which may be 1242243830Sdim /// different from the built-in \c id if \c id has been typedef'd. 1243226633Sdim QualType getObjCIdRedefinitionType() const { 1244226633Sdim if (ObjCIdRedefinitionType.isNull()) 1245226633Sdim return getObjCIdType(); 1246226633Sdim return ObjCIdRedefinitionType; 1247226633Sdim } 1248226633Sdim 1249243830Sdim /// \brief Set the user-written type that redefines \c id. 1250226633Sdim void setObjCIdRedefinitionType(QualType RedefType) { 1251226633Sdim ObjCIdRedefinitionType = RedefType; 1252226633Sdim } 1253198092Srdivacky 1254243830Sdim /// \brief Retrieve the type that \c Class has been defined to, which may be 1255243830Sdim /// different from the built-in \c Class if \c Class has been typedef'd. 1256226633Sdim QualType getObjCClassRedefinitionType() const { 1257226633Sdim if (ObjCClassRedefinitionType.isNull()) 1258226633Sdim return getObjCClassType(); 1259226633Sdim return ObjCClassRedefinitionType; 1260193326Sed } 1261226633Sdim 1262226633Sdim /// \brief Set the user-written type that redefines 'SEL'. 1263226633Sdim void setObjCClassRedefinitionType(QualType RedefType) { 1264226633Sdim ObjCClassRedefinitionType = RedefType; 1265226633Sdim } 1266193326Sed 1267226633Sdim /// \brief Retrieve the type that 'SEL' has been defined to, which may be 1268226633Sdim /// different from the built-in 'SEL' if 'SEL' has been typedef'd. 1269226633Sdim QualType getObjCSelRedefinitionType() const { 1270226633Sdim if (ObjCSelRedefinitionType.isNull()) 1271226633Sdim return getObjCSelType(); 1272226633Sdim return ObjCSelRedefinitionType; 1273226633Sdim } 1274193326Sed 1275226633Sdim 1276226633Sdim /// \brief Set the user-written type that redefines 'SEL'. 1277226633Sdim void setObjCSelRedefinitionType(QualType RedefType) { 1278226633Sdim ObjCSelRedefinitionType = RedefType; 1279226633Sdim } 1280226633Sdim 1281226633Sdim /// \brief Retrieve the Objective-C "instancetype" type, if already known; 1282226633Sdim /// otherwise, returns a NULL type; 1283226633Sdim QualType getObjCInstanceType() { 1284226633Sdim return getTypeDeclType(getObjCInstanceTypeDecl()); 1285226633Sdim } 1286226633Sdim 1287226633Sdim /// \brief Retrieve the typedef declaration corresponding to the Objective-C 1288226633Sdim /// "instancetype" type. 1289226633Sdim TypedefDecl *getObjCInstanceTypeDecl(); 1290226633Sdim 1291198092Srdivacky /// \brief Set the type for the C FILE type. 1292198092Srdivacky void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } 1293198092Srdivacky 1294198092Srdivacky /// \brief Retrieve the C FILE type. 1295218893Sdim QualType getFILEType() const { 1296198092Srdivacky if (FILEDecl) 1297198092Srdivacky return getTypeDeclType(FILEDecl); 1298198092Srdivacky return QualType(); 1299198092Srdivacky } 1300198092Srdivacky 1301198092Srdivacky /// \brief Set the type for the C jmp_buf type. 1302198092Srdivacky void setjmp_bufDecl(TypeDecl *jmp_bufDecl) { 1303198092Srdivacky this->jmp_bufDecl = jmp_bufDecl; 1304198092Srdivacky } 1305198092Srdivacky 1306198092Srdivacky /// \brief Retrieve the C jmp_buf type. 1307218893Sdim QualType getjmp_bufType() const { 1308198092Srdivacky if (jmp_bufDecl) 1309198092Srdivacky return getTypeDeclType(jmp_bufDecl); 1310198092Srdivacky return QualType(); 1311198092Srdivacky } 1312198092Srdivacky 1313198092Srdivacky /// \brief Set the type for the C sigjmp_buf type. 1314198092Srdivacky void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) { 1315198092Srdivacky this->sigjmp_bufDecl = sigjmp_bufDecl; 1316198092Srdivacky } 1317198092Srdivacky 1318198092Srdivacky /// \brief Retrieve the C sigjmp_buf type. 1319218893Sdim QualType getsigjmp_bufType() const { 1320198092Srdivacky if (sigjmp_bufDecl) 1321198092Srdivacky return getTypeDeclType(sigjmp_bufDecl); 1322198092Srdivacky return QualType(); 1323198092Srdivacky } 1324198092Srdivacky 1325227737Sdim /// \brief Set the type for the C ucontext_t type. 1326227737Sdim void setucontext_tDecl(TypeDecl *ucontext_tDecl) { 1327227737Sdim this->ucontext_tDecl = ucontext_tDecl; 1328227737Sdim } 1329227737Sdim 1330227737Sdim /// \brief Retrieve the C ucontext_t type. 1331227737Sdim QualType getucontext_tType() const { 1332227737Sdim if (ucontext_tDecl) 1333227737Sdim return getTypeDeclType(ucontext_tDecl); 1334227737Sdim return QualType(); 1335227737Sdim } 1336227737Sdim 1337218893Sdim /// \brief The result type of logical operations, '<', '>', '!=', etc. 1338218893Sdim QualType getLogicalOperationType() const { 1339234353Sdim return getLangOpts().CPlusPlus ? BoolTy : IntTy; 1340218893Sdim } 1341218893Sdim 1342243830Sdim /// \brief Emit the Objective-CC type encoding for the given type \p T into 1343243830Sdim /// \p S. 1344243830Sdim /// 1345243830Sdim /// If \p Field is specified then record field names are also encoded. 1346243830Sdim void getObjCEncodingForType(QualType T, std::string &S, 1347218893Sdim const FieldDecl *Field=0) const; 1348193326Sed 1349193326Sed void getLegacyIntegralTypeEncoding(QualType &t) const; 1350198092Srdivacky 1351243830Sdim /// \brief Put the string version of the type qualifiers \p QT into \p S. 1352198092Srdivacky void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT, 1353193326Sed std::string &S) const; 1354198092Srdivacky 1355243830Sdim /// \brief Emit the encoded type for the function \p Decl into \p S. 1356223017Sdim /// 1357243830Sdim /// This is in the same format as Objective-C method encodings. 1358243830Sdim /// 1359223017Sdim /// \returns true if an error occurred (e.g., because one of the parameter 1360223017Sdim /// types is incomplete), false otherwise. 1361223017Sdim bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S); 1362218893Sdim 1363243830Sdim /// \brief Emit the encoded type for the method declaration \p Decl into 1364243830Sdim /// \p S. 1365223017Sdim /// 1366223017Sdim /// \returns true if an error occurred (e.g., because one of the parameter 1367223017Sdim /// types is incomplete), false otherwise. 1368234353Sdim bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S, 1369234353Sdim bool Extended = false) 1370218893Sdim const; 1371198092Srdivacky 1372243830Sdim /// \brief Return the encoded type for this block declaration. 1373218893Sdim std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const; 1374199482Srdivacky 1375193326Sed /// getObjCEncodingForPropertyDecl - Return the encoded type for 1376193326Sed /// this method declaration. If non-NULL, Container must be either 1377193326Sed /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should 1378193326Sed /// only be NULL when getting encodings for protocol properties. 1379198092Srdivacky void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD, 1380193326Sed const Decl *Container, 1381218893Sdim std::string &S) const; 1382198092Srdivacky 1383198092Srdivacky bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto, 1384218893Sdim ObjCProtocolDecl *rProto) const; 1385198092Srdivacky 1386243830Sdim /// \brief Return the size of type \p T for Objective-C encoding purpose, 1387243830Sdim /// in characters. 1388243830Sdim CharUnits getObjCEncodingTypeSize(QualType T) const; 1389194613Sed 1390243830Sdim /// \brief Retrieve the typedef corresponding to the predefined \c id type 1391226633Sdim /// in Objective-C. 1392226633Sdim TypedefDecl *getObjCIdDecl() const; 1393226633Sdim 1394243830Sdim /// \brief Represents the Objective-CC \c id type. 1395243830Sdim /// 1396243830Sdim /// This is set up lazily, by Sema. \c id is always a (typedef for a) 1397243830Sdim /// pointer type, a pointer to a struct. 1398226633Sdim QualType getObjCIdType() const { 1399226633Sdim return getTypeDeclType(getObjCIdDecl()); 1400226633Sdim } 1401198092Srdivacky 1402226633Sdim /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type 1403226633Sdim /// in Objective-C. 1404226633Sdim TypedefDecl *getObjCSelDecl() const; 1405226633Sdim 1406226633Sdim /// \brief Retrieve the type that corresponds to the predefined Objective-C 1407226633Sdim /// 'SEL' type. 1408226633Sdim QualType getObjCSelType() const { 1409226633Sdim return getTypeDeclType(getObjCSelDecl()); 1410226633Sdim } 1411198092Srdivacky 1412226633Sdim /// \brief Retrieve the typedef declaration corresponding to the predefined 1413226633Sdim /// Objective-C 'Class' type. 1414226633Sdim TypedefDecl *getObjCClassDecl() const; 1415226633Sdim 1416243830Sdim /// \brief Represents the Objective-C \c Class type. 1417243830Sdim /// 1418243830Sdim /// This is set up lazily, by Sema. \c Class is always a (typedef for a) 1419243830Sdim /// pointer type, a pointer to a struct. 1420226633Sdim QualType getObjCClassType() const { 1421226633Sdim return getTypeDeclType(getObjCClassDecl()); 1422226633Sdim } 1423198092Srdivacky 1424234353Sdim /// \brief Retrieve the Objective-C class declaration corresponding to 1425243830Sdim /// the predefined \c Protocol class. 1426234353Sdim ObjCInterfaceDecl *getObjCProtocolDecl() const; 1427243830Sdim 1428243830Sdim /// \brief Retrieve declaration of 'BOOL' typedef 1429243830Sdim TypedefDecl *getBOOLDecl() const { 1430243830Sdim return BOOLDecl; 1431243830Sdim } 1432243830Sdim 1433243830Sdim /// \brief Save declaration of 'BOOL' typedef 1434243830Sdim void setBOOLDecl(TypedefDecl *TD) { 1435243830Sdim BOOLDecl = TD; 1436243830Sdim } 1437243830Sdim 1438243830Sdim /// \brief type of 'BOOL' type. 1439243830Sdim QualType getBOOLType() const { 1440243830Sdim return getTypeDeclType(getBOOLDecl()); 1441243830Sdim } 1442234353Sdim 1443243830Sdim /// \brief Retrieve the type of the Objective-C \c Protocol class. 1444234353Sdim QualType getObjCProtoType() const { 1445234353Sdim return getObjCInterfaceType(getObjCProtocolDecl()); 1446234353Sdim } 1447234353Sdim 1448239462Sdim /// \brief Retrieve the C type declaration corresponding to the predefined 1449243830Sdim /// \c __builtin_va_list type. 1450239462Sdim TypedefDecl *getBuiltinVaListDecl() const; 1451193326Sed 1452243830Sdim /// \brief Retrieve the type of the \c __builtin_va_list type. 1453239462Sdim QualType getBuiltinVaListType() const { 1454239462Sdim return getTypeDeclType(getBuiltinVaListDecl()); 1455239462Sdim } 1456239462Sdim 1457239462Sdim /// \brief Retrieve the C type declaration corresponding to the predefined 1458243830Sdim /// \c __va_list_tag type used to help define the \c __builtin_va_list type 1459243830Sdim /// for some targets. 1460239462Sdim QualType getVaListTagType() const; 1461239462Sdim 1462243830Sdim /// \brief Return a type with additional \c const, \c volatile, or 1463243830Sdim /// \c restrict qualifiers. 1464218893Sdim QualType getCVRQualifiedType(QualType T, unsigned CVR) const { 1465198092Srdivacky return getQualifiedType(T, Qualifiers::fromCVRMask(CVR)); 1466198092Srdivacky } 1467198092Srdivacky 1468243830Sdim /// \brief Un-split a SplitQualType. 1469234353Sdim QualType getQualifiedType(SplitQualType split) const { 1470234353Sdim return getQualifiedType(split.Ty, split.Quals); 1471234353Sdim } 1472234353Sdim 1473243830Sdim /// \brief Return a type with additional qualifiers. 1474218893Sdim QualType getQualifiedType(QualType T, Qualifiers Qs) const { 1475198092Srdivacky if (!Qs.hasNonFastQualifiers()) 1476198092Srdivacky return T.withFastQualifiers(Qs.getFastQualifiers()); 1477198092Srdivacky QualifierCollector Qc(Qs); 1478198092Srdivacky const Type *Ptr = Qc.strip(T); 1479198092Srdivacky return getExtQualType(Ptr, Qc); 1480198092Srdivacky } 1481198092Srdivacky 1482243830Sdim /// \brief Return a type with additional qualifiers. 1483218893Sdim QualType getQualifiedType(const Type *T, Qualifiers Qs) const { 1484198092Srdivacky if (!Qs.hasNonFastQualifiers()) 1485198092Srdivacky return QualType(T, Qs.getFastQualifiers()); 1486198092Srdivacky return getExtQualType(T, Qs); 1487198092Srdivacky } 1488198092Srdivacky 1489243830Sdim /// \brief Return a type with the given lifetime qualifier. 1490243830Sdim /// 1491243830Sdim /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None. 1492224145Sdim QualType getLifetimeQualifiedType(QualType type, 1493224145Sdim Qualifiers::ObjCLifetime lifetime) { 1494224145Sdim assert(type.getObjCLifetime() == Qualifiers::OCL_None); 1495224145Sdim assert(lifetime != Qualifiers::OCL_None); 1496224145Sdim 1497224145Sdim Qualifiers qs; 1498224145Sdim qs.addObjCLifetime(lifetime); 1499224145Sdim return getQualifiedType(type, qs); 1500224145Sdim } 1501251662Sdim 1502251662Sdim /// getUnqualifiedObjCPointerType - Returns version of 1503251662Sdim /// Objective-C pointer type with lifetime qualifier removed. 1504251662Sdim QualType getUnqualifiedObjCPointerType(QualType type) const { 1505251662Sdim if (!type.getTypePtr()->isObjCObjectPointerType() || 1506251662Sdim !type.getQualifiers().hasObjCLifetime()) 1507251662Sdim return type; 1508251662Sdim Qualifiers Qs = type.getQualifiers(); 1509251662Sdim Qs.removeObjCLifetime(); 1510251662Sdim return getQualifiedType(type.getUnqualifiedType(), Qs); 1511251662Sdim } 1512251662Sdim 1513212904Sdim DeclarationNameInfo getNameForTemplate(TemplateName Name, 1514218893Sdim SourceLocation NameLoc) const; 1515199990Srdivacky 1516202879Srdivacky TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, 1517218893Sdim UnresolvedSetIterator End) const; 1518200583Srdivacky 1519198092Srdivacky TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, 1520193326Sed bool TemplateKeyword, 1521218893Sdim TemplateDecl *Template) const; 1522193326Sed 1523198092Srdivacky TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 1524218893Sdim const IdentifierInfo *Name) const; 1525198893Srdivacky TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, 1526218893Sdim OverloadedOperatorKind Operator) const; 1527224145Sdim TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param, 1528224145Sdim TemplateName replacement) const; 1529218893Sdim TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param, 1530218893Sdim const TemplateArgument &ArgPack) const; 1531218893Sdim 1532194179Sed enum GetBuiltinTypeError { 1533239462Sdim GE_None, ///< No error 1534239462Sdim GE_Missing_stdio, ///< Missing a type from <stdio.h> 1535239462Sdim GE_Missing_setjmp, ///< Missing a type from <setjmp.h> 1536239462Sdim GE_Missing_ucontext ///< Missing a type from <ucontext.h> 1537194179Sed }; 1538198092Srdivacky 1539243830Sdim /// \brief Return the type for the specified builtin. 1540243830Sdim /// 1541243830Sdim /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of 1542218893Sdim /// arguments to the builtin that are required to be integer constant 1543218893Sdim /// expressions. 1544218893Sdim QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, 1545218893Sdim unsigned *IntegerConstantArgs = 0) const; 1546198092Srdivacky 1547193326Sedprivate: 1548198893Srdivacky CanQualType getFromTargetType(unsigned Type) const; 1549234353Sdim std::pair<uint64_t, unsigned> getTypeInfoImpl(const Type *T) const; 1550193326Sed 1551193326Sed //===--------------------------------------------------------------------===// 1552193326Sed // Type Predicates. 1553193326Sed //===--------------------------------------------------------------------===// 1554198092Srdivacky 1555193326Sedpublic: 1556243830Sdim /// \brief Return one of the GCNone, Weak or Strong Objective-C garbage 1557243830Sdim /// collection attributes. 1558218893Sdim Qualifiers::GC getObjCGCAttrKind(QualType Ty) const; 1559198092Srdivacky 1560243830Sdim /// \brief Return true if the given vector types are of the same unqualified 1561243830Sdim /// type or if they are equivalent to the same GCC vector type. 1562243830Sdim /// 1563243830Sdim /// \note This ignores whether they are target-specific (AltiVec or Neon) 1564243830Sdim /// types. 1565212904Sdim bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec); 1566212904Sdim 1567243830Sdim /// \brief Return true if this is an \c NSObject object with its \c NSObject 1568243830Sdim /// attribute set. 1569224145Sdim static bool isObjCNSObjectType(QualType Ty) { 1570224145Sdim return Ty->isObjCNSObjectType(); 1571224145Sdim } 1572198092Srdivacky 1573193326Sed //===--------------------------------------------------------------------===// 1574193326Sed // Type Sizing and Analysis 1575193326Sed //===--------------------------------------------------------------------===// 1576198092Srdivacky 1577243830Sdim /// \brief Return the APFloat 'semantics' for the specified scalar floating 1578243830Sdim /// point type. 1579193326Sed const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const; 1580198092Srdivacky 1581243830Sdim /// \brief Get the size and alignment of the specified complete type in bits. 1582218893Sdim std::pair<uint64_t, unsigned> getTypeInfo(const Type *T) const; 1583218893Sdim std::pair<uint64_t, unsigned> getTypeInfo(QualType T) const { 1584193326Sed return getTypeInfo(T.getTypePtr()); 1585193326Sed } 1586198092Srdivacky 1587243830Sdim /// \brief Return the size of the specified (complete) type \p T, in bits. 1588218893Sdim uint64_t getTypeSize(QualType T) const { 1589193326Sed return getTypeInfo(T).first; 1590193326Sed } 1591218893Sdim uint64_t getTypeSize(const Type *T) const { 1592193326Sed return getTypeInfo(T).first; 1593193326Sed } 1594198092Srdivacky 1595243830Sdim /// \brief Return the size of the character type, in bits. 1596218893Sdim uint64_t getCharWidth() const { 1597199990Srdivacky return getTypeSize(CharTy); 1598199990Srdivacky } 1599199990Srdivacky 1600243830Sdim /// \brief Convert a size in bits to a size in characters. 1601218893Sdim CharUnits toCharUnitsFromBits(int64_t BitSize) const; 1602218893Sdim 1603243830Sdim /// \brief Convert a size in characters to a size in bits. 1604218893Sdim int64_t toBits(CharUnits CharSize) const; 1605218893Sdim 1606243830Sdim /// \brief Return the size of the specified (complete) type \p T, in 1607243830Sdim /// characters. 1608218893Sdim CharUnits getTypeSizeInChars(QualType T) const; 1609218893Sdim CharUnits getTypeSizeInChars(const Type *T) const; 1610199990Srdivacky 1611243830Sdim /// \brief Return the ABI-specified alignment of a (complete) type \p T, in 1612243830Sdim /// bits. 1613218893Sdim unsigned getTypeAlign(QualType T) const { 1614193326Sed return getTypeInfo(T).second; 1615193326Sed } 1616218893Sdim unsigned getTypeAlign(const Type *T) const { 1617193326Sed return getTypeInfo(T).second; 1618193326Sed } 1619198092Srdivacky 1620243830Sdim /// \brief Return the ABI-specified alignment of a (complete) type \p T, in 1621243830Sdim /// characters. 1622218893Sdim CharUnits getTypeAlignInChars(QualType T) const; 1623218893Sdim CharUnits getTypeAlignInChars(const Type *T) const; 1624243830Sdim 1625243830Sdim // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the 1626243830Sdim // type is a record, its data size is returned. 1627243830Sdim std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const; 1628203955Srdivacky 1629218893Sdim std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const; 1630218893Sdim std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const; 1631208600Srdivacky 1632243830Sdim /// \brief Return the "preferred" alignment of the specified type \p T for 1633243830Sdim /// the current target, in bits. 1634243830Sdim /// 1635243830Sdim /// This can be different than the ABI alignment in cases where it is 1636243830Sdim /// beneficial for performance to overalign a data type. 1637218893Sdim unsigned getPreferredTypeAlign(const Type *T) const; 1638198092Srdivacky 1639251662Sdim /// \brief Return the alignment in bits that should be given to a 1640251662Sdim /// global variable with type \p T. 1641251662Sdim unsigned getAlignOfGlobalVar(QualType T) const; 1642251662Sdim 1643251662Sdim /// \brief Return the alignment in characters that should be given to a 1644251662Sdim /// global variable with type \p T. 1645251662Sdim CharUnits getAlignOfGlobalVarInChars(QualType T) const; 1646251662Sdim 1647243830Sdim /// \brief Return a conservative estimate of the alignment of the specified 1648243830Sdim /// decl \p D. 1649243830Sdim /// 1650243830Sdim /// \pre \p D must not be a bitfield type, as bitfields do not have a valid 1651243830Sdim /// alignment. 1652243830Sdim /// 1653263508Sdim /// If \p ForAlignof, references are treated like their underlying type 1654263508Sdim /// and large arrays don't get any special treatment. If not \p ForAlignof 1655263508Sdim /// it computes the value expected by CodeGen: references are treated like 1656263508Sdim /// pointers and large arrays get extra alignment. 1657263508Sdim CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const; 1658198092Srdivacky 1659243830Sdim /// \brief Get or compute information about the layout of the specified 1660243830Sdim /// record (struct/union/class) \p D, which indicates its size and field 1661193326Sed /// position information. 1662218893Sdim const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const; 1663263508Sdim const ASTRecordLayout *BuildMicrosoftASTRecordLayout(const RecordDecl *D) const; 1664198092Srdivacky 1665243830Sdim /// \brief Get or compute information about the layout of the specified 1666243830Sdim /// Objective-C interface. 1667218893Sdim const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) 1668218893Sdim const; 1669193326Sed 1670234353Sdim void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS, 1671234353Sdim bool Simple = false) const; 1672207619Srdivacky 1673243830Sdim /// \brief Get or compute information about the layout of the specified 1674243830Sdim /// Objective-C implementation. 1675243830Sdim /// 1676243830Sdim /// This may differ from the interface if synthesized ivars are present. 1677193326Sed const ASTRecordLayout & 1678218893Sdim getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const; 1679193326Sed 1680249423Sdim /// \brief Get our current best idea for the key function of the 1681249423Sdim /// given record decl, or NULL if there isn't one. 1682200583Srdivacky /// 1683243830Sdim /// The key function is, according to the Itanium C++ ABI section 5.2.3: 1684249423Sdim /// ...the first non-pure virtual function that is not inline at the 1685249423Sdim /// point of class definition. 1686243830Sdim /// 1687249423Sdim /// Other ABIs use the same idea. However, the ARM C++ ABI ignores 1688249423Sdim /// virtual functions that are defined 'inline', which means that 1689249423Sdim /// the result of this computation can change. 1690249423Sdim const CXXMethodDecl *getCurrentKeyFunction(const CXXRecordDecl *RD); 1691200583Srdivacky 1692249423Sdim /// \brief Observe that the given method cannot be a key function. 1693249423Sdim /// Checks the key-function cache for the method's class and clears it 1694249423Sdim /// if matches the given declaration. 1695249423Sdim /// 1696249423Sdim /// This is used in ABIs where out-of-line definitions marked 1697249423Sdim /// inline are not considered to be key functions. 1698249423Sdim /// 1699249423Sdim /// \param method should be the declaration from the class definition 1700249423Sdim void setNonKeyFunction(const CXXMethodDecl *method); 1701249423Sdim 1702234353Sdim /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits. 1703234353Sdim uint64_t getFieldOffset(const ValueDecl *FD) const; 1704234353Sdim 1705218893Sdim bool isNearlyEmpty(const CXXRecordDecl *RD) const; 1706218893Sdim 1707218893Sdim MangleContext *createMangleContext(); 1708212904Sdim 1709212904Sdim void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, 1710226633Sdim SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const; 1711212904Sdim 1712218893Sdim unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; 1713198893Srdivacky void CollectInheritedProtocols(const Decl *CDecl, 1714203955Srdivacky llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols); 1715193326Sed 1716193326Sed //===--------------------------------------------------------------------===// 1717193326Sed // Type Operators 1718193326Sed //===--------------------------------------------------------------------===// 1719198092Srdivacky 1720243830Sdim /// \brief Return the canonical (structural) type corresponding to the 1721243830Sdim /// specified potentially non-canonical type \p T. 1722243830Sdim /// 1723243830Sdim /// The non-canonical version of a type may have many "decorated" versions of 1724243830Sdim /// types. Decorators can include typedefs, 'typeof' operators, etc. The 1725243830Sdim /// returned type is guaranteed to be free of any of these, allowing two 1726243830Sdim /// canonical types to be compared for exact equality with a simple pointer 1727243830Sdim /// comparison. 1728218893Sdim CanQualType getCanonicalType(QualType T) const { 1729218893Sdim return CanQualType::CreateUnsafe(T.getCanonicalType()); 1730218893Sdim } 1731218893Sdim 1732218893Sdim const Type *getCanonicalType(const Type *T) const { 1733193326Sed return T->getCanonicalTypeInternal().getTypePtr(); 1734193326Sed } 1735193326Sed 1736243830Sdim /// \brief Return the canonical parameter type corresponding to the specific 1737243830Sdim /// potentially non-canonical one. 1738243830Sdim /// 1739198398Srdivacky /// Qualifiers are stripped off, functions are turned into function 1740198398Srdivacky /// pointers, and arrays decay one level into pointers. 1741218893Sdim CanQualType getCanonicalParamType(QualType T) const; 1742198398Srdivacky 1743243830Sdim /// \brief Determine whether the given types \p T1 and \p T2 are equivalent. 1744234353Sdim bool hasSameType(QualType T1, QualType T2) const { 1745193326Sed return getCanonicalType(T1) == getCanonicalType(T2); 1746193326Sed } 1747198092Srdivacky 1748243830Sdim /// \brief Return this type as a completely-unqualified array type, 1749243830Sdim /// capturing the qualifiers in \p Quals. 1750201361Srdivacky /// 1751243830Sdim /// This will remove the minimal amount of sugaring from the types, similar 1752243830Sdim /// to the behavior of QualType::getUnqualifiedType(). 1753243830Sdim /// 1754202379Srdivacky /// \param T is the qualified type, which may be an ArrayType 1755201361Srdivacky /// 1756201361Srdivacky /// \param Quals will receive the full set of qualifiers that were 1757202379Srdivacky /// applied to the array. 1758201361Srdivacky /// 1759201361Srdivacky /// \returns if this is an array type, the completely unqualified array type 1760202379Srdivacky /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). 1761201361Srdivacky QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals); 1762201361Srdivacky 1763193326Sed /// \brief Determine whether the given types are equivalent after 1764193326Sed /// cvr-qualifiers have been removed. 1765234353Sdim bool hasSameUnqualifiedType(QualType T1, QualType T2) const { 1766218893Sdim return getCanonicalType(T1).getTypePtr() == 1767218893Sdim getCanonicalType(T2).getTypePtr(); 1768193326Sed } 1769193326Sed 1770263508Sdim bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl, 1771263508Sdim const ObjCMethodDecl *MethodImp); 1772263508Sdim 1773210299Sed bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2); 1774210299Sed 1775193326Sed /// \brief Retrieves the "canonical" nested name specifier for a 1776193326Sed /// given nested name specifier. 1777193326Sed /// 1778193326Sed /// The canonical nested name specifier is a nested name specifier 1779193326Sed /// that uniquely identifies a type or namespace within the type 1780193326Sed /// system. For example, given: 1781193326Sed /// 1782193326Sed /// \code 1783193326Sed /// namespace N { 1784193326Sed /// struct S { 1785193326Sed /// template<typename T> struct X { typename T* type; }; 1786193326Sed /// }; 1787193326Sed /// } 1788193326Sed /// 1789193326Sed /// template<typename T> struct Y { 1790193326Sed /// typename N::S::X<T>::type member; 1791193326Sed /// }; 1792193326Sed /// \endcode 1793193326Sed /// 1794193326Sed /// Here, the nested-name-specifier for N::S::X<T>:: will be 1795193326Sed /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined 1796193326Sed /// by declarations in the type system and the canonical type for 1797193326Sed /// the template type parameter 'T' is template-param-0-0. 1798193326Sed NestedNameSpecifier * 1799218893Sdim getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const; 1800193326Sed 1801263508Sdim /// \brief Retrieves the default calling convention for the current target. 1802263508Sdim CallingConv getDefaultCallingConvention(bool isVariadic, 1803263508Sdim bool IsCXXMethod) const; 1804218893Sdim 1805193326Sed /// \brief Retrieves the "canonical" template name that refers to a 1806193326Sed /// given template. 1807193326Sed /// 1808193326Sed /// The canonical template name is the simplest expression that can 1809193326Sed /// be used to refer to a given template. For most templates, this 1810193326Sed /// expression is just the template declaration itself. For example, 1811193326Sed /// the template std::vector can be referred to via a variety of 1812239462Sdim /// names---std::vector, \::std::vector, vector (if vector is in 1813193326Sed /// scope), etc.---but all of these names map down to the same 1814193326Sed /// TemplateDecl, which is used to form the canonical template name. 1815193326Sed /// 1816193326Sed /// Dependent template names are more interesting. Here, the 1817193326Sed /// template name could be something like T::template apply or 1818193326Sed /// std::allocator<T>::template rebind, where the nested name 1819193326Sed /// specifier itself is dependent. In this case, the canonical 1820193326Sed /// template name uses the shortest form of the dependent 1821193326Sed /// nested-name-specifier, which itself contains all canonical 1822193326Sed /// types, values, and templates. 1823218893Sdim TemplateName getCanonicalTemplateName(TemplateName Name) const; 1824193326Sed 1825199482Srdivacky /// \brief Determine whether the given template names refer to the same 1826199482Srdivacky /// template. 1827199482Srdivacky bool hasSameTemplateName(TemplateName X, TemplateName Y); 1828199482Srdivacky 1829198092Srdivacky /// \brief Retrieve the "canonical" template argument. 1830198092Srdivacky /// 1831198092Srdivacky /// The canonical template argument is the simplest template argument 1832198092Srdivacky /// (which may be a type, value, expression, or declaration) that 1833198092Srdivacky /// expresses the value of the argument. 1834218893Sdim TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg) 1835218893Sdim const; 1836198092Srdivacky 1837193326Sed /// Type Query functions. If the type is an instance of the specified class, 1838193326Sed /// return the Type pointer for the underlying maximally pretty type. This 1839193326Sed /// is a member of ASTContext because this may need to do some amount of 1840193326Sed /// canonicalization, e.g. to move type qualifiers into the element type. 1841218893Sdim const ArrayType *getAsArrayType(QualType T) const; 1842218893Sdim const ConstantArrayType *getAsConstantArrayType(QualType T) const { 1843193326Sed return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T)); 1844193326Sed } 1845218893Sdim const VariableArrayType *getAsVariableArrayType(QualType T) const { 1846193326Sed return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T)); 1847193326Sed } 1848218893Sdim const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const { 1849193326Sed return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T)); 1850193326Sed } 1851218893Sdim const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T) 1852218893Sdim const { 1853202379Srdivacky return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T)); 1854202379Srdivacky } 1855202379Srdivacky 1856243830Sdim /// \brief Return the innermost element type of an array type. 1857243830Sdim /// 1858198092Srdivacky /// For example, will return "int" for int[m][n] 1859218893Sdim QualType getBaseElementType(const ArrayType *VAT) const; 1860198092Srdivacky 1861243830Sdim /// \brief Return the innermost element type of a type (which needn't 1862243830Sdim /// actually be an array type). 1863218893Sdim QualType getBaseElementType(QualType QT) const; 1864198092Srdivacky 1865243830Sdim /// \brief Return number of constant array elements. 1866198092Srdivacky uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const; 1867198092Srdivacky 1868224145Sdim /// \brief Perform adjustment on the parameter type of a function. 1869224145Sdim /// 1870224145Sdim /// This routine adjusts the given parameter type @p T to the actual 1871224145Sdim /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8], 1872224145Sdim /// C++ [dcl.fct]p3). The adjusted parameter type is returned. 1873239462Sdim QualType getAdjustedParameterType(QualType T) const; 1874224145Sdim 1875224145Sdim /// \brief Retrieve the parameter type as adjusted for use in the signature 1876224145Sdim /// of a function, decaying array and function types and removing top-level 1877224145Sdim /// cv-qualifiers. 1878239462Sdim QualType getSignatureParameterType(QualType T) const; 1879224145Sdim 1880243830Sdim /// \brief Return the properly qualified result of decaying the specified 1881243830Sdim /// array type to a pointer. 1882193326Sed /// 1883243830Sdim /// This operation is non-trivial when handling typedefs etc. The canonical 1884243830Sdim /// type of \p T must be an array type, this returns a pointer to a properly 1885243830Sdim /// qualified element of the array. 1886243830Sdim /// 1887193326Sed /// See C99 6.7.5.3p7 and C99 6.3.2.1p3. 1888218893Sdim QualType getArrayDecayedType(QualType T) const; 1889198092Srdivacky 1890243830Sdim /// \brief Return the type that \p PromotableType will promote to: C99 1891243830Sdim /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type. 1892218893Sdim QualType getPromotedIntegerType(QualType PromotableType) const; 1893198092Srdivacky 1894243830Sdim /// \brief Recurses in pointer/array types until it finds an Objective-C 1895243830Sdim /// retainable type and returns its ownership. 1896224145Sdim Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const; 1897224145Sdim 1898198092Srdivacky /// \brief Whether this is a promotable bitfield reference according 1899198092Srdivacky /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions). 1900198092Srdivacky /// 1901198092Srdivacky /// \returns the type this bit-field will promote to, or NULL if no 1902198092Srdivacky /// promotion occurs. 1903218893Sdim QualType isPromotableBitField(Expr *E) const; 1904198092Srdivacky 1905243830Sdim /// \brief Return the highest ranked integer type, see C99 6.3.1.8p1. 1906243830Sdim /// 1907243830Sdim /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If 1908243830Sdim /// \p LHS < \p RHS, return -1. 1909218893Sdim int getIntegerTypeOrder(QualType LHS, QualType RHS) const; 1910198092Srdivacky 1911243830Sdim /// \brief Compare the rank of the two specified floating point types, 1912243830Sdim /// ignoring the domain of the type (i.e. 'double' == '_Complex double'). 1913243830Sdim /// 1914243830Sdim /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If 1915243830Sdim /// \p LHS < \p RHS, return -1. 1916218893Sdim int getFloatingTypeOrder(QualType LHS, QualType RHS) const; 1917193326Sed 1918243830Sdim /// \brief Return a real floating point or a complex type (based on 1919243830Sdim /// \p typeDomain/\p typeSize). 1920243830Sdim /// 1921243830Sdim /// \param typeDomain a real floating point or complex type. 1922243830Sdim /// \param typeSize a real floating point or complex type. 1923198092Srdivacky QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize, 1924193326Sed QualType typeDomain) const; 1925193326Sed 1926221345Sdim unsigned getTargetAddressSpace(QualType T) const { 1927221345Sdim return getTargetAddressSpace(T.getQualifiers()); 1928221345Sdim } 1929221345Sdim 1930221345Sdim unsigned getTargetAddressSpace(Qualifiers Q) const { 1931221345Sdim return getTargetAddressSpace(Q.getAddressSpace()); 1932221345Sdim } 1933221345Sdim 1934221345Sdim unsigned getTargetAddressSpace(unsigned AS) const { 1935221345Sdim if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count) 1936221345Sdim return AS; 1937221345Sdim else 1938226633Sdim return (*AddrSpaceMap)[AS - LangAS::Offset]; 1939221345Sdim } 1940221345Sdim 1941263508Sdim bool addressSpaceMapManglingFor(unsigned AS) const { 1942263508Sdim return AddrSpaceMapMangling || 1943263508Sdim AS < LangAS::Offset || 1944263508Sdim AS >= LangAS::Offset + LangAS::Count; 1945263508Sdim } 1946263508Sdim 1947193326Sedprivate: 1948193326Sed // Helper for integer ordering 1949218893Sdim unsigned getIntegerRank(const Type *T) const; 1950193326Sed 1951193326Sedpublic: 1952193326Sed 1953193326Sed //===--------------------------------------------------------------------===// 1954193326Sed // Type Compatibility Predicates 1955193326Sed //===--------------------------------------------------------------------===// 1956198092Srdivacky 1957193326Sed /// Compatibility predicates used to check assignment expressions. 1958212904Sdim bool typesAreCompatible(QualType T1, QualType T2, 1959212904Sdim bool CompareUnqualified = false); // C99 6.2.7p1 1960198092Srdivacky 1961224145Sdim bool propertyTypesAreCompatible(QualType, QualType); 1962205408Srdivacky bool typesAreBlockPointerCompatible(QualType, QualType); 1963205408Srdivacky 1964193326Sed bool isObjCIdType(QualType T) const { 1965226633Sdim return T == getObjCIdType(); 1966193326Sed } 1967193326Sed bool isObjCClassType(QualType T) const { 1968226633Sdim return T == getObjCClassType(); 1969193326Sed } 1970193326Sed bool isObjCSelType(QualType T) const { 1971226633Sdim return T == getObjCSelType(); 1972193326Sed } 1973198092Srdivacky bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, 1974198092Srdivacky bool ForCompare); 1975193326Sed 1976212904Sdim bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS); 1977212904Sdim 1978193326Sed // Check the safety of assignment from LHS to RHS 1979198092Srdivacky bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, 1980198092Srdivacky const ObjCObjectPointerType *RHSOPT); 1981208600Srdivacky bool canAssignObjCInterfaces(const ObjCObjectType *LHS, 1982208600Srdivacky const ObjCObjectType *RHS); 1983205408Srdivacky bool canAssignObjCInterfacesInBlockPointer( 1984205408Srdivacky const ObjCObjectPointerType *LHSOPT, 1985221345Sdim const ObjCObjectPointerType *RHSOPT, 1986221345Sdim bool BlockReturnType); 1987193326Sed bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); 1988198893Srdivacky QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, 1989198893Srdivacky const ObjCObjectPointerType *RHSOPT); 1990212904Sdim bool canBindObjCObjectType(QualType To, QualType From); 1991212904Sdim 1992193326Sed // Functions for calculating composite types 1993212904Sdim QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, 1994221345Sdim bool Unqualified = false, bool BlockReturnType = false); 1995212904Sdim QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false, 1996212904Sdim bool Unqualified = false); 1997218893Sdim QualType mergeFunctionArgumentTypes(QualType, QualType, 1998218893Sdim bool OfBlockPointer=false, 1999218893Sdim bool Unqualified = false); 2000218893Sdim QualType mergeTransparentUnionType(QualType, QualType, 2001218893Sdim bool OfBlockPointer=false, 2002218893Sdim bool Unqualified = false); 2003208600Srdivacky 2004208600Srdivacky QualType mergeObjCGCQualifiers(QualType, QualType); 2005226633Sdim 2006226633Sdim bool FunctionTypesMatchOnNSConsumedAttrs( 2007226633Sdim const FunctionProtoType *FromFunctionType, 2008226633Sdim const FunctionProtoType *ToFunctionType); 2009193326Sed 2010212904Sdim void ResetObjCLayout(const ObjCContainerDecl *CD) { 2011212904Sdim ObjCLayouts[CD] = 0; 2012212904Sdim } 2013198092Srdivacky 2014193326Sed //===--------------------------------------------------------------------===// 2015193326Sed // Integer Predicates 2016193326Sed //===--------------------------------------------------------------------===// 2017193326Sed 2018193326Sed // The width of an integer, as defined in C99 6.2.6.2. This is the number 2019193326Sed // of bits in an integer type excluding any padding bits. 2020218893Sdim unsigned getIntWidth(QualType T) const; 2021193326Sed 2022193326Sed // Per C99 6.2.5p6, for every signed integer type, there is a corresponding 2023193326Sed // unsigned integer type. This method takes a signed type, and returns the 2024193326Sed // corresponding unsigned integer type. 2025243830Sdim QualType getCorrespondingUnsignedType(QualType T) const; 2026193326Sed 2027193326Sed //===--------------------------------------------------------------------===// 2028193326Sed // Type Iterators. 2029193326Sed //===--------------------------------------------------------------------===// 2030198092Srdivacky 2031249423Sdim typedef SmallVectorImpl<Type *>::iterator type_iterator; 2032249423Sdim typedef SmallVectorImpl<Type *>::const_iterator const_type_iterator; 2033198092Srdivacky 2034193326Sed type_iterator types_begin() { return Types.begin(); } 2035193326Sed type_iterator types_end() { return Types.end(); } 2036193326Sed const_type_iterator types_begin() const { return Types.begin(); } 2037198092Srdivacky const_type_iterator types_end() const { return Types.end(); } 2038198092Srdivacky 2039193326Sed //===--------------------------------------------------------------------===// 2040193326Sed // Integer Values 2041193326Sed //===--------------------------------------------------------------------===// 2042193326Sed 2043243830Sdim /// \brief Make an APSInt of the appropriate width and signedness for the 2044243830Sdim /// given \p Value and integer \p Type. 2045218893Sdim llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const { 2046223017Sdim llvm::APSInt Res(getIntWidth(Type), 2047223017Sdim !Type->isSignedIntegerOrEnumerationType()); 2048193326Sed Res = Value; 2049193326Sed return Res; 2050193326Sed } 2051193326Sed 2052234353Sdim bool isSentinelNullExpr(const Expr *E); 2053234353Sdim 2054243830Sdim /// \brief Get the implementation of the ObjCInterfaceDecl \p D, or NULL if 2055243830Sdim /// none exists. 2056198092Srdivacky ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D); 2057243830Sdim /// \brief Get the implementation of the ObjCCategoryDecl \p D, or NULL if 2058243830Sdim /// none exists. 2059198092Srdivacky ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D); 2060198092Srdivacky 2061243830Sdim /// \brief Return true if there is at least one \@implementation in the TU. 2062218893Sdim bool AnyObjCImplementation() { 2063218893Sdim return !ObjCImpls.empty(); 2064218893Sdim } 2065218893Sdim 2066198092Srdivacky /// \brief Set the implementation of ObjCInterfaceDecl. 2067198092Srdivacky void setObjCImplementation(ObjCInterfaceDecl *IFaceD, 2068198092Srdivacky ObjCImplementationDecl *ImplD); 2069198092Srdivacky /// \brief Set the implementation of ObjCCategoryDecl. 2070198092Srdivacky void setObjCImplementation(ObjCCategoryDecl *CatD, 2071198092Srdivacky ObjCCategoryImplDecl *ImplD); 2072226633Sdim 2073226633Sdim /// \brief Get the duplicate declaration of a ObjCMethod in the same 2074243830Sdim /// interface, or null if none exists. 2075226633Sdim const ObjCMethodDecl *getObjCMethodRedeclaration( 2076226633Sdim const ObjCMethodDecl *MD) const { 2077239462Sdim return ObjCMethodRedecls.lookup(MD); 2078226633Sdim } 2079226633Sdim 2080226633Sdim void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, 2081226633Sdim const ObjCMethodDecl *Redecl) { 2082239462Sdim assert(!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration"); 2083226633Sdim ObjCMethodRedecls[MD] = Redecl; 2084226633Sdim } 2085234353Sdim 2086243830Sdim /// \brief Returns the Objective-C interface that \p ND belongs to if it is 2087243830Sdim /// an Objective-C method/property/ivar etc. that is part of an interface, 2088234353Sdim /// otherwise returns null. 2089249423Sdim const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const; 2090218893Sdim 2091218893Sdim /// \brief Set the copy inialization expression of a block var decl. 2092218893Sdim void setBlockVarCopyInits(VarDecl*VD, Expr* Init); 2093243830Sdim /// \brief Get the copy initialization expression of the VarDecl \p VD, or 2094243830Sdim /// NULL if none exists. 2095243830Sdim Expr *getBlockVarCopyInits(const VarDecl* VD); 2096198092Srdivacky 2097200583Srdivacky /// \brief Allocate an uninitialized TypeSourceInfo. 2098198092Srdivacky /// 2099200583Srdivacky /// The caller should initialize the memory held by TypeSourceInfo using 2100198092Srdivacky /// the TypeLoc wrappers. 2101198092Srdivacky /// 2102198092Srdivacky /// \param T the type that will be the basis for type source info. This type 2103198092Srdivacky /// should refer to how the declarator was written in source code, not to 2104198092Srdivacky /// what type semantic analysis resolved the declarator to. 2105198398Srdivacky /// 2106198398Srdivacky /// \param Size the size of the type info to create, or 0 if the size 2107198398Srdivacky /// should be calculated based on the type. 2108218893Sdim TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const; 2109198092Srdivacky 2110200583Srdivacky /// \brief Allocate a TypeSourceInfo where all locations have been 2111198893Srdivacky /// initialized to a given location, which defaults to the empty 2112198893Srdivacky /// location. 2113200583Srdivacky TypeSourceInfo * 2114218893Sdim getTrivialTypeSourceInfo(QualType T, 2115218893Sdim SourceLocation Loc = SourceLocation()) const; 2116198893Srdivacky 2117210299Sed TypeSourceInfo *getNullTypeSourceInfo() { return &NullTypeSourceInfo; } 2118210299Sed 2119208600Srdivacky /// \brief Add a deallocation callback that will be invoked when the 2120208600Srdivacky /// ASTContext is destroyed. 2121208600Srdivacky /// 2122243830Sdim /// \param Callback A callback function that will be invoked on destruction. 2123208600Srdivacky /// 2124243830Sdim /// \param Data Pointer data that will be provided to the callback function 2125208600Srdivacky /// when it is called. 2126208600Srdivacky void AddDeallocation(void (*Callback)(void*), void *Data); 2127210299Sed 2128212904Sdim GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD); 2129212904Sdim GVALinkage GetGVALinkageForVariable(const VarDecl *VD); 2130212904Sdim 2131212904Sdim /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH 2132212904Sdim /// lazily, only when used; this is only relevant for function or file scoped 2133212904Sdim /// var definitions. 2134212904Sdim /// 2135212904Sdim /// \returns true if the function/var must be CodeGen'ed/deserialized even if 2136212904Sdim /// it is not used. 2137212904Sdim bool DeclMustBeEmitted(const Decl *D); 2138212904Sdim 2139263508Sdim void setManglingNumber(const NamedDecl *ND, unsigned Number); 2140263508Sdim unsigned getManglingNumber(const NamedDecl *ND) const; 2141249423Sdim 2142263508Sdim /// \brief Retrieve the context for computing mangling numbers in the given 2143263508Sdim /// DeclContext. 2144263508Sdim MangleNumberingContext &getManglingNumberContext(const DeclContext *DC); 2145263508Sdim 2146263508Sdim MangleNumberingContext *createMangleNumberingContext() const; 2147263508Sdim 2148226633Sdim /// \brief Used by ParmVarDecl to store on the side the 2149226633Sdim /// index of the parameter when it exceeds the size of the normal bitfield. 2150226633Sdim void setParameterIndex(const ParmVarDecl *D, unsigned index); 2151226633Sdim 2152226633Sdim /// \brief Used by ParmVarDecl to retrieve on the side the 2153226633Sdim /// index of the parameter when it exceeds the size of the normal bitfield. 2154226633Sdim unsigned getParameterIndex(const ParmVarDecl *D) const; 2155263508Sdim 2156263508Sdim /// \brief Get the storage for the constant value of a materialized temporary 2157263508Sdim /// of static storage duration. 2158263508Sdim APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E, 2159263508Sdim bool MayCreate); 2160263508Sdim 2161210299Sed //===--------------------------------------------------------------------===// 2162210299Sed // Statistics 2163210299Sed //===--------------------------------------------------------------------===// 2164210299Sed 2165210299Sed /// \brief The number of implicitly-declared default constructors. 2166210299Sed static unsigned NumImplicitDefaultConstructors; 2167208600Srdivacky 2168210299Sed /// \brief The number of implicitly-declared default constructors for 2169210299Sed /// which declarations were built. 2170210299Sed static unsigned NumImplicitDefaultConstructorsDeclared; 2171210299Sed 2172210299Sed /// \brief The number of implicitly-declared copy constructors. 2173210299Sed static unsigned NumImplicitCopyConstructors; 2174210299Sed 2175210299Sed /// \brief The number of implicitly-declared copy constructors for 2176210299Sed /// which declarations were built. 2177210299Sed static unsigned NumImplicitCopyConstructorsDeclared; 2178210299Sed 2179223017Sdim /// \brief The number of implicitly-declared move constructors. 2180223017Sdim static unsigned NumImplicitMoveConstructors; 2181223017Sdim 2182223017Sdim /// \brief The number of implicitly-declared move constructors for 2183223017Sdim /// which declarations were built. 2184223017Sdim static unsigned NumImplicitMoveConstructorsDeclared; 2185223017Sdim 2186210299Sed /// \brief The number of implicitly-declared copy assignment operators. 2187210299Sed static unsigned NumImplicitCopyAssignmentOperators; 2188210299Sed 2189210299Sed /// \brief The number of implicitly-declared copy assignment operators for 2190210299Sed /// which declarations were built. 2191210299Sed static unsigned NumImplicitCopyAssignmentOperatorsDeclared; 2192210299Sed 2193223017Sdim /// \brief The number of implicitly-declared move assignment operators. 2194223017Sdim static unsigned NumImplicitMoveAssignmentOperators; 2195223017Sdim 2196223017Sdim /// \brief The number of implicitly-declared move assignment operators for 2197223017Sdim /// which declarations were built. 2198223017Sdim static unsigned NumImplicitMoveAssignmentOperatorsDeclared; 2199223017Sdim 2200210299Sed /// \brief The number of implicitly-declared destructors. 2201210299Sed static unsigned NumImplicitDestructors; 2202210299Sed 2203210299Sed /// \brief The number of implicitly-declared destructors for which 2204210299Sed /// declarations were built. 2205210299Sed static unsigned NumImplicitDestructorsDeclared; 2206210299Sed 2207193326Sedprivate: 2208243830Sdim ASTContext(const ASTContext &) LLVM_DELETED_FUNCTION; 2209243830Sdim void operator=(const ASTContext &) LLVM_DELETED_FUNCTION; 2210198092Srdivacky 2211226633Sdimpublic: 2212226633Sdim /// \brief Initialize built-in types. 2213226633Sdim /// 2214226633Sdim /// This routine may only be invoked once for a given ASTContext object. 2215226633Sdim /// It is normally invoked by the ASTContext constructor. However, the 2216226633Sdim /// constructor can be asked to delay initialization, which places the burden 2217226633Sdim /// of calling this function on the user of that object. 2218226633Sdim /// 2219226633Sdim /// \param Target The target 2220226633Sdim void InitBuiltinTypes(const TargetInfo &Target); 2221226633Sdim 2222226633Sdimprivate: 2223198893Srdivacky void InitBuiltinType(CanQualType &R, BuiltinType::Kind K); 2224198092Srdivacky 2225243830Sdim // Return the Objective-C type encoding for a given type. 2226198092Srdivacky void getObjCEncodingForTypeImpl(QualType t, std::string &S, 2227193326Sed bool ExpandPointedToStructures, 2228193326Sed bool ExpandStructures, 2229193326Sed const FieldDecl *Field, 2230193326Sed bool OutermostType = false, 2231223017Sdim bool EncodingProperty = false, 2232234353Sdim bool StructField = false, 2233234353Sdim bool EncodeBlockParameters = false, 2234249423Sdim bool EncodeClassNames = false, 2235249423Sdim bool EncodePointerToObjCTypedef = false) const; 2236223017Sdim 2237223017Sdim // Adds the encoding of the structure's members. 2238223017Sdim void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S, 2239223017Sdim const FieldDecl *Field, 2240223017Sdim bool includeVBases = true) const; 2241234353Sdim 2242234353Sdim // Adds the encoding of a method parameter or return type. 2243234353Sdim void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT, 2244234353Sdim QualType T, std::string& S, 2245234353Sdim bool Extended) const; 2246234353Sdim 2247218893Sdim const ASTRecordLayout & 2248218893Sdim getObjCLayout(const ObjCInterfaceDecl *D, 2249218893Sdim const ObjCImplementationDecl *Impl) const; 2250212904Sdim 2251203955Srdivackyprivate: 2252263508Sdim /// \brief A set of deallocations that should be performed when the 2253208600Srdivacky /// ASTContext is destroyed. 2254263508Sdim typedef llvm::SmallDenseMap<void(*)(void*), llvm::SmallVector<void*, 16> > 2255263508Sdim DeallocationMap; 2256263508Sdim DeallocationMap Deallocations; 2257263508Sdim 2258203955Srdivacky // FIXME: This currently contains the set of StoredDeclMaps used 2259203955Srdivacky // by DeclContext objects. This probably should not be in ASTContext, 2260203955Srdivacky // but we include it here so that ASTContext can quickly deallocate them. 2261206084Srdivacky llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM; 2262210299Sed 2263203955Srdivacky friend class DeclContext; 2264208600Srdivacky friend class DeclarationNameTable; 2265203955Srdivacky void ReleaseDeclContextMaps(); 2266249423Sdim 2267249423Sdim llvm::OwningPtr<ParentMap> AllParents; 2268193326Sed}; 2269249423Sdim 2270243830Sdim/// \brief Utility function for constructing a nullary selector. 2271226633Sdimstatic inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) { 2272198893Srdivacky IdentifierInfo* II = &Ctx.Idents.get(name); 2273198893Srdivacky return Ctx.Selectors.getSelector(0, &II); 2274198893Srdivacky} 2275193326Sed 2276243830Sdim/// \brief Utility function for constructing an unary selector. 2277226633Sdimstatic inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) { 2278198893Srdivacky IdentifierInfo* II = &Ctx.Idents.get(name); 2279198893Srdivacky return Ctx.Selectors.getSelector(1, &II); 2280198893Srdivacky} 2281198893Srdivacky 2282193326Sed} // end namespace clang 2283193326Sed 2284193326Sed// operator new and delete aren't allowed inside namespaces. 2285234353Sdim 2286193326Sed/// @brief Placement new for using the ASTContext's allocator. 2287193326Sed/// 2288193326Sed/// This placement form of operator new uses the ASTContext's allocator for 2289234353Sdim/// obtaining memory. 2290234353Sdim/// 2291249423Sdim/// IMPORTANT: These are also declared in clang/AST/AttrIterator.h! Any changes 2292249423Sdim/// here need to also be made there. 2293234353Sdim/// 2294234353Sdim/// We intentionally avoid using a nothrow specification here so that the calls 2295234353Sdim/// to this operator will not perform a null check on the result -- the 2296234353Sdim/// underlying allocator never returns null pointers. 2297234353Sdim/// 2298193326Sed/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 2299193326Sed/// @code 2300205408Srdivacky/// // Default alignment (8) 2301193326Sed/// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments); 2302193326Sed/// // Specific alignment 2303205408Srdivacky/// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments); 2304193326Sed/// @endcode 2305193326Sed/// Please note that you cannot use delete on the pointer; it must be 2306193326Sed/// deallocated using an explicit destructor call followed by 2307193326Sed/// @c Context.Deallocate(Ptr). 2308193326Sed/// 2309193326Sed/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 2310193326Sed/// @param C The ASTContext that provides the allocator. 2311193326Sed/// @param Alignment The alignment of the allocated memory (if the underlying 2312193326Sed/// allocator supports it). 2313193326Sed/// @return The allocated memory. Could be NULL. 2314218893Sdiminline void *operator new(size_t Bytes, const clang::ASTContext &C, 2315234353Sdim size_t Alignment) { 2316193326Sed return C.Allocate(Bytes, Alignment); 2317193326Sed} 2318193326Sed/// @brief Placement delete companion to the new above. 2319193326Sed/// 2320193326Sed/// This operator is just a companion to the new above. There is no way of 2321193326Sed/// invoking it directly; see the new operator for more details. This operator 2322193326Sed/// is called implicitly by the compiler if a placement new expression using 2323193326Sed/// the ASTContext throws in the object constructor. 2324234353Sdiminline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) { 2325193326Sed C.Deallocate(Ptr); 2326193326Sed} 2327193326Sed 2328193326Sed/// This placement form of operator new[] uses the ASTContext's allocator for 2329234353Sdim/// obtaining memory. 2330234353Sdim/// 2331234353Sdim/// We intentionally avoid using a nothrow specification here so that the calls 2332234353Sdim/// to this operator will not perform a null check on the result -- the 2333234353Sdim/// underlying allocator never returns null pointers. 2334234353Sdim/// 2335193326Sed/// Usage looks like this (assuming there's an ASTContext 'Context' in scope): 2336193326Sed/// @code 2337205408Srdivacky/// // Default alignment (8) 2338193326Sed/// char *data = new (Context) char[10]; 2339193326Sed/// // Specific alignment 2340205408Srdivacky/// char *data = new (Context, 4) char[10]; 2341193326Sed/// @endcode 2342193326Sed/// Please note that you cannot use delete on the pointer; it must be 2343193326Sed/// deallocated using an explicit destructor call followed by 2344193326Sed/// @c Context.Deallocate(Ptr). 2345193326Sed/// 2346193326Sed/// @param Bytes The number of bytes to allocate. Calculated by the compiler. 2347193326Sed/// @param C The ASTContext that provides the allocator. 2348193326Sed/// @param Alignment The alignment of the allocated memory (if the underlying 2349193326Sed/// allocator supports it). 2350193326Sed/// @return The allocated memory. Could be NULL. 2351218893Sdiminline void *operator new[](size_t Bytes, const clang::ASTContext& C, 2352234353Sdim size_t Alignment = 8) { 2353193326Sed return C.Allocate(Bytes, Alignment); 2354193326Sed} 2355193326Sed 2356193326Sed/// @brief Placement delete[] companion to the new[] above. 2357193326Sed/// 2358193326Sed/// This operator is just a companion to the new[] above. There is no way of 2359193326Sed/// invoking it directly; see the new[] operator for more details. This operator 2360193326Sed/// is called implicitly by the compiler if a placement new[] expression using 2361193326Sed/// the ASTContext throws in the object constructor. 2362234353Sdiminline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) { 2363193326Sed C.Deallocate(Ptr); 2364193326Sed} 2365193326Sed 2366193326Sed#endif 2367