17#include "llvm/ADT/StringExtras.h"
18#include "llvm/Support/ConvertUTF.h"
42 unsigned accumulator = 0;
43 bool hasDigits =
false;
47 if (c >=
'0' && c <=
'9') {
49 accumulator = (accumulator * 10) + (c -
'0');
64 unsigned &BitWidth,
unsigned &ModifierLength) {
65 StringRef W = StringRef(I, E - I).take_while(llvm::isDigit);
66 if (W.empty() || W.front() ==
'0')
69 if (W.getAsInteger(10, BitWidth))
73 ModifierLength += W.size();
79 const char *&Beg,
const char *E,
unsigned &argIndex) {
92 const char *I = Beg + 1;
117 const char *Tmp = Beg;
133 const char *&Beg,
const char *E,
unsigned *argIndex) {
192 const char *Start = I;
219 const char *lmPosition = I;
225 if (I != E && *I ==
'h') {
228 }
else if (I != E && *I ==
'l' && LO.OpenCL) {
237 if (I != E && *I ==
'l') {
265 if (IsScanf && !LO.C99 && !LO.CPlusPlus11) {
270 if (I != E && (*I ==
's' || *I ==
'S' || *I ==
'[')) {
287 if (I + 1 != E && I + 2 != E) {
288 if (I[1] ==
'6' && I[2] ==
'4') {
296 if (I[1] ==
'3' && I[2] ==
'2') {
315 if (I != E && *I ==
'D') {
326 const char *WidthModifier = I + 1;
327 unsigned BitWidth = 0;
328 unsigned ModifierLength = 1;
331 if (WidthModifier != E && *WidthModifier ==
'f') {
332 WidthModifier = I + 2;
354 const char *SpecifierBegin,
const char *FmtStrEnd,
unsigned &Len) {
355 if (SpecifierBegin + 1 >= FmtStrEnd)
358 const llvm::UTF8 *SB =
359 reinterpret_cast<const llvm::UTF8 *
>(SpecifierBegin + 1);
360 const llvm::UTF8 *SE =
reinterpret_cast<const llvm::UTF8 *
>(FmtStrEnd);
361 const char FirstByte = *SB;
366 unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
369 if (SB + NumBytes > SE)
385 const auto *TD = TT->getDecl();
386 const auto *DC = TT->getDecl()->getDeclContext();
387 if (DC->isTranslationUnit() || DC->isStdNamespace()) {
388 StringRef Name = TD->getIdentifier()->getName();
389 if (Name ==
"size_t") {
392 }
else if (Name ==
"ssize_t" ) {
395 }
else if (Name ==
"ptrdiff_t") {
398 }
else if (Name ==
"intmax_t") {
401 }
else if (Name ==
"uintmax_t") {
409 switch (PST->getKind()) {
411 case Kind::SignedSizeT:
418 llvm_unreachable(
"unexpected kind");
431 if (!T->isIntegerType() || T->isBooleanType())
432 return MatchKind::NoMatch;
434 if (
C.hasSameType(T, E))
435 return MatchKind::Match;
437 if (
C.getCorrespondingSignedType(T.getCanonicalType()) !=
439 return MatchKind::NoMatch;
441 return MatchKind::NoMatchSignedness;
450 argTy =
C.getDecayedType(argTy);
465 if (
const auto *OBT = argTy->
getAs<OverflowBehaviorType>())
466 argTy = OBT->getUnderlyingType();
470 llvm_unreachable(
"ArgType must be valid");
483 if (!ED->isComplete())
486 argTy = ED->getIntegerType();
491 switch (BT->getKind()) {
494 case BuiltinType::Char_S:
495 case BuiltinType::SChar:
496 case BuiltinType::UChar:
497 case BuiltinType::Char_U:
499 case BuiltinType::Bool:
506 switch (BT->getKind()) {
509 case BuiltinType::Int:
510 case BuiltinType::UInt:
512 case BuiltinType::Short:
513 case BuiltinType::UShort:
514 case BuiltinType::WChar_S:
515 case BuiltinType::WChar_U:
524 if (TK == TypeKind::SizeT || TK == TypeKind::PtrdiffT) {
532 if (!ED->isComplete())
534 else if (!ED->isScoped())
535 argTy = ED->getIntegerType();
539 argTy =
C.getCorrespondingUnsaturatedType(argTy);
541 argTy =
C.getCanonicalType(argTy).getUnqualifiedType();
548 switch (BT->getKind()) {
551 case BuiltinType::Bool:
552 if (Ptr && (T ==
C.UnsignedCharTy || T ==
C.SignedCharTy))
555 case BuiltinType::Char_S:
556 case BuiltinType::SChar:
557 if (T ==
C.UnsignedShortTy || T ==
C.ShortTy)
559 if (T ==
C.UnsignedCharTy)
561 if (T ==
C.SignedCharTy)
564 case BuiltinType::Char_U:
565 case BuiltinType::UChar:
566 if (T ==
C.UnsignedShortTy || T ==
C.ShortTy)
568 if (T ==
C.UnsignedCharTy)
570 if (T ==
C.SignedCharTy)
573 case BuiltinType::Short:
574 if (T ==
C.UnsignedShortTy)
577 case BuiltinType::UShort:
581 case BuiltinType::Int:
582 if (T ==
C.UnsignedIntTy)
585 case BuiltinType::UInt:
589 case BuiltinType::Long:
590 if (T ==
C.UnsignedLongTy)
593 case BuiltinType::ULong:
597 case BuiltinType::LongLong:
598 if (T ==
C.UnsignedLongLongTy)
601 case BuiltinType::ULongLong:
602 if (T ==
C.LongLongTy)
608 switch (BT->getKind()) {
611 case BuiltinType::Bool:
612 if (T ==
C.IntTy || T ==
C.UnsignedIntTy)
615 case BuiltinType::Int:
616 case BuiltinType::UInt:
617 if (T ==
C.SignedCharTy || T ==
C.UnsignedCharTy || T ==
C.ShortTy ||
618 T ==
C.UnsignedShortTy || T ==
C.WCharTy || T ==
C.WideCharTy)
621 case BuiltinType::Char_U:
622 if (T ==
C.UnsignedIntTy)
624 if (T ==
C.UnsignedShortTy)
627 case BuiltinType::Char_S:
633 case BuiltinType::Half:
634 case BuiltinType::Float:
638 case BuiltinType::Short:
639 case BuiltinType::UShort:
640 if (T ==
C.SignedCharTy || T ==
C.UnsignedCharTy)
643 case BuiltinType::WChar_U:
644 case BuiltinType::WChar_S:
645 if (T !=
C.WCharTy && T !=
C.WideCharTy)
662 C.hasSameUnqualifiedType(PT->getPointeeType(),
C.getWideCharType()))
667 QualType WInt =
C.getCanonicalType(
C.getWIntType()).getUnqualifiedType();
669 if (
C.getCanonicalType(argTy).getUnqualifiedType() == WInt)
672 QualType PromoArg =
C.isPromotableIntegerType(argTy)
673 ?
C.getPromotedIntegerType(argTy)
675 PromoArg =
C.getCanonicalType(PromoArg).getUnqualifiedType();
680 C.getCorrespondingUnsignedType(PromoArg) == WInt)
725 llvm_unreachable(
"Invalid ArgType Kind!");
732 uint64_t IntSize =
C.getTypeSize(
C.IntTy);
733 uint64_t ASize =
C.getTypeSize(A);
734 uint64_t BSize =
C.getTypeSize(B);
735 if (std::max(ASize, IntSize) != std::max(BSize, IntSize))
738 return MK::NoMatchSignedness;
740 return MK::MatchPromotion;
749 if (K == AK::InvalidTy ||
Other.K == AK::InvalidTy)
751 if (K == AK::UnsupportedTy ||
Other.K == AK::UnsupportedTy)
753 if (K == AK::UnknownTy ||
Other.K == AK::UnknownTy)
760 bool LeftWasPointer =
false;
762 bool RightWasPointer =
false;
765 LeftWasPointer =
true;
766 }
else if (Left.K == AK::SpecificTy && Left.T->isPointerType()) {
767 Left.T = Left.T->getPointeeType();
768 LeftWasPointer =
true;
772 RightWasPointer =
true;
773 }
else if (Right.K == AK::SpecificTy && Right.T->isPointerType()) {
774 Right.T = Right.T->getPointeeType();
775 RightWasPointer =
true;
778 if (LeftWasPointer != RightWasPointer)
783 if (Right.K == AK::SpecificTy)
784 std::swap(Left, Right);
786 if (Left.K == AK::SpecificTy) {
787 if (Right.K == AK::SpecificTy) {
788 if (Left.TK != TypeKind::DontCare) {
790 }
else if (Right.TK != TypeKind::DontCare) {
794 auto Canon1 =
C.getCanonicalType(Left.T);
795 auto Canon2 =
C.getCanonicalType(Right.T);
796 if (Canon1 == Canon2)
801 if (BT1 ==
nullptr || BT2 ==
nullptr)
806 if (!LeftWasPointer && BT1->isInteger() && BT2->
isInteger())
809 }
else if (Right.K == AK::AnyCharTy) {
810 if (!LeftWasPointer && Left.T->isIntegerType())
813 }
else if (Right.K == AK::WIntTy) {
814 if (!LeftWasPointer && Left.T->isIntegerType())
832 QualType Vec =
C.getExtVectorType(T, NumElts);
846 Res.TK = IsFast ? (
Signed ? TypeKind::FastIntN : TypeKind::FastUIntN)
847 : (
Signed ? TypeKind::IntN : TypeKind::UIntN);
856 llvm_unreachable(
"No representative type for Invalid ArgType");
858 llvm_unreachable(
"No representative type for Unknown ArgType");
860 llvm_unreachable(
"No representative type for Unsupported ArgType");
865 if (TK == TypeKind::PtrdiffT || TK == TypeKind::SizeT)
872 Res =
C.getPointerType(
C.CharTy);
875 Res =
C.getPointerType(
C.getWideCharType());
878 Res =
C.ObjCBuiltinIdTy;
884 Res =
C.getWIntType();
890 Res =
C.getPointerType(Res);
904 const char *Prefix =
nullptr;
909 case TypeKind::UIntN:
912 case TypeKind::FastIntN:
915 case TypeKind::FastUIntN:
916 Prefix =
"uint_fast";
918 case TypeKind::DontCare:
919 case TypeKind::SizeT:
920 case TypeKind::PtrdiffT:
925 Alias += std::to_string(BitWidth);
929 if (!Alias.empty()) {
932 Alias += (Alias[Alias.size() - 1] ==
'*') ?
"*" :
" *";
940 return std::string(
"'") + S +
"'";
942 return std::string(
"'") + Alias +
"'" +
1005 llvm_unreachable(
"Invalid LengthModifier Kind!");
1110std::optional<ConversionSpecifier>
1116 return std::nullopt;
1160 switch (
LM.getKind()) {
1167 if (LO.OpenCL &&
CS.isDoubleArg())
1170 if (
CS.isFixedPointArg())
1173 if (
Target.getTriple().isOSMSVCRT()) {
1174 switch (
CS.getKind()) {
1192 switch (
CS.getKind()) {
1208 return Target.getTriple().isOSFreeBSD() ||
Target.getTriple().isPS();
1218 if (
CS.isDoubleArg()) {
1225 if (
CS.isFixedPointArg())
1228 switch (
CS.getKind()) {
1248 return Target.getTriple().isOSFreeBSD() ||
Target.getTriple().isPS();
1254 switch (
CS.getKind()) {
1271 return !
Target.getTriple().isOSDarwin() &&
1272 !
Target.getTriple().isOSWindows();
1284 ?
Target.getIntTypeByWidth(
LM.getBitWidth(),
true)
1285 :
Target.getLeastIntTypeByWidth(
LM.getBitWidth(),
1290 switch (
CS.getKind()) {
1307 switch (
CS.getKind()) {
1317 switch (
CS.getKind()) {
1330 switch (
CS.getKind()) {
1337 return Target.getTriple().isOSMSVCRT();
1342 switch (
CS.getKind()) {
1348 return Target.getTriple().isOSMSVCRT();
1356 switch (
CS.getKind()) {
1370 llvm_unreachable(
"Invalid LengthModifier Kind!");
1374 switch (
LM.getKind()) {
1400 llvm_unreachable(
"Invalid LengthModifier Kind!");
1405 switch (
CS.getKind()) {
1433 return LangOpt.ObjC;
1449 return LangOpt.FixedPoint;
1451 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
1456 switch (
CS.getKind()) {
1471std::optional<LengthModifier>
1482 return std::nullopt;
Defines the clang::LangOptions interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth,...
QualType getLeastIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
This class is used for builtin types like 'int'.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents a pointer to an Objective C object.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
QualType getCanonicalType() const
bool isConstQualified() const
Determine whether this type is const-qualified.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Exposes information about the current target.
bool isStructureType() const
bool isBlockPointerType() const
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isSaturatedFixedPointType() const
Return true if this is a saturated fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g....
QualType getCanonicalTypeInternal() const
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
bool isObjCObjectPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
@ Other
Other implicit parameter.
IntType
===-— Target Data Type Query Methods ----------------------------—===//