cmCommandArgumentParserHelper.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 EscapeQuotes;
  59. bool NoEscapeMode;
  60. bool ReplaceAtSyntax;
  61. bool RemoveEmpty;
  62. };
  63. #define YYSTYPE cmCommandArgumentParserHelper::ParserType
  64. #define YYSTYPE_IS_DECLARED
  65. #define YY_EXTRA_TYPE cmCommandArgumentParserHelper*
  66. #define YY_DECL \
  67. int cmCommandArgument_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
  68. #endif