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