cmDependsJavaParserHelper.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <cmConfigure.h>
  13. #include "cmStandardIncludes.h"
  14. #define YYSTYPE cmDependsJavaParserHelper::ParserType
  15. #define YYSTYPE_IS_DECLARED
  16. #define YY_EXTRA_TYPE cmDependsJavaParserHelper*
  17. #define YY_DECL int cmDependsJava_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
  18. /** \class cmDependsJavaParserHelper
  19. * \brief Helper class for parsing java source files
  20. *
  21. * Finds dependencies for java file and list of outputs
  22. */
  23. class cmDependsJavaParserHelper
  24. {
  25. public:
  26. typedef struct
  27. {
  28. char* str;
  29. } ParserType;
  30. cmDependsJavaParserHelper();
  31. ~cmDependsJavaParserHelper();
  32. int ParseString(const char* str, int verb);
  33. int ParseFile(const char* file);
  34. // For the lexer:
  35. void AllocateParserType(cmDependsJavaParserHelper::ParserType* pt,
  36. const char* str, int len = 0);
  37. int LexInput(char* buf, int maxlen);
  38. void Error(const char* str);
  39. // For yacc
  40. void AddClassFound(const char* sclass);
  41. void PrepareElement(ParserType* me);
  42. void DeallocateParserType(char** pt);
  43. void CheckEmpty(int line, int cnt, ParserType* pt);
  44. void StartClass(const char* cls);
  45. void EndClass();
  46. void AddPackagesImport(const char* sclass);
  47. void SetCurrentPackage(const char* pkg) { this->CurrentPackage = pkg; }
  48. const char* GetCurrentPackage() { return this->CurrentPackage.c_str(); }
  49. void SetCurrentCombine(const char* cmb) { this->CurrentCombine = cmb; }
  50. const char* GetCurrentCombine() { return this->CurrentCombine.c_str(); }
  51. void UpdateCombine(const char* str1, const char* str2);
  52. std::vector<std::string>& GetClassesFound() { return this->ClassesFound; }
  53. std::vector<std::string> GetFilesProduced();
  54. private:
  55. class CurrentClass
  56. {
  57. public:
  58. std::string Name;
  59. std::vector<CurrentClass> NestedClasses;
  60. void AddFileNamesForPrinting(std::vector<std::string>* files,
  61. const char* prefix, const char* sep) const;
  62. };
  63. std::string CurrentPackage;
  64. std::string::size_type InputBufferPos;
  65. std::string InputBuffer;
  66. std::vector<char> OutputBuffer;
  67. std::vector<std::string> ClassesFound;
  68. std::vector<std::string> PackagesImport;
  69. std::string CurrentCombine;
  70. std::vector<CurrentClass> ClassStack;
  71. int CurrentLine;
  72. int UnionsAvailable;
  73. int LastClassId;
  74. int CurrentDepth;
  75. int Verbose;
  76. std::vector<char*> Allocates;
  77. void PrintClasses();
  78. void Print(const char* place, const char* str);
  79. void CombineUnions(char** out, const char* in1, char** in2, const char* sep);
  80. void SafePrintMissing(const char* str, int line, int cnt);
  81. void CleanupParser();
  82. };
  83. #endif