18 #include "llvm/Support/Regex.h"
27 using namespace clang;
39 const char *Start,
const char *&Beg,
const char *
E,
54 const char *FlagBeg,
const char *
E,
bool Warn) {
55 StringRef Flag(FlagBeg,
E - FlagBeg);
58 FS.setHasObjCTechnicalTerm(FlagBeg);
78 bool isFreeBSDKPrintf) {
84 const char *Start =
nullptr;
88 for ( ; I !=
E ; ++I) {
125 unsigned char PrivacyFlags = 0;
126 StringRef MatchedStr;
129 StringRef Str(I,
E - I);
130 std::string Match =
"^[[:space:]]*"
131 "(private|public|sensitive|mask\\.[^[:space:],}]*)"
133 llvm::Regex R(Match);
136 if (R.match(Str, &Matches)) {
137 MatchedStr = Matches[1];
138 I += Matches[0].size();
143 if (MatchedStr.starts_with(
"mask")) {
144 StringRef MaskType = MatchedStr.substr(
sizeof(
"mask.") - 1);
145 unsigned Size = MaskType.size();
146 if (Warn && (Size == 0 || Size > 8))
148 FS.setMaskType(MaskType);
149 }
else if (MatchedStr ==
"sensitive")
151 else if (PrivacyFlags !=
153 MatchedStr ==
"private")
155 else if (PrivacyFlags == 0 && MatchedStr ==
"public")
158 size_t CommaOrBracePos =
159 Str.find_if([](
char c) {
return c ==
',' ||
c ==
'}'; });
161 if (CommaOrBracePos == StringRef::npos) {
168 I += CommaOrBracePos + 1;
171 }
while (*(I - 1) ==
',');
174 switch (PrivacyFlags) {
178 FS.setIsPrivate(MatchedStr.data());
181 FS.setIsPublic(MatchedStr.data());
184 FS.setIsSensitive(MatchedStr.data());
187 llvm_unreachable(
"Unexpected privacy flag value");
193 for ( ; I !=
E; ++I) {
195 default: hasMore =
false;
break;
198 FS.setHasThousandsGrouping(I);
200 case '-': FS.setIsLeftJustified(I);
break;
201 case '+': FS.setHasPlusPrefix(I);
break;
202 case ' ': FS.setHasSpacePrefix(I);
break;
203 case '#': FS.setHasAlternativeForm(I);
break;
204 case '0': FS.setHasLeadingZeros(I);
break;
219 FS.usesPositionalArg() ?
nullptr : &argIndex))
239 FS.usesPositionalArg() ?
nullptr : &argIndex))
267 const char *ObjCModifierFlagsStart =
nullptr,
268 *ObjCModifierFlagsEnd =
nullptr;
270 ObjCModifierFlagsStart = I;
274 ObjCModifierFlagsEnd = I;
300 const char *conversionPosition = I++;
302 switch (*conversionPosition) {
331 if (isFreeBSDKPrintf)
349 if (isFreeBSDKPrintf)
351 else if (LO.FixedPoint)
355 if (isFreeBSDKPrintf)
360 if (isFreeBSDKPrintf)
362 else if (
Target.getTriple().isOSDarwin())
366 if (
Target.getTriple().isOSDarwin())
370 if (
Target.getTriple().isOSDarwin())
375 if (
Target.getTriple().isOSMSVCRT())
398 ObjCModifierFlagsStart) {
400 ObjCModifierFlagsEnd + 1,
406 FS.setConversionSpecifier(CS);
408 FS.setArgIndex(argIndex++);
415 unsigned Len = I - Start;
418 FS.setConversionSpecifier(CS);
431 bool isFreeBSDKPrintf) {
433 unsigned argIndex = 0;
453 assert(I ==
E &&
"Format string not exhausted");
462 unsigned argIndex = 0;
480 if (FS.getConversionSpecifier().getKind() == ConversionSpecifier::Kind::sArg)
489 unsigned ArgIndex = 0;
508 bool IsObjCLiteral)
const {
510 switch (LM.getKind()) {
525 switch (LM.getKind()) {
550 :
ArgType(Ctx.IntTy,
"__int32");
561 switch (LM.getKind()) {
585 :
ArgType(Ctx.UnsignedIntTy,
"unsigned __int32");
595 if (CS.isDoubleArg()) {
596 if (!VectorNumElts.isInvalid()) {
597 switch (LM.getKind()) {
614 switch (LM.getKind()) {
642 llvm_unreachable(
"only used for OpenCL which doesn not handle nArg");
646 if (CS.isFixedPointArg() && !Ctx.
getLangOpts().FixedPoint)
649 switch (CS.getKind()) {
681 switch (LM.getKind()) {
692 switch (LM.getKind()) {
703 switch (LM.getKind()) {
714 switch (LM.getKind()) {
734 bool IsObjCLiteral)
const {
740 ArgType ScalarTy = getScalarArgType(Ctx, IsObjCLiteral);
741 if (!ScalarTy.
isValid() || VectorNumElts.isInvalid())
744 return ScalarTy.
makeVectorType(Ctx, VectorNumElts.getConstantAmount());
764 HasThousandsGrouping =
false;
765 HasPlusPrefix =
false;
766 HasSpacePrefix =
false;
767 HasAlternativeForm =
false;
768 HasLeadingZeroes =
false;
780 HasAlternativeForm =
false;
781 HasLeadingZeroes =
false;
794 QT = ETy->getDecl()->getIntegerType();
812 case BuiltinType::Bool:
813 case BuiltinType::WChar_U:
814 case BuiltinType::WChar_S:
815 case BuiltinType::Char8:
816 case BuiltinType::Char16:
817 case BuiltinType::Char32:
818 case BuiltinType::UInt128:
819 case BuiltinType::Int128:
820 case BuiltinType::Half:
821 case BuiltinType::BFloat16:
822 case BuiltinType::Float16:
823 case BuiltinType::Float128:
824 case BuiltinType::Ibm128:
825 case BuiltinType::ShortAccum:
826 case BuiltinType::Accum:
827 case BuiltinType::LongAccum:
828 case BuiltinType::UShortAccum:
829 case BuiltinType::UAccum:
830 case BuiltinType::ULongAccum:
831 case BuiltinType::ShortFract:
832 case BuiltinType::Fract:
833 case BuiltinType::LongFract:
834 case BuiltinType::UShortFract:
835 case BuiltinType::UFract:
836 case BuiltinType::ULongFract:
837 case BuiltinType::SatShortAccum:
838 case BuiltinType::SatAccum:
839 case BuiltinType::SatLongAccum:
840 case BuiltinType::SatUShortAccum:
841 case BuiltinType::SatUAccum:
842 case BuiltinType::SatULongAccum:
843 case BuiltinType::SatShortFract:
844 case BuiltinType::SatFract:
845 case BuiltinType::SatLongFract:
846 case BuiltinType::SatUShortFract:
847 case BuiltinType::SatUFract:
848 case BuiltinType::SatULongFract:
852 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
853 case BuiltinType::Id:
854 #include "clang/Basic/OpenCLImageTypes.def"
855 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
856 case BuiltinType::Sampled##Id:
857 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
858 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
859 #include "clang/Basic/OpenCLImageTypes.def"
860 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
861 case BuiltinType::Id:
862 #include "clang/Basic/OpenCLExtensionTypes.def"
863 #define SVE_TYPE(Name, Id, SingletonId) \
864 case BuiltinType::Id:
865 #include "clang/Basic/AArch64SVEACLETypes.def"
866 #define PPC_VECTOR_TYPE(Name, Id, Size) \
867 case BuiltinType::Id:
868 #include "clang/Basic/PPCTypes.def"
869 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
870 #include "clang/Basic/RISCVVTypes.def"
871 #define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
872 #include "clang/Basic/WebAssemblyReferenceTypes.def"
873 #define AMDGPU_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
874 #include "clang/Basic/AMDGPUTypes.def"
875 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
876 #include "clang/Basic/HLSLIntangibleTypes.def"
877 #define SIGNED_TYPE(Id, SingletonId)
878 #define UNSIGNED_TYPE(Id, SingletonId)
879 #define FLOATING_TYPE(Id, SingletonId)
880 #define BUILTIN_TYPE(Id, SingletonId) \
881 case BuiltinType::Id:
882 #include "clang/AST/BuiltinTypes.def"
886 case BuiltinType::UInt:
887 case BuiltinType::Int:
889 LM.setKind(VectorNumElts.isInvalid() ?
892 case BuiltinType::Double:
893 LM.setKind(VectorNumElts.isInvalid() ?
896 case BuiltinType::Char_U:
897 case BuiltinType::UChar:
898 case BuiltinType::Char_S:
899 case BuiltinType::SChar:
903 case BuiltinType::Short:
904 case BuiltinType::UShort:
908 case BuiltinType::Long:
909 case BuiltinType::ULong:
913 case BuiltinType::LongLong:
914 case BuiltinType::ULongLong:
918 case BuiltinType::LongDouble:
924 if (LangOpt.C99 || LangOpt.CPlusPlus11)
925 namedTypeToLengthModifier(QT, LM);
930 switch (CS.getKind()) {
958 HasAlternativeForm =
false;
959 HasLeadingZeroes =
false;
960 HasPlusPrefix =
false;
967 HasAlternativeForm =
false;
970 HasAlternativeForm =
false;
971 HasPlusPrefix =
false;
973 llvm_unreachable(
"Unexpected type");
985 if (usesPositionalArg()) {
986 os << getPositionalArgIndex() <<
"$";
990 if (IsLeftJustified) os <<
"-";
991 if (HasPlusPrefix) os <<
"+";
992 if (HasSpacePrefix) os <<
" ";
993 if (HasAlternativeForm) os <<
"#";
994 if (HasLeadingZeroes) os <<
"0";
997 FieldWidth.toString(os);
999 Precision.toString(os);
1002 if (!VectorNumElts.isInvalid())
1003 os <<
'v' << VectorNumElts.getConstantAmount();
1006 os << LM.toString();
1008 os << CS.toString();
1011 bool PrintfSpecifier::hasValidPlusPrefix()
const {
1016 switch (CS.getKind()) {
1039 bool PrintfSpecifier::hasValidAlternativeForm()
const {
1040 if (!HasAlternativeForm)
1044 switch (CS.getKind()) {
1072 bool PrintfSpecifier::hasValidLeadingZeros()
const {
1073 if (!HasLeadingZeroes)
1077 switch (CS.getKind()) {
1110 bool PrintfSpecifier::hasValidSpacePrefix()
const {
1111 if (!HasSpacePrefix)
1115 switch (CS.getKind()) {
1138 bool PrintfSpecifier::hasValidLeftJustified()
const {
1139 if (!IsLeftJustified)
1143 switch (CS.getKind()) {
1152 bool PrintfSpecifier::hasValidThousandsGroupingPrefix()
const {
1153 if (!HasThousandsGrouping)
1156 switch (CS.getKind()) {
1172 bool PrintfSpecifier::hasValidPrecision()
const {
1177 switch (CS.getKind()) {
1211 bool PrintfSpecifier::hasValidFieldWidth()
const {
1216 switch (CS.getKind()) {
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 ...
CanQualType UnsignedShortAccumTy
QualType getUnsignedPointerDiffType() const
Return the unique unsigned counterpart of "ptrdiff_t" integer type.
CanQualType getIntMaxType() const
Return the unique type for "intmax_t" (C99 7.18.1.5), defined in <stdint.h>.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
CanQualType UnsignedLongFractTy
const LangOptions & getLangOpts() const
QualType getPointerDiffType() const
Return the unique type for "ptrdiff_t" (C99 7.17) defined in <stddef.h>.
CanQualType UnsignedFractTy
CanQualType UnsignedLongTy
CanQualType UnsignedLongAccumTy
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
CanQualType UnsignedCharTy
CanQualType UnsignedShortFractTy
CanQualType UnsignedIntTy
CanQualType UnsignedLongLongTy
CanQualType UnsignedShortTy
const TargetInfo & getTargetInfo() const
CanQualType getSignedSizeType() const
Return the unique signed counterpart of the integer type corresponding to size_t.
CanQualType getUIntMaxType() const
Return the unique type for "uintmax_t" (C99 7.18.1.5), defined in <stdint.h>.
CanQualType UnsignedAccumTy
This class is used for builtin types like 'int'.
QualType withConst() const
Retrieves a version of this type with const applied.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
Exposes information about the current target.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isPointerType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isAnyCharacterType() const
Determine whether this type is any of the built-in character types.
bool isRealFloatingType() const
Floating point categories.
bool isWideCharType() const
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
const T * getAs() const
Member-template getAs<specific type>'.
bool isObjCRetainableType() const
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
Defines the clang::TargetInfo interface.
Pieces specific to fprintf format strings.
std::string toString(const til::SExpr *E)
The JSON file list parser is used to communicate input to InstallAPI.