18 #include "llvm/Support/ConvertUTF.h" 27 using namespace clang;
30 FormatStringHandler::~FormatStringHandler() {}
42 unsigned accumulator = 0;
43 bool hasDigits =
false;
45 for ( ; I != E; ++I) {
47 if (c >=
'0' && c <=
'9') {
49 accumulator = (accumulator * 10) + (c -
'0');
54 return OptionalAmount(OptionalAmount::Constant, accumulator, Beg, I - Beg,
69 return OptionalAmount(OptionalAmount::Arg, argIndex++, Beg, 0,
false);
82 const char *I = Beg + 1;
107 const char *Tmp = Beg;
126 const char *&Beg,
const char *E,
127 unsigned *argIndex) {
160 if (Amt.
getHowSpecified() == OptionalAmount::Constant && *(I++) ==
'$') {
190 const char *Start = I;
218 const char *lmPosition = I;
224 if (I != E && *I ==
'h') {
226 lmKind = LengthModifier::AsChar;
228 lmKind = LengthModifier::AsShort;
233 if (I != E && *I ==
'l') {
235 lmKind = LengthModifier::AsLongLong;
237 lmKind = LengthModifier::AsLong;
240 case 'j': lmKind = LengthModifier::AsIntMax; ++I;
break;
241 case 'z': lmKind = LengthModifier::AsSizeT; ++I;
break;
242 case 't': lmKind = LengthModifier::AsPtrDiff; ++I;
break;
243 case 'L': lmKind = LengthModifier::AsLongDouble; ++I;
break;
244 case 'q': lmKind = LengthModifier::AsQuad; ++I;
break;
246 if (IsScanf && !LO.C99 && !LO.CPlusPlus11) {
251 if (I != E && (*I ==
's' || *I ==
'S' || *I ==
'[')) {
252 lmKind = LengthModifier::AsAllocate;
260 lmKind = LengthModifier::AsMAllocate;
268 if (I + 1 != E && I + 2 != E) {
269 if (I[1] ==
'6' && I[2] ==
'4') {
271 lmKind = LengthModifier::AsInt64;
277 if (I[1] ==
'3' && I[2] ==
'2') {
279 lmKind = LengthModifier::AsInt32;
284 lmKind = LengthModifier::AsInt3264;
287 lmKind = LengthModifier::AsWide; ++I;
break;
295 const char *SpecifierBegin,
const char *FmtStrEnd,
unsigned &Len) {
296 if (SpecifierBegin + 1 >= FmtStrEnd)
299 const llvm::UTF8 *SB =
300 reinterpret_cast<const llvm::UTF8 *
>(SpecifierBegin + 1);
301 const llvm::UTF8 *SE =
reinterpret_cast<const llvm::UTF8 *
>(FmtStrEnd);
302 const char FirstByte = *SB;
307 unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
310 if (SB + NumBytes > SE)
338 llvm_unreachable(
"ArgType must be valid");
347 if (!ETy->getDecl()->isComplete())
349 argTy = ETy->getDecl()->getIntegerType();
353 switch (BT->getKind()) {
356 case BuiltinType::Char_S:
357 case BuiltinType::SChar:
358 case BuiltinType::UChar:
359 case BuiltinType::Char_U:
369 if (!ETy->getDecl()->isComplete())
372 argTy = ETy->getDecl()->getIntegerType();
380 switch (BT->getKind()) {
383 case BuiltinType::Char_S:
384 case BuiltinType::SChar:
385 case BuiltinType::Char_U:
386 case BuiltinType::UChar:
389 case BuiltinType::Short:
391 case BuiltinType::UShort:
392 return T == C.
ShortTy ? Match : NoMatch;
393 case BuiltinType::Int:
395 case BuiltinType::UInt:
396 return T == C.
IntTy ? Match : NoMatch;
397 case BuiltinType::Long:
399 case BuiltinType::ULong:
400 return T == C.
LongTy ? Match : NoMatch;
401 case BuiltinType::LongLong:
403 case BuiltinType::ULongLong:
415 switch (BT->getKind()) {
416 case BuiltinType::Void:
417 case BuiltinType::Char_U:
418 case BuiltinType::UChar:
419 case BuiltinType::Char_S:
420 case BuiltinType::SChar:
455 return WInt == PromoArg ? Match : NoMatch;
463 return NoMatchPedantic;
468 case ObjCPointerTy: {
487 llvm_unreachable(
"Invalid ArgType Kind!");
492 return ArgType::Invalid();
502 llvm_unreachable(
"No representative type for Invalid ArgType");
504 llvm_unreachable(
"No representative type for Unknown ArgType");
534 std::string ArgType::getRepresentativeTypeName(
ASTContext &C)
const {
535 std::string S = getRepresentativeType(C).getAsString();
543 Alias += (Alias[Alias.size()-1] ==
'*') ?
"*" :
" *";
551 return std::string(
"'") + Alias +
"' (aka '" + S +
"')";
552 return std::string(
"'") + S +
"'";
614 case dArg:
return "d";
615 case DArg:
return "D";
616 case iArg:
return "i";
617 case oArg:
return "o";
618 case OArg:
return "O";
619 case uArg:
return "u";
620 case UArg:
return "U";
621 case xArg:
return "x";
622 case XArg:
return "X";
623 case fArg:
return "f";
624 case FArg:
return "F";
625 case eArg:
return "e";
626 case EArg:
return "E";
627 case gArg:
return "g";
628 case GArg:
return "G";
629 case aArg:
return "a";
630 case AArg:
return "A";
631 case cArg:
return "c";
632 case sArg:
return "s";
633 case pArg:
return "p";
636 case nArg:
return "n";
637 case PercentArg:
return "%";
638 case ScanListArg:
return "[";
639 case InvalidSpecifier:
return nullptr;
642 case CArg:
return "C";
643 case SArg:
return "S";
646 case ObjCObjArg:
return "@";
649 case FreeBSDbArg:
return "b";
650 case FreeBSDDArg:
return "D";
651 case FreeBSDrArg:
return "r";
652 case FreeBSDyArg:
return "y";
655 case PrintErrno:
return "m";
658 case ZArg:
return "Z";
712 switch (LM.getKind()) {
719 switch (CS.getKind()) {
737 switch (CS.getKind()) {
758 switch (CS.getKind()) {
790 switch (CS.getKind()) {
807 return !Target.
getTriple().isOSDarwin() &&
814 switch (CS.getKind()) {
824 switch (CS.getKind()) {
837 switch (CS.getKind()) {
849 switch (CS.getKind()) {
860 llvm_unreachable(
"Invalid LengthModifier Kind!");
864 switch (LM.getKind()) {
884 llvm_unreachable(
"Invalid LengthModifier Kind!");
889 switch (CS.getKind()) {
928 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
933 switch(CS.getKind()) {
963 assert(isa<TypedefType>(QT) &&
"Expected a TypedefType");
968 if (Identifier->
getName() ==
"size_t") {
971 }
else if (Identifier->
getName() ==
"ssize_t") {
975 }
else if (Identifier->
getName() ==
"intmax_t") {
978 }
else if (Identifier->
getName() ==
"uintmax_t") {
981 }
else if (Identifier->
getName() ==
"ptrdiff_t") {
987 if (!isa<TypedefType>(T))
990 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