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++) ==
'$') {
188 const char *lmPosition =
I;
194 if (I != E && *I ==
'h') {
196 lmKind = LengthModifier::AsChar;
198 lmKind = LengthModifier::AsShort;
203 if (I != E && *I ==
'l') {
205 lmKind = LengthModifier::AsLongLong;
207 lmKind = LengthModifier::AsLong;
210 case 'j': lmKind = LengthModifier::AsIntMax; ++
I;
break;
211 case 'z': lmKind = LengthModifier::AsSizeT; ++
I;
break;
212 case 't': lmKind = LengthModifier::AsPtrDiff; ++
I;
break;
213 case 'L': lmKind = LengthModifier::AsLongDouble; ++
I;
break;
214 case 'q': lmKind = LengthModifier::AsQuad; ++
I;
break;
216 if (IsScanf && !LO.C99 && !LO.CPlusPlus11) {
221 if (I != E && (*I ==
's' || *I ==
'S' || *I ==
'[')) {
222 lmKind = LengthModifier::AsAllocate;
230 lmKind = LengthModifier::AsMAllocate;
238 if (I + 1 != E && I + 2 != E) {
239 if (I[1] ==
'6' && I[2] ==
'4') {
241 lmKind = LengthModifier::AsInt64;
247 if (I[1] ==
'3' && I[2] ==
'2') {
249 lmKind = LengthModifier::AsInt32;
254 lmKind = LengthModifier::AsInt3264;
257 lmKind = LengthModifier::AsWide; ++
I;
break;
265 const char *SpecifierBegin,
const char *FmtStrEnd,
unsigned &Len) {
266 if (SpecifierBegin + 1 >= FmtStrEnd)
269 const UTF8 *SB =
reinterpret_cast<const UTF8 *
>(SpecifierBegin + 1);
270 const UTF8 *SE =
reinterpret_cast<const UTF8 *
>(FmtStrEnd);
271 const char FirstByte = *SB;
276 unsigned NumBytes = getNumBytesForUTF8(FirstByte);
279 if (SB + NumBytes > SE)
307 llvm_unreachable(
"ArgType must be valid");
314 argTy = ETy->getDecl()->getIntegerType();
317 switch (BT->getKind()) {
320 case BuiltinType::Char_S:
321 case BuiltinType::SChar:
322 case BuiltinType::UChar:
323 case BuiltinType::Char_U:
331 argTy = ETy->getDecl()->getIntegerType();
338 switch (BT->getKind()) {
341 case BuiltinType::Char_S:
342 case BuiltinType::SChar:
343 case BuiltinType::Char_U:
344 case BuiltinType::UChar:
347 case BuiltinType::Short:
349 case BuiltinType::UShort:
350 return T == C.
ShortTy ? Match : NoMatch;
351 case BuiltinType::Int:
353 case BuiltinType::UInt:
354 return T == C.
IntTy ? Match : NoMatch;
355 case BuiltinType::Long:
357 case BuiltinType::ULong:
358 return T == C.
LongTy ? Match : NoMatch;
359 case BuiltinType::LongLong:
361 case BuiltinType::ULongLong:
373 switch (BT->getKind()) {
374 case BuiltinType::Void:
375 case BuiltinType::Char_U:
376 case BuiltinType::UChar:
377 case BuiltinType::Char_S:
378 case BuiltinType::SChar:
411 return WInt == PromoArg ? Match : NoMatch;
419 return NoMatchPedantic;
424 case ObjCPointerTy: {
443 llvm_unreachable(
"Invalid ArgType Kind!");
450 llvm_unreachable(
"No representative type for Invalid ArgType");
452 llvm_unreachable(
"No representative type for Unknown ArgType");
482 std::string ArgType::getRepresentativeTypeName(
ASTContext &C)
const {
483 std::string
S = getRepresentativeType(C).getAsString();
491 Alias += (Alias[Alias.size()-1] ==
'*') ?
"*" :
" *";
499 return std::string(
"'") + Alias +
"' (aka '" + S +
"')";
500 return std::string(
"'") + S +
"'";
562 case dArg:
return "d";
563 case DArg:
return "D";
564 case iArg:
return "i";
565 case oArg:
return "o";
566 case OArg:
return "O";
567 case uArg:
return "u";
568 case UArg:
return "U";
569 case xArg:
return "x";
570 case XArg:
return "X";
571 case fArg:
return "f";
572 case FArg:
return "F";
573 case eArg:
return "e";
574 case EArg:
return "E";
575 case gArg:
return "g";
576 case GArg:
return "G";
577 case aArg:
return "a";
578 case AArg:
return "A";
579 case cArg:
return "c";
580 case sArg:
return "s";
581 case pArg:
return "p";
582 case nArg:
return "n";
588 case CArg:
return "C";
589 case SArg:
return "S";
604 case ZArg:
return "Z";
753 return !Target.
getTriple().isOSDarwin() &&
806 llvm_unreachable(
"Invalid LengthModifier Kind!");
830 llvm_unreachable(
"Invalid LengthModifier Kind!");
860 return LangOpt.ObjC1 || LangOpt.ObjC2;
873 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
908 assert(isa<TypedefType>(QT) &&
"Expected a TypedefType");
913 if (Identifier->
getName() ==
"size_t") {
916 }
else if (Identifier->
getName() ==
"ssize_t") {
920 }
else if (Identifier->
getName() ==
"intmax_t") {
923 }
else if (Identifier->
getName() ==
"uintmax_t") {
926 }
else if (Identifier->
getName() ==
"ptrdiff_t") {
932 if (!isa<TypedefType>(T))
935 Typedef = cast<TypedefType>(T)->getDecl();
QualType getPromotedIntegerType(QualType PromotableType) const
Return the type that PromotableType will promote to: C99 6.3.1.1p2, assuming that PromotableType is a...
bool isNullPtrType() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
CanQual< T > getUnqualifiedType() const
Retrieve the unqualified form of this type.
QualType getUnderlyingType() const
bool isVoidPointerType() const
bool isBlockPointerType() const
One of these records is kept for each identifier that is lexed.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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...
detail::InMemoryDirectory::const_iterator I
CanQualType UnsignedCharTy
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Exposes information about the current target.
Defines the clang::LangOptions interface.
StringRef getName() const
Return the actual identifier string.
QualType getWIntType() const
In C99, this returns a type compatible with the type defined in <stddef.h> as defined by the target...
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...
bool isPromotableIntegerType() const
More type predicates useful for type checking/promotion.
QualType getPointeeType() const
CanQualType UnsignedShortTy
Base class for declarations which introduce a typedef-name.
CanQualType ObjCBuiltinIdTy
CanQualType UnsignedLongLongTy
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
detail::InMemoryDirectory::const_iterator E
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getCorrespondingUnsignedType(QualType T) const
const RecordType * getAsStructureType() const
Represents a pointer to an Objective C object.
const T * getAs() const
Member-template getAs<specific type>'.
CanQualType UnsignedLongTy
bool isObjCObjectPointerType() const
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.
bool isConstQualified() const
Determine whether this type is const-qualified.
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.
CanQualType UnsignedIntTy
bool isPointerType() const