Home | History | Annotate | Download | only in Analysis
      1 #ifndef LLVM_CLANG_FORMAT_PARSING_H
      2 #define LLVM_CLANG_FORMAT_PARSING_H
      3 
      4 #include "clang/Analysis/Analyses/FormatString.h"
      5 #include "clang/AST/ASTContext.h"
      6 #include "clang/AST/Type.h"
      7 #include "llvm/Support/raw_ostream.h"
      8 
      9 namespace clang {
     10 
     11 template <typename T>
     12 class UpdateOnReturn {
     13   T &ValueToUpdate;
     14   const T &ValueToCopy;
     15 public:
     16   UpdateOnReturn(T &valueToUpdate, const T &valueToCopy)
     17     : ValueToUpdate(valueToUpdate), ValueToCopy(valueToCopy) {}
     18 
     19   ~UpdateOnReturn() {
     20     ValueToUpdate = ValueToCopy;
     21   }
     22 };
     23 
     24 namespace analyze_format_string {
     25 
     26 OptionalAmount ParseAmount(const char *&Beg, const char *E);
     27 OptionalAmount ParseNonPositionAmount(const char *&Beg, const char *E,
     28                                       unsigned &argIndex);
     29 
     30 OptionalAmount ParsePositionAmount(FormatStringHandler &H,
     31                                    const char *Start, const char *&Beg,
     32                                    const char *E, PositionContext p);
     33 
     34 bool ParseFieldWidth(FormatStringHandler &H,
     35                      FormatSpecifier &CS,
     36                      const char *Start, const char *&Beg, const char *E,
     37                      unsigned *argIndex);
     38 
     39 bool ParseArgPosition(FormatStringHandler &H,
     40                       FormatSpecifier &CS, const char *Start,
     41                       const char *&Beg, const char *E);
     42 
     43 /// Returns true if a LengthModifier was parsed and installed in the
     44 /// FormatSpecifier& argument, and false otherwise.
     45 bool ParseLengthModifier(FormatSpecifier &FS, const char *&Beg, const char *E);
     46 
     47 template <typename T> class SpecifierResult {
     48   T FS;
     49   const char *Start;
     50   bool Stop;
     51 public:
     52   SpecifierResult(bool stop = false)
     53   : Start(0), Stop(stop) {}
     54   SpecifierResult(const char *start,
     55                   const T &fs)
     56   : FS(fs), Start(start), Stop(false) {}
     57 
     58   const char *getStart() const { return Start; }
     59   bool shouldStop() const { return Stop; }
     60   bool hasValue() const { return Start != 0; }
     61   const T &getValue() const {
     62     assert(hasValue());
     63     return FS;
     64   }
     65   const T &getValue() { return FS; }
     66 };
     67 
     68 } // end analyze_format_string namespace
     69 } // end clang namespace
     70 
     71 #endif
     72 
     73