cmCommandArgumentParserHelper.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 <string>
  7. #include <vector>
  8. class cmMakefile;
  9. class cmCommandArgumentParserHelper
  10. {
  11. CM_DISABLE_COPY(cmCommandArgumentParserHelper)
  12. public:
  13. struct ParserType
  14. {
  15. const char* str;
  16. };
  17. cmCommandArgumentParserHelper();
  18. ~cmCommandArgumentParserHelper();
  19. int ParseString(const char* str, int verb);
  20. // For the lexer:
  21. void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
  22. const char* str, int len = 0);
  23. bool HandleEscapeSymbol(cmCommandArgumentParserHelper::ParserType* pt,
  24. char symbol);
  25. int LexInput(char* buf, int maxlen);
  26. void Error(const char* str);
  27. // For yacc
  28. const char* CombineUnions(const char* in1, const char* in2);
  29. const char* ExpandSpecialVariable(const char* key, const char* var);
  30. const char* ExpandVariable(const char* var);
  31. const char* ExpandVariableForAt(const char* var);
  32. void SetResult(const char* value);
  33. void SetMakefile(const cmMakefile* mf);
  34. std::string& GetResult() { return this->Result; }
  35. void SetLineFile(long line, const char* file);
  36. void SetEscapeQuotes(bool b) { this->EscapeQuotes = b; }
  37. void SetNoEscapeMode(bool b) { this->NoEscapeMode = b; }
  38. void SetReplaceAtSyntax(bool b) { this->ReplaceAtSyntax = b; }
  39. void SetRemoveEmpty(bool b) { this->RemoveEmpty = b; }
  40. const char* GetError() { return this->ErrorString.c_str(); }
  41. private:
  42. std::string::size_type InputBufferPos;
  43. std::string InputBuffer;
  44. std::vector<char> OutputBuffer;
  45. void Print(const char* place, const char* str);
  46. void SafePrintMissing(const char* str, int line, int cnt);
  47. const char* AddString(const std::string& str);
  48. void CleanupParser();
  49. void SetError(std::string const& msg);
  50. std::vector<char*> Variables;
  51. const cmMakefile* Makefile;
  52. std::string Result;
  53. std::string ErrorString;
  54. const char* FileName;
  55. long FileLine;
  56. int CurrentLine;
  57. int Verbose;
  58. bool WarnUninitialized;
  59. bool CheckSystemVars;
  60. bool EscapeQuotes;
  61. bool NoEscapeMode;
  62. bool ReplaceAtSyntax;
  63. bool RemoveEmpty;
  64. };
  65. #define YYSTYPE cmCommandArgumentParserHelper::ParserType
  66. #define YYSTYPE_IS_DECLARED
  67. #define YY_EXTRA_TYPE cmCommandArgumentParserHelper*
  68. #define YY_DECL \
  69. int cmCommandArgument_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
  70. #endif