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