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