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:
362 case BuiltinType::Bool:
372 if (!ETy->getDecl()->isComplete())
375 argTy = ETy->getDecl()->getIntegerType();
383 switch (BT->getKind()) {
386 case BuiltinType::Char_S:
387 case BuiltinType::SChar:
388 case BuiltinType::Char_U:
389 case BuiltinType::UChar:
390 case BuiltinType::Bool:
392 return NoMatchTypeConfusion;
395 case BuiltinType::Short:
397 case BuiltinType::UShort:
398 return T == C.
ShortTy ? Match : NoMatch;
399 case BuiltinType::Int:
401 case BuiltinType::UInt:
402 return T == C.
IntTy ? Match : NoMatch;
403 case BuiltinType::Long:
405 case BuiltinType::ULong:
406 return T == C.
LongTy ? Match : NoMatch;
407 case BuiltinType::LongLong:
409 case BuiltinType::ULongLong:
421 switch (BT->getKind()) {
422 case BuiltinType::Void:
423 case BuiltinType::Char_U:
424 case BuiltinType::UChar:
425 case BuiltinType::Char_S:
426 case BuiltinType::SChar:
461 return WInt == PromoArg ? Match : NoMatch;
469 return NoMatchPedantic;
474 case ObjCPointerTy: {
493 llvm_unreachable(
"Invalid ArgType Kind!");
499 return ArgType::Invalid();
509 llvm_unreachable(
"No representative type for Invalid ArgType");
511 llvm_unreachable(
"No representative type for Unknown ArgType");
541 std::string ArgType::getRepresentativeTypeName(
ASTContext &C)
const {
542 std::string S = getRepresentativeType(C).getAsString();
550 Alias += (Alias[Alias.size()-1] ==
'*') ?
"*" :
" *";
558 return std::string(
"'") + Alias +
"' (aka '" + S +
"')";
559 return std::string(
"'") + S +
"'";
623 case dArg:
return "d";
624 case DArg:
return "D";
625 case iArg:
return "i";
626 case oArg:
return "o";
627 case OArg:
return "O";
628 case uArg:
return "u";
629 case UArg:
return "U";
630 case xArg:
return "x";
631 case XArg:
return "X";
632 case fArg:
return "f";
633 case FArg:
return "F";
634 case eArg:
return "e";
635 case EArg:
return "E";
636 case gArg:
return "g";
637 case GArg:
return "G";
638 case aArg:
return "a";
639 case AArg:
return "A";
640 case cArg:
return "c";
641 case sArg:
return "s";
642 case pArg:
return "p";
645 case nArg:
return "n";
646 case PercentArg:
return "%";
647 case ScanListArg:
return "[";
648 case InvalidSpecifier:
return nullptr;
651 case CArg:
return "C";
652 case SArg:
return "S";
655 case ObjCObjArg:
return "@";
658 case FreeBSDbArg:
return "b";
659 case FreeBSDDArg:
return "D";
660 case FreeBSDrArg:
return "r";
661 case FreeBSDyArg:
return "y";
664 case PrintErrno:
return "m";
667 case ZArg:
return "Z";
722 switch (LM.getKind()) {
729 if (LO.OpenCL && CS.isDoubleArg())
730 return !VectorNumElts.isInvalid();
733 switch (CS.getKind()) {
751 switch (CS.getKind()) {
771 return LO.OpenCL && !VectorNumElts.isInvalid();
775 if (CS.isDoubleArg()) {
777 if (LO.OpenCL && VectorNumElts.isInvalid())
782 switch (CS.getKind()) {
806 switch (CS.getKind()) {
823 return !Target.
getTriple().isOSDarwin() &&
830 switch (CS.getKind()) {
840 switch (CS.getKind()) {
853 switch (CS.getKind()) {
865 switch (CS.getKind()) {
876 llvm_unreachable(
"Invalid LengthModifier Kind!");
880 switch (LM.getKind()) {
901 llvm_unreachable(
"Invalid LengthModifier Kind!");
906 switch (CS.getKind()) {
945 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
950 switch(CS.getKind()) {
980 assert(isa<TypedefType>(QT) &&
"Expected a TypedefType");
985 if (Identifier->
getName() ==
"size_t") {
988 }
else if (Identifier->
getName() ==
"ssize_t") {
992 }
else if (Identifier->
getName() ==
"intmax_t") {
995 }
else if (Identifier->
getName() ==
"uintmax_t") {
998 }
else if (Identifier->
getName() ==
"ptrdiff_t") {
1004 if (!isa<TypedefType>(T))
1007 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