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