Doxygen
Loading...
Searching...
No Matches
fortrancode.l File Reference
#include <stdint.h>
#include "fortrancode.h"
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "classlist.h"
#include "config.h"
#include "containers.h"
#include "debug.h"
#include "doxygen.h"
#include "filedef.h"
#include "fortranscanner.h"
#include "groupdef.h"
#include "membername.h"
#include "message.h"
#include "namespacedef.h"
#include "outputlist.h"
#include "tooltip.h"
#include "util.h"
#include "doxygen_lex.h"
#include "fortrancode.l.h"
Include dependency graph for fortrancode.l:

Go to the source code of this file.

Classes

class  UseEntry
 data of an use-statement More...
class  UseMap
 module name -> list of ONLY/remote entries (module name = name of the module, which can be accessed via use-directive) More...
class  Scope
 Contains names of used modules and names of local variables. More...
struct  fortrancodeYY_state
struct  FortranCodeParser::Private

Macros

#define YY_TYPEDEF_YY_SCANNER_T
#define yyguts_t   fortrancodeYYguts_t
#define DBG_CTX(x)
#define YY_NO_TOP_STATE   1
#define YY_NO_INPUT   1
#define YY_NO_UNISTD_H   1
#define YY_USER_ACTION   {yy_old_start = yy_my_start; yy_my_start = yy_end; yy_end += static_cast<int>(yyleng);}
#define YY_FTN_RESET   {yy_old_start = 0; yy_my_start = 0; yy_end = 1;}
#define YY_FTN_REJECT   {yy_end = yy_my_start; yy_my_start = yy_old_start; REJECT;}
#define YY_INPUT(buf, result, max_size)

Typedefs

typedef yyguts_t * yyscan_t

Functions

static const char * stateToString (int state)
static bool getFortranNamespaceDefs (const DString &mname, NamespaceDef *&cd)
 searches for definition of a module (Namespace)
static bool getFortranTypeDefs (const DString &tname, const DString &moduleName, ClassDef *&cd, const UseMap &useMap)
 searches for definition of a type
static void startFontClass (yyscan_t yyscanner, const char *s, bool specialComment=false)
static void endFontClass (yyscan_t yyscanner, bool specialComment=false)
static void setCurrentDoc (yyscan_t yyscanner, const DString &anchor)
static void addToSearchIndex (yyscan_t yyscanner, const DString &text)
static void startCodeLine (yyscan_t yyscanner)
static void endCodeLine (yyscan_t yyscanner)
static void nextCodeLine (yyscan_t yyscanner)
static void codifyLines (yyscan_t yyscanner, const DString &text)
static void writeMultiLineCodeLink (yyscan_t yyscanner, OutputCodeList &ol, Definition *d, const DString &text)
static bool getGenericProcedureLink (yyscan_t,const ClassDef *, const DString &, OutputCodeList &)
 gets the link to a generic procedure which depends not on the name, but on the parameter list
static bool getLink (yyscan_t yyscanner, const UseMap &useMap, const DString &memberText, OutputCodeList &ol, const DString &text)
static void generateLink (yyscan_t yyscanner, OutputCodeList &ol, const DString &lname)
static int countLines (yyscan_t yyscanner)
static void startScope (yyscan_t yyscanner)
 start scope
static void endScope (yyscan_t yyscanner)
 end scope
static void addUse (yyscan_t yyscanner, const DString &moduleName)
static void addLocalVar (yyscan_t yyscanner, const DString &varName)
static MemberDef * getFortranDefs (yyscan_t yyscanner, const DString &memberName, const DString &moduleName, const UseMap &useMap)
 searches for definition of function memberName
static int yyread (yyscan_t yyscanner, char *buf, int max_size)
static void pop_state (yyscan_t yyscanner)
static const char * getLexerFILE ()
int yylex (yyscan_t yyscanner)
static void codeFolding (yyscan_t yyscanner, const Definition *d)
static void checkContLines (yyscan_t yyscanner, const char *s)
void parseFortranCode (OutputCodeList &, const char *, const DString &, bool, const char *, const FileDef *, int, int, bool, const MemberDef *, bool, const Definition *, bool, FortranFormat)

Variables

int yy_old_start = 0
int yy_my_start = 0
int yy_end = 1

Macro Definition Documentation

◆ DBG_CTX

#define DBG_CTX ( x)
Value:
do { } while(0)

Definition at line 72 of file fortrancode.l.

◆ YY_FTN_REJECT

#define YY_FTN_REJECT   {yy_end = yy_my_start; yy_my_start = yy_old_start; REJECT;}

Definition at line 90 of file fortrancode.l.

◆ YY_FTN_RESET

#define YY_FTN_RESET   {yy_old_start = 0; yy_my_start = 0; yy_end = 1;}

Definition at line 89 of file fortrancode.l.

◆ YY_INPUT

#define YY_INPUT ( buf,
result,
max_size )
Value:
result=yyread(yyscanner,buf,max_size);
static int yyread(yyscan_t yyscanner, char *buf, int max_size)

Definition at line 221 of file fortrancode.l.

◆ YY_NO_INPUT

#define YY_NO_INPUT   1

Definition at line 75 of file fortrancode.l.

◆ YY_NO_TOP_STATE

#define YY_NO_TOP_STATE   1

Definition at line 74 of file fortrancode.l.

◆ YY_NO_UNISTD_H

#define YY_NO_UNISTD_H   1

Definition at line 76 of file fortrancode.l.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T
Todo
  • continuation lines not always recognized
  • merging of use-statements with same module name and different only-names
  • rename part of use-statement
  • links to interface functions
  • references to variables

Definition at line 37 of file fortrancode.l.

◆ YY_USER_ACTION

#define YY_USER_ACTION   {yy_old_start = yy_my_start; yy_my_start = yy_end; yy_end += static_cast<int>(yyleng);}

Definition at line 88 of file fortrancode.l.

◆ yyguts_t

#define yyguts_t   fortrancodeYYguts_t

Definition at line 38 of file fortrancode.l.

Typedef Documentation

◆ yyscan_t

typedef yyguts_t* yyscan_t

Definition at line 40 of file fortrancode.l.

Function Documentation

◆ addLocalVar()

void addLocalVar ( yyscan_t yyscanner,
const DString & varName )
static

Definition at line 1398 of file fortrancode.l.

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 }
DString lower() const
Definition dstring.h:326
const std::string & str() const
Definition dstring.h:645
#define yyguts_t
Definition code.l:23
1407}

References DString::lower(), DString::str(), and yyguts_t.

◆ addToSearchIndex()

void addToSearchIndex ( yyscan_t yyscanner,
const DString & text )
static

Definition at line 902 of file fortrancode.l.

903{
904 if (Doxygen::searchIndex.enabled())
905 {
906 Doxygen::searchIndex.addWord(text,false);
907 }
static SearchIndexIntf searchIndex
Definition doxygen.h:117
void addWord(const DString &word, bool hiPriority)
908}

References SearchIndexIntf::addWord(), and Doxygen::searchIndex.

Referenced by generateLink(), and getLink().

◆ addUse()

void addUse ( yyscan_t yyscanner,
const DString & moduleName )
static

Definition at line 1391 of file fortrancode.l.

1392{
1393 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1394 if (!yyextra->scopeStack.empty())
1395 yyextra->scopeStack.back().useNames.push_back(moduleName);
1396}

References yyguts_t.

◆ checkContLines()

void checkContLines ( yyscan_t yyscanner,
const char * s )
static

Definition at line 1412 of file fortrancode.l.

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;
const char * prepassFixedForm(const char *contents, int *hasContLine, int fixedCommentAfter)
1433}

References prepassFixedForm(), and yyguts_t.

Referenced by FortranCodeParser::parseCode().

◆ codeFolding()

void codeFolding ( yyscan_t yyscanner,
const Definition * d )
static

Definition at line 910 of file fortrancode.l.

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 }
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual int getEndBodyLine() const =0
virtual int getStartDefLine() const =0
#define Config_getBool(name)
Definition config.h:33
949}

References Config_getBool, Definition::getEndBodyLine(), Definition::getStartDefLine(), and yyguts_t.

Referenced by startCodeLine().

◆ codifyLines()

void codifyLines ( yyscan_t yyscanner,
const DString & text )
static

write a code fragment 'text' that may span multiple lines, inserting line numbers for each line.

Definition at line 1036 of file fortrancode.l.

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 }
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
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
static void nextCodeLine(yyscan_t yyscanner)
1061}

References DString::data(), DString::empty(), nextCodeLine(), and yyguts_t.

Referenced by generateLink().

◆ countLines()

int countLines ( yyscan_t yyscanner)
static

counts the number of lines in the input

Definition at line 1344 of file fortrancode.l.

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}

References yyguts_t.

Referenced by FortranCodeParser::parseCode().

◆ endCodeLine()

void endCodeLine ( yyscan_t yyscanner)
static

Definition at line 1013 of file fortrancode.l.

1014{
1015 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1016 endFontClass(yyscanner);
1017 yyextra->code->endCodeLine();
1018 yyextra->insideCodeLine=false;
static void endFontClass(yyscan_t yyscanner, bool specialComment=false)
1019}

References endFontClass(), and yyguts_t.

Referenced by nextCodeLine(), and FortranCodeParser::parseCode().

◆ endFontClass()

void endFontClass ( yyscan_t yyscanner,
bool specialComment = false )
static

Definition at line 854 of file fortrancode.l.

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}

References yyguts_t.

Referenced by endCodeLine(), and startFontClass().

◆ endScope()

void endScope ( yyscan_t yyscanner)
static

end scope

Definition at line 1373 of file fortrancode.l.

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 }
#define DBG_CTX(x)
Definition fortrancode.l:72
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();
Contains names of used modules and names of local variables.
std::vector< DString > useNames
contains names of used modules
const char * name(int level)
Definition latexgen.h:368
1389}

References DBG_CTX, Scope::useNames, and yyguts_t.

◆ generateLink()

void generateLink ( yyscan_t yyscanner,
OutputCodeList & ol,
const DString & lname )
static

Definition at line 1300 of file fortrancode.l.

1301{
1302 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1303 ClassDef *cd=nullptr;
1304 NamespaceDef *nsd=nullptr;
1305 DString name = lname;
A abstract class representing of a compound symbol.
Definition classdef.h:100
An abstract interface of a namespace symbol.
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
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 }
virtual CompoundType compoundType() const =0
Returns the type of compound this is, i.e. class/struct/union/...
virtual bool isLinkable() const =0
static void writeMultiLineCodeLink(yyscan_t yyscanner, OutputCodeList &ol, Definition *d, const DString &text)
static bool getLink(yyscan_t yyscanner, const UseMap &useMap, const DString &memberText, OutputCodeList &ol, const DString &text)
static bool getFortranNamespaceDefs(const DString &mname, NamespaceDef *&cd)
searches for definition of a module (Namespace)
static bool getFortranTypeDefs(const DString &tname, const DString &moduleName, ClassDef *&cd, const UseMap &useMap)
searches for definition of a type
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)
1341}

References addToSearchIndex(), ClassDef::Class, codifyLines(), ClassDef::compoundType(), getFortranNamespaceDefs(), getFortranTypeDefs(), getGenericProcedureLink(), getLink(), Definition::isLinkable(), removeRedundantWhiteSpace(), writeMultiLineCodeLink(), and yyguts_t.

◆ getFortranDefs()

MemberDef * getFortranDefs ( yyscan_t yyscanner,
const DString & memberName,
const DString & moduleName,
const UseMap & useMap )
static

searches for definition of function memberName

Parameters
yyscannerthe scanner data to be used
memberNamethe name of the function/variable
moduleNamename of enclosing module or null, if global entry
useMapmap of data of USE-statement
Returns
MemberDef pointer, if found, or nullptr otherwise

Definition at line 1170 of file fortrancode.l.

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 */
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
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 }
StringUnorderedSet externalVars
contains names of external entities
StringUnorderedSet localVars
contains names of local variables
1188
1189 // search for function
1191 if (!mn)
1192 {
1193 mn = Doxygen::memberNameLinkedMap->find(memberName);
1194 }
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
const T * find(const std::string &key) const
Definition linkedmap.h:47
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();
A model of a file symbol.
Definition filedef.h:97
A model of a group of symbols.
Definition groupdef.h:48
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;
virtual const DString & name() const =0
data of an use-statement
Definition fortrancode.l:98
std::vector< DString > onlyNames
1254}

References DString::empty(), Scope::externalVars, LinkedMap< T, Hash, KeyEqual, Map >::find(), Doxygen::functionNameLinkedMap, Definition::isLinkable(), Scope::localVars, DString::lower(), Doxygen::memberNameLinkedMap, Definition::name(), UseEntry::onlyNames, DString::str(), and yyguts_t.

Referenced by getLink().

◆ getFortranNamespaceDefs()

bool getFortranNamespaceDefs ( const DString & mname,
NamespaceDef *& cd )
static

searches for definition of a module (Namespace)

Parameters
mnamethe name of the module
cdthe entry, if found or null
Returns
true, if module is found

Definition at line 1110 of file fortrancode.l.

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;
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
1117
1118 return false;
1119}

References DString::empty(), and Doxygen::namespaceLinkedMap.

Referenced by generateLink().

◆ getFortranTypeDefs()

bool getFortranTypeDefs ( const DString & tname,
const DString & moduleName,
ClassDef *& cd,
const UseMap & useMap )
static

searches for definition of a type

Parameters
tnamethe name of the type
moduleNamename of enclosing module or null, if global entry
cdthe entry, if found or null
useMapmap of data of USE-statement
Returns
true, if type is found

Definition at line 1129 of file fortrancode.l.

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 }
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:88
1158
1159 return false;
1160}

References Doxygen::classLinkedMap, DString::empty(), and LinkedMap< T, Hash, KeyEqual, Map >::find().

Referenced by generateLink().

◆ getGenericProcedureLink()

bool getGenericProcedureLink ( yyscan_t ,
const ClassDef * ,
const DString & ,
OutputCodeList &  )
static

gets the link to a generic procedure which depends not on the name, but on the parameter list

Todo
implementation

Definition at line 1260 of file fortrancode.l.

1263{
1264 return false;
1265}

Referenced by generateLink().

◆ getLexerFILE()

const char * getLexerFILE ( )
inlinestatic

Definition at line 224 of file fortrancode.l.

224{return __FILE__;}

◆ getLink()

bool getLink ( yyscan_t yyscanner,
const UseMap & useMap,
const DString & memberText,
OutputCodeList & ol,
const DString & text )
static

Definition at line 1267 of file fortrancode.l.

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
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual bool isVariable() const =0
static MemberDef * getFortranDefs(yyscan_t yyscanner, const DString &memberName, const DString &moduleName, const UseMap &useMap)
searches for definition of function memberName
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;
virtual const FileDef * getBodyDef() const =0
virtual Definition * getOuterScope() const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
virtual GroupDef * getGroupDef()=0
void addDocCrossReference(const MemberDef *s, const MemberDef *d)
1297}

References addDocCrossReference(), addToSearchIndex(), DString::empty(), Definition::getBodyDef(), getFortranDefs(), MemberDef::getGroupDef(), Definition::getLanguage(), Definition::getOuterScope(), Doxygen::globalScope, Definition::isLinkable(), MemberDef::isVariable(), removeRedundantWhiteSpace(), writeMultiLineCodeLink(), and yyguts_t.

Referenced by generateLink().

◆ nextCodeLine()

void nextCodeLine ( yyscan_t yyscanner)
static

Definition at line 1021 of file fortrancode.l.

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 }
static void endCodeLine(yyscan_t yyscanner)
static void startCodeLine(yyscan_t yyscanner)
1031}

References endCodeLine(), startCodeLine(), and yyguts_t.

Referenced by codifyLines(), and writeMultiLineCodeLink().

◆ parseFortranCode()

void parseFortranCode ( OutputCodeList & ,
const char * ,
const DString & ,
bool ,
const char * ,
const FileDef * ,
int ,
int ,
bool ,
const MemberDef * ,
bool ,
const Definition * ,
bool ,
FortranFormat  )

Definition at line 1435 of file fortrancode.l.

1440{
1441 //printf("***parseCode() exBlock=%d exName=%s fd=%p\n",exBlock,exName,fd);
1442
1443 return;
1444}

◆ pop_state()

void pop_state ( yyscan_t yyscanner)
inlinestatic

Definition at line 1563 of file fortrancode.l.

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);
#define warn(file, line, fmt,...)
Definition message.h:97
1570}

References warn, and yyguts_t.

◆ setCurrentDoc()

void setCurrentDoc ( yyscan_t yyscanner,
const DString & anchor )
static

Definition at line 886 of file fortrancode.l.

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 }
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
900}

References Doxygen::searchIndex, SearchIndexIntf::setCurrentDoc(), and yyguts_t.

Referenced by FortranCodeParser::parseCode(), and startCodeLine().

◆ startCodeLine()

void startCodeLine ( yyscan_t yyscanner)
static

start a new line of code, inserting a line number if yyextra->sourceFileDef is true. If a definition starts at the current line, then the line number is linked to the documentation of that definition.

Definition at line 955 of file fortrancode.l.

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 }
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
virtual bool isLinkableInProject() const =0
virtual DString getReference() const =0
virtual DString getOutputFileBase() const =0
static void setCurrentDoc(yyscan_t yyscanner, const DString &anchor)
static void codeFolding(yyscan_t yyscanner, const Definition *d)
1010}

References codeFolding(), Definition::getOutputFileBase(), Definition::getReference(), Definition::isLinkableInProject(), setCurrentDoc(), DString::sprintf(), and yyguts_t.

Referenced by nextCodeLine(), and FortranCodeParser::parseCode().

◆ startFontClass()

void startFontClass ( yyscan_t yyscanner,
const char * s,
bool specialComment = false )
static

Definition at line 869 of file fortrancode.l.

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 }
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:50
884}

References dstrcmp(), endFontClass(), and yyguts_t.

◆ startScope()

void startScope ( yyscan_t yyscanner)
static

start scope

Definition at line 1365 of file fortrancode.l.

1366{
1367 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1368 DBG_CTX((stderr, "===> startScope %s",yytext));
1369 yyextra->scopeStack.emplace_back();
1370}

References DBG_CTX, and yyguts_t.

◆ stateToString()

const char * stateToString ( int state)
static

◆ writeMultiLineCodeLink()

void writeMultiLineCodeLink ( yyscan_t yyscanner,
OutputCodeList & ol,
Definition * d,
const DString & text )
static

writes a link to a fragment text that may span multiple lines, inserting line numbers for each line. If text contains newlines, the link will be split into multiple links with the same destination, one for each line.

Definition at line 1067 of file fortrancode.l.

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 }
virtual DString briefDescriptionAsTooltip() const =0
virtual DString anchor() const =0
virtual CodeSymbolType codeSymbolType() 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
1102}

References Definition::anchor(), Definition::briefDescriptionAsTooltip(), Definition::codeSymbolType(), Config_getBool, DString::data(), Definition::getOutputFileBase(), Definition::getReference(), nextCodeLine(), OutputCodeList::writeCodeLink(), and yyguts_t.

Referenced by generateLink(), and getLink().

◆ yylex()

int yylex ( yyscan_t yyscanner)

Definition at line 278 of file fortrancode.l.

283 {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 }
static void startFontClass(yyscan_t yyscanner, const char *s, bool specialComment=false)
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
int yy_my_start
Definition fortrancode.l:86
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;
static void generateLink(yyscan_t yyscanner, OutputCodeList &ol, const DString &lname)
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 }
static void addUse(yyscan_t yyscanner, const DString &moduleName)
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 }
static void pop_state(yyscan_t yyscanner)
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
static void startScope(yyscan_t yyscanner)
start scope
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 }
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 }
static void endScope(yyscan_t yyscanner)
end scope
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 }
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 }
static void addLocalVar(yyscan_t yyscanner, const DString &varName)
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 }
int yy_old_start
Definition fortrancode.l:85
int yy_end
Definition fortrancode.l:87
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%%

◆ yyread()

int yyread ( yyscan_t yyscanner,
char * buf,
int max_size )
static

Definition at line 839 of file fortrancode.l.

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}

References yyguts_t.

Variable Documentation

◆ yy_end

int yy_end = 1

Definition at line 87 of file fortrancode.l.

◆ yy_my_start

int yy_my_start = 0

Definition at line 86 of file fortrancode.l.

◆ yy_old_start

int yy_old_start = 0

Definition at line 85 of file fortrancode.l.