1 //===--- ASTContext.h - Context to hold long-lived AST nodes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::ASTContext interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_ASTCONTEXT_H
16 #define LLVM_CLANG_AST_ASTCONTEXT_H
18 #include "clang/AST/ASTTypeTraits.h"
19 #include "clang/AST/CanonicalType.h"
20 #include "clang/AST/CommentCommandTraits.h"
21 #include "clang/AST/Decl.h"
22 #include "clang/AST/ExternalASTSource.h"
23 #include "clang/AST/NestedNameSpecifier.h"
24 #include "clang/AST/PrettyPrinter.h"
25 #include "clang/AST/RawCommentList.h"
26 #include "clang/AST/TemplateName.h"
27 #include "clang/AST/Type.h"
28 #include "clang/Basic/AddressSpaces.h"
29 #include "clang/Basic/IdentifierTable.h"
30 #include "clang/Basic/LangOptions.h"
31 #include "clang/Basic/OperatorKinds.h"
32 #include "clang/Basic/PartialDiagnostic.h"
33 #include "clang/Basic/SanitizerBlacklist.h"
34 #include "clang/Basic/VersionTuple.h"
35 #include "llvm/ADT/DenseMap.h"
36 #include "llvm/ADT/FoldingSet.h"
37 #include "llvm/ADT/IntrusiveRefCntPtr.h"
38 #include "llvm/ADT/SmallPtrSet.h"
39 #include "llvm/ADT/TinyPtrVector.h"
40 #include "llvm/Support/Allocator.h"
51 class ASTRecordLayout;
54 class DiagnosticsEngine;
56 class ASTMutationListener;
57 class IdentifierTable;
58 class MaterializeTemporaryExpr;
62 class MangleNumberingContext;
66 class ObjCPropertyDecl;
67 class UnresolvedSetIterator;
69 class UsingShadowDecl;
70 class VTableContextBase;
72 namespace Builtin { class Context; }
81 bool AlignIsRequired : 1;
82 TypeInfo() : Width(0), Align(0), AlignIsRequired(false) {}
83 TypeInfo(uint64_t Width, unsigned Align, bool AlignIsRequired)
84 : Width(Width), Align(Align), AlignIsRequired(AlignIsRequired) {}
87 /// \brief Holds long-lived AST nodes (such as types and decls) that can be
88 /// referred to throughout the semantic analysis of a file.
89 class ASTContext : public RefCountedBase<ASTContext> {
90 ASTContext &this_() { return *this; }
92 mutable SmallVector<Type *, 0> Types;
93 mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
94 mutable llvm::FoldingSet<ComplexType> ComplexTypes;
95 mutable llvm::FoldingSet<PointerType> PointerTypes;
96 mutable llvm::FoldingSet<AdjustedType> AdjustedTypes;
97 mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
98 mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
99 mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
100 mutable llvm::FoldingSet<MemberPointerType> MemberPointerTypes;
101 mutable llvm::FoldingSet<ConstantArrayType> ConstantArrayTypes;
102 mutable llvm::FoldingSet<IncompleteArrayType> IncompleteArrayTypes;
103 mutable std::vector<VariableArrayType*> VariableArrayTypes;
104 mutable llvm::FoldingSet<DependentSizedArrayType> DependentSizedArrayTypes;
105 mutable llvm::FoldingSet<DependentSizedExtVectorType>
106 DependentSizedExtVectorTypes;
107 mutable llvm::FoldingSet<VectorType> VectorTypes;
108 mutable llvm::FoldingSet<FunctionNoProtoType> FunctionNoProtoTypes;
109 mutable llvm::ContextualFoldingSet<FunctionProtoType, ASTContext&>
111 mutable llvm::FoldingSet<DependentTypeOfExprType> DependentTypeOfExprTypes;
112 mutable llvm::FoldingSet<DependentDecltypeType> DependentDecltypeTypes;
113 mutable llvm::FoldingSet<TemplateTypeParmType> TemplateTypeParmTypes;
114 mutable llvm::FoldingSet<SubstTemplateTypeParmType>
115 SubstTemplateTypeParmTypes;
116 mutable llvm::FoldingSet<SubstTemplateTypeParmPackType>
117 SubstTemplateTypeParmPackTypes;
118 mutable llvm::ContextualFoldingSet<TemplateSpecializationType, ASTContext&>
119 TemplateSpecializationTypes;
120 mutable llvm::FoldingSet<ParenType> ParenTypes;
121 mutable llvm::FoldingSet<ElaboratedType> ElaboratedTypes;
122 mutable llvm::FoldingSet<DependentNameType> DependentNameTypes;
123 mutable llvm::ContextualFoldingSet<DependentTemplateSpecializationType,
125 DependentTemplateSpecializationTypes;
126 llvm::FoldingSet<PackExpansionType> PackExpansionTypes;
127 mutable llvm::FoldingSet<ObjCObjectTypeImpl> ObjCObjectTypes;
128 mutable llvm::FoldingSet<ObjCObjectPointerType> ObjCObjectPointerTypes;
129 mutable llvm::FoldingSet<AutoType> AutoTypes;
130 mutable llvm::FoldingSet<AtomicType> AtomicTypes;
131 llvm::FoldingSet<AttributedType> AttributedTypes;
133 mutable llvm::FoldingSet<QualifiedTemplateName> QualifiedTemplateNames;
134 mutable llvm::FoldingSet<DependentTemplateName> DependentTemplateNames;
135 mutable llvm::FoldingSet<SubstTemplateTemplateParmStorage>
136 SubstTemplateTemplateParms;
137 mutable llvm::ContextualFoldingSet<SubstTemplateTemplateParmPackStorage,
139 SubstTemplateTemplateParmPacks;
141 /// \brief The set of nested name specifiers.
143 /// This set is managed by the NestedNameSpecifier class.
144 mutable llvm::FoldingSet<NestedNameSpecifier> NestedNameSpecifiers;
145 mutable NestedNameSpecifier *GlobalNestedNameSpecifier;
146 friend class NestedNameSpecifier;
148 /// \brief A cache mapping from RecordDecls to ASTRecordLayouts.
150 /// This is lazily created. This is intentionally not serialized.
151 mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
153 mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
156 /// \brief A cache from types to size and alignment information.
157 typedef llvm::DenseMap<const Type *, struct TypeInfo> TypeInfoMap;
158 mutable TypeInfoMap MemoizedTypeInfo;
160 /// \brief A cache mapping from CXXRecordDecls to key functions.
161 llvm::DenseMap<const CXXRecordDecl*, LazyDeclPtr> KeyFunctions;
163 /// \brief Mapping from ObjCContainers to their ObjCImplementations.
164 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*> ObjCImpls;
166 /// \brief Mapping from ObjCMethod to its duplicate declaration in the same
168 llvm::DenseMap<const ObjCMethodDecl*,const ObjCMethodDecl*> ObjCMethodRedecls;
170 /// \brief Mapping from __block VarDecls to their copy initialization expr.
171 llvm::DenseMap<const VarDecl*, Expr*> BlockVarCopyInits;
173 /// \brief Mapping from class scope functions specialization to their
174 /// template patterns.
175 llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
176 ClassScopeSpecializationPattern;
178 /// \brief Mapping from materialized temporaries with static storage duration
179 /// that appear in constant initializers to their evaluated values.
180 llvm::DenseMap<const MaterializeTemporaryExpr*, APValue>
181 MaterializedTemporaryValues;
183 /// \brief Representation of a "canonical" template template parameter that
184 /// is used in canonical template names.
185 class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
186 TemplateTemplateParmDecl *Parm;
189 CanonicalTemplateTemplateParm(TemplateTemplateParmDecl *Parm)
192 TemplateTemplateParmDecl *getParam() const { return Parm; }
194 void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Parm); }
196 static void Profile(llvm::FoldingSetNodeID &ID,
197 TemplateTemplateParmDecl *Parm);
199 mutable llvm::FoldingSet<CanonicalTemplateTemplateParm>
200 CanonTemplateTemplateParms;
202 TemplateTemplateParmDecl *
203 getCanonicalTemplateTemplateParmDecl(TemplateTemplateParmDecl *TTP) const;
205 /// \brief The typedef for the __int128_t type.
206 mutable TypedefDecl *Int128Decl;
208 /// \brief The typedef for the __uint128_t type.
209 mutable TypedefDecl *UInt128Decl;
211 /// \brief The typedef for the __float128 stub type.
212 mutable TypeDecl *Float128StubDecl;
214 /// \brief The typedef for the target specific predefined
215 /// __builtin_va_list type.
216 mutable TypedefDecl *BuiltinVaListDecl;
218 /// \brief The typedef for the predefined \c id type.
219 mutable TypedefDecl *ObjCIdDecl;
221 /// \brief The typedef for the predefined \c SEL type.
222 mutable TypedefDecl *ObjCSelDecl;
224 /// \brief The typedef for the predefined \c Class type.
225 mutable TypedefDecl *ObjCClassDecl;
227 /// \brief The typedef for the predefined \c Protocol class in Objective-C.
228 mutable ObjCInterfaceDecl *ObjCProtocolClassDecl;
230 /// \brief The typedef for the predefined 'BOOL' type.
231 mutable TypedefDecl *BOOLDecl;
233 // Typedefs which may be provided defining the structure of Objective-C
235 QualType ObjCIdRedefinitionType;
236 QualType ObjCClassRedefinitionType;
237 QualType ObjCSelRedefinitionType;
239 /// The identifier 'NSObject'.
240 IdentifierInfo *NSObjectName = nullptr;
242 /// The identifier 'NSCopying'.
243 IdentifierInfo *NSCopyingName = nullptr;
245 QualType ObjCConstantStringType;
246 mutable RecordDecl *CFConstantStringTypeDecl;
248 mutable QualType ObjCSuperType;
250 QualType ObjCNSStringType;
252 /// \brief The typedef declaration for the Objective-C "instancetype" type.
253 TypedefDecl *ObjCInstanceTypeDecl;
255 /// \brief The type for the C FILE type.
258 /// \brief The type for the C jmp_buf type.
259 TypeDecl *jmp_bufDecl;
261 /// \brief The type for the C sigjmp_buf type.
262 TypeDecl *sigjmp_bufDecl;
264 /// \brief The type for the C ucontext_t type.
265 TypeDecl *ucontext_tDecl;
267 /// \brief Type for the Block descriptor for Blocks CodeGen.
269 /// Since this is only used for generation of debug info, it is not
271 mutable RecordDecl *BlockDescriptorType;
273 /// \brief Type for the Block descriptor for Blocks CodeGen.
275 /// Since this is only used for generation of debug info, it is not
277 mutable RecordDecl *BlockDescriptorExtendedType;
279 /// \brief Declaration for the CUDA cudaConfigureCall function.
280 FunctionDecl *cudaConfigureCallDecl;
282 /// \brief Keeps track of all declaration attributes.
284 /// Since so few decls have attrs, we keep them in a hash map instead of
285 /// wasting space in the Decl class.
286 llvm::DenseMap<const Decl*, AttrVec*> DeclAttrs;
288 /// \brief A mapping from non-redeclarable declarations in modules that were
289 /// merged with other declarations to the canonical declaration that they were
291 llvm::DenseMap<Decl*, Decl*> MergedDecls;
293 /// \brief A mapping from a defining declaration to a list of modules (other
294 /// than the owning module of the declaration) that contain merged
295 /// definitions of that entity.
296 llvm::DenseMap<NamedDecl*, llvm::TinyPtrVector<Module*>> MergedDefModules;
299 /// \brief A type synonym for the TemplateOrInstantiation mapping.
300 typedef llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *>
301 TemplateOrSpecializationInfo;
305 /// \brief A mapping to contain the template or declaration that
306 /// a variable declaration describes or was instantiated from,
309 /// For non-templates, this value will be NULL. For variable
310 /// declarations that describe a variable template, this will be a
311 /// pointer to a VarTemplateDecl. For static data members
312 /// of class template specializations, this will be the
313 /// MemberSpecializationInfo referring to the member variable that was
314 /// instantiated or specialized. Thus, the mapping will keep track of
315 /// the static data member templates from which static data members of
316 /// class template specializations were instantiated.
318 /// Given the following example:
321 /// template<typename T>
326 /// template<typename T>
327 /// T X<T>::value = T(17);
329 /// int *x = &X<int>::value;
332 /// This mapping will contain an entry that maps from the VarDecl for
333 /// X<int>::value to the corresponding VarDecl for X<T>::value (within the
334 /// class template X) and will be marked TSK_ImplicitInstantiation.
335 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>
336 TemplateOrInstantiation;
338 /// \brief Keeps track of the declaration from which a UsingDecl was
339 /// created during instantiation.
341 /// The source declaration is always a UsingDecl, an UnresolvedUsingValueDecl,
342 /// or an UnresolvedUsingTypenameDecl.
346 /// template<typename T>
351 /// template<typename T>
352 /// struct B : A<T> {
356 /// template struct B<int>;
359 /// This mapping will contain an entry that maps from the UsingDecl in
360 /// B<int> to the UnresolvedUsingDecl in B<T>.
361 llvm::DenseMap<UsingDecl *, NamedDecl *> InstantiatedFromUsingDecl;
363 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>
364 InstantiatedFromUsingShadowDecl;
366 llvm::DenseMap<FieldDecl *, FieldDecl *> InstantiatedFromUnnamedFieldDecl;
368 /// \brief Mapping that stores the methods overridden by a given C++
371 /// Since most C++ member functions aren't virtual and therefore
372 /// don't override anything, we store the overridden functions in
373 /// this map on the side rather than within the CXXMethodDecl structure.
374 typedef llvm::TinyPtrVector<const CXXMethodDecl*> CXXMethodVector;
375 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector> OverriddenMethods;
377 /// \brief Mapping from each declaration context to its corresponding
378 /// mangling numbering context (used for constructs like lambdas which
379 /// need to be consistently numbered for the mangler).
380 llvm::DenseMap<const DeclContext *, MangleNumberingContext *>
381 MangleNumberingContexts;
383 /// \brief Side-table of mangling numbers for declarations which rarely
384 /// need them (like static local vars).
385 llvm::DenseMap<const NamedDecl *, unsigned> MangleNumbers;
386 llvm::DenseMap<const VarDecl *, unsigned> StaticLocalNumbers;
388 /// \brief Mapping that stores parameterIndex values for ParmVarDecls when
389 /// that value exceeds the bitfield size of ParmVarDeclBits.ParameterIndex.
390 typedef llvm::DenseMap<const VarDecl *, unsigned> ParameterIndexTable;
391 ParameterIndexTable ParamIndices;
393 ImportDecl *FirstLocalImport;
394 ImportDecl *LastLocalImport;
396 TranslationUnitDecl *TUDecl;
397 mutable ExternCContextDecl *ExternCContext;
399 /// \brief The associated SourceManager object.a
400 SourceManager &SourceMgr;
402 /// \brief The language options used to create the AST associated with
403 /// this ASTContext object.
404 LangOptions &LangOpts;
406 /// \brief Blacklist object that is used by sanitizers to decide which
407 /// entities should not be instrumented.
408 std::unique_ptr<SanitizerBlacklist> SanitizerBL;
410 /// \brief The allocator used to create AST objects.
412 /// AST objects are never destructed; rather, all memory associated with the
413 /// AST objects will be released when the ASTContext itself is destroyed.
414 mutable llvm::BumpPtrAllocator BumpAlloc;
416 /// \brief Allocator for partial diagnostics.
417 PartialDiagnostic::StorageAllocator DiagAllocator;
419 /// \brief The current C++ ABI.
420 std::unique_ptr<CXXABI> ABI;
421 CXXABI *createCXXABI(const TargetInfo &T);
423 /// \brief The logical -> physical address space map.
424 const LangAS::Map *AddrSpaceMap;
426 /// \brief Address space map mangling must be used with language specific
427 /// address spaces (e.g. OpenCL/CUDA)
428 bool AddrSpaceMapMangling;
430 friend class ASTDeclReader;
431 friend class ASTReader;
432 friend class ASTWriter;
433 friend class CXXRecordDecl;
435 const TargetInfo *Target;
436 clang::PrintingPolicy PrintingPolicy;
439 IdentifierTable &Idents;
440 SelectorTable &Selectors;
441 Builtin::Context &BuiltinInfo;
442 mutable DeclarationNameTable DeclarationNames;
443 IntrusiveRefCntPtr<ExternalASTSource> ExternalSource;
444 ASTMutationListener *Listener;
446 /// \brief Contains parents of a node.
447 typedef llvm::SmallVector<ast_type_traits::DynTypedNode, 2> ParentVector;
449 /// \brief Maps from a node to its parents.
450 typedef llvm::DenseMap<const void *,
451 llvm::PointerUnion<ast_type_traits::DynTypedNode *,
452 ParentVector *>> ParentMap;
454 /// \brief Returns the parents of the given node.
456 /// Note that this will lazily compute the parents of all nodes
457 /// and store them for later retrieval. Thus, the first call is O(n)
458 /// in the number of AST nodes.
460 /// Caveats and FIXMEs:
461 /// Calculating the parent map over all AST nodes will need to load the
462 /// full AST. This can be undesirable in the case where the full AST is
463 /// expensive to create (for example, when using precompiled header
464 /// preambles). Thus, there are good opportunities for optimization here.
465 /// One idea is to walk the given node downwards, looking for references
466 /// to declaration contexts - once a declaration context is found, compute
467 /// the parent map for the declaration context; if that can satisfy the
468 /// request, loading the whole AST can be avoided. Note that this is made
469 /// more complex by statements in templates having multiple parents - those
470 /// problems can be solved by building closure over the templated parts of
471 /// the AST, which also avoids touching large parts of the AST.
472 /// Additionally, we will want to add an interface to already give a hint
473 /// where to search for the parents, for example when looking at a statement
474 /// inside a certain function.
476 /// 'NodeT' can be one of Decl, Stmt, Type, TypeLoc,
477 /// NestedNameSpecifier or NestedNameSpecifierLoc.
478 template <typename NodeT>
479 ArrayRef<ast_type_traits::DynTypedNode> getParents(const NodeT &Node) {
480 return getParents(ast_type_traits::DynTypedNode::create(Node));
483 ArrayRef<ast_type_traits::DynTypedNode>
484 getParents(const ast_type_traits::DynTypedNode &Node);
486 const clang::PrintingPolicy &getPrintingPolicy() const {
487 return PrintingPolicy;
490 void setPrintingPolicy(const clang::PrintingPolicy &Policy) {
491 PrintingPolicy = Policy;
494 SourceManager& getSourceManager() { return SourceMgr; }
495 const SourceManager& getSourceManager() const { return SourceMgr; }
497 llvm::BumpPtrAllocator &getAllocator() const {
501 void *Allocate(size_t Size, unsigned Align = 8) const {
502 return BumpAlloc.Allocate(Size, Align);
504 void Deallocate(void *Ptr) const { }
506 /// Return the total amount of physical memory allocated for representing
507 /// AST nodes and type information.
508 size_t getASTAllocatedMemory() const {
509 return BumpAlloc.getTotalMemory();
511 /// Return the total memory used for various side tables.
512 size_t getSideTableAllocatedMemory() const;
514 PartialDiagnostic::StorageAllocator &getDiagAllocator() {
515 return DiagAllocator;
518 const TargetInfo &getTargetInfo() const { return *Target; }
520 /// getIntTypeForBitwidth -
521 /// sets integer QualTy according to specified details:
522 /// bitwidth, signed/unsigned.
523 /// Returns empty type if there is no appropriate target types.
524 QualType getIntTypeForBitwidth(unsigned DestWidth,
525 unsigned Signed) const;
526 /// getRealTypeForBitwidth -
527 /// sets floating point QualTy according to specified bitwidth.
528 /// Returns empty type if there is no appropriate target types.
529 QualType getRealTypeForBitwidth(unsigned DestWidth) const;
531 bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const;
533 const LangOptions& getLangOpts() const { return LangOpts; }
535 const SanitizerBlacklist &getSanitizerBlacklist() const {
539 DiagnosticsEngine &getDiagnostics() const;
541 FullSourceLoc getFullLoc(SourceLocation Loc) const {
542 return FullSourceLoc(Loc,SourceMgr);
545 /// \brief All comments in this translation unit.
546 RawCommentList Comments;
548 /// \brief True if comments are already loaded from ExternalASTSource.
549 mutable bool CommentsLoaded;
551 class RawCommentAndCacheFlags {
554 /// We searched for a comment attached to the particular declaration, but
560 /// We have found a comment attached to this particular declaration.
565 /// This declaration does not have an attached comment, and we have
566 /// searched the redeclaration chain.
568 /// If getRaw() == 0, the whole redeclaration chain does not have any
571 /// If getRaw() != 0, it is a comment propagated from other
576 Kind getKind() const LLVM_READONLY {
577 return Data.getInt();
580 void setKind(Kind K) {
584 const RawComment *getRaw() const LLVM_READONLY {
585 return Data.getPointer();
588 void setRaw(const RawComment *RC) {
592 const Decl *getOriginalDecl() const LLVM_READONLY {
596 void setOriginalDecl(const Decl *Orig) {
601 llvm::PointerIntPair<const RawComment *, 2, Kind> Data;
602 const Decl *OriginalDecl;
605 /// \brief Mapping from declarations to comments attached to any
608 /// Raw comments are owned by Comments list. This mapping is populated
610 mutable llvm::DenseMap<const Decl *, RawCommentAndCacheFlags> RedeclComments;
612 /// \brief Mapping from declarations to parsed comments attached to any
614 mutable llvm::DenseMap<const Decl *, comments::FullComment *> ParsedComments;
616 /// \brief Return the documentation comment attached to a given declaration,
617 /// without looking into cache.
618 RawComment *getRawCommentForDeclNoCache(const Decl *D) const;
621 RawCommentList &getRawCommentList() {
625 void addComment(const RawComment &RC) {
626 assert(LangOpts.RetainCommentsFromSystemHeaders ||
627 !SourceMgr.isInSystemHeader(RC.getSourceRange().getBegin()));
628 Comments.addComment(RC, BumpAlloc);
631 /// \brief Return the documentation comment attached to a given declaration.
632 /// Returns NULL if no comment is attached.
634 /// \param OriginalDecl if not NULL, is set to declaration AST node that had
635 /// the comment, if the comment we found comes from a redeclaration.
637 getRawCommentForAnyRedecl(const Decl *D,
638 const Decl **OriginalDecl = nullptr) const;
640 /// Return parsed documentation comment attached to a given declaration.
641 /// Returns NULL if no comment is attached.
643 /// \param PP the Preprocessor used with this TU. Could be NULL if
644 /// preprocessor is not available.
645 comments::FullComment *getCommentForDecl(const Decl *D,
646 const Preprocessor *PP) const;
648 /// Return parsed documentation comment attached to a given declaration.
649 /// Returns NULL if no comment is attached. Does not look at any
650 /// redeclarations of the declaration.
651 comments::FullComment *getLocalCommentForDeclUncached(const Decl *D) const;
653 comments::FullComment *cloneFullComment(comments::FullComment *FC,
654 const Decl *D) const;
657 mutable comments::CommandTraits CommentCommandTraits;
659 /// \brief Iterator that visits import declarations.
660 class import_iterator {
664 typedef ImportDecl *value_type;
665 typedef ImportDecl *reference;
666 typedef ImportDecl *pointer;
667 typedef int difference_type;
668 typedef std::forward_iterator_tag iterator_category;
670 import_iterator() : Import() {}
671 explicit import_iterator(ImportDecl *Import) : Import(Import) {}
673 reference operator*() const { return Import; }
674 pointer operator->() const { return Import; }
676 import_iterator &operator++() {
677 Import = ASTContext::getNextLocalImport(Import);
681 import_iterator operator++(int) {
682 import_iterator Other(*this);
687 friend bool operator==(import_iterator X, import_iterator Y) {
688 return X.Import == Y.Import;
691 friend bool operator!=(import_iterator X, import_iterator Y) {
692 return X.Import != Y.Import;
697 comments::CommandTraits &getCommentCommandTraits() const {
698 return CommentCommandTraits;
701 /// \brief Retrieve the attributes for the given declaration.
702 AttrVec& getDeclAttrs(const Decl *D);
704 /// \brief Erase the attributes corresponding to the given declaration.
705 void eraseDeclAttrs(const Decl *D);
707 /// \brief If this variable is an instantiated static data member of a
708 /// class template specialization, returns the templated static data member
709 /// from which it was instantiated.
711 MemberSpecializationInfo *getInstantiatedFromStaticDataMember(
714 TemplateOrSpecializationInfo
715 getTemplateOrSpecializationInfo(const VarDecl *Var);
717 FunctionDecl *getClassScopeSpecializationPattern(const FunctionDecl *FD);
719 void setClassScopeSpecializationPattern(FunctionDecl *FD,
720 FunctionDecl *Pattern);
722 /// \brief Note that the static data member \p Inst is an instantiation of
723 /// the static data member template \p Tmpl of a class template.
724 void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
725 TemplateSpecializationKind TSK,
726 SourceLocation PointOfInstantiation = SourceLocation());
728 void setTemplateOrSpecializationInfo(VarDecl *Inst,
729 TemplateOrSpecializationInfo TSI);
731 /// \brief If the given using decl \p Inst is an instantiation of a
732 /// (possibly unresolved) using decl from a template instantiation,
734 NamedDecl *getInstantiatedFromUsingDecl(UsingDecl *Inst);
736 /// \brief Remember that the using decl \p Inst is an instantiation
737 /// of the using decl \p Pattern of a class template.
738 void setInstantiatedFromUsingDecl(UsingDecl *Inst, NamedDecl *Pattern);
740 void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst,
741 UsingShadowDecl *Pattern);
742 UsingShadowDecl *getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst);
744 FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
746 void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
748 // Access to the set of methods overridden by the given C++ method.
749 typedef CXXMethodVector::const_iterator overridden_cxx_method_iterator;
750 overridden_cxx_method_iterator
751 overridden_methods_begin(const CXXMethodDecl *Method) const;
753 overridden_cxx_method_iterator
754 overridden_methods_end(const CXXMethodDecl *Method) const;
756 unsigned overridden_methods_size(const CXXMethodDecl *Method) const;
758 /// \brief Note that the given C++ \p Method overrides the given \p
759 /// Overridden method.
760 void addOverriddenMethod(const CXXMethodDecl *Method,
761 const CXXMethodDecl *Overridden);
763 /// \brief Return C++ or ObjC overridden methods for the given \p Method.
765 /// An ObjC method is considered to override any method in the class's
766 /// base classes, its protocols, or its categories' protocols, that has
767 /// the same selector and is of the same kind (class or instance).
768 /// A method in an implementation is not considered as overriding the same
769 /// method in the interface or its categories.
770 void getOverriddenMethods(
771 const NamedDecl *Method,
772 SmallVectorImpl<const NamedDecl *> &Overridden) const;
774 /// \brief Notify the AST context that a new import declaration has been
775 /// parsed or implicitly created within this translation unit.
776 void addedLocalImportDecl(ImportDecl *Import);
778 static ImportDecl *getNextLocalImport(ImportDecl *Import) {
779 return Import->NextLocalImport;
782 typedef llvm::iterator_range<import_iterator> import_range;
783 import_range local_imports() const {
784 return import_range(import_iterator(FirstLocalImport), import_iterator());
787 Decl *getPrimaryMergedDecl(Decl *D) {
788 Decl *Result = MergedDecls.lookup(D);
789 return Result ? Result : D;
791 void setPrimaryMergedDecl(Decl *D, Decl *Primary) {
792 MergedDecls[D] = Primary;
795 /// \brief Note that the definition \p ND has been merged into module \p M,
796 /// and should be visible whenever \p M is visible.
797 void mergeDefinitionIntoModule(NamedDecl *ND, Module *M,
798 bool NotifyListeners = true);
799 /// \brief Clean up the merged definition list. Call this if you might have
800 /// added duplicates into the list.
801 void deduplicateMergedDefinitonsFor(NamedDecl *ND);
803 /// \brief Get the additional modules in which the definition \p Def has
805 ArrayRef<Module*> getModulesWithMergedDefinition(NamedDecl *Def) {
806 auto MergedIt = MergedDefModules.find(Def);
807 if (MergedIt == MergedDefModules.end())
809 return MergedIt->second;
812 TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
814 ExternCContextDecl *getExternCContextDecl() const;
820 CanQualType WCharTy; // [C++ 3.9.1p5].
821 CanQualType WideCharTy; // Same as WCharTy in C++, integer type in C99.
822 CanQualType WIntTy; // [C99 7.24.1], integer type unchanged by default promotions.
823 CanQualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
824 CanQualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
825 CanQualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
826 CanQualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
827 CanQualType UnsignedLongLongTy, UnsignedInt128Ty;
828 CanQualType FloatTy, DoubleTy, LongDoubleTy;
829 CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
830 CanQualType FloatComplexTy, DoubleComplexTy, LongDoubleComplexTy;
831 CanQualType VoidPtrTy, NullPtrTy;
832 CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
833 CanQualType BuiltinFnTy;
834 CanQualType PseudoObjectTy, ARCUnbridgedCastTy;
835 CanQualType ObjCBuiltinIdTy, ObjCBuiltinClassTy, ObjCBuiltinSelTy;
836 CanQualType ObjCBuiltinBoolTy;
837 CanQualType OCLImage1dTy, OCLImage1dArrayTy, OCLImage1dBufferTy;
838 CanQualType OCLImage2dTy, OCLImage2dArrayTy;
839 CanQualType OCLImage3dTy;
840 CanQualType OCLSamplerTy, OCLEventTy;
842 // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
843 mutable QualType AutoDeductTy; // Deduction against 'auto'.
844 mutable QualType AutoRRefDeductTy; // Deduction against 'auto &&'.
846 // Type used to help define __builtin_va_list for some targets.
847 // The type is built when constructing 'BuiltinVaListDecl'.
848 mutable QualType VaListTagTy;
850 ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents,
851 SelectorTable &sels, Builtin::Context &builtins);
855 /// \brief Attach an external AST source to the AST context.
857 /// The external AST source provides the ability to load parts of
858 /// the abstract syntax tree as needed from some external storage,
859 /// e.g., a precompiled header.
860 void setExternalSource(IntrusiveRefCntPtr<ExternalASTSource> Source);
862 /// \brief Retrieve a pointer to the external AST source associated
863 /// with this AST context, if any.
864 ExternalASTSource *getExternalSource() const {
865 return ExternalSource.get();
868 /// \brief Attach an AST mutation listener to the AST context.
870 /// The AST mutation listener provides the ability to track modifications to
871 /// the abstract syntax tree entities committed after they were initially
873 void setASTMutationListener(ASTMutationListener *Listener) {
874 this->Listener = Listener;
877 /// \brief Retrieve a pointer to the AST mutation listener associated
878 /// with this AST context, if any.
879 ASTMutationListener *getASTMutationListener() const { return Listener; }
881 void PrintStats() const;
882 const SmallVectorImpl<Type *>& getTypes() const { return Types; }
884 /// \brief Create a new implicit TU-level CXXRecordDecl or RecordDecl
886 RecordDecl *buildImplicitRecord(StringRef Name,
887 RecordDecl::TagKind TK = TTK_Struct) const;
889 /// \brief Create a new implicit TU-level typedef declaration.
890 TypedefDecl *buildImplicitTypedef(QualType T, StringRef Name) const;
892 /// \brief Retrieve the declaration for the 128-bit signed integer type.
893 TypedefDecl *getInt128Decl() const;
895 /// \brief Retrieve the declaration for the 128-bit unsigned integer type.
896 TypedefDecl *getUInt128Decl() const;
898 /// \brief Retrieve the declaration for a 128-bit float stub type.
899 TypeDecl *getFloat128StubType() const;
901 //===--------------------------------------------------------------------===//
903 //===--------------------------------------------------------------------===//
906 /// \brief Return a type with extended qualifiers.
907 QualType getExtQualType(const Type *Base, Qualifiers Quals) const;
909 QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
912 /// \brief Return the uniqued reference to the type for an address space
913 /// qualified type with the specified type and address space.
915 /// The resulting type has a union of the qualifiers from T and the address
916 /// space. If T already has an address space specifier, it is silently
918 QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace) const;
920 /// \brief Return the uniqued reference to the type for an Objective-C
921 /// gc-qualified type.
923 /// The retulting type has a union of the qualifiers from T and the gc
925 QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
927 /// \brief Return the uniqued reference to the type for a \c restrict
930 /// The resulting type has a union of the qualifiers from \p T and
932 QualType getRestrictType(QualType T) const {
933 return T.withFastQualifiers(Qualifiers::Restrict);
936 /// \brief Return the uniqued reference to the type for a \c volatile
939 /// The resulting type has a union of the qualifiers from \p T and
941 QualType getVolatileType(QualType T) const {
942 return T.withFastQualifiers(Qualifiers::Volatile);
945 /// \brief Return the uniqued reference to the type for a \c const
948 /// The resulting type has a union of the qualifiers from \p T and \c const.
950 /// It can be reasonably expected that this will always be equivalent to
951 /// calling T.withConst().
952 QualType getConstType(QualType T) const { return T.withConst(); }
954 /// \brief Change the ExtInfo on a function type.
955 const FunctionType *adjustFunctionType(const FunctionType *Fn,
956 FunctionType::ExtInfo EInfo);
958 /// \brief Change the result type of a function type once it is deduced.
959 void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
961 /// \brief Change the exception specification on a function once it is
962 /// delay-parsed, instantiated, or computed.
963 void adjustExceptionSpec(FunctionDecl *FD,
964 const FunctionProtoType::ExceptionSpecInfo &ESI,
965 bool AsWritten = false);
967 /// \brief Return the uniqued reference to the type for a complex
968 /// number with the specified element type.
969 QualType getComplexType(QualType T) const;
970 CanQualType getComplexType(CanQualType T) const {
971 return CanQualType::CreateUnsafe(getComplexType((QualType) T));
974 /// \brief Return the uniqued reference to the type for a pointer to
975 /// the specified type.
976 QualType getPointerType(QualType T) const;
977 CanQualType getPointerType(CanQualType T) const {
978 return CanQualType::CreateUnsafe(getPointerType((QualType) T));
981 /// \brief Return the uniqued reference to a type adjusted from the original
982 /// type to a new type.
983 QualType getAdjustedType(QualType Orig, QualType New) const;
984 CanQualType getAdjustedType(CanQualType Orig, CanQualType New) const {
985 return CanQualType::CreateUnsafe(
986 getAdjustedType((QualType)Orig, (QualType)New));
989 /// \brief Return the uniqued reference to the decayed version of the given
990 /// type. Can only be called on array and function types which decay to
992 QualType getDecayedType(QualType T) const;
993 CanQualType getDecayedType(CanQualType T) const {
994 return CanQualType::CreateUnsafe(getDecayedType((QualType) T));
997 /// \brief Return the uniqued reference to the atomic type for the specified
999 QualType getAtomicType(QualType T) const;
1001 /// \brief Return the uniqued reference to the type for a block of the
1003 QualType getBlockPointerType(QualType T) const;
1005 /// Gets the struct used to keep track of the descriptor for pointer to
1007 QualType getBlockDescriptorType() const;
1009 /// Gets the struct used to keep track of the extended descriptor for
1010 /// pointer to blocks.
1011 QualType getBlockDescriptorExtendedType() const;
1013 void setcudaConfigureCallDecl(FunctionDecl *FD) {
1014 cudaConfigureCallDecl = FD;
1016 FunctionDecl *getcudaConfigureCallDecl() {
1017 return cudaConfigureCallDecl;
1020 /// Returns true iff we need copy/dispose helpers for the given type.
1021 bool BlockRequiresCopying(QualType Ty, const VarDecl *D);
1024 /// Returns true, if given type has a known lifetime. HasByrefExtendedLayout is set
1025 /// to false in this case. If HasByrefExtendedLayout returns true, byref variable
1026 /// has extended lifetime.
1027 bool getByrefLifetime(QualType Ty,
1028 Qualifiers::ObjCLifetime &Lifetime,
1029 bool &HasByrefExtendedLayout) const;
1031 /// \brief Return the uniqued reference to the type for an lvalue reference
1032 /// to the specified type.
1033 QualType getLValueReferenceType(QualType T, bool SpelledAsLValue = true)
1036 /// \brief Return the uniqued reference to the type for an rvalue reference
1037 /// to the specified type.
1038 QualType getRValueReferenceType(QualType T) const;
1040 /// \brief Return the uniqued reference to the type for a member pointer to
1041 /// the specified type in the specified class.
1043 /// The class \p Cls is a \c Type because it could be a dependent name.
1044 QualType getMemberPointerType(QualType T, const Type *Cls) const;
1046 /// \brief Return a non-unique reference to the type for a variable array of
1047 /// the specified element type.
1048 QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
1049 ArrayType::ArraySizeModifier ASM,
1050 unsigned IndexTypeQuals,
1051 SourceRange Brackets) const;
1053 /// \brief Return a non-unique reference to the type for a dependently-sized
1054 /// array of the specified element type.
1056 /// FIXME: We will need these to be uniqued, or at least comparable, at some
1058 QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
1059 ArrayType::ArraySizeModifier ASM,
1060 unsigned IndexTypeQuals,
1061 SourceRange Brackets) const;
1063 /// \brief Return a unique reference to the type for an incomplete array of
1064 /// the specified element type.
1065 QualType getIncompleteArrayType(QualType EltTy,
1066 ArrayType::ArraySizeModifier ASM,
1067 unsigned IndexTypeQuals) const;
1069 /// \brief Return the unique reference to the type for a constant array of
1070 /// the specified element type.
1071 QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
1072 ArrayType::ArraySizeModifier ASM,
1073 unsigned IndexTypeQuals) const;
1075 /// \brief Returns a vla type where known sizes are replaced with [*].
1076 QualType getVariableArrayDecayedType(QualType Ty) const;
1078 /// \brief Return the unique reference to a vector type of the specified
1079 /// element type and size.
1081 /// \pre \p VectorType must be a built-in type.
1082 QualType getVectorType(QualType VectorType, unsigned NumElts,
1083 VectorType::VectorKind VecKind) const;
1085 /// \brief Return the unique reference to an extended vector type
1086 /// of the specified element type and size.
1088 /// \pre \p VectorType must be a built-in type.
1089 QualType getExtVectorType(QualType VectorType, unsigned NumElts) const;
1091 /// \pre Return a non-unique reference to the type for a dependently-sized
1092 /// vector of the specified element type.
1094 /// FIXME: We will need these to be uniqued, or at least comparable, at some
1096 QualType getDependentSizedExtVectorType(QualType VectorType,
1098 SourceLocation AttrLoc) const;
1100 /// \brief Return a K&R style C function type like 'int()'.
1101 QualType getFunctionNoProtoType(QualType ResultTy,
1102 const FunctionType::ExtInfo &Info) const;
1104 QualType getFunctionNoProtoType(QualType ResultTy) const {
1105 return getFunctionNoProtoType(ResultTy, FunctionType::ExtInfo());
1108 /// \brief Return a normal function type with a typed argument list.
1109 QualType getFunctionType(QualType ResultTy, ArrayRef<QualType> Args,
1110 const FunctionProtoType::ExtProtoInfo &EPI) const;
1112 /// \brief Return the unique reference to the type for the specified type
1114 QualType getTypeDeclType(const TypeDecl *Decl,
1115 const TypeDecl *PrevDecl = nullptr) const {
1116 assert(Decl && "Passed null for Decl param");
1117 if (Decl->TypeForDecl) return QualType(Decl->TypeForDecl, 0);
1120 assert(PrevDecl->TypeForDecl && "previous decl has no TypeForDecl");
1121 Decl->TypeForDecl = PrevDecl->TypeForDecl;
1122 return QualType(PrevDecl->TypeForDecl, 0);
1125 return getTypeDeclTypeSlow(Decl);
1128 /// \brief Return the unique reference to the type for the specified
1129 /// typedef-name decl.
1130 QualType getTypedefType(const TypedefNameDecl *Decl,
1131 QualType Canon = QualType()) const;
1133 QualType getRecordType(const RecordDecl *Decl) const;
1135 QualType getEnumType(const EnumDecl *Decl) const;
1137 QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
1139 QualType getAttributedType(AttributedType::Kind attrKind,
1140 QualType modifiedType,
1141 QualType equivalentType);
1143 QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
1144 QualType Replacement) const;
1145 QualType getSubstTemplateTypeParmPackType(
1146 const TemplateTypeParmType *Replaced,
1147 const TemplateArgument &ArgPack);
1150 getTemplateTypeParmType(unsigned Depth, unsigned Index,
1152 TemplateTypeParmDecl *ParmDecl = nullptr) const;
1154 QualType getTemplateSpecializationType(TemplateName T,
1155 const TemplateArgument *Args,
1157 QualType Canon = QualType()) const;
1159 QualType getCanonicalTemplateSpecializationType(TemplateName T,
1160 const TemplateArgument *Args,
1161 unsigned NumArgs) const;
1163 QualType getTemplateSpecializationType(TemplateName T,
1164 const TemplateArgumentListInfo &Args,
1165 QualType Canon = QualType()) const;
1168 getTemplateSpecializationTypeInfo(TemplateName T, SourceLocation TLoc,
1169 const TemplateArgumentListInfo &Args,
1170 QualType Canon = QualType()) const;
1172 QualType getParenType(QualType NamedType) const;
1174 QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
1175 NestedNameSpecifier *NNS,
1176 QualType NamedType) const;
1177 QualType getDependentNameType(ElaboratedTypeKeyword Keyword,
1178 NestedNameSpecifier *NNS,
1179 const IdentifierInfo *Name,
1180 QualType Canon = QualType()) const;
1182 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
1183 NestedNameSpecifier *NNS,
1184 const IdentifierInfo *Name,
1185 const TemplateArgumentListInfo &Args) const;
1186 QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword,
1187 NestedNameSpecifier *NNS,
1188 const IdentifierInfo *Name,
1190 const TemplateArgument *Args) const;
1192 QualType getPackExpansionType(QualType Pattern,
1193 Optional<unsigned> NumExpansions);
1195 QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
1196 ObjCInterfaceDecl *PrevDecl = nullptr) const;
1198 /// Legacy interface: cannot provide type arguments or __kindof.
1199 QualType getObjCObjectType(QualType Base,
1200 ObjCProtocolDecl * const *Protocols,
1201 unsigned NumProtocols) const;
1203 QualType getObjCObjectType(QualType Base,
1204 ArrayRef<QualType> typeArgs,
1205 ArrayRef<ObjCProtocolDecl *> protocols,
1206 bool isKindOf) const;
1208 bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl);
1209 /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in
1210 /// QT's qualified-id protocol list adopt all protocols in IDecl's list
1212 bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT,
1213 ObjCInterfaceDecl *IDecl);
1215 /// \brief Return a ObjCObjectPointerType type for the given ObjCObjectType.
1216 QualType getObjCObjectPointerType(QualType OIT) const;
1218 /// \brief GCC extension.
1219 QualType getTypeOfExprType(Expr *e) const;
1220 QualType getTypeOfType(QualType t) const;
1222 /// \brief C++11 decltype.
1223 QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
1225 /// \brief Unary type transforms
1226 QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType,
1227 UnaryTransformType::UTTKind UKind) const;
1229 /// \brief C++11 deduced auto type.
1230 QualType getAutoType(QualType DeducedType, bool IsDecltypeAuto,
1231 bool IsDependent) const;
1233 /// \brief C++11 deduction pattern for 'auto' type.
1234 QualType getAutoDeductType() const;
1236 /// \brief C++11 deduction pattern for 'auto &&' type.
1237 QualType getAutoRRefDeductType() const;
1239 /// \brief Return the unique reference to the type for the specified TagDecl
1240 /// (struct/union/class/enum) decl.
1241 QualType getTagDeclType(const TagDecl *Decl) const;
1243 /// \brief Return the unique type for "size_t" (C99 7.17), defined in
1246 /// The sizeof operator requires this (C99 6.5.3.4p4).
1247 CanQualType getSizeType() const;
1249 /// \brief Return the unique type for "intmax_t" (C99 7.18.1.5), defined in
1251 CanQualType getIntMaxType() const;
1253 /// \brief Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in
1255 CanQualType getUIntMaxType() const;
1257 /// \brief Return the unique wchar_t type available in C++ (and available as
1258 /// __wchar_t as a Microsoft extension).
1259 QualType getWCharType() const { return WCharTy; }
1261 /// \brief Return the type of wide characters. In C++, this returns the
1262 /// unique wchar_t type. In C99, this returns a type compatible with the type
1263 /// defined in <stddef.h> as defined by the target.
1264 QualType getWideCharType() const { return WideCharTy; }
1266 /// \brief Return the type of "signed wchar_t".
1268 /// Used when in C++, as a GCC extension.
1269 QualType getSignedWCharType() const;
1271 /// \brief Return the type of "unsigned wchar_t".
1273 /// Used when in C++, as a GCC extension.
1274 QualType getUnsignedWCharType() const;
1276 /// \brief In C99, this returns a type compatible with the type
1277 /// defined in <stddef.h> as defined by the target.
1278 QualType getWIntType() const { return WIntTy; }
1280 /// \brief Return a type compatible with "intptr_t" (C99 7.18.1.4),
1281 /// as defined by the target.
1282 QualType getIntPtrType() const;
1284 /// \brief Return a type compatible with "uintptr_t" (C99 7.18.1.4),
1285 /// as defined by the target.
1286 QualType getUIntPtrType() const;
1288 /// \brief Return the unique type for "ptrdiff_t" (C99 7.17) defined in
1289 /// <stddef.h>. Pointer - pointer requires this (C99 6.5.6p9).
1290 QualType getPointerDiffType() const;
1292 /// \brief Return the unique type for "pid_t" defined in
1293 /// <sys/types.h>. We need this to compute the correct type for vfork().
1294 QualType getProcessIDType() const;
1296 /// \brief Return the C structure type used to represent constant CFStrings.
1297 QualType getCFConstantStringType() const;
1299 /// \brief Returns the C struct type for objc_super
1300 QualType getObjCSuperType() const;
1301 void setObjCSuperType(QualType ST) { ObjCSuperType = ST; }
1303 /// Get the structure type used to representation CFStrings, or NULL
1304 /// if it hasn't yet been built.
1305 QualType getRawCFConstantStringType() const {
1306 if (CFConstantStringTypeDecl)
1307 return getTagDeclType(CFConstantStringTypeDecl);
1310 void setCFConstantStringType(QualType T);
1312 // This setter/getter represents the ObjC type for an NSConstantString.
1313 void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
1314 QualType getObjCConstantStringInterface() const {
1315 return ObjCConstantStringType;
1318 QualType getObjCNSStringType() const {
1319 return ObjCNSStringType;
1322 void setObjCNSStringType(QualType T) {
1323 ObjCNSStringType = T;
1326 /// \brief Retrieve the type that \c id has been defined to, which may be
1327 /// different from the built-in \c id if \c id has been typedef'd.
1328 QualType getObjCIdRedefinitionType() const {
1329 if (ObjCIdRedefinitionType.isNull())
1330 return getObjCIdType();
1331 return ObjCIdRedefinitionType;
1334 /// \brief Set the user-written type that redefines \c id.
1335 void setObjCIdRedefinitionType(QualType RedefType) {
1336 ObjCIdRedefinitionType = RedefType;
1339 /// \brief Retrieve the type that \c Class has been defined to, which may be
1340 /// different from the built-in \c Class if \c Class has been typedef'd.
1341 QualType getObjCClassRedefinitionType() const {
1342 if (ObjCClassRedefinitionType.isNull())
1343 return getObjCClassType();
1344 return ObjCClassRedefinitionType;
1347 /// \brief Set the user-written type that redefines 'SEL'.
1348 void setObjCClassRedefinitionType(QualType RedefType) {
1349 ObjCClassRedefinitionType = RedefType;
1352 /// \brief Retrieve the type that 'SEL' has been defined to, which may be
1353 /// different from the built-in 'SEL' if 'SEL' has been typedef'd.
1354 QualType getObjCSelRedefinitionType() const {
1355 if (ObjCSelRedefinitionType.isNull())
1356 return getObjCSelType();
1357 return ObjCSelRedefinitionType;
1361 /// \brief Set the user-written type that redefines 'SEL'.
1362 void setObjCSelRedefinitionType(QualType RedefType) {
1363 ObjCSelRedefinitionType = RedefType;
1366 /// Retrieve the identifier 'NSObject'.
1367 IdentifierInfo *getNSObjectName() {
1368 if (!NSObjectName) {
1369 NSObjectName = &Idents.get("NSObject");
1372 return NSObjectName;
1375 /// Retrieve the identifier 'NSCopying'.
1376 IdentifierInfo *getNSCopyingName() {
1377 if (!NSCopyingName) {
1378 NSCopyingName = &Idents.get("NSCopying");
1381 return NSCopyingName;
1384 /// \brief Retrieve the Objective-C "instancetype" type, if already known;
1385 /// otherwise, returns a NULL type;
1386 QualType getObjCInstanceType() {
1387 return getTypeDeclType(getObjCInstanceTypeDecl());
1390 /// \brief Retrieve the typedef declaration corresponding to the Objective-C
1391 /// "instancetype" type.
1392 TypedefDecl *getObjCInstanceTypeDecl();
1394 /// \brief Set the type for the C FILE type.
1395 void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
1397 /// \brief Retrieve the C FILE type.
1398 QualType getFILEType() const {
1400 return getTypeDeclType(FILEDecl);
1404 /// \brief Set the type for the C jmp_buf type.
1405 void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
1406 this->jmp_bufDecl = jmp_bufDecl;
1409 /// \brief Retrieve the C jmp_buf type.
1410 QualType getjmp_bufType() const {
1412 return getTypeDeclType(jmp_bufDecl);
1416 /// \brief Set the type for the C sigjmp_buf type.
1417 void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
1418 this->sigjmp_bufDecl = sigjmp_bufDecl;
1421 /// \brief Retrieve the C sigjmp_buf type.
1422 QualType getsigjmp_bufType() const {
1424 return getTypeDeclType(sigjmp_bufDecl);
1428 /// \brief Set the type for the C ucontext_t type.
1429 void setucontext_tDecl(TypeDecl *ucontext_tDecl) {
1430 this->ucontext_tDecl = ucontext_tDecl;
1433 /// \brief Retrieve the C ucontext_t type.
1434 QualType getucontext_tType() const {
1436 return getTypeDeclType(ucontext_tDecl);
1440 /// \brief The result type of logical operations, '<', '>', '!=', etc.
1441 QualType getLogicalOperationType() const {
1442 return getLangOpts().CPlusPlus ? BoolTy : IntTy;
1445 /// \brief Emit the Objective-CC type encoding for the given type \p T into
1448 /// If \p Field is specified then record field names are also encoded.
1449 void getObjCEncodingForType(QualType T, std::string &S,
1450 const FieldDecl *Field=nullptr,
1451 QualType *NotEncodedT=nullptr) const;
1453 /// \brief Emit the Objective-C property type encoding for the given
1454 /// type \p T into \p S.
1455 void getObjCEncodingForPropertyType(QualType T, std::string &S) const;
1457 void getLegacyIntegralTypeEncoding(QualType &t) const;
1459 /// \brief Put the string version of the type qualifiers \p QT into \p S.
1460 void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
1461 std::string &S) const;
1463 /// \brief Emit the encoded type for the function \p Decl into \p S.
1465 /// This is in the same format as Objective-C method encodings.
1467 /// \returns true if an error occurred (e.g., because one of the parameter
1468 /// types is incomplete), false otherwise.
1469 bool getObjCEncodingForFunctionDecl(const FunctionDecl *Decl, std::string& S);
1471 /// \brief Emit the encoded type for the method declaration \p Decl into
1474 /// \returns true if an error occurred (e.g., because one of the parameter
1475 /// types is incomplete), false otherwise.
1476 bool getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S,
1477 bool Extended = false)
1480 /// \brief Return the encoded type for this block declaration.
1481 std::string getObjCEncodingForBlock(const BlockExpr *blockExpr) const;
1483 /// getObjCEncodingForPropertyDecl - Return the encoded type for
1484 /// this method declaration. If non-NULL, Container must be either
1485 /// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
1486 /// only be NULL when getting encodings for protocol properties.
1487 void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
1488 const Decl *Container,
1489 std::string &S) const;
1491 bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
1492 ObjCProtocolDecl *rProto) const;
1494 ObjCPropertyImplDecl *getObjCPropertyImplDeclForPropertyDecl(
1495 const ObjCPropertyDecl *PD,
1496 const Decl *Container) const;
1498 /// \brief Return the size of type \p T for Objective-C encoding purpose,
1500 CharUnits getObjCEncodingTypeSize(QualType T) const;
1502 /// \brief Retrieve the typedef corresponding to the predefined \c id type
1504 TypedefDecl *getObjCIdDecl() const;
1506 /// \brief Represents the Objective-CC \c id type.
1508 /// This is set up lazily, by Sema. \c id is always a (typedef for a)
1509 /// pointer type, a pointer to a struct.
1510 QualType getObjCIdType() const {
1511 return getTypeDeclType(getObjCIdDecl());
1514 /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type
1516 TypedefDecl *getObjCSelDecl() const;
1518 /// \brief Retrieve the type that corresponds to the predefined Objective-C
1520 QualType getObjCSelType() const {
1521 return getTypeDeclType(getObjCSelDecl());
1524 /// \brief Retrieve the typedef declaration corresponding to the predefined
1525 /// Objective-C 'Class' type.
1526 TypedefDecl *getObjCClassDecl() const;
1528 /// \brief Represents the Objective-C \c Class type.
1530 /// This is set up lazily, by Sema. \c Class is always a (typedef for a)
1531 /// pointer type, a pointer to a struct.
1532 QualType getObjCClassType() const {
1533 return getTypeDeclType(getObjCClassDecl());
1536 /// \brief Retrieve the Objective-C class declaration corresponding to
1537 /// the predefined \c Protocol class.
1538 ObjCInterfaceDecl *getObjCProtocolDecl() const;
1540 /// \brief Retrieve declaration of 'BOOL' typedef
1541 TypedefDecl *getBOOLDecl() const {
1545 /// \brief Save declaration of 'BOOL' typedef
1546 void setBOOLDecl(TypedefDecl *TD) {
1550 /// \brief type of 'BOOL' type.
1551 QualType getBOOLType() const {
1552 return getTypeDeclType(getBOOLDecl());
1555 /// \brief Retrieve the type of the Objective-C \c Protocol class.
1556 QualType getObjCProtoType() const {
1557 return getObjCInterfaceType(getObjCProtocolDecl());
1560 /// \brief Retrieve the C type declaration corresponding to the predefined
1561 /// \c __builtin_va_list type.
1562 TypedefDecl *getBuiltinVaListDecl() const;
1564 /// \brief Retrieve the type of the \c __builtin_va_list type.
1565 QualType getBuiltinVaListType() const {
1566 return getTypeDeclType(getBuiltinVaListDecl());
1569 /// \brief Retrieve the C type declaration corresponding to the predefined
1570 /// \c __va_list_tag type used to help define the \c __builtin_va_list type
1571 /// for some targets.
1572 QualType getVaListTagType() const;
1574 /// \brief Return a type with additional \c const, \c volatile, or
1575 /// \c restrict qualifiers.
1576 QualType getCVRQualifiedType(QualType T, unsigned CVR) const {
1577 return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
1580 /// \brief Un-split a SplitQualType.
1581 QualType getQualifiedType(SplitQualType split) const {
1582 return getQualifiedType(split.Ty, split.Quals);
1585 /// \brief Return a type with additional qualifiers.
1586 QualType getQualifiedType(QualType T, Qualifiers Qs) const {
1587 if (!Qs.hasNonFastQualifiers())
1588 return T.withFastQualifiers(Qs.getFastQualifiers());
1589 QualifierCollector Qc(Qs);
1590 const Type *Ptr = Qc.strip(T);
1591 return getExtQualType(Ptr, Qc);
1594 /// \brief Return a type with additional qualifiers.
1595 QualType getQualifiedType(const Type *T, Qualifiers Qs) const {
1596 if (!Qs.hasNonFastQualifiers())
1597 return QualType(T, Qs.getFastQualifiers());
1598 return getExtQualType(T, Qs);
1601 /// \brief Return a type with the given lifetime qualifier.
1603 /// \pre Neither type.ObjCLifetime() nor \p lifetime may be \c OCL_None.
1604 QualType getLifetimeQualifiedType(QualType type,
1605 Qualifiers::ObjCLifetime lifetime) {
1606 assert(type.getObjCLifetime() == Qualifiers::OCL_None);
1607 assert(lifetime != Qualifiers::OCL_None);
1610 qs.addObjCLifetime(lifetime);
1611 return getQualifiedType(type, qs);
1614 /// getUnqualifiedObjCPointerType - Returns version of
1615 /// Objective-C pointer type with lifetime qualifier removed.
1616 QualType getUnqualifiedObjCPointerType(QualType type) const {
1617 if (!type.getTypePtr()->isObjCObjectPointerType() ||
1618 !type.getQualifiers().hasObjCLifetime())
1620 Qualifiers Qs = type.getQualifiers();
1621 Qs.removeObjCLifetime();
1622 return getQualifiedType(type.getUnqualifiedType(), Qs);
1625 DeclarationNameInfo getNameForTemplate(TemplateName Name,
1626 SourceLocation NameLoc) const;
1628 TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin,
1629 UnresolvedSetIterator End) const;
1631 TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
1632 bool TemplateKeyword,
1633 TemplateDecl *Template) const;
1635 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1636 const IdentifierInfo *Name) const;
1637 TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
1638 OverloadedOperatorKind Operator) const;
1639 TemplateName getSubstTemplateTemplateParm(TemplateTemplateParmDecl *param,
1640 TemplateName replacement) const;
1641 TemplateName getSubstTemplateTemplateParmPack(TemplateTemplateParmDecl *Param,
1642 const TemplateArgument &ArgPack) const;
1644 enum GetBuiltinTypeError {
1645 GE_None, ///< No error
1646 GE_Missing_stdio, ///< Missing a type from <stdio.h>
1647 GE_Missing_setjmp, ///< Missing a type from <setjmp.h>
1648 GE_Missing_ucontext ///< Missing a type from <ucontext.h>
1651 /// \brief Return the type for the specified builtin.
1653 /// If \p IntegerConstantArgs is non-null, it is filled in with a bitmask of
1654 /// arguments to the builtin that are required to be integer constant
1656 QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
1657 unsigned *IntegerConstantArgs = nullptr) const;
1660 CanQualType getFromTargetType(unsigned Type) const;
1661 TypeInfo getTypeInfoImpl(const Type *T) const;
1663 //===--------------------------------------------------------------------===//
1665 //===--------------------------------------------------------------------===//
1668 /// \brief Return one of the GCNone, Weak or Strong Objective-C garbage
1669 /// collection attributes.
1670 Qualifiers::GC getObjCGCAttrKind(QualType Ty) const;
1672 /// \brief Return true if the given vector types are of the same unqualified
1673 /// type or if they are equivalent to the same GCC vector type.
1675 /// \note This ignores whether they are target-specific (AltiVec or Neon)
1677 bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
1679 /// \brief Return true if this is an \c NSObject object with its \c NSObject
1681 static bool isObjCNSObjectType(QualType Ty) {
1682 return Ty->isObjCNSObjectType();
1685 //===--------------------------------------------------------------------===//
1686 // Type Sizing and Analysis
1687 //===--------------------------------------------------------------------===//
1689 /// \brief Return the APFloat 'semantics' for the specified scalar floating
1691 const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
1693 /// \brief Get the size and alignment of the specified complete type in bits.
1694 TypeInfo getTypeInfo(const Type *T) const;
1695 TypeInfo getTypeInfo(QualType T) const { return getTypeInfo(T.getTypePtr()); }
1697 /// \brief Get default simd alignment of the specified complete type in bits.
1698 unsigned getOpenMPDefaultSimdAlign(QualType T) const;
1700 /// \brief Return the size of the specified (complete) type \p T, in bits.
1701 uint64_t getTypeSize(QualType T) const { return getTypeInfo(T).Width; }
1702 uint64_t getTypeSize(const Type *T) const { return getTypeInfo(T).Width; }
1704 /// \brief Return the size of the character type, in bits.
1705 uint64_t getCharWidth() const {
1706 return getTypeSize(CharTy);
1709 /// \brief Convert a size in bits to a size in characters.
1710 CharUnits toCharUnitsFromBits(int64_t BitSize) const;
1712 /// \brief Convert a size in characters to a size in bits.
1713 int64_t toBits(CharUnits CharSize) const;
1715 /// \brief Return the size of the specified (complete) type \p T, in
1717 CharUnits getTypeSizeInChars(QualType T) const;
1718 CharUnits getTypeSizeInChars(const Type *T) const;
1720 /// \brief Return the ABI-specified alignment of a (complete) type \p T, in
1722 unsigned getTypeAlign(QualType T) const { return getTypeInfo(T).Align; }
1723 unsigned getTypeAlign(const Type *T) const { return getTypeInfo(T).Align; }
1725 /// \brief Return the ABI-specified alignment of a (complete) type \p T, in
1727 CharUnits getTypeAlignInChars(QualType T) const;
1728 CharUnits getTypeAlignInChars(const Type *T) const;
1730 // getTypeInfoDataSizeInChars - Return the size of a type, in chars. If the
1731 // type is a record, its data size is returned.
1732 std::pair<CharUnits, CharUnits> getTypeInfoDataSizeInChars(QualType T) const;
1734 std::pair<CharUnits, CharUnits> getTypeInfoInChars(const Type *T) const;
1735 std::pair<CharUnits, CharUnits> getTypeInfoInChars(QualType T) const;
1737 /// \brief Determine if the alignment the type has was required using an
1738 /// alignment attribute.
1739 bool isAlignmentRequired(const Type *T) const;
1740 bool isAlignmentRequired(QualType T) const;
1742 /// \brief Return the "preferred" alignment of the specified type \p T for
1743 /// the current target, in bits.
1745 /// This can be different than the ABI alignment in cases where it is
1746 /// beneficial for performance to overalign a data type.
1747 unsigned getPreferredTypeAlign(const Type *T) const;
1749 /// \brief Return the default alignment for __attribute__((aligned)) on
1750 /// this target, to be used if no alignment value is specified.
1751 unsigned getTargetDefaultAlignForAttributeAligned(void) const;
1753 /// \brief Return the alignment in bits that should be given to a
1754 /// global variable with type \p T.
1755 unsigned getAlignOfGlobalVar(QualType T) const;
1757 /// \brief Return the alignment in characters that should be given to a
1758 /// global variable with type \p T.
1759 CharUnits getAlignOfGlobalVarInChars(QualType T) const;
1761 /// \brief Return a conservative estimate of the alignment of the specified
1764 /// \pre \p D must not be a bitfield type, as bitfields do not have a valid
1767 /// If \p ForAlignof, references are treated like their underlying type
1768 /// and large arrays don't get any special treatment. If not \p ForAlignof
1769 /// it computes the value expected by CodeGen: references are treated like
1770 /// pointers and large arrays get extra alignment.
1771 CharUnits getDeclAlign(const Decl *D, bool ForAlignof = false) const;
1773 /// \brief Get or compute information about the layout of the specified
1774 /// record (struct/union/class) \p D, which indicates its size and field
1775 /// position information.
1776 const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D) const;
1777 const ASTRecordLayout *BuildMicrosoftASTRecordLayout(const RecordDecl *D) const;
1779 /// \brief Get or compute information about the layout of the specified
1780 /// Objective-C interface.
1781 const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D)
1784 void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
1785 bool Simple = false) const;
1787 /// \brief Get or compute information about the layout of the specified
1788 /// Objective-C implementation.
1790 /// This may differ from the interface if synthesized ivars are present.
1791 const ASTRecordLayout &
1792 getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
1794 /// \brief Get our current best idea for the key function of the
1795 /// given record decl, or NULL if there isn't one.
1797 /// The key function is, according to the Itanium C++ ABI section 5.2.3:
1798 /// ...the first non-pure virtual function that is not inline at the
1799 /// point of class definition.
1801 /// Other ABIs use the same idea. However, the ARM C++ ABI ignores
1802 /// virtual functions that are defined 'inline', which means that
1803 /// the result of this computation can change.
1804 const CXXMethodDecl *getCurrentKeyFunction(const CXXRecordDecl *RD);
1806 /// \brief Observe that the given method cannot be a key function.
1807 /// Checks the key-function cache for the method's class and clears it
1808 /// if matches the given declaration.
1810 /// This is used in ABIs where out-of-line definitions marked
1811 /// inline are not considered to be key functions.
1813 /// \param method should be the declaration from the class definition
1814 void setNonKeyFunction(const CXXMethodDecl *method);
1816 /// Loading virtual member pointers using the virtual inheritance model
1817 /// always results in an adjustment using the vbtable even if the index is
1820 /// This is usually OK because the first slot in the vbtable points
1821 /// backwards to the top of the MDC. However, the MDC might be reusing a
1822 /// vbptr from an nv-base. In this case, the first slot in the vbtable
1823 /// points to the start of the nv-base which introduced the vbptr and *not*
1824 /// the MDC. Modify the NonVirtualBaseAdjustment to account for this.
1825 CharUnits getOffsetOfBaseWithVBPtr(const CXXRecordDecl *RD) const;
1827 /// Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
1828 uint64_t getFieldOffset(const ValueDecl *FD) const;
1830 bool isNearlyEmpty(const CXXRecordDecl *RD) const;
1832 VTableContextBase *getVTableContext();
1834 MangleContext *createMangleContext();
1836 void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass,
1837 SmallVectorImpl<const ObjCIvarDecl*> &Ivars) const;
1839 unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const;
1840 void CollectInheritedProtocols(const Decl *CDecl,
1841 llvm::SmallPtrSet<ObjCProtocolDecl*, 8> &Protocols);
1843 //===--------------------------------------------------------------------===//
1845 //===--------------------------------------------------------------------===//
1847 /// \brief Return the canonical (structural) type corresponding to the
1848 /// specified potentially non-canonical type \p T.
1850 /// The non-canonical version of a type may have many "decorated" versions of
1851 /// types. Decorators can include typedefs, 'typeof' operators, etc. The
1852 /// returned type is guaranteed to be free of any of these, allowing two
1853 /// canonical types to be compared for exact equality with a simple pointer
1855 CanQualType getCanonicalType(QualType T) const {
1856 return CanQualType::CreateUnsafe(T.getCanonicalType());
1859 const Type *getCanonicalType(const Type *T) const {
1860 return T->getCanonicalTypeInternal().getTypePtr();
1863 /// \brief Return the canonical parameter type corresponding to the specific
1864 /// potentially non-canonical one.
1866 /// Qualifiers are stripped off, functions are turned into function
1867 /// pointers, and arrays decay one level into pointers.
1868 CanQualType getCanonicalParamType(QualType T) const;
1870 /// \brief Determine whether the given types \p T1 and \p T2 are equivalent.
1871 bool hasSameType(QualType T1, QualType T2) const {
1872 return getCanonicalType(T1) == getCanonicalType(T2);
1875 bool hasSameType(const Type *T1, const Type *T2) const {
1876 return getCanonicalType(T1) == getCanonicalType(T2);
1879 /// \brief Return this type as a completely-unqualified array type,
1880 /// capturing the qualifiers in \p Quals.
1882 /// This will remove the minimal amount of sugaring from the types, similar
1883 /// to the behavior of QualType::getUnqualifiedType().
1885 /// \param T is the qualified type, which may be an ArrayType
1887 /// \param Quals will receive the full set of qualifiers that were
1888 /// applied to the array.
1890 /// \returns if this is an array type, the completely unqualified array type
1891 /// that corresponds to it. Otherwise, returns T.getUnqualifiedType().
1892 QualType getUnqualifiedArrayType(QualType T, Qualifiers &Quals);
1894 /// \brief Determine whether the given types are equivalent after
1895 /// cvr-qualifiers have been removed.
1896 bool hasSameUnqualifiedType(QualType T1, QualType T2) const {
1897 return getCanonicalType(T1).getTypePtr() ==
1898 getCanonicalType(T2).getTypePtr();
1901 bool hasSameNullabilityTypeQualifier(QualType SubT, QualType SuperT,
1902 bool IsParam) const {
1903 auto SubTnullability = SubT->getNullability(*this);
1904 auto SuperTnullability = SuperT->getNullability(*this);
1905 if (SubTnullability.hasValue() == SuperTnullability.hasValue()) {
1906 // Neither has nullability; return true
1907 if (!SubTnullability)
1909 // Both have nullability qualifier.
1910 if (*SubTnullability == *SuperTnullability ||
1911 *SubTnullability == NullabilityKind::Unspecified ||
1912 *SuperTnullability == NullabilityKind::Unspecified)
1916 // Ok for the superclass method parameter to be "nonnull" and the subclass
1917 // method parameter to be "nullable"
1918 return (*SuperTnullability == NullabilityKind::NonNull &&
1919 *SubTnullability == NullabilityKind::Nullable);
1922 // For the return type, it's okay for the superclass method to specify
1923 // "nullable" and the subclass method specify "nonnull"
1924 return (*SuperTnullability == NullabilityKind::Nullable &&
1925 *SubTnullability == NullabilityKind::NonNull);
1931 bool ObjCMethodsAreEqual(const ObjCMethodDecl *MethodDecl,
1932 const ObjCMethodDecl *MethodImp);
1934 bool UnwrapSimilarPointerTypes(QualType &T1, QualType &T2);
1936 /// \brief Retrieves the "canonical" nested name specifier for a
1937 /// given nested name specifier.
1939 /// The canonical nested name specifier is a nested name specifier
1940 /// that uniquely identifies a type or namespace within the type
1941 /// system. For example, given:
1946 /// template<typename T> struct X { typename T* type; };
1950 /// template<typename T> struct Y {
1951 /// typename N::S::X<T>::type member;
1955 /// Here, the nested-name-specifier for N::S::X<T>:: will be
1956 /// S::X<template-param-0-0>, since 'S' and 'X' are uniquely defined
1957 /// by declarations in the type system and the canonical type for
1958 /// the template type parameter 'T' is template-param-0-0.
1959 NestedNameSpecifier *
1960 getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
1962 /// \brief Retrieves the default calling convention for the current target.
1963 CallingConv getDefaultCallingConvention(bool isVariadic,
1964 bool IsCXXMethod) const;
1966 /// \brief Retrieves the "canonical" template name that refers to a
1969 /// The canonical template name is the simplest expression that can
1970 /// be used to refer to a given template. For most templates, this
1971 /// expression is just the template declaration itself. For example,
1972 /// the template std::vector can be referred to via a variety of
1973 /// names---std::vector, \::std::vector, vector (if vector is in
1974 /// scope), etc.---but all of these names map down to the same
1975 /// TemplateDecl, which is used to form the canonical template name.
1977 /// Dependent template names are more interesting. Here, the
1978 /// template name could be something like T::template apply or
1979 /// std::allocator<T>::template rebind, where the nested name
1980 /// specifier itself is dependent. In this case, the canonical
1981 /// template name uses the shortest form of the dependent
1982 /// nested-name-specifier, which itself contains all canonical
1983 /// types, values, and templates.
1984 TemplateName getCanonicalTemplateName(TemplateName Name) const;
1986 /// \brief Determine whether the given template names refer to the same
1988 bool hasSameTemplateName(TemplateName X, TemplateName Y);
1990 /// \brief Retrieve the "canonical" template argument.
1992 /// The canonical template argument is the simplest template argument
1993 /// (which may be a type, value, expression, or declaration) that
1994 /// expresses the value of the argument.
1995 TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg)
1998 /// Type Query functions. If the type is an instance of the specified class,
1999 /// return the Type pointer for the underlying maximally pretty type. This
2000 /// is a member of ASTContext because this may need to do some amount of
2001 /// canonicalization, e.g. to move type qualifiers into the element type.
2002 const ArrayType *getAsArrayType(QualType T) const;
2003 const ConstantArrayType *getAsConstantArrayType(QualType T) const {
2004 return dyn_cast_or_null<ConstantArrayType>(getAsArrayType(T));
2006 const VariableArrayType *getAsVariableArrayType(QualType T) const {
2007 return dyn_cast_or_null<VariableArrayType>(getAsArrayType(T));
2009 const IncompleteArrayType *getAsIncompleteArrayType(QualType T) const {
2010 return dyn_cast_or_null<IncompleteArrayType>(getAsArrayType(T));
2012 const DependentSizedArrayType *getAsDependentSizedArrayType(QualType T)
2014 return dyn_cast_or_null<DependentSizedArrayType>(getAsArrayType(T));
2017 /// \brief Return the innermost element type of an array type.
2019 /// For example, will return "int" for int[m][n]
2020 QualType getBaseElementType(const ArrayType *VAT) const;
2022 /// \brief Return the innermost element type of a type (which needn't
2023 /// actually be an array type).
2024 QualType getBaseElementType(QualType QT) const;
2026 /// \brief Return number of constant array elements.
2027 uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
2029 /// \brief Perform adjustment on the parameter type of a function.
2031 /// This routine adjusts the given parameter type @p T to the actual
2032 /// parameter type used by semantic analysis (C99 6.7.5.3p[7,8],
2033 /// C++ [dcl.fct]p3). The adjusted parameter type is returned.
2034 QualType getAdjustedParameterType(QualType T) const;
2036 /// \brief Retrieve the parameter type as adjusted for use in the signature
2037 /// of a function, decaying array and function types and removing top-level
2039 QualType getSignatureParameterType(QualType T) const;
2041 QualType getExceptionObjectType(QualType T) const;
2043 /// \brief Return the properly qualified result of decaying the specified
2044 /// array type to a pointer.
2046 /// This operation is non-trivial when handling typedefs etc. The canonical
2047 /// type of \p T must be an array type, this returns a pointer to a properly
2048 /// qualified element of the array.
2050 /// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
2051 QualType getArrayDecayedType(QualType T) const;
2053 /// \brief Return the type that \p PromotableType will promote to: C99
2054 /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type.
2055 QualType getPromotedIntegerType(QualType PromotableType) const;
2057 /// \brief Recurses in pointer/array types until it finds an Objective-C
2058 /// retainable type and returns its ownership.
2059 Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
2061 /// \brief Whether this is a promotable bitfield reference according
2062 /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
2064 /// \returns the type this bit-field will promote to, or NULL if no
2065 /// promotion occurs.
2066 QualType isPromotableBitField(Expr *E) const;
2068 /// \brief Return the highest ranked integer type, see C99 6.3.1.8p1.
2070 /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If
2071 /// \p LHS < \p RHS, return -1.
2072 int getIntegerTypeOrder(QualType LHS, QualType RHS) const;
2074 /// \brief Compare the rank of the two specified floating point types,
2075 /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
2077 /// If \p LHS > \p RHS, returns 1. If \p LHS == \p RHS, returns 0. If
2078 /// \p LHS < \p RHS, return -1.
2079 int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
2081 /// \brief Return a real floating point or a complex type (based on
2082 /// \p typeDomain/\p typeSize).
2084 /// \param typeDomain a real floating point or complex type.
2085 /// \param typeSize a real floating point or complex type.
2086 QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
2087 QualType typeDomain) const;
2089 unsigned getTargetAddressSpace(QualType T) const {
2090 return getTargetAddressSpace(T.getQualifiers());
2093 unsigned getTargetAddressSpace(Qualifiers Q) const {
2094 return getTargetAddressSpace(Q.getAddressSpace());
2097 unsigned getTargetAddressSpace(unsigned AS) const {
2098 if (AS < LangAS::Offset || AS >= LangAS::Offset + LangAS::Count)
2101 return (*AddrSpaceMap)[AS - LangAS::Offset];
2104 bool addressSpaceMapManglingFor(unsigned AS) const {
2105 return AddrSpaceMapMangling ||
2106 AS < LangAS::Offset ||
2107 AS >= LangAS::Offset + LangAS::Count;
2111 // Helper for integer ordering
2112 unsigned getIntegerRank(const Type *T) const;
2116 //===--------------------------------------------------------------------===//
2117 // Type Compatibility Predicates
2118 //===--------------------------------------------------------------------===//
2120 /// Compatibility predicates used to check assignment expressions.
2121 bool typesAreCompatible(QualType T1, QualType T2,
2122 bool CompareUnqualified = false); // C99 6.2.7p1
2124 bool propertyTypesAreCompatible(QualType, QualType);
2125 bool typesAreBlockPointerCompatible(QualType, QualType);
2127 bool isObjCIdType(QualType T) const {
2128 return T == getObjCIdType();
2130 bool isObjCClassType(QualType T) const {
2131 return T == getObjCClassType();
2133 bool isObjCSelType(QualType T) const {
2134 return T == getObjCSelType();
2136 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2139 bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS);
2141 // Check the safety of assignment from LHS to RHS
2142 bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
2143 const ObjCObjectPointerType *RHSOPT);
2144 bool canAssignObjCInterfaces(const ObjCObjectType *LHS,
2145 const ObjCObjectType *RHS);
2146 bool canAssignObjCInterfacesInBlockPointer(
2147 const ObjCObjectPointerType *LHSOPT,
2148 const ObjCObjectPointerType *RHSOPT,
2149 bool BlockReturnType);
2150 bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
2151 QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT,
2152 const ObjCObjectPointerType *RHSOPT);
2153 bool canBindObjCObjectType(QualType To, QualType From);
2155 // Functions for calculating composite types
2156 QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false,
2157 bool Unqualified = false, bool BlockReturnType = false);
2158 QualType mergeFunctionTypes(QualType, QualType, bool OfBlockPointer=false,
2159 bool Unqualified = false);
2160 QualType mergeFunctionParameterTypes(QualType, QualType,
2161 bool OfBlockPointer = false,
2162 bool Unqualified = false);
2163 QualType mergeTransparentUnionType(QualType, QualType,
2164 bool OfBlockPointer=false,
2165 bool Unqualified = false);
2167 QualType mergeObjCGCQualifiers(QualType, QualType);
2169 bool FunctionTypesMatchOnNSConsumedAttrs(
2170 const FunctionProtoType *FromFunctionType,
2171 const FunctionProtoType *ToFunctionType);
2173 void ResetObjCLayout(const ObjCContainerDecl *CD) {
2174 ObjCLayouts[CD] = nullptr;
2177 //===--------------------------------------------------------------------===//
2178 // Integer Predicates
2179 //===--------------------------------------------------------------------===//
2181 // The width of an integer, as defined in C99 6.2.6.2. This is the number
2182 // of bits in an integer type excluding any padding bits.
2183 unsigned getIntWidth(QualType T) const;
2185 // Per C99 6.2.5p6, for every signed integer type, there is a corresponding
2186 // unsigned integer type. This method takes a signed type, and returns the
2187 // corresponding unsigned integer type.
2188 QualType getCorrespondingUnsignedType(QualType T) const;
2190 //===--------------------------------------------------------------------===//
2192 //===--------------------------------------------------------------------===//
2193 typedef llvm::iterator_range<SmallVectorImpl<Type *>::const_iterator>
2196 type_const_range types() const {
2197 return type_const_range(Types.begin(), Types.end());
2200 //===--------------------------------------------------------------------===//
2202 //===--------------------------------------------------------------------===//
2204 /// \brief Make an APSInt of the appropriate width and signedness for the
2205 /// given \p Value and integer \p Type.
2206 llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const {
2207 llvm::APSInt Res(getIntWidth(Type),
2208 !Type->isSignedIntegerOrEnumerationType());
2213 bool isSentinelNullExpr(const Expr *E);
2215 /// \brief Get the implementation of the ObjCInterfaceDecl \p D, or NULL if
2217 ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
2218 /// \brief Get the implementation of the ObjCCategoryDecl \p D, or NULL if
2220 ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D);
2222 /// \brief Return true if there is at least one \@implementation in the TU.
2223 bool AnyObjCImplementation() {
2224 return !ObjCImpls.empty();
2227 /// \brief Set the implementation of ObjCInterfaceDecl.
2228 void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
2229 ObjCImplementationDecl *ImplD);
2230 /// \brief Set the implementation of ObjCCategoryDecl.
2231 void setObjCImplementation(ObjCCategoryDecl *CatD,
2232 ObjCCategoryImplDecl *ImplD);
2234 /// \brief Get the duplicate declaration of a ObjCMethod in the same
2235 /// interface, or null if none exists.
2236 const ObjCMethodDecl *getObjCMethodRedeclaration(
2237 const ObjCMethodDecl *MD) const {
2238 return ObjCMethodRedecls.lookup(MD);
2241 void setObjCMethodRedeclaration(const ObjCMethodDecl *MD,
2242 const ObjCMethodDecl *Redecl) {
2243 assert(!getObjCMethodRedeclaration(MD) && "MD already has a redeclaration");
2244 ObjCMethodRedecls[MD] = Redecl;
2247 /// \brief Returns the Objective-C interface that \p ND belongs to if it is
2248 /// an Objective-C method/property/ivar etc. that is part of an interface,
2249 /// otherwise returns null.
2250 const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) const;
2252 /// \brief Set the copy inialization expression of a block var decl.
2253 void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
2254 /// \brief Get the copy initialization expression of the VarDecl \p VD, or
2255 /// NULL if none exists.
2256 Expr *getBlockVarCopyInits(const VarDecl* VD);
2258 /// \brief Allocate an uninitialized TypeSourceInfo.
2260 /// The caller should initialize the memory held by TypeSourceInfo using
2261 /// the TypeLoc wrappers.
2263 /// \param T the type that will be the basis for type source info. This type
2264 /// should refer to how the declarator was written in source code, not to
2265 /// what type semantic analysis resolved the declarator to.
2267 /// \param Size the size of the type info to create, or 0 if the size
2268 /// should be calculated based on the type.
2269 TypeSourceInfo *CreateTypeSourceInfo(QualType T, unsigned Size = 0) const;
2271 /// \brief Allocate a TypeSourceInfo where all locations have been
2272 /// initialized to a given location, which defaults to the empty
2275 getTrivialTypeSourceInfo(QualType T,
2276 SourceLocation Loc = SourceLocation()) const;
2278 /// \brief Add a deallocation callback that will be invoked when the
2279 /// ASTContext is destroyed.
2281 /// \param Callback A callback function that will be invoked on destruction.
2283 /// \param Data Pointer data that will be provided to the callback function
2284 /// when it is called.
2285 void AddDeallocation(void (*Callback)(void*), void *Data);
2287 GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const;
2288 GVALinkage GetGVALinkageForVariable(const VarDecl *VD);
2290 /// \brief Determines if the decl can be CodeGen'ed or deserialized from PCH
2291 /// lazily, only when used; this is only relevant for function or file scoped
2292 /// var definitions.
2294 /// \returns true if the function/var must be CodeGen'ed/deserialized even if
2296 bool DeclMustBeEmitted(const Decl *D);
2298 const CXXConstructorDecl *
2299 getCopyConstructorForExceptionObject(CXXRecordDecl *RD);
2301 void addCopyConstructorForExceptionObject(CXXRecordDecl *RD,
2302 CXXConstructorDecl *CD);
2304 void addDefaultArgExprForConstructor(const CXXConstructorDecl *CD,
2305 unsigned ParmIdx, Expr *DAE);
2307 Expr *getDefaultArgExprForConstructor(const CXXConstructorDecl *CD,
2310 void setManglingNumber(const NamedDecl *ND, unsigned Number);
2311 unsigned getManglingNumber(const NamedDecl *ND) const;
2313 void setStaticLocalNumber(const VarDecl *VD, unsigned Number);
2314 unsigned getStaticLocalNumber(const VarDecl *VD) const;
2316 /// \brief Retrieve the context for computing mangling numbers in the given
2318 MangleNumberingContext &getManglingNumberContext(const DeclContext *DC);
2320 MangleNumberingContext *createMangleNumberingContext() const;
2322 /// \brief Used by ParmVarDecl to store on the side the
2323 /// index of the parameter when it exceeds the size of the normal bitfield.
2324 void setParameterIndex(const ParmVarDecl *D, unsigned index);
2326 /// \brief Used by ParmVarDecl to retrieve on the side the
2327 /// index of the parameter when it exceeds the size of the normal bitfield.
2328 unsigned getParameterIndex(const ParmVarDecl *D) const;
2330 /// \brief Get the storage for the constant value of a materialized temporary
2331 /// of static storage duration.
2332 APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,
2335 //===--------------------------------------------------------------------===//
2337 //===--------------------------------------------------------------------===//
2339 /// \brief The number of implicitly-declared default constructors.
2340 static unsigned NumImplicitDefaultConstructors;
2342 /// \brief The number of implicitly-declared default constructors for
2343 /// which declarations were built.
2344 static unsigned NumImplicitDefaultConstructorsDeclared;
2346 /// \brief The number of implicitly-declared copy constructors.
2347 static unsigned NumImplicitCopyConstructors;
2349 /// \brief The number of implicitly-declared copy constructors for
2350 /// which declarations were built.
2351 static unsigned NumImplicitCopyConstructorsDeclared;
2353 /// \brief The number of implicitly-declared move constructors.
2354 static unsigned NumImplicitMoveConstructors;
2356 /// \brief The number of implicitly-declared move constructors for
2357 /// which declarations were built.
2358 static unsigned NumImplicitMoveConstructorsDeclared;
2360 /// \brief The number of implicitly-declared copy assignment operators.
2361 static unsigned NumImplicitCopyAssignmentOperators;
2363 /// \brief The number of implicitly-declared copy assignment operators for
2364 /// which declarations were built.
2365 static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
2367 /// \brief The number of implicitly-declared move assignment operators.
2368 static unsigned NumImplicitMoveAssignmentOperators;
2370 /// \brief The number of implicitly-declared move assignment operators for
2371 /// which declarations were built.
2372 static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
2374 /// \brief The number of implicitly-declared destructors.
2375 static unsigned NumImplicitDestructors;
2377 /// \brief The number of implicitly-declared destructors for which
2378 /// declarations were built.
2379 static unsigned NumImplicitDestructorsDeclared;
2382 ASTContext(const ASTContext &) = delete;
2383 void operator=(const ASTContext &) = delete;
2386 /// \brief Initialize built-in types.
2388 /// This routine may only be invoked once for a given ASTContext object.
2389 /// It is normally invoked after ASTContext construction.
2391 /// \param Target The target
2392 void InitBuiltinTypes(const TargetInfo &Target);
2395 void InitBuiltinType(CanQualType &R, BuiltinType::Kind K);
2397 // Return the Objective-C type encoding for a given type.
2398 void getObjCEncodingForTypeImpl(QualType t, std::string &S,
2399 bool ExpandPointedToStructures,
2400 bool ExpandStructures,
2401 const FieldDecl *Field,
2402 bool OutermostType = false,
2403 bool EncodingProperty = false,
2404 bool StructField = false,
2405 bool EncodeBlockParameters = false,
2406 bool EncodeClassNames = false,
2407 bool EncodePointerToObjCTypedef = false,
2408 QualType *NotEncodedT=nullptr) const;
2410 // Adds the encoding of the structure's members.
2411 void getObjCEncodingForStructureImpl(RecordDecl *RD, std::string &S,
2412 const FieldDecl *Field,
2413 bool includeVBases = true,
2414 QualType *NotEncodedT=nullptr) const;
2416 // Adds the encoding of a method parameter or return type.
2417 void getObjCEncodingForMethodParameter(Decl::ObjCDeclQualifier QT,
2418 QualType T, std::string& S,
2419 bool Extended) const;
2421 /// \brief Returns true if this is an inline-initialized static data member
2422 /// which is treated as a definition for MSVC compatibility.
2423 bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const;
2426 const ASTRecordLayout &
2427 getObjCLayout(const ObjCInterfaceDecl *D,
2428 const ObjCImplementationDecl *Impl) const;
2430 /// \brief A set of deallocations that should be performed when the
2431 /// ASTContext is destroyed.
2432 typedef llvm::SmallDenseMap<void(*)(void*), llvm::SmallVector<void*, 16> >
2434 DeallocationMap Deallocations;
2436 // FIXME: This currently contains the set of StoredDeclMaps used
2437 // by DeclContext objects. This probably should not be in ASTContext,
2438 // but we include it here so that ASTContext can quickly deallocate them.
2439 llvm::PointerIntPair<StoredDeclsMap*,1> LastSDM;
2441 friend class DeclContext;
2442 friend class DeclarationNameTable;
2443 void ReleaseDeclContextMaps();
2444 void ReleaseParentMapEntries();
2446 std::unique_ptr<ParentMap> AllParents;
2448 std::unique_ptr<VTableContextBase> VTContext;
2451 enum PragmaSectionFlag : unsigned {
2457 PSF_Invalid = 0x80000000U,
2460 struct SectionInfo {
2461 DeclaratorDecl *Decl;
2462 SourceLocation PragmaSectionLocation;
2465 SectionInfo(DeclaratorDecl *Decl,
2466 SourceLocation PragmaSectionLocation,
2469 PragmaSectionLocation(PragmaSectionLocation),
2470 SectionFlags(SectionFlags) {}
2473 llvm::StringMap<SectionInfo> SectionInfos;
2476 /// \brief Utility function for constructing a nullary selector.
2477 static inline Selector GetNullarySelector(StringRef name, ASTContext& Ctx) {
2478 IdentifierInfo* II = &Ctx.Idents.get(name);
2479 return Ctx.Selectors.getSelector(0, &II);
2482 /// \brief Utility function for constructing an unary selector.
2483 static inline Selector GetUnarySelector(StringRef name, ASTContext& Ctx) {
2484 IdentifierInfo* II = &Ctx.Idents.get(name);
2485 return Ctx.Selectors.getSelector(1, &II);
2488 } // end namespace clang
2490 // operator new and delete aren't allowed inside namespaces.
2492 /// @brief Placement new for using the ASTContext's allocator.
2494 /// This placement form of operator new uses the ASTContext's allocator for
2495 /// obtaining memory.
2497 /// IMPORTANT: These are also declared in clang/AST/AttrIterator.h! Any changes
2498 /// here need to also be made there.
2500 /// We intentionally avoid using a nothrow specification here so that the calls
2501 /// to this operator will not perform a null check on the result -- the
2502 /// underlying allocator never returns null pointers.
2504 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
2506 /// // Default alignment (8)
2507 /// IntegerLiteral *Ex = new (Context) IntegerLiteral(arguments);
2508 /// // Specific alignment
2509 /// IntegerLiteral *Ex2 = new (Context, 4) IntegerLiteral(arguments);
2511 /// Memory allocated through this placement new operator does not need to be
2512 /// explicitly freed, as ASTContext will free all of this memory when it gets
2513 /// destroyed. Please note that you cannot use delete on the pointer.
2515 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
2516 /// @param C The ASTContext that provides the allocator.
2517 /// @param Alignment The alignment of the allocated memory (if the underlying
2518 /// allocator supports it).
2519 /// @return The allocated memory. Could be NULL.
2520 inline void *operator new(size_t Bytes, const clang::ASTContext &C,
2522 return C.Allocate(Bytes, Alignment);
2524 /// @brief Placement delete companion to the new above.
2526 /// This operator is just a companion to the new above. There is no way of
2527 /// invoking it directly; see the new operator for more details. This operator
2528 /// is called implicitly by the compiler if a placement new expression using
2529 /// the ASTContext throws in the object constructor.
2530 inline void operator delete(void *Ptr, const clang::ASTContext &C, size_t) {
2534 /// This placement form of operator new[] uses the ASTContext's allocator for
2535 /// obtaining memory.
2537 /// We intentionally avoid using a nothrow specification here so that the calls
2538 /// to this operator will not perform a null check on the result -- the
2539 /// underlying allocator never returns null pointers.
2541 /// Usage looks like this (assuming there's an ASTContext 'Context' in scope):
2543 /// // Default alignment (8)
2544 /// char *data = new (Context) char[10];
2545 /// // Specific alignment
2546 /// char *data = new (Context, 4) char[10];
2548 /// Memory allocated through this placement new[] operator does not need to be
2549 /// explicitly freed, as ASTContext will free all of this memory when it gets
2550 /// destroyed. Please note that you cannot use delete on the pointer.
2552 /// @param Bytes The number of bytes to allocate. Calculated by the compiler.
2553 /// @param C The ASTContext that provides the allocator.
2554 /// @param Alignment The alignment of the allocated memory (if the underlying
2555 /// allocator supports it).
2556 /// @return The allocated memory. Could be NULL.
2557 inline void *operator new[](size_t Bytes, const clang::ASTContext& C,
2558 size_t Alignment = 8) {
2559 return C.Allocate(Bytes, Alignment);
2562 /// @brief Placement delete[] companion to the new[] above.
2564 /// This operator is just a companion to the new[] above. There is no way of
2565 /// invoking it directly; see the new[] operator for more details. This operator
2566 /// is called implicitly by the compiler if a placement new[] expression using
2567 /// the ASTContext throws in the object constructor.
2568 inline void operator delete[](void *Ptr, const clang::ASTContext &C, size_t) {
2572 /// \brief Create the representation of a LazyGenerationalUpdatePtr.
2573 template <typename Owner, typename T,
2574 void (clang::ExternalASTSource::*Update)(Owner)>
2575 typename clang::LazyGenerationalUpdatePtr<Owner, T, Update>::ValueType
2576 clang::LazyGenerationalUpdatePtr<Owner, T, Update>::makeValue(
2577 const clang::ASTContext &Ctx, T Value) {
2578 // Note, this is implemented here so that ExternalASTSource.h doesn't need to
2579 // include ASTContext.h. We explicitly instantiate it for all relevant types
2580 // in ASTContext.cpp.
2581 if (auto *Source = Ctx.getExternalSource())
2582 return new (Ctx) LazyData(Source, Value);