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++) ==
'$') {
189 const char *Start = I;
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;
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)
340 llvm_unreachable(
"ArgType must be valid");
349 if (!ETy->getDecl()->isComplete())
351 argTy = ETy->getDecl()->getIntegerType();
355 switch (BT->getKind()) {
358 case BuiltinType::Char_S:
359 case BuiltinType::SChar:
360 case BuiltinType::UChar:
361 case BuiltinType::Char_U:
371 if (!ETy->getDecl()->isComplete())
374 argTy = ETy->getDecl()->getIntegerType();
382 switch (BT->getKind()) {
385 case BuiltinType::Char_S:
386 case BuiltinType::SChar:
387 case BuiltinType::Char_U:
388 case BuiltinType::UChar:
391 case BuiltinType::Short:
393 case BuiltinType::UShort:
394 return T == C.
ShortTy ? Match : NoMatch;
395 case BuiltinType::Int:
397 case BuiltinType::UInt:
398 return T == C.
IntTy ? Match : NoMatch;
399 case BuiltinType::Long:
401 case BuiltinType::ULong:
402 return T == C.
LongTy ? Match : NoMatch;
403 case BuiltinType::LongLong:
405 case BuiltinType::ULongLong:
417 switch (BT->getKind()) {
418 case BuiltinType::Void:
419 case BuiltinType::Char_U:
420 case BuiltinType::UChar:
421 case BuiltinType::Char_S:
422 case BuiltinType::SChar:
457 return WInt == PromoArg ? Match : NoMatch;
465 return NoMatchPedantic;
470 case ObjCPointerTy: {
489 llvm_unreachable(
"Invalid ArgType Kind!");
495 return ArgType::Invalid();
505 llvm_unreachable(
"No representative type for Invalid ArgType");
507 llvm_unreachable(
"No representative type for Unknown ArgType");
537 std::string ArgType::getRepresentativeTypeName(
ASTContext &C)
const {
538 std::string S = getRepresentativeType(C).getAsString();
546 Alias += (Alias[Alias.size()-1] ==
'*') ?
"*" :
" *";
554 return std::string(
"'") + Alias +
"' (aka '" + S +
"')";
555 return std::string(
"'") + S +
"'";
619 case dArg:
return "d";
620 case DArg:
return "D";
621 case iArg:
return "i";
622 case oArg:
return "o";
623 case OArg:
return "O";
624 case uArg:
return "u";
625 case UArg:
return "U";
626 case xArg:
return "x";
627 case XArg:
return "X";
628 case fArg:
return "f";
629 case FArg:
return "F";
630 case eArg:
return "e";
631 case EArg:
return "E";
632 case gArg:
return "g";
633 case GArg:
return "G";
634 case aArg:
return "a";
635 case AArg:
return "A";
636 case cArg:
return "c";
637 case sArg:
return "s";
638 case pArg:
return "p";
641 case nArg:
return "n";
642 case PercentArg:
return "%";
643 case ScanListArg:
return "[";
644 case InvalidSpecifier:
return nullptr;
647 case CArg:
return "C";
648 case SArg:
return "S";
651 case ObjCObjArg:
return "@";
654 case FreeBSDbArg:
return "b";
655 case FreeBSDDArg:
return "D";
656 case FreeBSDrArg:
return "r";
657 case FreeBSDyArg:
return "y";
660 case PrintErrno:
return "m";
663 case ZArg:
return "Z";
718 switch (LM.getKind()) {
725 if (LO.OpenCL && CS.isDoubleArg())
726 return !VectorNumElts.isInvalid();
729 switch (CS.getKind()) {
747 switch (CS.getKind()) {
767 return LO.OpenCL && !VectorNumElts.isInvalid();
771 if (CS.isDoubleArg()) {
773 if (LO.OpenCL && VectorNumElts.isInvalid())
778 switch (CS.getKind()) {
802 switch (CS.getKind()) {
819 return !Target.
getTriple().isOSDarwin() &&
826 switch (CS.getKind()) {
836 switch (CS.getKind()) {
849 switch (CS.getKind()) {
861 switch (CS.getKind()) {
872 llvm_unreachable(
"Invalid LengthModifier Kind!");
876 switch (LM.getKind()) {
897 llvm_unreachable(
"Invalid LengthModifier Kind!");
902 switch (CS.getKind()) {
941 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
946 switch(CS.getKind()) {
976 assert(isa<TypedefType>(QT) &&
"Expected a TypedefType");
981 if (Identifier->
getName() ==
"size_t") {
984 }
else if (Identifier->
getName() ==
"ssize_t") {
988 }
else if (Identifier->
getName() ==
"intmax_t") {
991 }
else if (Identifier->
getName() ==
"uintmax_t") {
994 }
else if (Identifier->
getName() ==
"ptrdiff_t") {
1000 if (!isa<TypedefType>(T))
1003 Typedef = cast<TypedefType>(T)->getDecl();
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
const RecordType * getAsStructureType() const
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
QualType getCorrespondingUnsignedType(QualType T) const
const T * getAs() const
Member-template getAs<specific type>'.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
CanQualType UnsignedCharTy
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
Exposes information about the current target.
Defines the clang::LangOptions interface.
bool isNullPtrType() const
bool isVoidPointerType() const
bool isConstQualified() const
Determine whether this type is const-qualified.
QualType getWideCharType() const
Return the type of wide characters.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size...
QualType getWIntType() const
In C99, this returns a type compatible with the type defined in <stddef.h> as defined by the target...
bool isObjCObjectPointerType() const
StringRef getName() const
Return the actual identifier string.
CanQualType UnsignedShortTy
Base class for declarations which introduce a typedef-name.
CanQualType ObjCBuiltinIdTy
Dataflow Directional Tag Classes.
QualType getUnderlyingType() const
CanQualType UnsignedLongLongTy
Represents a pointer to an Objective C object.
CanQualType UnsignedLongTy
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
bool hasSignedIntegerRepresentation() const
Determine whether this type has an signed integer representation of some sort, e.g., it is an signed integer type or a vector.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
This class is used for builtin types like 'int'.
Defines the clang::TargetInfo interface.
static Decl::Kind getKind(const Decl *D)
bool isPointerType() const
CanQualType UnsignedIntTy