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