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