cmCommandArgumentParserHelper.h 2.6 KB

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