clang API Documentation

FormatStringParsing.h
Go to the documentation of this file.
00001 #ifndef LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H
00002 #define LLVM_CLANG_LIB_ANALYSIS_FORMATSTRINGPARSING_H
00003 
00004 #include "clang/AST/ASTContext.h"
00005 #include "clang/AST/Type.h"
00006 #include "clang/Analysis/Analyses/FormatString.h"
00007 #include "llvm/Support/raw_ostream.h"
00008 
00009 namespace clang {
00010 
00011 class LangOptions;
00012 
00013 template <typename T>
00014 class UpdateOnReturn {
00015   T &ValueToUpdate;
00016   const T &ValueToCopy;
00017 public:
00018   UpdateOnReturn(T &valueToUpdate, const T &valueToCopy)
00019     : ValueToUpdate(valueToUpdate), ValueToCopy(valueToCopy) {}
00020 
00021   ~UpdateOnReturn() {
00022     ValueToUpdate = ValueToCopy;
00023   }
00024 };
00025 
00026 namespace analyze_format_string {
00027   
00028 OptionalAmount ParseAmount(const char *&Beg, const char *E);
00029 OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E,
00030                                       unsigned &argIndex);
00031 
00032 OptionalAmount ParsePositionAmount(FormatStringHandler &H,
00033                                    const char *Start, const char *&Beg,
00034                                    const char *E, PositionContext p);
00035   
00036 bool ParseFieldWidth(FormatStringHandler &H,
00037                      FormatSpecifier &CS,
00038                      const char *Start, const char *&Beg, const char *E,
00039                      unsigned *argIndex);
00040     
00041 bool ParseArgPosition(FormatStringHandler &H,
00042                       FormatSpecifier &CS, const char *Start,
00043                       const char *&Beg, const char *E);
00044 
00045 /// Returns true if a LengthModifier was parsed and installed in the
00046 /// FormatSpecifier& argument, and false otherwise.
00047 bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E,
00048                          const LangOptions &LO, bool IsScanf = false);
00049   
00050 template <typename T> class SpecifierResult {
00051   T FS;
00052   const char *Start;
00053   bool Stop;
00054 public:
00055   SpecifierResult(bool stop = false)
00056   : Start(nullptr), Stop(stop) {}
00057   SpecifierResult(const char *start,
00058                   const T &fs)
00059   : FS(fs), Start(start), Stop(false) {}
00060   
00061   const char *getStart() const { return Start; }
00062   bool shouldStop() const { return Stop; }
00063   bool hasValue() const { return Start != nullptr; }
00064   const T &getValue() const {
00065     assert(hasValue());
00066     return FS;
00067   }
00068   const T &getValue() { return FS; }
00069 };
00070   
00071 } // end analyze_format_string namespace
00072 } // end clang namespace
00073 
00074 #endif