cmFortranParser.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 cmFortranParser_h
  4. #define cmFortranParser_h
  5. #if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx)
  6. #include "cmConfigure.h" // IWYU pragma: keep
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #endif
  11. #include <stddef.h> /* size_t */
  12. /* Forward declare parser object type. */
  13. typedef struct cmFortranParser_s cmFortranParser;
  14. /* Functions to enter/exit #include'd files in order. */
  15. bool cmFortranParser_FilePush(cmFortranParser* parser, const char* fname);
  16. bool cmFortranParser_FilePop(cmFortranParser* parser);
  17. /* Callbacks for lexer. */
  18. int cmFortranParser_Input(cmFortranParser* parser, char* buffer,
  19. size_t bufferSize);
  20. void cmFortranParser_StringStart(cmFortranParser* parser);
  21. const char* cmFortranParser_StringEnd(cmFortranParser* parser);
  22. void cmFortranParser_StringAppend(cmFortranParser* parser, char c);
  23. void cmFortranParser_SetInInterface(cmFortranParser* parser, bool is_in);
  24. bool cmFortranParser_GetInInterface(cmFortranParser* parser);
  25. void cmFortranParser_SetInPPFalseBranch(cmFortranParser* parser, bool is_in);
  26. bool cmFortranParser_GetInPPFalseBranch(cmFortranParser* parser);
  27. void cmFortranParser_SetOldStartcond(cmFortranParser* parser, int arg);
  28. int cmFortranParser_GetOldStartcond(cmFortranParser* parser);
  29. /* Callbacks for parser. */
  30. void cmFortranParser_Error(cmFortranParser* parser, const char* message);
  31. void cmFortranParser_RuleUse(cmFortranParser* parser, const char* name);
  32. void cmFortranParser_RuleLineDirective(cmFortranParser* parser,
  33. const char* filename);
  34. void cmFortranParser_RuleInclude(cmFortranParser* parser, const char* name);
  35. void cmFortranParser_RuleModule(cmFortranParser* parser, const char* name);
  36. void cmFortranParser_RuleDefine(cmFortranParser* parser, const char* name);
  37. void cmFortranParser_RuleUndef(cmFortranParser* parser, const char* name);
  38. void cmFortranParser_RuleIfdef(cmFortranParser* parser, const char* name);
  39. void cmFortranParser_RuleIfndef(cmFortranParser* parser, const char* name);
  40. void cmFortranParser_RuleIf(cmFortranParser* parser);
  41. void cmFortranParser_RuleElif(cmFortranParser* parser);
  42. void cmFortranParser_RuleElse(cmFortranParser* parser);
  43. void cmFortranParser_RuleEndif(cmFortranParser* parser);
  44. /* Define the parser stack element type. */
  45. struct cmFortran_yystype
  46. {
  47. char* string;
  48. };
  49. /* Setup the proper yylex interface. */
  50. #define YY_EXTRA_TYPE cmFortranParser*
  51. #define YY_DECL int cmFortran_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
  52. #define YYSTYPE cmFortran_yystype
  53. #define YYSTYPE_IS_DECLARED 1
  54. #if !defined(cmFortranLexer_cxx)
  55. #define YY_NO_UNISTD_H
  56. #include "cmFortranLexer.h"
  57. #endif
  58. #if !defined(cmFortranLexer_cxx)
  59. #if !defined(cmFortranParser_cxx)
  60. #undef YY_EXTRA_TYPE
  61. #undef YY_DECL
  62. #undef YYSTYPE
  63. #undef YYSTYPE_IS_DECLARED
  64. #endif
  65. #endif
  66. #if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx)
  67. #include <stack>
  68. // Information about a single source file.
  69. class cmFortranSourceInfo
  70. {
  71. public:
  72. // The name of the source file.
  73. std::string Source;
  74. // Set of provided and required modules.
  75. std::set<std::string> Provides;
  76. std::set<std::string> Requires;
  77. // Set of files included in the translation unit.
  78. std::set<std::string> Includes;
  79. };
  80. // Parser methods not included in generated interface.
  81. // Get the current buffer processed by the lexer.
  82. YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner);
  83. // The parser entry point.
  84. int cmFortran_yyparse(yyscan_t);
  85. // Define parser object internal structure.
  86. struct cmFortranFile
  87. {
  88. cmFortranFile(FILE* file, YY_BUFFER_STATE buffer, const std::string& dir)
  89. : File(file)
  90. , Buffer(buffer)
  91. , Directory(dir)
  92. , LastCharWasNewline(false)
  93. {
  94. }
  95. FILE* File;
  96. YY_BUFFER_STATE Buffer;
  97. std::string Directory;
  98. bool LastCharWasNewline;
  99. };
  100. struct cmFortranParser_s
  101. {
  102. cmFortranParser_s(std::vector<std::string> const& includes,
  103. std::set<std::string> const& defines,
  104. cmFortranSourceInfo& info);
  105. ~cmFortranParser_s();
  106. bool FindIncludeFile(const char* dir, const char* includeName,
  107. std::string& fileName);
  108. // The include file search path.
  109. std::vector<std::string> IncludePath;
  110. // Lexical scanner instance.
  111. yyscan_t Scanner;
  112. // Stack of open files in the translation unit.
  113. std::stack<cmFortranFile> FileStack;
  114. // Buffer for string literals.
  115. std::string TokenString;
  116. // Error message text if a parser error occurs.
  117. std::string Error;
  118. // Flag for whether lexer is reading from inside an interface.
  119. bool InInterface;
  120. int OldStartcond;
  121. std::set<std::string> PPDefinitions;
  122. size_t InPPFalseBranch;
  123. std::stack<bool> SkipToEnd;
  124. // Information about the parsed source.
  125. cmFortranSourceInfo& Info;
  126. };
  127. #endif
  128. #endif