clang 20.0.0git
FormatString.h
Go to the documentation of this file.
1//= FormatString.h - Analysis of printf/fprintf format strings --*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines APIs for analyzing the format strings of printf, fscanf,
10// and friends.
11//
12// The structure of format strings for fprintf are described in C99 7.19.6.1.
13//
14// The structure of format strings for fscanf are described in C99 7.19.6.2.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_CLANG_AST_FORMATSTRING_H
19#define LLVM_CLANG_AST_FORMATSTRING_H
20
22#include <optional>
23
24namespace clang {
25
26class TargetInfo;
27
28//===----------------------------------------------------------------------===//
29/// Common components of both fprintf and fscanf format strings.
30namespace analyze_format_string {
31
32/// Class representing optional flags with location and representation
33/// information.
35public:
36 OptionalFlag(const char *Representation)
37 : representation(Representation), flag(false) {}
38 bool isSet() const { return flag; }
39 void set() { flag = true; }
40 void clear() { flag = false; }
41 void setPosition(const char *position) {
42 assert(position);
43 flag = true;
44 this->position = position;
45 }
46 const char *getPosition() const {
47 assert(position);
48 return position;
49 }
50 const char *toString() const { return representation; }
51
52 // Overloaded operators for bool like qualities
53 explicit operator bool() const { return flag; }
54 OptionalFlag& operator=(const bool &rhs) {
55 flag = rhs;
56 return *this; // Return a reference to myself.
57 }
58private:
59 const char *representation;
60 const char *position;
61 bool flag;
62};
63
64/// Represents the length modifier in a format string in scanf/printf.
66public:
67 enum Kind {
69 AsChar, // 'hh'
70 AsShort, // 'h'
71 AsShortLong, // 'hl' (OpenCL float/int vector element)
72 AsLong, // 'l'
73 AsLongLong, // 'll'
74 AsQuad, // 'q' (BSD, deprecated, for 64-bit integer types)
75 AsIntMax, // 'j'
76 AsSizeT, // 'z'
77 AsPtrDiff, // 't'
78 AsInt32, // 'I32' (MSVCRT, like __int32)
79 AsInt3264, // 'I' (MSVCRT, like __int3264 from MIDL)
80 AsInt64, // 'I64' (MSVCRT, like __int64)
82 AsAllocate, // for '%as', GNU extension to C90 scanf
83 AsMAllocate, // for '%ms', GNU extension to scanf
84 AsWide, // 'w' (MSVCRT, like l but only for c, C, s, S, or Z
85 AsWideChar = AsLong // for '%ls', only makes sense for printf
86 };
87
89 : Position(nullptr), kind(None) {}
90 LengthModifier(const char *pos, Kind k)
91 : Position(pos), kind(k) {}
92
93 const char *getStart() const {
94 return Position;
95 }
96
97 unsigned getLength() const {
98 switch (kind) {
99 default:
100 return 1;
101 case AsLongLong:
102 case AsChar:
103 return 2;
104 case AsInt32:
105 case AsInt64:
106 return 3;
107 case None:
108 return 0;
109 }
110 }
111
112 Kind getKind() const { return kind; }
113 void setKind(Kind k) { kind = k; }
114
115 const char *toString() const;
116
117private:
118 const char *Position;
119 Kind kind;
120};
121
123public:
124 enum Kind {
126 // C99 conversion specifiers.
129 DArg, // Apple extension
131 // C23 conversion specifiers.
134
137
139 OArg, // Apple extension
141 UArg, // Apple extension
146
157
164
165 // Apple extension: P specifies to os_log that the data being pointed to is
166 // to be copied by os_log. The precision indicates the number of bytes to
167 // copy.
169
170 // ** Printf-specific **
171
172 ZArg, // MS extension
173
174 // ISO/IEC TR 18037 (fixed-point) specific specifiers.
175 kArg, // %k for signed accum types
176 KArg, // %K for unsigned accum types
177 rArg, // %r for signed fract types
178 RArg, // %R for unsigned fract types
181
182 // Objective-C specific specifiers.
186
187 // FreeBSD kernel specific specifiers.
192
193 // GlibC specific specifiers.
195
198
199 // ** Scanf-specific **
203 };
204
205 ConversionSpecifier(bool isPrintf = true)
206 : IsPrintf(isPrintf), Position(nullptr), EndScanList(nullptr),
208
209 ConversionSpecifier(bool isPrintf, const char *pos, Kind k)
210 : IsPrintf(isPrintf), Position(pos), EndScanList(nullptr), kind(k) {}
211
212 const char *getStart() const {
213 return Position;
214 }
215
216 StringRef getCharacters() const {
217 return StringRef(getStart(), getLength());
218 }
219
220 bool consumesDataArgument() const {
221 switch (kind) {
222 case PrintErrno:
223 assert(IsPrintf);
224 return false;
225 case PercentArg:
226 return false;
227 case InvalidSpecifier:
228 return false;
229 default:
230 return true;
231 }
232 }
233
234 Kind getKind() const { return kind; }
235 void setKind(Kind k) { kind = k; }
236 unsigned getLength() const {
237 return EndScanList ? EndScanList - Position : 1;
238 }
239 void setEndScanList(const char *pos) { EndScanList = pos; }
240
241 bool isIntArg() const { return (kind >= IntArgBeg && kind <= IntArgEnd) ||
242 kind == FreeBSDrArg || kind == FreeBSDyArg; }
243 bool isUIntArg() const { return kind >= UIntArgBeg && kind <= UIntArgEnd; }
244 bool isAnyIntArg() const { return kind >= IntArgBeg && kind <= UIntArgEnd; }
245 bool isDoubleArg() const {
246 return kind >= DoubleArgBeg && kind <= DoubleArgEnd;
247 }
248 bool isFixedPointArg() const {
250 }
251
252 const char *toString() const;
253
254 bool isPrintfKind() const { return IsPrintf; }
255
256 std::optional<ConversionSpecifier> getStandardSpecifier() const;
257
258protected:
260 const char *Position;
261 const char *EndScanList;
263};
264
265class ArgType {
266public:
269
270 /// How well a given conversion specifier matches its argument.
272 /// The conversion specifier and the argument types are incompatible. For
273 /// instance, "%d" and float.
275 /// The conversion specifier and the argument type are compatible. For
276 /// instance, "%d" and int.
277 Match = 1,
278 /// The conversion specifier and the argument type are compatible because of
279 /// default argument promotions. For instance, "%hhd" and int.
281 /// The conversion specifier and the argument type are compatible but still
282 /// seems likely to be an error. For instanace, "%hhd" and short.
284 /// The conversion specifier and the argument type are disallowed by the C
285 /// standard, but are in practice harmless. For instance, "%p" and int*.
287 /// The conversion specifier and the argument type have different sign.
289 /// The conversion specifier and the argument type are compatible, but still
290 /// seems likely to be an error. For instance, "%hd" and _Bool.
292 };
293
294private:
295 const Kind K;
296 QualType T;
297 const char *Name = nullptr;
298 bool Ptr = false;
299
300 /// The TypeKind identifies certain well-known types like size_t and
301 /// ptrdiff_t.
302 enum class TypeKind { DontCare, SizeT, PtrdiffT };
303 TypeKind TK = TypeKind::DontCare;
304
305public:
306 ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
307 ArgType(QualType T, const char *N = nullptr) : K(SpecificTy), T(T), Name(N) {}
309
310 static ArgType Invalid() { return ArgType(InvalidTy); }
311 bool isValid() const { return K != InvalidTy; }
312
313 bool isSizeT() const { return TK == TypeKind::SizeT; }
314
315 bool isPtrdiffT() const { return TK == TypeKind::PtrdiffT; }
316
317 /// Create an ArgType which corresponds to the type pointer to A.
318 static ArgType PtrTo(const ArgType& A) {
319 assert(A.K >= InvalidTy && "ArgType cannot be pointer to invalid/unknown");
320 ArgType Res = A;
321 Res.Ptr = true;
322 return Res;
323 }
324
325 /// Create an ArgType which corresponds to the size_t/ssize_t type.
326 static ArgType makeSizeT(const ArgType &A) {
327 ArgType Res = A;
328 Res.TK = TypeKind::SizeT;
329 return Res;
330 }
331
332 /// Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t
333 /// type.
334 static ArgType makePtrdiffT(const ArgType &A) {
335 ArgType Res = A;
336 Res.TK = TypeKind::PtrdiffT;
337 return Res;
338 }
339
341
343
344 ArgType makeVectorType(ASTContext &C, unsigned NumElts) const;
345
346 std::string getRepresentativeTypeName(ASTContext &C) const;
347};
348
350public:
352
354 unsigned amount,
355 const char *amountStart,
356 unsigned amountLength,
358 : start(amountStart), length(amountLength), hs(howSpecified), amt(amount),
359 UsesPositionalArg(usesPositionalArg), UsesDotPrefix(false) {}
360
361 OptionalAmount(bool valid = true)
362 : start(nullptr),length(0), hs(valid ? NotSpecified : Invalid), amt(0),
363 UsesPositionalArg(false), UsesDotPrefix(false) {}
364
365 explicit OptionalAmount(unsigned Amount)
366 : start(nullptr), length(0), hs(Constant), amt(Amount),
367 UsesPositionalArg(false), UsesDotPrefix(false) {}
368
369 bool isInvalid() const {
370 return hs == Invalid;
371 }
372
373 HowSpecified getHowSpecified() const { return hs; }
374 void setHowSpecified(HowSpecified h) { hs = h; }
375
376 bool hasDataArgument() const { return hs == Arg; }
377
378 unsigned getArgIndex() const {
379 assert(hasDataArgument());
380 return amt;
381 }
382
383 unsigned getConstantAmount() const {
384 assert(hs == Constant);
385 return amt;
386 }
387
388 const char *getStart() const {
389 // We include the . character if it is given.
390 return start - UsesDotPrefix;
391 }
392
393 unsigned getConstantLength() const {
394 assert(hs == Constant);
395 return length + UsesDotPrefix;
396 }
397
398 ArgType getArgType(ASTContext &Ctx) const;
399
400 void toString(raw_ostream &os) const;
401
402 bool usesPositionalArg() const { return (bool) UsesPositionalArg; }
403 unsigned getPositionalArgIndex() const {
404 assert(hasDataArgument());
405 return amt + 1;
406 }
407
408 bool usesDotPrefix() const { return UsesDotPrefix; }
409 void setUsesDotPrefix() { UsesDotPrefix = true; }
410
411private:
412 const char *start;
413 unsigned length;
414 HowSpecified hs;
415 unsigned amt;
416 bool UsesPositionalArg : 1;
417 bool UsesDotPrefix;
418};
419
420
422protected:
427
428 /// Positional arguments, an IEEE extension:
429 /// IEEE Std 1003.1, 2004 Edition
430 /// http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
432 unsigned argIndex;
433public:
434 FormatSpecifier(bool isPrintf)
435 : CS(isPrintf), VectorNumElts(false),
437
439 LM = lm;
440 }
441
443
444 void setArgIndex(unsigned i) {
445 argIndex = i;
446 }
447
448 unsigned getArgIndex() const {
449 return argIndex;
450 }
451
452 unsigned getPositionalArgIndex() const {
453 return argIndex + 1;
454 }
455
457 return LM;
458 }
459
461 return FieldWidth;
462 }
463
465 VectorNumElts = Amt;
466 }
467
469 return VectorNumElts;
470 }
471
472 void setFieldWidth(const OptionalAmount &Amt) {
473 FieldWidth = Amt;
474 }
475
476 bool usesPositionalArg() const { return UsesPositionalArg; }
477
479 const LangOptions &LO) const;
480
481 bool hasStandardLengthModifier() const;
482
483 std::optional<LengthModifier> getCorrectedLengthModifier() const;
484
485 bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const;
486
488
489 /// For a TypedefType QT, if it is a named integer type such as size_t,
490 /// assign the appropriate value to LM and return true.
492};
493
494} // end analyze_format_string namespace
495
496//===----------------------------------------------------------------------===//
497/// Pieces specific to fprintf format strings.
498
499namespace analyze_printf {
500
503public:
506
507 PrintfConversionSpecifier(const char *pos, Kind k)
508 : ConversionSpecifier(true, pos, k) {}
509
510 bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; }
511 bool isDoubleArg() const { return kind >= DoubleArgBeg &&
512 kind <= DoubleArgEnd; }
513
515 return CS->isPrintfKind();
516 }
517};
518
523
525 OptionalFlag HasThousandsGrouping; // ''', POSIX extension.
526 OptionalFlag IsLeftJustified; // '-'
527 OptionalFlag HasPlusPrefix; // '+'
528 OptionalFlag HasSpacePrefix; // ' '
529 OptionalFlag HasAlternativeForm; // '#'
530 OptionalFlag HasLeadingZeroes; // '0'
531 OptionalFlag HasObjCTechnicalTerm; // '[tt]'
532 OptionalFlag IsPrivate; // '{private}'
533 OptionalFlag IsPublic; // '{public}'
534 OptionalFlag IsSensitive; // '{sensitive}'
535 OptionalAmount Precision;
536 StringRef MaskType;
537
538 ArgType getScalarArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
539
540public:
542 : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"),
543 IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "),
544 HasAlternativeForm("#"), HasLeadingZeroes("0"),
545 HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public"),
546 IsSensitive("sensitive") {}
547
548 static PrintfSpecifier Parse(const char *beg, const char *end);
549
550 // Methods for incrementally constructing the PrintfSpecifier.
552 CS = cs;
553 }
554 void setHasThousandsGrouping(const char *position) {
555 HasThousandsGrouping.setPosition(position);
556 }
557 void setIsLeftJustified(const char *position) {
558 IsLeftJustified.setPosition(position);
559 }
560 void setHasPlusPrefix(const char *position) {
561 HasPlusPrefix.setPosition(position);
562 }
563 void setHasSpacePrefix(const char *position) {
564 HasSpacePrefix.setPosition(position);
565 }
566 void setHasAlternativeForm(const char *position) {
567 HasAlternativeForm.setPosition(position);
568 }
569 void setHasLeadingZeros(const char *position) {
570 HasLeadingZeroes.setPosition(position);
571 }
572 void setHasObjCTechnicalTerm(const char *position) {
573 HasObjCTechnicalTerm.setPosition(position);
574 }
575 void setIsPrivate(const char *position) { IsPrivate.setPosition(position); }
576 void setIsPublic(const char *position) { IsPublic.setPosition(position); }
577 void setIsSensitive(const char *position) {
578 IsSensitive.setPosition(position);
579 }
581
582 // Methods for querying the format specifier.
583
585 return cast<PrintfConversionSpecifier>(CS);
586 }
587
588 void setPrecision(const OptionalAmount &Amt) {
589 Precision = Amt;
590 Precision.setUsesDotPrefix();
591 }
592
594 return Precision;
595 }
596
597 bool consumesDataArgument() const {
599 }
600
601 /// Returns the builtin type that a data argument
602 /// paired with this format specifier should have. This method
603 /// will return null if the format specifier does not have
604 /// a matching data argument or the matching argument matches
605 /// more than one type.
606 ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
607
609 return HasThousandsGrouping;
610 }
611 const OptionalFlag &isLeftJustified() const { return IsLeftJustified; }
612 const OptionalFlag &hasPlusPrefix() const { return HasPlusPrefix; }
613 const OptionalFlag &hasAlternativeForm() const { return HasAlternativeForm; }
614 const OptionalFlag &hasLeadingZeros() const { return HasLeadingZeroes; }
615 const OptionalFlag &hasSpacePrefix() const { return HasSpacePrefix; }
616 const OptionalFlag &hasObjCTechnicalTerm() const { return HasObjCTechnicalTerm; }
617 const OptionalFlag &isPrivate() const { return IsPrivate; }
618 const OptionalFlag &isPublic() const { return IsPublic; }
619 const OptionalFlag &isSensitive() const { return IsSensitive; }
620 bool usesPositionalArg() const { return UsesPositionalArg; }
621
622 StringRef getMaskType() const { return MaskType; }
623 void setMaskType(StringRef S) { MaskType = S; }
624
625 /// Changes the specifier and length according to a QualType, retaining any
626 /// flags or options. Returns true on success, or false when a conversion
627 /// was not successful.
628 bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx,
629 bool IsObjCLiteral);
630
631 void toString(raw_ostream &os) const;
632
633 // Validation methods - to check if any element results in undefined behavior
634 bool hasValidPlusPrefix() const;
635 bool hasValidAlternativeForm() const;
636 bool hasValidLeadingZeros() const;
637 bool hasValidSpacePrefix() const;
638 bool hasValidLeftJustified() const;
640
641 bool hasValidPrecision() const;
642 bool hasValidFieldWidth() const;
643};
644} // end analyze_printf namespace
645
646//===----------------------------------------------------------------------===//
647/// Pieces specific to fscanf format strings.
648
649namespace analyze_scanf {
650
653public:
656
657 ScanfConversionSpecifier(const char *pos, Kind k)
658 : ConversionSpecifier(false, pos, k) {}
659
661 return !CS->isPrintfKind();
662 }
663};
664
669
671 OptionalFlag SuppressAssignment; // '*'
672public:
674 FormatSpecifier(/* isPrintf = */ false),
675 SuppressAssignment("*") {}
676
677 void setSuppressAssignment(const char *position) {
678 SuppressAssignment.setPosition(position);
679 }
680
682 return SuppressAssignment;
683 }
684
686 CS = cs;
687 }
688
690 return cast<ScanfConversionSpecifier>(CS);
691 }
692
693 bool consumesDataArgument() const {
694 return CS.consumesDataArgument() && !SuppressAssignment;
695 }
696
697 ArgType getArgType(ASTContext &Ctx) const;
698
699 bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt,
700 ASTContext &Ctx);
701
702 void toString(raw_ostream &os) const;
703
704 static ScanfSpecifier Parse(const char *beg, const char *end);
705};
706
707} // end analyze_scanf namespace
708
709//===----------------------------------------------------------------------===//
710// Parsing and processing of format strings (both fprintf and fscanf).
711
712namespace analyze_format_string {
713
715
717public:
719 virtual ~FormatStringHandler();
720
721 virtual void HandleNullChar(const char *nullCharacter) {}
722
723 virtual void HandlePosition(const char *startPos, unsigned posLen) {}
724
725 virtual void HandleInvalidPosition(const char *startPos, unsigned posLen,
726 PositionContext p) {}
727
728 virtual void HandleZeroPosition(const char *startPos, unsigned posLen) {}
729
730 virtual void HandleIncompleteSpecifier(const char *startSpecifier,
731 unsigned specifierLen) {}
732
733 virtual void HandleEmptyObjCModifierFlag(const char *startFlags,
734 unsigned flagsLen) {}
735
736 virtual void HandleInvalidObjCModifierFlag(const char *startFlag,
737 unsigned flagLen) {}
738
739 virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart,
740 const char *flagsEnd,
741 const char *conversionPosition) {}
742 // Printf-specific handlers.
743
746 const char *startSpecifier,
747 unsigned specifierLen) {
748 return true;
749 }
750
752 const char *startSpecifier,
753 unsigned specifierLen,
754 const TargetInfo &Target) {
755 return true;
756 }
757
758 /// Handle mask types whose sizes are not between one and eight bytes.
759 virtual void handleInvalidMaskType(StringRef MaskType) {}
760
761 // Scanf-specific handlers.
762
765 const char *startSpecifier,
766 unsigned specifierLen) {
767 return true;
768 }
769
771 const char *startSpecifier,
772 unsigned specifierLen) {
773 return true;
774 }
775
776 virtual void HandleIncompleteScanList(const char *start, const char *end) {}
777};
778
779bool ParsePrintfString(FormatStringHandler &H,
780 const char *beg, const char *end, const LangOptions &LO,
781 const TargetInfo &Target, bool isFreeBSDKPrintf);
782
783bool ParseFormatStringHasSArg(const char *beg, const char *end,
784 const LangOptions &LO, const TargetInfo &Target);
785
786bool ParseScanfString(FormatStringHandler &H,
787 const char *beg, const char *end, const LangOptions &LO,
788 const TargetInfo &Target);
789
790/// Return true if the given string has at least one formatting specifier.
792 const char *End,
793 const LangOptions &LO,
794 const TargetInfo &Target);
795
796} // end analyze_format_string namespace
797} // end clang namespace
798#endif
llvm::MachO::Target Target
Definition: MachO.h:51
SourceLocation Begin
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:476
A (possibly-)qualified type.
Definition: Type.h:941
Exposes information about the current target.
Definition: TargetInfo.h:218
static ArgType makePtrdiffT(const ArgType &A)
Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t type.
Definition: FormatString.h:334
MatchKind
How well a given conversion specifier matches its argument.
Definition: FormatString.h:271
@ NoMatch
The conversion specifier and the argument types are incompatible.
Definition: FormatString.h:274
@ NoMatchPedantic
The conversion specifier and the argument type are disallowed by the C standard, but are in practice ...
Definition: FormatString.h:286
@ Match
The conversion specifier and the argument type are compatible.
Definition: FormatString.h:277
@ MatchPromotion
The conversion specifier and the argument type are compatible because of default argument promotions.
Definition: FormatString.h:280
@ NoMatchSignedness
The conversion specifier and the argument type have different sign.
Definition: FormatString.h:288
@ NoMatchTypeConfusion
The conversion specifier and the argument type are compatible, but still seems likely to be an error.
Definition: FormatString.h:291
@ NoMatchPromotionTypeConfusion
The conversion specifier and the argument type are compatible but still seems likely to be an error.
Definition: FormatString.h:283
static ArgType PtrTo(const ArgType &A)
Create an ArgType which corresponds to the type pointer to A.
Definition: FormatString.h:318
ArgType makeVectorType(ASTContext &C, unsigned NumElts) const
QualType getRepresentativeType(ASTContext &C) const
std::string getRepresentativeTypeName(ASTContext &C) const
ArgType(QualType T, const char *N=nullptr)
Definition: FormatString.h:307
static ArgType makeSizeT(const ArgType &A)
Create an ArgType which corresponds to the size_t/ssize_t type.
Definition: FormatString.h:326
ArgType(Kind K=UnknownTy, const char *N=nullptr)
Definition: FormatString.h:306
MatchKind matchesType(ASTContext &C, QualType argTy) const
std::optional< ConversionSpecifier > getStandardSpecifier() const
ConversionSpecifier(bool isPrintf, const char *pos, Kind k)
Definition: FormatString.h:209
void setFieldWidth(const OptionalAmount &Amt)
Definition: FormatString.h:472
const OptionalAmount & getFieldWidth() const
Definition: FormatString.h:460
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
const LengthModifier & getLengthModifier() const
Definition: FormatString.h:456
const OptionalAmount & getVectorNumElts() const
Definition: FormatString.h:468
static bool namedTypeToLengthModifier(QualType QT, LengthModifier &LM)
For a TypedefType QT, if it is a named integer type such as size_t, assign the appropriate value to L...
bool hasValidLengthModifier(const TargetInfo &Target, const LangOptions &LO) const
bool UsesPositionalArg
Positional arguments, an IEEE extension: IEEE Std 1003.1, 2004 Edition http://www....
Definition: FormatString.h:431
std::optional< LengthModifier > getCorrectedLengthModifier() const
void setVectorNumElts(const OptionalAmount &Amt)
Definition: FormatString.h:464
virtual bool HandleInvalidPrintfConversionSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:744
virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart, const char *flagsEnd, const char *conversionPosition)
Definition: FormatString.h:739
virtual void HandleInvalidObjCModifierFlag(const char *startFlag, unsigned flagLen)
Definition: FormatString.h:736
virtual void HandleIncompleteScanList(const char *start, const char *end)
Definition: FormatString.h:776
virtual void HandleNullChar(const char *nullCharacter)
Definition: FormatString.h:721
virtual void handleInvalidMaskType(StringRef MaskType)
Handle mask types whose sizes are not between one and eight bytes.
Definition: FormatString.h:759
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:723
virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen, const TargetInfo &Target)
Definition: FormatString.h:751
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:725
virtual void HandleEmptyObjCModifierFlag(const char *startFlags, unsigned flagsLen)
Definition: FormatString.h:733
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:728
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:730
virtual bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:770
virtual bool HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:763
Represents the length modifier in a format string in scanf/printf.
Definition: FormatString.h:65
ArgType getArgType(ASTContext &Ctx) const
OptionalAmount(HowSpecified howSpecified, unsigned amount, const char *amountStart, unsigned amountLength, bool usesPositionalArg)
Definition: FormatString.h:353
Class representing optional flags with location and representation information.
Definition: FormatString.h:34
OptionalFlag(const char *Representation)
Definition: FormatString.h:36
void setPosition(const char *position)
Definition: FormatString.h:41
OptionalFlag & operator=(const bool &rhs)
Definition: FormatString.h:54
PrintfConversionSpecifier(const char *pos, Kind k)
Definition: FormatString.h:507
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
Definition: FormatString.h:514
const OptionalFlag & isPrivate() const
Definition: FormatString.h:617
void setHasAlternativeForm(const char *position)
Definition: FormatString.h:566
void setIsSensitive(const char *position)
Definition: FormatString.h:577
void setHasSpacePrefix(const char *position)
Definition: FormatString.h:563
void setHasThousandsGrouping(const char *position)
Definition: FormatString.h:554
const OptionalAmount & getPrecision() const
Definition: FormatString.h:593
static PrintfSpecifier Parse(const char *beg, const char *end)
const OptionalFlag & hasSpacePrefix() const
Definition: FormatString.h:615
void setIsLeftJustified(const char *position)
Definition: FormatString.h:557
bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx, bool IsObjCLiteral)
Changes the specifier and length according to a QualType, retaining any flags or options.
const OptionalFlag & isSensitive() const
Definition: FormatString.h:619
const OptionalFlag & isLeftJustified() const
Definition: FormatString.h:611
const OptionalFlag & hasLeadingZeros() const
Definition: FormatString.h:614
const OptionalFlag & hasAlternativeForm() const
Definition: FormatString.h:613
void setHasPlusPrefix(const char *position)
Definition: FormatString.h:560
void setIsPrivate(const char *position)
Definition: FormatString.h:575
const PrintfConversionSpecifier & getConversionSpecifier() const
Definition: FormatString.h:584
void setHasLeadingZeros(const char *position)
Definition: FormatString.h:569
const OptionalFlag & hasPlusPrefix() const
Definition: FormatString.h:612
const OptionalFlag & hasThousandsGrouping() const
Definition: FormatString.h:608
ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const
Returns the builtin type that a data argument paired with this format specifier should have.
void setIsPublic(const char *position)
Definition: FormatString.h:576
const OptionalFlag & hasObjCTechnicalTerm() const
Definition: FormatString.h:616
void setPrecision(const OptionalAmount &Amt)
Definition: FormatString.h:588
void setHasObjCTechnicalTerm(const char *position)
Definition: FormatString.h:572
const OptionalFlag & isPublic() const
Definition: FormatString.h:618
void setConversionSpecifier(const PrintfConversionSpecifier &cs)
Definition: FormatString.h:551
ScanfConversionSpecifier(const char *pos, Kind k)
Definition: FormatString.h:657
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
Definition: FormatString.h:660
static ScanfSpecifier Parse(const char *beg, const char *end)
bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt, ASTContext &Ctx)
const OptionalFlag & getSuppressAssignment() const
Definition: FormatString.h:681
void toString(raw_ostream &os) const
void setConversionSpecifier(const ScanfConversionSpecifier &cs)
Definition: FormatString.h:685
const ScanfConversionSpecifier & getConversionSpecifier() const
Definition: FormatString.h:689
void setSuppressAssignment(const char *position)
Definition: FormatString.h:677
ArgType getArgType(ASTContext &Ctx) const
bool parseFormatStringHasFormattingSpecifiers(const char *Begin, const char *End, const LangOptions &LO, const TargetInfo &Target)
Return true if the given string has at least one formatting specifier.
bool ParsePrintfString(FormatStringHandler &H, const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target, bool isFreeBSDKPrintf)
bool ParseScanfString(FormatStringHandler &H, const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target)
bool ParseFormatStringHasSArg(const char *beg, const char *end, const LangOptions &LO, const TargetInfo &Target)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
#define bool
Definition: stdbool.h:24