LCOV - code coverage report
Current view: top level - clang/AST - ASTContext.h (source / functions) Hit Total Coverage
Test: clang.info Lines: 3 13 23.1 %
Date: 2016-01-31 12:01:00 Functions: 3 9 33.3 %

          Line data    Source code
       1             : //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : ///
      10             : /// \file
      11             : /// \brief Defines the clang::ASTContext interface.
      12             : ///
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
      16             : #define LLVM_CLANG_AST_ASTCONTEXT_H
      17             : 
      18             : #include "clang/AST/ASTTypeTraits.h"
      19             : #include "clang/AST/CanonicalType.h"
      20             : #include "clang/AST/CommentCommandTraits.h"
      21             : #include "clang/AST/Decl.h"
      22             : #include "clang/AST/ExternalASTSource.h"
      23             : #include "clang/AST/NestedNameSpecifier.h"
      24             : #include "clang/AST/PrettyPrinter.h"
      25             : #include "clang/AST/RawCommentList.h"
      26             : #include "clang/AST/TemplateName.h"
      27             : #include "clang/AST/Type.h"
      28             : #include "clang/Basic/AddressSpaces.h"
      29             : #include "clang/Basic/IdentifierTable.h"
      30             : #include "clang/Basic/LangOptions.h"
      31             : #include "clang/Basic/OperatorKinds.h"
      32             : #include "clang/Basic/PartialDiagnostic.h"
      33             : #include "clang/Basic/SanitizerBlacklist.h"
      34             : #include "clang/Basic/VersionTuple.h"
      35             : #include "llvm/ADT/DenseMap.h"
      36             : #include "llvm/ADT/FoldingSet.h"
      37             : #include "llvm/ADT/IntrusiveRefCntPtr.h"
      38             : #include "llvm/ADT/SmallPtrSet.h"
      39             : #include "llvm/ADT/TinyPtrVector.h"
      40             : #include "llvm/Support/Allocator.h"
      41             : #include <memory>
      42             : #include <vector>
      43             : 
      44             : namespace llvm {
      45             :   struct fltSemantics;
      46             : }
      47             : 
      48             : namespace clang {
      49             :   class FileManager;
      50             :   class AtomicExpr;
      51             :   class ASTRecordLayout;
      52             :   class BlockExpr;
      53             :   class CharUnits;
      54             :   class DiagnosticsEngine;
      55             :   class Expr;
      56             :   class ASTMutationListener;
      57             :   class IdentifierTable;
      58             :   class MaterializeTemporaryExpr;
      59             :   class SelectorTable;
      60             :   class TargetInfo;
      61             :   class CXXABI;
      62             :   class MangleNumberingContext;
      63             :   // Decls
      64             :   class MangleContext;
      65             :   class ObjCIvarDecl;
      66             :   class ObjCPropertyDecl;
      67             :   class UnresolvedSetIterator;
      68             :   class UsingDecl;
      69             :   class UsingShadowDecl;
      70             :   class VTableContextBase;
      71             : 
      72             :   namespace Builtin { class Context; }
      73             : 
      74             :   namespace comments {
      75             :     class FullComment;
      76             :   }
      77             : 
      78             :   struct TypeInfo {
      79             :     uint64_t Width;
      80             :     unsigned Align;
      81             :     bool AlignIsRequired : 1;
      82             :     TypeInfo() : Width(0), Align(0), AlignIsRequired(false) {}
      83             :     TypeInfo(uint64_t Width, unsigned Align, bool AlignIsRequired)
      84             :         : Width(Width), Align(Align), AlignIsRequired(AlignIsRequired) {}
      85             :   };
      86             : 
      87             : /// \brief Holds long-lived AST nodes (such as types and decls) that can be
      88             : /// referred to throughout the semantic analysis of a file.
      89             : class ASTContext : public RefCountedBase<ASTContext> {
      90             :   ASTContext &this_() { return *this; }
      91             : 
      92             :   mutable SmallVector<Type *, 0> Types;
      93             :   mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
      94             :   mutable llvm::FoldingSet<ComplexType> ComplexTypes;
      95             :   mutable llvm::FoldingSet<PointerType> PointerTypes;
      96             :   mutable llvm::FoldingSet<AdjustedType> AdjustedTypes;
      97             :   mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
      98             :   mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
      99             :   mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
     100             :   mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
     101             :   mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
     102             :   mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
     103             :   mutable std::vector<VariableArrayType*> VariableArrayTypes;
     104             :   mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
     105             :   mutable llvm::FoldingSet<DependentSizedExtVectorType>
     106             :     DependentSizedExtVectorTypes;
     107             :   mutable llvm::FoldingSet<VectorType> VectorTypes;
     108             :   mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
     109             :   mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
     110             :     FunctionProtoTypes;
     111             :   mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
     112             :   mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
     113             :   mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
     114             :   mutable llvm::FoldingSet<SubstTemplateTypeParmType>
     115             :     SubstTemplateTypeParmTypes;
     116             :   mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
     117             :     SubstTemplateTypeParmPackTypes;
     118             :   mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
     119             :     TemplateSpecializationTypes;
     120             :   mutable llvm::FoldingSet<ParenType> ParenTypes;
     121             :   mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
     122             :   mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
     123             :   mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType,
     124             :                                      ASTContext&>
     125             :     DependentTemplateSpecializationTypes;
     126             :   llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
     127             :   mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
     128             :   mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
     129             :   mutable llvm::FoldingSet<AutoType> AutoTypes;
     130             :   mutable llvm::FoldingSet<AtomicType> AtomicTypes;
     131             :   llvm::FoldingSet<AttributedType> AttributedTypes;
     132             : 
     133             :   mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
     134             :   mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
     135             :   mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage> 
     136             :     SubstTemplateTemplateParms;
     137             :   mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
     138             :                                      ASTContext&> 
     139             :     SubstTemplateTemplateParmPacks;
     140             :   
     141             :   /// \brief The set of nested name specifiers.
     142             :   ///
     143             :   /// This set is managed by the NestedNameSpecifier class.
     144             :   mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
     145             :   mutable NestedNameSpecifier *GlobalNestedNameSpecifier;
     146             :   friend class NestedNameSpecifier;
     147             : 
     148             :   /// \brief A cache mapping from RecordDecls to ASTRecordLayouts.
     149             :   ///
     150             :   /// This is lazily created.  This is intentionally not serialized.
     151             :   mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
     152             :     ASTRecordLayouts;
     153             :   mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
     154             :     ObjCLayouts;
     155             : 
     156             :   /// \brief A cache from types to size and alignment information.
     157             :   typedef llvm::DenseMap<const Type *, struct TypeInfo> TypeInfoMap;
     158             :   mutable TypeInfoMap MemoizedTypeInfo;
     159             : 
     160             :   /// \brief A cache mapping from CXXRecordDecls to key functions.
     161             :   llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions;
     162             :   
     163             :   /// \brief Mapping from ObjCContainers to their ObjCImplementations.
     164             :   llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
     165             :   
     166             :   /// \brief Mapping from ObjCMethod to its duplicate declaration in the same
     167             :   /// interface.
     168             :   llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
     169             : 
     170             :   /// \brief Mapping from __block VarDecls to their copy initialization expr.
     171             :   llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits;
     172             :     
     173             :   /// \brief Mapping from class scope functions specialization to their
     174             :   /// template patterns.
     175             :   llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
     176             :     ClassScopeSpecializationPattern;
     177             : 
     178             :   /// \brief Mapping from materialized temporaries with static storage duration
     179             :   /// that appear in constant initializers to their evaluated values.
     180             :   llvm::DenseMap<const MaterializeTemporaryExpr*, APValue>
     181             :     MaterializedTemporaryValues;
     182             : 
     183             :   /// \brief Representation of a "canonical" template template parameter that
     184             :   /// is used in canonical template names.
     185             :   class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
     186             :     TemplateTemplateParmDecl *Parm;
     187             :     
     188             :   public:
     189             :     CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm) 
     190             :       : Parm(Parm) { }
     191             :     
     192             :     TemplateTemplateParmDecl *getParam() const { return Parm; }
     193             :     
     194             :     void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
     195             :     
     196             :     static void Profile(llvm::FoldingSetNodeID &ID, 
     197             :                         TemplateTemplateParmDecl *Parm);
     198             :   };
     199             :   mutable llvm::FoldingSet<CanonicalTemplateTemplateParm>
     200             :     CanonTemplateTemplateParms;
     201             :   
     202             :   TemplateTemplateParmDecl *
     203             :     getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
     204             : 
     205             :   /// \brief The typedef for the __int128_t type.
     206             :   mutable TypedefDecl *Int128Decl;
     207             : 
     208             :   /// \brief The typedef for the __uint128_t type.
     209             :   mutable TypedefDecl *UInt128Decl;
     210             : 
     211             :   /// \brief The typedef for the __float128 stub type.
     212             :   mutable TypeDecl *Float128StubDecl;
     213             :   
     214             :   /// \brief The typedef for the target specific predefined
     215             :   /// __builtin_va_list type.
     216             :   mutable TypedefDecl *BuiltinVaListDecl;
     217             : 
     218             :   /// \brief The typedef for the predefined \c id type.
     219             :   mutable TypedefDecl *ObjCIdDecl;
     220             :   
     221             :   /// \brief The typedef for the predefined \c SEL type.
     222             :   mutable TypedefDecl *ObjCSelDecl;
     223             : 
     224             :   /// \brief The typedef for the predefined \c Class type.
     225             :   mutable TypedefDecl *ObjCClassDecl;
     226             : 
     227             :   /// \brief The typedef for the predefined \c Protocol class in Objective-C.
     228             :   mutable ObjCInterfaceDecl *ObjCProtocolClassDecl;
     229             :   
     230             :   /// \brief The typedef for the predefined 'BOOL' type.
     231             :   mutable TypedefDecl *BOOLDecl;
     232             : 
     233             :   // Typedefs which may be provided defining the structure of Objective-C
     234             :   // pseudo-builtins
     235             :   QualType ObjCIdRedefinitionType;
     236             :   QualType ObjCClassRedefinitionType;
     237             :   QualType ObjCSelRedefinitionType;
     238             : 
     239             :   /// The identifier 'NSObject'.
     240             :   IdentifierInfo *NSObjectName = nullptr;
     241             : 
     242             :   /// The identifier 'NSCopying'.
     243             :   IdentifierInfo *NSCopyingName = nullptr;
     244             : 
     245             :   QualType ObjCConstantStringType;
     246             :   mutable RecordDecl *CFConstantStringTypeDecl;
     247             :   
     248             :   mutable QualType ObjCSuperType;
     249             :   
     250             :   QualType ObjCNSStringType;
     251             : 
     252             :   /// \brief The typedef declaration for the Objective-C "instancetype" type.
     253             :   TypedefDecl *ObjCInstanceTypeDecl;
     254             :   
     255             :   /// \brief The type for the C FILE type.
     256             :   TypeDecl *FILEDecl;
     257             : 
     258             :   /// \brief The type for the C jmp_buf type.
     259             :   TypeDecl *jmp_bufDecl;
     260             : 
     261             :   /// \brief The type for the C sigjmp_buf type.
     262             :   TypeDecl *sigjmp_bufDecl;
     263             : 
     264             :   /// \brief The type for the C ucontext_t type.
     265             :   TypeDecl *ucontext_tDecl;
     266             : 
     267             :   /// \brief Type for the Block descriptor for Blocks CodeGen.
     268             :   ///
     269             :   /// Since this is only used for generation of debug info, it is not
     270             :   /// serialized.
     271             :   mutable RecordDecl *BlockDescriptorType;
     272             : 
     273             :   /// \brief Type for the Block descriptor for Blocks CodeGen.
     274             :   ///
     275             :   /// Since this is only used for generation of debug info, it is not
     276             :   /// serialized.
     277             :   mutable RecordDecl *BlockDescriptorExtendedType;
     278             : 
     279             :   /// \brief Declaration for the CUDA cudaConfigureCall function.
     280             :   FunctionDecl *cudaConfigureCallDecl;
     281             : 
     282             :   /// \brief Keeps track of all declaration attributes.
     283             :   ///
     284             :   /// Since so few decls have attrs, we keep them in a hash map instead of
     285             :   /// wasting space in the Decl class.
     286             :   llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
     287             : 
     288             :   /// \brief A mapping from non-redeclarable declarations in modules that were
     289             :   /// merged with other declarations to the canonical declaration that they were
     290             :   /// merged into.
     291             :   llvm::DenseMap<Decl*, Decl*> MergedDecls;
     292             : 
     293             :   /// \brief A mapping from a defining declaration to a list of modules (other
     294             :   /// than the owning module of the declaration) that contain merged
     295             :   /// definitions of that entity.
     296             :   llvm::DenseMap<NamedDecl*, llvm::TinyPtrVector<Module*>> MergedDefModules;
     297             : 
     298             : public:
     299             :   /// \brief A type synonym for the TemplateOrInstantiation mapping.
     300             :   typedef llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *>
     301             :   TemplateOrSpecializationInfo;
     302             : 
     303             : private:
     304             : 
     305             :   /// \brief A mapping to contain the template or declaration that
     306             :   /// a variable declaration describes or was instantiated from,
     307             :   /// respectively.
     308             :   ///
     309             :   /// For non-templates, this value will be NULL. For variable
     310             :   /// declarations that describe a variable template, this will be a
     311             :   /// pointer to a VarTemplateDecl. For static data members
     312             :   /// of class template specializations, this will be the
     313             :   /// MemberSpecializationInfo referring to the member variable that was
     314             :   /// instantiated or specialized. Thus, the mapping will keep track of
     315             :   /// the static data member templates from which static data members of
     316             :   /// class template specializations were instantiated.
     317             :   ///
     318             :   /// Given the following example:
     319             :   ///
     320             :   /// \code
     321             :   /// template<typename T>
     322             :   /// struct X {
     323             :   ///   static T value;
     324             :   /// };
     325             :   ///
     326             :   /// template<typename T>
     327             :   ///   T X<T>::value = T(17);
     328             :   ///
     329             :   /// int *x = &X<int>::value;
     330             :   /// \endcode
     331             :   ///
     332             :   /// This mapping will contain an entry that maps from the VarDecl for
     333             :   /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
     334             :   /// class template X) and will be marked TSK_ImplicitInstantiation.
     335             :   llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>
     336             :   TemplateOrInstantiation;
     337             : 
     338             :   /// \brief Keeps track of the declaration from which a UsingDecl was
     339             :   /// created during instantiation.
     340             :   ///
     341             :   /// The source declaration is always a UsingDecl, an UnresolvedUsingValueDecl,
     342             :   /// or an UnresolvedUsingTypenameDecl.
     343             :   ///
     344             :   /// For example:
     345             :   /// \code
     346             :   /// template<typename T>
     347             :   /// struct A {
     348             :   ///   void f();
     349             :   /// };
     350             :   ///
     351             :   /// template<typename T>
     352             :   /// struct B : A<T> {
     353             :   ///   using A<T>::f;
     354             :   /// };
     355             :   ///
     356             :   /// template struct B<int>;
     357             :   /// \endcode
     358             :   ///
     359             :   /// This mapping will contain an entry that maps from the UsingDecl in
     360             :   /// B<int> to the UnresolvedUsingDecl in B<T>.
     361             :   llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
     362             : 
     363             :   llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
     364             :     InstantiatedFromUsingShadowDecl;
     365             : 
     366             :   llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
     367             : 
     368             :   /// \brief Mapping that stores the methods overridden by a given C++
     369             :   /// member function.
     370             :   ///
     371             :   /// Since most C++ member functions aren't virtual and therefore
     372             :   /// don't override anything, we store the overridden functions in
     373             :   /// this map on the side rather than within the CXXMethodDecl structure.
     374             :   typedef llvm::TinyPtrVector<const CXXMethodDecl*> CXXMethodVector;
     375             :   llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
     376             : 
     377             :   /// \brief Mapping from each declaration context to its corresponding
     378             :   /// mangling numbering context (used for constructs like lambdas which
     379             :   /// need to be consistently numbered for the mangler).
     380             :   llvm::DenseMap<const DeclContext *, MangleNumberingContext *>
     381             :       MangleNumberingContexts;
     382             : 
     383             :   /// \brief Side-table of mangling numbers for declarations which rarely
     384             :   /// need them (like static local vars).
     385             :   llvm::DenseMap<const NamedDecl *, unsigned> MangleNumbers;
     386             :   llvm::DenseMap<const VarDecl *, unsigned> StaticLocalNumbers;
     387             : 
     388             :   /// \brief Mapping that stores parameterIndex values for ParmVarDecls when
     389             :   /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex.
     390             :   typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable;
     391             :   ParameterIndexTable ParamIndices;  
     392             :   
     393             :   ImportDecl *FirstLocalImport;
     394             :   ImportDecl *LastLocalImport;
     395             :   
     396             :   TranslationUnitDecl *TUDecl;
     397             :   mutable ExternCContextDecl *ExternCContext;
     398             : 
     399             :   /// \brief The associated SourceManager object.a
     400             :   SourceManager &SourceMgr;
     401             : 
     402             :   /// \brief The language options used to create the AST associated with
     403             :   ///  this ASTContext object.
     404             :   LangOptions &LangOpts;
     405             : 
     406             :   /// \brief Blacklist object that is used by sanitizers to decide which
     407             :   /// entities should not be instrumented.
     408             :   std::unique_ptr<SanitizerBlacklist> SanitizerBL;
     409             : 
     410             :   /// \brief The allocator used to create AST objects.
     411             :   ///
     412             :   /// AST objects are never destructed; rather, all memory associated with the
     413             :   /// AST objects will be released when the ASTContext itself is destroyed.
     414             :   mutable llvm::BumpPtrAllocator BumpAlloc;
     415             : 
     416             :   /// \brief Allocator for partial diagnostics.
     417             :   PartialDiagnostic::StorageAllocator DiagAllocator;
     418             : 
     419             :   /// \brief The current C++ ABI.
     420             :   std::unique_ptr<CXXABI> ABI;
     421             :   CXXABI *createCXXABI(const TargetInfo &T);
     422             : 
     423             :   /// \brief The logical -> physical address space map.
     424             :   const LangAS::Map *AddrSpaceMap;
     425             : 
     426             :   /// \brief Address space map mangling must be used with language specific 
     427             :   /// address spaces (e.g. OpenCL/CUDA)
     428             :   bool AddrSpaceMapMangling;
     429             : 
     430             :   friend class ASTDeclReader;
     431             :   friend class ASTReader;
     432             :   friend class ASTWriter;
     433             :   friend class CXXRecordDecl;
     434             : 
     435             :   const TargetInfo *Target;
     436             :   clang::PrintingPolicy PrintingPolicy;
     437             :   
     438             : public:
     439             :   IdentifierTable &Idents;
     440             :   SelectorTable &Selectors;
     441             :   Builtin::Context &BuiltinInfo;
     442             :   mutable DeclarationNameTable DeclarationNames;
     443             :   IntrusiveRefCntPtr<ExternalASTSource> ExternalSource;
     444             :   ASTMutationListener *Listener;
     445             : 
     446             :   /// \brief Contains parents of a node.
     447             :   typedef llvm::SmallVector<ast_type_traits::DynTypedNode, 2> ParentVector;
     448             : 
     449             :   /// \brief Maps from a node to its parents.
     450             :   typedef llvm::DenseMap<const void *,
     451             :                          llvm::PointerUnion<ast_type_traits::DynTypedNode *,
     452             :                                             ParentVector *>> ParentMap;
     453             : 
     454             :   /// \brief Returns the parents of the given node.
     455             :   ///
     456             :   /// Note that this will lazily compute the parents of all nodes
     457             :   /// and store them for later retrieval. Thus, the first call is O(n)
     458             :   /// in the number of AST nodes.
     459             :   ///
     460             :   /// Caveats and FIXMEs:
     461             :   /// Calculating the parent map over all AST nodes will need to load the
     462             :   /// full AST. This can be undesirable in the case where the full AST is
     463             :   /// expensive to create (for example, when using precompiled header
     464             :   /// preambles). Thus, there are good opportunities for optimization here.
     465             :   /// One idea is to walk the given node downwards, looking for references
     466             :   /// to declaration contexts - once a declaration context is found, compute
     467             :   /// the parent map for the declaration context; if that can satisfy the
     468             :   /// request, loading the whole AST can be avoided. Note that this is made
     469             :   /// more complex by statements in templates having multiple parents - those
     470             :   /// problems can be solved by building closure over the templated parts of
     471             :   /// the AST, which also avoids touching large parts of the AST.
     472             :   /// Additionally, we will want to add an interface to already give a hint
     473             :   /// where to search for the parents, for example when looking at a statement
     474             :   /// inside a certain function.
     475             :   ///
     476             :   /// 'NodeT' can be one of Decl, Stmt, Type, TypeLoc,
     477             :   /// NestedNameSpecifier or NestedNameSpecifierLoc.
     478             :   template <typename NodeT>
     479             :   ArrayRef<ast_type_traits::DynTypedNode> getParents(const NodeT &Node) {
     480             :     return getParents(ast_type_traits::DynTypedNode::create(Node));
     481             :   }
     482             : 
     483             :   ArrayRef<ast_type_traits::DynTypedNode>
     484             :   getParents(const ast_type_traits::DynTypedNode &Node);
     485             : 
     486             :   const clang::PrintingPolicy &getPrintingPolicy() const {
     487             :     return PrintingPolicy;
     488             :   }
     489             : 
     490             :   void setPrintingPolicy(const clang::PrintingPolicy &Policy) {
     491             :     PrintingPolicy = Policy;
     492             :   }
     493             :   
     494          23 :   SourceManager& getSourceManager() { return SourceMgr; }
     495             :   const SourceManager& getSourceManager() const { return SourceMgr; }
     496             : 
     497             :   llvm::BumpPtrAllocator &getAllocator() const {
     498             :     return BumpAlloc;
     499             :   }
     500             : 
     501             :   void *Allocate(size_t Size, unsigned Align = 8) const {
     502           0 :     return BumpAlloc.Allocate(Size, Align);
     503             :   }
     504           0 :   void Deallocate(void *Ptr) const { }
     505             :   
     506             :   /// Return the total amount of physical memory allocated for representing
     507             :   /// AST nodes and type information.
     508             :   size_t getASTAllocatedMemory() const {
     509             :     return BumpAlloc.getTotalMemory();
     510             :   }
     511             :   /// Return the total memory used for various side tables.
     512             :   size_t getSideTableAllocatedMemory() const;
     513             :   
     514             :   PartialDiagnostic::StorageAllocator &getDiagAllocator() {
     515             :     return DiagAllocator;
     516             :   }
     517             : 
     518             :   const TargetInfo &getTargetInfo() const { return *Target; }
     519             :   
     520             :   /// getIntTypeForBitwidth -
     521             :   /// sets integer QualTy according to specified details:
     522             :   /// bitwidth, signed/unsigned.
     523             :   /// Returns empty type if there is no appropriate target types.
     524             :   QualType getIntTypeForBitwidth(unsigned DestWidth,
     525             :                                  unsigned Signed) const;
     526             :   /// getRealTypeForBitwidth -
     527             :   /// sets floating point QualTy according to specified bitwidth.
     528             :   /// Returns empty type if there is no appropriate target types.
     529             :   QualType getRealTypeForBitwidth(unsigned DestWidth) const;
     530             : 
     531             :   bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const;
     532             :   
     533          12 :   const LangOptions& getLangOpts() const { return LangOpts; }
     534             : 
     535             :   const SanitizerBlacklist &getSanitizerBlacklist() const {
     536             :     return *SanitizerBL;
     537             :   }
     538             : 
     539             :   DiagnosticsEngine &getDiagnostics() const;
     540             : 
     541             :   FullSourceLoc getFullLoc(SourceLocation Loc) const {
     542             :     return FullSourceLoc(Loc,SourceMgr);
     543             :   }
     544             : 
     545             :   /// \brief All comments in this translation unit.
     546             :   RawCommentList Comments;
     547             : 
     548             :   /// \brief True if comments are already loaded from ExternalASTSource.
     549             :   mutable bool CommentsLoaded;
     550             : 
     551             :   class RawCommentAndCacheFlags {
     552             :   public:
     553             :     enum Kind {
     554             :       /// We searched for a comment attached to the particular declaration, but
     555             :       /// didn't find any.
     556             :       ///
     557             :       /// getRaw() == 0.
     558             :       NoCommentInDecl = 0,
     559             : 
     560             :       /// We have found a comment attached to this particular declaration.
     561             :       ///
     562             :       /// getRaw() != 0.
     563             :       FromDecl,
     564             : 
     565             :       /// This declaration does not have an attached comment, and we have
     566             :       /// searched the redeclaration chain.
     567             :       ///
     568             :       /// If getRaw() == 0, the whole redeclaration chain does not have any
     569             :       /// comments.
     570             :       ///
     571             :       /// If getRaw() != 0, it is a comment propagated from other
     572             :       /// redeclaration.
     573             :       FromRedecl
     574             :     };
     575             : 
     576             :     Kind getKind() const LLVM_READONLY {
     577             :       return Data.getInt();
     578             :     }
     579             : 
     580             :     void setKind(Kind K) {
     581             :       Data.setInt(K);
     582             :     }
     583             : 
     584             :     const RawComment *getRaw() const LLVM_READONLY {
     585             :       return Data.getPointer();
     586             :     }
     587             : 
     588             :     void setRaw(const RawComment *RC) {
     589             :       Data.setPointer(RC);
     590             :     }
     591             : 
     592             :     const Decl *getOriginalDecl() const LLVM_READONLY {
     593             :       return OriginalDecl;
     594             :     }
     595             : 
     596             :     void setOriginalDecl(const Decl *Orig) {
     597             :       OriginalDecl = Orig;
     598             :     }
     599             : 
     600             :   private:
     601             :     llvm::PointerIntPair<const RawComment *, 2, Kind> Data;
     602             :     const Decl *OriginalDecl;
     603             :   };
     604             : 
     605             :   /// \brief Mapping from declarations to comments attached to any
     606             :   /// redeclaration.
     607             :   ///
     608             :   /// Raw comments are owned by Comments list.  This mapping is populated
     609             :   /// lazily.
     610             :   mutable llvm::DenseMap<const Decl *, RawCommentAndCacheFlags> RedeclComments;
     611             : 
     612             :   /// \brief Mapping from declarations to parsed comments attached to any
     613             :   /// redeclaration.
     614             :   mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments;
     615             : 
     616             :   /// \brief Return the documentation comment attached to a given declaration,
     617             :   /// without looking into cache.
     618             :   RawComment *getRawCommentForDeclNoCache(const Decl *D) const;
     619             : 
     620             : public:
     621             :   RawCommentList &getRawCommentList() {
     622             :     return Comments;
     623             :   }
     624             : 
     625             :   void addComment(const RawComment &RC) {
     626             :     assert(LangOpts.RetainCommentsFromSystemHeaders ||
     627             :            !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin()));
     628             :     Comments.addComment(RC, BumpAlloc);
     629             :   }
     630             : 
     631             :   /// \brief Return the documentation comment attached to a given declaration.
     632             :   /// Returns NULL if no comment is attached.
     633             :   ///
     634             :   /// \param OriginalDecl if not NULL, is set to declaration AST node that had
     635             :   /// the comment, if the comment we found comes from a redeclaration.
     636             :   const RawComment *
     637             :   getRawCommentForAnyRedecl(const Decl *D,
     638             :                             const Decl **OriginalDecl = nullptr) const;
     639             : 
     640             :   /// Return parsed documentation comment attached to a given declaration.
     641             :   /// Returns NULL if no comment is attached.
     642             :   ///
     643             :   /// \param PP the Preprocessor used with this TU.  Could be NULL if
     644             :   /// preprocessor is not available.
     645             :   comments::FullComment *getCommentForDecl(const Decl *D,
     646             :                                            const Preprocessor *PP) const;
     647             : 
     648             :   /// Return parsed documentation comment attached to a given declaration.
     649             :   /// Returns NULL if no comment is attached. Does not look at any
     650             :   /// redeclarations of the declaration.
     651             :   comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const;
     652             : 
     653             :   comments::FullComment *cloneFullComment(comments::FullComment *FC,
     654             :                                          const Decl *D) const;
     655             : 
     656             : private:
     657             :   mutable comments::CommandTraits CommentCommandTraits;
     658             : 
     659             :   /// \brief Iterator that visits import declarations.
     660             :   class import_iterator {
     661             :     ImportDecl *Import;
     662             : 
     663             :   public:
     664             :     typedef ImportDecl               *value_type;
     665             :     typedef ImportDecl               *reference;
     666             :     typedef ImportDecl               *pointer;
     667             :     typedef int                       difference_type;
     668             :     typedef std::forward_iterator_tag iterator_category;
     669             : 
     670             :     import_iterator() : Import() {}
     671             :     explicit import_iterator(ImportDecl *Import) : Import(Import) {}
     672             : 
     673             :     reference operator*() const { return Import; }
     674             :     pointer operator->() const { return Import; }
     675             : 
     676             :     import_iterator &operator++() {
     677             :       Import = ASTContext::getNextLocalImport(Import);
     678             :       return *this;
     679             :     }
     680             : 
     681             :     import_iterator operator++(int) {
     682             :       import_iterator Other(*this);
     683             :       ++(*this);
     684             :       return Other;
     685             :     }
     686             : 
     687             :     friend bool operator==(import_iterator X, import_iterator Y) {
     688             :       return X.Import == Y.Import;
     689             :     }
     690             : 
     691             :     friend bool operator!=(import_iterator X, import_iterator Y) {
     692             :       return X.Import != Y.Import;
     693             :     }
     694             :   };
     695             : 
     696             : public:
     697             :   comments::CommandTraits &getCommentCommandTraits() const {
     698             :     return CommentCommandTraits;
     699             :   }
     700             : 
     701             :   /// \brief Retrieve the attributes for the given declaration.
     702             :   AttrVec& getDeclAttrs(const Decl *D);
     703             : 
     704             :   /// \brief Erase the attributes corresponding to the given declaration.
     705             :   void eraseDeclAttrs(const Decl *D);
     706             : 
     707             :   /// \brief If this variable is an instantiated static data member of a
     708             :   /// class template specialization, returns the templated static data member
     709             :   /// from which it was instantiated.
     710             :   // FIXME: Remove ?
     711             :   MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
     712             :                                                            const VarDecl *Var);
     713             : 
     714             :   TemplateOrSpecializationInfo
     715             :   getTemplateOrSpecializationInfo(const VarDecl *Var);
     716             : 
     717             :   FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD);
     718             : 
     719             :   void setClassScopeSpecializationPattern(FunctionDecl *FD,
     720             :                                           FunctionDecl *Pattern);
     721             : 
     722             :   /// \brief Note that the static data member \p Inst is an instantiation of
     723             :   /// the static data member template \p Tmpl of a class template.
     724             :   void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
     725             :                                            TemplateSpecializationKind TSK,
     726             :                         SourceLocation PointOfInstantiation = SourceLocation());
     727             : 
     728             :   void setTemplateOrSpecializationInfo(VarDecl *Inst,
     729             :                                        TemplateOrSpecializationInfo TSI);
     730             : 
     731             :   /// \brief If the given using decl \p Inst is an instantiation of a
     732             :   /// (possibly unresolved) using decl from a template instantiation,
     733             :   /// return it.
     734             :   NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
     735             : 
     736             :   /// \brief Remember that the using decl \p Inst is an instantiation
     737             :   /// of the using decl \p Pattern of a class template.
     738             :   void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
     739             : 
     740             :   void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
     741             :                                           UsingShadowDecl *Pattern);
     742             :   UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
     743             : 
     744             :   FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
     745             : 
     746             :   void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
     747             :   
     748             :   // Access to the set of methods overridden by the given C++ method.
     749             :   typedef CXXMethodVector::const_iterator overridden_cxx_method_iterator;
     750             :   overridden_cxx_method_iterator
     751             :   overridden_methods_begin(const CXXMethodDecl *Method) const;
     752             : 
     753             :   overridden_cxx_method_iterator
     754             :   overridden_methods_end(const CXXMethodDecl *Method) const;
     755             : 
     756             :   unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
     757             : 
     758             :   /// \brief Note that the given C++ \p Method overrides the given \p
     759             :   /// Overridden method.
     760             :   void addOverriddenMethod(const CXXMethodDecl *Method, 
     761             :                            const CXXMethodDecl *Overridden);
     762             : 
     763             :   /// \brief Return C++ or ObjC overridden methods for the given \p Method.
     764             :   ///
     765             :   /// An ObjC method is considered to override any method in the class's
     766             :   /// base classes, its protocols, or its categories' protocols, that has
     767             :   /// the same selector and is of the same kind (class or instance).
     768             :   /// A method in an implementation is not considered as overriding the same
     769             :   /// method in the interface or its categories.
     770             :   void getOverriddenMethods(
     771             :                         const NamedDecl *Method,
     772             :                         SmallVectorImpl<const NamedDecl *> &Overridden) const;
     773             :   
     774             :   /// \brief Notify the AST context that a new import declaration has been
     775             :   /// parsed or implicitly created within this translation unit.
     776             :   void addedLocalImportDecl(ImportDecl *Import);
     777             : 
     778             :   static ImportDecl *getNextLocalImport(ImportDecl *Import) {
     779             :     return Import->NextLocalImport;
     780             :   }
     781             :   
     782             :   typedef llvm::iterator_range<import_iterator> import_range;
     783             :   import_range local_imports() const {
     784             :     return import_range(import_iterator(FirstLocalImport), import_iterator());
     785             :   }
     786             : 
     787             :   Decl *getPrimaryMergedDecl(Decl *D) {
     788             :     Decl *Result = MergedDecls.lookup(D);
     789             :     return Result ? Result : D;
     790             :   }
     791             :   void setPrimaryMergedDecl(Decl *D, Decl *Primary) {
     792             :     MergedDecls[D] = Primary;
     793             :   }
     794             : 
     795             :   /// \brief Note that the definition \p ND has been merged into module \p M,
     796             :   /// and should be visible whenever \p M is visible.
     797             :   void mergeDefinitionIntoModule(NamedDecl *ND, Module *M,
     798             :                                  bool NotifyListeners = true);
     799             :   /// \brief Clean up the merged definition list. Call this if you might have
     800             :   /// added duplicates into the list.
     801             :   void deduplicateMergedDefinitonsFor(NamedDecl *ND);
     802             : 
     803             :   /// \brief Get the additional modules in which the definition \p Def has
     804             :   /// been merged.
     805             :   ArrayRef<Module*> getModulesWithMergedDefinition(NamedDecl *Def) {
     806             :     auto MergedIt = MergedDefModules.find(Def);
     807             :     if (MergedIt == MergedDefModules.end())
     808             :       return None;
     809             :     return MergedIt->second;
     810             :   }
     811             : 
     812          12 :   TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
     813             : 
     814             :   ExternCContextDecl *getExternCContextDecl() const;
     815             : 
     816             :   // Builtin Types.
     817             :   CanQualType VoidTy;
     818             :   CanQualType BoolTy;
     819             :   CanQualType CharTy;
     820             :   CanQualType WCharTy;  // [C++ 3.9.1p5].
     821             :   CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99.
     822             :   CanQualType WIntTy;   // [C99 7.24.1], integer type unchanged by default promotions.
     823             :   CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
     824             :   CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
     825             :   CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
     826             :   CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
     827             :   CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
     828             :   CanQualType FloatTy, DoubleTy, LongDoubleTy;
     829             :   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
     830             :   CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
     831             :   CanQualType VoidPtrTy, NullPtrTy;
     832             :   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
     833             :   CanQualType BuiltinFnTy;
     834             :   CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
     835             :   CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
     836             :   CanQualType ObjCBuiltinBoolTy;
     837             :   CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy;
     838             :   CanQualType OCLImage2dTy, OCLImage2dArrayTy;
     839             :   CanQualType OCLImage3dTy;
     840             :   CanQualType OCLSamplerTy, OCLEventTy;
     841             : 
     842             :   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
     843             :   mutable QualType AutoDeductTy;     // Deduction against 'auto'.
     844             :   mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
     845             : 
     846             :   // Type used to help define __builtin_va_list for some targets.
     847             :   // The type is built when constructing 'BuiltinVaListDecl'.
     848             :   mutable QualType VaListTagTy;
     849             : 
     850             :   ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents,
     851             :              SelectorTable &sels, Builtin::Context &builtins);
     852             : 
     853             :   ~ASTContext();
     854             : 
     855             :   /// \brief Attach an external AST source to the AST context.
     856             :   ///
     857             :   /// The external AST source provides the ability to load parts of
     858             :   /// the abstract syntax tree as needed from some external storage,
     859             :   /// e.g., a precompiled header.
     860             :   void setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source);
     861             : 
     862             :   /// \brief Retrieve a pointer to the external AST source associated
     863             :   /// with this AST context, if any.
     864             :   ExternalASTSource *getExternalSource() const {
     865           0 :     return ExternalSource.get();
     866             :   }
     867             : 
     868             :   /// \brief Attach an AST mutation listener to the AST context.
     869             :   ///
     870             :   /// The AST mutation listener provides the ability to track modifications to
     871             :   /// the abstract syntax tree entities committed after they were initially
     872             :   /// created.
     873             :   void setASTMutationListener(ASTMutationListener *Listener) {
     874             :     this->Listener = Listener;
     875             :   }
     876             : 
     877             :   /// \brief Retrieve a pointer to the AST mutation listener associated
     878             :   /// with this AST context, if any.
     879             :   ASTMutationListener *getASTMutationListener() const { return Listener; }
     880             : 
     881             :   void PrintStats() const;
     882             :   const SmallVectorImpl<Type *>& getTypes() const { return Types; }
     883             : 
     884             :   /// \brief Create a new implicit TU-level CXXRecordDecl or RecordDecl
     885             :   /// declaration.
     886             :   RecordDecl *buildImplicitRecord(StringRef Name,
     887             :                                   RecordDecl::TagKind TK = TTK_Struct) const;
     888             : 
     889             :   /// \brief Create a new implicit TU-level typedef declaration.
     890             :   TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const;
     891             : 
     892             :   /// \brief Retrieve the declaration for the 128-bit signed integer type.
     893             :   TypedefDecl *getInt128Decl() const;
     894             : 
     895             :   /// \brief Retrieve the declaration for the 128-bit unsigned integer type.
     896             :   TypedefDecl *getUInt128Decl() const;
     897             : 
     898             :   /// \brief Retrieve the declaration for a 128-bit float stub type.
     899             :   TypeDecl *getFloat128StubType() const;
     900             : 
     901             :   //===--------------------------------------------------------------------===//
     902             :   //                           Type Constructors
     903             :   //===--------------------------------------------------------------------===//
     904             : 
     905             : private:
     906             :   /// \brief Return a type with extended qualifiers.
     907             :   QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
     908             : 
     909             :   QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
     910             : 
     911             : public:
     912             :   /// \brief Return the uniqued reference to the type for an address space
     913             :   /// qualified type with the specified type and address space.
     914             :   ///
     915             :   /// The resulting type has a union of the qualifiers from T and the address
     916             :   /// space. If T already has an address space specifier, it is silently
     917             :   /// replaced.
     918             :   QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
     919             : 
     920             :   /// \brief Return the uniqued reference to the type for an Objective-C
     921             :   /// gc-qualified type.
     922             :   ///
     923             :   /// The retulting type has a union of the qualifiers from T and the gc
     924             :   /// attribute.
     925             :   QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
     926             : 
     927             :   /// \brief Return the uniqued reference to the type for a \c restrict
     928             :   /// qualified type.
     929             :   ///
     930             :   /// The resulting type has a union of the qualifiers from \p T and
     931             :   /// \c restrict.
     932             :   QualType getRestrictType(QualType T) const {
     933             :     return T.withFastQualifiers(Qualifiers::Restrict);
     934             :   }
     935             : 
     936             :   /// \brief Return the uniqued reference to the type for a \c volatile
     937             :   /// qualified type.
     938             :   ///
     939             :   /// The resulting type has a union of the qualifiers from \p T and
     940             :   /// \c volatile.
     941             :   QualType getVolatileType(QualType T) const {
     942             :     return T.withFastQualifiers(Qualifiers::Volatile);
     943             :   }
     944             : 
     945             :   /// \brief Return the uniqued reference to the type for a \c const
     946             :   /// qualified type.
     947             :   ///
     948             :   /// The resulting type has a union of the qualifiers from \p T and \c const.
     949             :   ///
     950             :   /// It can be reasonably expected that this will always be equivalent to
     951             :   /// calling T.withConst().
     952             :   QualType getConstType(QualType T) const { return T.withConst(); }
     953             : 
     954             :   /// \brief Change the ExtInfo on a function type.
     955             :   const FunctionType *adjustFunctionType(const FunctionType *Fn,
     956             :                                          FunctionType::ExtInfo EInfo);
     957             : 
     958             :   /// \brief Change the result type of a function type once it is deduced.
     959             :   void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
     960             : 
     961             :   /// \brief Change the exception specification on a function once it is
     962             :   /// delay-parsed, instantiated, or computed.
     963             :   void adjustExceptionSpec(FunctionDecl *FD,
     964             :                            const FunctionProtoType::ExceptionSpecInfo &ESI,
     965             :                            bool AsWritten = false);
     966             : 
     967             :   /// \brief Return the uniqued reference to the type for a complex
     968             :   /// number with the specified element type.
     969             :   QualType getComplexType(QualType T) const;
     970             :   CanQualType getComplexType(CanQualType T) const {
     971             :     return CanQualType::CreateUnsafe(getComplexType((QualType) T));
     972             :   }
     973             : 
     974             :   /// \brief Return the uniqued reference to the type for a pointer to
     975             :   /// the specified type.
     976             :   QualType getPointerType(QualType T) const;
     977             :   CanQualType getPointerType(CanQualType T) const {
     978             :     return CanQualType::CreateUnsafe(getPointerType((QualType) T));
     979             :   }
     980             : 
     981             :   /// \brief Return the uniqued reference to a type adjusted from the original
     982             :   /// type to a new type.
     983             :   QualType getAdjustedType(QualType Orig, QualType New) const;
     984             :   CanQualType getAdjustedType(CanQualType Orig, CanQualType New) const {
     985             :     return CanQualType::CreateUnsafe(
     986             :         getAdjustedType((QualType)Orig, (QualType)New));
     987             :   }
     988             : 
     989             :   /// \brief Return the uniqued reference to the decayed version of the given
     990             :   /// type.  Can only be called on array and function types which decay to
     991             :   /// pointer types.
     992             :   QualType getDecayedType(QualType T) const;
     993             :   CanQualType getDecayedType(CanQualType T) const {
     994             :     return CanQualType::CreateUnsafe(getDecayedType((QualType) T));
     995             :   }
     996             : 
     997             :   /// \brief Return the uniqued reference to the atomic type for the specified
     998             :   /// type.
     999             :   QualType getAtomicType(QualType T) const;
    1000             : 
    1001             :   /// \brief Return the uniqued reference to the type for a block of the
    1002             :   /// specified type.
    1003             :   QualType getBlockPointerType(QualType T) const;
    1004             : 
    1005             :   /// Gets the struct used to keep track of the descriptor for pointer to
    1006             :   /// blocks.
    1007             :   QualType getBlockDescriptorType() const;
    1008             : 
    1009             :   /// Gets the struct used to keep track of the extended descriptor for
    1010             :   /// pointer to blocks.
    1011             :   QualType getBlockDescriptorExtendedType() const;
    1012             : 
    1013             :   void setcudaConfigureCallDecl(FunctionDecl *FD) {
    1014             :     cudaConfigureCallDecl = FD;
    1015             :   }
    1016             :   FunctionDecl *getcudaConfigureCallDecl() {
    1017             :     return cudaConfigureCallDecl;
    1018             :   }
    1019             : 
    1020             :   /// Returns true iff we need copy/dispose helpers for the given type.
    1021             :   bool BlockRequiresCopying(QualType Ty, const VarDecl *D);
    1022             :   
    1023             :   
    1024             :   /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout is set
    1025             :   /// to false in this case. If HasByrefExtendedLayout returns true, byref variable
    1026             :   /// has extended lifetime. 
    1027             :   bool getByrefLifetime(QualType Ty,
    1028             :                         Qualifiers::ObjCLifetime &Lifetime,
    1029             :                         bool &HasByrefExtendedLayout) const;
    1030             :   
    1031             :   /// \brief Return the uniqued reference to the type for an lvalue reference
    1032             :   /// to the specified type.
    1033             :   QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
    1034             :     const;
    1035             : 
    1036             :   /// \brief Return the uniqued reference to the type for an rvalue reference
    1037             :   /// to the specified type.
    1038             :   QualType getRValueReferenceType(QualType T) const;
    1039             : 
    1040             :   /// \brief Return the uniqued reference to the type for a member pointer to
    1041             :   /// the specified type in the specified class.
    1042             :   ///
    1043             :   /// The class \p Cls is a \c Type because it could be a dependent name.
    1044             :   QualType getMemberPointerType(QualType T, const Type *Cls) const;
    1045             : 
    1046             :   /// \brief Return a non-unique reference to the type for a variable array of
    1047             :   /// the specified element type.
    1048             :   QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
    1049             :                                 ArrayType::ArraySizeModifier ASM,
    1050             :                                 unsigned IndexTypeQuals,
    1051             :                                 SourceRange Brackets) const;
    1052             : 
    1053             :   /// \brief Return a non-unique reference to the type for a dependently-sized
    1054             :   /// array of the specified element type.
    1055             :   ///
    1056             :   /// FIXME: We will need these to be uniqued, or at least comparable, at some
    1057             :   /// point.
    1058             :   QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
    1059             :                                       ArrayType::ArraySizeModifier ASM,
    1060             :                                       unsigned IndexTypeQuals,
    1061             :                                       SourceRange Brackets) const;
    1062             : 
    1063             :   /// \brief Return a unique reference to the type for an incomplete array of
    1064             :   /// the specified element type.
    1065             :   QualType getIncompleteArrayType(QualType EltTy,
    1066             :                                   ArrayType::ArraySizeModifier ASM,
    1067             :                                   unsigned IndexTypeQuals) const;
    1068             : 
    1069             :   /// \brief Return the unique reference to the type for a constant array of
    1070             :   /// the specified element type.
    1071             :   QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
    1072             :                                 ArrayType::ArraySizeModifier ASM,
    1073             :                                 unsigned IndexTypeQuals) const;
    1074             :   
    1075             :   /// \brief Returns a vla type where known sizes are replaced with [*].
    1076             :   QualType getVariableArrayDecayedType(QualType Ty) const;
    1077             : 
    1078             :   /// \brief Return the unique reference to a vector type of the specified
    1079             :   /// element type and size.
    1080             :   ///
    1081             :   /// \pre \p VectorType must be a built-in type.
    1082             :   QualType getVectorType(QualType VectorType, unsigned NumElts,
    1083             :                          VectorType::VectorKind VecKind) const;
    1084             : 
    1085             :   /// \brief Return the unique reference to an extended vector type
    1086             :   /// of the specified element type and size.
    1087             :   ///
    1088             :   /// \pre \p VectorType must be a built-in type.
    1089             :   QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
    1090             : 
    1091             :   /// \pre Return a non-unique reference to the type for a dependently-sized
    1092             :   /// vector of the specified element type.
    1093             :   ///
    1094             :   /// FIXME: We will need these to be uniqued, or at least comparable, at some
    1095             :   /// point.
    1096             :   QualType getDependentSizedExtVectorType(QualType VectorType,
    1097             :                                           Expr *SizeExpr,
    1098             :                                           SourceLocation AttrLoc) const;
    1099             : 
    1100             :   /// \brief Return a K&R style C function type like 'int()'.
    1101             :   QualType getFunctionNoProtoType(QualType ResultTy,
    1102             :                                   const FunctionType::ExtInfo &Info) const;
    1103             : 
    1104             :   QualType getFunctionNoProtoType(QualType ResultTy) const {
    1105             :     return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
    1106             :   }
    1107             : 
    1108             :   /// \brief Return a normal function type with a typed argument list.
    1109             :   QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args,
    1110             :                            const FunctionProtoType::ExtProtoInfo &EPI) const;
    1111             : 
    1112             :   /// \brief Return the unique reference to the type for the specified type
    1113             :   /// declaration.
    1114             :   QualType getTypeDeclType(const TypeDecl *Decl,
    1115             :                            const TypeDecl *PrevDecl = nullptr) const {
    1116             :     assert(Decl && "Passed null for Decl param");
    1117             :     if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
    1118             : 
    1119             :     if (PrevDecl) {
    1120             :       assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
    1121             :       Decl->TypeForDecl = PrevDecl->TypeForDecl;
    1122             :       return QualType(PrevDecl->TypeForDecl, 0);
    1123             :     }
    1124             : 
    1125             :     return getTypeDeclTypeSlow(Decl);
    1126             :   }
    1127             : 
    1128             :   /// \brief Return the unique reference to the type for the specified
    1129             :   /// typedef-name decl.
    1130             :   QualType getTypedefType(const TypedefNameDecl *Decl,
    1131             :                           QualType Canon = QualType()) const;
    1132             : 
    1133             :   QualType getRecordType(const RecordDecl *Decl) const;
    1134             : 
    1135             :   QualType getEnumType(const EnumDecl *Decl) const;
    1136             : 
    1137             :   QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
    1138             : 
    1139             :   QualType getAttributedType(AttributedType::Kind attrKind,
    1140             :                              QualType modifiedType,
    1141             :                              QualType equivalentType);
    1142             : 
    1143             :   QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
    1144             :                                         QualType Replacement) const;
    1145             :   QualType getSubstTemplateTypeParmPackType(
    1146             :                                           const TemplateTypeParmType *Replaced,
    1147             :                                             const TemplateArgument &ArgPack);
    1148             : 
    1149             :   QualType
    1150             :   getTemplateTypeParmType(unsigned Depth, unsigned Index,
    1151             :                           bool ParameterPack,
    1152             :                           TemplateTypeParmDecl *ParmDecl = nullptr) const;
    1153             : 
    1154             :   QualType getTemplateSpecializationType(TemplateName T,
    1155             :                                          const TemplateArgument *Args,
    1156             :                                          unsigned NumArgs,
    1157             :                                          QualType Canon = QualType()) const;
    1158             : 
    1159             :   QualType getCanonicalTemplateSpecializationType(TemplateName T,
    1160             :                                                   const TemplateArgument *Args,
    1161             :                                                   unsigned NumArgs) const;
    1162             : 
    1163             :   QualType getTemplateSpecializationType(TemplateName T,
    1164             :                                          const TemplateArgumentListInfo &Args,
    1165             :                                          QualType Canon = QualType()) const;
    1166             : 
    1167             :   TypeSourceInfo *
    1168             :   getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
    1169             :                                     const TemplateArgumentListInfo &Args,
    1170             :                                     QualType Canon = QualType()) const;
    1171             : 
    1172             :   QualType getParenType(QualType NamedType) const;
    1173             : 
    1174             :   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
    1175             :                              NestedNameSpecifier *NNS,
    1176             :                              QualType NamedType) const;
    1177             :   QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
    1178             :                                 NestedNameSpecifier *NNS,
    1179             :                                 const IdentifierInfo *Name,
    1180             :                                 QualType Canon = QualType()) const;
    1181             : 
    1182             :   QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
    1183             :                                                   NestedNameSpecifier *NNS,
    1184             :                                                   const IdentifierInfo *Name,
    1185             :                                     const TemplateArgumentListInfo &Args) const;
    1186             :   QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
    1187             :                                                   NestedNameSpecifier *NNS,
    1188             :                                                   const IdentifierInfo *Name,
    1189             :                                                   unsigned NumArgs,
    1190             :                                             const TemplateArgument *Args) const;
    1191             : 
    1192             :   QualType getPackExpansionType(QualType Pattern,
    1193             :                                 Optional<unsigned> NumExpansions);
    1194             : 
    1195             :   QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
    1196             :                                 ObjCInterfaceDecl *PrevDecl = nullptr) const;
    1197             : 
    1198             :   /// Legacy interface: cannot provide type arguments or __kindof.
    1199             :   QualType getObjCObjectType(QualType Base,
    1200             :                              ObjCProtocolDecl * const *Protocols,
    1201             :                              unsigned NumProtocols) const;
    1202             : 
    1203             :   QualType getObjCObjectType(QualType Base,
    1204             :                              ArrayRef<QualType> typeArgs,
    1205             :                              ArrayRef<ObjCProtocolDecl *> protocols,
    1206             :                              bool isKindOf) const;
    1207             :   
    1208             :   bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
    1209             :   /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in
    1210             :   /// QT's qualified-id protocol list adopt all protocols in IDecl's list
    1211             :   /// of protocols.
    1212             :   bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT,
    1213             :                                             ObjCInterfaceDecl *IDecl);
    1214             : 
    1215             :   /// \brief Return a ObjCObjectPointerType type for the given ObjCObjectType.
    1216             :   QualType getObjCObjectPointerType(QualType OIT) const;
    1217             : 
    1218             :   /// \brief GCC extension.
    1219             :   QualType getTypeOfExprType(Expr *e) const;
    1220             :   QualType getTypeOfType(QualType t) const;
    1221             : 
    1222             :   /// \brief C++11 decltype.
    1223             :   QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
    1224             : 
    1225             :   /// \brief Unary type transforms
    1226             :   QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
    1227             :                                  UnaryTransformType::UTTKind UKind) const;
    1228             : 
    1229             :   /// \brief C++11 deduced auto type.
    1230             :   QualType getAutoType(QualType DeducedType, bool IsDecltypeAuto,
    1231             :                        bool IsDependent) const;
    1232             : 
    1233             :   /// \brief C++11 deduction pattern for 'auto' type.
    1234             :   QualType getAutoDeductType() const;
    1235             : 
    1236             :   /// \brief C++11 deduction pattern for 'auto &&' type.
    1237             :   QualType getAutoRRefDeductType() const;
    1238             : 
    1239             :   /// \brief Return the unique reference to the type for the specified TagDecl
    1240             :   /// (struct/union/class/enum) decl.
    1241             :   QualType getTagDeclType(const TagDecl *Decl) const;
    1242             : 
    1243             :   /// \brief Return the unique type for "size_t" (C99 7.17), defined in
    1244             :   /// <stddef.h>.
    1245             :   ///
    1246             :   /// The sizeof operator requires this (C99 6.5.3.4p4).
    1247             :   CanQualType getSizeType() const;
    1248             : 
    1249             :   /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
    1250             :   /// <stdint.h>.
    1251             :   CanQualType getIntMaxType() const;
    1252             : 
    1253             :   /// \brief Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in
    1254             :   /// <stdint.h>.
    1255             :   CanQualType getUIntMaxType() const;
    1256             : 
    1257             :   /// \brief Return the unique wchar_t type available in C++ (and available as
    1258             :   /// __wchar_t as a Microsoft extension).
    1259             :   QualType getWCharType() const { return WCharTy; }
    1260             : 
    1261             :   /// \brief Return the type of wide characters. In C++, this returns the
    1262             :   /// unique wchar_t type. In C99, this returns a type compatible with the type
    1263             :   /// defined in <stddef.h> as defined by the target.
    1264             :   QualType getWideCharType() const { return WideCharTy; }
    1265             : 
    1266             :   /// \brief Return the type of "signed wchar_t".
    1267             :   ///
    1268             :   /// Used when in C++, as a GCC extension.
    1269             :   QualType getSignedWCharType() const;
    1270             : 
    1271             :   /// \brief Return the type of "unsigned wchar_t".
    1272             :   ///
    1273             :   /// Used when in C++, as a GCC extension.
    1274             :   QualType getUnsignedWCharType() const;
    1275             : 
    1276             :   /// \brief In C99, this returns a type compatible with the type
    1277             :   /// defined in <stddef.h> as defined by the target.
    1278             :   QualType getWIntType() const { return WIntTy; }
    1279             : 
    1280             :   /// \brief Return a type compatible with "intptr_t" (C99 7.18.1.4),
    1281             :   /// as defined by the target.
    1282             :   QualType getIntPtrType() const;
    1283             : 
    1284             :   /// \brief Return a type compatible with "uintptr_t" (C99 7.18.1.4),
    1285             :   /// as defined by the target.
    1286             :   QualType getUIntPtrType() const;
    1287             : 
    1288             :   /// \brief Return the unique type for "ptrdiff_t" (C99 7.17) defined in
    1289             :   /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
    1290             :   QualType getPointerDiffType() const;
    1291             : 
    1292             :   /// \brief Return the unique type for "pid_t" defined in
    1293             :   /// <sys/types.h>. We need this to compute the correct type for vfork().
    1294             :   QualType getProcessIDType() const;
    1295             : 
    1296             :   /// \brief Return the C structure type used to represent constant CFStrings.
    1297             :   QualType getCFConstantStringType() const;
    1298             :   
    1299             :   /// \brief Returns the C struct type for objc_super
    1300             :   QualType getObjCSuperType() const;
    1301             :   void setObjCSuperType(QualType ST) { ObjCSuperType = ST; }
    1302             :   
    1303             :   /// Get the structure type used to representation CFStrings, or NULL
    1304             :   /// if it hasn't yet been built.
    1305             :   QualType getRawCFConstantStringType() const {
    1306             :     if (CFConstantStringTypeDecl)
    1307             :       return getTagDeclType(CFConstantStringTypeDecl);
    1308             :     return QualType();
    1309             :   }
    1310             :   void setCFConstantStringType(QualType T);
    1311             : 
    1312             :   // This setter/getter represents the ObjC type for an NSConstantString.
    1313             :   void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
    1314             :   QualType getObjCConstantStringInterface() const {
    1315             :     return ObjCConstantStringType;
    1316             :   }
    1317             : 
    1318             :   QualType getObjCNSStringType() const {
    1319             :     return ObjCNSStringType;
    1320             :   }
    1321             :   
    1322             :   void setObjCNSStringType(QualType T) {
    1323             :     ObjCNSStringType = T;
    1324             :   }
    1325             :   
    1326             :   /// \brief Retrieve the type that \c id has been defined to, which may be
    1327             :   /// different from the built-in \c id if \c id has been typedef'd.
    1328             :   QualType getObjCIdRedefinitionType() const {
    1329             :     if (ObjCIdRedefinitionType.isNull())
    1330             :       return getObjCIdType();
    1331             :     return ObjCIdRedefinitionType;
    1332             :   }
    1333             :   
    1334             :   /// \brief Set the user-written type that redefines \c id.
    1335             :   void setObjCIdRedefinitionType(QualType RedefType) {
    1336             :     ObjCIdRedefinitionType = RedefType;
    1337             :   }
    1338             : 
    1339             :   /// \brief Retrieve the type that \c Class has been defined to, which may be
    1340             :   /// different from the built-in \c Class if \c Class has been typedef'd.
    1341             :   QualType getObjCClassRedefinitionType() const {
    1342             :     if (ObjCClassRedefinitionType.isNull())
    1343             :       return getObjCClassType();
    1344             :     return ObjCClassRedefinitionType;
    1345             :   }
    1346             :   
    1347             :   /// \brief Set the user-written type that redefines 'SEL'.
    1348             :   void setObjCClassRedefinitionType(QualType RedefType) {
    1349             :     ObjCClassRedefinitionType = RedefType;
    1350             :   }
    1351             : 
    1352             :   /// \brief Retrieve the type that 'SEL' has been defined to, which may be
    1353             :   /// different from the built-in 'SEL' if 'SEL' has been typedef'd.
    1354             :   QualType getObjCSelRedefinitionType() const {
    1355             :     if (ObjCSelRedefinitionType.isNull())
    1356             :       return getObjCSelType();
    1357             :     return ObjCSelRedefinitionType;
    1358             :   }
    1359             : 
    1360             :   
    1361             :   /// \brief Set the user-written type that redefines 'SEL'.
    1362             :   void setObjCSelRedefinitionType(QualType RedefType) {
    1363             :     ObjCSelRedefinitionType = RedefType;
    1364             :   }
    1365             : 
    1366             :   /// Retrieve the identifier 'NSObject'.
    1367             :   IdentifierInfo *getNSObjectName() {
    1368             :     if (!NSObjectName) {
    1369             :       NSObjectName = &Idents.get("NSObject");
    1370             :     }
    1371             : 
    1372             :     return NSObjectName;
    1373             :   }
    1374             : 
    1375             :   /// Retrieve the identifier 'NSCopying'.
    1376             :   IdentifierInfo *getNSCopyingName() {
    1377             :     if (!NSCopyingName) {
    1378             :       NSCopyingName = &Idents.get("NSCopying");
    1379             :     }
    1380             : 
    1381             :     return NSCopyingName;
    1382             :   }
    1383             : 
    1384             :   /// \brief Retrieve the Objective-C "instancetype" type, if already known;
    1385             :   /// otherwise, returns a NULL type;
    1386             :   QualType getObjCInstanceType() {
    1387             :     return getTypeDeclType(getObjCInstanceTypeDecl());
    1388             :   }
    1389             : 
    1390             :   /// \brief Retrieve the typedef declaration corresponding to the Objective-C
    1391             :   /// "instancetype" type.
    1392             :   TypedefDecl *getObjCInstanceTypeDecl();
    1393             :   
    1394             :   /// \brief Set the type for the C FILE type.
    1395             :   void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
    1396             : 
    1397             :   /// \brief Retrieve the C FILE type.
    1398             :   QualType getFILEType() const {
    1399             :     if (FILEDecl)
    1400             :       return getTypeDeclType(FILEDecl);
    1401             :     return QualType();
    1402             :   }
    1403             : 
    1404             :   /// \brief Set the type for the C jmp_buf type.
    1405             :   void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
    1406             :     this->jmp_bufDecl = jmp_bufDecl;
    1407             :   }
    1408             : 
    1409             :   /// \brief Retrieve the C jmp_buf type.
    1410             :   QualType getjmp_bufType() const {
    1411             :     if (jmp_bufDecl)
    1412             :       return getTypeDeclType(jmp_bufDecl);
    1413             :     return QualType();
    1414             :   }
    1415             : 
    1416             :   /// \brief Set the type for the C sigjmp_buf type.
    1417             :   void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
    1418             :     this->sigjmp_bufDecl = sigjmp_bufDecl;
    1419             :   }
    1420             : 
    1421             :   /// \brief Retrieve the C sigjmp_buf type.
    1422             :   QualType getsigjmp_bufType() const {
    1423             :     if (sigjmp_bufDecl)
    1424             :       return getTypeDeclType(sigjmp_bufDecl);
    1425             :     return QualType();
    1426             :   }
    1427             : 
    1428             :   /// \brief Set the type for the C ucontext_t type.
    1429             :   void setucontext_tDecl(TypeDecl *ucontext_tDecl) {
    1430             :     this->ucontext_tDecl = ucontext_tDecl;
    1431             :   }
    1432             : 
    1433             :   /// \brief Retrieve the C ucontext_t type.
    1434             :   QualType getucontext_tType() const {
    1435             :     if (ucontext_tDecl)
    1436             :       return getTypeDeclType(ucontext_tDecl);
    1437             :     return QualType();
    1438             :   }
    1439             : 
    1440             :   /// \brief The result type of logical operations, '<', '>', '!=', etc.
    1441             :   QualType getLogicalOperationType() const {
    1442             :     return getLangOpts().CPlusPlus ? BoolTy : IntTy;
    1443             :   }
    1444             : 
    1445             :   /// \brief Emit the Objective-CC type encoding for the given type \p T into
    1446             :   /// \p S.
    1447             :   ///
    1448             :   /// If \p Field is specified then record field names are also encoded.
    1449             :   void getObjCEncodingForType(QualType T, std::string &S,
    1450             :                               const FieldDecl *Field=nullptr,
    1451             :                               QualType *NotEncodedT=nullptr) const;
    1452             : 
    1453             :   /// \brief Emit the Objective-C property type encoding for the given
    1454             :   /// type \p T into \p S.
    1455             :   void getObjCEncodingForPropertyType(QualType T, std::string &S) const;
    1456             : 
    1457             :   void getLegacyIntegralTypeEncoding(QualType &t) const;
    1458             : 
    1459             :   /// \brief Put the string version of the type qualifiers \p QT into \p S.
    1460             :   void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
    1461             :                                        std::string &S) const;
    1462             : 
    1463             :   /// \brief Emit the encoded type for the function \p Decl into \p S.
    1464             :   ///
    1465             :   /// This is in the same format as Objective-C method encodings.
    1466             :   ///
    1467             :   /// \returns true if an error occurred (e.g., because one of the parameter
    1468             :   /// types is incomplete), false otherwise.
    1469             :   bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
    1470             : 
    1471             :   /// \brief Emit the encoded type for the method declaration \p Decl into
    1472             :   /// \p S.
    1473             :   ///
    1474             :   /// \returns true if an error occurred (e.g., because one of the parameter
    1475             :   /// types is incomplete), false otherwise.
    1476             :   bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S,
    1477             :                                     bool Extended = false)
    1478             :     const;
    1479             : 
    1480             :   /// \brief Return the encoded type for this block declaration.
    1481             :   std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
    1482             :   
    1483             :   /// getObjCEncodingForPropertyDecl - Return the encoded type for
    1484             :   /// this method declaration. If non-NULL, Container must be either
    1485             :   /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
    1486             :   /// only be NULL when getting encodings for protocol properties.
    1487             :   void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
    1488             :                                       const Decl *Container,
    1489             :                                       std::string &S) const;
    1490             : 
    1491             :   bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
    1492             :                                       ObjCProtocolDecl *rProto) const;
    1493             :   
    1494             :   ObjCPropertyImplDecl *getObjCPropertyImplDeclForPropertyDecl(
    1495             :                                                   const ObjCPropertyDecl *PD,
    1496             :                                                   const Decl *Container) const;
    1497             : 
    1498             :   /// \brief Return the size of type \p T for Objective-C encoding purpose,
    1499             :   /// in characters.
    1500             :   CharUnits getObjCEncodingTypeSize(QualType T) const;
    1501             : 
    1502             :   /// \brief Retrieve the typedef corresponding to the predefined \c id type
    1503             :   /// in Objective-C.
    1504             :   TypedefDecl *getObjCIdDecl() const;
    1505             :   
    1506             :   /// \brief Represents the Objective-CC \c id type.
    1507             :   ///
    1508             :   /// This is set up lazily, by Sema.  \c id is always a (typedef for a)
    1509             :   /// pointer type, a pointer to a struct.
    1510             :   QualType getObjCIdType() const {
    1511             :     return getTypeDeclType(getObjCIdDecl());
    1512             :   }
    1513             : 
    1514             :   /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type
    1515             :   /// in Objective-C.
    1516             :   TypedefDecl *getObjCSelDecl() const;
    1517             :   
    1518             :   /// \brief Retrieve the type that corresponds to the predefined Objective-C
    1519             :   /// 'SEL' type.
    1520             :   QualType getObjCSelType() const { 
    1521             :     return getTypeDeclType(getObjCSelDecl());
    1522             :   }
    1523             : 
    1524             :   /// \brief Retrieve the typedef declaration corresponding to the predefined
    1525             :   /// Objective-C 'Class' type.
    1526             :   TypedefDecl *getObjCClassDecl() const;
    1527             :   
    1528             :   /// \brief Represents the Objective-C \c Class type.
    1529             :   ///
    1530             :   /// This is set up lazily, by Sema.  \c Class is always a (typedef for a)
    1531             :   /// pointer type, a pointer to a struct.
    1532             :   QualType getObjCClassType() const { 
    1533             :     return getTypeDeclType(getObjCClassDecl());
    1534             :   }
    1535             : 
    1536             :   /// \brief Retrieve the Objective-C class declaration corresponding to 
    1537             :   /// the predefined \c Protocol class.
    1538             :   ObjCInterfaceDecl *getObjCProtocolDecl() const;
    1539             : 
    1540             :   /// \brief Retrieve declaration of 'BOOL' typedef
    1541             :   TypedefDecl *getBOOLDecl() const {
    1542             :     return BOOLDecl;
    1543             :   }
    1544             : 
    1545             :   /// \brief Save declaration of 'BOOL' typedef
    1546             :   void setBOOLDecl(TypedefDecl *TD) {
    1547             :     BOOLDecl = TD;
    1548             :   }
    1549             : 
    1550             :   /// \brief type of 'BOOL' type.
    1551             :   QualType getBOOLType() const {
    1552             :     return getTypeDeclType(getBOOLDecl());
    1553             :   }
    1554             :   
    1555             :   /// \brief Retrieve the type of the Objective-C \c Protocol class.
    1556             :   QualType getObjCProtoType() const {
    1557             :     return getObjCInterfaceType(getObjCProtocolDecl());
    1558             :   }
    1559             :   
    1560             :   /// \brief Retrieve the C type declaration corresponding to the predefined
    1561             :   /// \c __builtin_va_list type.
    1562             :   TypedefDecl *getBuiltinVaListDecl() const;
    1563             : 
    1564             :   /// \brief Retrieve the type of the \c __builtin_va_list type.
    1565             :   QualType getBuiltinVaListType() const {
    1566             :     return getTypeDeclType(getBuiltinVaListDecl());
    1567             :   }
    1568             : 
    1569             :   /// \brief Retrieve the C type declaration corresponding to the predefined
    1570             :   /// \c __va_list_tag type used to help define the \c __builtin_va_list type
    1571             :   /// for some targets.
    1572             :   QualType getVaListTagType() const;
    1573             : 
    1574             :   /// \brief Return a type with additional \c const, \c volatile, or
    1575             :   /// \c restrict qualifiers.
    1576             :   QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
    1577             :     return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
    1578             :   }
    1579             : 
    1580             :   /// \brief Un-split a SplitQualType.
    1581             :   QualType getQualifiedType(SplitQualType split) const {
    1582             :     return getQualifiedType(split.Ty, split.Quals);
    1583             :   }
    1584             : 
    1585             :   /// \brief Return a type with additional qualifiers.
    1586             :   QualType getQualifiedType(QualType T, Qualifiers Qs) const {
    1587             :     if (!Qs.hasNonFastQualifiers())
    1588             :       return T.withFastQualifiers(Qs.getFastQualifiers());
    1589             :     QualifierCollector Qc(Qs);
    1590             :     const Type *Ptr = Qc.strip(T);
    1591             :     return getExtQualType(Ptr, Qc);
    1592             :   }
    1593             : 
    1594             :   /// \brief Return a type with additional qualifiers.
    1595             :   QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
    1596             :     if (!Qs.hasNonFastQualifiers())
    1597             :       return QualType(T, Qs.getFastQualifiers());
    1598             :     return getExtQualType(T, Qs);
    1599             :   }
    1600             : 
    1601             :   /// \brief Return a type with the given lifetime qualifier.
    1602             :   ///
    1603             :   /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None.
    1604             :   QualType getLifetimeQualifiedType(QualType type,
    1605             :                                     Qualifiers::ObjCLifetime lifetime) {
    1606             :     assert(type.getObjCLifetime() == Qualifiers::OCL_None);
    1607             :     assert(lifetime != Qualifiers::OCL_None);
    1608             : 
    1609             :     Qualifiers qs;
    1610             :     qs.addObjCLifetime(lifetime);
    1611             :     return getQualifiedType(type, qs);
    1612             :   }
    1613             :   
    1614             :   /// getUnqualifiedObjCPointerType - Returns version of
    1615             :   /// Objective-C pointer type with lifetime qualifier removed.
    1616             :   QualType getUnqualifiedObjCPointerType(QualType type) const {
    1617             :     if (!type.getTypePtr()->isObjCObjectPointerType() ||
    1618             :         !type.getQualifiers().hasObjCLifetime())
    1619             :       return type;
    1620             :     Qualifiers Qs = type.getQualifiers();
    1621             :     Qs.removeObjCLifetime();
    1622             :     return getQualifiedType(type.getUnqualifiedType(), Qs);
    1623             :   }
    1624             :   
    1625             :   DeclarationNameInfo getNameForTemplate(TemplateName Name,
    1626             :                                          SourceLocation NameLoc) const;
    1627             : 
    1628             :   TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
    1629             :                                          UnresolvedSetIterator End) const;
    1630             : 
    1631             :   TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
    1632             :                                         bool TemplateKeyword,
    1633             :                                         TemplateDecl *Template) const;
    1634             : 
    1635             :   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
    1636             :                                         const IdentifierInfo *Name) const;
    1637             :   TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
    1638             :                                         OverloadedOperatorKind Operator) const;
    1639             :   TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param,
    1640             :                                             TemplateName replacement) const;
    1641             :   TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
    1642             :                                         const TemplateArgument &ArgPack) const;
    1643             :   
    1644             :   enum GetBuiltinTypeError {
    1645             :     GE_None,              ///< No error
    1646             :     GE_Missing_stdio,     ///< Missing a type from <stdio.h>
    1647             :     GE_Missing_setjmp,    ///< Missing a type from <setjmp.h>
    1648             :     GE_Missing_ucontext   ///< Missing a type from <ucontext.h>
    1649             :   };
    1650             : 
    1651             :   /// \brief Return the type for the specified builtin.
    1652             :   ///
    1653             :   /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of
    1654             :   /// arguments to the builtin that are required to be integer constant
    1655             :   /// expressions.
    1656             :   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
    1657             :                           unsigned *IntegerConstantArgs = nullptr) const;
    1658             : 
    1659             : private:
    1660             :   CanQualType getFromTargetType(unsigned Type) const;
    1661             :   TypeInfo getTypeInfoImpl(const Type *T) const;
    1662             : 
    1663             :   //===--------------------------------------------------------------------===//
    1664             :   //                         Type Predicates.
    1665             :   //===--------------------------------------------------------------------===//
    1666             : 
    1667             : public:
    1668             :   /// \brief Return one of the GCNone, Weak or Strong Objective-C garbage
    1669             :   /// collection attributes.
    1670             :   Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
    1671             : 
    1672             :   /// \brief Return true if the given vector types are of the same unqualified
    1673             :   /// type or if they are equivalent to the same GCC vector type.
    1674             :   ///
    1675             :   /// \note This ignores whether they are target-specific (AltiVec or Neon)
    1676             :   /// types.
    1677             :   bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
    1678             : 
    1679             :   /// \brief Return true if this is an \c NSObject object with its \c NSObject
    1680             :   /// attribute set.
    1681             :   static bool isObjCNSObjectType(QualType Ty) {
    1682             :     return Ty->isObjCNSObjectType();
    1683             :   }
    1684             : 
    1685             :   //===--------------------------------------------------------------------===//
    1686             :   //                         Type Sizing and Analysis
    1687             :   //===--------------------------------------------------------------------===//
    1688             : 
    1689             :   /// \brief Return the APFloat 'semantics' for the specified scalar floating
    1690             :   /// point type.
    1691             :   const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
    1692             : 
    1693             :   /// \brief Get the size and alignment of the specified complete type in bits.
    1694             :   TypeInfo getTypeInfo(const Type *T) const;
    1695             :   TypeInfo getTypeInfo(QualType T) const { return getTypeInfo(T.getTypePtr()); }
    1696             : 
    1697             :   /// \brief Get default simd alignment of the specified complete type in bits.
    1698             :   unsigned getOpenMPDefaultSimdAlign(QualType T) const;
    1699             : 
    1700             :   /// \brief Return the size of the specified (complete) type \p T, in bits.
    1701             :   uint64_t getTypeSize(QualType T) const { return getTypeInfo(T).Width; }
    1702             :   uint64_t getTypeSize(const Type *T) const { return getTypeInfo(T).Width; }
    1703             : 
    1704             :   /// \brief Return the size of the character type, in bits.
    1705             :   uint64_t getCharWidth() const {
    1706             :     return getTypeSize(CharTy);
    1707             :   }
    1708             :   
    1709             :   /// \brief Convert a size in bits to a size in characters.
    1710             :   CharUnits toCharUnitsFromBits(int64_t BitSize) const;
    1711             : 
    1712             :   /// \brief Convert a size in characters to a size in bits.
    1713             :   int64_t toBits(CharUnits CharSize) const;
    1714             : 
    1715             :   /// \brief Return the size of the specified (complete) type \p T, in
    1716             :   /// characters.
    1717             :   CharUnits getTypeSizeInChars(QualType T) const;
    1718             :   CharUnits getTypeSizeInChars(const Type *T) const;
    1719             : 
    1720             :   /// \brief Return the ABI-specified alignment of a (complete) type \p T, in
    1721             :   /// bits.
    1722             :   unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
    1723             :   unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; }
    1724             : 
    1725             :   /// \brief Return the ABI-specified alignment of a (complete) type \p T, in 
    1726             :   /// characters.
    1727             :   CharUnits getTypeAlignInChars(QualType T) const;
    1728             :   CharUnits getTypeAlignInChars(const Type *T) const;
    1729             :   
    1730             :   // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the
    1731             :   // type is a record, its data size is returned.
    1732             :   std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const;
    1733             : 
    1734             :   std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
    1735             :   std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
    1736             : 
    1737             :   /// \brief Determine if the alignment the type has was required using an
    1738             :   /// alignment attribute.
    1739             :   bool isAlignmentRequired(const Type *T) const;
    1740             :   bool isAlignmentRequired(QualType T) const;
    1741             : 
    1742             :   /// \brief Return the "preferred" alignment of the specified type \p T for
    1743             :   /// the current target, in bits.
    1744             :   ///
    1745             :   /// This can be different than the ABI alignment in cases where it is
    1746             :   /// beneficial for performance to overalign a data type.
    1747             :   unsigned getPreferredTypeAlign(const Type *T) const;
    1748             : 
    1749             :   /// \brief Return the default alignment for __attribute__((aligned)) on
    1750             :   /// this target, to be used if no alignment value is specified.
    1751             :   unsigned getTargetDefaultAlignForAttributeAligned(void) const;
    1752             : 
    1753             :   /// \brief Return the alignment in bits that should be given to a
    1754             :   /// global variable with type \p T.
    1755             :   unsigned getAlignOfGlobalVar(QualType T) const;
    1756             : 
    1757             :   /// \brief Return the alignment in characters that should be given to a
    1758             :   /// global variable with type \p T.
    1759             :   CharUnits getAlignOfGlobalVarInChars(QualType T) const;
    1760             : 
    1761             :   /// \brief Return a conservative estimate of the alignment of the specified
    1762             :   /// decl \p D.
    1763             :   ///
    1764             :   /// \pre \p D must not be a bitfield type, as bitfields do not have a valid
    1765             :   /// alignment.
    1766             :   ///
    1767             :   /// If \p ForAlignof, references are treated like their underlying type
    1768             :   /// and  large arrays don't get any special treatment. If not \p ForAlignof
    1769             :   /// it computes the value expected by CodeGen: references are treated like
    1770             :   /// pointers and large arrays get extra alignment.
    1771             :   CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const;
    1772             : 
    1773             :   /// \brief Get or compute information about the layout of the specified
    1774             :   /// record (struct/union/class) \p D, which indicates its size and field
    1775             :   /// position information.
    1776             :   const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
    1777             :   const ASTRecordLayout *BuildMicrosoftASTRecordLayout(const RecordDecl *D) const;
    1778             : 
    1779             :   /// \brief Get or compute information about the layout of the specified
    1780             :   /// Objective-C interface.
    1781             :   const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
    1782             :     const;
    1783             : 
    1784             :   void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
    1785             :                         bool Simple = false) const;
    1786             : 
    1787             :   /// \brief Get or compute information about the layout of the specified
    1788             :   /// Objective-C implementation.
    1789             :   ///
    1790             :   /// This may differ from the interface if synthesized ivars are present.
    1791             :   const ASTRecordLayout &
    1792             :   getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
    1793             : 
    1794             :   /// \brief Get our current best idea for the key function of the
    1795             :   /// given record decl, or NULL if there isn't one.
    1796             :   ///
    1797             :   /// The key function is, according to the Itanium C++ ABI section 5.2.3:
    1798             :   ///   ...the first non-pure virtual function that is not inline at the
    1799             :   ///   point of class definition.
    1800             :   ///
    1801             :   /// Other ABIs use the same idea.  However, the ARM C++ ABI ignores
    1802             :   /// virtual functions that are defined 'inline', which means that
    1803             :   /// the result of this computation can change.
    1804             :   const CXXMethodDecl *getCurrentKeyFunction(const CXXRecordDecl *RD);
    1805             : 
    1806             :   /// \brief Observe that the given method cannot be a key function.
    1807             :   /// Checks the key-function cache for the method's class and clears it
    1808             :   /// if matches the given declaration.
    1809             :   ///
    1810             :   /// This is used in ABIs where out-of-line definitions marked
    1811             :   /// inline are not considered to be key functions.
    1812             :   ///
    1813             :   /// \param method should be the declaration from the class definition
    1814             :   void setNonKeyFunction(const CXXMethodDecl *method);
    1815             : 
    1816             :   /// Loading virtual member pointers using the virtual inheritance model
    1817             :   /// always results in an adjustment using the vbtable even if the index is
    1818             :   /// zero.
    1819             :   ///
    1820             :   /// This is usually OK because the first slot in the vbtable points
    1821             :   /// backwards to the top of the MDC.  However, the MDC might be reusing a
    1822             :   /// vbptr from an nv-base.  In this case, the first slot in the vbtable
    1823             :   /// points to the start of the nv-base which introduced the vbptr and *not*
    1824             :   /// the MDC.  Modify the NonVirtualBaseAdjustment to account for this.
    1825             :   CharUnits getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const;
    1826             : 
    1827             :   /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
    1828             :   uint64_t getFieldOffset(const ValueDecl *FD) const;
    1829             : 
    1830             :   bool isNearlyEmpty(const CXXRecordDecl *RD) const;
    1831             : 
    1832             :   VTableContextBase *getVTableContext();
    1833             : 
    1834             :   MangleContext *createMangleContext();
    1835             :   
    1836             :   void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
    1837             :                             SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
    1838             :   
    1839             :   unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
    1840             :   void CollectInheritedProtocols(const Decl *CDecl,
    1841             :                           llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
    1842             : 
    1843             :   //===--------------------------------------------------------------------===//
    1844             :   //                            Type Operators
    1845             :   //===--------------------------------------------------------------------===//
    1846             : 
    1847             :   /// \brief Return the canonical (structural) type corresponding to the
    1848             :   /// specified potentially non-canonical type \p T.
    1849             :   ///
    1850             :   /// The non-canonical version of a type may have many "decorated" versions of
    1851             :   /// types.  Decorators can include typedefs, 'typeof' operators, etc. The
    1852             :   /// returned type is guaranteed to be free of any of these, allowing two
    1853             :   /// canonical types to be compared for exact equality with a simple pointer
    1854             :   /// comparison.
    1855             :   CanQualType getCanonicalType(QualType T) const {
    1856             :     return CanQualType::CreateUnsafe(T.getCanonicalType());
    1857             :   }
    1858             : 
    1859             :   const Type *getCanonicalType(const Type *T) const {
    1860             :     return T->getCanonicalTypeInternal().getTypePtr();
    1861             :   }
    1862             : 
    1863             :   /// \brief Return the canonical parameter type corresponding to the specific
    1864             :   /// potentially non-canonical one.
    1865             :   ///
    1866             :   /// Qualifiers are stripped off, functions are turned into function
    1867             :   /// pointers, and arrays decay one level into pointers.
    1868             :   CanQualType getCanonicalParamType(QualType T) const;
    1869             : 
    1870             :   /// \brief Determine whether the given types \p T1 and \p T2 are equivalent.
    1871             :   bool hasSameType(QualType T1, QualType T2) const {
    1872             :     return getCanonicalType(T1) == getCanonicalType(T2);
    1873             :   }
    1874             : 
    1875             :   bool hasSameType(const Type *T1, const Type *T2) const {
    1876             :     return getCanonicalType(T1) == getCanonicalType(T2);
    1877             :   }
    1878             : 
    1879             :   /// \brief Return this type as a completely-unqualified array type,
    1880             :   /// capturing the qualifiers in \p Quals.
    1881             :   ///
    1882             :   /// This will remove the minimal amount of sugaring from the types, similar
    1883             :   /// to the behavior of QualType::getUnqualifiedType().
    1884             :   ///
    1885             :   /// \param T is the qualified type, which may be an ArrayType
    1886             :   ///
    1887             :   /// \param Quals will receive the full set of qualifiers that were
    1888             :   /// applied to the array.
    1889             :   ///
    1890             :   /// \returns if this is an array type, the completely unqualified array type
    1891             :   /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
    1892             :   QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
    1893             : 
    1894             :   /// \brief Determine whether the given types are equivalent after
    1895             :   /// cvr-qualifiers have been removed.
    1896             :   bool hasSameUnqualifiedType(QualType T1, QualType T2) const {
    1897             :     return getCanonicalType(T1).getTypePtr() ==
    1898             :            getCanonicalType(T2).getTypePtr();
    1899             :   }
    1900             : 
    1901             :   bool hasSameNullabilityTypeQualifier(QualType SubT, QualType SuperT,
    1902             :                                        bool IsParam) const {
    1903             :     auto SubTnullability = SubT->getNullability(*this);
    1904             :     auto SuperTnullability = SuperT->getNullability(*this);
    1905             :     if (SubTnullability.hasValue() == SuperTnullability.hasValue()) {
    1906             :       // Neither has nullability; return true
    1907             :       if (!SubTnullability)
    1908             :         return true;
    1909             :       // Both have nullability qualifier.
    1910             :       if (*SubTnullability == *SuperTnullability ||
    1911             :           *SubTnullability == NullabilityKind::Unspecified ||
    1912             :           *SuperTnullability == NullabilityKind::Unspecified)
    1913             :         return true;
    1914             :       
    1915             :       if (IsParam) {
    1916             :         // Ok for the superclass method parameter to be "nonnull" and the subclass
    1917             :         // method parameter to be "nullable"
    1918             :         return (*SuperTnullability == NullabilityKind::NonNull &&
    1919             :                 *SubTnullability == NullabilityKind::Nullable);
    1920             :       }
    1921             :       else {
    1922             :         // For the return type, it's okay for the superclass method to specify
    1923             :         // "nullable" and the subclass method specify "nonnull"
    1924             :         return (*SuperTnullability == NullabilityKind::Nullable &&
    1925             :                 *SubTnullability == NullabilityKind::NonNull);
    1926             :       }
    1927             :     }
    1928             :     return true;
    1929             :   }
    1930             : 
    1931             :   bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl,
    1932             :                            const ObjCMethodDecl *MethodImp);
    1933             :   
    1934             :   bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
    1935             :   
    1936             :   /// \brief Retrieves the "canonical" nested name specifier for a
    1937             :   /// given nested name specifier.
    1938             :   ///
    1939             :   /// The canonical nested name specifier is a nested name specifier
    1940             :   /// that uniquely identifies a type or namespace within the type
    1941             :   /// system. For example, given:
    1942             :   ///
    1943             :   /// \code
    1944             :   /// namespace N {
    1945             :   ///   struct S {
    1946             :   ///     template<typename T> struct X { typename T* type; };
    1947             :   ///   };
    1948             :   /// }
    1949             :   ///
    1950             :   /// template<typename T> struct Y {
    1951             :   ///   typename N::S::X<T>::type member;
    1952             :   /// };
    1953             :   /// \endcode
    1954             :   ///
    1955             :   /// Here, the nested-name-specifier for N::S::X<T>:: will be
    1956             :   /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
    1957             :   /// by declarations in the type system and the canonical type for
    1958             :   /// the template type parameter 'T' is template-param-0-0.
    1959             :   NestedNameSpecifier *
    1960             :   getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
    1961             : 
    1962             :   /// \brief Retrieves the default calling convention for the current target.
    1963             :   CallingConv getDefaultCallingConvention(bool isVariadic,
    1964             :                                           bool IsCXXMethod) const;
    1965             : 
    1966             :   /// \brief Retrieves the "canonical" template name that refers to a
    1967             :   /// given template.
    1968             :   ///
    1969             :   /// The canonical template name is the simplest expression that can
    1970             :   /// be used to refer to a given template. For most templates, this
    1971             :   /// expression is just the template declaration itself. For example,
    1972             :   /// the template std::vector can be referred to via a variety of
    1973             :   /// names---std::vector, \::std::vector, vector (if vector is in
    1974             :   /// scope), etc.---but all of these names map down to the same
    1975             :   /// TemplateDecl, which is used to form the canonical template name.
    1976             :   ///
    1977             :   /// Dependent template names are more interesting. Here, the
    1978             :   /// template name could be something like T::template apply or
    1979             :   /// std::allocator<T>::template rebind, where the nested name
    1980             :   /// specifier itself is dependent. In this case, the canonical
    1981             :   /// template name uses the shortest form of the dependent
    1982             :   /// nested-name-specifier, which itself contains all canonical
    1983             :   /// types, values, and templates.
    1984             :   TemplateName getCanonicalTemplateName(TemplateName Name) const;
    1985             : 
    1986             :   /// \brief Determine whether the given template names refer to the same
    1987             :   /// template.
    1988             :   bool hasSameTemplateName(TemplateName X, TemplateName Y);
    1989             :   
    1990             :   /// \brief Retrieve the "canonical" template argument.
    1991             :   ///
    1992             :   /// The canonical template argument is the simplest template argument
    1993             :   /// (which may be a type, value, expression, or declaration) that
    1994             :   /// expresses the value of the argument.
    1995             :   TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
    1996             :     const;
    1997             : 
    1998             :   /// Type Query functions.  If the type is an instance of the specified class,
    1999             :   /// return the Type pointer for the underlying maximally pretty type.  This
    2000             :   /// is a member of ASTContext because this may need to do some amount of
    2001             :   /// canonicalization, e.g. to move type qualifiers into the element type.
    2002             :   const ArrayType *getAsArrayType(QualType T) const;
    2003             :   const ConstantArrayType *getAsConstantArrayType(QualType T) const {
    2004             :     return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
    2005             :   }
    2006             :   const VariableArrayType *getAsVariableArrayType(QualType T) const {
    2007             :     return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
    2008             :   }
    2009             :   const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
    2010             :     return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
    2011             :   }
    2012             :   const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
    2013             :     const {
    2014             :     return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
    2015             :   }
    2016             :   
    2017             :   /// \brief Return the innermost element type of an array type.
    2018             :   ///
    2019             :   /// For example, will return "int" for int[m][n]
    2020             :   QualType getBaseElementType(const ArrayType *VAT) const;
    2021             : 
    2022             :   /// \brief Return the innermost element type of a type (which needn't
    2023             :   /// actually be an array type).
    2024             :   QualType getBaseElementType(QualType QT) const;
    2025             : 
    2026             :   /// \brief Return number of constant array elements.
    2027             :   uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
    2028             : 
    2029             :   /// \brief Perform adjustment on the parameter type of a function.
    2030             :   ///
    2031             :   /// This routine adjusts the given parameter type @p T to the actual
    2032             :   /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
    2033             :   /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
    2034             :   QualType getAdjustedParameterType(QualType T) const;
    2035             :   
    2036             :   /// \brief Retrieve the parameter type as adjusted for use in the signature
    2037             :   /// of a function, decaying array and function types and removing top-level
    2038             :   /// cv-qualifiers.
    2039             :   QualType getSignatureParameterType(QualType T) const;
    2040             :   
    2041             :   QualType getExceptionObjectType(QualType T) const;
    2042             :   
    2043             :   /// \brief Return the properly qualified result of decaying the specified
    2044             :   /// array type to a pointer.
    2045             :   ///
    2046             :   /// This operation is non-trivial when handling typedefs etc.  The canonical
    2047             :   /// type of \p T must be an array type, this returns a pointer to a properly
    2048             :   /// qualified element of the array.
    2049             :   ///
    2050             :   /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
    2051             :   QualType getArrayDecayedType(QualType T) const;
    2052             : 
    2053             :   /// \brief Return the type that \p PromotableType will promote to: C99
    2054             :   /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type.
    2055             :   QualType getPromotedIntegerType(QualType PromotableType) const;
    2056             : 
    2057             :   /// \brief Recurses in pointer/array types until it finds an Objective-C
    2058             :   /// retainable type and returns its ownership.
    2059             :   Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
    2060             : 
    2061             :   /// \brief Whether this is a promotable bitfield reference according
    2062             :   /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
    2063             :   ///
    2064             :   /// \returns the type this bit-field will promote to, or NULL if no
    2065             :   /// promotion occurs.
    2066             :   QualType isPromotableBitField(Expr *E) const;
    2067             : 
    2068             :   /// \brief Return the highest ranked integer type, see C99 6.3.1.8p1. 
    2069             :   ///
    2070             :   /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
    2071             :   /// \p LHS < \p RHS, return -1.
    2072             :   int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
    2073             : 
    2074             :   /// \brief Compare the rank of the two specified floating point types,
    2075             :   /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
    2076             :   ///
    2077             :   /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
    2078             :   /// \p LHS < \p RHS, return -1.
    2079             :   int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
    2080             : 
    2081             :   /// \brief Return a real floating point or a complex type (based on
    2082             :   /// \p typeDomain/\p typeSize).
    2083             :   ///
    2084             :   /// \param typeDomain a real floating point or complex type.
    2085             :   /// \param typeSize a real floating point or complex type.
    2086             :   QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
    2087             :                                              QualType typeDomain) const;
    2088             : 
    2089             :   unsigned getTargetAddressSpace(QualType T) const {
    2090             :     return getTargetAddressSpace(T.getQualifiers());
    2091             :   }
    2092             : 
    2093             :   unsigned getTargetAddressSpace(Qualifiers Q) const {
    2094             :     return getTargetAddressSpace(Q.getAddressSpace());
    2095             :   }
    2096             : 
    2097             :   unsigned getTargetAddressSpace(unsigned AS) const {
    2098             :     if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count)
    2099             :       return AS;
    2100             :     else
    2101             :       return (*AddrSpaceMap)[AS - LangAS::Offset];
    2102             :   }
    2103             : 
    2104             :   bool addressSpaceMapManglingFor(unsigned AS) const {
    2105             :     return AddrSpaceMapMangling || 
    2106             :            AS < LangAS::Offset || 
    2107             :            AS >= LangAS::Offset + LangAS::Count;
    2108             :   }
    2109             : 
    2110             : private:
    2111             :   // Helper for integer ordering
    2112             :   unsigned getIntegerRank(const Type *T) const;
    2113             : 
    2114             : public:
    2115             : 
    2116             :   //===--------------------------------------------------------------------===//
    2117             :   //                    Type Compatibility Predicates
    2118             :   //===--------------------------------------------------------------------===//
    2119             : 
    2120             :   /// Compatibility predicates used to check assignment expressions.
    2121             :   bool typesAreCompatible(QualType T1, QualType T2, 
    2122             :                           bool CompareUnqualified = false); // C99 6.2.7p1
    2123             : 
    2124             :   bool propertyTypesAreCompatible(QualType, QualType); 
    2125             :   bool typesAreBlockPointerCompatible(QualType, QualType); 
    2126             : 
    2127             :   bool isObjCIdType(QualType T) const {
    2128             :     return T == getObjCIdType();
    2129             :   }
    2130             :   bool isObjCClassType(QualType T) const {
    2131             :     return T == getObjCClassType();
    2132             :   }
    2133             :   bool isObjCSelType(QualType T) const {
    2134             :     return T == getObjCSelType();
    2135             :   }
    2136             :   bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
    2137             :                                          bool ForCompare);
    2138             : 
    2139             :   bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
    2140             :   
    2141             :   // Check the safety of assignment from LHS to RHS
    2142             :   bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
    2143             :                                const ObjCObjectPointerType *RHSOPT);
    2144             :   bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
    2145             :                                const ObjCObjectType *RHS);
    2146             :   bool canAssignObjCInterfacesInBlockPointer(
    2147             :                                           const ObjCObjectPointerType *LHSOPT,
    2148             :                                           const ObjCObjectPointerType *RHSOPT,
    2149             :                                           bool BlockReturnType);
    2150             :   bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
    2151             :   QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
    2152             :                                    const ObjCObjectPointerType *RHSOPT);
    2153             :   bool canBindObjCObjectType(QualType To, QualType From);
    2154             : 
    2155             :   // Functions for calculating composite types
    2156             :   QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
    2157             :                       bool Unqualified = false, bool BlockReturnType = false);
    2158             :   QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
    2159             :                               bool Unqualified = false);
    2160             :   QualType mergeFunctionParameterTypes(QualType, QualType,
    2161             :                                        bool OfBlockPointer = false,
    2162             :                                        bool Unqualified = false);
    2163             :   QualType mergeTransparentUnionType(QualType, QualType,
    2164             :                                      bool OfBlockPointer=false,
    2165             :                                      bool Unqualified = false);
    2166             :   
    2167             :   QualType mergeObjCGCQualifiers(QualType, QualType);
    2168             :     
    2169             :   bool FunctionTypesMatchOnNSConsumedAttrs(
    2170             :          const FunctionProtoType *FromFunctionType,
    2171             :          const FunctionProtoType *ToFunctionType);
    2172             : 
    2173             :   void ResetObjCLayout(const ObjCContainerDecl *CD) {
    2174             :     ObjCLayouts[CD] = nullptr;
    2175             :   }
    2176             : 
    2177             :   //===--------------------------------------------------------------------===//
    2178             :   //                    Integer Predicates
    2179             :   //===--------------------------------------------------------------------===//
    2180             : 
    2181             :   // The width of an integer, as defined in C99 6.2.6.2. This is the number
    2182             :   // of bits in an integer type excluding any padding bits.
    2183             :   unsigned getIntWidth(QualType T) const;
    2184             : 
    2185             :   // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
    2186             :   // unsigned integer type.  This method takes a signed type, and returns the
    2187             :   // corresponding unsigned integer type.
    2188             :   QualType getCorrespondingUnsignedType(QualType T) const;
    2189             : 
    2190             :   //===--------------------------------------------------------------------===//
    2191             :   //                    Type Iterators.
    2192             :   //===--------------------------------------------------------------------===//
    2193             :   typedef llvm::iterator_range<SmallVectorImpl<Type *>::const_iterator>
    2194             :     type_const_range;
    2195             : 
    2196             :   type_const_range types() const {
    2197             :     return type_const_range(Types.begin(), Types.end());
    2198             :   }
    2199             : 
    2200             :   //===--------------------------------------------------------------------===//
    2201             :   //                    Integer Values
    2202             :   //===--------------------------------------------------------------------===//
    2203             : 
    2204             :   /// \brief Make an APSInt of the appropriate width and signedness for the
    2205             :   /// given \p Value and integer \p Type.
    2206             :   llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
    2207             :     llvm::APSInt Res(getIntWidth(Type), 
    2208             :                      !Type->isSignedIntegerOrEnumerationType());
    2209             :     Res = Value;
    2210             :     return Res;
    2211             :   }
    2212             : 
    2213             :   bool isSentinelNullExpr(const Expr *E);
    2214             : 
    2215             :   /// \brief Get the implementation of the ObjCInterfaceDecl \p D, or NULL if
    2216             :   /// none exists.
    2217             :   ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
    2218             :   /// \brief Get the implementation of the ObjCCategoryDecl \p D, or NULL if
    2219             :   /// none exists.
    2220             :   ObjCCategoryImplDecl   *getObjCImplementation(ObjCCategoryDecl *D);
    2221             : 
    2222             :   /// \brief Return true if there is at least one \@implementation in the TU.
    2223             :   bool AnyObjCImplementation() {
    2224             :     return !ObjCImpls.empty();
    2225             :   }
    2226             : 
    2227             :   /// \brief Set the implementation of ObjCInterfaceDecl.
    2228             :   void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
    2229             :                              ObjCImplementationDecl *ImplD);
    2230             :   /// \brief Set the implementation of ObjCCategoryDecl.
    2231             :   void setObjCImplementation(ObjCCategoryDecl *CatD,
    2232             :                              ObjCCategoryImplDecl *ImplD);
    2233             : 
    2234             :   /// \brief Get the duplicate declaration of a ObjCMethod in the same
    2235             :   /// interface, or null if none exists.
    2236             :   const ObjCMethodDecl *getObjCMethodRedeclaration(
    2237             :                                                const ObjCMethodDecl *MD) const {
    2238             :     return ObjCMethodRedecls.lookup(MD);
    2239             :   }
    2240             : 
    2241             :   void setObjCMethodRedeclaration(const ObjCMethodDecl *MD,
    2242             :                                   const ObjCMethodDecl *Redecl) {
    2243             :     assert(!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration");
    2244             :     ObjCMethodRedecls[MD] = Redecl;
    2245             :   }
    2246             : 
    2247             :   /// \brief Returns the Objective-C interface that \p ND belongs to if it is
    2248             :   /// an Objective-C method/property/ivar etc. that is part of an interface,
    2249             :   /// otherwise returns null.
    2250             :   const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const;
    2251             :   
    2252             :   /// \brief Set the copy inialization expression of a block var decl.
    2253             :   void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
    2254             :   /// \brief Get the copy initialization expression of the VarDecl \p VD, or
    2255             :   /// NULL if none exists.
    2256             :   Expr *getBlockVarCopyInits(const VarDecl* VD);
    2257             : 
    2258             :   /// \brief Allocate an uninitialized TypeSourceInfo.
    2259             :   ///
    2260             :   /// The caller should initialize the memory held by TypeSourceInfo using
    2261             :   /// the TypeLoc wrappers.
    2262             :   ///
    2263             :   /// \param T the type that will be the basis for type source info. This type
    2264             :   /// should refer to how the declarator was written in source code, not to
    2265             :   /// what type semantic analysis resolved the declarator to.
    2266             :   ///
    2267             :   /// \param Size the size of the type info to create, or 0 if the size
    2268             :   /// should be calculated based on the type.
    2269             :   TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
    2270             : 
    2271             :   /// \brief Allocate a TypeSourceInfo where all locations have been
    2272             :   /// initialized to a given location, which defaults to the empty
    2273             :   /// location.
    2274             :   TypeSourceInfo *
    2275             :   getTrivialTypeSourceInfo(QualType T, 
    2276             :                            SourceLocation Loc = SourceLocation()) const;
    2277             : 
    2278             :   /// \brief Add a deallocation callback that will be invoked when the 
    2279             :   /// ASTContext is destroyed.
    2280             :   ///
    2281             :   /// \param Callback A callback function that will be invoked on destruction.
    2282             :   ///
    2283             :   /// \param Data Pointer data that will be provided to the callback function
    2284             :   /// when it is called.
    2285             :   void AddDeallocation(void (*Callback)(void*), void *Data);
    2286             : 
    2287             :   GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const;
    2288             :   GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
    2289             : 
    2290             :   /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH
    2291             :   /// lazily, only when used; this is only relevant for function or file scoped
    2292             :   /// var definitions.
    2293             :   ///
    2294             :   /// \returns true if the function/var must be CodeGen'ed/deserialized even if
    2295             :   /// it is not used.
    2296             :   bool DeclMustBeEmitted(const Decl *D);
    2297             : 
    2298             :   const CXXConstructorDecl *
    2299             :   getCopyConstructorForExceptionObject(CXXRecordDecl *RD);
    2300             : 
    2301             :   void addCopyConstructorForExceptionObject(CXXRecordDecl *RD,
    2302             :                                             CXXConstructorDecl *CD);
    2303             : 
    2304             :   void addDefaultArgExprForConstructor(const CXXConstructorDecl *CD,
    2305             :                                        unsigned ParmIdx, Expr *DAE);
    2306             : 
    2307             :   Expr *getDefaultArgExprForConstructor(const CXXConstructorDecl *CD,
    2308             :                                         unsigned ParmIdx);
    2309             : 
    2310             :   void setManglingNumber(const NamedDecl *ND, unsigned Number);
    2311             :   unsigned getManglingNumber(const NamedDecl *ND) const;
    2312             : 
    2313             :   void setStaticLocalNumber(const VarDecl *VD, unsigned Number);
    2314             :   unsigned getStaticLocalNumber(const VarDecl *VD) const;
    2315             : 
    2316             :   /// \brief Retrieve the context for computing mangling numbers in the given
    2317             :   /// DeclContext.
    2318             :   MangleNumberingContext &getManglingNumberContext(const DeclContext *DC);
    2319             : 
    2320             :   MangleNumberingContext *createMangleNumberingContext() const;
    2321             : 
    2322             :   /// \brief Used by ParmVarDecl to store on the side the
    2323             :   /// index of the parameter when it exceeds the size of the normal bitfield.
    2324             :   void setParameterIndex(const ParmVarDecl *D, unsigned index);
    2325             : 
    2326             :   /// \brief Used by ParmVarDecl to retrieve on the side the
    2327             :   /// index of the parameter when it exceeds the size of the normal bitfield.
    2328             :   unsigned getParameterIndex(const ParmVarDecl *D) const;
    2329             : 
    2330             :   /// \brief Get the storage for the constant value of a materialized temporary
    2331             :   /// of static storage duration.
    2332             :   APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,
    2333             :                                          bool MayCreate);
    2334             : 
    2335             :   //===--------------------------------------------------------------------===//
    2336             :   //                    Statistics
    2337             :   //===--------------------------------------------------------------------===//
    2338             : 
    2339             :   /// \brief The number of implicitly-declared default constructors.
    2340             :   static unsigned NumImplicitDefaultConstructors;
    2341             :   
    2342             :   /// \brief The number of implicitly-declared default constructors for 
    2343             :   /// which declarations were built.
    2344             :   static unsigned NumImplicitDefaultConstructorsDeclared;
    2345             : 
    2346             :   /// \brief The number of implicitly-declared copy constructors.
    2347             :   static unsigned NumImplicitCopyConstructors;
    2348             :   
    2349             :   /// \brief The number of implicitly-declared copy constructors for 
    2350             :   /// which declarations were built.
    2351             :   static unsigned NumImplicitCopyConstructorsDeclared;
    2352             : 
    2353             :   /// \brief The number of implicitly-declared move constructors.
    2354             :   static unsigned NumImplicitMoveConstructors;
    2355             : 
    2356             :   /// \brief The number of implicitly-declared move constructors for
    2357             :   /// which declarations were built.
    2358             :   static unsigned NumImplicitMoveConstructorsDeclared;
    2359             : 
    2360             :   /// \brief The number of implicitly-declared copy assignment operators.
    2361             :   static unsigned NumImplicitCopyAssignmentOperators;
    2362             :   
    2363             :   /// \brief The number of implicitly-declared copy assignment operators for 
    2364             :   /// which declarations were built.
    2365             :   static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
    2366             : 
    2367             :   /// \brief The number of implicitly-declared move assignment operators.
    2368             :   static unsigned NumImplicitMoveAssignmentOperators;
    2369             :   
    2370             :   /// \brief The number of implicitly-declared move assignment operators for 
    2371             :   /// which declarations were built.
    2372             :   static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
    2373             : 
    2374             :   /// \brief The number of implicitly-declared destructors.
    2375             :   static unsigned NumImplicitDestructors;
    2376             :   
    2377             :   /// \brief The number of implicitly-declared destructors for which 
    2378             :   /// declarations were built.
    2379             :   static unsigned NumImplicitDestructorsDeclared;
    2380             :   
    2381             : private:
    2382             :   ASTContext(const ASTContext &) = delete;
    2383             :   void operator=(const ASTContext &) = delete;
    2384             : 
    2385             : public:
    2386             :   /// \brief Initialize built-in types.
    2387             :   ///
    2388             :   /// This routine may only be invoked once for a given ASTContext object.
    2389             :   /// It is normally invoked after ASTContext construction.
    2390             :   ///
    2391             :   /// \param Target The target 
    2392             :   void InitBuiltinTypes(const TargetInfo &Target);
    2393             :   
    2394             : private:
    2395             :   void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
    2396             : 
    2397             :   // Return the Objective-C type encoding for a given type.
    2398             :   void getObjCEncodingForTypeImpl(QualType t, std::string &S,
    2399             :                                   bool ExpandPointedToStructures,
    2400             :                                   bool ExpandStructures,
    2401             :                                   const FieldDecl *Field,
    2402             :                                   bool OutermostType = false,
    2403             :                                   bool EncodingProperty = false,
    2404             :                                   bool StructField = false,
    2405             :                                   bool EncodeBlockParameters = false,
    2406             :                                   bool EncodeClassNames = false,
    2407             :                                   bool EncodePointerToObjCTypedef = false,
    2408             :                                   QualType *NotEncodedT=nullptr) const;
    2409             : 
    2410             :   // Adds the encoding of the structure's members.
    2411             :   void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
    2412             :                                        const FieldDecl *Field,
    2413             :                                        bool includeVBases = true,
    2414             :                                        QualType *NotEncodedT=nullptr) const;
    2415             : public:
    2416             :   // Adds the encoding of a method parameter or return type.
    2417             :   void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT,
    2418             :                                          QualType T, std::string& S,
    2419             :                                          bool Extended) const;
    2420             : 
    2421             :   /// \brief Returns true if this is an inline-initialized static data member
    2422             :   /// which is treated as a definition for MSVC compatibility.
    2423             :   bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const;
    2424             :   
    2425             : private:
    2426             :   const ASTRecordLayout &
    2427             :   getObjCLayout(const ObjCInterfaceDecl *D,
    2428             :                 const ObjCImplementationDecl *Impl) const;
    2429             : 
    2430             :   /// \brief A set of deallocations that should be performed when the
    2431             :   /// ASTContext is destroyed.
    2432             :   typedef llvm::SmallDenseMap<void(*)(void*), llvm::SmallVector<void*, 16> >
    2433             :     DeallocationMap;
    2434             :   DeallocationMap Deallocations;
    2435             : 
    2436             :   // FIXME: This currently contains the set of StoredDeclMaps used
    2437             :   // by DeclContext objects.  This probably should not be in ASTContext,
    2438             :   // but we include it here so that ASTContext can quickly deallocate them.
    2439             :   llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
    2440             : 
    2441             :   friend class DeclContext;
    2442             :   friend class DeclarationNameTable;
    2443             :   void ReleaseDeclContextMaps();
    2444             :   void ReleaseParentMapEntries();
    2445             : 
    2446             :   std::unique_ptr<ParentMap> AllParents;
    2447             : 
    2448             :   std::unique_ptr<VTableContextBase> VTContext;
    2449             : 
    2450             : public:
    2451             :   enum PragmaSectionFlag : unsigned {
    2452             :     PSF_None = 0,
    2453             :     PSF_Read = 0x1,
    2454             :     PSF_Write = 0x2,
    2455             :     PSF_Execute = 0x4,
    2456             :     PSF_Implicit = 0x8,
    2457             :     PSF_Invalid = 0x80000000U,
    2458             :   };
    2459             : 
    2460             :   struct SectionInfo {
    2461             :     DeclaratorDecl *Decl;
    2462             :     SourceLocation PragmaSectionLocation;
    2463             :     int SectionFlags;
    2464             :     SectionInfo() {}
    2465             :     SectionInfo(DeclaratorDecl *Decl,
    2466             :                 SourceLocation PragmaSectionLocation,
    2467             :                 int SectionFlags)
    2468             :       : Decl(Decl),
    2469             :         PragmaSectionLocation(PragmaSectionLocation),
    2470             :         SectionFlags(SectionFlags) {}
    2471             :   };
    2472             : 
    2473             :   llvm::StringMap<SectionInfo> SectionInfos;
    2474             : };
    2475             : 
    2476             : /// \brief Utility function for constructing a nullary selector.
    2477             : static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) {
    2478             :   IdentifierInfo* II = &Ctx.Idents.get(name);
    2479             :   return Ctx.Selectors.getSelector(0, &II);
    2480             : }
    2481             : 
    2482             : /// \brief Utility function for constructing an unary selector.
    2483             : static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) {
    2484             :   IdentifierInfo* II = &Ctx.Idents.get(name);
    2485             :   return Ctx.Selectors.getSelector(1, &II);
    2486             : }
    2487             : 
    2488             : }  // end namespace clang
    2489             : 
    2490             : // operator new and delete aren't allowed inside namespaces.
    2491             : 
    2492             : /// @brief Placement new for using the ASTContext's allocator.
    2493             : ///
    2494             : /// This placement form of operator new uses the ASTContext's allocator for
    2495             : /// obtaining memory.
    2496             : ///
    2497             : /// IMPORTANT: These are also declared in clang/AST/AttrIterator.h! Any changes
    2498             : /// here need to also be made there.
    2499             : ///
    2500             : /// We intentionally avoid using a nothrow specification here so that the calls
    2501             : /// to this operator will not perform a null check on the result -- the
    2502             : /// underlying allocator never returns null pointers.
    2503             : ///
    2504             : /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
    2505             : /// @code
    2506             : /// // Default alignment (8)
    2507             : /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
    2508             : /// // Specific alignment
    2509             : /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
    2510             : /// @endcode
    2511             : /// Memory allocated through this placement new operator does not need to be
    2512             : /// explicitly freed, as ASTContext will free all of this memory when it gets
    2513             : /// destroyed. Please note that you cannot use delete on the pointer.
    2514             : ///
    2515             : /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
    2516             : /// @param C The ASTContext that provides the allocator.
    2517             : /// @param Alignment The alignment of the allocated memory (if the underlying
    2518             : ///                  allocator supports it).
    2519             : /// @return The allocated memory. Could be NULL.
    2520             : inline void *operator new(size_t Bytes, const clang::ASTContext &C,
    2521             :                           size_t Alignment) {
    2522           0 :   return C.Allocate(Bytes, Alignment);
    2523             : }
    2524             : /// @brief Placement delete companion to the new above.
    2525             : ///
    2526             : /// This operator is just a companion to the new above. There is no way of
    2527             : /// invoking it directly; see the new operator for more details. This operator
    2528             : /// is called implicitly by the compiler if a placement new expression using
    2529             : /// the ASTContext throws in the object constructor.
    2530             : inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) {
    2531           0 :   C.Deallocate(Ptr);
    2532           0 : }
    2533             : 
    2534             : /// This placement form of operator new[] uses the ASTContext's allocator for
    2535             : /// obtaining memory.
    2536             : ///
    2537             : /// We intentionally avoid using a nothrow specification here so that the calls
    2538             : /// to this operator will not perform a null check on the result -- the
    2539             : /// underlying allocator never returns null pointers.
    2540             : ///
    2541             : /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
    2542             : /// @code
    2543             : /// // Default alignment (8)
    2544             : /// char *data = new (Context) char[10];
    2545             : /// // Specific alignment
    2546             : /// char *data = new (Context, 4) char[10];
    2547             : /// @endcode
    2548             : /// Memory allocated through this placement new[] operator does not need to be
    2549             : /// explicitly freed, as ASTContext will free all of this memory when it gets
    2550             : /// destroyed. Please note that you cannot use delete on the pointer.
    2551             : ///
    2552             : /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
    2553             : /// @param C The ASTContext that provides the allocator.
    2554             : /// @param Alignment The alignment of the allocated memory (if the underlying
    2555             : ///                  allocator supports it).
    2556             : /// @return The allocated memory. Could be NULL.
    2557             : inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
    2558             :                             size_t Alignment = 8) {
    2559             :   return C.Allocate(Bytes, Alignment);
    2560             : }
    2561             : 
    2562             : /// @brief Placement delete[] companion to the new[] above.
    2563             : ///
    2564             : /// This operator is just a companion to the new[] above. There is no way of
    2565             : /// invoking it directly; see the new[] operator for more details. This operator
    2566             : /// is called implicitly by the compiler if a placement new[] expression using
    2567             : /// the ASTContext throws in the object constructor.
    2568             : inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
    2569             :   C.Deallocate(Ptr);
    2570             : }
    2571             : 
    2572             : /// \brief Create the representation of a LazyGenerationalUpdatePtr.
    2573             : template <typename Owner, typename T,
    2574             :           void (clang::ExternalASTSource::*Update)(Owner)>
    2575             : typename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType
    2576             :     clang::LazyGenerationalUpdatePtr<Owner, T, Update>::makeValue(
    2577             :         const clang::ASTContext &Ctx, T Value) {
    2578             :   // Note, this is implemented here so that ExternalASTSource.h doesn't need to
    2579             :   // include ASTContext.h. We explicitly instantiate it for all relevant types
    2580             :   // in ASTContext.cpp.
    2581           0 :   if (auto *Source = Ctx.getExternalSource())
    2582           0 :     return new (Ctx) LazyData(Source, Value);
    2583           0 :   return Value;
    2584           0 : }
    2585             : 
    2586             : #endif

Generated by: LCOV version 1.11