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