17 #include "llvm/Support/ConvertUTF.h"
26 using namespace clang;
29 FormatStringHandler::~FormatStringHandler() {}
41 unsigned accumulator = 0;
42 bool hasDigits =
false;
44 for ( ; I != E; ++I) {
46 if (
c >=
'0' &&
c <=
'9') {
48 accumulator = (accumulator * 10) + (
c -
'0');
53 return OptionalAmount(OptionalAmount::Constant, accumulator, Beg, I - Beg,
68 return OptionalAmount(OptionalAmount::Arg, argIndex++, Beg, 0,
false);
81 const char *I = Beg + 1;
106 const char *Tmp = Beg;
125 const char *&Beg,
const char *E,
126 unsigned *argIndex) {
159 if (Amt.
getHowSpecified() == OptionalAmount::Constant && *(I++) ==
'$') {
170 FS.setUsesPositionalArg();
189 const char *Start = I;
204 FS.setVectorNumElts(NumElts);
217 const char *lmPosition = I;
223 if (I != E && *I ==
'h') {
225 lmKind = LengthModifier::AsChar;
226 }
else if (I != E && *I ==
'l' && LO.OpenCL) {
228 lmKind = LengthModifier::AsShortLong;
230 lmKind = LengthModifier::AsShort;
235 if (I != E && *I ==
'l') {
237 lmKind = LengthModifier::AsLongLong;
239 lmKind = LengthModifier::AsLong;
242 case 'j': lmKind = LengthModifier::AsIntMax; ++I;
break;
243 case 'z': lmKind = LengthModifier::AsSizeT; ++I;
break;
244 case 't': lmKind = LengthModifier::AsPtrDiff; ++I;
break;
245 case 'L': lmKind = LengthModifier::AsLongDouble; ++I;
break;
246 case 'q': lmKind = LengthModifier::AsQuad; ++I;
break;
248 if (IsScanf && !LO.C99 && !LO.CPlusPlus11) {
253 if (I != E && (*I ==
's' || *I ==
'S' || *I ==
'[')) {
254 lmKind = LengthModifier::AsAllocate;
262 lmKind = LengthModifier::AsMAllocate;
270 if (I + 1 != E && I + 2 != E) {
271 if (I[1] ==
'6' && I[2] ==
'4') {
273 lmKind = LengthModifier::AsInt64;
279 if (I[1] ==
'3' && I[2] ==
'2') {
281 lmKind = LengthModifier::AsInt32;
286 lmKind = LengthModifier::AsInt3264;
289 lmKind = LengthModifier::AsWide; ++I;
break;
292 FS.setLengthModifier(lm);
297 const char *SpecifierBegin,
const char *FmtStrEnd,
unsigned &Len) {
298 if (SpecifierBegin + 1 >= FmtStrEnd)
301 const llvm::UTF8 *SB =
302 reinterpret_cast<const llvm::UTF8 *
>(SpecifierBegin + 1);
303 const llvm::UTF8 *SE =
reinterpret_cast<const llvm::UTF8 *
>(FmtStrEnd);
304 const char FirstByte = *SB;
309 unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
312 if (SB + NumBytes > SE)
329 argTy = C.getDecayedType(argTy);
346 llvm_unreachable(
"ArgType must be valid");
356 if (!ETy->getDecl()->isComplete())
358 if (ETy->isUnscopedEnumerationType())
359 argTy = ETy->getDecl()->getIntegerType();
364 switch (BT->getKind()) {
367 case BuiltinType::Char_S:
368 case BuiltinType::SChar:
369 case BuiltinType::UChar:
370 case BuiltinType::Char_U:
372 case BuiltinType::Bool:
379 switch (BT->getKind()) {
382 case BuiltinType::Int:
383 case BuiltinType::UInt:
384 return MatchPromotion;
385 case BuiltinType::Short:
386 case BuiltinType::UShort:
387 case BuiltinType::WChar_S:
388 case BuiltinType::WChar_U:
389 return NoMatchPromotionTypeConfusion;
401 if (!ETy->getDecl()->isComplete())
403 else if (ETy->isUnscopedEnumerationType())
404 argTy = ETy->getDecl()->getIntegerType();
408 argTy = C.getCorrespondingUnsaturatedType(argTy);
410 argTy = C.getCanonicalType(argTy).getUnqualifiedType();
417 switch (BT->getKind()) {
420 case BuiltinType::Bool:
421 if (Ptr && (
T == C.UnsignedCharTy ||
T == C.SignedCharTy))
424 case BuiltinType::Char_S:
425 case BuiltinType::SChar:
426 if (
T == C.UnsignedShortTy ||
T == C.ShortTy)
427 return NoMatchTypeConfusion;
428 if (
T == C.UnsignedCharTy)
429 return NoMatchSignedness;
430 if (
T == C.SignedCharTy)
433 case BuiltinType::Char_U:
434 case BuiltinType::UChar:
435 if (
T == C.UnsignedShortTy ||
T == C.ShortTy)
436 return NoMatchTypeConfusion;
437 if (
T == C.UnsignedCharTy)
439 if (
T == C.SignedCharTy)
440 return NoMatchSignedness;
442 case BuiltinType::Short:
443 if (
T == C.UnsignedShortTy)
444 return NoMatchSignedness;
446 case BuiltinType::UShort:
448 return NoMatchSignedness;
450 case BuiltinType::Int:
451 if (
T == C.UnsignedIntTy)
452 return NoMatchSignedness;
454 case BuiltinType::UInt:
456 return NoMatchSignedness;
458 case BuiltinType::Long:
459 if (
T == C.UnsignedLongTy)
460 return NoMatchSignedness;
462 case BuiltinType::ULong:
464 return NoMatchSignedness;
466 case BuiltinType::LongLong:
467 if (
T == C.UnsignedLongLongTy)
468 return NoMatchSignedness;
470 case BuiltinType::ULongLong:
471 if (
T == C.LongLongTy)
472 return NoMatchSignedness;
477 switch (BT->getKind()) {
480 case BuiltinType::Bool:
481 if (
T == C.IntTy ||
T == C.UnsignedIntTy)
482 return MatchPromotion;
484 case BuiltinType::Int:
485 case BuiltinType::UInt:
486 if (
T == C.SignedCharTy ||
T == C.UnsignedCharTy ||
487 T == C.ShortTy ||
T == C.UnsignedShortTy ||
T == C.WCharTy ||
489 return MatchPromotion;
491 case BuiltinType::Char_U:
492 if (
T == C.UnsignedIntTy)
493 return MatchPromotion;
494 if (
T == C.UnsignedShortTy)
495 return NoMatchPromotionTypeConfusion;
497 case BuiltinType::Char_S:
499 return MatchPromotion;
501 return NoMatchPromotionTypeConfusion;
503 case BuiltinType::Half:
506 return MatchPromotion;
508 case BuiltinType::Short:
509 case BuiltinType::UShort:
510 if (
T == C.SignedCharTy ||
T == C.UnsignedCharTy)
511 return NoMatchPromotionTypeConfusion;
513 case BuiltinType::WChar_U:
514 case BuiltinType::WChar_S:
515 if (
T != C.WCharTy &&
T != C.WideCharTy)
516 return NoMatchPromotionTypeConfusion;
529 switch (BT->getKind()) {
530 case BuiltinType::Char_U:
531 case BuiltinType::UChar:
532 case BuiltinType::Char_S:
533 case BuiltinType::SChar:
548 return pointeeTy == C.getWideCharType() ? Match : NoMatch;
552 QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
554 if (C.getCanonicalType(argTy).getUnqualifiedType() == WInt)
557 QualType PromoArg = C.isPromotableIntegerType(argTy)
558 ? C.getPromotedIntegerType(argTy)
560 PromoArg = C.getCanonicalType(PromoArg).getUnqualifiedType();
565 C.getCorrespondingUnsignedType(PromoArg) == WInt)
568 return WInt == PromoArg ? Match : NoMatch;
576 return NoMatchPedantic;
581 case ObjCPointerTy: {
600 llvm_unreachable(
"Invalid ArgType Kind!");
606 return ArgType::Invalid();
608 QualType Vec = C.getExtVectorType(
T, NumElts);
616 llvm_unreachable(
"No representative type for Invalid ArgType");
618 llvm_unreachable(
"No representative type for Unknown ArgType");
626 Res = C.getPointerType(C.CharTy);
629 Res = C.getPointerType(C.getWideCharType());
632 Res = C.ObjCBuiltinIdTy;
638 Res = C.getWIntType();
644 Res = C.getPointerType(Res);
648 std::string ArgType::getRepresentativeTypeName(
ASTContext &C)
const {
649 std::string S = getRepresentativeType(C).getAsString(C.getPrintingPolicy());
657 Alias += (Alias[Alias.size()-1] ==
'*') ?
"*" :
" *";
665 return std::string(
"'") + Alias +
"' (aka '" + S +
"')";
666 return std::string(
"'") + S +
"'";
730 case bArg:
return "b";
731 case BArg:
return "B";
732 case dArg:
return "d";
733 case DArg:
return "D";
734 case iArg:
return "i";
735 case oArg:
return "o";
736 case OArg:
return "O";
737 case uArg:
return "u";
738 case UArg:
return "U";
739 case xArg:
return "x";
740 case XArg:
return "X";
741 case fArg:
return "f";
742 case FArg:
return "F";
743 case eArg:
return "e";
744 case EArg:
return "E";
745 case gArg:
return "g";
746 case GArg:
return "G";
747 case aArg:
return "a";
748 case AArg:
return "A";
749 case cArg:
return "c";
750 case sArg:
return "s";
751 case pArg:
return "p";
754 case nArg:
return "n";
760 case CArg:
return "C";
761 case SArg:
return "S";
776 case ZArg:
return "Z";
791 std::optional<ConversionSpecifier>
854 if (
Target.getTriple().isOSMSVCRT()) {
889 return Target.getTriple().isOSFreeBSD() ||
Target.getTriple().isPS();
929 return Target.getTriple().isOSFreeBSD() ||
Target.getTriple().isPS();
952 return !
Target.getTriple().isOSDarwin() &&
953 !
Target.getTriple().isOSWindows();
989 return Target.getTriple().isOSMSVCRT();
1000 return Target.getTriple().isOSMSVCRT();
1005 llvm_unreachable(
"Invalid LengthModifier Kind!");
1030 llvm_unreachable(
"Invalid LengthModifier Kind!");
1063 return LangOpt.ObjC;
1079 return LangOpt.FixedPoint;
1081 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
1101 std::optional<LengthModifier>
1112 return std::nullopt;
1118 QT = TT->getDecl()->getUnderlyingType()) {
1124 }
else if (
Identifier->getName() ==
"ssize_t") {
1128 }
else if (
Identifier->getName() ==
"intmax_t") {
1131 }
else if (
Identifier->getName() ==
"uintmax_t") {
1134 }
else if (
Identifier->getName() ==
"ptrdiff_t") {
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
__device__ __2f16 float c
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
This class is used for builtin types like 'int'.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents a pointer to an Objective C object.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isConstQualified() const
Determine whether this type is const-qualified.
Exposes information about the current target.
bool isBlockPointerType() const
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
bool isVoidPointerType() const
bool isPointerType() const
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....
const RecordType * getAsStructureType() const
bool isObjCObjectPointerType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isNullPtrType() const
Base class for declarations which introduce a typedef-name.
Defines the clang::TargetInfo interface.
constexpr XRayInstrMask None
unsigned kind
All of the diagnostics that can be emitted by the frontend.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T