clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Type.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include/clang/AST -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../include -I /usr/src/gnu/usr.bin/clang/libclangAST/obj -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/lib/AST/Type.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "clang/AST/Type.h" |
14 | #include "Linkage.h" |
15 | #include "clang/AST/ASTContext.h" |
16 | #include "clang/AST/Attr.h" |
17 | #include "clang/AST/CharUnits.h" |
18 | #include "clang/AST/Decl.h" |
19 | #include "clang/AST/DeclBase.h" |
20 | #include "clang/AST/DeclCXX.h" |
21 | #include "clang/AST/DeclObjC.h" |
22 | #include "clang/AST/DeclTemplate.h" |
23 | #include "clang/AST/DependenceFlags.h" |
24 | #include "clang/AST/Expr.h" |
25 | #include "clang/AST/NestedNameSpecifier.h" |
26 | #include "clang/AST/NonTrivialTypeVisitor.h" |
27 | #include "clang/AST/PrettyPrinter.h" |
28 | #include "clang/AST/TemplateBase.h" |
29 | #include "clang/AST/TemplateName.h" |
30 | #include "clang/AST/TypeVisitor.h" |
31 | #include "clang/Basic/AddressSpaces.h" |
32 | #include "clang/Basic/ExceptionSpecificationType.h" |
33 | #include "clang/Basic/IdentifierTable.h" |
34 | #include "clang/Basic/LLVM.h" |
35 | #include "clang/Basic/LangOptions.h" |
36 | #include "clang/Basic/Linkage.h" |
37 | #include "clang/Basic/Specifiers.h" |
38 | #include "clang/Basic/TargetCXXABI.h" |
39 | #include "clang/Basic/TargetInfo.h" |
40 | #include "clang/Basic/Visibility.h" |
41 | #include "llvm/ADT/APInt.h" |
42 | #include "llvm/ADT/APSInt.h" |
43 | #include "llvm/ADT/ArrayRef.h" |
44 | #include "llvm/ADT/FoldingSet.h" |
45 | #include "llvm/ADT/None.h" |
46 | #include "llvm/ADT/SmallVector.h" |
47 | #include "llvm/Support/Casting.h" |
48 | #include "llvm/Support/ErrorHandling.h" |
49 | #include "llvm/Support/MathExtras.h" |
50 | #include <algorithm> |
51 | #include <cassert> |
52 | #include <cstdint> |
53 | #include <cstring> |
54 | #include <type_traits> |
55 | |
56 | using namespace clang; |
57 | |
58 | bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const { |
59 | return (*this != Other) && |
60 | |
61 | (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) && |
62 | |
63 | ((getObjCGCAttr() == Other.getObjCGCAttr()) || |
64 | (hasObjCGCAttr() && !Other.hasObjCGCAttr())) && |
65 | |
66 | ((getAddressSpace() == Other.getAddressSpace()) || |
67 | (hasAddressSpace()&& !Other.hasAddressSpace())) && |
68 | |
69 | ((getObjCLifetime() == Other.getObjCLifetime()) || |
70 | (hasObjCLifetime() && !Other.hasObjCLifetime())); |
71 | } |
72 | |
73 | const IdentifierInfo* QualType::getBaseTypeIdentifier() const { |
74 | const Type* ty = getTypePtr(); |
75 | NamedDecl *ND = nullptr; |
76 | if (ty->isPointerType() || ty->isReferenceType()) |
77 | return ty->getPointeeType().getBaseTypeIdentifier(); |
78 | else if (ty->isRecordType()) |
79 | ND = ty->castAs<RecordType>()->getDecl(); |
80 | else if (ty->isEnumeralType()) |
81 | ND = ty->castAs<EnumType>()->getDecl(); |
82 | else if (ty->getTypeClass() == Type::Typedef) |
83 | ND = ty->castAs<TypedefType>()->getDecl(); |
84 | else if (ty->isArrayType()) |
85 | return ty->castAsArrayTypeUnsafe()-> |
86 | getElementType().getBaseTypeIdentifier(); |
87 | |
88 | if (ND) |
89 | return ND->getIdentifier(); |
90 | return nullptr; |
91 | } |
92 | |
93 | bool QualType::mayBeDynamicClass() const { |
94 | const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl(); |
95 | return ClassDecl && ClassDecl->mayBeDynamicClass(); |
96 | } |
97 | |
98 | bool QualType::mayBeNotDynamicClass() const { |
99 | const auto *ClassDecl = getTypePtr()->getPointeeCXXRecordDecl(); |
100 | return !ClassDecl || ClassDecl->mayBeNonDynamicClass(); |
101 | } |
102 | |
103 | bool QualType::isConstant(QualType T, const ASTContext &Ctx) { |
104 | if (T.isConstQualified()) |
105 | return true; |
106 | |
107 | if (const ArrayType *AT = Ctx.getAsArrayType(T)) |
108 | return AT->getElementType().isConstant(Ctx); |
109 | |
110 | return T.getAddressSpace() == LangAS::opencl_constant; |
111 | } |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | ArrayType::ArrayType(TypeClass tc, QualType et, QualType can, |
119 | ArraySizeModifier sm, unsigned tq, const Expr *sz) |
120 | |
121 | |
122 | |
123 | |
124 | |
125 | |
126 | : Type(tc, can, |
127 | et->getDependence() | |
128 | (sz ? toTypeDependence( |
129 | turnValueToTypeDependence(sz->getDependence())) |
130 | : TypeDependence::None) | |
131 | (tc == VariableArray ? TypeDependence::VariablyModified |
132 | : TypeDependence::None) | |
133 | (tc == DependentSizedArray |
134 | ? TypeDependence::DependentInstantiation |
135 | : TypeDependence::None)), |
136 | ElementType(et) { |
137 | ArrayTypeBits.IndexTypeQuals = tq; |
138 | ArrayTypeBits.SizeModifier = sm; |
139 | } |
140 | |
141 | unsigned ConstantArrayType::getNumAddressingBits(const ASTContext &Context, |
142 | QualType ElementType, |
143 | const llvm::APInt &NumElements) { |
144 | uint64_t ElementSize = Context.getTypeSizeInChars(ElementType).getQuantity(); |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | if (llvm::isPowerOf2_64(ElementSize)) { |
153 | return NumElements.getActiveBits() + llvm::Log2_64(ElementSize); |
154 | } |
155 | |
156 | |
157 | |
158 | if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 && |
159 | (NumElements.getZExtValue() >> 32) == 0) { |
160 | uint64_t TotalSize = NumElements.getZExtValue() * ElementSize; |
161 | return 64 - llvm::countLeadingZeros(TotalSize); |
162 | } |
163 | |
164 | |
165 | llvm::APSInt SizeExtended(NumElements, true); |
166 | unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType()); |
167 | SizeExtended = SizeExtended.extend(std::max(SizeTypeBits, |
168 | SizeExtended.getBitWidth()) * 2); |
169 | |
170 | llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize)); |
171 | TotalSize *= SizeExtended; |
172 | |
173 | return TotalSize.getActiveBits(); |
174 | } |
175 | |
176 | unsigned ConstantArrayType::getMaxSizeBits(const ASTContext &Context) { |
177 | unsigned Bits = Context.getTypeSize(Context.getSizeType()); |
178 | |
179 | |
180 | |
181 | |
182 | if (Bits > 61) |
183 | Bits = 61; |
184 | |
185 | return Bits; |
186 | } |
187 | |
188 | void ConstantArrayType::Profile(llvm::FoldingSetNodeID &ID, |
189 | const ASTContext &Context, QualType ET, |
190 | const llvm::APInt &ArraySize, |
191 | const Expr *SizeExpr, ArraySizeModifier SizeMod, |
192 | unsigned TypeQuals) { |
193 | ID.AddPointer(ET.getAsOpaquePtr()); |
194 | ID.AddInteger(ArraySize.getZExtValue()); |
195 | ID.AddInteger(SizeMod); |
196 | ID.AddInteger(TypeQuals); |
197 | ID.AddBoolean(SizeExpr != 0); |
198 | if (SizeExpr) |
199 | SizeExpr->Profile(ID, Context, true); |
200 | } |
201 | |
202 | DependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context, |
203 | QualType et, QualType can, |
204 | Expr *e, ArraySizeModifier sm, |
205 | unsigned tq, |
206 | SourceRange brackets) |
207 | : ArrayType(DependentSizedArray, et, can, sm, tq, e), |
208 | Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) {} |
209 | |
210 | void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, |
211 | const ASTContext &Context, |
212 | QualType ET, |
213 | ArraySizeModifier SizeMod, |
214 | unsigned TypeQuals, |
215 | Expr *E) { |
216 | ID.AddPointer(ET.getAsOpaquePtr()); |
217 | ID.AddInteger(SizeMod); |
218 | ID.AddInteger(TypeQuals); |
219 | E->Profile(ID, Context, true); |
220 | } |
221 | |
222 | DependentVectorType::DependentVectorType(const ASTContext &Context, |
223 | QualType ElementType, |
224 | QualType CanonType, Expr *SizeExpr, |
225 | SourceLocation Loc, |
226 | VectorType::VectorKind VecKind) |
227 | : Type(DependentVector, CanonType, |
228 | TypeDependence::DependentInstantiation | |
229 | ElementType->getDependence() | |
230 | (SizeExpr ? toTypeDependence(SizeExpr->getDependence()) |
231 | : TypeDependence::None)), |
232 | Context(Context), ElementType(ElementType), SizeExpr(SizeExpr), Loc(Loc) { |
233 | VectorTypeBits.VecKind = VecKind; |
234 | } |
235 | |
236 | void DependentVectorType::Profile(llvm::FoldingSetNodeID &ID, |
237 | const ASTContext &Context, |
238 | QualType ElementType, const Expr *SizeExpr, |
239 | VectorType::VectorKind VecKind) { |
240 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
241 | ID.AddInteger(VecKind); |
242 | SizeExpr->Profile(ID, Context, true); |
243 | } |
244 | |
245 | DependentSizedExtVectorType::DependentSizedExtVectorType( |
246 | const ASTContext &Context, QualType ElementType, QualType can, |
247 | Expr *SizeExpr, SourceLocation loc) |
248 | : Type(DependentSizedExtVector, can, |
249 | TypeDependence::DependentInstantiation | |
250 | ElementType->getDependence() | |
251 | (SizeExpr ? toTypeDependence(SizeExpr->getDependence()) |
252 | : TypeDependence::None)), |
253 | Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) { |
254 | } |
255 | |
256 | void |
257 | DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, |
258 | const ASTContext &Context, |
259 | QualType ElementType, Expr *SizeExpr) { |
260 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
261 | SizeExpr->Profile(ID, Context, true); |
262 | } |
263 | |
264 | DependentAddressSpaceType::DependentAddressSpaceType(const ASTContext &Context, |
265 | QualType PointeeType, |
266 | QualType can, |
267 | Expr *AddrSpaceExpr, |
268 | SourceLocation loc) |
269 | : Type(DependentAddressSpace, can, |
270 | TypeDependence::DependentInstantiation | |
271 | PointeeType->getDependence() | |
272 | (AddrSpaceExpr ? toTypeDependence(AddrSpaceExpr->getDependence()) |
273 | : TypeDependence::None)), |
274 | Context(Context), AddrSpaceExpr(AddrSpaceExpr), PointeeType(PointeeType), |
275 | loc(loc) {} |
276 | |
277 | void DependentAddressSpaceType::Profile(llvm::FoldingSetNodeID &ID, |
278 | const ASTContext &Context, |
279 | QualType PointeeType, |
280 | Expr *AddrSpaceExpr) { |
281 | ID.AddPointer(PointeeType.getAsOpaquePtr()); |
282 | AddrSpaceExpr->Profile(ID, Context, true); |
283 | } |
284 | |
285 | MatrixType::MatrixType(TypeClass tc, QualType matrixType, QualType canonType, |
286 | const Expr *RowExpr, const Expr *ColumnExpr) |
287 | : Type(tc, canonType, |
288 | (RowExpr ? (matrixType->getDependence() | TypeDependence::Dependent | |
289 | TypeDependence::Instantiation | |
290 | (matrixType->isVariablyModifiedType() |
291 | ? TypeDependence::VariablyModified |
292 | : TypeDependence::None) | |
293 | (matrixType->containsUnexpandedParameterPack() || |
294 | (RowExpr && |
295 | RowExpr->containsUnexpandedParameterPack()) || |
296 | (ColumnExpr && |
297 | ColumnExpr->containsUnexpandedParameterPack()) |
298 | ? TypeDependence::UnexpandedPack |
299 | : TypeDependence::None)) |
300 | : matrixType->getDependence())), |
301 | ElementType(matrixType) {} |
302 | |
303 | ConstantMatrixType::ConstantMatrixType(QualType matrixType, unsigned nRows, |
304 | unsigned nColumns, QualType canonType) |
305 | : ConstantMatrixType(ConstantMatrix, matrixType, nRows, nColumns, |
306 | canonType) {} |
307 | |
308 | ConstantMatrixType::ConstantMatrixType(TypeClass tc, QualType matrixType, |
309 | unsigned nRows, unsigned nColumns, |
310 | QualType canonType) |
311 | : MatrixType(tc, matrixType, canonType), NumRows(nRows), |
312 | NumColumns(nColumns) {} |
313 | |
314 | DependentSizedMatrixType::DependentSizedMatrixType( |
315 | const ASTContext &CTX, QualType ElementType, QualType CanonicalType, |
316 | Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc) |
317 | : MatrixType(DependentSizedMatrix, ElementType, CanonicalType, RowExpr, |
318 | ColumnExpr), |
319 | Context(CTX), RowExpr(RowExpr), ColumnExpr(ColumnExpr), loc(loc) {} |
320 | |
321 | void DependentSizedMatrixType::Profile(llvm::FoldingSetNodeID &ID, |
322 | const ASTContext &CTX, |
323 | QualType ElementType, Expr *RowExpr, |
324 | Expr *ColumnExpr) { |
325 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
326 | RowExpr->Profile(ID, CTX, true); |
327 | ColumnExpr->Profile(ID, CTX, true); |
328 | } |
329 | |
330 | VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, |
331 | VectorKind vecKind) |
332 | : VectorType(Vector, vecType, nElements, canonType, vecKind) {} |
333 | |
334 | VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, |
335 | QualType canonType, VectorKind vecKind) |
336 | : Type(tc, canonType, vecType->getDependence()), ElementType(vecType) { |
337 | VectorTypeBits.VecKind = vecKind; |
338 | VectorTypeBits.NumElements = nElements; |
339 | } |
340 | |
341 | ExtIntType::ExtIntType(bool IsUnsigned, unsigned NumBits) |
342 | : Type(ExtInt, QualType{}, TypeDependence::None), IsUnsigned(IsUnsigned), |
343 | NumBits(NumBits) {} |
344 | |
345 | DependentExtIntType::DependentExtIntType(const ASTContext &Context, |
346 | bool IsUnsigned, Expr *NumBitsExpr) |
347 | : Type(DependentExtInt, QualType{}, |
348 | toTypeDependence(NumBitsExpr->getDependence())), |
349 | Context(Context), ExprAndUnsigned(NumBitsExpr, IsUnsigned) {} |
350 | |
351 | bool DependentExtIntType::isUnsigned() const { |
352 | return ExprAndUnsigned.getInt(); |
353 | } |
354 | |
355 | clang::Expr *DependentExtIntType::getNumBitsExpr() const { |
356 | return ExprAndUnsigned.getPointer(); |
357 | } |
358 | |
359 | void DependentExtIntType::Profile(llvm::FoldingSetNodeID &ID, |
360 | const ASTContext &Context, bool IsUnsigned, |
361 | Expr *NumBitsExpr) { |
362 | ID.AddBoolean(IsUnsigned); |
363 | NumBitsExpr->Profile(ID, Context, true); |
364 | } |
365 | |
366 | |
367 | |
368 | |
369 | const Type *Type::getArrayElementTypeNoTypeQual() const { |
370 | |
371 | if (const auto *ATy = dyn_cast<ArrayType>(this)) |
372 | return ATy->getElementType().getTypePtr(); |
373 | |
374 | |
375 | if (!isa<ArrayType>(CanonicalType)) |
376 | return nullptr; |
377 | |
378 | |
379 | |
380 | return cast<ArrayType>(getUnqualifiedDesugaredType()) |
381 | ->getElementType().getTypePtr(); |
382 | } |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | QualType QualType::getDesugaredType(QualType T, const ASTContext &Context) { |
391 | SplitQualType split = getSplitDesugaredType(T); |
392 | return Context.getQualifiedType(split.Ty, split.Quals); |
393 | } |
394 | |
395 | QualType QualType::getSingleStepDesugaredTypeImpl(QualType type, |
396 | const ASTContext &Context) { |
397 | SplitQualType split = type.split(); |
398 | QualType desugar = split.Ty->getLocallyUnqualifiedSingleStepDesugaredType(); |
399 | return Context.getQualifiedType(desugar, split.Quals); |
400 | } |
401 | |
402 | |
403 | |
404 | |
405 | #define TYPE(CLASS, BASE) \ |
406 | static_assert(!std::is_polymorphic<CLASS##Type>::value, \ |
407 | #CLASS "Type should not be polymorphic!"); |
408 | #include "clang/AST/TypeNodes.inc" |
409 | |
410 | |
411 | |
412 | |
413 | |
414 | |
415 | |
416 | #define TYPE(CLASS, BASE) \ |
417 | static_assert(std::is_trivially_destructible<CLASS##Type>::value || \ |
418 | std::is_same<CLASS##Type, ConstantArrayType>::value, \ |
419 | #CLASS "Type should be trivially destructible!"); |
420 | #include "clang/AST/TypeNodes.inc" |
421 | |
422 | QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const { |
423 | switch (getTypeClass()) { |
424 | #define ABSTRACT_TYPE(Class, Parent) |
425 | #define TYPE(Class, Parent) \ |
426 | case Type::Class: { \ |
427 | const auto *ty = cast<Class##Type>(this); \ |
428 | if (!ty->isSugared()) return QualType(ty, 0); \ |
429 | return ty->desugar(); \ |
430 | } |
431 | #include "clang/AST/TypeNodes.inc" |
432 | } |
433 | llvm_unreachable("bad type kind!"); |
434 | } |
435 | |
436 | SplitQualType QualType::getSplitDesugaredType(QualType T) { |
437 | QualifierCollector Qs; |
438 | |
439 | QualType Cur = T; |
440 | while (true) { |
441 | const Type *CurTy = Qs.strip(Cur); |
442 | switch (CurTy->getTypeClass()) { |
443 | #define ABSTRACT_TYPE(Class, Parent) |
444 | #define TYPE(Class, Parent) \ |
445 | case Type::Class: { \ |
446 | const auto *Ty = cast<Class##Type>(CurTy); \ |
447 | if (!Ty->isSugared()) \ |
448 | return SplitQualType(Ty, Qs); \ |
449 | Cur = Ty->desugar(); \ |
450 | break; \ |
451 | } |
452 | #include "clang/AST/TypeNodes.inc" |
453 | } |
454 | } |
455 | } |
456 | |
457 | SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) { |
458 | SplitQualType split = type.split(); |
459 | |
460 | |
461 | Qualifiers quals = split.Quals; |
462 | |
463 | |
464 | const Type *lastTypeWithQuals = split.Ty; |
465 | |
466 | while (true) { |
467 | QualType next; |
468 | |
469 | |
470 | |
471 | switch (split.Ty->getTypeClass()) { |
472 | #define ABSTRACT_TYPE(Class, Parent) |
473 | #define TYPE(Class, Parent) \ |
474 | case Type::Class: { \ |
475 | const auto *ty = cast<Class##Type>(split.Ty); \ |
476 | if (!ty->isSugared()) goto done; \ |
477 | next = ty->desugar(); \ |
478 | break; \ |
479 | } |
480 | #include "clang/AST/TypeNodes.inc" |
481 | } |
482 | |
483 | |
484 | |
485 | split = next.split(); |
486 | if (!split.Quals.empty()) { |
487 | lastTypeWithQuals = split.Ty; |
488 | quals.addConsistentQualifiers(split.Quals); |
489 | } |
490 | } |
491 | |
492 | done: |
493 | return SplitQualType(lastTypeWithQuals, quals); |
494 | } |
495 | |
496 | QualType QualType::IgnoreParens(QualType T) { |
497 | |
498 | while (const auto *PT = T->getAs<ParenType>()) |
499 | T = PT->getInnerType(); |
500 | return T; |
501 | } |
502 | |
503 | |
504 | |
505 | |
506 | template<typename T> static const T *getAsSugar(const Type *Cur) { |
507 | while (true) { |
508 | if (const auto *Sugar = dyn_cast<T>(Cur)) |
509 | return Sugar; |
510 | switch (Cur->getTypeClass()) { |
511 | #define ABSTRACT_TYPE(Class, Parent) |
512 | #define TYPE(Class, Parent) \ |
513 | case Type::Class: { \ |
514 | const auto *Ty = cast<Class##Type>(Cur); \ |
515 | if (!Ty->isSugared()) return 0; \ |
516 | Cur = Ty->desugar().getTypePtr(); \ |
517 | break; \ |
518 | } |
519 | #include "clang/AST/TypeNodes.inc" |
520 | } |
521 | } |
522 | } |
523 | |
524 | template <> const TypedefType *Type::getAs() const { |
525 | return getAsSugar<TypedefType>(this); |
526 | } |
527 | |
528 | template <> const TemplateSpecializationType *Type::getAs() const { |
529 | return getAsSugar<TemplateSpecializationType>(this); |
530 | } |
531 | |
532 | template <> const AttributedType *Type::getAs() const { |
533 | return getAsSugar<AttributedType>(this); |
534 | } |
535 | |
536 | |
537 | |
538 | |
539 | const Type *Type::getUnqualifiedDesugaredType() const { |
540 | const Type *Cur = this; |
541 | |
542 | while (true) { |
543 | switch (Cur->getTypeClass()) { |
544 | #define ABSTRACT_TYPE(Class, Parent) |
545 | #define TYPE(Class, Parent) \ |
546 | case Class: { \ |
547 | const auto *Ty = cast<Class##Type>(Cur); \ |
548 | if (!Ty->isSugared()) return Cur; \ |
549 | Cur = Ty->desugar().getTypePtr(); \ |
550 | break; \ |
551 | } |
552 | #include "clang/AST/TypeNodes.inc" |
553 | } |
554 | } |
555 | } |
556 | |
557 | bool Type::isClassType() const { |
558 | if (const auto *RT = getAs<RecordType>()) |
559 | return RT->getDecl()->isClass(); |
560 | return false; |
561 | } |
562 | |
563 | bool Type::isStructureType() const { |
564 | if (const auto *RT = getAs<RecordType>()) |
565 | return RT->getDecl()->isStruct(); |
566 | return false; |
567 | } |
568 | |
569 | bool Type::isObjCBoxableRecordType() const { |
570 | if (const auto *RT = getAs<RecordType>()) |
571 | return RT->getDecl()->hasAttr<ObjCBoxableAttr>(); |
572 | return false; |
573 | } |
574 | |
575 | bool Type::isInterfaceType() const { |
576 | if (const auto *RT = getAs<RecordType>()) |
577 | return RT->getDecl()->isInterface(); |
578 | return false; |
579 | } |
580 | |
581 | bool Type::isStructureOrClassType() const { |
582 | if (const auto *RT = getAs<RecordType>()) { |
583 | RecordDecl *RD = RT->getDecl(); |
584 | return RD->isStruct() || RD->isClass() || RD->isInterface(); |
585 | } |
586 | return false; |
587 | } |
588 | |
589 | bool Type::isVoidPointerType() const { |
590 | if (const auto *PT = getAs<PointerType>()) |
591 | return PT->getPointeeType()->isVoidType(); |
592 | return false; |
593 | } |
594 | |
595 | bool Type::isUnionType() const { |
596 | if (const auto *RT = getAs<RecordType>()) |
597 | return RT->getDecl()->isUnion(); |
598 | return false; |
599 | } |
600 | |
601 | bool Type::isComplexType() const { |
602 | if (const auto *CT = dyn_cast<ComplexType>(CanonicalType)) |
603 | return CT->getElementType()->isFloatingType(); |
604 | return false; |
605 | } |
606 | |
607 | bool Type::isComplexIntegerType() const { |
608 | |
609 | return getAsComplexIntegerType(); |
610 | } |
611 | |
612 | bool Type::isScopedEnumeralType() const { |
613 | if (const auto *ET = getAs<EnumType>()) |
614 | return ET->getDecl()->isScoped(); |
615 | return false; |
616 | } |
617 | |
618 | const ComplexType *Type::getAsComplexIntegerType() const { |
619 | if (const auto *Complex = getAs<ComplexType>()) |
620 | if (Complex->getElementType()->isIntegerType()) |
621 | return Complex; |
622 | return nullptr; |
623 | } |
624 | |
625 | QualType Type::getPointeeType() const { |
626 | if (const auto *PT = getAs<PointerType>()) |
627 | return PT->getPointeeType(); |
628 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
629 | return OPT->getPointeeType(); |
630 | if (const auto *BPT = getAs<BlockPointerType>()) |
631 | return BPT->getPointeeType(); |
632 | if (const auto *RT = getAs<ReferenceType>()) |
633 | return RT->getPointeeType(); |
634 | if (const auto *MPT = getAs<MemberPointerType>()) |
635 | return MPT->getPointeeType(); |
636 | if (const auto *DT = getAs<DecayedType>()) |
637 | return DT->getPointeeType(); |
638 | return {}; |
639 | } |
640 | |
641 | const RecordType *Type::getAsStructureType() const { |
642 | |
643 | if (const auto *RT = dyn_cast<RecordType>(this)) { |
644 | if (RT->getDecl()->isStruct()) |
645 | return RT; |
646 | } |
647 | |
648 | |
649 | if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) { |
650 | if (!RT->getDecl()->isStruct()) |
651 | return nullptr; |
652 | |
653 | |
654 | |
655 | return cast<RecordType>(getUnqualifiedDesugaredType()); |
656 | } |
657 | return nullptr; |
658 | } |
659 | |
660 | const RecordType *Type::getAsUnionType() const { |
661 | |
662 | if (const auto *RT = dyn_cast<RecordType>(this)) { |
663 | if (RT->getDecl()->isUnion()) |
664 | return RT; |
665 | } |
666 | |
667 | |
668 | if (const auto *RT = dyn_cast<RecordType>(CanonicalType)) { |
669 | if (!RT->getDecl()->isUnion()) |
670 | return nullptr; |
671 | |
672 | |
673 | |
674 | return cast<RecordType>(getUnqualifiedDesugaredType()); |
675 | } |
676 | |
677 | return nullptr; |
678 | } |
679 | |
680 | bool Type::isObjCIdOrObjectKindOfType(const ASTContext &ctx, |
681 | const ObjCObjectType *&bound) const { |
682 | bound = nullptr; |
683 | |
684 | const auto *OPT = getAs<ObjCObjectPointerType>(); |
685 | if (!OPT) |
686 | return false; |
687 | |
688 | |
689 | if (OPT->isObjCIdType()) |
690 | return true; |
691 | |
692 | |
693 | if (!OPT->isKindOfType()) |
694 | return false; |
695 | |
696 | |
697 | if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType()) |
698 | return false; |
699 | |
700 | |
701 | bound = OPT->getObjectType()->stripObjCKindOfTypeAndQuals(ctx) |
702 | ->getAs<ObjCObjectType>(); |
703 | return true; |
704 | } |
705 | |
706 | bool Type::isObjCClassOrClassKindOfType() const { |
707 | const auto *OPT = getAs<ObjCObjectPointerType>(); |
708 | if (!OPT) |
709 | return false; |
710 | |
711 | |
712 | if (OPT->isObjCClassType()) |
713 | return true; |
714 | |
715 | |
716 | if (!OPT->isKindOfType()) |
717 | return false; |
718 | |
719 | |
720 | return OPT->isObjCClassType() || OPT->isObjCQualifiedClassType(); |
721 | } |
722 | |
723 | ObjCTypeParamType::ObjCTypeParamType(const ObjCTypeParamDecl *D, QualType can, |
724 | ArrayRef<ObjCProtocolDecl *> protocols) |
725 | : Type(ObjCTypeParam, can, |
726 | can->getDependence() & ~TypeDependence::UnexpandedPack), |
727 | OTPDecl(const_cast<ObjCTypeParamDecl *>(D)) { |
728 | initialize(protocols); |
729 | } |
730 | |
731 | ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, |
732 | ArrayRef<QualType> typeArgs, |
733 | ArrayRef<ObjCProtocolDecl *> protocols, |
734 | bool isKindOf) |
735 | : Type(ObjCObject, Canonical, Base->getDependence()), BaseType(Base) { |
736 | ObjCObjectTypeBits.IsKindOf = isKindOf; |
737 | |
738 | ObjCObjectTypeBits.NumTypeArgs = typeArgs.size(); |
739 | assert(getTypeArgsAsWritten().size() == typeArgs.size() && |
740 | "bitfield overflow in type argument count"); |
741 | if (!typeArgs.empty()) |
742 | memcpy(getTypeArgStorage(), typeArgs.data(), |
743 | typeArgs.size() * sizeof(QualType)); |
744 | |
745 | for (auto typeArg : typeArgs) { |
746 | addDependence(typeArg->getDependence() & ~TypeDependence::VariablyModified); |
747 | } |
748 | |
749 | |
750 | initialize(protocols); |
751 | } |
752 | |
753 | bool ObjCObjectType::isSpecialized() const { |
754 | |
755 | if (ObjCObjectTypeBits.NumTypeArgs > 0) |
756 | return true; |
757 | |
758 | |
759 | if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) { |
760 | |
761 | if (isa<ObjCInterfaceType>(objcObject)) |
762 | return false; |
763 | |
764 | return objcObject->isSpecialized(); |
765 | } |
766 | |
767 | |
768 | return false; |
769 | } |
770 | |
771 | ArrayRef<QualType> ObjCObjectType::getTypeArgs() const { |
772 | |
773 | if (isSpecializedAsWritten()) |
774 | return getTypeArgsAsWritten(); |
775 | |
776 | |
777 | if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) { |
778 | |
779 | if (isa<ObjCInterfaceType>(objcObject)) |
780 | return {}; |
781 | |
782 | return objcObject->getTypeArgs(); |
783 | } |
784 | |
785 | |
786 | return {}; |
787 | } |
788 | |
789 | bool ObjCObjectType::isKindOfType() const { |
790 | if (isKindOfTypeAsWritten()) |
791 | return true; |
792 | |
793 | |
794 | if (const auto objcObject = getBaseType()->getAs<ObjCObjectType>()) { |
795 | |
796 | if (isa<ObjCInterfaceType>(objcObject)) |
797 | return false; |
798 | |
799 | return objcObject->isKindOfType(); |
800 | } |
801 | |
802 | |
803 | return false; |
804 | } |
805 | |
806 | QualType ObjCObjectType::stripObjCKindOfTypeAndQuals( |
807 | const ASTContext &ctx) const { |
808 | if (!isKindOfType() && qual_empty()) |
809 | return QualType(this, 0); |
810 | |
811 | |
812 | SplitQualType splitBaseType = getBaseType().split(); |
813 | QualType baseType(splitBaseType.Ty, 0); |
814 | if (const auto *baseObj = splitBaseType.Ty->getAs<ObjCObjectType>()) |
815 | baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx); |
816 | |
817 | return ctx.getObjCObjectType(ctx.getQualifiedType(baseType, |
818 | splitBaseType.Quals), |
819 | getTypeArgsAsWritten(), |
820 | {}, |
821 | false); |
822 | } |
823 | |
824 | const ObjCObjectPointerType *ObjCObjectPointerType::stripObjCKindOfTypeAndQuals( |
825 | const ASTContext &ctx) const { |
826 | if (!isKindOfType() && qual_empty()) |
827 | return this; |
828 | |
829 | QualType obj = getObjectType()->stripObjCKindOfTypeAndQuals(ctx); |
830 | return ctx.getObjCObjectPointerType(obj)->castAs<ObjCObjectPointerType>(); |
831 | } |
832 | |
833 | namespace { |
834 | |
835 | |
836 | |
837 | template <typename Derived> |
838 | struct SimpleTransformVisitor : public TypeVisitor<Derived, QualType> { |
839 | ASTContext &Ctx; |
840 | |
841 | QualType recurse(QualType type) { |
842 | |
843 | SplitQualType splitType = type.split(); |
844 | |
845 | |
846 | QualType result = static_cast<Derived *>(this)->Visit(splitType.Ty); |
847 | if (result.isNull()) |
848 | return result; |
849 | |
850 | |
851 | |
852 | return Ctx.getQualifiedType(result, splitType.Quals); |
853 | } |
854 | |
855 | public: |
856 | explicit SimpleTransformVisitor(ASTContext &ctx) : Ctx(ctx) {} |
857 | |
858 | |
859 | |
860 | #define TYPE(Class, Base) |
861 | #define DEPENDENT_TYPE(Class, Base) \ |
862 | QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); } |
863 | #include "clang/AST/TypeNodes.inc" |
864 | |
865 | #define TRIVIAL_TYPE_CLASS(Class) \ |
866 | QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); } |
867 | #define SUGARED_TYPE_CLASS(Class) \ |
868 | QualType Visit##Class##Type(const Class##Type *T) { \ |
869 | if (!T->isSugared()) \ |
870 | return QualType(T, 0); \ |
871 | QualType desugaredType = recurse(T->desugar()); \ |
872 | if (desugaredType.isNull()) \ |
873 | return {}; \ |
874 | if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \ |
875 | return QualType(T, 0); \ |
876 | return desugaredType; \ |
877 | } |
878 | |
879 | TRIVIAL_TYPE_CLASS(Builtin) |
880 | |
881 | QualType VisitComplexType(const ComplexType *T) { |
882 | QualType elementType = recurse(T->getElementType()); |
883 | if (elementType.isNull()) |
884 | return {}; |
885 | |
886 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
887 | return QualType(T, 0); |
888 | |
889 | return Ctx.getComplexType(elementType); |
890 | } |
891 | |
892 | QualType VisitPointerType(const PointerType *T) { |
893 | QualType pointeeType = recurse(T->getPointeeType()); |
894 | if (pointeeType.isNull()) |
895 | return {}; |
896 | |
897 | if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) |
898 | return QualType(T, 0); |
899 | |
900 | return Ctx.getPointerType(pointeeType); |
901 | } |
902 | |
903 | QualType VisitBlockPointerType(const BlockPointerType *T) { |
904 | QualType pointeeType = recurse(T->getPointeeType()); |
905 | if (pointeeType.isNull()) |
906 | return {}; |
907 | |
908 | if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) |
909 | return QualType(T, 0); |
910 | |
911 | return Ctx.getBlockPointerType(pointeeType); |
912 | } |
913 | |
914 | QualType VisitLValueReferenceType(const LValueReferenceType *T) { |
915 | QualType pointeeType = recurse(T->getPointeeTypeAsWritten()); |
916 | if (pointeeType.isNull()) |
917 | return {}; |
918 | |
919 | if (pointeeType.getAsOpaquePtr() |
920 | == T->getPointeeTypeAsWritten().getAsOpaquePtr()) |
921 | return QualType(T, 0); |
922 | |
923 | return Ctx.getLValueReferenceType(pointeeType, T->isSpelledAsLValue()); |
924 | } |
925 | |
926 | QualType VisitRValueReferenceType(const RValueReferenceType *T) { |
927 | QualType pointeeType = recurse(T->getPointeeTypeAsWritten()); |
928 | if (pointeeType.isNull()) |
929 | return {}; |
930 | |
931 | if (pointeeType.getAsOpaquePtr() |
932 | == T->getPointeeTypeAsWritten().getAsOpaquePtr()) |
933 | return QualType(T, 0); |
934 | |
935 | return Ctx.getRValueReferenceType(pointeeType); |
936 | } |
937 | |
938 | QualType VisitMemberPointerType(const MemberPointerType *T) { |
939 | QualType pointeeType = recurse(T->getPointeeType()); |
940 | if (pointeeType.isNull()) |
941 | return {}; |
942 | |
943 | if (pointeeType.getAsOpaquePtr() == T->getPointeeType().getAsOpaquePtr()) |
944 | return QualType(T, 0); |
945 | |
946 | return Ctx.getMemberPointerType(pointeeType, T->getClass()); |
947 | } |
948 | |
949 | QualType VisitConstantArrayType(const ConstantArrayType *T) { |
950 | QualType elementType = recurse(T->getElementType()); |
951 | if (elementType.isNull()) |
952 | return {}; |
953 | |
954 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
955 | return QualType(T, 0); |
956 | |
957 | return Ctx.getConstantArrayType(elementType, T->getSize(), T->getSizeExpr(), |
958 | T->getSizeModifier(), |
959 | T->getIndexTypeCVRQualifiers()); |
960 | } |
961 | |
962 | QualType VisitVariableArrayType(const VariableArrayType *T) { |
963 | QualType elementType = recurse(T->getElementType()); |
964 | if (elementType.isNull()) |
965 | return {}; |
966 | |
967 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
968 | return QualType(T, 0); |
969 | |
970 | return Ctx.getVariableArrayType(elementType, T->getSizeExpr(), |
971 | T->getSizeModifier(), |
972 | T->getIndexTypeCVRQualifiers(), |
973 | T->getBracketsRange()); |
974 | } |
975 | |
976 | QualType VisitIncompleteArrayType(const IncompleteArrayType *T) { |
977 | QualType elementType = recurse(T->getElementType()); |
978 | if (elementType.isNull()) |
979 | return {}; |
980 | |
981 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
982 | return QualType(T, 0); |
983 | |
984 | return Ctx.getIncompleteArrayType(elementType, T->getSizeModifier(), |
985 | T->getIndexTypeCVRQualifiers()); |
986 | } |
987 | |
988 | QualType VisitVectorType(const VectorType *T) { |
989 | QualType elementType = recurse(T->getElementType()); |
990 | if (elementType.isNull()) |
991 | return {}; |
992 | |
993 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
994 | return QualType(T, 0); |
995 | |
996 | return Ctx.getVectorType(elementType, T->getNumElements(), |
997 | T->getVectorKind()); |
998 | } |
999 | |
1000 | QualType VisitExtVectorType(const ExtVectorType *T) { |
1001 | QualType elementType = recurse(T->getElementType()); |
1002 | if (elementType.isNull()) |
1003 | return {}; |
1004 | |
1005 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
1006 | return QualType(T, 0); |
1007 | |
1008 | return Ctx.getExtVectorType(elementType, T->getNumElements()); |
1009 | } |
1010 | |
1011 | QualType VisitConstantMatrixType(const ConstantMatrixType *T) { |
1012 | QualType elementType = recurse(T->getElementType()); |
1013 | if (elementType.isNull()) |
1014 | return {}; |
1015 | if (elementType.getAsOpaquePtr() == T->getElementType().getAsOpaquePtr()) |
1016 | return QualType(T, 0); |
1017 | |
1018 | return Ctx.getConstantMatrixType(elementType, T->getNumRows(), |
1019 | T->getNumColumns()); |
1020 | } |
1021 | |
1022 | QualType VisitFunctionNoProtoType(const FunctionNoProtoType *T) { |
1023 | QualType returnType = recurse(T->getReturnType()); |
1024 | if (returnType.isNull()) |
1025 | return {}; |
1026 | |
1027 | if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr()) |
1028 | return QualType(T, 0); |
1029 | |
1030 | return Ctx.getFunctionNoProtoType(returnType, T->getExtInfo()); |
1031 | } |
1032 | |
1033 | QualType VisitFunctionProtoType(const FunctionProtoType *T) { |
1034 | QualType returnType = recurse(T->getReturnType()); |
1035 | if (returnType.isNull()) |
1036 | return {}; |
1037 | |
1038 | |
1039 | SmallVector<QualType, 4> paramTypes; |
1040 | bool paramChanged = false; |
1041 | for (auto paramType : T->getParamTypes()) { |
1042 | QualType newParamType = recurse(paramType); |
1043 | if (newParamType.isNull()) |
1044 | return {}; |
1045 | |
1046 | if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr()) |
1047 | paramChanged = true; |
1048 | |
1049 | paramTypes.push_back(newParamType); |
1050 | } |
1051 | |
1052 | |
1053 | FunctionProtoType::ExtProtoInfo info = T->getExtProtoInfo(); |
1054 | bool exceptionChanged = false; |
1055 | if (info.ExceptionSpec.Type == EST_Dynamic) { |
1056 | SmallVector<QualType, 4> exceptionTypes; |
1057 | for (auto exceptionType : info.ExceptionSpec.Exceptions) { |
1058 | QualType newExceptionType = recurse(exceptionType); |
1059 | if (newExceptionType.isNull()) |
1060 | return {}; |
1061 | |
1062 | if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr()) |
1063 | exceptionChanged = true; |
1064 | |
1065 | exceptionTypes.push_back(newExceptionType); |
1066 | } |
1067 | |
1068 | if (exceptionChanged) { |
1069 | info.ExceptionSpec.Exceptions = |
1070 | llvm::makeArrayRef(exceptionTypes).copy(Ctx); |
1071 | } |
1072 | } |
1073 | |
1074 | if (returnType.getAsOpaquePtr() == T->getReturnType().getAsOpaquePtr() && |
1075 | !paramChanged && !exceptionChanged) |
1076 | return QualType(T, 0); |
1077 | |
1078 | return Ctx.getFunctionType(returnType, paramTypes, info); |
1079 | } |
1080 | |
1081 | QualType VisitParenType(const ParenType *T) { |
1082 | QualType innerType = recurse(T->getInnerType()); |
1083 | if (innerType.isNull()) |
1084 | return {}; |
1085 | |
1086 | if (innerType.getAsOpaquePtr() == T->getInnerType().getAsOpaquePtr()) |
1087 | return QualType(T, 0); |
1088 | |
1089 | return Ctx.getParenType(innerType); |
1090 | } |
1091 | |
1092 | SUGARED_TYPE_CLASS(Typedef) |
1093 | SUGARED_TYPE_CLASS(ObjCTypeParam) |
1094 | SUGARED_TYPE_CLASS(MacroQualified) |
1095 | |
1096 | QualType VisitAdjustedType(const AdjustedType *T) { |
1097 | QualType originalType = recurse(T->getOriginalType()); |
1098 | if (originalType.isNull()) |
1099 | return {}; |
1100 | |
1101 | QualType adjustedType = recurse(T->getAdjustedType()); |
1102 | if (adjustedType.isNull()) |
1103 | return {}; |
1104 | |
1105 | if (originalType.getAsOpaquePtr() |
1106 | == T->getOriginalType().getAsOpaquePtr() && |
1107 | adjustedType.getAsOpaquePtr() == T->getAdjustedType().getAsOpaquePtr()) |
1108 | return QualType(T, 0); |
1109 | |
1110 | return Ctx.getAdjustedType(originalType, adjustedType); |
1111 | } |
1112 | |
1113 | QualType VisitDecayedType(const DecayedType *T) { |
1114 | QualType originalType = recurse(T->getOriginalType()); |
1115 | if (originalType.isNull()) |
1116 | return {}; |
1117 | |
1118 | if (originalType.getAsOpaquePtr() |
1119 | == T->getOriginalType().getAsOpaquePtr()) |
1120 | return QualType(T, 0); |
1121 | |
1122 | return Ctx.getDecayedType(originalType); |
1123 | } |
1124 | |
1125 | SUGARED_TYPE_CLASS(TypeOfExpr) |
1126 | SUGARED_TYPE_CLASS(TypeOf) |
1127 | SUGARED_TYPE_CLASS(Decltype) |
1128 | SUGARED_TYPE_CLASS(UnaryTransform) |
1129 | TRIVIAL_TYPE_CLASS(Record) |
1130 | TRIVIAL_TYPE_CLASS(Enum) |
1131 | |
1132 | |
1133 | SUGARED_TYPE_CLASS(Elaborated) |
1134 | |
1135 | QualType VisitAttributedType(const AttributedType *T) { |
1136 | QualType modifiedType = recurse(T->getModifiedType()); |
1137 | if (modifiedType.isNull()) |
1138 | return {}; |
1139 | |
1140 | QualType equivalentType = recurse(T->getEquivalentType()); |
1141 | if (equivalentType.isNull()) |
1142 | return {}; |
1143 | |
1144 | if (modifiedType.getAsOpaquePtr() |
1145 | == T->getModifiedType().getAsOpaquePtr() && |
1146 | equivalentType.getAsOpaquePtr() |
1147 | == T->getEquivalentType().getAsOpaquePtr()) |
1148 | return QualType(T, 0); |
1149 | |
1150 | return Ctx.getAttributedType(T->getAttrKind(), modifiedType, |
1151 | equivalentType); |
1152 | } |
1153 | |
1154 | QualType VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { |
1155 | QualType replacementType = recurse(T->getReplacementType()); |
1156 | if (replacementType.isNull()) |
1157 | return {}; |
1158 | |
1159 | if (replacementType.getAsOpaquePtr() |
1160 | == T->getReplacementType().getAsOpaquePtr()) |
1161 | return QualType(T, 0); |
1162 | |
1163 | return Ctx.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
1164 | replacementType); |
1165 | } |
1166 | |
1167 | |
1168 | SUGARED_TYPE_CLASS(TemplateSpecialization) |
1169 | |
1170 | QualType VisitAutoType(const AutoType *T) { |
1171 | if (!T->isDeduced()) |
1172 | return QualType(T, 0); |
1173 | |
1174 | QualType deducedType = recurse(T->getDeducedType()); |
1175 | if (deducedType.isNull()) |
1176 | return {}; |
1177 | |
1178 | if (deducedType.getAsOpaquePtr() |
1179 | == T->getDeducedType().getAsOpaquePtr()) |
1180 | return QualType(T, 0); |
1181 | |
1182 | return Ctx.getAutoType(deducedType, T->getKeyword(), |
1183 | T->isDependentType(), false, |
1184 | T->getTypeConstraintConcept(), |
1185 | T->getTypeConstraintArguments()); |
1186 | } |
1187 | |
1188 | QualType VisitObjCObjectType(const ObjCObjectType *T) { |
1189 | QualType baseType = recurse(T->getBaseType()); |
1190 | if (baseType.isNull()) |
1191 | return {}; |
1192 | |
1193 | |
1194 | bool typeArgChanged = false; |
1195 | SmallVector<QualType, 4> typeArgs; |
1196 | for (auto typeArg : T->getTypeArgsAsWritten()) { |
1197 | QualType newTypeArg = recurse(typeArg); |
1198 | if (newTypeArg.isNull()) |
1199 | return {}; |
1200 | |
1201 | if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) |
1202 | typeArgChanged = true; |
1203 | |
1204 | typeArgs.push_back(newTypeArg); |
1205 | } |
1206 | |
1207 | if (baseType.getAsOpaquePtr() == T->getBaseType().getAsOpaquePtr() && |
1208 | !typeArgChanged) |
1209 | return QualType(T, 0); |
1210 | |
1211 | return Ctx.getObjCObjectType(baseType, typeArgs, |
1212 | llvm::makeArrayRef(T->qual_begin(), |
1213 | T->getNumProtocols()), |
1214 | T->isKindOfTypeAsWritten()); |
1215 | } |
1216 | |
1217 | TRIVIAL_TYPE_CLASS(ObjCInterface) |
1218 | |
1219 | QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { |
1220 | QualType pointeeType = recurse(T->getPointeeType()); |
1221 | if (pointeeType.isNull()) |
1222 | return {}; |
1223 | |
1224 | if (pointeeType.getAsOpaquePtr() |
1225 | == T->getPointeeType().getAsOpaquePtr()) |
1226 | return QualType(T, 0); |
1227 | |
1228 | return Ctx.getObjCObjectPointerType(pointeeType); |
1229 | } |
1230 | |
1231 | QualType VisitAtomicType(const AtomicType *T) { |
1232 | QualType valueType = recurse(T->getValueType()); |
1233 | if (valueType.isNull()) |
1234 | return {}; |
1235 | |
1236 | if (valueType.getAsOpaquePtr() |
1237 | == T->getValueType().getAsOpaquePtr()) |
1238 | return QualType(T, 0); |
1239 | |
1240 | return Ctx.getAtomicType(valueType); |
1241 | } |
1242 | |
1243 | #undef TRIVIAL_TYPE_CLASS |
1244 | #undef SUGARED_TYPE_CLASS |
1245 | }; |
1246 | |
1247 | struct SubstObjCTypeArgsVisitor |
1248 | : public SimpleTransformVisitor<SubstObjCTypeArgsVisitor> { |
1249 | using BaseType = SimpleTransformVisitor<SubstObjCTypeArgsVisitor>; |
1250 | |
1251 | ArrayRef<QualType> TypeArgs; |
1252 | ObjCSubstitutionContext SubstContext; |
1253 | |
1254 | SubstObjCTypeArgsVisitor(ASTContext &ctx, ArrayRef<QualType> typeArgs, |
1255 | ObjCSubstitutionContext context) |
1256 | : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {} |
1257 | |
1258 | QualType VisitObjCTypeParamType(const ObjCTypeParamType *OTPTy) { |
1259 | |
1260 | |
1261 | ObjCTypeParamDecl *typeParam = OTPTy->getDecl(); |
1262 | |
1263 | if (!TypeArgs.empty()) { |
1264 | QualType argType = TypeArgs[typeParam->getIndex()]; |
1265 | if (OTPTy->qual_empty()) |
1266 | return argType; |
1267 | |
1268 | |
1269 | bool hasError; |
1270 | SmallVector<ObjCProtocolDecl *, 8> protocolsVec; |
1271 | protocolsVec.append(OTPTy->qual_begin(), OTPTy->qual_end()); |
1272 | ArrayRef<ObjCProtocolDecl *> protocolsToApply = protocolsVec; |
1273 | return Ctx.applyObjCProtocolQualifiers( |
1274 | argType, protocolsToApply, hasError, true); |
1275 | } |
1276 | |
1277 | switch (SubstContext) { |
1278 | case ObjCSubstitutionContext::Ordinary: |
1279 | case ObjCSubstitutionContext::Parameter: |
1280 | case ObjCSubstitutionContext::Superclass: |
1281 | |
1282 | return typeParam->getUnderlyingType(); |
1283 | |
1284 | case ObjCSubstitutionContext::Result: |
1285 | case ObjCSubstitutionContext::Property: { |
1286 | |
1287 | const auto *objPtr = |
1288 | typeParam->getUnderlyingType()->castAs<ObjCObjectPointerType>(); |
1289 | |
1290 | |
1291 | |
1292 | if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType()) |
1293 | return typeParam->getUnderlyingType(); |
1294 | |
1295 | |
1296 | const auto *obj = objPtr->getObjectType(); |
1297 | QualType resultTy = Ctx.getObjCObjectType( |
1298 | obj->getBaseType(), obj->getTypeArgsAsWritten(), obj->getProtocols(), |
1299 | true); |
1300 | |
1301 | |
1302 | return Ctx.getObjCObjectPointerType(resultTy); |
1303 | } |
1304 | } |
1305 | llvm_unreachable("Unexpected ObjCSubstitutionContext!"); |
1306 | } |
1307 | |
1308 | QualType VisitFunctionType(const FunctionType *funcType) { |
1309 | |
1310 | |
1311 | |
1312 | |
1313 | QualType returnType = funcType->getReturnType().substObjCTypeArgs( |
1314 | Ctx, TypeArgs, ObjCSubstitutionContext::Result); |
1315 | if (returnType.isNull()) |
1316 | return {}; |
1317 | |
1318 | |
1319 | |
1320 | if (isa<FunctionNoProtoType>(funcType)) { |
1321 | |
1322 | if (returnType.getAsOpaquePtr() == |
1323 | funcType->getReturnType().getAsOpaquePtr()) |
1324 | return BaseType::VisitFunctionType(funcType); |
1325 | |
1326 | |
1327 | return Ctx.getFunctionNoProtoType(returnType, funcType->getExtInfo()); |
1328 | } |
1329 | |
1330 | const auto *funcProtoType = cast<FunctionProtoType>(funcType); |
1331 | |
1332 | |
1333 | SmallVector<QualType, 4> paramTypes; |
1334 | bool paramChanged = false; |
1335 | for (auto paramType : funcProtoType->getParamTypes()) { |
1336 | QualType newParamType = paramType.substObjCTypeArgs( |
1337 | Ctx, TypeArgs, ObjCSubstitutionContext::Parameter); |
1338 | if (newParamType.isNull()) |
1339 | return {}; |
1340 | |
1341 | if (newParamType.getAsOpaquePtr() != paramType.getAsOpaquePtr()) |
1342 | paramChanged = true; |
1343 | |
1344 | paramTypes.push_back(newParamType); |
1345 | } |
1346 | |
1347 | |
1348 | FunctionProtoType::ExtProtoInfo info = funcProtoType->getExtProtoInfo(); |
1349 | bool exceptionChanged = false; |
1350 | if (info.ExceptionSpec.Type == EST_Dynamic) { |
1351 | SmallVector<QualType, 4> exceptionTypes; |
1352 | for (auto exceptionType : info.ExceptionSpec.Exceptions) { |
1353 | QualType newExceptionType = exceptionType.substObjCTypeArgs( |
1354 | Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary); |
1355 | if (newExceptionType.isNull()) |
1356 | return {}; |
1357 | |
1358 | if (newExceptionType.getAsOpaquePtr() != exceptionType.getAsOpaquePtr()) |
1359 | exceptionChanged = true; |
1360 | |
1361 | exceptionTypes.push_back(newExceptionType); |
1362 | } |
1363 | |
1364 | if (exceptionChanged) { |
1365 | info.ExceptionSpec.Exceptions = |
1366 | llvm::makeArrayRef(exceptionTypes).copy(Ctx); |
1367 | } |
1368 | } |
1369 | |
1370 | if (returnType.getAsOpaquePtr() == |
1371 | funcProtoType->getReturnType().getAsOpaquePtr() && |
1372 | !paramChanged && !exceptionChanged) |
1373 | return BaseType::VisitFunctionType(funcType); |
1374 | |
1375 | return Ctx.getFunctionType(returnType, paramTypes, info); |
1376 | } |
1377 | |
1378 | QualType VisitObjCObjectType(const ObjCObjectType *objcObjectType) { |
1379 | |
1380 | |
1381 | if (objcObjectType->isSpecializedAsWritten()) { |
1382 | SmallVector<QualType, 4> newTypeArgs; |
1383 | bool anyChanged = false; |
1384 | for (auto typeArg : objcObjectType->getTypeArgsAsWritten()) { |
1385 | QualType newTypeArg = typeArg.substObjCTypeArgs( |
1386 | Ctx, TypeArgs, ObjCSubstitutionContext::Ordinary); |
1387 | if (newTypeArg.isNull()) |
1388 | return {}; |
1389 | |
1390 | if (newTypeArg.getAsOpaquePtr() != typeArg.getAsOpaquePtr()) { |
1391 | |
1392 | |
1393 | ArrayRef<ObjCProtocolDecl *> protocols( |
1394 | objcObjectType->qual_begin(), objcObjectType->getNumProtocols()); |
1395 | if (TypeArgs.empty() && |
1396 | SubstContext != ObjCSubstitutionContext::Superclass) { |
1397 | return Ctx.getObjCObjectType( |
1398 | objcObjectType->getBaseType(), {}, protocols, |
1399 | objcObjectType->isKindOfTypeAsWritten()); |
1400 | } |
1401 | |
1402 | anyChanged = true; |
1403 | } |
1404 | |
1405 | newTypeArgs.push_back(newTypeArg); |
1406 | } |
1407 | |
1408 | if (anyChanged) { |
1409 | ArrayRef<ObjCProtocolDecl *> protocols( |
1410 | objcObjectType->qual_begin(), objcObjectType->getNumProtocols()); |
1411 | return Ctx.getObjCObjectType(objcObjectType->getBaseType(), newTypeArgs, |
1412 | protocols, |
1413 | objcObjectType->isKindOfTypeAsWritten()); |
1414 | } |
1415 | } |
1416 | |
1417 | return BaseType::VisitObjCObjectType(objcObjectType); |
1418 | } |
1419 | |
1420 | QualType VisitAttributedType(const AttributedType *attrType) { |
1421 | QualType newType = BaseType::VisitAttributedType(attrType); |
1422 | if (newType.isNull()) |
1423 | return {}; |
1424 | |
1425 | const auto *newAttrType = dyn_cast<AttributedType>(newType.getTypePtr()); |
1426 | if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf) |
1427 | return newType; |
1428 | |
1429 | |
1430 | QualType newEquivType = newAttrType->getEquivalentType(); |
1431 | const ObjCObjectPointerType *ptrType = |
1432 | newEquivType->getAs<ObjCObjectPointerType>(); |
1433 | const ObjCObjectType *objType = ptrType |
1434 | ? ptrType->getObjectType() |
1435 | : newEquivType->getAs<ObjCObjectType>(); |
1436 | if (!objType) |
1437 | return newType; |
1438 | |
1439 | |
1440 | |
1441 | newEquivType = Ctx.getObjCObjectType( |
1442 | objType->getBaseType(), objType->getTypeArgsAsWritten(), |
1443 | objType->getProtocols(), |
1444 | |
1445 | objType->isObjCUnqualifiedId() ? false : true); |
1446 | |
1447 | |
1448 | if (ptrType) |
1449 | newEquivType = Ctx.getObjCObjectPointerType(newEquivType); |
1450 | |
1451 | |
1452 | return Ctx.getAttributedType(newAttrType->getAttrKind(), |
1453 | newAttrType->getModifiedType(), newEquivType); |
1454 | } |
1455 | }; |
1456 | |
1457 | struct StripObjCKindOfTypeVisitor |
1458 | : public SimpleTransformVisitor<StripObjCKindOfTypeVisitor> { |
1459 | using BaseType = SimpleTransformVisitor<StripObjCKindOfTypeVisitor>; |
1460 | |
1461 | explicit StripObjCKindOfTypeVisitor(ASTContext &ctx) : BaseType(ctx) {} |
1462 | |
1463 | QualType VisitObjCObjectType(const ObjCObjectType *objType) { |
1464 | if (!objType->isKindOfType()) |
1465 | return BaseType::VisitObjCObjectType(objType); |
1466 | |
1467 | QualType baseType = objType->getBaseType().stripObjCKindOfType(Ctx); |
1468 | return Ctx.getObjCObjectType(baseType, objType->getTypeArgsAsWritten(), |
1469 | objType->getProtocols(), |
1470 | false); |
1471 | } |
1472 | }; |
1473 | |
1474 | } |
1475 | |
1476 | |
1477 | |
1478 | QualType QualType::substObjCTypeArgs(ASTContext &ctx, |
1479 | ArrayRef<QualType> typeArgs, |
1480 | ObjCSubstitutionContext context) const { |
1481 | SubstObjCTypeArgsVisitor visitor(ctx, typeArgs, context); |
1482 | return visitor.recurse(*this); |
1483 | } |
1484 | |
1485 | QualType QualType::substObjCMemberType(QualType objectType, |
1486 | const DeclContext *dc, |
1487 | ObjCSubstitutionContext context) const { |
1488 | if (auto subs = objectType->getObjCSubstitutions(dc)) |
1489 | return substObjCTypeArgs(dc->getParentASTContext(), *subs, context); |
1490 | |
1491 | return *this; |
1492 | } |
1493 | |
1494 | QualType QualType::stripObjCKindOfType(const ASTContext &constCtx) const { |
1495 | |
1496 | auto &ctx = const_cast<ASTContext &>(constCtx); |
1497 | StripObjCKindOfTypeVisitor visitor(ctx); |
1498 | return visitor.recurse(*this); |
1499 | } |
1500 | |
1501 | QualType QualType::getAtomicUnqualifiedType() const { |
1502 | if (const auto AT = getTypePtr()->getAs<AtomicType>()) |
1503 | return AT->getValueType().getUnqualifiedType(); |
1504 | return getUnqualifiedType(); |
1505 | } |
1506 | |
1507 | Optional<ArrayRef<QualType>> Type::getObjCSubstitutions( |
1508 | const DeclContext *dc) const { |
1509 | |
1510 | if (const auto method = dyn_cast<ObjCMethodDecl>(dc)) |
1511 | dc = method->getDeclContext(); |
1512 | |
1513 | |
1514 | |
1515 | const auto *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc); |
1516 | const ObjCCategoryDecl *dcCategoryDecl = nullptr; |
1517 | ObjCTypeParamList *dcTypeParams = nullptr; |
1518 | if (dcClassDecl) { |
1519 | |
1520 | |
1521 | dcTypeParams = dcClassDecl->getTypeParamList(); |
1522 | if (!dcTypeParams) |
1523 | return None; |
1524 | } else { |
1525 | |
1526 | |
1527 | dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc); |
1528 | if (!dcCategoryDecl) |
1529 | return None; |
1530 | |
1531 | |
1532 | |
1533 | dcTypeParams = dcCategoryDecl->getTypeParamList(); |
1534 | if (!dcTypeParams) |
1535 | return None; |
1536 | |
1537 | dcClassDecl = dcCategoryDecl->getClassInterface(); |
1538 | if (!dcClassDecl) |
1539 | return None; |
1540 | } |
1541 | assert(dcTypeParams && "No substitutions to perform"); |
1542 | assert(dcClassDecl && "No class context"); |
1543 | |
1544 | |
1545 | const ObjCObjectType *objectType; |
1546 | if (const auto *objectPointerType = getAs<ObjCObjectPointerType>()) { |
1547 | objectType = objectPointerType->getObjectType(); |
1548 | } else if (getAs<BlockPointerType>()) { |
1549 | ASTContext &ctx = dc->getParentASTContext(); |
1550 | objectType = ctx.getObjCObjectType(ctx.ObjCBuiltinIdTy, {}, {}) |
1551 | ->castAs<ObjCObjectType>(); |
1552 | } else { |
1553 | objectType = getAs<ObjCObjectType>(); |
1554 | } |
1555 | |
1556 | |
1557 | ObjCInterfaceDecl *curClassDecl = objectType ? objectType->getInterface() |
1558 | : nullptr; |
1559 | if (!curClassDecl) { |
1560 | |
1561 | |
1562 | return llvm::ArrayRef<QualType>(); |
1563 | } |
1564 | |
1565 | |
1566 | |
1567 | while (curClassDecl != dcClassDecl) { |
1568 | |
1569 | QualType superType = objectType->getSuperClassType(); |
1570 | if (superType.isNull()) { |
1571 | objectType = nullptr; |
1572 | break; |
1573 | } |
1574 | |
1575 | objectType = superType->castAs<ObjCObjectType>(); |
1576 | curClassDecl = objectType->getInterface(); |
1577 | } |
1578 | |
1579 | |
1580 | |
1581 | if (!objectType || objectType->isUnspecialized()) { |
1582 | return llvm::ArrayRef<QualType>(); |
1583 | } |
1584 | |
1585 | |
1586 | return objectType->getTypeArgs(); |
1587 | } |
1588 | |
1589 | bool Type::acceptsObjCTypeParams() const { |
1590 | if (auto *IfaceT = getAsObjCInterfaceType()) { |
1591 | if (auto *ID = IfaceT->getInterface()) { |
1592 | if (ID->getTypeParamList()) |
1593 | return true; |
1594 | } |
1595 | } |
1596 | |
1597 | return false; |
1598 | } |
1599 | |
1600 | void ObjCObjectType::computeSuperClassTypeSlow() const { |
1601 | |
1602 | |
1603 | |
1604 | ObjCInterfaceDecl *classDecl = getInterface(); |
1605 | if (!classDecl) { |
1606 | CachedSuperClassType.setInt(true); |
1607 | return; |
1608 | } |
1609 | |
1610 | |
1611 | const ObjCObjectType *superClassObjTy = classDecl->getSuperClassType(); |
1612 | if (!superClassObjTy) { |
1613 | CachedSuperClassType.setInt(true); |
1614 | return; |
1615 | } |
1616 | |
1617 | ObjCInterfaceDecl *superClassDecl = superClassObjTy->getInterface(); |
1618 | if (!superClassDecl) { |
1619 | CachedSuperClassType.setInt(true); |
1620 | return; |
1621 | } |
1622 | |
1623 | |
1624 | |
1625 | QualType superClassType(superClassObjTy, 0); |
1626 | ObjCTypeParamList *superClassTypeParams = superClassDecl->getTypeParamList(); |
1627 | if (!superClassTypeParams) { |
1628 | CachedSuperClassType.setPointerAndInt( |
1629 | superClassType->castAs<ObjCObjectType>(), true); |
1630 | return; |
1631 | } |
1632 | |
1633 | |
1634 | if (superClassObjTy->isUnspecialized()) { |
1635 | CachedSuperClassType.setPointerAndInt(superClassObjTy, true); |
1636 | return; |
1637 | } |
1638 | |
1639 | |
1640 | |
1641 | ObjCTypeParamList *typeParams = classDecl->getTypeParamList(); |
1642 | if (!typeParams) { |
1643 | CachedSuperClassType.setPointerAndInt( |
1644 | superClassType->castAs<ObjCObjectType>(), true); |
1645 | return; |
1646 | } |
1647 | |
1648 | |
1649 | |
1650 | if (isUnspecialized()) { |
1651 | QualType unspecializedSuper |
1652 | = classDecl->getASTContext().getObjCInterfaceType( |
1653 | superClassObjTy->getInterface()); |
1654 | CachedSuperClassType.setPointerAndInt( |
1655 | unspecializedSuper->castAs<ObjCObjectType>(), |
1656 | true); |
1657 | return; |
1658 | } |
1659 | |
1660 | |
1661 | ArrayRef<QualType> typeArgs = getTypeArgs(); |
1662 | assert(typeArgs.size() == typeParams->size()); |
1663 | CachedSuperClassType.setPointerAndInt( |
1664 | superClassType.substObjCTypeArgs(classDecl->getASTContext(), typeArgs, |
1665 | ObjCSubstitutionContext::Superclass) |
1666 | ->castAs<ObjCObjectType>(), |
1667 | true); |
1668 | } |
1669 | |
1670 | const ObjCInterfaceType *ObjCObjectPointerType::getInterfaceType() const { |
1671 | if (auto interfaceDecl = getObjectType()->getInterface()) { |
1672 | return interfaceDecl->getASTContext().getObjCInterfaceType(interfaceDecl) |
1673 | ->castAs<ObjCInterfaceType>(); |
1674 | } |
1675 | |
1676 | return nullptr; |
1677 | } |
1678 | |
1679 | QualType ObjCObjectPointerType::getSuperClassType() const { |
1680 | QualType superObjectType = getObjectType()->getSuperClassType(); |
1681 | if (superObjectType.isNull()) |
1682 | return superObjectType; |
1683 | |
1684 | ASTContext &ctx = getInterfaceDecl()->getASTContext(); |
1685 | return ctx.getObjCObjectPointerType(superObjectType); |
1686 | } |
1687 | |
1688 | const ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const { |
1689 | |
1690 | |
1691 | |
1692 | if (const auto *T = getAs<ObjCObjectType>()) |
1693 | if (T->getNumProtocols() && T->getInterface()) |
1694 | return T; |
1695 | return nullptr; |
1696 | } |
1697 | |
1698 | bool Type::isObjCQualifiedInterfaceType() const { |
1699 | return getAsObjCQualifiedInterfaceType() != nullptr; |
1700 | } |
1701 | |
1702 | const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const { |
1703 | |
1704 | |
1705 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) { |
1706 | if (OPT->isObjCQualifiedIdType()) |
1707 | return OPT; |
1708 | } |
1709 | return nullptr; |
1710 | } |
1711 | |
1712 | const ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const { |
1713 | |
1714 | |
1715 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) { |
1716 | if (OPT->isObjCQualifiedClassType()) |
1717 | return OPT; |
1718 | } |
1719 | return nullptr; |
1720 | } |
1721 | |
1722 | const ObjCObjectType *Type::getAsObjCInterfaceType() const { |
1723 | if (const auto *OT = getAs<ObjCObjectType>()) { |
1724 | if (OT->getInterface()) |
1725 | return OT; |
1726 | } |
1727 | return nullptr; |
1728 | } |
1729 | |
1730 | const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const { |
1731 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) { |
1732 | if (OPT->getInterfaceType()) |
1733 | return OPT; |
1734 | } |
1735 | return nullptr; |
1736 | } |
1737 | |
1738 | const CXXRecordDecl *Type::getPointeeCXXRecordDecl() const { |
1739 | QualType PointeeType; |
1740 | if (const auto *PT = getAs<PointerType>()) |
1741 | PointeeType = PT->getPointeeType(); |
1742 | else if (const auto *RT = getAs<ReferenceType>()) |
1743 | PointeeType = RT->getPointeeType(); |
1744 | else |
1745 | return nullptr; |
1746 | |
1747 | if (const auto *RT = PointeeType->getAs<RecordType>()) |
1748 | return dyn_cast<CXXRecordDecl>(RT->getDecl()); |
1749 | |
1750 | return nullptr; |
1751 | } |
1752 | |
1753 | CXXRecordDecl *Type::getAsCXXRecordDecl() const { |
1754 | return dyn_cast_or_null<CXXRecordDecl>(getAsTagDecl()); |
1755 | } |
1756 | |
1757 | RecordDecl *Type::getAsRecordDecl() const { |
1758 | return dyn_cast_or_null<RecordDecl>(getAsTagDecl()); |
1759 | } |
1760 | |
1761 | TagDecl *Type::getAsTagDecl() const { |
1762 | if (const auto *TT = getAs<TagType>()) |
1763 | return TT->getDecl(); |
1764 | if (const auto *Injected = getAs<InjectedClassNameType>()) |
1765 | return Injected->getDecl(); |
1766 | |
1767 | return nullptr; |
1768 | } |
1769 | |
1770 | bool Type::hasAttr(attr::Kind AK) const { |
1771 | const Type *Cur = this; |
1772 | while (const auto *AT = Cur->getAs<AttributedType>()) { |
1773 | if (AT->getAttrKind() == AK) |
1774 | return true; |
1775 | Cur = AT->getEquivalentType().getTypePtr(); |
1776 | } |
1777 | return false; |
1778 | } |
1779 | |
1780 | namespace { |
1781 | |
1782 | class GetContainedDeducedTypeVisitor : |
1783 | public TypeVisitor<GetContainedDeducedTypeVisitor, Type*> { |
1784 | bool Syntactic; |
1785 | |
1786 | public: |
1787 | GetContainedDeducedTypeVisitor(bool Syntactic = false) |
1788 | : Syntactic(Syntactic) {} |
1789 | |
1790 | using TypeVisitor<GetContainedDeducedTypeVisitor, Type*>::Visit; |
1791 | |
1792 | Type *Visit(QualType T) { |
1793 | if (T.isNull()) |
1794 | return nullptr; |
1795 | return Visit(T.getTypePtr()); |
1796 | } |
1797 | |
1798 | |
1799 | Type *VisitDeducedType(const DeducedType *AT) { |
1800 | return const_cast<DeducedType*>(AT); |
1801 | } |
1802 | |
1803 | |
1804 | Type *VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { |
1805 | return Visit(T->getReplacementType()); |
1806 | } |
1807 | |
1808 | Type *VisitElaboratedType(const ElaboratedType *T) { |
1809 | return Visit(T->getNamedType()); |
1810 | } |
1811 | |
1812 | Type *VisitPointerType(const PointerType *T) { |
1813 | return Visit(T->getPointeeType()); |
1814 | } |
1815 | |
1816 | Type *VisitBlockPointerType(const BlockPointerType *T) { |
1817 | return Visit(T->getPointeeType()); |
1818 | } |
1819 | |
1820 | Type *VisitReferenceType(const ReferenceType *T) { |
1821 | return Visit(T->getPointeeTypeAsWritten()); |
1822 | } |
1823 | |
1824 | Type *VisitMemberPointerType(const MemberPointerType *T) { |
1825 | return Visit(T->getPointeeType()); |
1826 | } |
1827 | |
1828 | Type *VisitArrayType(const ArrayType *T) { |
1829 | return Visit(T->getElementType()); |
1830 | } |
1831 | |
1832 | Type *VisitDependentSizedExtVectorType( |
1833 | const DependentSizedExtVectorType *T) { |
1834 | return Visit(T->getElementType()); |
1835 | } |
1836 | |
1837 | Type *VisitVectorType(const VectorType *T) { |
1838 | return Visit(T->getElementType()); |
1839 | } |
1840 | |
1841 | Type *VisitDependentSizedMatrixType(const DependentSizedMatrixType *T) { |
1842 | return Visit(T->getElementType()); |
1843 | } |
1844 | |
1845 | Type *VisitConstantMatrixType(const ConstantMatrixType *T) { |
1846 | return Visit(T->getElementType()); |
1847 | } |
1848 | |
1849 | Type *VisitFunctionProtoType(const FunctionProtoType *T) { |
1850 | if (Syntactic && T->hasTrailingReturn()) |
1851 | return const_cast<FunctionProtoType*>(T); |
1852 | return VisitFunctionType(T); |
1853 | } |
1854 | |
1855 | Type *VisitFunctionType(const FunctionType *T) { |
1856 | return Visit(T->getReturnType()); |
1857 | } |
1858 | |
1859 | Type *VisitParenType(const ParenType *T) { |
1860 | return Visit(T->getInnerType()); |
1861 | } |
1862 | |
1863 | Type *VisitAttributedType(const AttributedType *T) { |
1864 | return Visit(T->getModifiedType()); |
1865 | } |
1866 | |
1867 | Type *VisitMacroQualifiedType(const MacroQualifiedType *T) { |
1868 | return Visit(T->getUnderlyingType()); |
1869 | } |
1870 | |
1871 | Type *VisitAdjustedType(const AdjustedType *T) { |
1872 | return Visit(T->getOriginalType()); |
1873 | } |
1874 | |
1875 | Type *VisitPackExpansionType(const PackExpansionType *T) { |
1876 | return Visit(T->getPattern()); |
1877 | } |
1878 | }; |
1879 | |
1880 | } |
1881 | |
1882 | DeducedType *Type::getContainedDeducedType() const { |
1883 | return cast_or_null<DeducedType>( |
1884 | GetContainedDeducedTypeVisitor().Visit(this)); |
1885 | } |
1886 | |
1887 | bool Type::hasAutoForTrailingReturnType() const { |
1888 | return dyn_cast_or_null<FunctionType>( |
1889 | GetContainedDeducedTypeVisitor(true).Visit(this)); |
1890 | } |
1891 | |
1892 | bool Type::hasIntegerRepresentation() const { |
1893 | if (const auto *VT = dyn_cast<VectorType>(CanonicalType)) |
1894 | return VT->getElementType()->isIntegerType(); |
1895 | else |
1896 | return isIntegerType(); |
1897 | } |
1898 | |
1899 | |
1900 | |
1901 | |
1902 | |
1903 | |
1904 | |
1905 | |
1906 | |
1907 | |
1908 | |
1909 | |
1910 | |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | bool Type::isIntegralType(const ASTContext &Ctx) const { |
1919 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1920 | return BT->getKind() >= BuiltinType::Bool && |
1921 | BT->getKind() <= BuiltinType::Int128; |
1922 | |
1923 | |
1924 | if (!Ctx.getLangOpts().CPlusPlus) |
1925 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) |
1926 | return ET->getDecl()->isComplete(); |
1927 | |
1928 | return isExtIntType(); |
1929 | } |
1930 | |
1931 | bool Type::isIntegralOrUnscopedEnumerationType() const { |
1932 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1933 | return BT->getKind() >= BuiltinType::Bool && |
1934 | BT->getKind() <= BuiltinType::Int128; |
1935 | |
1936 | if (isExtIntType()) |
1937 | return true; |
1938 | |
1939 | return isUnscopedEnumerationType(); |
1940 | } |
1941 | |
1942 | bool Type::isUnscopedEnumerationType() const { |
1943 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) |
1944 | return !ET->getDecl()->isScoped(); |
1945 | |
1946 | return false; |
1947 | } |
1948 | |
1949 | bool Type::isCharType() const { |
1950 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1951 | return BT->getKind() == BuiltinType::Char_U || |
1952 | BT->getKind() == BuiltinType::UChar || |
1953 | BT->getKind() == BuiltinType::Char_S || |
1954 | BT->getKind() == BuiltinType::SChar; |
1955 | return false; |
1956 | } |
1957 | |
1958 | bool Type::isWideCharType() const { |
1959 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1960 | return BT->getKind() == BuiltinType::WChar_S || |
1961 | BT->getKind() == BuiltinType::WChar_U; |
1962 | return false; |
1963 | } |
1964 | |
1965 | bool Type::isChar8Type() const { |
1966 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1967 | return BT->getKind() == BuiltinType::Char8; |
1968 | return false; |
1969 | } |
1970 | |
1971 | bool Type::isChar16Type() const { |
1972 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1973 | return BT->getKind() == BuiltinType::Char16; |
1974 | return false; |
1975 | } |
1976 | |
1977 | bool Type::isChar32Type() const { |
1978 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
1979 | return BT->getKind() == BuiltinType::Char32; |
1980 | return false; |
1981 | } |
1982 | |
1983 | |
1984 | |
1985 | bool Type::isAnyCharacterType() const { |
1986 | const auto *BT = dyn_cast<BuiltinType>(CanonicalType); |
1987 | if (!BT) return false; |
1988 | switch (BT->getKind()) { |
1989 | default: return false; |
1990 | case BuiltinType::Char_U: |
1991 | case BuiltinType::UChar: |
1992 | case BuiltinType::WChar_U: |
1993 | case BuiltinType::Char8: |
1994 | case BuiltinType::Char16: |
1995 | case BuiltinType::Char32: |
1996 | case BuiltinType::Char_S: |
1997 | case BuiltinType::SChar: |
1998 | case BuiltinType::WChar_S: |
1999 | return true; |
2000 | } |
2001 | } |
2002 | |
2003 | |
2004 | |
2005 | |
2006 | bool Type::isSignedIntegerType() const { |
2007 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
2008 | return BT->getKind() >= BuiltinType::Char_S && |
2009 | BT->getKind() <= BuiltinType::Int128; |
2010 | } |
2011 | |
2012 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { |
2013 | |
2014 | |
2015 | if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) |
2016 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
2017 | } |
2018 | |
2019 | if (const ExtIntType *IT = dyn_cast<ExtIntType>(CanonicalType)) |
2020 | return IT->isSigned(); |
2021 | |
2022 | return false; |
2023 | } |
2024 | |
2025 | bool Type::isSignedIntegerOrEnumerationType() const { |
2026 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
2027 | return BT->getKind() >= BuiltinType::Char_S && |
2028 | BT->getKind() <= BuiltinType::Int128; |
2029 | } |
2030 | |
2031 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) { |
2032 | if (ET->getDecl()->isComplete()) |
2033 | return ET->getDecl()->getIntegerType()->isSignedIntegerType(); |
2034 | } |
2035 | |
2036 | if (const ExtIntType *IT = dyn_cast<ExtIntType>(CanonicalType)) |
2037 | return IT->isSigned(); |
2038 | |
2039 | |
2040 | return false; |
2041 | } |
2042 | |
2043 | bool Type::hasSignedIntegerRepresentation() const { |
2044 | if (const auto *VT = dyn_cast<VectorType>(CanonicalType)) |
2045 | return VT->getElementType()->isSignedIntegerOrEnumerationType(); |
2046 | else |
2047 | return isSignedIntegerOrEnumerationType(); |
2048 | } |
2049 | |
2050 | |
2051 | |
2052 | |
2053 | bool Type::isUnsignedIntegerType() const { |
2054 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
2055 | return BT->getKind() >= BuiltinType::Bool && |
2056 | BT->getKind() <= BuiltinType::UInt128; |
2057 | } |
2058 | |
2059 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) { |
2060 | |
2061 | |
2062 | if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) |
2063 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
2064 | } |
2065 | |
2066 | if (const ExtIntType *IT = dyn_cast<ExtIntType>(CanonicalType)) |
2067 | return IT->isUnsigned(); |
2068 | |
2069 | return false; |
2070 | } |
2071 | |
2072 | bool Type::isUnsignedIntegerOrEnumerationType() const { |
2073 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
2074 | return BT->getKind() >= BuiltinType::Bool && |
2075 | BT->getKind() <= BuiltinType::UInt128; |
2076 | } |
2077 | |
2078 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) { |
2079 | if (ET->getDecl()->isComplete()) |
2080 | return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); |
2081 | } |
2082 | |
2083 | if (const ExtIntType *IT = dyn_cast<ExtIntType>(CanonicalType)) |
2084 | return IT->isUnsigned(); |
2085 | |
2086 | return false; |
2087 | } |
2088 | |
2089 | bool Type::hasUnsignedIntegerRepresentation() const { |
2090 | if (const auto *VT = dyn_cast<VectorType>(CanonicalType)) |
2091 | return VT->getElementType()->isUnsignedIntegerOrEnumerationType(); |
2092 | if (const auto *VT = dyn_cast<MatrixType>(CanonicalType)) |
2093 | return VT->getElementType()->isUnsignedIntegerOrEnumerationType(); |
2094 | return isUnsignedIntegerOrEnumerationType(); |
2095 | } |
2096 | |
2097 | bool Type::isFloatingType() const { |
2098 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
2099 | return BT->getKind() >= BuiltinType::Half && |
2100 | BT->getKind() <= BuiltinType::Float128; |
2101 | if (const auto *CT = dyn_cast<ComplexType>(CanonicalType)) |
2102 | return CT->getElementType()->isFloatingType(); |
2103 | return false; |
2104 | } |
2105 | |
2106 | bool Type::hasFloatingRepresentation() const { |
2107 | if (const auto *VT = dyn_cast<VectorType>(CanonicalType)) |
2108 | return VT->getElementType()->isFloatingType(); |
2109 | else |
2110 | return isFloatingType(); |
2111 | } |
2112 | |
2113 | bool Type::isRealFloatingType() const { |
2114 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
2115 | return BT->isFloatingPoint(); |
2116 | return false; |
2117 | } |
2118 | |
2119 | bool Type::isRealType() const { |
2120 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
2121 | return BT->getKind() >= BuiltinType::Bool && |
2122 | BT->getKind() <= BuiltinType::Float128; |
2123 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) |
2124 | return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); |
2125 | return isExtIntType(); |
2126 | } |
2127 | |
2128 | bool Type::isArithmeticType() const { |
2129 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
2130 | return BT->getKind() >= BuiltinType::Bool && |
2131 | BT->getKind() <= BuiltinType::Float128 && |
2132 | BT->getKind() != BuiltinType::BFloat16; |
2133 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) |
2134 | |
2135 | |
2136 | |
2137 | |
2138 | |
2139 | |
2140 | return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete(); |
2141 | return isa<ComplexType>(CanonicalType) || isExtIntType(); |
2142 | } |
2143 | |
2144 | Type::ScalarTypeKind Type::getScalarTypeKind() const { |
2145 | assert(isScalarType()); |
2146 | |
2147 | const Type *T = CanonicalType.getTypePtr(); |
2148 | if (const auto *BT = dyn_cast<BuiltinType>(T)) { |
2149 | if (BT->getKind() == BuiltinType::Bool) return STK_Bool; |
2150 | if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer; |
2151 | if (BT->isInteger()) return STK_Integral; |
2152 | if (BT->isFloatingPoint()) return STK_Floating; |
2153 | if (BT->isFixedPointType()) return STK_FixedPoint; |
2154 | llvm_unreachable("unknown scalar builtin type"); |
2155 | } else if (isa<PointerType>(T)) { |
2156 | return STK_CPointer; |
2157 | } else if (isa<BlockPointerType>(T)) { |
2158 | return STK_BlockPointer; |
2159 | } else if (isa<ObjCObjectPointerType>(T)) { |
2160 | return STK_ObjCObjectPointer; |
2161 | } else if (isa<MemberPointerType>(T)) { |
2162 | return STK_MemberPointer; |
2163 | } else if (isa<EnumType>(T)) { |
2164 | assert(cast<EnumType>(T)->getDecl()->isComplete()); |
2165 | return STK_Integral; |
2166 | } else if (const auto *CT = dyn_cast<ComplexType>(T)) { |
2167 | if (CT->getElementType()->isRealFloatingType()) |
2168 | return STK_FloatingComplex; |
2169 | return STK_IntegralComplex; |
2170 | } else if (isExtIntType()) { |
2171 | return STK_Integral; |
2172 | } |
2173 | |
2174 | llvm_unreachable("unknown scalar type"); |
2175 | } |
2176 | |
2177 | |
2178 | |
2179 | |
2180 | |
2181 | |
2182 | |
2183 | |
2184 | |
2185 | |
2186 | bool Type::isAggregateType() const { |
2187 | if (const auto *Record = dyn_cast<RecordType>(CanonicalType)) { |
2188 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl())) |
2189 | return ClassDecl->isAggregate(); |
2190 | |
2191 | return true; |
2192 | } |
2193 | |
2194 | return isa<ArrayType>(CanonicalType); |
2195 | } |
2196 | |
2197 | |
2198 | |
2199 | |
2200 | bool Type::isConstantSizeType() const { |
2201 | assert(!isIncompleteType() && "This doesn't make sense for incomplete types"); |
2202 | assert(!isDependentType() && "This doesn't make sense for dependent types"); |
2203 | |
2204 | return !isa<VariableArrayType>(CanonicalType); |
2205 | } |
2206 | |
2207 | |
2208 | |
2209 | |
2210 | bool Type::isIncompleteType(NamedDecl **Def) const { |
2211 | if (Def) |
2212 | *Def = nullptr; |
2213 | |
2214 | switch (CanonicalType->getTypeClass()) { |
2215 | default: return false; |
2216 | case Builtin: |
2217 | |
2218 | |
2219 | return isVoidType(); |
2220 | case Enum: { |
2221 | EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl(); |
2222 | if (Def) |
2223 | *Def = EnumD; |
2224 | return !EnumD->isComplete(); |
2225 | } |
2226 | case Record: { |
2227 | |
2228 | |
2229 | RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl(); |
2230 | if (Def) |
2231 | *Def = Rec; |
2232 | return !Rec->isCompleteDefinition(); |
2233 | } |
2234 | case ConstantArray: |
2235 | case VariableArray: |
2236 | |
2237 | |
2238 | |
2239 | |
2240 | return cast<ArrayType>(CanonicalType)->getElementType() |
2241 | ->isIncompleteType(Def); |
2242 | case IncompleteArray: |
2243 | |
2244 | return true; |
2245 | case MemberPointer: { |
2246 | |
2247 | |
2248 | |
2249 | auto *MPTy = cast<MemberPointerType>(CanonicalType); |
2250 | const Type *ClassTy = MPTy->getClass(); |
2251 | |
2252 | if (ClassTy->isDependentType()) |
2253 | return false; |
2254 | const CXXRecordDecl *RD = ClassTy->getAsCXXRecordDecl(); |
2255 | ASTContext &Context = RD->getASTContext(); |
2256 | |
2257 | if (!Context.getTargetInfo().getCXXABI().isMicrosoft()) |
2258 | return false; |
2259 | |
2260 | |
2261 | RD = RD->getMostRecentNonInjectedDecl(); |
2262 | |
2263 | if (RD->hasAttr<MSInheritanceAttr>()) |
2264 | return false; |
2265 | return true; |
2266 | } |
2267 | case ObjCObject: |
2268 | return cast<ObjCObjectType>(CanonicalType)->getBaseType() |
2269 | ->isIncompleteType(Def); |
2270 | case ObjCInterface: { |
2271 | |
2272 | ObjCInterfaceDecl *Interface |
2273 | = cast<ObjCInterfaceType>(CanonicalType)->getDecl(); |
2274 | if (Def) |
2275 | *Def = Interface; |
2276 | return !Interface->hasDefinition(); |
2277 | } |
2278 | } |
2279 | } |
2280 | |
2281 | bool Type::isSizelessBuiltinType() const { |
2282 | if (const BuiltinType *BT = getAs<BuiltinType>()) { |
2283 | switch (BT->getKind()) { |
2284 | |
2285 | #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: |
2286 | #include "clang/Basic/AArch64SVEACLETypes.def" |
2287 | #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id: |
2288 | #include "clang/Basic/RISCVVTypes.def" |
2289 | return true; |
2290 | default: |
2291 | return false; |
2292 | } |
2293 | } |
2294 | return false; |
2295 | } |
2296 | |
2297 | bool Type::isSizelessType() const { return isSizelessBuiltinType(); } |
2298 | |
2299 | bool Type::isVLSTBuiltinType() const { |
2300 | if (const BuiltinType *BT = getAs<BuiltinType>()) { |
2301 | switch (BT->getKind()) { |
2302 | case BuiltinType::SveInt8: |
2303 | case BuiltinType::SveInt16: |
2304 | case BuiltinType::SveInt32: |
2305 | case BuiltinType::SveInt64: |
2306 | case BuiltinType::SveUint8: |
2307 | case BuiltinType::SveUint16: |
2308 | case BuiltinType::SveUint32: |
2309 | case BuiltinType::SveUint64: |
2310 | case BuiltinType::SveFloat16: |
2311 | case BuiltinType::SveFloat32: |
2312 | case BuiltinType::SveFloat64: |
2313 | case BuiltinType::SveBFloat16: |
2314 | case BuiltinType::SveBool: |
2315 | return true; |
2316 | default: |
2317 | return false; |
2318 | } |
2319 | } |
2320 | return false; |
2321 | } |
2322 | |
2323 | QualType Type::getSveEltType(const ASTContext &Ctx) const { |
2324 | assert(isVLSTBuiltinType() && "unsupported type!"); |
2325 | |
2326 | const BuiltinType *BTy = getAs<BuiltinType>(); |
| 1 | Assuming the object is not a 'BuiltinType' | |
|
| 2 | | 'BTy' initialized to a null pointer value | |
|
2327 | if (BTy->getKind() == BuiltinType::SveBool) |
| 3 | | Called C++ object pointer is null |
|
2328 | |
2329 | |
2330 | |
2331 | return Ctx.UnsignedCharTy; |
2332 | else |
2333 | return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType; |
2334 | } |
2335 | |
2336 | bool QualType::isPODType(const ASTContext &Context) const { |
2337 | |
2338 | if (Context.getLangOpts().CPlusPlus11) |
2339 | return isCXX11PODType(Context); |
2340 | |
2341 | return isCXX98PODType(Context); |
2342 | } |
2343 | |
2344 | bool QualType::isCXX98PODType(const ASTContext &Context) const { |
2345 | |
2346 | |
2347 | |
2348 | if (isNull()) |
2349 | return false; |
2350 | |
2351 | if ((*this)->isIncompleteArrayType()) |
2352 | return Context.getBaseElementType(*this).isCXX98PODType(Context); |
2353 | |
2354 | if ((*this)->isIncompleteType()) |
2355 | return false; |
2356 | |
2357 | if (hasNonTrivialObjCLifetime()) |
2358 | return false; |
2359 | |
2360 | QualType CanonicalType = getTypePtr()->CanonicalType; |
2361 | switch (CanonicalType->getTypeClass()) { |
2362 | |
2363 | default: return false; |
2364 | case Type::VariableArray: |
2365 | case Type::ConstantArray: |
2366 | |
2367 | return Context.getBaseElementType(*this).isCXX98PODType(Context); |
2368 | |
2369 | case Type::ObjCObjectPointer: |
2370 | case Type::BlockPointer: |
2371 | case Type::Builtin: |
2372 | case Type::Complex: |
2373 | case Type::Pointer: |
2374 | case Type::MemberPointer: |
2375 | case Type::Vector: |
2376 | case Type::ExtVector: |
2377 | case Type::ExtInt: |
2378 | return true; |
2379 | |
2380 | case Type::Enum: |
2381 | return true; |
2382 | |
2383 | case Type::Record: |
2384 | if (const auto *ClassDecl = |
2385 | dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl())) |
2386 | return ClassDecl->isPOD(); |
2387 | |
2388 | |
2389 | return true; |
2390 | } |
2391 | } |
2392 | |
2393 | bool QualType::isTrivialType(const ASTContext &Context) const { |
2394 | |
2395 | |
2396 | |
2397 | if (isNull()) |
2398 | return false; |
2399 | |
2400 | if ((*this)->isArrayType()) |
2401 | return Context.getBaseElementType(*this).isTrivialType(Context); |
2402 | |
2403 | if ((*this)->isSizelessBuiltinType()) |
2404 | return true; |
2405 | |
2406 | |
2407 | |
2408 | if ((*this)->isIncompleteType()) |
2409 | return false; |
2410 | |
2411 | if (hasNonTrivialObjCLifetime()) |
2412 | return false; |
2413 | |
2414 | QualType CanonicalType = getTypePtr()->CanonicalType; |
2415 | if (CanonicalType->isDependentType()) |
2416 | return false; |
2417 | |
2418 | |
2419 | |
2420 | |
2421 | |
2422 | |
2423 | |
2424 | if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) |
2425 | return true; |
2426 | if (const auto *RT = CanonicalType->getAs<RecordType>()) { |
2427 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) { |
2428 | |
2429 | |
2430 | |
2431 | |
2432 | return ClassDecl->hasDefaultConstructor() && |
2433 | !ClassDecl->hasNonTrivialDefaultConstructor() && |
2434 | ClassDecl->isTriviallyCopyable(); |
2435 | } |
2436 | |
2437 | return true; |
2438 | } |
2439 | |
2440 | |
2441 | return false; |
2442 | } |
2443 | |
2444 | bool QualType::isTriviallyCopyableType(const ASTContext &Context) const { |
2445 | if ((*this)->isArrayType()) |
2446 | return Context.getBaseElementType(*this).isTriviallyCopyableType(Context); |
2447 | |
2448 | if (hasNonTrivialObjCLifetime()) |
2449 | return false; |
2450 | |
2451 | |
2452 | |
2453 | |
2454 | |
2455 | |
2456 | QualType CanonicalType = getCanonicalType(); |
2457 | if (CanonicalType->isDependentType()) |
2458 | return false; |
2459 | |
2460 | if (CanonicalType->isSizelessBuiltinType()) |
2461 | return true; |
2462 | |
2463 | |
2464 | |
2465 | if (CanonicalType->isIncompleteType()) |
2466 | return false; |
2467 | |
2468 | |
2469 | if (CanonicalType->isScalarType() || CanonicalType->isVectorType()) |
2470 | return true; |
2471 | |
2472 | if (const auto *RT = CanonicalType->getAs<RecordType>()) { |
2473 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) { |
2474 | if (!ClassDecl->isTriviallyCopyable()) return false; |
2475 | } |
2476 | |
2477 | return true; |
2478 | } |
2479 | |
2480 | |
2481 | return false; |
2482 | } |
2483 | |
2484 | bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const { |
2485 | return !Context.getLangOpts().ObjCAutoRefCount && |
2486 | Context.getLangOpts().ObjCWeak && |
2487 | getObjCLifetime() != Qualifiers::OCL_Weak; |
2488 | } |
2489 | |
2490 | bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion(const RecordDecl *RD) { |
2491 | return RD->hasNonTrivialToPrimitiveDefaultInitializeCUnion(); |
2492 | } |
2493 | |
2494 | bool QualType::hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD) { |
2495 | return RD->hasNonTrivialToPrimitiveDestructCUnion(); |
2496 | } |
2497 | |
2498 | bool QualType::hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD) { |
2499 | return RD->hasNonTrivialToPrimitiveCopyCUnion(); |
2500 | } |
2501 | |
2502 | QualType::PrimitiveDefaultInitializeKind |
2503 | QualType::isNonTrivialToPrimitiveDefaultInitialize() const { |
2504 | if (const auto *RT = |
2505 | getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>()) |
2506 | if (RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize()) |
2507 | return PDIK_Struct; |
2508 | |
2509 | switch (getQualifiers().getObjCLifetime()) { |
2510 | case Qualifiers::OCL_Strong: |
2511 | return PDIK_ARCStrong; |
2512 | case Qualifiers::OCL_Weak: |
2513 | return PDIK_ARCWeak; |
2514 | default: |
2515 | return PDIK_Trivial; |
2516 | } |
2517 | } |
2518 | |
2519 | QualType::PrimitiveCopyKind QualType::isNonTrivialToPrimitiveCopy() const { |
2520 | if (const auto *RT = |
2521 | getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>()) |
2522 | if (RT->getDecl()->isNonTrivialToPrimitiveCopy()) |
2523 | return PCK_Struct; |
2524 | |
2525 | Qualifiers Qs = getQualifiers(); |
2526 | switch (Qs.getObjCLifetime()) { |
2527 | case Qualifiers::OCL_Strong: |
2528 | return PCK_ARCStrong; |
2529 | case Qualifiers::OCL_Weak: |
2530 | return PCK_ARCWeak; |
2531 | default: |
2532 | return Qs.hasVolatile() ? PCK_VolatileTrivial : PCK_Trivial; |
2533 | } |
2534 | } |
2535 | |
2536 | QualType::PrimitiveCopyKind |
2537 | QualType::isNonTrivialToPrimitiveDestructiveMove() const { |
2538 | return isNonTrivialToPrimitiveCopy(); |
2539 | } |
2540 | |
2541 | bool Type::isLiteralType(const ASTContext &Ctx) const { |
2542 | if (isDependentType()) |
2543 | return false; |
2544 | |
2545 | |
2546 | |
2547 | |
2548 | if (Ctx.getLangOpts().CPlusPlus14 && isVoidType()) |
2549 | return true; |
2550 | |
2551 | |
2552 | |
2553 | |
2554 | |
2555 | if (isVariableArrayType()) |
2556 | return false; |
2557 | const Type *BaseTy = getBaseElementTypeUnsafe(); |
2558 | assert(BaseTy && "NULL element type"); |
2559 | |
2560 | |
2561 | |
2562 | if (BaseTy->isIncompleteType()) |
2563 | return false; |
2564 | |
2565 | |
2566 | |
2567 | |
2568 | |
2569 | |
2570 | if (BaseTy->isScalarType() || BaseTy->isVectorType() || |
2571 | BaseTy->isAnyComplexType()) |
2572 | return true; |
2573 | |
2574 | if (BaseTy->isReferenceType()) |
2575 | return true; |
2576 | |
2577 | if (const auto *RT = BaseTy->getAs<RecordType>()) { |
2578 | |
2579 | |
2580 | |
2581 | |
2582 | |
2583 | |
2584 | |
2585 | |
2586 | |
2587 | |
2588 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) |
2589 | return ClassDecl->isLiteral(); |
2590 | |
2591 | return true; |
2592 | } |
2593 | |
2594 | |
2595 | if (const auto *AT = BaseTy->getAs<AtomicType>()) |
2596 | return AT->getValueType()->isLiteralType(Ctx); |
2597 | |
2598 | |
2599 | |
2600 | if (isa<AutoType>(BaseTy->getCanonicalTypeInternal())) |
2601 | return true; |
2602 | |
2603 | return false; |
2604 | } |
2605 | |
2606 | bool Type::isStructuralType() const { |
2607 | |
2608 | |
2609 | |
2610 | |
2611 | if (isScalarType() || isVectorType()) |
2612 | return true; |
2613 | |
2614 | if (isLValueReferenceType()) |
2615 | return true; |
2616 | |
2617 | if (const CXXRecordDecl *RD = getAsCXXRecordDecl()) |
2618 | return RD->isStructural(); |
2619 | return false; |
2620 | } |
2621 | |
2622 | bool Type::isStandardLayoutType() const { |
2623 | if (isDependentType()) |
2624 | return false; |
2625 | |
2626 | |
2627 | |
2628 | |
2629 | |
2630 | const Type *BaseTy = getBaseElementTypeUnsafe(); |
2631 | assert(BaseTy && "NULL element type"); |
2632 | |
2633 | |
2634 | |
2635 | if (BaseTy->isIncompleteType()) |
2636 | return false; |
2637 | |
2638 | |
2639 | if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; |
2640 | if (const auto *RT = BaseTy->getAs<RecordType>()) { |
2641 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) |
2642 | if (!ClassDecl->isStandardLayout()) |
2643 | return false; |
2644 | |
2645 | |
2646 | |
2647 | |
2648 | return true; |
2649 | } |
2650 | |
2651 | |
2652 | return false; |
2653 | } |
2654 | |
2655 | |
2656 | |
2657 | |
2658 | bool QualType::isCXX11PODType(const ASTContext &Context) const { |
2659 | const Type *ty = getTypePtr(); |
2660 | if (ty->isDependentType()) |
2661 | return false; |
2662 | |
2663 | if (hasNonTrivialObjCLifetime()) |
2664 | return false; |
2665 | |
2666 | |
2667 | |
2668 | |
2669 | const Type *BaseTy = ty->getBaseElementTypeUnsafe(); |
2670 | assert(BaseTy && "NULL element type"); |
2671 | |
2672 | if (BaseTy->isSizelessBuiltinType()) |
2673 | return true; |
2674 | |
2675 | |
2676 | |
2677 | if (BaseTy->isIncompleteType()) |
2678 | return false; |
2679 | |
2680 | |
2681 | if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true; |
2682 | if (const auto *RT = BaseTy->getAs<RecordType>()) { |
2683 | if (const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) { |
2684 | |
2685 | |
2686 | if (!ClassDecl->isTrivial()) return false; |
2687 | |
2688 | |
2689 | |
2690 | |
2691 | if (!ClassDecl->isStandardLayout()) return false; |
2692 | |
2693 | |
2694 | |
2695 | |
2696 | |
2697 | |
2698 | |
2699 | |
2700 | |
2701 | } |
2702 | |
2703 | return true; |
2704 | } |
2705 | |
2706 | |
2707 | return false; |
2708 | } |
2709 | |
2710 | bool Type::isNothrowT() const { |
2711 | if (const auto *RD = getAsCXXRecordDecl()) { |
2712 | IdentifierInfo *II = RD->getIdentifier(); |
2713 | if (II && II->isStr("nothrow_t") && RD->isInStdNamespace()) |
2714 | return true; |
2715 | } |
2716 | return false; |
2717 | } |
2718 | |
2719 | bool Type::isAlignValT() const { |
2720 | if (const auto *ET = getAs<EnumType>()) { |
2721 | IdentifierInfo *II = ET->getDecl()->getIdentifier(); |
2722 | if (II && II->isStr("align_val_t") && ET->getDecl()->isInStdNamespace()) |
2723 | return true; |
2724 | } |
2725 | return false; |
2726 | } |
2727 | |
2728 | bool Type::isStdByteType() const { |
2729 | if (const auto *ET = getAs<EnumType>()) { |
2730 | IdentifierInfo *II = ET->getDecl()->getIdentifier(); |
2731 | if (II && II->isStr("byte") && ET->getDecl()->isInStdNamespace()) |
2732 | return true; |
2733 | } |
2734 | return false; |
2735 | } |
2736 | |
2737 | bool Type::isPromotableIntegerType() const { |
2738 | if (const auto *BT = getAs<BuiltinType>()) |
2739 | switch (BT->getKind()) { |
2740 | case BuiltinType::Bool: |
2741 | case BuiltinType::Char_S: |
2742 | case BuiltinType::Char_U: |
2743 | case BuiltinType::SChar: |
2744 | case BuiltinType::UChar: |
2745 | case BuiltinType::Short: |
2746 | case BuiltinType::UShort: |
2747 | case BuiltinType::WChar_S: |
2748 | case BuiltinType::WChar_U: |
2749 | case BuiltinType::Char8: |
2750 | case BuiltinType::Char16: |
2751 | case BuiltinType::Char32: |
2752 | return true; |
2753 | default: |
2754 | return false; |
2755 | } |
2756 | |
2757 | |
2758 | |
2759 | if (const auto *ET = getAs<EnumType>()){ |
2760 | if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull() |
2761 | || ET->getDecl()->isScoped()) |
2762 | return false; |
2763 | |
2764 | return true; |
2765 | } |
2766 | |
2767 | return false; |
2768 | } |
2769 | |
2770 | bool Type::isSpecifierType() const { |
2771 | |
2772 | switch (getTypeClass()) { |
2773 | case Builtin: |
2774 | case Record: |
2775 | case Enum: |
2776 | case Typedef: |
2777 | case Complex: |
2778 | case TypeOfExpr: |
2779 | case TypeOf: |
2780 | case TemplateTypeParm: |
2781 | case SubstTemplateTypeParm: |
2782 | case TemplateSpecialization: |
2783 | case Elaborated: |
2784 | case DependentName: |
2785 | case DependentTemplateSpecialization: |
2786 | case ObjCInterface: |
2787 | case ObjCObject: |
2788 | case ObjCObjectPointer: |
2789 | return true; |
2790 | default: |
2791 | return false; |
2792 | } |
2793 | } |
2794 | |
2795 | ElaboratedTypeKeyword |
2796 | TypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) { |
2797 | switch (TypeSpec) { |
2798 | default: return ETK_None; |
2799 | case TST_typename: return ETK_Typename; |
2800 | case TST_class: return ETK_Class; |
2801 | case TST_struct: return ETK_Struct; |
2802 | case TST_interface: return ETK_Interface; |
2803 | case TST_union: return ETK_Union; |
2804 | case TST_enum: return ETK_Enum; |
2805 | } |
2806 | } |
2807 | |
2808 | TagTypeKind |
2809 | TypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) { |
2810 | switch(TypeSpec) { |
2811 | case TST_class: return TTK_Class; |
2812 | case TST_struct: return TTK_Struct; |
2813 | case TST_interface: return TTK_Interface; |
2814 | case TST_union: return TTK_Union; |
2815 | case TST_enum: return TTK_Enum; |
2816 | } |
2817 | |
2818 | llvm_unreachable("Type specifier is not a tag type kind."); |
2819 | } |
2820 | |
2821 | ElaboratedTypeKeyword |
2822 | TypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) { |
2823 | switch (Kind) { |
2824 | case TTK_Class: return ETK_Class; |
2825 | case TTK_Struct: return ETK_Struct; |
2826 | case TTK_Interface: return ETK_Interface; |
2827 | case TTK_Union: return ETK_Union; |
2828 | case TTK_Enum: return ETK_Enum; |
2829 | } |
2830 | llvm_unreachable("Unknown tag type kind."); |
2831 | } |
2832 | |
2833 | TagTypeKind |
2834 | TypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) { |
2835 | switch (Keyword) { |
2836 | case ETK_Class: return TTK_Class; |
2837 | case ETK_Struct: return TTK_Struct; |
2838 | case ETK_Interface: return TTK_Interface; |
2839 | case ETK_Union: return TTK_Union; |
2840 | case ETK_Enum: return TTK_Enum; |
2841 | case ETK_None: |
2842 | case ETK_Typename: |
2843 | llvm_unreachable("Elaborated type keyword is not a tag type kind."); |
2844 | } |
2845 | llvm_unreachable("Unknown elaborated type keyword."); |
2846 | } |
2847 | |
2848 | bool |
2849 | TypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) { |
2850 | switch (Keyword) { |
2851 | case ETK_None: |
2852 | case ETK_Typename: |
2853 | return false; |
2854 | case ETK_Class: |
2855 | case ETK_Struct: |
2856 | case ETK_Interface: |
2857 | case ETK_Union: |
2858 | case ETK_Enum: |
2859 | return true; |
2860 | } |
2861 | llvm_unreachable("Unknown elaborated type keyword."); |
2862 | } |
2863 | |
2864 | StringRef TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) { |
2865 | switch (Keyword) { |
2866 | case ETK_None: return {}; |
2867 | case ETK_Typename: return "typename"; |
2868 | case ETK_Class: return "class"; |
2869 | case ETK_Struct: return "struct"; |
2870 | case ETK_Interface: return "__interface"; |
2871 | case ETK_Union: return "union"; |
2872 | case ETK_Enum: return "enum"; |
2873 | } |
2874 | |
2875 | llvm_unreachable("Unknown elaborated type keyword."); |
2876 | } |
2877 | |
2878 | DependentTemplateSpecializationType::DependentTemplateSpecializationType( |
2879 | ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, |
2880 | const IdentifierInfo *Name, ArrayRef<TemplateArgument> Args, QualType Canon) |
2881 | : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, |
2882 | TypeDependence::DependentInstantiation | |
2883 | (NNS ? toTypeDependence(NNS->getDependence()) |
2884 | : TypeDependence::None)), |
2885 | NNS(NNS), Name(Name) { |
2886 | DependentTemplateSpecializationTypeBits.NumArgs = Args.size(); |
2887 | assert((!NNS || NNS->isDependent()) && |
2888 | "DependentTemplateSpecializatonType requires dependent qualifier"); |
2889 | TemplateArgument *ArgBuffer = getArgBuffer(); |
2890 | for (const TemplateArgument &Arg : Args) { |
2891 | addDependence(toTypeDependence(Arg.getDependence() & |
2892 | TemplateArgumentDependence::UnexpandedPack)); |
2893 | |
2894 | new (ArgBuffer++) TemplateArgument(Arg); |
2895 | } |
2896 | } |
2897 | |
2898 | void |
2899 | DependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, |
2900 | const ASTContext &Context, |
2901 | ElaboratedTypeKeyword Keyword, |
2902 | NestedNameSpecifier *Qualifier, |
2903 | const IdentifierInfo *Name, |
2904 | ArrayRef<TemplateArgument> Args) { |
2905 | ID.AddInteger(Keyword); |
2906 | ID.AddPointer(Qualifier); |
2907 | ID.AddPointer(Name); |
2908 | for (const TemplateArgument &Arg : Args) |
2909 | Arg.Profile(ID, Context); |
2910 | } |
2911 | |
2912 | bool Type::isElaboratedTypeSpecifier() const { |
2913 | ElaboratedTypeKeyword Keyword; |
2914 | if (const auto *Elab = dyn_cast<ElaboratedType>(this)) |
2915 | Keyword = Elab->getKeyword(); |
2916 | else if (const auto *DepName = dyn_cast<DependentNameType>(this)) |
2917 | Keyword = DepName->getKeyword(); |
2918 | else if (const auto *DepTST = |
2919 | dyn_cast<DependentTemplateSpecializationType>(this)) |
2920 | Keyword = DepTST->getKeyword(); |
2921 | else |
2922 | return false; |
2923 | |
2924 | return TypeWithKeyword::KeywordIsTagTypeKind(Keyword); |
2925 | } |
2926 | |
2927 | const char *Type::getTypeClassName() const { |
2928 | switch (TypeBits.TC) { |
2929 | #define ABSTRACT_TYPE(Derived, Base) |
2930 | #define TYPE(Derived, Base) case Derived: return #Derived; |
2931 | #include "clang/AST/TypeNodes.inc" |
2932 | } |
2933 | |
2934 | llvm_unreachable("Invalid type class."); |
2935 | } |
2936 | |
2937 | StringRef BuiltinType::getName(const PrintingPolicy &Policy) const { |
2938 | switch (getKind()) { |
2939 | case Void: |
2940 | return "void"; |
2941 | case Bool: |
2942 | return Policy.Bool ? "bool" : "_Bool"; |
2943 | case Char_S: |
2944 | return "char"; |
2945 | case Char_U: |
2946 | return "char"; |
2947 | case SChar: |
2948 | return "signed char"; |
2949 | case Short: |
2950 | return "short"; |
2951 | case Int: |
2952 | return "int"; |
2953 | case Long: |
2954 | return "long"; |
2955 | case LongLong: |
2956 | return "long long"; |
2957 | case Int128: |
2958 | return "__int128"; |
2959 | case UChar: |
2960 | return "unsigned char"; |
2961 | case UShort: |
2962 | return "unsigned short"; |
2963 | case UInt: |
2964 | return "unsigned int"; |
2965 | case ULong: |
2966 | return "unsigned long"; |
2967 | case ULongLong: |
2968 | return "unsigned long long"; |
2969 | case UInt128: |
2970 | return "unsigned __int128"; |
2971 | case Half: |
2972 | return Policy.Half ? "half" : "__fp16"; |
2973 | case BFloat16: |
2974 | return "__bf16"; |
2975 | case Float: |
2976 | return "float"; |
2977 | case Double: |
2978 | return "double"; |
2979 | case LongDouble: |
2980 | return "long double"; |
2981 | case ShortAccum: |
2982 | return "short _Accum"; |
2983 | case Accum: |
2984 | return "_Accum"; |
2985 | case LongAccum: |
2986 | return "long _Accum"; |
2987 | case UShortAccum: |
2988 | return "unsigned short _Accum"; |
2989 | case UAccum: |
2990 | return "unsigned _Accum"; |
2991 | case ULongAccum: |
2992 | return "unsigned long _Accum"; |
2993 | case BuiltinType::ShortFract: |
2994 | return "short _Fract"; |
2995 | case BuiltinType::Fract: |
2996 | return "_Fract"; |
2997 | case BuiltinType::LongFract: |
2998 | return "long _Fract"; |
2999 | case BuiltinType::UShortFract: |
3000 | return "unsigned short _Fract"; |
3001 | case BuiltinType::UFract: |
3002 | return "unsigned _Fract"; |
3003 | case BuiltinType::ULongFract: |
3004 | return "unsigned long _Fract"; |
3005 | case BuiltinType::SatShortAccum: |
3006 | return "_Sat short _Accum"; |
3007 | case BuiltinType::SatAccum: |
3008 | return "_Sat _Accum"; |
3009 | case BuiltinType::SatLongAccum: |
3010 | return "_Sat long _Accum"; |
3011 | case BuiltinType::SatUShortAccum: |
3012 | return "_Sat unsigned short _Accum"; |
3013 | case BuiltinType::SatUAccum: |
3014 | return "_Sat unsigned _Accum"; |
3015 | case BuiltinType::SatULongAccum: |
3016 | return "_Sat unsigned long _Accum"; |
3017 | case BuiltinType::SatShortFract: |
3018 | return "_Sat short _Fract"; |
3019 | case BuiltinType::SatFract: |
3020 | return "_Sat _Fract"; |
3021 | case BuiltinType::SatLongFract: |
3022 | return "_Sat long _Fract"; |
3023 | case BuiltinType::SatUShortFract: |
3024 | return "_Sat unsigned short _Fract"; |
3025 | case BuiltinType::SatUFract: |
3026 | return "_Sat unsigned _Fract"; |
3027 | case BuiltinType::SatULongFract: |
3028 | return "_Sat unsigned long _Fract"; |
3029 | case Float16: |
3030 | return "_Float16"; |
3031 | case Float128: |
3032 | return "__float128"; |
3033 | case WChar_S: |
3034 | case WChar_U: |
3035 | return Policy.MSWChar ? "__wchar_t" : "wchar_t"; |
3036 | case Char8: |
3037 | return "char8_t"; |
3038 | case Char16: |
3039 | return "char16_t"; |
3040 | case Char32: |
3041 | return "char32_t"; |
3042 | case NullPtr: |
3043 | return "nullptr_t"; |
3044 | case Overload: |
3045 | return "<overloaded function type>"; |
3046 | case BoundMember: |
3047 | return "<bound member function type>"; |
3048 | case PseudoObject: |
3049 | return "<pseudo-object type>"; |
3050 | case Dependent: |
3051 | return "<dependent type>"; |
3052 | case UnknownAny: |
3053 | return "<unknown type>"; |
3054 | case ARCUnbridgedCast: |
3055 | return "<ARC unbridged cast type>"; |
3056 | case BuiltinFn: |
3057 | return "<builtin fn type>"; |
3058 | case ObjCId: |
3059 | return "id"; |
3060 | case ObjCClass: |
3061 | return "Class"; |
3062 | case ObjCSel: |
3063 | return "SEL"; |
3064 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
3065 | case Id: \ |
3066 | return "__" #Access " " #ImgType "_t"; |
3067 | #include "clang/Basic/OpenCLImageTypes.def" |
3068 | case OCLSampler: |
3069 | return "sampler_t"; |
3070 | case OCLEvent: |
3071 | return "event_t"; |
3072 | case OCLClkEvent: |
3073 | return "clk_event_t"; |
3074 | case OCLQueue: |
3075 | return "queue_t"; |
3076 | case OCLReserveID: |
3077 | return "reserve_id_t"; |
3078 | case IncompleteMatrixIdx: |
3079 | return "<incomplete matrix index type>"; |
3080 | case OMPArraySection: |
3081 | return "<OpenMP array section type>"; |
3082 | case OMPArrayShaping: |
3083 | return "<OpenMP array shaping type>"; |
3084 | case OMPIterator: |
3085 | return "<OpenMP iterator type>"; |
3086 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
3087 | case Id: \ |
3088 | return #ExtType; |
3089 | #include "clang/Basic/OpenCLExtensionTypes.def" |
3090 | #define SVE_TYPE(Name, Id, SingletonId) \ |
3091 | case Id: \ |
3092 | return Name; |
3093 | #include "clang/Basic/AArch64SVEACLETypes.def" |
3094 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ |
3095 | case Id: \ |
3096 | return #Name; |
3097 | #include "clang/Basic/PPCTypes.def" |
3098 | #define RVV_TYPE(Name, Id, SingletonId) \ |
3099 | case Id: \ |
3100 | return Name; |
3101 | #include "clang/Basic/RISCVVTypes.def" |
3102 | } |
3103 | |
3104 | llvm_unreachable("Invalid builtin type."); |
3105 | } |
3106 | |
3107 | QualType QualType::getNonPackExpansionType() const { |
3108 | |
3109 | if (auto *PET = dyn_cast<PackExpansionType>(getTypePtr())) |
3110 | return PET->getPattern(); |
3111 | return *this; |
3112 | } |
3113 | |
3114 | QualType QualType::getNonLValueExprType(const ASTContext &Context) const { |
3115 | if (const auto *RefType = getTypePtr()->getAs<ReferenceType>()) |
3116 | return RefType->getPointeeType(); |
3117 | |
3118 | |
3119 | |
3120 | |
3121 | |
3122 | |
3123 | if (!Context.getLangOpts().CPlusPlus || |
3124 | (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType())) |
3125 | return getUnqualifiedType(); |
3126 | |
3127 | return *this; |
3128 | } |
3129 | |
3130 | StringRef FunctionType::getNameForCallConv(CallingConv CC) { |
3131 | switch (CC) { |
3132 | case CC_C: return "cdecl"; |
3133 | case CC_X86StdCall: return "stdcall"; |
3134 | case CC_X86FastCall: return "fastcall"; |
3135 | case CC_X86ThisCall: return "thiscall"; |
3136 | case CC_X86Pascal: return "pascal"; |
3137 | case CC_X86VectorCall: return "vectorcall"; |
3138 | case CC_Win64: return "ms_abi"; |
3139 | case CC_X86_64SysV: return "sysv_abi"; |
3140 | case CC_X86RegCall : return "regcall"; |
3141 | case CC_AAPCS: return "aapcs"; |
3142 | case CC_AAPCS_VFP: return "aapcs-vfp"; |
3143 | case CC_AArch64VectorCall: return "aarch64_vector_pcs"; |
3144 | case CC_IntelOclBicc: return "intel_ocl_bicc"; |
3145 | case CC_SpirFunction: return "spir_function"; |
3146 | case CC_OpenCLKernel: return "opencl_kernel"; |
3147 | case CC_Swift: return "swiftcall"; |
3148 | case CC_SwiftAsync: return "swiftasynccall"; |
3149 | case CC_PreserveMost: return "preserve_most"; |
3150 | case CC_PreserveAll: return "preserve_all"; |
3151 | } |
3152 | |
3153 | llvm_unreachable("Invalid calling convention."); |
3154 | } |
3155 | |
3156 | FunctionProtoType::FunctionProtoType(QualType result, ArrayRef<QualType> params, |
3157 | QualType canonical, |
3158 | const ExtProtoInfo &epi) |
3159 | : FunctionType(FunctionProto, result, canonical, result->getDependence(), |
3160 | epi.ExtInfo) { |
3161 | FunctionTypeBits.FastTypeQuals = epi.TypeQuals.getFastQualifiers(); |
3162 | FunctionTypeBits.RefQualifier = epi.RefQualifier; |
3163 | FunctionTypeBits.NumParams = params.size(); |
3164 | assert(getNumParams() == params.size() && "NumParams overflow!"); |
3165 | FunctionTypeBits.ExceptionSpecType = epi.ExceptionSpec.Type; |
3166 | FunctionTypeBits.HasExtParameterInfos = !!epi.ExtParameterInfos; |
3167 | FunctionTypeBits.Variadic = epi.Variadic; |
3168 | FunctionTypeBits.HasTrailingReturn = epi.HasTrailingReturn; |
3169 | |
3170 | |
3171 | if (hasExtraBitfields(epi.ExceptionSpec.Type)) { |
3172 | auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>(); |
3173 | ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size(); |
3174 | } |
3175 | |
3176 | |
3177 | auto *argSlot = getTrailingObjects<QualType>(); |
3178 | for (unsigned i = 0; i != getNumParams(); ++i) { |
3179 | addDependence(params[i]->getDependence() & |
3180 | ~TypeDependence::VariablyModified); |
3181 | argSlot[i] = params[i]; |
3182 | } |
3183 | |
3184 | |
3185 | if (getExceptionSpecType() == EST_Dynamic) { |
3186 | assert(hasExtraBitfields() && "missing trailing extra bitfields!"); |
3187 | auto *exnSlot = |
3188 | reinterpret_cast<QualType *>(getTrailingObjects<ExceptionType>()); |
3189 | unsigned I = 0; |
3190 | for (QualType ExceptionType : epi.ExceptionSpec.Exceptions) { |
3191 | |
3192 | |
3193 | |
3194 | addDependence( |
3195 | ExceptionType->getDependence() & |
3196 | (TypeDependence::Instantiation | TypeDependence::UnexpandedPack)); |
3197 | |
3198 | exnSlot[I++] = ExceptionType; |
3199 | } |
3200 | } |
3201 | |
3202 | else if (isComputedNoexcept(getExceptionSpecType())) { |
3203 | assert(epi.ExceptionSpec.NoexceptExpr && "computed noexcept with no expr"); |
3204 | assert((getExceptionSpecType() == EST_DependentNoexcept) == |
3205 | epi.ExceptionSpec.NoexceptExpr->isValueDependent()); |
3206 | |
3207 | |
3208 | *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr; |
3209 | |
3210 | addDependence( |
3211 | toTypeDependence(epi.ExceptionSpec.NoexceptExpr->getDependence()) & |
3212 | (TypeDependence::Instantiation | TypeDependence::UnexpandedPack)); |
3213 | } |
3214 | |
3215 | else if (getExceptionSpecType() == EST_Uninstantiated) { |
3216 | |
3217 | |
3218 | auto **slot = getTrailingObjects<FunctionDecl *>(); |
3219 | slot[0] = epi.ExceptionSpec.SourceDecl; |
3220 | slot[1] = epi.ExceptionSpec.SourceTemplate; |
3221 | |
3222 | |
3223 | } else if (getExceptionSpecType() == EST_Unevaluated) { |
3224 | |
3225 | |
3226 | auto **slot = getTrailingObjects<FunctionDecl *>(); |
3227 | slot[0] = epi.ExceptionSpec.SourceDecl; |
3228 | } |
3229 | |
3230 | |
3231 | |
3232 | if (isCanonicalUnqualified()) { |
3233 | if (getExceptionSpecType() == EST_Dynamic || |
3234 | getExceptionSpecType() == EST_DependentNoexcept) { |
3235 | assert(hasDependentExceptionSpec() && "type should not be canonical"); |
3236 | addDependence(TypeDependence::DependentInstantiation); |
3237 | } |
3238 | } else if (getCanonicalTypeInternal()->isDependentType()) { |
3239 | |
3240 | addDependence(TypeDependence::DependentInstantiation); |
3241 | } |
3242 | |
3243 | |
3244 | if (epi.ExtParameterInfos) { |
3245 | auto *extParamInfos = getTrailingObjects<ExtParameterInfo>(); |
3246 | for (unsigned i = 0; i != getNumParams(); ++i) |
3247 | extParamInfos[i] = epi.ExtParameterInfos[i]; |
3248 | } |
3249 | |
3250 | if (epi.TypeQuals.hasNonFastQualifiers()) { |
3251 | FunctionTypeBits.HasExtQuals = 1; |
3252 | *getTrailingObjects<Qualifiers>() = epi.TypeQuals; |
3253 | } else { |
3254 | FunctionTypeBits.HasExtQuals = 0; |
3255 | } |
3256 | |
3257 | |
3258 | if (epi.Variadic) { |
3259 | auto &EllipsisLoc = *getTrailingObjects<SourceLocation>(); |
3260 | EllipsisLoc = epi.EllipsisLoc; |
3261 | } |
3262 | } |
3263 | |
3264 | bool FunctionProtoType::hasDependentExceptionSpec() const { |
3265 | if (Expr *NE = getNoexceptExpr()) |
3266 | return NE->isValueDependent(); |
3267 | for (QualType ET : exceptions()) |
3268 | |
3269 | |
3270 | |
3271 | if (ET->isDependentType() || ET->getAs<PackExpansionType>()) |
3272 | return true; |
3273 | return false; |
3274 | } |
3275 | |
3276 | bool FunctionProtoType::hasInstantiationDependentExceptionSpec() const { |
3277 | if (Expr *NE = getNoexceptExpr()) |
3278 | return NE->isInstantiationDependent(); |
3279 | for (QualType ET : exceptions()) |
3280 | if (ET->isInstantiationDependentType()) |
3281 | return true; |
3282 | return false; |
3283 | } |
3284 | |
3285 | CanThrowResult FunctionProtoType::canThrow() const { |
3286 | switch (getExceptionSpecType()) { |
3287 | case EST_Unparsed: |
3288 | case EST_Unevaluated: |
3289 | case EST_Uninstantiated: |
3290 | llvm_unreachable("should not call this with unresolved exception specs"); |
3291 | |
3292 | case EST_DynamicNone: |
3293 | case EST_BasicNoexcept: |
3294 | case EST_NoexceptTrue: |
3295 | case EST_NoThrow: |
3296 | return CT_Cannot; |
3297 | |
3298 | case EST_None: |
3299 | case EST_MSAny: |
3300 | case EST_NoexceptFalse: |
3301 | return CT_Can; |
3302 | |
3303 | case EST_Dynamic: |
3304 | |
3305 | |
3306 | for (unsigned I = 0; I != getNumExceptions(); ++I) |
3307 | if (!getExceptionType(I)->getAs<PackExpansionType>()) |
3308 | return CT_Can; |
3309 | return CT_Dependent; |
3310 | |
3311 | case EST_DependentNoexcept: |
3312 | return CT_Dependent; |
3313 | } |
3314 | |
3315 | llvm_unreachable("unexpected exception specification kind"); |
3316 | } |
3317 | |
3318 | bool FunctionProtoType::isTemplateVariadic() const { |
3319 | for (unsigned ArgIdx = getNumParams(); ArgIdx; --ArgIdx) |
3320 | if (isa<PackExpansionType>(getParamType(ArgIdx - 1))) |
3321 | return true; |
3322 | |
3323 | return false; |
3324 | } |
3325 | |
3326 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
3327 | const QualType *ArgTys, unsigned NumParams, |
3328 | const ExtProtoInfo &epi, |
3329 | const ASTContext &Context, bool Canonical) { |
3330 | |
3331 | |
3332 | |
3333 | |
3334 | |
3335 | |
3336 | |
3337 | |
3338 | |
3339 | |
3340 | |
3341 | |
3342 | |
3343 | |
3344 | |
3345 | |
3346 | |
3347 | ID.AddPointer(Result.getAsOpaquePtr()); |
3348 | for (unsigned i = 0; i != NumParams; ++i) |
3349 | ID.AddPointer(ArgTys[i].getAsOpaquePtr()); |
3350 | |
3351 | |
3352 | |
3353 | assert(!(unsigned(epi.Variadic) & ~1) && |
3354 | !(unsigned(epi.RefQualifier) & ~3) && |
3355 | !(unsigned(epi.ExceptionSpec.Type) & ~15) && |
3356 | "Values larger than expected."); |
3357 | ID.AddInteger(unsigned(epi.Variadic) + |
3358 | (epi.RefQualifier << 1) + |
3359 | (epi.ExceptionSpec.Type << 3)); |
3360 | ID.Add(epi.TypeQuals); |
3361 | if (epi.ExceptionSpec.Type == EST_Dynamic) { |
3362 | for (QualType Ex : epi.ExceptionSpec.Exceptions) |
3363 | ID.AddPointer(Ex.getAsOpaquePtr()); |
3364 | } else if (isComputedNoexcept(epi.ExceptionSpec.Type)) { |
3365 | epi.ExceptionSpec.NoexceptExpr->Profile(ID, Context, Canonical); |
3366 | } else if (epi.ExceptionSpec.Type == EST_Uninstantiated || |
3367 | epi.ExceptionSpec.Type == EST_Unevaluated) { |
3368 | ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl()); |
3369 | } |
3370 | if (epi.ExtParameterInfos) { |
3371 | for (unsigned i = 0; i != NumParams; ++i) |
3372 | ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue()); |
3373 | } |
3374 | epi.ExtInfo.Profile(ID); |
3375 | ID.AddBoolean(epi.HasTrailingReturn); |
3376 | } |
3377 | |
3378 | void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, |
3379 | const ASTContext &Ctx) { |
3380 | Profile(ID, getReturnType(), param_type_begin(), getNumParams(), |
3381 | getExtProtoInfo(), Ctx, isCanonicalUnqualified()); |
3382 | } |
3383 | |
3384 | TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D, |
3385 | QualType underlying, QualType can) |
3386 | : Type(tc, can, underlying->getDependence()), |
3387 | Decl(const_cast<TypedefNameDecl *>(D)) { |
3388 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
3389 | } |
3390 | |
3391 | QualType TypedefType::desugar() const { |
3392 | return getDecl()->getUnderlyingType(); |
3393 | } |
3394 | |
3395 | QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); } |
3396 | |
3397 | QualType MacroQualifiedType::getModifiedType() const { |
3398 | |
3399 | |
3400 | QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType(); |
3401 | while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) { |
3402 | if (InnerMQT->getMacroIdentifier() != getMacroIdentifier()) |
3403 | break; |
3404 | Inner = InnerMQT->getModifiedType(); |
3405 | } |
3406 | return Inner; |
3407 | } |
3408 | |
3409 | TypeOfExprType::TypeOfExprType(Expr *E, QualType can) |
3410 | : Type(TypeOfExpr, can, |
3411 | toTypeDependence(E->getDependence()) | |
3412 | (E->getType()->getDependence() & |
3413 | TypeDependence::VariablyModified)), |
3414 | TOExpr(E) {} |
3415 | |
3416 | bool TypeOfExprType::isSugared() const { |
3417 | return !TOExpr->isTypeDependent(); |
3418 | } |
3419 | |
3420 | QualType TypeOfExprType::desugar() const { |
3421 | if (isSugared()) |
3422 | return getUnderlyingExpr()->getType(); |
3423 | |
3424 | return QualType(this, 0); |
3425 | } |
3426 | |
3427 | void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, |
3428 | const ASTContext &Context, Expr *E) { |
3429 | E->Profile(ID, Context, true); |
3430 | } |
3431 | |
3432 | DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) |
3433 | |
3434 | |
3435 | |
3436 | : Type(Decltype, can, |
3437 | toTypeDependence(E->getDependence()) | |
3438 | (E->isInstantiationDependent() ? TypeDependence::Dependent |
3439 | : TypeDependence::None) | |
3440 | (E->getType()->getDependence() & |
3441 | TypeDependence::VariablyModified)), |
3442 | E(E), UnderlyingType(underlyingType) {} |
3443 | |
3444 | bool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); } |
3445 | |
3446 | QualType DecltypeType::desugar() const { |
3447 | if (isSugared()) |
3448 | return getUnderlyingType(); |
3449 | |
3450 | return QualType(this, 0); |
3451 | } |
3452 | |
3453 | DependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E) |
3454 | : DecltypeType(E, Context.DependentTy), Context(Context) {} |
3455 | |
3456 | void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, |
3457 | const ASTContext &Context, Expr *E) { |
3458 | E->Profile(ID, Context, true); |
3459 | } |
3460 | |
3461 | UnaryTransformType::UnaryTransformType(QualType BaseType, |
3462 | QualType UnderlyingType, UTTKind UKind, |
3463 | QualType CanonicalType) |
3464 | : Type(UnaryTransform, CanonicalType, BaseType->getDependence()), |
3465 | BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {} |
3466 | |
3467 | DependentUnaryTransformType::DependentUnaryTransformType(const ASTContext &C, |
3468 | QualType BaseType, |
3469 | UTTKind UKind) |
3470 | : UnaryTransformType(BaseType, C.DependentTy, UKind, QualType()) {} |
3471 | |
3472 | TagType::TagType(TypeClass TC, const TagDecl *D, QualType can) |
3473 | : Type(TC, can, |
3474 | D->isDependentType() ? TypeDependence::DependentInstantiation |
3475 | : TypeDependence::None), |
3476 | decl(const_cast<TagDecl *>(D)) {} |
3477 | |
3478 | static TagDecl *getInterestingTagDecl(TagDecl *decl) { |
3479 | for (auto I : decl->redecls()) { |
3480 | if (I->isCompleteDefinition() || I->isBeingDefined()) |
3481 | return I; |
3482 | } |
3483 | |
3484 | return decl; |
3485 | } |
3486 | |
3487 | TagDecl *TagType::getDecl() const { |
3488 | return getInterestingTagDecl(decl); |
3489 | } |
3490 | |
3491 | bool TagType::isBeingDefined() const { |
3492 | return getDecl()->isBeingDefined(); |
3493 | } |
3494 | |
3495 | bool RecordType::hasConstFields() const { |
3496 | std::vector<const RecordType*> RecordTypeList; |
3497 | RecordTypeList.push_back(this); |
3498 | unsigned NextToCheckIndex = 0; |
3499 | |
3500 | while (RecordTypeList.size() > NextToCheckIndex) { |
3501 | for (FieldDecl *FD : |
3502 | RecordTypeList[NextToCheckIndex]->getDecl()->fields()) { |
3503 | QualType FieldTy = FD->getType(); |
3504 | if (FieldTy.isConstQualified()) |
3505 | return true; |
3506 | FieldTy = FieldTy.getCanonicalType(); |
3507 | if (const auto *FieldRecTy = FieldTy->getAs<RecordType>()) { |
3508 | if (llvm::find(RecordTypeList, FieldRecTy) == RecordTypeList.end()) |
3509 | RecordTypeList.push_back(FieldRecTy); |
3510 | } |
3511 | } |
3512 | ++NextToCheckIndex; |
3513 | } |
3514 | return false; |
3515 | } |
3516 | |
3517 | bool AttributedType::isQualifier() const { |
3518 | |
3519 | switch (getAttrKind()) { |
3520 | |
3521 | |
3522 | |
3523 | case attr::ObjCGC: |
3524 | case attr::ObjCOwnership: |
3525 | case attr::ObjCInertUnsafeUnretained: |
3526 | case attr::TypeNonNull: |
3527 | case attr::TypeNullable: |
3528 | case attr::TypeNullableResult: |
3529 | case attr::TypeNullUnspecified: |
3530 | case attr::LifetimeBound: |
3531 | case attr::AddressSpace: |
3532 | return true; |
3533 | |
3534 | |
3535 | |
3536 | default: |
3537 | return false; |
3538 | } |
3539 | } |
3540 | |
3541 | bool AttributedType::isMSTypeSpec() const { |
3542 | |
3543 | switch (getAttrKind()) { |
3544 | default: return false; |
3545 | case attr::Ptr32: |
3546 | case attr::Ptr64: |
3547 | case attr::SPtr: |
3548 | case attr::UPtr: |
3549 | return true; |
3550 | } |
3551 | llvm_unreachable("invalid attr kind"); |
3552 | } |
3553 | |
3554 | bool AttributedType::isCallingConv() const { |
3555 | |
3556 | switch (getAttrKind()) { |
3557 | default: return false; |
3558 | case attr::Pcs: |
3559 | case attr::CDecl: |
3560 | case attr::FastCall: |
3561 | case attr::StdCall: |
3562 | case attr::ThisCall: |
3563 | case attr::RegCall: |
3564 | case attr::SwiftCall: |
3565 | case attr::SwiftAsyncCall: |
3566 | case attr::VectorCall: |
3567 | case attr::AArch64VectorPcs: |
3568 | case attr::Pascal: |
3569 | case attr::MSABI: |
3570 | case attr::SysVABI: |
3571 | case attr::IntelOclBicc: |
3572 | case attr::PreserveMost: |
3573 | case attr::PreserveAll: |
3574 | return true; |
3575 | } |
3576 | llvm_unreachable("invalid attr kind"); |
3577 | } |
3578 | |
3579 | CXXRecordDecl *InjectedClassNameType::getDecl() const { |
3580 | return cast<CXXRecordDecl>(getInterestingTagDecl(Decl)); |
3581 | } |
3582 | |
3583 | IdentifierInfo *TemplateTypeParmType::getIdentifier() const { |
3584 | return isCanonicalUnqualified() ? nullptr : getDecl()->getIdentifier(); |
3585 | } |
3586 | |
3587 | SubstTemplateTypeParmPackType::SubstTemplateTypeParmPackType( |
3588 | const TemplateTypeParmType *Param, QualType Canon, |
3589 | const TemplateArgument &ArgPack) |
3590 | : Type(SubstTemplateTypeParmPack, Canon, |
3591 | TypeDependence::DependentInstantiation | |
3592 | TypeDependence::UnexpandedPack), |
3593 | Replaced(Param), Arguments(ArgPack.pack_begin()) { |
3594 | SubstTemplateTypeParmPackTypeBits.NumArgs = ArgPack.pack_size(); |
3595 | } |
3596 | |
3597 | TemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const { |
3598 | return TemplateArgument(llvm::makeArrayRef(Arguments, getNumArgs())); |
3599 | } |
3600 | |
3601 | void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) { |
3602 | Profile(ID, getReplacedParameter(), getArgumentPack()); |
3603 | } |
3604 | |
3605 | void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID, |
3606 | const TemplateTypeParmType *Replaced, |
3607 | const TemplateArgument &ArgPack) { |
3608 | ID.AddPointer(Replaced); |
3609 | ID.AddInteger(ArgPack.pack_size()); |
3610 | for (const auto &P : ArgPack.pack_elements()) |
3611 | ID.AddPointer(P.getAsType().getAsOpaquePtr()); |
3612 | } |
3613 | |
3614 | bool TemplateSpecializationType::anyDependentTemplateArguments( |
3615 | const TemplateArgumentListInfo &Args, ArrayRef<TemplateArgument> Converted) { |
3616 | return anyDependentTemplateArguments(Args.arguments(), Converted); |
3617 | } |
3618 | |
3619 | bool TemplateSpecializationType::anyDependentTemplateArguments( |
3620 | ArrayRef<TemplateArgumentLoc> Args, ArrayRef<TemplateArgument> Converted) { |
3621 | for (const TemplateArgument &Arg : Converted) |
3622 | if (Arg.isDependent()) |
3623 | return true; |
3624 | return false; |
3625 | } |
3626 | |
3627 | bool TemplateSpecializationType::anyInstantiationDependentTemplateArguments( |
3628 | ArrayRef<TemplateArgumentLoc> Args) { |
3629 | for (const TemplateArgumentLoc &ArgLoc : Args) { |
3630 | if (ArgLoc.getArgument().isInstantiationDependent()) |
3631 | return true; |
3632 | } |
3633 | return false; |
3634 | } |
3635 | |
3636 | TemplateSpecializationType::TemplateSpecializationType( |
3637 | TemplateName T, ArrayRef<TemplateArgument> Args, QualType Canon, |
3638 | QualType AliasedType) |
3639 | : Type(TemplateSpecialization, Canon.isNull() ? QualType(this, 0) : Canon, |
3640 | (Canon.isNull() |
3641 | ? TypeDependence::DependentInstantiation |
3642 | : Canon->getDependence() & ~(TypeDependence::VariablyModified | |
3643 | TypeDependence::UnexpandedPack)) | |
3644 | (toTypeDependence(T.getDependence()) & |
3645 | TypeDependence::UnexpandedPack)), |
3646 | Template(T) { |
3647 | TemplateSpecializationTypeBits.NumArgs = Args.size(); |
3648 | TemplateSpecializationTypeBits.TypeAlias = !AliasedType.isNull(); |
3649 | |
3650 | assert(!T.getAsDependentTemplateName() && |
3651 | "Use DependentTemplateSpecializationType for dependent template-name"); |
3652 | assert((T.getKind() == TemplateName::Template || |
3653 | T.getKind() == TemplateName::SubstTemplateTemplateParm || |
3654 | T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && |
3655 | "Unexpected template name for TemplateSpecializationType"); |
3656 | |
3657 | auto *TemplateArgs = reinterpret_cast<TemplateArgument *>(this + 1); |
3658 | for (const TemplateArgument &Arg : Args) { |
3659 | |
3660 | |
3661 | |
3662 | |
3663 | |
3664 | |
3665 | |
3666 | |
3667 | addDependence(toTypeDependence(Arg.getDependence()) & |
3668 | ~TypeDependence::Dependent); |
3669 | if (Arg.getKind() == TemplateArgument::Type) |
3670 | addDependence(Arg.getAsType()->getDependence() & |
3671 | TypeDependence::VariablyModified); |
3672 | new (TemplateArgs++) TemplateArgument(Arg); |
3673 | } |
3674 | |
3675 | |
3676 | if (isTypeAlias()) { |
3677 | auto *Begin = reinterpret_cast<TemplateArgument *>(this + 1); |
3678 | *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType; |
3679 | } |
3680 | } |
3681 | |
3682 | void |
3683 | TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, |
3684 | TemplateName T, |
3685 | ArrayRef<TemplateArgument> Args, |
3686 | const ASTContext &Context) { |
3687 | T.Profile(ID); |
3688 | for (const TemplateArgument &Arg : Args) |
3689 | Arg.Profile(ID, Context); |
3690 | } |
3691 | |
3692 | QualType |
3693 | QualifierCollector::apply(const ASTContext &Context, QualType QT) const { |
3694 | if (!hasNonFastQualifiers()) |
3695 | return QT.withFastQualifiers(getFastQualifiers()); |
3696 | |
3697 | return Context.getQualifiedType(QT, *this); |
3698 | } |
3699 | |
3700 | QualType |
3701 | QualifierCollector::apply(const ASTContext &Context, const Type *T) const { |
3702 | if (!hasNonFastQualifiers()) |
3703 | return QualType(T, getFastQualifiers()); |
3704 | |
3705 | return Context.getQualifiedType(T, *this); |
3706 | } |
3707 | |
3708 | void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID, |
3709 | QualType BaseType, |
3710 | ArrayRef<QualType> typeArgs, |
3711 | ArrayRef<ObjCProtocolDecl *> protocols, |
3712 | bool isKindOf) { |
3713 | ID.AddPointer(BaseType.getAsOpaquePtr()); |
3714 | ID.AddInteger(typeArgs.size()); |
3715 | for (auto typeArg : typeArgs) |
3716 | ID.AddPointer(typeArg.getAsOpaquePtr()); |
3717 | ID.AddInteger(protocols.size()); |
3718 | for (auto proto : protocols) |
3719 | ID.AddPointer(proto); |
3720 | ID.AddBoolean(isKindOf); |
3721 | } |
3722 | |
3723 | void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) { |
3724 | Profile(ID, getBaseType(), getTypeArgsAsWritten(), |
3725 | llvm::makeArrayRef(qual_begin(), getNumProtocols()), |
3726 | isKindOfTypeAsWritten()); |
3727 | } |
3728 | |
3729 | void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID, |
3730 | const ObjCTypeParamDecl *OTPDecl, |
3731 | QualType CanonicalType, |
3732 | ArrayRef<ObjCProtocolDecl *> protocols) { |
3733 | ID.AddPointer(OTPDecl); |
3734 | ID.AddPointer(CanonicalType.getAsOpaquePtr()); |
3735 | ID.AddInteger(protocols.size()); |
3736 | for (auto proto : protocols) |
3737 | ID.AddPointer(proto); |
3738 | } |
3739 | |
3740 | void ObjCTypeParamType::Profile(llvm::FoldingSetNodeID &ID) { |
3741 | Profile(ID, getDecl(), getCanonicalTypeInternal(), |
3742 | llvm::makeArrayRef(qual_begin(), getNumProtocols())); |
3743 | } |
3744 | |
3745 | namespace { |
3746 | |
3747 | |
3748 | class CachedProperties { |
3749 | Linkage L; |
3750 | bool local; |
3751 | |
3752 | public: |
3753 | CachedProperties(Linkage L, bool local) : L(L), local(local) {} |
3754 | |
3755 | Linkage getLinkage() const { return L; } |
3756 | bool hasLocalOrUnnamedType() const { return local; } |
3757 | |
3758 | friend CachedProperties merge(CachedProperties L, CachedProperties R) { |
3759 | Linkage MergedLinkage = minLinkage(L.L, R.L); |
3760 | return CachedProperties(MergedLinkage, |
3761 | L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType()); |
3762 | } |
3763 | }; |
3764 | |
3765 | } |
3766 | |
3767 | static CachedProperties computeCachedProperties(const Type *T); |
3768 | |
3769 | namespace clang { |
3770 | |
3771 | |
3772 | |
3773 | |
3774 | template <class Private> class TypePropertyCache { |
3775 | public: |
3776 | static CachedProperties get(QualType T) { |
3777 | return get(T.getTypePtr()); |
3778 | } |
3779 | |
3780 | static CachedProperties get(const Type *T) { |
3781 | ensure(T); |
3782 | return CachedProperties(T->TypeBits.getLinkage(), |
3783 | T->TypeBits.hasLocalOrUnnamedType()); |
3784 | } |
3785 | |
3786 | static void ensure(const Type *T) { |
3787 | |
3788 | if (T->TypeBits.isCacheValid()) return; |
3789 | |
3790 | |
3791 | |
3792 | if (!T->isCanonicalUnqualified()) { |
3793 | const Type *CT = T->getCanonicalTypeInternal().getTypePtr(); |
3794 | ensure(CT); |
3795 | T->TypeBits.CacheValid = true; |
3796 | T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage; |
3797 | T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed; |
3798 | return; |
3799 | } |
3800 | |
3801 | |
3802 | CachedProperties Result = computeCachedProperties(T); |
3803 | T->TypeBits.CacheValid = true; |
3804 | T->TypeBits.CachedLinkage = Result.getLinkage(); |
3805 | T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType(); |
3806 | } |
3807 | }; |
3808 | |
3809 | } |
3810 | |
3811 | |
3812 | |
3813 | |
3814 | namespace { |
3815 | |
3816 | class Private {}; |
3817 | |
3818 | } |
3819 | |
3820 | using Cache = TypePropertyCache<Private>; |
3821 | |
3822 | static CachedProperties computeCachedProperties(const Type *T) { |
3823 | switch (T->getTypeClass()) { |
3824 | #define TYPE(Class,Base) |
3825 | #define NON_CANONICAL_TYPE(Class,Base) case Type::Class: |
3826 | #include "clang/AST/TypeNodes.inc" |
3827 | llvm_unreachable("didn't expect a non-canonical type here"); |
3828 | |
3829 | #define TYPE(Class,Base) |
3830 | #define DEPENDENT_TYPE(Class,Base) case Type::Class: |
3831 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: |
3832 | #include "clang/AST/TypeNodes.inc" |
3833 | |
3834 | if (!T->isInstantiationDependentType()) T->dump(); |
3835 | assert(T->isInstantiationDependentType()); |
3836 | return CachedProperties(ExternalLinkage, false); |
3837 | |
3838 | case Type::Auto: |
3839 | case Type::DeducedTemplateSpecialization: |
3840 | |
3841 | |
3842 | return CachedProperties(ExternalLinkage, false); |
3843 | |
3844 | case Type::ExtInt: |
3845 | case Type::Builtin: |
3846 | |
3847 | |
3848 | |
3849 | return CachedProperties(ExternalLinkage, false); |
3850 | |
3851 | case Type::Record: |
3852 | case Type::Enum: { |
3853 | const TagDecl *Tag = cast<TagType>(T)->getDecl(); |
3854 | |
3855 | |
3856 | |
3857 | |
3858 | |
3859 | Linkage L = Tag->getLinkageInternal(); |
3860 | bool IsLocalOrUnnamed = |
3861 | Tag->getDeclContext()->isFunctionOrMethod() || |
3862 | !Tag->hasNameForLinkage(); |
3863 | return CachedProperties(L, IsLocalOrUnnamed); |
3864 | } |
3865 | |
3866 | |
3867 | |
3868 | |
3869 | case Type::Complex: |
3870 | return Cache::get(cast<ComplexType>(T)->getElementType()); |
3871 | case Type::Pointer: |
3872 | return Cache::get(cast<PointerType>(T)->getPointeeType()); |
3873 | case Type::BlockPointer: |
3874 | return Cache::get(cast<BlockPointerType>(T)->getPointeeType()); |
3875 | case Type::LValueReference: |
3876 | case Type::RValueReference: |
3877 | return Cache::get(cast<ReferenceType>(T)->getPointeeType()); |
3878 | case Type::MemberPointer: { |
3879 | const auto *MPT = cast<MemberPointerType>(T); |
3880 | return merge(Cache::get(MPT->getClass()), |
3881 | Cache::get(MPT->getPointeeType())); |
3882 | } |
3883 | case Type::ConstantArray: |
3884 | case Type::IncompleteArray: |
3885 | case Type::VariableArray: |
3886 | return Cache::get(cast<ArrayType>(T)->getElementType()); |
3887 | case Type::Vector: |
3888 | case Type::ExtVector: |
3889 | return Cache::get(cast<VectorType>(T)->getElementType()); |
3890 | case Type::ConstantMatrix: |
3891 | return Cache::get(cast<ConstantMatrixType>(T)->getElementType()); |
3892 | case Type::FunctionNoProto: |
3893 | return Cache::get(cast<FunctionType>(T)->getReturnType()); |
3894 | case Type::FunctionProto: { |
3895 | const auto *FPT = cast<FunctionProtoType>(T); |
3896 | CachedProperties result = Cache::get(FPT->getReturnType()); |
3897 | for (const auto &ai : FPT->param_types()) |
3898 | result = merge(result, Cache::get(ai)); |
3899 | return result; |
3900 | } |
3901 | case Type::ObjCInterface: { |
3902 | Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal(); |
3903 | return CachedProperties(L, false); |
3904 | } |
3905 | case Type::ObjCObject: |
3906 | return Cache::get(cast<ObjCObjectType>(T)->getBaseType()); |
3907 | case Type::ObjCObjectPointer: |
3908 | return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType()); |
3909 | case Type::Atomic: |
3910 | return Cache::get(cast<AtomicType>(T)->getValueType()); |
3911 | case Type::Pipe: |
3912 | return Cache::get(cast<PipeType>(T)->getElementType()); |
3913 | } |
3914 | |
3915 | llvm_unreachable("unhandled type class"); |
3916 | } |
3917 | |
3918 | |
3919 | Linkage Type::getLinkage() const { |
3920 | Cache::ensure(this); |
3921 | return TypeBits.getLinkage(); |
3922 | } |
3923 | |
3924 | bool Type::hasUnnamedOrLocalType() const { |
3925 | Cache::ensure(this); |
3926 | return TypeBits.hasLocalOrUnnamedType(); |
3927 | } |
3928 | |
3929 | LinkageInfo LinkageComputer::computeTypeLinkageInfo(const Type *T) { |
3930 | switch (T->getTypeClass()) { |
3931 | #define TYPE(Class,Base) |
3932 | #define NON_CANONICAL_TYPE(Class,Base) case Type::Class: |
3933 | #include "clang/AST/TypeNodes.inc" |
3934 | llvm_unreachable("didn't expect a non-canonical type here"); |
3935 | |
3936 | #define TYPE(Class,Base) |
3937 | #define DEPENDENT_TYPE(Class,Base) case Type::Class: |
3938 | #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class: |
3939 | #include "clang/AST/TypeNodes.inc" |
3940 | |
3941 | assert(T->isInstantiationDependentType()); |
3942 | return LinkageInfo::external(); |
3943 | |
3944 | case Type::ExtInt: |
3945 | case Type::Builtin: |
3946 | return LinkageInfo::external(); |
3947 | |
3948 | case Type::Auto: |
3949 | case Type::DeducedTemplateSpecialization: |
3950 | return LinkageInfo::external(); |
3951 | |
3952 | case Type::Record: |
3953 | case Type::Enum: |
3954 | return getDeclLinkageAndVisibility(cast<TagType>(T)->getDecl()); |
3955 | |
3956 | case Type::Complex: |
3957 | return computeTypeLinkageInfo(cast<ComplexType>(T)->getElementType()); |
3958 | case Type::Pointer: |
3959 | return computeTypeLinkageInfo(cast<PointerType>(T)->getPointeeType()); |
3960 | case Type::BlockPointer: |
3961 | return computeTypeLinkageInfo(cast<BlockPointerType>(T)->getPointeeType()); |
3962 | case Type::LValueReference: |
3963 | case Type::RValueReference: |
3964 | return computeTypeLinkageInfo(cast<ReferenceType>(T)->getPointeeType()); |
3965 | case Type::MemberPointer: { |
3966 | const auto *MPT = cast<MemberPointerType>(T); |
3967 | LinkageInfo LV = computeTypeLinkageInfo(MPT->getClass()); |
3968 | LV.merge(computeTypeLinkageInfo(MPT->getPointeeType())); |
3969 | return LV; |
3970 | } |
3971 | case Type::ConstantArray: |
3972 | case Type::IncompleteArray: |
3973 | case Type::VariableArray: |
3974 | return computeTypeLinkageInfo(cast<ArrayType>(T)->getElementType()); |
3975 | case Type::Vector: |
3976 | case Type::ExtVector: |
3977 | return computeTypeLinkageInfo(cast<VectorType>(T)->getElementType()); |
3978 | case Type::ConstantMatrix: |
3979 | return computeTypeLinkageInfo( |
3980 | cast<ConstantMatrixType>(T)->getElementType()); |
3981 | case Type::FunctionNoProto: |
3982 | return computeTypeLinkageInfo(cast<FunctionType>(T)->getReturnType()); |
3983 | case Type::FunctionProto: { |
3984 | const auto *FPT = cast<FunctionProtoType>(T); |
3985 | LinkageInfo LV = computeTypeLinkageInfo(FPT->getReturnType()); |
3986 | for (const auto &ai : FPT->param_types()) |
3987 | LV.merge(computeTypeLinkageInfo(ai)); |
3988 | return LV; |
3989 | } |
3990 | case Type::ObjCInterface: |
3991 | return getDeclLinkageAndVisibility(cast<ObjCInterfaceType>(T)->getDecl()); |
3992 | case Type::ObjCObject: |
3993 | return computeTypeLinkageInfo(cast<ObjCObjectType>(T)->getBaseType()); |
3994 | case Type::ObjCObjectPointer: |
3995 | return computeTypeLinkageInfo( |
3996 | cast<ObjCObjectPointerType>(T)->getPointeeType()); |
3997 | case Type::Atomic: |
3998 | return computeTypeLinkageInfo(cast<AtomicType>(T)->getValueType()); |
3999 | case Type::Pipe: |
4000 | return computeTypeLinkageInfo(cast<PipeType>(T)->getElementType()); |
4001 | } |
4002 | |
4003 | llvm_unreachable("unhandled type class"); |
4004 | } |
4005 | |
4006 | bool Type::isLinkageValid() const { |
4007 | if (!TypeBits.isCacheValid()) |
4008 | return true; |
4009 | |
4010 | Linkage L = LinkageComputer{} |
4011 | .computeTypeLinkageInfo(getCanonicalTypeInternal()) |
4012 | .getLinkage(); |
4013 | return L == TypeBits.getLinkage(); |
4014 | } |
4015 | |
4016 | LinkageInfo LinkageComputer::getTypeLinkageAndVisibility(const Type *T) { |
4017 | if (!T->isCanonicalUnqualified()) |
4018 | return computeTypeLinkageInfo(T->getCanonicalTypeInternal()); |
4019 | |
4020 | LinkageInfo LV = computeTypeLinkageInfo(T); |
4021 | assert(LV.getLinkage() == T->getLinkage()); |
4022 | return LV; |
4023 | } |
4024 | |
4025 | LinkageInfo Type::getLinkageAndVisibility() const { |
4026 | return LinkageComputer{}.getTypeLinkageAndVisibility(this); |
4027 | } |
4028 | |
4029 | Optional<NullabilityKind> |
4030 | Type::getNullability(const ASTContext &Context) const { |
4031 | QualType Type(this, 0); |
4032 | while (const auto *AT = Type->getAs<AttributedType>()) { |
4033 | |
4034 | |
4035 | if (auto Nullability = AT->getImmediateNullability()) |
4036 | return Nullability; |
4037 | |
4038 | Type = AT->getEquivalentType(); |
4039 | } |
4040 | return None; |
4041 | } |
4042 | |
4043 | bool Type::canHaveNullability(bool ResultIfUnknown) const { |
4044 | QualType type = getCanonicalTypeInternal(); |
4045 | |
4046 | switch (type->getTypeClass()) { |
4047 | |
4048 | #define NON_CANONICAL_TYPE(Class, Parent) \ |
4049 | case Type::Class: \ |
4050 | llvm_unreachable("non-canonical type"); |
4051 | #define TYPE(Class, Parent) |
4052 | #include "clang/AST/TypeNodes.inc" |
4053 | |
4054 | |
4055 | case Type::Pointer: |
4056 | case Type::BlockPointer: |
4057 | case Type::MemberPointer: |
4058 | case Type::ObjCObjectPointer: |
4059 | return true; |
4060 | |
4061 | |
4062 | case Type::UnresolvedUsing: |
4063 | case Type::TypeOfExpr: |
4064 | case Type::TypeOf: |
4065 | case Type::Decltype: |
4066 | case Type::UnaryTransform: |
4067 | case Type::TemplateTypeParm: |
4068 | case Type::SubstTemplateTypeParmPack: |
4069 | case Type::DependentName: |
4070 | case Type::DependentTemplateSpecialization: |
4071 | case Type::Auto: |
4072 | return ResultIfUnknown; |
4073 | |
4074 | |
4075 | |
4076 | |
4077 | case Type::TemplateSpecialization: |
4078 | if (TemplateDecl *templateDecl |
4079 | = cast<TemplateSpecializationType>(type.getTypePtr()) |
4080 | ->getTemplateName().getAsTemplateDecl()) { |
4081 | if (isa<ClassTemplateDecl>(templateDecl)) |
4082 | return false; |
4083 | } |
4084 | return ResultIfUnknown; |
4085 | |
4086 | case Type::Builtin: |
4087 | switch (cast<BuiltinType>(type.getTypePtr())->getKind()) { |
4088 | |
4089 | #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: |
4090 | #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id: |
4091 | #define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id: |
4092 | #define BUILTIN_TYPE(Id, SingletonId) |
4093 | #include "clang/AST/BuiltinTypes.def" |
4094 | return false; |
4095 | |
4096 | |
4097 | case BuiltinType::Dependent: |
4098 | case BuiltinType::Overload: |
4099 | case BuiltinType::BoundMember: |
4100 | case BuiltinType::PseudoObject: |
4101 | case BuiltinType::UnknownAny: |
4102 | case BuiltinType::ARCUnbridgedCast: |
4103 | return ResultIfUnknown; |
4104 | |
4105 | case BuiltinType::Void: |
4106 | case BuiltinType::ObjCId: |
4107 | case BuiltinType::ObjCClass: |
4108 | case BuiltinType::ObjCSel: |
4109 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
4110 | case BuiltinType::Id: |
4111 | #include "clang/Basic/OpenCLImageTypes.def" |
4112 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
4113 | case BuiltinType::Id: |
4114 | #include "clang/Basic/OpenCLExtensionTypes.def" |
4115 | case BuiltinType::OCLSampler: |
4116 | case BuiltinType::OCLEvent: |
4117 | case BuiltinType::OCLClkEvent: |
4118 | case BuiltinType::OCLQueue: |
4119 | case BuiltinType::OCLReserveID: |
4120 | #define SVE_TYPE(Name, Id, SingletonId) \ |
4121 | case BuiltinType::Id: |
4122 | #include "clang/Basic/AArch64SVEACLETypes.def" |
4123 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ |
4124 | case BuiltinType::Id: |
4125 | #include "clang/Basic/PPCTypes.def" |
4126 | #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id: |
4127 | #include "clang/Basic/RISCVVTypes.def" |
4128 | case BuiltinType::BuiltinFn: |
4129 | case BuiltinType::NullPtr: |
4130 | case BuiltinType::IncompleteMatrixIdx: |
4131 | case BuiltinType::OMPArraySection: |
4132 | case BuiltinType::OMPArrayShaping: |
4133 | case BuiltinType::OMPIterator: |
4134 | return false; |
4135 | } |
4136 | llvm_unreachable("unknown builtin type"); |
4137 | |
4138 | |
4139 | case Type::Complex: |
4140 | case Type::LValueReference: |
4141 | case Type::RValueReference: |
4142 | case Type::ConstantArray: |
4143 | case Type::IncompleteArray: |
4144 | case Type::VariableArray: |
4145 | case Type::DependentSizedArray: |
4146 | case Type::DependentVector: |
4147 | case Type::DependentSizedExtVector: |
4148 | case Type::Vector: |
4149 | case Type::ExtVector: |
4150 | case Type::ConstantMatrix: |
4151 | case Type::DependentSizedMatrix: |
4152 | case Type::DependentAddressSpace: |
4153 | case Type::FunctionProto: |
4154 | case Type::FunctionNoProto: |
4155 | case Type::Record: |
4156 | case Type::DeducedTemplateSpecialization: |
4157 | case Type::Enum: |
4158 | case Type::InjectedClassName: |
4159 | case Type::PackExpansion: |
4160 | case Type::ObjCObject: |
4161 | case Type::ObjCInterface: |
4162 | case Type::Atomic: |
4163 | case Type::Pipe: |
4164 | case Type::ExtInt: |
4165 | case Type::DependentExtInt: |
4166 | return false; |
4167 | } |
4168 | llvm_unreachable("bad type kind!"); |
4169 | } |
4170 | |
4171 | llvm::Optional<NullabilityKind> |
4172 | AttributedType::getImmediateNullability() const { |
4173 | if (getAttrKind() == attr::TypeNonNull) |
4174 | return NullabilityKind::NonNull; |
4175 | if (getAttrKind() == attr::TypeNullable) |
4176 | return NullabilityKind::Nullable; |
4177 | if (getAttrKind() == attr::TypeNullUnspecified) |
4178 | return NullabilityKind::Unspecified; |
4179 | if (getAttrKind() == attr::TypeNullableResult) |
4180 | return NullabilityKind::NullableResult; |
4181 | return None; |
4182 | } |
4183 | |
4184 | Optional<NullabilityKind> AttributedType::stripOuterNullability(QualType &T) { |
4185 | QualType AttrTy = T; |
4186 | if (auto MacroTy = dyn_cast<MacroQualifiedType>(T)) |
4187 | AttrTy = MacroTy->getUnderlyingType(); |
4188 | |
4189 | if (auto attributed = dyn_cast<AttributedType>(AttrTy)) { |
4190 | if (auto nullability = attributed->getImmediateNullability()) { |
4191 | T = attributed->getModifiedType(); |
4192 | return nullability; |
4193 | } |
4194 | } |
4195 | |
4196 | return None; |
4197 | } |
4198 | |
4199 | bool Type::isBlockCompatibleObjCPointerType(ASTContext &ctx) const { |
4200 | const auto *objcPtr = getAs<ObjCObjectPointerType>(); |
4201 | if (!objcPtr) |
4202 | return false; |
4203 | |
4204 | if (objcPtr->isObjCIdType()) { |
4205 | |
4206 | return true; |
4207 | } |
4208 | |
4209 | |
4210 | if (ObjCInterfaceDecl *iface = objcPtr->getInterfaceDecl()) { |
4211 | if (iface->getIdentifier() != ctx.getNSObjectName()) |
4212 | return false; |
4213 | |
4214 | |
4215 | } else if (objcPtr->isObjCQualifiedIdType()) { |
4216 | |
4217 | } else { |
4218 | return false; |
4219 | } |
4220 | |
4221 | |
4222 | for (ObjCProtocolDecl *proto : objcPtr->quals()) { |
4223 | |
4224 | if (proto->getIdentifier() != ctx.getNSObjectName() && |
4225 | proto->getIdentifier() != ctx.getNSCopyingName()) |
4226 | return false; |
4227 | } |
4228 | |
4229 | return true; |
4230 | } |
4231 | |
4232 | Qualifiers::ObjCLifetime Type::getObjCARCImplicitLifetime() const { |
4233 | if (isObjCARCImplicitlyUnretainedType()) |
4234 | return Qualifiers::OCL_ExplicitNone; |
4235 | return Qualifiers::OCL_Strong; |
4236 | } |
4237 | |
4238 | bool Type::isObjCARCImplicitlyUnretainedType() const { |
4239 | assert(isObjCLifetimeType() && |
4240 | "cannot query implicit lifetime for non-inferrable type"); |
4241 | |
4242 | const Type *canon = getCanonicalTypeInternal().getTypePtr(); |
4243 | |
4244 | |
4245 | while (const auto *array = dyn_cast<ArrayType>(canon)) |
4246 | canon = array->getElementType().getTypePtr(); |
4247 | |
4248 | if (const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) { |
4249 | |
4250 | if (opt->getObjectType()->isObjCClass()) |
4251 | return true; |
4252 | } |
4253 | |
4254 | return false; |
4255 | } |
4256 | |
4257 | bool Type::isObjCNSObjectType() const { |
4258 | const Type *cur = this; |
4259 | while (true) { |
4260 | if (const auto *typedefType = dyn_cast<TypedefType>(cur)) |
4261 | return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>(); |
4262 | |
4263 | |
4264 | QualType next = cur->getLocallyUnqualifiedSingleStepDesugaredType(); |
4265 | if (next.getTypePtr() == cur) return false; |
4266 | cur = next.getTypePtr(); |
4267 | } |
4268 | } |
4269 | |
4270 | bool Type::isObjCIndependentClassType() const { |
4271 | if (const auto *typedefType = dyn_cast<TypedefType>(this)) |
4272 | return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>(); |
4273 | return false; |
4274 | } |
4275 | |
4276 | bool Type::isObjCRetainableType() const { |
4277 | return isObjCObjectPointerType() || |
4278 | isBlockPointerType() || |
4279 | isObjCNSObjectType(); |
4280 | } |
4281 | |
4282 | bool Type::isObjCIndirectLifetimeType() const { |
4283 | if (isObjCLifetimeType()) |
4284 | return true; |
4285 | if (const auto *OPT = getAs<PointerType>()) |
4286 | return OPT->getPointeeType()->isObjCIndirectLifetimeType(); |
4287 | if (const auto *Ref = getAs<ReferenceType>()) |
4288 | return Ref->getPointeeType()->isObjCIndirectLifetimeType(); |
4289 | if (const auto *MemPtr = getAs<MemberPointerType>()) |
4290 | return MemPtr->getPointeeType()->isObjCIndirectLifetimeType(); |
4291 | return false; |
4292 | } |
4293 | |
4294 | |
4295 | |
4296 | bool Type::isObjCLifetimeType() const { |
4297 | const Type *type = this; |
4298 | while (const ArrayType *array = type->getAsArrayTypeUnsafe()) |
4299 | type = array->getElementType().getTypePtr(); |
4300 | return type->isObjCRetainableType(); |
4301 | } |
4302 | |
4303 | |
4304 | |
4305 | bool Type::isObjCARCBridgableType() const { |
4306 | return isObjCObjectPointerType() || isBlockPointerType(); |
4307 | } |
4308 | |
4309 | |
4310 | bool Type::isCARCBridgableType() const { |
4311 | const auto *Pointer = getAs<PointerType>(); |
4312 | if (!Pointer) |
4313 | return false; |
4314 | |
4315 | QualType Pointee = Pointer->getPointeeType(); |
4316 | return Pointee->isVoidType() || Pointee->isRecordType(); |
4317 | } |
4318 | |
4319 | |
4320 | bool Type::isCUDADeviceBuiltinSurfaceType() const { |
4321 | if (const auto *RT = getAs<RecordType>()) |
4322 | return RT->getDecl()->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>(); |
4323 | return false; |
4324 | } |
4325 | |
4326 | |
4327 | bool Type::isCUDADeviceBuiltinTextureType() const { |
4328 | if (const auto *RT = getAs<RecordType>()) |
4329 | return RT->getDecl()->hasAttr<CUDADeviceBuiltinTextureTypeAttr>(); |
4330 | return false; |
4331 | } |
4332 | |
4333 | bool Type::hasSizedVLAType() const { |
4334 | if (!isVariablyModifiedType()) return false; |
4335 | |
4336 | if (const auto *ptr = getAs<PointerType>()) |
4337 | return ptr->getPointeeType()->hasSizedVLAType(); |
4338 | if (const auto *ref = getAs<ReferenceType>()) |
4339 | return ref->getPointeeType()->hasSizedVLAType(); |
4340 | if (const ArrayType *arr = getAsArrayTypeUnsafe()) { |
4341 | if (isa<VariableArrayType>(arr) && |
4342 | cast<VariableArrayType>(arr)->getSizeExpr()) |
4343 | return true; |
4344 | |
4345 | return arr->getElementType()->hasSizedVLAType(); |
4346 | } |
4347 | |
4348 | return false; |
4349 | } |
4350 | |
4351 | QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) { |
4352 | switch (type.getObjCLifetime()) { |
4353 | case Qualifiers::OCL_None: |
4354 | case Qualifiers::OCL_ExplicitNone: |
4355 | case Qualifiers::OCL_Autoreleasing: |
4356 | break; |
4357 | |
4358 | case Qualifiers::OCL_Strong: |
4359 | return DK_objc_strong_lifetime; |
4360 | case Qualifiers::OCL_Weak: |
4361 | return DK_objc_weak_lifetime; |
4362 | } |
4363 | |
4364 | if (const auto *RT = |
4365 | type->getBaseElementTypeUnsafe()->getAs<RecordType>()) { |
4366 | const RecordDecl *RD = RT->getDecl(); |
4367 | if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { |
4368 | |
4369 | if (CXXRD->hasDefinition() && !CXXRD->hasTrivialDestructor()) |
4370 | return DK_cxx_destructor; |
4371 | } else { |
4372 | |
4373 | |
4374 | if (RD->isNonTrivialToPrimitiveDestroy()) |
4375 | return DK_nontrivial_c_struct; |
4376 | } |
4377 | } |
4378 | |
4379 | return DK_none; |
4380 | } |
4381 | |
4382 | CXXRecordDecl *MemberPointerType::getMostRecentCXXRecordDecl() const { |
4383 | return getClass()->getAsCXXRecordDecl()->getMostRecentNonInjectedDecl(); |
4384 | } |
4385 | |
4386 | void clang::FixedPointValueToString(SmallVectorImpl<char> &Str, |
4387 | llvm::APSInt Val, unsigned Scale) { |
4388 | llvm::FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(), |
4389 | false, |
4390 | false); |
4391 | llvm::APFixedPoint(Val, FXSema).toString(Str); |
4392 | } |
4393 | |
4394 | AutoType::AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword, |
4395 | TypeDependence ExtraDependence, |
4396 | ConceptDecl *TypeConstraintConcept, |
4397 | ArrayRef<TemplateArgument> TypeConstraintArgs) |
4398 | : DeducedType(Auto, DeducedAsType, ExtraDependence) { |
4399 | AutoTypeBits.Keyword = (unsigned)Keyword; |
4400 | AutoTypeBits.NumArgs = TypeConstraintArgs.size(); |
4401 | this->TypeConstraintConcept = TypeConstraintConcept; |
4402 | if (TypeConstraintConcept) { |
4403 | TemplateArgument *ArgBuffer = getArgBuffer(); |
4404 | for (const TemplateArgument &Arg : TypeConstraintArgs) { |
4405 | addDependence( |
4406 | toSyntacticDependence(toTypeDependence(Arg.getDependence()))); |
4407 | |
4408 | new (ArgBuffer++) TemplateArgument(Arg); |
4409 | } |
4410 | } |
4411 | } |
4412 | |
4413 | void AutoType::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
4414 | QualType Deduced, AutoTypeKeyword Keyword, |
4415 | bool IsDependent, ConceptDecl *CD, |
4416 | ArrayRef<TemplateArgument> Arguments) { |
4417 | ID.AddPointer(Deduced.getAsOpaquePtr()); |
4418 | ID.AddInteger((unsigned)Keyword); |
4419 | ID.AddBoolean(IsDependent); |
4420 | ID.AddPointer(CD); |
4421 | for (const TemplateArgument &Arg : Arguments) |
4422 | Arg.Profile(ID, Context); |
4423 | } |