cmDependsJavaParserHelper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmDependsJavaParserHelper_h
  11. #define cmDependsJavaParserHelper_h
  12. #include "cmStandardIncludes.h"
  13. #define YYSTYPE cmDependsJavaParserHelper::ParserType
  14. #define YYSTYPE_IS_DECLARED
  15. #define YY_EXTRA_TYPE cmDependsJavaParserHelper*
  16. #define YY_DECL int cmDependsJava_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
  17. /** \class cmDependsJavaParserHelper
  18. * \brief Helper class for parsing java source files
  19. *
  20. * Finds dependencies for java file and list of outputs
  21. */
  22. class cmDependsJavaParserHelper
  23. {
  24. public:
  25. typedef struct {
  26. char* str;
  27. } ParserType;
  28. cmDependsJavaParserHelper();
  29. ~cmDependsJavaParserHelper();
  30. int ParseString(const char* str, int verb);
  31. int ParseFile(const char* file);
  32. // For the lexer:
  33. void AllocateParserType(cmDependsJavaParserHelper::ParserType* pt,
  34. const char* str, int len = 0);
  35. int LexInput(char* buf, int maxlen);
  36. void Error(const char* str);
  37. // For yacc
  38. void AddClassFound(const char* sclass);
  39. void PrepareElement(ParserType* opt);
  40. void DeallocateParserType(char** pt);
  41. void CheckEmpty(int line, int cnt, ParserType* pt);
  42. void StartClass(const char* cls);
  43. void EndClass();
  44. void AddPackagesImport(const char* sclass);
  45. void SetCurrentPackage(const char* pkg) { this->CurrentPackage = pkg; }
  46. const char* GetCurrentPackage() { return this->CurrentPackage.c_str(); }
  47. void SetCurrentCombine(const char* cmb) { this->CurrentCombine = cmb; }
  48. const char* GetCurrentCombine() { return this->CurrentCombine.c_str(); }
  49. void UpdateCombine(const char* str1, const char* str2);
  50. std::vector<std::string>& GetClassesFound() { return this->ClassesFound; }
  51. std::vector<std::string> GetFilesProduced();
  52. private:
  53. class CurrentClass
  54. {
  55. public:
  56. std::string Name;
  57. std::vector<CurrentClass>* NestedClasses;
  58. CurrentClass()
  59. {
  60. this->NestedClasses = new std::vector<CurrentClass>;
  61. }
  62. ~CurrentClass()
  63. {
  64. delete this->NestedClasses;
  65. }
  66. CurrentClass& operator=(CurrentClass const& c)
  67. {
  68. this->NestedClasses->clear();
  69. this->Name = c.Name;
  70. std::copy(
  71. c.NestedClasses->begin(),
  72. c.NestedClasses->end(),
  73. std::back_inserter(
  74. *this->NestedClasses)
  75. );
  76. return *this;
  77. }
  78. CurrentClass(CurrentClass const& c)
  79. {
  80. (*this) = c;
  81. }
  82. void AddFileNamesForPrinting(std::vector<std::string> *files,
  83. const char* prefix, const char* sep);
  84. };
  85. std::string CurrentPackage;
  86. std::string::size_type InputBufferPos;
  87. std::string InputBuffer;
  88. std::vector<char> OutputBuffer;
  89. std::vector<std::string> ClassesFound;
  90. std::vector<std::string> PackagesImport;
  91. std::string CurrentCombine;
  92. std::vector<CurrentClass> ClassStack;
  93. int CurrentLine;
  94. int UnionsAvailable;
  95. int LastClassId;
  96. int CurrentDepth;
  97. int Verbose;
  98. std::vector<char*> Allocates;
  99. void PrintClasses();
  100. void Print(const char* place, const char* str);
  101. void CombineUnions(char** out, const char* in1, char** in2,
  102. const char* sep);
  103. void SafePrintMissing(const char* str, int line, int cnt);
  104. void CleanupParser();
  105. };
  106. #endif