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 llvm::UTF8 *SB =
270 reinterpret_cast<const llvm::UTF8 *
>(SpecifierBegin + 1);
271 const llvm::UTF8 *SE =
reinterpret_cast<const llvm::UTF8 *
>(FmtStrEnd);
272 const char FirstByte = *SB;
277 unsigned NumBytes = llvm::getNumBytesForUTF8(FirstByte);
280 if (SB + NumBytes > SE)
308 llvm_unreachable(
"ArgType must be valid");
317 if (!ETy->getDecl()->isComplete())
319 argTy = ETy->getDecl()->getIntegerType();
323 switch (BT->getKind()) {
326 case BuiltinType::Char_S:
327 case BuiltinType::SChar:
328 case BuiltinType::UChar:
329 case BuiltinType::Char_U:
339 if (!ETy->getDecl()->isComplete())
342 argTy = ETy->getDecl()->getIntegerType();
350 switch (BT->getKind()) {
353 case BuiltinType::Char_S:
354 case BuiltinType::SChar:
355 case BuiltinType::Char_U:
356 case BuiltinType::UChar:
359 case BuiltinType::Short:
361 case BuiltinType::UShort:
362 return T == C.
ShortTy ? Match : NoMatch;
363 case BuiltinType::Int:
365 case BuiltinType::UInt:
366 return T == C.
IntTy ? Match : NoMatch;
367 case BuiltinType::Long:
369 case BuiltinType::ULong:
370 return T == C.
LongTy ? Match : NoMatch;
371 case BuiltinType::LongLong:
373 case BuiltinType::ULongLong:
385 switch (BT->getKind()) {
386 case BuiltinType::Void:
387 case BuiltinType::Char_U:
388 case BuiltinType::UChar:
389 case BuiltinType::Char_S:
390 case BuiltinType::SChar:
423 return WInt == PromoArg ? Match : NoMatch;
431 return NoMatchPedantic;
436 case ObjCPointerTy: {
455 llvm_unreachable(
"Invalid ArgType Kind!");
462 llvm_unreachable(
"No representative type for Invalid ArgType");
464 llvm_unreachable(
"No representative type for Unknown ArgType");
494 std::string ArgType::getRepresentativeTypeName(
ASTContext &C)
const {
495 std::string S = getRepresentativeType(C).getAsString();
503 Alias += (Alias[Alias.size()-1] ==
'*') ?
"*" :
" *";
511 return std::string(
"'") + Alias +
"' (aka '" + S +
"')";
512 return std::string(
"'") + S +
"'";
574 case dArg:
return "d";
575 case DArg:
return "D";
576 case iArg:
return "i";
577 case oArg:
return "o";
578 case OArg:
return "O";
579 case uArg:
return "u";
580 case UArg:
return "U";
581 case xArg:
return "x";
582 case XArg:
return "X";
583 case fArg:
return "f";
584 case FArg:
return "F";
585 case eArg:
return "e";
586 case EArg:
return "E";
587 case gArg:
return "g";
588 case GArg:
return "G";
589 case aArg:
return "a";
590 case AArg:
return "A";
591 case cArg:
return "c";
592 case sArg:
return "s";
593 case pArg:
return "p";
596 case nArg:
return "n";
597 case PercentArg:
return "%";
598 case ScanListArg:
return "[";
599 case InvalidSpecifier:
return nullptr;
602 case CArg:
return "C";
603 case SArg:
return "S";
606 case ObjCObjArg:
return "@";
609 case FreeBSDbArg:
return "b";
610 case FreeBSDDArg:
return "D";
611 case FreeBSDrArg:
return "r";
612 case FreeBSDyArg:
return "y";
615 case PrintErrno:
return "m";
618 case ZArg:
return "Z";
672 switch (LM.getKind()) {
679 switch (CS.getKind()) {
697 switch (CS.getKind()) {
718 switch (CS.getKind()) {
750 switch (CS.getKind()) {
767 return !Target.
getTriple().isOSDarwin() &&
774 switch (CS.getKind()) {
784 switch (CS.getKind()) {
797 switch (CS.getKind()) {
809 switch (CS.getKind()) {
820 llvm_unreachable(
"Invalid LengthModifier Kind!");
824 switch (LM.getKind()) {
844 llvm_unreachable(
"Invalid LengthModifier Kind!");
849 switch (CS.getKind()) {
875 return LangOpt.ObjC1 || LangOpt.ObjC2;
888 llvm_unreachable(
"Invalid ConversionSpecifier Kind!");
893 switch(CS.getKind()) {
923 assert(isa<TypedefType>(QT) &&
"Expected a TypedefType");
928 if (Identifier->
getName() ==
"size_t") {
931 }
else if (Identifier->
getName() ==
"ssize_t") {
935 }
else if (Identifier->
getName() ==
"intmax_t") {
938 }
else if (Identifier->
getName() ==
"uintmax_t") {
941 }
else if (Identifier->
getName() ==
"ptrdiff_t") {
947 if (!isa<TypedefType>(T))
950 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 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