cmCommandArgumentParserHelper.h 2.64 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3
#ifndef cmCommandArgumentParserHelper_h
4 5
#define cmCommandArgumentParserHelper_h

6
#include "cmConfigure.h" // IWYU pragma: keep
7

8 9
#include <string>
#include <vector>
10 11 12 13 14 15

class cmMakefile;

class cmCommandArgumentParserHelper
{
public:
16
  struct ParserType
17
  {
18
    const char* str;
19
  };
20 21 22 23

  cmCommandArgumentParserHelper();
  ~cmCommandArgumentParserHelper();

wahikihiki's avatar
wahikihiki committed
24 25 26 27
  cmCommandArgumentParserHelper(cmCommandArgumentParserHelper const&) = delete;
  cmCommandArgumentParserHelper& operator=(
    cmCommandArgumentParserHelper const&) = delete;

28 29 30
  int ParseString(const char* str, int verb);

  // For the lexer:
31
  void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
32
                          const char* str, int len = 0);
33
  bool HandleEscapeSymbol(cmCommandArgumentParserHelper::ParserType* pt,
34
                          char symbol);
35 36 37 38 39

  int LexInput(char* buf, int maxlen);
  void Error(const char* str);

  // For yacc
40
  const char* CombineUnions(const char* in1, const char* in2);
41

42 43 44
  const char* ExpandSpecialVariable(const char* key, const char* var);
  const char* ExpandVariable(const char* var);
  const char* ExpandVariableForAt(const char* var);
45 46 47 48
  void SetResult(const char* value);

  void SetMakefile(const cmMakefile* mf);

49
  std::string& GetResult() { return this->Result; }
50 51

  void SetLineFile(long line, const char* file);
52 53
  void SetEscapeQuotes(bool b) { this->EscapeQuotes = b; }
  void SetNoEscapeMode(bool b) { this->NoEscapeMode = b; }
54
  void SetReplaceAtSyntax(bool b) { this->ReplaceAtSyntax = b; }
55
  void SetRemoveEmpty(bool b) { this->RemoveEmpty = b; }
56 57

  const char* GetError() { return this->ErrorString.c_str(); }
58

59
private:
60 61
  std::string::size_type InputBufferPos;
  std::string InputBuffer;
62 63 64 65 66
  std::vector<char> OutputBuffer;

  void Print(const char* place, const char* str);
  void SafePrintMissing(const char* str, int line, int cnt);

67
  const char* AddString(const std::string& str);
68 69

  void CleanupParser();
70
  void SetError(std::string const& msg);
71

72 73 74
  std::vector<char*> Variables;
  const cmMakefile* Makefile;
  std::string Result;
75
  std::string ErrorString;
76
  const char* FileName;
77 78 79
  long FileLine;
  int CurrentLine;
  int Verbose;
80 81
  bool EscapeQuotes;
  bool NoEscapeMode;
82
  bool ReplaceAtSyntax;
83
  bool RemoveEmpty;
84 85
};

86 87 88 89 90 91
#define YYSTYPE cmCommandArgumentParserHelper::ParserType
#define YYSTYPE_IS_DECLARED
#define YY_EXTRA_TYPE cmCommandArgumentParserHelper*
#define YY_DECL                                                               \
  int cmCommandArgument_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)

92
#endif