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