cmCommandArgumentParserHelper.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCommandArgumentParserHelper_h
  4. #define cmCommandArgumentParserHelper_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. class cmMakefile;
  10. class cmCommandArgumentParserHelper
  11. {
  12. public:
  13. struct ParserType
  14. {
  15. const char* str;
  16. };
  17. cmCommandArgumentParserHelper();
  18. ~cmCommandArgumentParserHelper();
  19. cmCommandArgumentParserHelper(cmCommandArgumentParserHelper const&) = delete;
  20. cmCommandArgumentParserHelper& operator=(
  21. cmCommandArgumentParserHelper const&) = delete;
  22. int ParseString(const char* str, int verb);
  23. // For the lexer:
  24. void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
  25. const char* str, int len = 0);
  26. bool HandleEscapeSymbol(cmCommandArgumentParserHelper::ParserType* pt,
  27. char symbol);
  28. int LexInput(char* buf, int maxlen);
  29. void Error(const char* str);
  30. // For yacc
  31. const char* CombineUnions(const char* in1, const char* in2);
  32. const char* ExpandSpecialVariable(const char* key, const char* var);
  33. const char* ExpandVariable(const char* var);
  34. const char* ExpandVariableForAt(const char* var);
  35. void SetResult(const char* value);
  36. void SetMakefile(const cmMakefile* mf);
  37. std::string& GetResult() { return this->Result; }
  38. void SetLineFile(long line, const char* file);
  39. void SetEscapeQuotes(bool b) { this->EscapeQuotes = b; }
  40. void SetNoEscapeMode(bool b) { this->NoEscapeMode = b; }
  41. void SetReplaceAtSyntax(bool b) { this->ReplaceAtSyntax = b; }
  42. void SetRemoveEmpty(bool b) { this->RemoveEmpty = b; }
  43. const char* GetError() { return this->ErrorString.c_str(); }
  44. private:
  45. std::string::size_type InputBufferPos;
  46. std::string InputBuffer;
  47. std::vector<char> OutputBuffer;
  48. void Print(const char* place, const char* str);
  49. void SafePrintMissing(const char* str, int line, int cnt);
  50. const char* AddString(const std::string& str);
  51. void CleanupParser();
  52. void SetError(std::string const& msg);
  53. std::vector<std::unique_ptr<char[]>> Variables;
  54. const cmMakefile* Makefile;
  55. std::string Result;
  56. std::string ErrorString;
  57. const char* FileName;
  58. long FileLine;
  59. int CurrentLine;
  60. int Verbose;
  61. bool EscapeQuotes;
  62. bool NoEscapeMode;
  63. bool ReplaceAtSyntax;
  64. bool RemoveEmpty;
  65. };
  66. #define YYSTYPE cmCommandArgumentParserHelper::ParserType
  67. #define YYSTYPE_IS_DECLARED
  68. #define YY_EXTRA_TYPE cmCommandArgumentParserHelper*
  69. #define YY_DECL \
  70. int cmCommandArgument_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
  71. #endif