diff options
author | Tim Northover <tnorthover@apple.com> | 2018-11-02 13:14:11 +0000 |
---|---|---|
committer | Tim Northover <tnorthover@apple.com> | 2018-11-02 13:14:11 +0000 |
commit | 314fbfa1c4c6665c54a220eefb10a6f23010a352 (patch) | |
tree | e7249debf2e3c4d030fd1be7460a7f72a30a1c19 /clang/lib/AST/FormatStringParsing.h | |
parent | c55d09a00e8067f27de2bb88c12a2bee64a2192a (diff) | |
download | bcm5719-llvm-314fbfa1c4c6665c54a220eefb10a6f23010a352.tar.gz bcm5719-llvm-314fbfa1c4c6665c54a220eefb10a6f23010a352.zip |
Reapply Logging: make os_log buffer size an integer constant expression.
The size of an os_log buffer is known at any stage of compilation, so making it
a constant expression means that the common idiom of declaring a buffer for it
won't result in a VLA. That allows the compiler to skip saving and restoring
the stack pointer around such buffers.
This also moves the OSLog and other FormatString helpers from
libclangAnalysis to libclangAST to avoid a circular dependency.
llvm-svn: 345971
Diffstat (limited to 'clang/lib/AST/FormatStringParsing.h')
-rw-r--r-- | clang/lib/AST/FormatStringParsing.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/clang/lib/AST/FormatStringParsing.h b/clang/lib/AST/FormatStringParsing.h new file mode 100644 index 00000000000..91fab155e4c --- /dev/null +++ b/clang/lib/AST/FormatStringParsing.h @@ -0,0 +1,79 @@ +#ifndef LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H +#define LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H + +#include "clang/AST/ASTContext.h" +#include "clang/AST/Type.h" +#include "clang/AST/FormatString.h" + +namespace clang { + +class LangOptions; + +template <typename T> +class UpdateOnReturn { + T &ValueToUpdate; + const T &ValueToCopy; +public: + UpdateOnReturn(T &valueToUpdate, const T &valueToCopy) + : ValueToUpdate(valueToUpdate), ValueToCopy(valueToCopy) {} + + ~UpdateOnReturn() { + ValueToUpdate = ValueToCopy; + } +}; + +namespace analyze_format_string { + +OptionalAmount ParseAmount(const char *&Beg, const char *E); +OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E, + unsigned &argIndex); + +OptionalAmount ParsePositionAmount(FormatStringHandler &H, + const char *Start, const char *&Beg, + const char *E, PositionContext p); + +bool ParseFieldWidth(FormatStringHandler &H, + FormatSpecifier &CS, + const char *Start, const char *&Beg, const char *E, + unsigned *argIndex); + +bool ParseArgPosition(FormatStringHandler &H, + FormatSpecifier &CS, const char *Start, + const char *&Beg, const char *E); + +/// Returns true if a LengthModifier was parsed and installed in the +/// FormatSpecifier& argument, and false otherwise. +bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E, + const LangOptions &LO, bool IsScanf = false); + +/// Returns true if the invalid specifier in \p SpecifierBegin is a UTF-8 +/// string; check that it won't go further than \p FmtStrEnd and write +/// up the total size in \p Len. +bool ParseUTF8InvalidSpecifier(const char *SpecifierBegin, + const char *FmtStrEnd, unsigned &Len); + +template <typename T> class SpecifierResult { + T FS; + const char *Start; + bool Stop; +public: + SpecifierResult(bool stop = false) + : Start(nullptr), Stop(stop) {} + SpecifierResult(const char *start, + const T &fs) + : FS(fs), Start(start), Stop(false) {} + + const char *getStart() const { return Start; } + bool shouldStop() const { return Stop; } + bool hasValue() const { return Start != nullptr; } + const T &getValue() const { + assert(hasValue()); + return FS; + } + const T &getValue() { return FS; } +}; + +} // end analyze_format_string namespace +} // end clang namespace + +#endif |