clang 19.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 are compatible, but still
288 /// seems likely to be an error. For instance, "%hd" and _Bool.
290 };
291
292private:
293 const Kind K;
294 QualType T;
295 const char *Name = nullptr;
296 bool Ptr = false;
297
298 /// The TypeKind identifies certain well-known types like size_t and
299 /// ptrdiff_t.
300 enum class TypeKind { DontCare, SizeT, PtrdiffT };
301 TypeKind TK = TypeKind::DontCare;
302
303public:
304 ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
305 ArgType(QualType T, const char *N = nullptr) : K(SpecificTy), T(T), Name(N) {}
307
308 static ArgType Invalid() { return ArgType(InvalidTy); }
309 bool isValid() const { return K != InvalidTy; }
310
311 bool isSizeT() const { return TK == TypeKind::SizeT; }
312
313 bool isPtrdiffT() const { return TK == TypeKind::PtrdiffT; }
314
315 /// Create an ArgType which corresponds to the type pointer to A.
316 static ArgType PtrTo(const ArgType& A) {
317 assert(A.K >= InvalidTy && "ArgType cannot be pointer to invalid/unknown");
318 ArgType Res = A;
319 Res.Ptr = true;
320 return Res;
321 }
322
323 /// Create an ArgType which corresponds to the size_t/ssize_t type.
324 static ArgType makeSizeT(const ArgType &A) {
325 ArgType Res = A;
326 Res.TK = TypeKind::SizeT;
327 return Res;
328 }
329
330 /// Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t
331 /// type.
332 static ArgType makePtrdiffT(const ArgType &A) {
333 ArgType Res = A;
334 Res.TK = TypeKind::PtrdiffT;
335 return Res;
336 }
337
339
341
342 ArgType makeVectorType(ASTContext &C, unsigned NumElts) const;
343
344 std::string getRepresentativeTypeName(ASTContext &C) const;
345};
346
348public:
350
352 unsigned amount,
353 const char *amountStart,
354 unsigned amountLength,
356 : start(amountStart), length(amountLength), hs(howSpecified), amt(amount),
357 UsesPositionalArg(usesPositionalArg), UsesDotPrefix(false) {}
358
359 OptionalAmount(bool valid = true)
360 : start(nullptr),length(0), hs(valid ? NotSpecified : Invalid), amt(0),
361 UsesPositionalArg(false), UsesDotPrefix(false) {}
362
363 explicit OptionalAmount(unsigned Amount)
364 : start(nullptr), length(0), hs(Constant), amt(Amount),
365 UsesPositionalArg(false), UsesDotPrefix(false) {}
366
367 bool isInvalid() const {
368 return hs == Invalid;
369 }
370
371 HowSpecified getHowSpecified() const { return hs; }
372 void setHowSpecified(HowSpecified h) { hs = h; }
373
374 bool hasDataArgument() const { return hs == Arg; }
375
376 unsigned getArgIndex() const {
377 assert(hasDataArgument());
378 return amt;
379 }
380
381 unsigned getConstantAmount() const {
382 assert(hs == Constant);
383 return amt;
384 }
385
386 const char *getStart() const {
387 // We include the . character if it is given.
388 return start - UsesDotPrefix;
389 }
390
391 unsigned getConstantLength() const {
392 assert(hs == Constant);
393 return length + UsesDotPrefix;
394 }
395
396 ArgType getArgType(ASTContext &Ctx) const;
397
398 void toString(raw_ostream &os) const;
399
400 bool usesPositionalArg() const { return (bool) UsesPositionalArg; }
401 unsigned getPositionalArgIndex() const {
402 assert(hasDataArgument());
403 return amt + 1;
404 }
405
406 bool usesDotPrefix() const { return UsesDotPrefix; }
407 void setUsesDotPrefix() { UsesDotPrefix = true; }
408
409private:
410 const char *start;
411 unsigned length;
412 HowSpecified hs;
413 unsigned amt;
414 bool UsesPositionalArg : 1;
415 bool UsesDotPrefix;
416};
417
418
420protected:
425
426 /// Positional arguments, an IEEE extension:
427 /// IEEE Std 1003.1, 2004 Edition
428 /// http://www.opengroup.org/onlinepubs/009695399/functions/printf.html
430 unsigned argIndex;
431public:
432 FormatSpecifier(bool isPrintf)
433 : CS(isPrintf), VectorNumElts(false),
435
437 LM = lm;
438 }
439
441
442 void setArgIndex(unsigned i) {
443 argIndex = i;
444 }
445
446 unsigned getArgIndex() const {
447 return argIndex;
448 }
449
450 unsigned getPositionalArgIndex() const {
451 return argIndex + 1;
452 }
453
455 return LM;
456 }
457
459 return FieldWidth;
460 }
461
463 VectorNumElts = Amt;
464 }
465
467 return VectorNumElts;
468 }
469
470 void setFieldWidth(const OptionalAmount &Amt) {
471 FieldWidth = Amt;
472 }
473
474 bool usesPositionalArg() const { return UsesPositionalArg; }
475
477 const LangOptions &LO) const;
478
479 bool hasStandardLengthModifier() const;
480
481 std::optional<LengthModifier> getCorrectedLengthModifier() const;
482
483 bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const;
484
486
487 /// For a TypedefType QT, if it is a named integer type such as size_t,
488 /// assign the appropriate value to LM and return true.
490};
491
492} // end analyze_format_string namespace
493
494//===----------------------------------------------------------------------===//
495/// Pieces specific to fprintf format strings.
496
497namespace analyze_printf {
498
501public:
504
505 PrintfConversionSpecifier(const char *pos, Kind k)
506 : ConversionSpecifier(true, pos, k) {}
507
508 bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; }
509 bool isDoubleArg() const { return kind >= DoubleArgBeg &&
510 kind <= DoubleArgEnd; }
511
513 return CS->isPrintfKind();
514 }
515};
516
521
523 OptionalFlag HasThousandsGrouping; // ''', POSIX extension.
524 OptionalFlag IsLeftJustified; // '-'
525 OptionalFlag HasPlusPrefix; // '+'
526 OptionalFlag HasSpacePrefix; // ' '
527 OptionalFlag HasAlternativeForm; // '#'
528 OptionalFlag HasLeadingZeroes; // '0'
529 OptionalFlag HasObjCTechnicalTerm; // '[tt]'
530 OptionalFlag IsPrivate; // '{private}'
531 OptionalFlag IsPublic; // '{public}'
532 OptionalFlag IsSensitive; // '{sensitive}'
533 OptionalAmount Precision;
534 StringRef MaskType;
535
536 ArgType getScalarArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
537
538public:
540 : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"),
541 IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "),
542 HasAlternativeForm("#"), HasLeadingZeroes("0"),
543 HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public"),
544 IsSensitive("sensitive") {}
545
546 static PrintfSpecifier Parse(const char *beg, const char *end);
547
548 // Methods for incrementally constructing the PrintfSpecifier.
550 CS = cs;
551 }
552 void setHasThousandsGrouping(const char *position) {
553 HasThousandsGrouping.setPosition(position);
554 }
555 void setIsLeftJustified(const char *position) {
556 IsLeftJustified.setPosition(position);
557 }
558 void setHasPlusPrefix(const char *position) {
559 HasPlusPrefix.setPosition(position);
560 }
561 void setHasSpacePrefix(const char *position) {
562 HasSpacePrefix.setPosition(position);
563 }
564 void setHasAlternativeForm(const char *position) {
565 HasAlternativeForm.setPosition(position);
566 }
567 void setHasLeadingZeros(const char *position) {
568 HasLeadingZeroes.setPosition(position);
569 }
570 void setHasObjCTechnicalTerm(const char *position) {
571 HasObjCTechnicalTerm.setPosition(position);
572 }
573 void setIsPrivate(const char *position) { IsPrivate.setPosition(position); }
574 void setIsPublic(const char *position) { IsPublic.setPosition(position); }
575 void setIsSensitive(const char *position) {
576 IsSensitive.setPosition(position);
577 }
579
580 // Methods for querying the format specifier.
581
583 return cast<PrintfConversionSpecifier>(CS);
584 }
585
586 void setPrecision(const OptionalAmount &Amt) {
587 Precision = Amt;
588 Precision.setUsesDotPrefix();
589 }
590
592 return Precision;
593 }
594
595 bool consumesDataArgument() const {
597 }
598
599 /// Returns the builtin type that a data argument
600 /// paired with this format specifier should have. This method
601 /// will return null if the format specifier does not have
602 /// a matching data argument or the matching argument matches
603 /// more than one type.
604 ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const;
605
607 return HasThousandsGrouping;
608 }
609 const OptionalFlag &isLeftJustified() const { return IsLeftJustified; }
610 const OptionalFlag &hasPlusPrefix() const { return HasPlusPrefix; }
611 const OptionalFlag &hasAlternativeForm() const { return HasAlternativeForm; }
612 const OptionalFlag &hasLeadingZeros() const { return HasLeadingZeroes; }
613 const OptionalFlag &hasSpacePrefix() const { return HasSpacePrefix; }
614 const OptionalFlag &hasObjCTechnicalTerm() const { return HasObjCTechnicalTerm; }
615 const OptionalFlag &isPrivate() const { return IsPrivate; }
616 const OptionalFlag &isPublic() const { return IsPublic; }
617 const OptionalFlag &isSensitive() const { return IsSensitive; }
618 bool usesPositionalArg() const { return UsesPositionalArg; }
619
620 StringRef getMaskType() const { return MaskType; }
621 void setMaskType(StringRef S) { MaskType = S; }
622
623 /// Changes the specifier and length according to a QualType, retaining any
624 /// flags or options. Returns true on success, or false when a conversion
625 /// was not successful.
626 bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx,
627 bool IsObjCLiteral);
628
629 void toString(raw_ostream &os) const;
630
631 // Validation methods - to check if any element results in undefined behavior
632 bool hasValidPlusPrefix() const;
633 bool hasValidAlternativeForm() const;
634 bool hasValidLeadingZeros() const;
635 bool hasValidSpacePrefix() const;
636 bool hasValidLeftJustified() const;
638
639 bool hasValidPrecision() const;
640 bool hasValidFieldWidth() const;
641};
642} // end analyze_printf namespace
643
644//===----------------------------------------------------------------------===//
645/// Pieces specific to fscanf format strings.
646
647namespace analyze_scanf {
648
651public:
654
655 ScanfConversionSpecifier(const char *pos, Kind k)
656 : ConversionSpecifier(false, pos, k) {}
657
659 return !CS->isPrintfKind();
660 }
661};
662
667
669 OptionalFlag SuppressAssignment; // '*'
670public:
672 FormatSpecifier(/* isPrintf = */ false),
673 SuppressAssignment("*") {}
674
675 void setSuppressAssignment(const char *position) {
676 SuppressAssignment.setPosition(position);
677 }
678
680 return SuppressAssignment;
681 }
682
684 CS = cs;
685 }
686
688 return cast<ScanfConversionSpecifier>(CS);
689 }
690
691 bool consumesDataArgument() const {
692 return CS.consumesDataArgument() && !SuppressAssignment;
693 }
694
695 ArgType getArgType(ASTContext &Ctx) const;
696
697 bool fixType(QualType QT, QualType RawQT, const LangOptions &LangOpt,
698 ASTContext &Ctx);
699
700 void toString(raw_ostream &os) const;
701
702 static ScanfSpecifier Parse(const char *beg, const char *end);
703};
704
705} // end analyze_scanf namespace
706
707//===----------------------------------------------------------------------===//
708// Parsing and processing of format strings (both fprintf and fscanf).
709
710namespace analyze_format_string {
711
713
715public:
717 virtual ~FormatStringHandler();
718
719 virtual void HandleNullChar(const char *nullCharacter) {}
720
721 virtual void HandlePosition(const char *startPos, unsigned posLen) {}
722
723 virtual void HandleInvalidPosition(const char *startPos, unsigned posLen,
724 PositionContext p) {}
725
726 virtual void HandleZeroPosition(const char *startPos, unsigned posLen) {}
727
728 virtual void HandleIncompleteSpecifier(const char *startSpecifier,
729 unsigned specifierLen) {}
730
731 virtual void HandleEmptyObjCModifierFlag(const char *startFlags,
732 unsigned flagsLen) {}
733
734 virtual void HandleInvalidObjCModifierFlag(const char *startFlag,
735 unsigned flagLen) {}
736
737 virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart,
738 const char *flagsEnd,
739 const char *conversionPosition) {}
740 // Printf-specific handlers.
741
744 const char *startSpecifier,
745 unsigned specifierLen) {
746 return true;
747 }
748
750 const char *startSpecifier,
751 unsigned specifierLen,
752 const TargetInfo &Target) {
753 return true;
754 }
755
756 /// Handle mask types whose sizes are not between one and eight bytes.
757 virtual void handleInvalidMaskType(StringRef MaskType) {}
758
759 // Scanf-specific handlers.
760
763 const char *startSpecifier,
764 unsigned specifierLen) {
765 return true;
766 }
767
769 const char *startSpecifier,
770 unsigned specifierLen) {
771 return true;
772 }
773
774 virtual void HandleIncompleteScanList(const char *start, const char *end) {}
775};
776
777bool ParsePrintfString(FormatStringHandler &H,
778 const char *beg, const char *end, const LangOptions &LO,
779 const TargetInfo &Target, bool isFreeBSDKPrintf);
780
781bool ParseFormatStringHasSArg(const char *beg, const char *end,
782 const LangOptions &LO, const TargetInfo &Target);
783
784bool ParseScanfString(FormatStringHandler &H,
785 const char *beg, const char *end, const LangOptions &LO,
786 const TargetInfo &Target);
787
788/// Return true if the given string has at least one formatting specifier.
790 const char *End,
791 const LangOptions &LO,
792 const TargetInfo &Target);
793
794} // end analyze_format_string namespace
795} // end clang namespace
796#endif
llvm::MachO::Target Target
Definition: MachO.h:44
SourceLocation Begin
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:449
A (possibly-)qualified type.
Definition: Type.h:738
Exposes information about the current target.
Definition: TargetInfo.h:213
static ArgType makePtrdiffT(const ArgType &A)
Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t type.
Definition: FormatString.h:332
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
@ NoMatchTypeConfusion
The conversion specifier and the argument type are compatible, but still seems likely to be an error.
Definition: FormatString.h:289
@ 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:316
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:305
static ArgType makeSizeT(const ArgType &A)
Create an ArgType which corresponds to the size_t/ssize_t type.
Definition: FormatString.h:324
ArgType(Kind K=UnknownTy, const char *N=nullptr)
Definition: FormatString.h:304
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:470
const OptionalAmount & getFieldWidth() const
Definition: FormatString.h:458
bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const
const LengthModifier & getLengthModifier() const
Definition: FormatString.h:454
const OptionalAmount & getVectorNumElts() const
Definition: FormatString.h:466
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:429
std::optional< LengthModifier > getCorrectedLengthModifier() const
void setVectorNumElts(const OptionalAmount &Amt)
Definition: FormatString.h:462
virtual bool HandleInvalidPrintfConversionSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:742
virtual void HandleObjCFlagsWithNonObjCConversion(const char *flagsStart, const char *flagsEnd, const char *conversionPosition)
Definition: FormatString.h:737
virtual void HandleInvalidObjCModifierFlag(const char *startFlag, unsigned flagLen)
Definition: FormatString.h:734
virtual void HandleIncompleteScanList(const char *start, const char *end)
Definition: FormatString.h:774
virtual void HandleNullChar(const char *nullCharacter)
Definition: FormatString.h:719
virtual void handleInvalidMaskType(StringRef MaskType)
Handle mask types whose sizes are not between one and eight bytes.
Definition: FormatString.h:757
virtual void HandlePosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:721
virtual bool HandlePrintfSpecifier(const analyze_printf::PrintfSpecifier &FS, const char *startSpecifier, unsigned specifierLen, const TargetInfo &Target)
Definition: FormatString.h:749
virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, PositionContext p)
Definition: FormatString.h:723
virtual void HandleEmptyObjCModifierFlag(const char *startFlags, unsigned flagsLen)
Definition: FormatString.h:731
virtual void HandleZeroPosition(const char *startPos, unsigned posLen)
Definition: FormatString.h:726
virtual void HandleIncompleteSpecifier(const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:728
virtual bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:768
virtual bool HandleInvalidScanfConversionSpecifier(const analyze_scanf::ScanfSpecifier &FS, const char *startSpecifier, unsigned specifierLen)
Definition: FormatString.h:761
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:351
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:505
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
Definition: FormatString.h:512
const OptionalFlag & isPrivate() const
Definition: FormatString.h:615
void setHasAlternativeForm(const char *position)
Definition: FormatString.h:564
void setIsSensitive(const char *position)
Definition: FormatString.h:575
void setHasSpacePrefix(const char *position)
Definition: FormatString.h:561
void setHasThousandsGrouping(const char *position)
Definition: FormatString.h:552
const OptionalAmount & getPrecision() const
Definition: FormatString.h:591
static PrintfSpecifier Parse(const char *beg, const char *end)
const OptionalFlag & hasSpacePrefix() const
Definition: FormatString.h:613
void setIsLeftJustified(const char *position)
Definition: FormatString.h:555
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:617
const OptionalFlag & isLeftJustified() const
Definition: FormatString.h:609
const OptionalFlag & hasLeadingZeros() const
Definition: FormatString.h:612
const OptionalFlag & hasAlternativeForm() const
Definition: FormatString.h:611
void setHasPlusPrefix(const char *position)
Definition: FormatString.h:558
void setIsPrivate(const char *position)
Definition: FormatString.h:573
const PrintfConversionSpecifier & getConversionSpecifier() const
Definition: FormatString.h:582
void setHasLeadingZeros(const char *position)
Definition: FormatString.h:567
const OptionalFlag & hasPlusPrefix() const
Definition: FormatString.h:610
const OptionalFlag & hasThousandsGrouping() const
Definition: FormatString.h:606
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:574
const OptionalFlag & hasObjCTechnicalTerm() const
Definition: FormatString.h:614
void setPrecision(const OptionalAmount &Amt)
Definition: FormatString.h:586
void setHasObjCTechnicalTerm(const char *position)
Definition: FormatString.h:570
const OptionalFlag & isPublic() const
Definition: FormatString.h:616
void setConversionSpecifier(const PrintfConversionSpecifier &cs)
Definition: FormatString.h:549
ScanfConversionSpecifier(const char *pos, Kind k)
Definition: FormatString.h:655
static bool classof(const analyze_format_string::ConversionSpecifier *CS)
Definition: FormatString.h:658
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:679
void toString(raw_ostream &os) const
void setConversionSpecifier(const ScanfConversionSpecifier &cs)
Definition: FormatString.h:683
const ScanfConversionSpecifier & getConversionSpecifier() const
Definition: FormatString.h:687
void setSuppressAssignment(const char *position)
Definition: FormatString.h:675
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.
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
#define bool
Definition: stdbool.h:20