Doxygen
Loading...
Searching...
No Matches
fortrancode.l
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Parser for syntax highlighting and references for Fortran90 F subset
4 *
5 * Copyright (C) by Anke Visser
6 * based on the work of Dimitri van Heesch.
7 * Copyright (C) 2020 by Dimitri van Heesch.
8 *
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation under the terms of the GNU General Public License is hereby
11 * granted. No representations are made about the suitability of this software
12 * for any purpose. It is provided "as is" without express or implied warranty.
13 * See the GNU General Public License for more details.
14 *
15 * Documents produced by Doxygen are derivative works derived from the
16 * input used in their production; they are not affected by this license.
17 *
18 */
19
20/**
21 @todo
22 - continuation lines not always recognized
23 - merging of use-statements with same module name and different only-names
24 - rename part of use-statement
25 - links to interface functions
26 - references to variables
27**/
28%option never-interactive
29%option case-insensitive
30%option reentrant
31%option prefix="fortrancodeYY"
32%option extra-type="struct fortrancodeYY_state *"
33%option noyy_top_state
34%top{
35#include <stdint.h>
36// forward declare yyscan_t to improve type safety
37#define YY_TYPEDEF_YY_SCANNER_T
38#define yyguts_t fortrancodeYYguts_t
39struct yyguts_t;
yyguts_t * yyscan_t
Definition code.l:25
#define yyguts_t
Definition code.l:23
41}
42
43%{
44
45// own header
46#include "fortrancode.h"
47
48// standard includes
49#include <map>
50#include <memory>
51#include <string>
52#include <vector>
53
54// other includes
55#include "classlist.h"
56#include "config.h"
57#include "containers.h"
58#include "debug.h"
59#include "doxygen.h"
60#include "filedef.h"
61#include "fortranscanner.h"
62#include "groupdef.h"
63#include "membername.h"
64#include "message.h"
65#include "namespacedef.h"
66#include "outputlist.h"
67#include "tooltip.h"
68#include "util.h"
69
70// Toggle for some debugging info
71//#define DBG_CTX(x) fprintf x
72#define DBG_CTX(x) do { } while(0)
73
74#define YY_NO_TOP_STATE 1
75#define YY_NO_INPUT 1
76#define YY_NO_UNISTD_H 1
77
78/*
79 * For fixed formatted code position 6 is of importance (continuation character).
80 * The following variables and macros keep track of the column number
81 * YY_USER_ACTION is always called for each scan action
82 * YY_FTN_RESET is used to handle end of lines and reset the column counter
83 * YY_FTN_REJECT resets the column counters when a pattern is rejected and thus rescanned.
84 */
87int yy_end = 1;
88#define YY_USER_ACTION {yy_old_start = yy_my_start; yy_my_start = yy_end; yy_end += static_cast<int>(yyleng);}
89#define YY_FTN_RESET {yy_old_start = 0; yy_my_start = 0; yy_end = 1;}
90#define YY_FTN_REJECT {yy_end = yy_my_start; yy_my_start = yy_old_start; REJECT;}
91
92//--------------------------------------------------------------------------------
93
94/**
95 data of an use-statement
96*/
98{
99 public:
100 DString module; // just for debug
101 std::vector<DString> onlyNames; /* entries of the ONLY-part */
102};
103
104/**
105 module name -> list of ONLY/remote entries
106 (module name = name of the module, which can be accessed via use-directive)
107*/
108class UseMap : public std::map<std::string,UseEntry>
109{
110};
111
112/**
113 Contains names of used modules and names of local variables.
114*/
115class Scope
116{
117 public:
118 std::vector<DString> useNames; //!< contains names of used modules
119 StringUnorderedSet localVars; //!< contains names of local variables
120 StringUnorderedSet externalVars; //!< contains names of external entities
121};
122
123/*===================================================================*/
124/*
125 * statics
126 */
127
129{
130 DString docBlock; //!< contents of all lines of a documentation block
131 DString currentModule=DString(); //!< name of the current enclosing module
132 UseMap useMembers; //!< info about used modules
133 UseEntry useEntry; //!< current use statement info
134 std::vector<Scope> scopeStack;
135 bool isExternal = false;
136 DString str=DString(); //!< contents of fortran string
137
138 OutputCodeList * code = nullptr;
139
140 const char * inputString = nullptr; //!< the code fragment as text
141 int inputPosition = 0; //!< read offset during parsing
142 int inputLines = 0; //!< number of line in the code fragment
144 int yyLineNr = 0; //!< current line number
145 int contLineNr = 0; //!< current, local, line number for continuation determination
146 int *hasContLine = nullptr; //!< signals whether or not a line has a continuation line (fixed source form)
147 bool insideCodeLine = false;
148 const Definition *searchCtx = nullptr;
149 bool collectXRefs = false;
150 bool isFixedForm = false;
151
152 bool insideBody = false; //!< inside subprog/program body? => create links
153 const char * currentFontClass = nullptr;
155
156 bool exampleBlock = false;
159
160 std::unique_ptr<FileDef> exampleFileDef;
161 const FileDef * sourceFileDef = nullptr;
162 bool lineNumbers = false;
163 const Definition * currentDefinition = nullptr;
164 const MemberDef * currentMemberDef = nullptr;
166
167 char stringStartSymbol = '\0'; // single or double quote
168// count in variable declaration to filter out
169// declared from referenced names
171
172// signal when in type / class /procedure declaration
173 int inTypeDecl = 0;
174
175 bool endComment = false;
177 std::vector<const Definition *> foldStack;
178
180};
181
182[[maybe_unused]] static const char *stateToString(int state);
183
184static bool getFortranNamespaceDefs(const DString &mname,
185 NamespaceDef *&cd);
186static bool getFortranTypeDefs(const DString &tname, const DString &moduleName,
187 ClassDef *&cd, const UseMap &useMap);
188
189//----------------------------------------------------------------------------
190
191static void startFontClass(yyscan_t yyscanner,const char *s,bool specialComment=false);
192static void endFontClass(yyscan_t yyscanner,bool specialComment=false);
193static void setCurrentDoc(yyscan_t yyscanner,const DString &anchor);
194static void addToSearchIndex(yyscan_t yyscanner,const DString &text);
195static void startCodeLine(yyscan_t yyscanner);
196static void endCodeLine(yyscan_t yyscanner);
197static void nextCodeLine(yyscan_t yyscanner);
198static void codifyLines(yyscan_t yyscanner,const DString &text);
199static void writeMultiLineCodeLink(yyscan_t yyscanner,OutputCodeList &ol,
200 Definition *d,const DString &text);
201static bool getGenericProcedureLink(yyscan_t yyscanner,const ClassDef *cd,
202 const DString &memberText,
203 OutputCodeList &ol);
204static bool getLink(yyscan_t yyscanner,const UseMap &useMap, // map with used modules
205 const DString &memberText, // exact member text
206 OutputCodeList &ol,
207 const DString &text);
208static void generateLink(yyscan_t yyscanner,OutputCodeList &ol, const DString &lname);
209static int countLines(yyscan_t yyscanner);
210static void startScope(yyscan_t yyscanner);
211static void endScope(yyscan_t yyscanner);
212static void addUse(yyscan_t yyscanner,const DString &moduleName);
213static void addLocalVar(yyscan_t yyscanner,const DString &varName);
214static MemberDef *getFortranDefs(yyscan_t yyscanner,const DString &memberName, const DString &moduleName,
215 const UseMap &useMap);
216static int yyread(yyscan_t yyscanner,char *buf,int max_size);
217static inline void pop_state(yyscan_t yyscanner);
218
219/* -----------------------------------------------------------------*/
220#undef YY_INPUT
221#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
222
223// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
224static inline const char *getLexerFILE() {return __FILE__;}
225#include "doxygen_lex.h"
226
A abstract class representing of a compound symbol.
Definition classdef.h:100
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
The common base class of all entity definitions found in the sources.
Definition definition.h:77
A model of a file symbol.
Definition filedef.h:97
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
An abstract interface of a namespace symbol.
Class representing a list of different code generators.
Definition outputlist.h:162
Contains names of used modules and names of local variables.
StringUnorderedSet externalVars
contains names of external entities
StringUnorderedSet localVars
contains names of local variables
std::vector< DString > useNames
contains names of used modules
Class that manages the tooltips for a source file.
Definition tooltip.h:27
data of an use-statement
Definition fortrancode.l:98
DString module
std::vector< DString > onlyNames
module name -> list of ONLY/remote entries (module name = name of the module, which can be accessed v...
std::unordered_set< std::string > StringUnorderedSet
Definition containers.h:29
static void writeMultiLineCodeLink(yyscan_t yyscanner, OutputCodeList &ol, Definition *d, const DString &text)
static void addUse(yyscan_t yyscanner, const DString &moduleName)
static void startScope(yyscan_t yyscanner)
start scope
static void endCodeLine(yyscan_t yyscanner)
static void endScope(yyscan_t yyscanner)
end scope
static bool getLink(yyscan_t yyscanner, const UseMap &useMap, const DString &memberText, OutputCodeList &ol, const DString &text)
static void nextCodeLine(yyscan_t yyscanner)
static void startCodeLine(yyscan_t yyscanner)
static void setCurrentDoc(yyscan_t yyscanner, const DString &anchor)
static MemberDef * getFortranDefs(yyscan_t yyscanner, const DString &memberName, const DString &moduleName, const UseMap &useMap)
searches for definition of function memberName
static void generateLink(yyscan_t yyscanner, OutputCodeList &ol, const DString &lname)
static int yyread(yyscan_t yyscanner, char *buf, int max_size)
static int countLines(yyscan_t yyscanner)
static const char * stateToString(int state)
static bool getFortranNamespaceDefs(const DString &mname, NamespaceDef *&cd)
searches for definition of a module (Namespace)
int yy_my_start
Definition fortrancode.l:86
static bool getFortranTypeDefs(const DString &tname, const DString &moduleName, ClassDef *&cd, const UseMap &useMap)
searches for definition of a type
static void pop_state(yyscan_t yyscanner)
static bool getGenericProcedureLink(yyscan_t yyscanner, const ClassDef *cd, const DString &memberText, OutputCodeList &ol)
gets the link to a generic procedure which depends not on the name, but on the parameter list
static void addToSearchIndex(yyscan_t yyscanner, const DString &text)
static void codifyLines(yyscan_t yyscanner, const DString &text)
static void startFontClass(yyscan_t yyscanner, const char *s, bool specialComment=false)
int yy_old_start
Definition fortrancode.l:85
static void endFontClass(yyscan_t yyscanner, bool specialComment=false)
static void addLocalVar(yyscan_t yyscanner, const DString &varName)
static const char * getLexerFILE()
int yy_end
Definition fortrancode.l:87
DString str
contents of fortran string
TooltipManager tooltipManager
OutputCodeList * code
DString docBlock
contents of all lines of a documentation block
int * hasContLine
signals whether or not a line has a continuation line (fixed source form)
bool insideBody
inside subprog/program body? => create links
int contLineNr
current, local, line number for continuation determination
int inputPosition
read offset during parsing
std::vector< Scope > scopeStack
std::unique_ptr< FileDef > exampleFileDef
const FileDef * sourceFileDef
const MemberDef * currentMemberDef
const Definition * searchCtx
UseEntry useEntry
current use statement info
DString currentModule
name of the current enclosing module
int yyLineNr
current line number
UseMap useMembers
info about used modules
std::vector< const Definition * > foldStack
const char * inputString
the code fragment as text
int inputLines
number of line in the code fragment
const Definition * currentDefinition
const char * currentFontClass
A bunch of utility functions.
227%}
228
229IDSYM [a-z_A-Z0-9]
230ID [a-z_A-Z]+{IDSYM}*
231SUBPROG (subroutine|function)
232BS [ \t]*
233BS_ [ \t]+
234COMMA {BS},{BS}
235ARGS_L0 ("("[^)]*")")
236ARGS_L1a [^()]*"("[^)]*")"[^)]*
237ARGS_L1 ("("{ARGS_L1a}*")")
238ARGS_L2 "("({ARGS_L0}|[^()]|{ARGS_L1a}|{ARGS_L1})*")"
239ARGS {BS}({ARGS_L0}|{ARGS_L1}|{ARGS_L2})
240
241NUM_TYPE (complex|integer|logical|real)
242LOG_OPER (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.)
243KIND {ARGS}
244CHAR (CHARACTER{ARGS}?|CHARACTER{BS}"*"({BS}[0-9]+|{ARGS}))
245TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS}COMPLEX|DOUBLE{BS}PRECISION|{CHAR}|TYPE|CLASS|PROCEDURE|ENUMERATOR)
246
247INTENT_SPEC intent{BS}"("{BS}(in|out|in{BS}out){BS}")"
248ATTR_SPEC (IMPLICIT|ALLOCATABLE|DIMENSION{ARGS}|EXTERNAL|{INTENT_SPEC}|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|PRIVATE|PUBLIC|SAVE|TARGET|(NON_)?RECURSIVE|PURE|IMPURE|ELEMENTAL|VALUE|NOPASS|DEFERRED|CONTIGUOUS|VOLATILE)
249ACCESS_SPEC (PROTECTED|PRIVATE|PUBLIC)
250/* Assume that attribute statements are almost the same as attributes. */
251FLOW (DO|SELECT|CASE|SELECT{BS}(CASE|TYPE|RANK)|WHERE|IF|THEN|ELSE|WHILE|FORALL|ELSEWHERE|ELSEIF|RETURN|CONTINUE|EXIT|GO{BS}TO)
252COMMANDS (FORMAT|CONTAINS|MODULE{BS_}PROCEDURE|WRITE|READ|ALLOCATE|ALLOCATED|ASSOCIATED|PRESENT|DEALLOCATE|NULLIFY|SIZE|INQUIRE|OPEN|CLOSE|FLUSH|DATA|COMMON)
253IGNORE (CALL)
254PREFIX ((NON_)?RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,4}((NON_)?RECURSIVE|IMPURE|PURE|ELEMENTAL)?0
255LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")"
256
257/* | */
258
259%option noyywrap
260%option stack
261%option caseless
262/*%option debug*/
263
264%x Start
265%x SubCall
266%x ClassName
267%x Subprog
268%x DocBlock
269%x Use
270%x UseOnly
271%x Import
272%x Declaration
273%x DeclarationBinding
274%x DeclContLine
275%x String
276%x Subprogend
277
279 /*==================================================================*/
280
281 /*-------- ignore ------------------------------------------------------------*/
282
283<Start>{IGNORE}/{BS}"(" { // do not search keywords, intrinsics... TODO: complete list
284 codifyLines(yyscanner,yytext);
285 }
286 /*-------- inner construct ---------------------------------------------------*/
287
288<Start>{COMMANDS}/{BS}[,( \t\n] { // highlight
289 /* font class is defined e.g. in doxygen.css */
290 startFontClass(yyscanner,"keyword");
291 codifyLines(yyscanner,yytext);
292 endFontClass(yyscanner);
293 }
294<Start>{FLOW}/{BS}[,( \t\n] {
295 if (yyextra->isFixedForm)
296 {
297 if ((yy_my_start == 1) && ((yytext[0] == 'c') || (yytext[0] == 'C'))) YY_FTN_REJECT;
298 }
299 if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction())
300 {
301 std::lock_guard<std::mutex> lock(Doxygen::countFlowKeywordsMutex);
302 MemberDefMutable *mdm = toMemberDefMutable(const_cast<MemberDef*>(yyextra->currentMemberDef));
303 if (mdm)
304 {
306 }
307 }
308 /* font class is defined e.g. in doxygen.css */
309 startFontClass(yyscanner,"keywordflow");
310 codifyLines(yyscanner,yytext);
311 endFontClass(yyscanner);
312 }
static std::mutex countFlowKeywordsMutex
Definition doxygen.h:132
virtual void incrementFlowKeyWordCount()=0
#define YY_FTN_REJECT
Definition fortrancode.l:90
MemberDefMutable * toMemberDefMutable(Definition *d)
313<Start>{BS}(RANK){BS_}(DEFAULT) |
314<Start>{BS}(RANK)/{BS}"("{BS}([0-9]+|"*"){BS}")" |
315<Start>{BS}(CASE|CLASS|TYPE){BS_}(IS|DEFAULT) {
316 startFontClass(yyscanner,"keywordflow");
317 codifyLines(yyscanner,yytext);
318 endFontClass(yyscanner);
319 }
320<Start>{BS}"end"({BS}{FLOW})/[ \t\n] { // list is a bit long as not all have possible end
321 startFontClass(yyscanner,"keywordflow");
322 codifyLines(yyscanner,yytext);
323 endFontClass(yyscanner);
324 }
325<Start>"implicit"{BS}("none"|{TYPE_SPEC}) {
326 startFontClass(yyscanner,"keywordtype");
327 codifyLines(yyscanner,yytext);
328 endFontClass(yyscanner);
329 }
330<Start>^{BS}"namelist"/[/] { // Namelist specification
331 startFontClass(yyscanner,"keywordtype");
332 codifyLines(yyscanner,yytext);
333 endFontClass(yyscanner);
334 }
335 /*-------- use statement -------------------------------------------*/
336<Start>"use"{BS_} {
337 startFontClass(yyscanner,"keywordtype");
338 codifyLines(yyscanner,yytext);
339 endFontClass(yyscanner);
340 yy_push_state(YY_START,yyscanner);
341 BEGIN(Use);
342 }
343<Use>"ONLY" { // TODO: rename
344 startFontClass(yyscanner,"keywordtype");
345 codifyLines(yyscanner,yytext);
346 endFontClass(yyscanner);
347 yy_push_state(YY_START,yyscanner);
348 BEGIN(UseOnly);
349 }
350<Use>{ID} {
351 DString tmp(yytext);
352 tmp = tmp.lower();
353 yyextra->insideBody=true;
354 generateLink(yyscanner,*yyextra->code, yytext);
355 yyextra->insideBody=false;
356
357 /* append module name to use dict */
358 yyextra->useEntry = UseEntry();
359 yyextra->useEntry.module = tmp;
360 yyextra->useMembers.emplace(tmp.str(), yyextra->useEntry);
361 addUse(yyscanner,tmp);
362 }
363<Use,UseOnly,Import>{BS},{BS} { codifyLines(yyscanner,yytext); }
364<UseOnly,Import>{BS}&{BS}"\n" { codifyLines(yyscanner,yytext);
365 yyextra->contLineNr++;
#define YY_FTN_RESET
Definition fortrancode.l:89
367<UseOnly>{ID} {
368 DString tmp(yytext);
369 tmp = tmp.lower();
370 yyextra->useEntry.onlyNames.push_back(tmp);
371 yyextra->insideBody=true;
372 generateLink(yyscanner,*yyextra->code, yytext);
373 yyextra->insideBody=false;
374 }
375<Use,UseOnly,Import>"\n" {
376 unput(*yytext);
377 pop_state(yyscanner);
379 }
380<*>"import"{BS}/"\n" |
381<*>"import"{BS_} {
382 if(YY_START == String) YY_FTN_REJECT; // ignore in strings
383 startFontClass(yyscanner,"keywordtype");
384 codifyLines(yyscanner,yytext);
385 endFontClass(yyscanner);
386 yy_push_state(YY_START,yyscanner);
387 BEGIN(Import);
388 }
389<Import>{ID} {
390 yyextra->insideBody=true;
391 generateLink(yyscanner,*yyextra->code, yytext);
392 yyextra->insideBody=false;
393 }
394<Import>("ONLY"|"NONE"|"ALL") {
395 startFontClass(yyscanner,"keywordtype");
396 codifyLines(yyscanner,yytext);
397 endFontClass(yyscanner);
398 }
399 /*-------- fortran module -----------------------------------------*/
400<Start>("block"{BS}"data"|"program"|"module"|"interface")/{BS_}|({COMMA}{ACCESS_SPEC})|\n { //
401 startScope(yyscanner);
402 startFontClass(yyscanner,"keyword");
403 codifyLines(yyscanner,yytext);
404 endFontClass(yyscanner);
405 yy_push_state(YY_START,yyscanner);
406 BEGIN(ClassName);
407 if (!dstricmp(yytext,"module")) yyextra->currentModule="module";
408 }
int dstricmp(const char *s1, const char *s2)
Definition dstring.cpp:444
409<Start>("enum")/{BS_}|{BS}{COMMA}{BS}{LANGUAGE_BIND_SPEC}|\n { //
410 startScope(yyscanner);
411 startFontClass(yyscanner,"keyword");
412 codifyLines(yyscanner,yytext);
413 endFontClass(yyscanner);
414 yy_push_state(YY_START,yyscanner);
415 BEGIN(ClassName);
416 }
417<*>{LANGUAGE_BIND_SPEC} { //
418 if(YY_START == String) YY_FTN_REJECT; // ignore in strings
419 startFontClass(yyscanner,"keyword");
420 codifyLines(yyscanner,yytext);
421 endFontClass(yyscanner);
422 }
423<Start>("type")/{BS_}|({COMMA}({ACCESS_SPEC}|ABSTRACT|EXTENDS))|\n { //
424 startScope(yyscanner);
425 startFontClass(yyscanner,"keyword");
426 codifyLines(yyscanner,yytext);
427 endFontClass(yyscanner);
428 yy_push_state(YY_START,yyscanner);
429 BEGIN(ClassName);
430 }
431<ClassName>{ID} {
432 if (yyextra->currentModule == "module")
433 {
434 yyextra->currentModule=yytext;
435 yyextra->currentModule = yyextra->currentModule.lower();
436 }
437 generateLink(yyscanner,*yyextra->code,yytext);
438 pop_state(yyscanner);
439 }
440<ClassName>({ACCESS_SPEC}|ABSTRACT|EXTENDS)/[,:( ] { //| variable declaration
441 startFontClass(yyscanner,"keyword");
442 yyextra->code->codify(yytext);
443 endFontClass(yyscanner);
444 }
445<ClassName>\n { // interface may be without name
446 pop_state(yyscanner);
448 }
449<Start>^{BS}"end"({BS_}"enum").* {
451 }
452<Start>^{BS}"end"({BS_}"type").* {
454 }
455<Start>^{BS}"end"({BS_}"module").* { // just reset yyextra->currentModule, rest is done in following rule
456 yyextra->currentModule=nullptr;
458 }
459 /*-------- subprog definition -------------------------------------*/
460<Start>({PREFIX}{BS_})?{TYPE_SPEC}{BS_}({PREFIX}{BS_})?{BS}/{SUBPROG}{BS_} { // TYPE_SPEC is for old function style function result
461 startFontClass(yyscanner,"keyword");
462 codifyLines(yyscanner,yytext);
463 endFontClass(yyscanner);
464 }
465<Start>({PREFIX}{BS_})?{SUBPROG}{BS_} { // Fortran subroutine or function found
466 startFontClass(yyscanner,"keyword");
467 codifyLines(yyscanner,yytext);
468 endFontClass(yyscanner);
469 yy_push_state(YY_START,yyscanner);
470 BEGIN(Subprog);
471 }
472<Subprog>{ID} { // subroutine/function name
473 DBG_CTX((stderr, "===> start subprogram %s\n", yytext));
474 startScope(yyscanner);
475 generateLink(yyscanner,*yyextra->code,yytext);
476 }
#define DBG_CTX(x)
Definition code.l:71
477<Subprog>"result"/{BS}"("[^)]*")" {
478 startFontClass(yyscanner,"keyword");
479 codifyLines(yyscanner,yytext);
480 endFontClass(yyscanner);
481 }
482<Subprog>"("[^)]*")" { // ignore rest of line
483 codifyLines(yyscanner,yytext);
484 }
485<Subprog,Subprogend>"\n" { codifyLines(yyscanner,yytext);
486 yyextra->contLineNr++;
487 pop_state(yyscanner);
489 }
490<Start>"end"{BS}("block"{BS}"data"|{SUBPROG}|"module"|"program"|"enum"|"type"|"interface")?{BS} { // Fortran subroutine or function ends
491 //cout << "===> end function " << yytext << endl;
492 endScope(yyscanner);
493 startFontClass(yyscanner,"keyword");
494 codifyLines(yyscanner,yytext);
495 endFontClass(yyscanner);
496 yy_push_state(YY_START,yyscanner);
497 BEGIN(Subprogend);
498 }
499<Subprogend>{ID}/{BS}(\n|!|;) {
500 generateLink(yyscanner,*yyextra->code,yytext);
501 pop_state(yyscanner);
502 }
503<Start>"end"{BS}("block"{BS}"data"|{SUBPROG}|"module"|"program"|"enum"|"type"|"interface"){BS}/(\n|!|;) { // Fortran subroutine or function ends
504 //cout << "===> end function " << yytext << endl;
505 endScope(yyscanner);
506 startFontClass(yyscanner,"keyword");
507 codifyLines(yyscanner,yytext);
508 endFontClass(yyscanner);
509 }
510 /*-------- variable declaration ----------------------------------*/
511<Start>^{BS}"real"/[,:( ] { // real is a bit tricky as it is a data type but also a function.
512 yy_push_state(YY_START,yyscanner);
513 BEGIN(Declaration);
514 startFontClass(yyscanner,"keywordtype");
515 yyextra->code->codify(yytext);
516 endFontClass(yyscanner);
517 }
518<Start>{TYPE_SPEC}/[,:( ] {
519 DString typ(yytext);
520 typ = removeRedundantWhiteSpace(typ.lower());
521 if (typ.startsWith("real")) YY_FTN_REJECT;
522 if (typ == "type" || typ == "class" || typ == "procedure") yyextra->inTypeDecl = 1;
523 yy_push_state(YY_START,yyscanner);
524 BEGIN(Declaration);
525 startFontClass(yyscanner,"keywordtype");
526 yyextra->code->codify(yytext);
527 endFontClass(yyscanner);
528 }
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
529<Start>{ATTR_SPEC} {
530 if (DString(yytext) == "external")
531 {
532 yy_push_state(YY_START,yyscanner);
533 BEGIN(Declaration);
534 yyextra->isExternal = true;
535 }
536 startFontClass(yyscanner,"keywordtype");
537 yyextra->code->codify(yytext);
538 endFontClass(yyscanner);
539 }
540<Declaration>({TYPE_SPEC}|{ATTR_SPEC})/[,:( ] { //| variable declaration
541 if (DString(yytext) == "external") yyextra->isExternal = true;
542 startFontClass(yyscanner,"keywordtype");
543 yyextra->code->codify(yytext);
544 endFontClass(yyscanner);
545 }
546<Declaration>{ID} { // local var
547 if (yyextra->isFixedForm && yy_my_start == 1)
548 {
549 startFontClass(yyscanner,"comment");
550 yyextra->code->codify(yytext);
551 endFontClass(yyscanner);
552 }
553 else if (yyextra->currentMemberDef &&
554 ((yyextra->currentMemberDef->isFunction() && (yyextra->currentMemberDef->typeString()!=DString("subroutine") || yyextra->inTypeDecl)) ||
555 yyextra->currentMemberDef->isVariable() || yyextra->currentMemberDef->isEnumValue()
556 )
557 )
558 {
559 generateLink(yyscanner,*yyextra->code, yytext);
560 }
561 else
562 {
563 yyextra->code->codify(yytext);
564 addLocalVar(yyscanner,yytext);
565 }
566 }
567<Declaration>{BS}("=>"|"="){BS} { // Procedure binding
568 BEGIN(DeclarationBinding);
569 yyextra->code->codify(yytext);
570 }
571<DeclarationBinding>{ID} { // Type bound procedure link
572 generateLink(yyscanner,*yyextra->code, yytext);
573 pop_state(yyscanner);
574 }
575<Declaration>[(] { // start of array or type / class specification
576 yyextra->bracketCount++;
577 yyextra->code->codify(yytext);
578 }
579
580<Declaration>[)] { // end array specification
581 yyextra->bracketCount--;
582 if (!yyextra->bracketCount) yyextra->inTypeDecl = 0;
583 yyextra->code->codify(yytext);
584 }
585
586<Declaration,DeclarationBinding>"&" { // continuation line
587 yyextra->code->codify(yytext);
588 if (!yyextra->isFixedForm)
589 {
590 yy_push_state(YY_START,yyscanner);
591 BEGIN(DeclContLine);
592 }
593 }
594<DeclContLine>"\n" { // declaration not yet finished
595 yyextra->contLineNr++;
596 codifyLines(yyscanner,yytext);
597 yyextra->bracketCount = 0;
598 pop_state(yyscanner);
600 }
601<Declaration,DeclarationBinding>"\n" { // end declaration line (?)
602 if (yyextra->endComment)
603 {
604 yyextra->endComment=false;
605 }
606 else
607 {
608 codifyLines(yyscanner,yytext);
609 }
610 yyextra->bracketCount = 0;
611 yyextra->contLineNr++;
612 if (!(yyextra->hasContLine && yyextra->hasContLine[yyextra->contLineNr - 1]))
613 {
614 yyextra->isExternal = false;
615 pop_state(yyscanner);
616 }
618 }
619
620 /*-------- subprog calls -----------------------------------------*/
621
622<Start>"call"{BS_} {
623 startFontClass(yyscanner,"keyword");
624 codifyLines(yyscanner,yytext);
625 endFontClass(yyscanner);
626 yy_push_state(YY_START,yyscanner);
627 BEGIN(SubCall);
628 }
629<SubCall>{ID} { // subroutine call
630 yyextra->insideBody=true;
631 generateLink(yyscanner,*yyextra->code, yytext);
632 yyextra->insideBody=false;
633 pop_state(yyscanner);
634 }
635<Start>{ID}{BS}/"(" { // function call
636 if (yyextra->isFixedForm && yy_my_start == 6)
637 {
638 // fixed form continuation line
640 }
641 else if (DString(yytext).stripWhiteSpace().lower() == "type")
642 {
643 yy_push_state(YY_START,yyscanner);
644 BEGIN(Declaration);
645 startFontClass(yyscanner,"keywordtype");
646 yyextra->code->codify(DString(yytext).stripWhiteSpace());
647 endFontClass(yyscanner);
648 yyextra->code->codify(DString(yytext + 4));
649 }
650 else
651 {
652 yyextra->insideBody=true;
653 generateLink(yyscanner,*yyextra->code,yytext);
654 yyextra->insideBody=false;
655 }
656 }
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...
Definition stringutil.h:75
657
658 /*-------- comments ---------------------------------------------------*/
659<Start,Declaration,DeclarationBinding>\n?{BS}"!>"|"!<" { // start comment line or comment block
660 if (yytext[0] == '\n')
661 {
662 yyextra->contLineNr++;
663 yy_old_start = 0;
664 yy_my_start = 1;
665 yy_end = static_cast<int>(yyleng);
666 }
667 // Actually we should see if ! on position 6, can be continuation
668 // but the chance is very unlikely, so no effort to solve it here
669 yy_push_state(YY_START,yyscanner);
670 BEGIN(DocBlock);
671 yyextra->docBlock=yytext;
672 }
673<Declaration,DeclarationBinding>{BS}"!<" { // start comment line or comment block
674 yy_push_state(YY_START,yyscanner);
675 BEGIN(DocBlock);
676 yyextra->docBlock=yytext;
677 }
678
679<DocBlock>.* { // contents of current comment line
680 yyextra->docBlock+=yytext;
681 }
682<DocBlock>"\n"{BS}("!>"|"!<"|"!!") { // comment block (next line is also comment line)
683 yyextra->contLineNr++;
684 yy_old_start = 0;
685 yy_my_start = 1;
686 yy_end = static_cast<int>(yyleng);
687 // Actually we should see if ! on position 6, can be continuation
688 // but the chance is very unlikely, so no effort to solve it here
689 yyextra->docBlock+=yytext;
690 }
691<DocBlock>"\n" { // comment block ends at the end of this line
692 // remove special comment (default config)
693 yyextra->contLineNr++;
694 startFontClass(yyscanner,"comment");
695 codifyLines(yyscanner,yyextra->docBlock);
696 endFontClass(yyscanner);
697 unput(*yytext);
698 yyextra->contLineNr--;
699 pop_state(yyscanner);
701 }
702
703<*>"!"[^><\n].*|"!"$ { // normal comment
704 if(YY_START == String) YY_FTN_REJECT; // ignore in strings
705 if (yyextra->isFixedForm && yy_my_start == 6) YY_FTN_REJECT;
706 startFontClass(yyscanner,"comment");
707 codifyLines(yyscanner,yytext);
708 endFontClass(yyscanner);
709 }
710
711<*>^[Cc*].* { // normal comment
712 if(! yyextra->isFixedForm) YY_FTN_REJECT;
713
714 startFontClass(yyscanner,"comment");
715 codifyLines(yyscanner,yytext);
716 endFontClass(yyscanner);
717 }
718<*>"assignment"/{BS}"("{BS}"="{BS}")" {
719 if(YY_START == String) YY_FTN_REJECT; // ignore in strings
720 startFontClass(yyscanner,"keyword");
721 codifyLines(yyscanner,yytext);
722 endFontClass(yyscanner);
723 }
724<*>"operator"/{BS}"("[^)]*")" {
725 if(YY_START == String) YY_FTN_REJECT; // ignore in strings
726 startFontClass(yyscanner,"keyword");
727 codifyLines(yyscanner,yytext);
728 endFontClass(yyscanner);
729 }
730
731 /*------ preprocessor --------------------------------------------*/
732<Start>"#".*\n {
733 if (yyextra->isFixedForm && yy_my_start == 6) YY_FTN_REJECT;
734 yyextra->contLineNr++;
735 startFontClass(yyscanner,"preprocessor");
736 codifyLines(yyscanner,yytext);
737 endFontClass(yyscanner);
739 }
740 /*------ variable references? -------------------------------------*/
741
742<Start>"%"{BS}{ID} { // ignore references to elements
743 yyextra->code->codify(yytext);
744 }
745<Start>{ID} {
746 yyextra->insideBody=true;
747 generateLink(yyscanner,*yyextra->code, yytext);
748 yyextra->insideBody=false;
749 }
750 /*------ strings --------------------------------------------------*/
751<String>\n { // string with \n inside
752 yyextra->contLineNr++;
753 yyextra->str+=yytext;
754 startFontClass(yyscanner,"stringliteral");
755 codifyLines(yyscanner,yyextra->str);
756 endFontClass(yyscanner);
757 yyextra->str = "";
759 }
760<String>\"|\' { // string ends with next quote without previous backspace
761 if(yytext[0]!=yyextra->stringStartSymbol) YY_FTN_REJECT; // single vs double quote
762 yyextra->str+=yytext;
763 startFontClass(yyscanner,"stringliteral");
764 codifyLines(yyscanner,yyextra->str);
765 endFontClass(yyscanner);
766 pop_state(yyscanner);
767 }
768<String>[\x80-\xFF]* |
769<String>. {yyextra->str+=yytext;}
770
771<*>\"|\' { /* string starts */
772 /* if(YY_START == StrIgnore) YY_FTN_REJECT; // ignore in simple comments */
773 if (yyextra->isFixedForm && yy_my_start == 6) YY_FTN_REJECT;
774 yy_push_state(YY_START,yyscanner);
775 yyextra->stringStartSymbol=yytext[0]; // single or double quote
776 BEGIN(String);
777 yyextra->str=yytext;
778 }
779 /*-----------------------------------------------------------------------------*/
780
781<*>\n {
782 if (yyextra->endComment)
783 {
784 yyextra->endComment=false;
785 }
786 else
787 {
788 codifyLines(yyscanner,yytext);
789 // comment cannot extend over the end of a line so should always be terminated at the end of the line.
790 if (yyextra->currentFontClass && !strcmp(yyextra->currentFontClass,"comment")) endFontClass(yyscanner);
791 }
792 yyextra->contLineNr++;
794 }
795<*>^{BS}"type"{BS}"=" { yyextra->code->codify(yytext); }
796
797<*>[\x80-\xFF]* { // keep utf8 characters together...
798 if (yyextra->isFixedForm && yy_my_start > yyextra->fixedCommentAfter)
799 {
800 startFontClass(yyscanner,"comment");
801 codifyLines(yyscanner,yytext);
802 }
803 else
804 {
805 yyextra->code->codify(yytext);
806 }
807 }
808<*>. {
809 if (yyextra->isFixedForm && yy_my_start > yyextra->fixedCommentAfter)
810 {
811 //yy_push_state(YY_START,yyscanner);
812 //BEGIN(DocBlock);
813 //yyextra->docBlock=yytext;
814 startFontClass(yyscanner,"comment");
815 codifyLines(yyscanner,yytext);
816 }
817 else
818 {
819 yyextra->code->codify(yytext);
820 }
821 }
822<*>{LOG_OPER} { // Fortran logical comparison keywords
823 yyextra->code->codify(yytext);
824 }
825<*><<EOF>> {
826 if (YY_START == DocBlock)
827 {
828 startFontClass(yyscanner,"comment");
829 codifyLines(yyscanner,yyextra->docBlock);
830 endFontClass(yyscanner);
831 }
832 yyterminate();
833 }
#define yyterminate()
834%%
835
836/*@ ----------------------------------------------------------------------------
837 */
838
839static int yyread(yyscan_t yyscanner,char *buf,int max_size)
840{
841 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
842 int inputPosition = yyextra->inputPosition;
843 const char *s = yyextra->inputString + inputPosition;
844 int c=0;
845 while( c < max_size && *s)
846 {
847 *buf++ = *s++;
848 c++;
849 }
850 yyextra->inputPosition += c;
851 return c;
852}
853
854static void endFontClass(yyscan_t yyscanner,bool specialComment)
855{
856 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
857 if (yyextra->currentFontClass)
858 {
859 yyextra->code->endFontClass();
860 yyextra->currentFontClass=nullptr;
861 }
862 if (specialComment && yyextra->insideSpecialComment)
863 {
864 yyextra->code->endSpecialComment();
865 yyextra->insideSpecialComment=false;
866 }
867}
868
869static void startFontClass(yyscan_t yyscanner,const char *s,bool specialComment)
870{
871 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
872 if (specialComment)
873 {
874 yyextra->code->startSpecialComment();
875 yyextra->insideSpecialComment = true;
876 }
877 // if font class is already set don't stop and start it.
878 if (dstrcmp(yyextra->currentFontClass,s)!=0)
879 {
880 endFontClass(yyscanner);
881 yyextra->code->startFontClass(s);
882 yyextra->currentFontClass=s;
883 }
884}
885
886static void setCurrentDoc(yyscan_t yyscanner,const DString &anchor)
887{
888 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
889 if (Doxygen::searchIndex.enabled())
890 {
891 if (yyextra->searchCtx)
892 {
893 Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),false);
894 }
895 else
896 {
897 Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,true);
898 }
899 }
900}
901
902static void addToSearchIndex(yyscan_t /*yyscanner*/,const DString &text)
903{
904 if (Doxygen::searchIndex.enabled())
905 {
906 Doxygen::searchIndex.addWord(text,false);
907 }
908}
909
910static void codeFolding(yyscan_t yyscanner,const Definition *d)
911{
912 if (Config_getBool(HTML_CODE_FOLDING))
913 {
914 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
915 while (!yyextra->foldStack.empty())
916 {
917 const Definition *dd = yyextra->foldStack.back();
918 if (dd->getEndBodyLine()+1==yyextra->yyLineNr) // +1 to close the section after the end of the body
919 {
920 yyextra->code->endFold();
921 //printf("%d: end codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(dd->name()),dd->getStartDefLine(),dd->getEndBodyLine());
922 yyextra->foldStack.pop_back();
923 }
924 else
925 {
926 break;
927 }
928 }
929 if (d)
930 {
931 int startLine = d->getStartDefLine();
932 int endLine = d->getEndBodyLine();
933 if (endLine!=-1 && startLine!=endLine &&
934 // since the end of a section is closed after the last line, we need to avoid starting a
935 // new section if the previous section ends at the same line, i.e. something like
936 // struct X {
937 // ...
938 // }; struct S { <- start of S and end of X at the same line
939 // ...
940 // };
941 (yyextra->foldStack.empty() || yyextra->foldStack.back()->getEndBodyLine()!=startLine))
942 {
943 //printf("%d: start codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->name()),d->getStartDefLine(),d->getEndBodyLine());
944 yyextra->code->startFold(yyextra->yyLineNr,"","");
945 yyextra->foldStack.push_back(d);
946 }
947 }
948 }
949}
950
951/*! start a new line of code, inserting a line number if yyextra->sourceFileDef
952 * is true. If a definition starts at the current line, then the line
953 * number is linked to the documentation of that definition.
954 */
955static void startCodeLine(yyscan_t yyscanner)
956{
957 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
958 if (yyextra->sourceFileDef && yyextra->lineNumbers)
959 {
960 //DString lineNumber,lineAnchor;
961 //lineNumber.sprintf("%05d",yyextra->yyLineNr);
962 //lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
963
964 const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
965 //printf("startCodeLine %d d=%s\n", yyextra->yyLineNr,d ? qPrint(d->name()) : "<null>");
966 if (!yyextra->includeCodeFragment && d)
967 {
968 yyextra->currentDefinition = d;
969 yyextra->currentMemberDef = yyextra->sourceFileDef->getSourceMember(yyextra->yyLineNr);
970 yyextra->insideBody = false;
971 yyextra->endComment = false;
972 DString lineAnchor;
973 lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
974 if (yyextra->currentMemberDef)
975 {
976 codeFolding(yyscanner,yyextra->currentMemberDef);
977 yyextra->code->writeLineNumber(yyextra->currentMemberDef->getReference(),
978 yyextra->currentMemberDef->getOutputFileBase(),
979 yyextra->currentMemberDef->anchor(),yyextra->yyLineNr,
980 !yyextra->includeCodeFragment);
981 setCurrentDoc(yyscanner,lineAnchor);
982 }
983 else if (d->isLinkableInProject())
984 {
985 codeFolding(yyscanner,d);
986 yyextra->code->writeLineNumber(d->getReference(),
988 DString(),yyextra->yyLineNr,
989 !yyextra->includeCodeFragment);
990 setCurrentDoc(yyscanner,lineAnchor);
991 }
992 else
993 {
994 codeFolding(yyscanner,nullptr);
995 }
996 }
997 else
998 {
999 codeFolding(yyscanner,nullptr);
1000 yyextra->code->writeLineNumber(DString(),DString(),DString(),yyextra->yyLineNr,
1001 !yyextra->includeCodeFragment);
1002 }
1003 }
1004 yyextra->code->startCodeLine(yyextra->yyLineNr);
1005 yyextra->insideCodeLine=true;
1006 if (yyextra->currentFontClass)
1007 {
1008 yyextra->code->startFontClass(yyextra->currentFontClass);
1009 }
1010}
1011
1012
1013static void endCodeLine(yyscan_t yyscanner)
1014{
1015 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1016 endFontClass(yyscanner);
1017 yyextra->code->endCodeLine();
1018 yyextra->insideCodeLine=false;
1019}
1020
1021static void nextCodeLine(yyscan_t yyscanner)
1022{
1023 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1024 const char * fc = yyextra->currentFontClass;
1025 endCodeLine(yyscanner);
1026 if (yyextra->yyLineNr<yyextra->inputLines)
1027 {
1028 yyextra->currentFontClass = fc;
1029 startCodeLine(yyscanner);
1030 }
1031}
1032
1033/*! write a code fragment 'text' that may span multiple lines, inserting
1034 * line numbers for each line.
1035 */
1036static void codifyLines(yyscan_t yyscanner,const DString &text)
1037{
1038 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1039 //printf("codifyLines(%d,\"%s\")\n",yyextra->yyLineNr,text);
1040 if (text.empty()) return;
1041 const char *p=text.data(),*sp=p;
1042 char c = 0;
1043 bool done=false;
1044 while (!done)
1045 {
1046 sp=p;
1047 while ((c=*p++) && c!='\n') { }
1048 if (c=='\n')
1049 {
1050 yyextra->yyLineNr++;
1051 size_t l = static_cast<size_t>(p-sp-1);
1052 yyextra->code->codify(DString(sp,l));
1053 nextCodeLine(yyscanner);
1054 }
1055 else
1056 {
1057 yyextra->code->codify(sp);
1058 done=true;
1059 }
1060 }
1061}
1062
1063/*! writes a link to a fragment \a text that may span multiple lines, inserting
1064 * line numbers for each line. If \a text contains newlines, the link will be
1065 * split into multiple links with the same destination, one for each line.
1066 */
1068 Definition *d,const DString &text)
1069{
1070 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1071 bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
1072 yyextra->tooltipManager.addTooltip(d);
1073 DString ref = d->getReference();
1074 DString file = d->getOutputFileBase();
1075 DString anchor = d->anchor();
1076 DString tooltip;
1077 if (!sourceTooltips) // fall back to simple "title" tooltips
1078 {
1079 tooltip = d->briefDescriptionAsTooltip();
1080 }
1081 bool done=false;
1082 const char *p=text.data();
1083 while (!done)
1084 {
1085 const char *sp=p;
1086 char c = 0;
1087 while ((c=*p++) && c!='\n') { }
1088 if (c=='\n')
1089 {
1090 yyextra->yyLineNr++;
1091 //printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
1092 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,DString(sp,p-sp-1),tooltip);
1093 nextCodeLine(yyscanner);
1094 }
1095 else
1096 {
1097 //printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
1098 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,sp,tooltip);
1099 done=true;
1100 }
1101 }
1102}
1103//-------------------------------------------------------------------------------
1104/**
1105 searches for definition of a module (Namespace)
1106 @param mname the name of the module
1107 @param cd the entry, if found or null
1108 @returns true, if module is found
1109*/
1110static bool getFortranNamespaceDefs(const DString &mname,
1111 NamespaceDef *&cd)
1112{
1113 if (mname.empty()) return false; /* empty name => nothing to link */
1114
1115 // search for module
1116 if ((cd=Doxygen::namespaceLinkedMap->find(mname))) return true;
1117
1118 return false;
1119}
1120//-------------------------------------------------------------------------------
1121/**
1122 searches for definition of a type
1123 @param tname the name of the type
1124 @param moduleName name of enclosing module or null, if global entry
1125 @param cd the entry, if found or null
1126 @param useMap map of data of USE-statement
1127 @returns true, if type is found
1128*/
1129static bool getFortranTypeDefs(const DString &tname, const DString &moduleName,
1130 ClassDef *&cd, const UseMap &useMap)
1131{
1132 if (tname.empty()) return false; /* empty name => nothing to link */
1133
1134 //cout << "=== search for type: " << tname << endl;
1135
1136 // search for type
1137 if ((cd=Doxygen::classLinkedMap->find(tname)))
1138 {
1139 //cout << "=== type found in global module" << endl;
1140 return true;
1141 }
1142 else if (!moduleName.empty() && (cd=Doxygen::classLinkedMap->find(moduleName+"::"+tname)))
1143 {
1144 //cout << "=== type found in local module" << endl;
1145 return true;
1146 }
1147 else
1148 {
1149 for (const auto &[name,useEntry] : useMap)
1150 {
1151 if ((cd=Doxygen::classLinkedMap->find(useEntry.module+"::"+tname)))
1152 {
1153 //cout << "=== type found in used module" << endl;
1154 return true;
1155 }
1156 }
1157 }
1158
1159 return false;
1160}
1161
1162/**
1163 searches for definition of function memberName
1164 @param yyscanner the scanner data to be used
1165 @param memberName the name of the function/variable
1166 @param moduleName name of enclosing module or null, if global entry
1167 @param useMap map of data of USE-statement
1168 @returns MemberDef pointer, if found, or nullptr otherwise
1169*/
1170static MemberDef *getFortranDefs(yyscan_t yyscanner,const DString &memberName, const DString &moduleName,
1171 const UseMap &useMap)
1172{
1173 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1174 MemberDef *potentialMd = nullptr;
1175 if (memberName.empty()) return nullptr; /* empty name => nothing to link */
1176
1177 // look in local variables
1178 for (auto it = yyextra->scopeStack.rbegin(); it!=yyextra->scopeStack.rend(); ++it)
1179 {
1180 const Scope &scope = *it;
1181 std::string lowMemName = memberName.lower().str();
1182 if (scope.localVars .find(lowMemName)!=std::end(scope.localVars) && // local var
1183 scope.externalVars.find(lowMemName)==std::end(scope.externalVars)) // and not external
1184 {
1185 return nullptr;
1186 }
1187 }
1188
1189 // search for function
1191 if (!mn)
1192 {
1193 mn = Doxygen::memberNameLinkedMap->find(memberName);
1194 }
1195
1196 if (mn) // name is known
1197 {
1198 // all found functions with given name
1199 for (const auto &md : *mn)
1200 {
1201 const FileDef *fd=md->getFileDef();
1202 const GroupDef *gd=md->getGroupDef();
1203 const ClassDef *cd=md->getClassDef();
1204
1205 //cout << "found link with same name: " << fd->fileName() << " " << memberName;
1206 //if (md->getNamespaceDef() != 0) cout << " in namespace " << md->getNamespaceDef()->name();cout << endl;
1207
1208 if ((gd && gd->isLinkable()) || (fd && fd->isLinkable()))
1209 {
1210 const NamespaceDef *nspace= md->getNamespaceDef();
1211
1212 if (nspace == nullptr)
1213 { // found function in global scope
1214 if (cd == nullptr)
1215 { // Skip if bound to type
1216 if (md.get()->getFileDef() == yyextra->sourceFileDef) return md.get();
1217 else if (!potentialMd) potentialMd = md.get();
1218 }
1219 }
1220 else if (moduleName == nspace->name())
1221 { // found in local scope
1222 return md.get();
1223 }
1224 else
1225 { // else search in used modules
1226 DString usedModuleName= nspace->name();
1227 auto use_it = useMap.find(usedModuleName.str());
1228 if (use_it!=useMap.end())
1229 {
1230 const UseEntry &ue = use_it->second;
1231 // check if only-list exists and if current entry exists is this list
1232 if (ue.onlyNames.empty())
1233 {
1234 //cout << " found in module " << usedModuleName << " entry " << memberName << endl;
1235 return md.get(); // whole module used
1236 }
1237 else
1238 {
1239 for ( const auto &name : ue.onlyNames)
1240 {
1241 //cout << " search in only: " << usedModuleName << ":: " << memberName << "==" << (*it)<< endl;
1242 if (memberName == name)
1243 {
1244 return md.get(); // found in ONLY-part of use list
1245 }
1246 }
1247 }
1248 }
1249 }
1250 } // if linkable
1251 } // for
1252 }
1253 return potentialMd;
1254}
1255
1256/**
1257 gets the link to a generic procedure which depends not on the name, but on the parameter list
1258 @todo implementation
1259*/
1261 const DString &,
1263{
1264 return false;
1265}
1266
1267static bool getLink(yyscan_t yyscanner,const UseMap &useMap, // dictionary with used modules
1268 const DString &memberText, // exact member text
1269 OutputCodeList &ol,
1270 const DString &text)
1271{
1272 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1273 MemberDef *md=nullptr;
1274 DString memberName= removeRedundantWhiteSpace(memberText);
1275
1276 if ((md=getFortranDefs(yyscanner,memberName, yyextra->currentModule, useMap)) && md->isLinkable())
1277 {
1278 if (md->isVariable() && (md->getLanguage()!=SrcLangExt::Fortran)) return false; // Non Fortran variables aren't handled yet,
1279 // see also linkifyText in util.cpp
1280
1282 md->getBodyDef() : md->getOuterScope();
1283 if (md->getGroupDef()) d = md->getGroupDef();
1284 if (d && d->isLinkable())
1285 {
1286 if (yyextra->currentDefinition && yyextra->currentMemberDef &&
1287 yyextra->insideBody && yyextra->collectXRefs)
1288 {
1289 addDocCrossReference(yyextra->currentMemberDef,md);
1290 }
1291 writeMultiLineCodeLink(yyscanner,ol,md,!text.empty() ? text : memberText);
1292 addToSearchIndex(yyscanner, !text.empty() ? text : memberText);
1293 return true;
1294 }
1295 }
1296 return false;
1297}
1298
1299
1300static void generateLink(yyscan_t yyscanner,OutputCodeList &ol, const DString &lname)
1301{
1302 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1303 ClassDef *cd=nullptr;
1304 NamespaceDef *nsd=nullptr;
1305 DString name = lname;
1306 name = removeRedundantWhiteSpace(name.lower());
1307
1308 // check if lowercase lname is a linkable type or interface
1309 if ( (getFortranTypeDefs(name, yyextra->currentModule, cd, yyextra->useMembers)) && cd->isLinkable() )
1310 {
1311 if ( (cd->compoundType() == ClassDef::Class) && // was Entry::INTERFACE_SEC) &&
1312 (getGenericProcedureLink(yyscanner, cd, name, ol)) )
1313 {
1314 //cout << "=== generic procedure resolved" << endl;
1315 }
1316 else
1317 { // write type or interface link
1318 writeMultiLineCodeLink(yyscanner, ol,cd,name);
1319 addToSearchIndex(yyscanner, name);
1320 }
1321 }
1322 // check for module
1323 else if ( (getFortranNamespaceDefs(name, nsd)) && nsd->isLinkable() )
1324 { // write module link
1325 writeMultiLineCodeLink(yyscanner,ol,nsd,name);
1326 addToSearchIndex(yyscanner,name);
1327 }
1328 // check for function/variable
1329 else if (getLink(yyscanner,yyextra->useMembers, name, ol, name))
1330 {
1331 //cout << "=== found link for lowercase " << lname << endl;
1332 }
1333 else
1334 {
1335 // nothing found, just write out the word
1336 //startFontClass("charliteral"); //test
1337 codifyLines(yyscanner,name);
1338 //endFontClass(yyscanner); //test
1339 addToSearchIndex(yyscanner,name);
1340 }
1341}
1342
1343/*! counts the number of lines in the input */
1344static int countLines(yyscan_t yyscanner)
1345{
1346 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1347 const char *p=yyextra->inputString;
1348 char c = 0;
1349 int count=1;
1350 while ((c=*p))
1351 {
1352 p++ ;
1353 if (c=='\n') count++;
1354 }
1355 if (p>yyextra->inputString && *(p-1)!='\n')
1356 { // last line does not end with a \n, so we add an extra
1357 // line and explicitly terminate the line after parsing.
1358 count++;
1359 }
1360 return count;
1361}
1362
1363//----------------------------------------------------------------------------
1364/** start scope */
1365static void startScope(yyscan_t yyscanner)
1366{
1367 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1368 DBG_CTX((stderr, "===> startScope %s",yytext));
1369 yyextra->scopeStack.emplace_back();
1370}
1371
1372/** end scope */
1373static void endScope(yyscan_t yyscanner)
1374{
1375 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1376 DBG_CTX((stderr,"===> endScope %s",yytext));
1377 if (yyextra->scopeStack.empty())
1378 {
1379 DBG_CTX((stderr,"WARNING: fortrancode.l: stack empty!\n"));
1380 return;
1381 }
1382
1383 Scope &scope = yyextra->scopeStack.back();
1384 for ( const auto &name : scope.useNames)
1385 {
1386 yyextra->useMembers.erase(name.str());
1387 }
1388 yyextra->scopeStack.pop_back();
1389}
1390
1391static void addUse(yyscan_t yyscanner,const DString &moduleName)
1392{
1393 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1394 if (!yyextra->scopeStack.empty())
1395 yyextra->scopeStack.back().useNames.push_back(moduleName);
1396}
1397
1398static void addLocalVar(yyscan_t yyscanner,const DString &varName)
1399{
1400 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1401 if (!yyextra->scopeStack.empty())
1402 {
1403 std::string lowVarName = varName.lower().str();
1404 yyextra->scopeStack.back().localVars.insert(lowVarName);
1405 if (yyextra->isExternal) yyextra->scopeStack.back().externalVars.insert(lowVarName);
1406 }
1407}
1408
1409/*===================================================================*/
1410
1411
1412static void checkContLines(yyscan_t yyscanner,const char *s)
1413{
1414 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1415 int numLines = 0;
1416 int i = 0;
1417 const char *p = s;
1418
1419 numLines = 2; // one for element 0, one in case no \n at end
1420 while (*p)
1421 {
1422 if (*p == '\n') numLines++;
1423 p++;
1424 }
1425
1426 yyextra->hasContLine = (int *) malloc((numLines) * sizeof(int));
1427 for (i = 0; i < numLines; i++)
1428 {
1429 yyextra->hasContLine[i] = 0;
1430 }
1431 p = prepassFixedForm(s, yyextra->hasContLine,yyextra->fixedCommentAfter);
1432 yyextra->hasContLine[0] = 0;
1433}
1434
1435void parseFortranCode(OutputCodeList &,const char *,const DString &,
1436 bool , const char *,const FileDef *,
1437 int ,int ,bool ,
1438 const MemberDef *,bool,const Definition *,
1439 bool , FortranFormat )
1440{
1441 //printf("***parseCode() exBlock=%d exName=%s fd=%p\n",exBlock,exName,fd);
1442
1443 return;
1444}
1445
1446//---------------------------------------------------------
1447
1454
1456{
1457 p->format = format;
1458 fortrancodeYYlex_init_extra(&p->state,&p->yyscanner);
1459#ifdef FLEX_DEBUG
1460 fortrancodeYYset_debug(Debug::isFlagSet(Debug::Lex_fortrancode)?1:0,p->yyscanner);
1461#endif
1463}
1464
1466{
1467 fortrancodeYYlex_destroy(p->yyscanner);
1468}
1469
1471{
1472 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
1473 yyextra->currentDefinition = nullptr;
1474 yyextra->currentMemberDef = nullptr;
1475 yyextra->currentFontClass = nullptr;
1476 yyextra->insideCodeLine = false;
1477 BEGIN( Start );
1478}
1479
1481 const DString & /* scopeName */,
1482 const DString & input,
1483 SrcLangExt /*lang*/,
1484 bool stripCodeComments,
1485 const CodeParserOptions &options
1486 )
1487{
1488 yyscan_t yyscanner = p->yyscanner;
1489 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
1490 if (input.empty()) return;
1491 DebugLex debugLex(Debug::Lex_fortrancode, __FILE__, options.fileDef() ? qPrint(options.fileDef()->fileName()): nullptr);
1492 codeOutIntf.stripCodeComments(stripCodeComments);
1493 yyextra->code = &codeOutIntf;
1494 yyextra->inputString = input.data();
1495 yyextra->inputPosition = 0;
1496 yyextra->fileName = options.fileDef() ? options.fileDef()->fileName():"";
1497 yyextra->isFixedForm = recognizeFixedForm(input,p->format);
1498 yyextra->contLineNr = 1;
1499 yyextra->hasContLine = nullptr;
1500 if (yyextra->isFixedForm)
1501 {
1502 checkContLines(yyscanner,yyextra->inputString);
1503 yyextra->fixedCommentAfter = Config_getInt(FORTRAN_COMMENT_AFTER);
1504 }
1505 yyextra->currentFontClass = nullptr;
1506 yyextra->insideCodeLine = false;
1507 yyextra->searchCtx = options.searchCtx();
1508 yyextra->collectXRefs = options.collectXRefs();
1509 yyextra->yyLineNr = options.startLine()!=-1 ? options.startLine() : 1;
1510 yyextra->inputLines = options.endLine()!=-1 ? options.endLine()+1 : yyextra->yyLineNr + countLines(yyscanner) - 1;
1511 yyextra->exampleBlock = options.isExample();
1512 yyextra->exampleName = options.exampleName();
1513 yyextra->sourceFileDef = options.fileDef();
1514 yyextra->lineNumbers = options.fileDef() && options.showLineNumbers();
1515 yyextra->foldStack.clear();
1516 yyextra->insideSpecialComment = false;
1517 if (options.isExample() && options.fileDef()==nullptr)
1518 {
1519 // create a dummy filedef for the example
1520 yyextra->exampleFileDef = createFileDef(DString(),options.exampleName());
1521 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
1522 }
1523 if (yyextra->sourceFileDef)
1524 {
1525 setCurrentDoc(yyscanner,DString("l00001"));
1526 }
1527 yyextra->currentDefinition = nullptr;
1528 yyextra->currentMemberDef = nullptr;
1529 if (!yyextra->exampleName.empty())
1530 {
1531 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example");
1532 }
1533 yyextra->includeCodeFragment = options.inlineFragment();
1534 startCodeLine(yyscanner);
1535 fortrancodeYYrestart(nullptr, yyscanner);
1536 BEGIN( Start );
1537 fortrancodeYYlex(yyscanner);
1538 if (yyextra->insideCodeLine)
1539 {
1540 endCodeLine(yyscanner);
1541 }
1542 if (Config_getBool(HTML_CODE_FOLDING))
1543 {
1544 while (!yyextra->foldStack.empty())
1545 {
1546 yyextra->code->endFold();
1547 yyextra->foldStack.pop_back();
1548 }
1549 }
1550 if (yyextra->exampleFileDef)
1551 {
1552 // delete the temporary file definition used for this example
1553 yyextra->exampleFileDef.reset();
1554 yyextra->sourceFileDef=nullptr;
1555 }
1556 if (yyextra->hasContLine) free(yyextra->hasContLine);
1557 yyextra->hasContLine = nullptr;
1558
1559 // write the tooltips
1560 yyextra->tooltipManager.writeTooltips(codeOutIntf);
1561}
1562
1563static inline void pop_state(yyscan_t yyscanner)
1564{
1565 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1566 if ( yyg->yy_start_stack_ptr <= 0 )
1567 warn(yyextra->fileName,yyextra->yyLineNr,"Unexpected statement '{}'",yytext );
1568 else
1569 yy_pop_state(yyscanner);
1570}
1571//---------------------------------------------------------
1572
1573#include "fortrancode.l.h"
virtual CompoundType compoundType() const =0
Returns the type of compound this is, i.e. class/struct/union/...
DString lower() const
Definition dstring.h:326
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
const std::string & str() const
Definition dstring.h:645
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
@ Lex_fortrancode
Definition debug.h:62
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
virtual int getEndBodyLine() const =0
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual bool isLinkable() const =0
virtual const DString & name() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual const FileDef * getBodyDef() const =0
virtual bool isLinkableInProject() const =0
virtual DString anchor() const =0
virtual int getStartDefLine() const =0
virtual DString getReference() const =0
virtual CodeSymbolType codeSymbolType() const =0
virtual Definition * getOuterScope() const =0
virtual DString getOutputFileBase() const =0
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:88
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
static SearchIndexIntf searchIndex
Definition doxygen.h:117
virtual DString fileName() const =0
void parseCode(OutputCodeList &codeOutIntf, const DString &scopeName, const DString &input, SrcLangExt lang, bool stripCodeComments, const CodeParserOptions &options) override
Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.
void resetCodeParserState() override
Resets the state of the code parser.
FortranCodeParser(FortranFormat format=FortranFormat::Unknown)
std::unique_ptr< Private > p
Definition fortrancode.h:39
~FortranCodeParser() override
A model of a group of symbols.
Definition groupdef.h:48
const T * find(const std::string &key) const
Definition linkedmap.h:47
virtual GroupDef * getGroupDef()=0
virtual bool isVariable() const =0
void writeCodeLink(CodeSymbolType type, const DString &ref, const DString &file, const DString &anchor, const DString &name, const DString &tooltip)
Definition outputlist.h:247
void stripCodeComments(bool b)
Definition outputlist.h:235
void addWord(const DString &word, bool hiPriority)
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
#define Config_getInt(name)
Definition config.h:34
#define Config_getBool(name)
Definition config.h:33
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:50
const char * qPrint(const char *s)
Definition dstring.h:783
std::unique_ptr< FileDef > createFileDef(const DString &p, const DString &n, const DString &ref, const DString &dn)
Definition filedef.cpp:270
void parseFortranCode(OutputCodeList &, const char *, const DString &, bool, const char *, const FileDef *, int, int, bool, const MemberDef *, bool, const Definition *, bool, FortranFormat)
static void checkContLines(yyscan_t yyscanner, const char *s)
static void codeFolding(yyscan_t yyscanner, const Definition *d)
const char * prepassFixedForm(const char *contents, int *hasContLine, int fixedCommentAfter)
bool recognizeFixedForm(const DString &contents, FortranFormat format)
void addDocCrossReference(const MemberDef *s, const MemberDef *d)
#define warn(file, line, fmt,...)
Definition message.h:97
Definition dstring.h:913
Options to configure the code parser.
Definition parserintf.h:77
bool isExample() const
Definition parserintf.h:80
const Definition * searchCtx() const
Definition parserintf.h:88
DString exampleName() const
Definition parserintf.h:81
const FileDef * fileDef() const
Definition parserintf.h:82
int endLine() const
Definition parserintf.h:84
bool showLineNumbers() const
Definition parserintf.h:87
bool inlineFragment() const
Definition parserintf.h:85
int startLine() const
Definition parserintf.h:83
bool collectXRefs() const
Definition parserintf.h:89
fortrancodeYY_state state
SrcLangExt
Definition types.h:207
FortranFormat
Definition types.h:614
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2995