Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmFortranParser.h
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#pragma once
4
5
#if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx)
6
#  include "cmConfigure.h" // IWYU pragma: keep
7
8
#  include <set>
9
#  include <string>
10
#  include <utility>
11
#  include <vector>
12
#endif
13
14
#include <cstddef> /* size_t */
15
16
/* Forward declare parser object type.  */
17
using cmFortranParser = struct cmFortranParser_s;
18
19
/* Functions to enter/exit #include'd files in order.  */
20
bool cmFortranParser_FilePush(cmFortranParser* parser, char const* fname);
21
bool cmFortranParser_FilePop(cmFortranParser* parser);
22
23
/* Callbacks for lexer.  */
24
int cmFortranParser_Input(cmFortranParser* parser, char* buffer,
25
                          size_t bufferSize);
26
27
void cmFortranParser_StringStart(cmFortranParser* parser);
28
char const* cmFortranParser_StringEnd(cmFortranParser* parser);
29
void cmFortranParser_StringAppend(cmFortranParser* parser, char c);
30
31
void cmFortranParser_SetInInterface(cmFortranParser* parser, bool is_in);
32
bool cmFortranParser_GetInInterface(cmFortranParser* parser);
33
34
void cmFortranParser_SetInPPFalseBranch(cmFortranParser* parser, bool is_in);
35
bool cmFortranParser_GetInPPFalseBranch(cmFortranParser* parser);
36
37
void cmFortranParser_SetOldStartcond(cmFortranParser* parser, int arg);
38
int cmFortranParser_GetOldStartcond(cmFortranParser* parser);
39
40
/* Callbacks for parser.  */
41
void cmFortranParser_Error(cmFortranParser* parser, char const* message);
42
void cmFortranParser_RuleUse(cmFortranParser* parser, char const* module_name);
43
void cmFortranParser_RuleUseIntrinsic(cmFortranParser* parser,
44
                                      char const* module_name);
45
void cmFortranParser_RuleLineDirective(cmFortranParser* parser,
46
                                       char const* filename);
47
void cmFortranParser_RuleInclude(cmFortranParser* parser, char const* name);
48
void cmFortranParser_RuleModule(cmFortranParser* parser,
49
                                char const* module_name);
50
void cmFortranParser_RuleSubmodule(cmFortranParser* parser,
51
                                   char const* module_name,
52
                                   char const* submodule_name);
53
void cmFortranParser_RuleSubmoduleNested(cmFortranParser* parser,
54
                                         char const* module_name,
55
                                         char const* submodule_name,
56
                                         char const* nested_submodule_name);
57
void cmFortranParser_RuleDefine(cmFortranParser* parser, char const* name);
58
void cmFortranParser_RuleUndef(cmFortranParser* parser, char const* name);
59
void cmFortranParser_RuleIfdef(cmFortranParser* parser, char const* name);
60
void cmFortranParser_RuleIfndef(cmFortranParser* parser, char const* name);
61
void cmFortranParser_RuleIf(cmFortranParser* parser);
62
void cmFortranParser_RuleElif(cmFortranParser* parser);
63
void cmFortranParser_RuleElse(cmFortranParser* parser);
64
void cmFortranParser_RuleEndif(cmFortranParser* parser);
65
66
/* Define the parser stack element type.  */
67
struct cmFortran_yystype
68
{
69
  char* string;
70
};
71
72
/* Setup the proper yylex interface.  */
73
#define YY_EXTRA_TYPE cmFortranParser*
74
#define YY_DECL int cmFortran_yylex(YYSTYPE* yylvalp, yyscan_t yyscanner)
75
0
#define YYSTYPE cmFortran_yystype
76
#define YYSTYPE_IS_DECLARED 1
77
#if !defined(cmFortranLexer_cxx)
78
#  define YY_NO_UNISTD_H
79
#  include "cmFortranLexer.h"
80
#endif
81
#if !defined(cmFortranLexer_cxx)
82
#  if !defined(cmFortranParser_cxx)
83
#    undef YY_EXTRA_TYPE
84
#    undef YY_DECL
85
#    undef YYSTYPE
86
#    undef YYSTYPE_IS_DECLARED
87
#  endif
88
#endif
89
90
#if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx)
91
#  include <stack>
92
93
// Information about a single source file.
94
class cmFortranSourceInfo
95
{
96
public:
97
  // The name of the source file.
98
  std::string Source;
99
100
  // Set of provided and required modules.
101
  std::set<std::string> Provides;
102
  std::set<std::string> Requires;
103
104
  // Set of intrinsic modules.
105
  std::set<std::string> Intrinsics;
106
107
  // Set of files included in the translation unit.
108
  std::set<std::string> Includes;
109
};
110
111
// Parser methods not included in generated interface.
112
113
// Get the current buffer processed by the lexer.
114
YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner);
115
116
// The parser entry point.
117
int cmFortran_yyparse(yyscan_t);
118
119
// Define parser object internal structure.
120
struct cmFortranFile
121
{
122
  cmFortranFile(FILE* file, YY_BUFFER_STATE buffer, std::string dir)
123
0
    : File(file)
124
0
    , Buffer(buffer)
125
0
    , Directory(std::move(dir))
126
0
  {
127
0
  }
128
  FILE* File;
129
  YY_BUFFER_STATE Buffer;
130
  std::string Directory;
131
  bool LastCharWasNewline = false;
132
};
133
134
struct cmFortranCompiler
135
{
136
  std::string Id;
137
  std::string SModSep;
138
  std::string SModExt;
139
};
140
141
struct cmFortranParser_s
142
{
143
  cmFortranParser_s(cmFortranCompiler fc, std::vector<std::string> includes,
144
                    std::set<std::string> defines, cmFortranSourceInfo& info);
145
  ~cmFortranParser_s();
146
147
  cmFortranParser_s(cmFortranParser_s const&) = delete;
148
  cmFortranParser_s& operator=(cmFortranParser_s const&) = delete;
149
150
  bool FindIncludeFile(char const* dir, char const* includeName,
151
                       std::string& fileName);
152
153
  std::string ModName(std::string const& mod_name) const;
154
  std::string SModName(std::string const& mod_name,
155
                       std::string const& sub_name) const;
156
157
  // What compiler.
158
  cmFortranCompiler Compiler;
159
160
  // The include file search path.
161
  std::vector<std::string> IncludePath;
162
163
  // Lexical scanner instance.
164
  yyscan_t Scanner;
165
166
  // List of full paths to already processed files.
167
  std::set<std::string> VisitedFilePaths;
168
169
  // Stack of open files in the translation unit.
170
  std::stack<cmFortranFile> FileStack;
171
172
  // Buffer for string literals.
173
  std::string TokenString;
174
175
  // Error message text if a parser error occurs.
176
  std::string Error;
177
178
  // Flag for whether lexer is reading from inside an interface.
179
  bool InInterface;
180
181
  int OldStartcond;
182
  std::set<std::string> PPDefinitions;
183
  size_t InPPFalseBranch;
184
  std::stack<bool> SkipToEnd;
185
186
  // Information about the parsed source.
187
  cmFortranSourceInfo& Info;
188
};
189
#endif