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