cmDependsJavaParserHelper.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. {
  27. char* str;
  28. } ParserType;
  29. cmDependsJavaParserHelper();
  30. ~cmDependsJavaParserHelper();
  31. int ParseString(const char* str, int verb);
  32. int ParseFile(const char* file);
  33. // For the lexer:
  34. void AllocateParserType(cmDependsJavaParserHelper::ParserType* pt,
  35. const char* str, int len = 0);
  36. int LexInput(char* buf, int maxlen);
  37. void Error(const char* str);
  38. // For yacc
  39. void AddClassFound(const char* sclass);
  40. void PrepareElement(ParserType* me);
  41. void DeallocateParserType(char** pt);
  42. void CheckEmpty(int line, int cnt, ParserType* pt);
  43. void StartClass(const char* cls);
  44. void EndClass();
  45. void AddPackagesImport(const char* sclass);
  46. void SetCurrentPackage(const char* pkg) { this->CurrentPackage = pkg; }
  47. const char* GetCurrentPackage() { return this->CurrentPackage.c_str(); }
  48. void SetCurrentCombine(const char* cmb) { this->CurrentCombine = cmb; }
  49. const char* GetCurrentCombine() { return this->CurrentCombine.c_str(); }
  50. void UpdateCombine(const char* str1, const char* str2);
  51. std::vector<std::string>& GetClassesFound() { return this->ClassesFound; }
  52. std::vector<std::string> GetFilesProduced();
  53. private:
  54. class CurrentClass
  55. {
  56. public:
  57. std::string Name;
  58. std::vector<CurrentClass> NestedClasses;
  59. void AddFileNamesForPrinting(std::vector<std::string>* files,
  60. const char* prefix, const char* sep) const;
  61. };
  62. std::string CurrentPackage;
  63. std::string::size_type InputBufferPos;
  64. std::string InputBuffer;
  65. std::vector<char> OutputBuffer;
  66. std::vector<std::string> ClassesFound;
  67. std::vector<std::string> PackagesImport;
  68. std::string CurrentCombine;
  69. std::vector<CurrentClass> ClassStack;
  70. int CurrentLine;
  71. int UnionsAvailable;
  72. int LastClassId;
  73. int CurrentDepth;
  74. int Verbose;
  75. std::vector<char*> Allocates;
  76. void PrintClasses();
  77. void Print(const char* place, const char* str);
  78. void CombineUnions(char** out, const char* in1, char** in2, const char* sep);
  79. void SafePrintMissing(const char* str, int line, int cnt);
  80. void CleanupParser();
  81. };
  82. #endif