diff options
Diffstat (limited to 'src/fortrancode.l')
-rw-r--r-- | src/fortrancode.l | 193 |
1 files changed, 97 insertions, 96 deletions
diff --git a/src/fortrancode.l b/src/fortrancode.l index 81bf9f6..d7b006f 100644 --- a/src/fortrancode.l +++ b/src/fortrancode.l @@ -6,8 +6,8 @@ * based on the work of Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -20,7 +20,7 @@ @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 + - links to interface functions - references to variables **/ %option never-interactive @@ -84,15 +84,15 @@ int yy_end = 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;} - + //-------------------------------------------------------------------------------- /** data of an use-statement */ -class UseEntry +class UseEntry { - public: + public: QCString module; // just for debug QCStringList onlyNames; /* entries of the ONLY-part */ }; @@ -101,7 +101,7 @@ class UseEntry module name -> list of ONLY/remote entries (module name = name of the module, which can be accessed via use-directive) */ -class UseSDict : public SDict<UseEntry> +class UseSDict : public SDict<UseEntry> { public: UseSDict() : SDict<UseEntry>(17) {} @@ -110,7 +110,7 @@ class UseSDict : public SDict<UseEntry> /** Contains names of used modules and names of local variables. */ -class Scope +class Scope { public: QCStringList useNames; //!< contains names of used modules @@ -121,10 +121,10 @@ class Scope }; /*===================================================================*/ -/* +/* * statics */ - + static QCString docBlock; //!< contents of all lines of a documentation block static QCString currentModule=0; //!< name of the current enclosing module static QCString currentClass=0; //!< name of the current enclosing class @@ -142,7 +142,7 @@ static QCString g_parmType; static QCString g_parmName; static const char * g_inputString; //!< the code fragment as text -static int g_inputPosition; //!< read offset during parsing +static int g_inputPosition; //!< read offset during parsing static int g_inputLines; //!< number of line in the code fragment static int g_yyLineNr; //!< current line number static int g_contLineNr; //!< current, local, line number for continuation determination @@ -233,7 +233,7 @@ static void startCodeLine() //QCString lineNumber,lineAnchor; //lineNumber.sprintf("%05d",g_yyLineNr); //lineAnchor.sprintf("l%05d",g_yyLineNr); - + Definition *d = g_sourceFileDef->getSourceDefinition(g_yyLineNr); //printf("startCodeLine %d d=%s\n", g_yyLineNr,d ? d->name().data() : "<null>"); if (!g_includeCodeFragment && d) @@ -266,7 +266,7 @@ static void startCodeLine() g_code->writeLineNumber(0,0,0,g_yyLineNr); } } - g_code->startCodeLine(g_sourceFileDef); + g_code->startCodeLine(g_sourceFileDef); if (g_currentFontClass) { g_code->startFontClass(g_currentFontClass); @@ -301,7 +301,7 @@ static void codifyLines(char *text) *(p-1)='\0'; g_code->codify(sp); endCodeLine(); - if (g_yyLineNr<g_inputLines) + if (g_yyLineNr<g_inputLines) { startCodeLine(); } @@ -327,7 +327,7 @@ static void codifyLines(QCString str) } /*! writes a link to a fragment \a text that may span multiple lines, inserting - * line numbers for each line. If \a text contains newlines, the link will be + * line numbers for each line. If \a text contains newlines, the link will be * split into multiple links with the same destination, one for each line. */ static void writeMultiLineCodeLink(CodeOutputInterface &ol, @@ -338,7 +338,7 @@ static void writeMultiLineCodeLink(CodeOutputInterface &ol, QCString ref = d->getReference(); QCString file = d->getOutputFileBase(); QCString anchor = d->anchor(); - QCString tooltip; + QCString tooltip; if (!sourceTooltips) // fall back to simple "title" tooltips { tooltip = d->briefDescriptionAsTooltip(); @@ -357,7 +357,7 @@ static void writeMultiLineCodeLink(CodeOutputInterface &ol, //printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp); ol.writeCodeLink(ref,file,anchor,sp,tooltip); endCodeLine(); - if (g_yyLineNr<g_inputLines) + if (g_yyLineNr<g_inputLines) { startCodeLine(); } @@ -394,27 +394,27 @@ static bool getFortranNamespaceDefs(const QCString &mname, @param moduleName name of enclosing module or null, if global entry @param cd the entry, if found or null @param usedict dictionary of data of USE-statement - @returns true, if type is found + @returns true, if type is found */ -static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName, +static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName, ClassDef *&cd, UseSDict *usedict=0) { if (tname.isEmpty()) return FALSE; /* empty name => nothing to link */ //cout << "=== search for type: " << tname << endl; - // search for type - if ((cd=Doxygen::classSDict->find(tname))) + // search for type + if ((cd=Doxygen::classSDict->find(tname))) { //cout << "=== type found in global module" << endl; return TRUE; } - else if (moduleName && (cd= Doxygen::classSDict->find(moduleName+"::"+tname))) + else if (moduleName && (cd= Doxygen::classSDict->find(moduleName+"::"+tname))) { //cout << "=== type found in local module" << endl; return TRUE; } - else + else { UseEntry *use; for (UseSDict::Iterator di(*usedict); (use=di.current()); ++di) @@ -436,9 +436,9 @@ static bool getFortranTypeDefs(const QCString &tname, const QCString &moduleName @param moduleName name of enclosing module or null, if global entry @param md the entry, if found or null @param usedict array of data of USE-statement - @returns true, if found + @returns true, if found */ -static bool getFortranDefs(const QCString &memberName, const QCString &moduleName, +static bool getFortranDefs(const QCString &memberName, const QCString &moduleName, MemberDef *&md, UseSDict *usedict=0) { if (memberName.isEmpty()) return FALSE; /* empty name => nothing to link */ @@ -453,16 +453,16 @@ static bool getFortranDefs(const QCString &memberName, const QCString &moduleNam } // search for function - MemberName *mn = Doxygen::functionNameSDict->find(memberName); + MemberName *mn = Doxygen::functionNameLinkedMap->find(memberName); if (!mn) { - mn = Doxygen::memberNameSDict->find(memberName); + mn = Doxygen::memberNameLinkedMap->find(memberName); } if (mn) // name is known { - MemberNameIterator mli(*mn); - for (mli.toFirst();(md=mli.current());++mli) // all found functions with given name + // all found functions with given name + for (const auto &md : *mn) { const FileDef *fd=md->getFileDef(); const GroupDef *gd=md->getGroupDef(); @@ -475,25 +475,26 @@ static bool getFortranDefs(const QCString &memberName, const QCString &moduleNam { const NamespaceDef *nspace= md->getNamespaceDef(); - if (nspace == 0) + if (nspace == 0) { // found function in global scope - if(cd == 0) { // Skip if bound to type + if(cd == 0) + { // Skip if bound to type return TRUE; } } - else if (moduleName == nspace->name()) + else if (moduleName == nspace->name()) { // found in local scope return TRUE; } - else + else { // else search in used modules QCString usedModuleName= nspace->name(); UseEntry *ue= usedict->find(usedModuleName); - if (ue) + if (ue) { // check if only-list exists and if current entry exists is this list QCStringList &only= ue->onlyNames; - if (only.isEmpty()) + if (only.isEmpty()) { //cout << " found in module " << usedModuleName << " entry " << memberName << endl; return TRUE; // whole module used @@ -521,9 +522,9 @@ static bool getFortranDefs(const QCString &memberName, const QCString &moduleNam gets the link to a generic procedure which depends not on the name, but on the parameter list @todo implementation */ -static bool getGenericProcedureLink(const ClassDef *cd, - const char *memberText, - CodeOutputInterface &ol) +static bool getGenericProcedureLink(const ClassDef *cd, + const char *memberText, + CodeOutputInterface &ol) { (void)cd; (void)memberText; @@ -540,7 +541,7 @@ static bool getLink(UseSDict *usedict, // dictionary with used modules QCString memberName= removeRedundantWhiteSpace(memberText); if (getFortranDefs(memberName, currentModule, md, usedict) && md->isLinkable()) - { + { if (md->isVariable() && (md->getLanguage()!=SrcLangExt_Fortran)) return FALSE; // Non Fortran variables aren't handled yet, // see also linkifyText in util.cpp @@ -549,15 +550,15 @@ static bool getLink(UseSDict *usedict, // dictionary with used modules if (md->getGroupDef()) d = md->getGroupDef(); if (d && d->isLinkable()) { - if (g_currentDefinition && g_currentMemberDef && + if (g_currentDefinition && g_currentMemberDef && md!=g_currentMemberDef && g_insideBody && g_collectXRefs) - { - addDocCrossReference(g_currentMemberDef,md); - } + { + addDocCrossReference(g_currentMemberDef,md); + } writeMultiLineCodeLink(ol,md,text ? text : memberText); addToSearchIndex(text ? text : memberText); return TRUE; - } + } } return FALSE; } @@ -569,16 +570,16 @@ static void generateLink(CodeOutputInterface &ol, char *lname) NamespaceDef *nsd=0; QCString tmp = lname; tmp = removeRedundantWhiteSpace(tmp.lower()); - + // check if lowercase lname is a linkable type or interface if ( (getFortranTypeDefs(tmp, currentModule, cd, useMembers)) && cd->isLinkable() ) { if ( (cd->compoundType() == ClassDef::Class) && // was Entry::INTERFACE_SEC) && - (getGenericProcedureLink(cd, tmp, ol)) ) + (getGenericProcedureLink(cd, tmp, ol)) ) { - //cout << "=== generic procedure resolved" << endl; - } - else + //cout << "=== generic procedure resolved" << endl; + } + else { // write type or interface link writeMultiLineCodeLink(ol,cd,tmp); addToSearchIndex(tmp.data()); @@ -591,11 +592,11 @@ static void generateLink(CodeOutputInterface &ol, char *lname) addToSearchIndex(tmp.data()); } // check for function/variable - else if (getLink(useMembers, tmp, ol, tmp)) + else if (getLink(useMembers, tmp, ol, tmp)) { //cout << "=== found link for lowercase " << lname << endl; } - else + else { // nothing found, just write out the word //startFontClass("charliteral"); //test @@ -611,23 +612,23 @@ static int countLines() const char *p=g_inputString; char c; int count=1; - while ((c=*p)) - { - p++ ; - if (c=='\n') count++; + while ((c=*p)) + { + p++ ; + if (c=='\n') count++; } - if (p>g_inputString && *(p-1)!='\n') + if (p>g_inputString && *(p-1)!='\n') { // last line does not end with a \n, so we add an extra // line and explicitly terminate the line after parsing. - count++, - g_needsTermination=TRUE; - } + count++, + g_needsTermination=TRUE; + } return count; } //---------------------------------------------------------------------------- /** start scope */ -static void startScope() +static void startScope() { DBG_CTX((stderr, "===> startScope %s",yytext)); Scope *scope = new Scope; @@ -635,31 +636,31 @@ static void startScope() } /** end scope */ -static void endScope() +static void endScope() { DBG_CTX((stderr,"===> endScope %s",yytext)); - if (scopeStack.isEmpty()) + if (scopeStack.isEmpty()) { - DBG_CTX((stderr,"WARNING: fortrancode.l: stack empty!\n")); + DBG_CTX((stderr,"WARNING: fortrancode.l: stack empty!\n")); return; } Scope *scope = scopeStack.getLast(); scopeStack.removeLast(); - for ( QCStringList::Iterator it = scope->useNames.begin(); it != scope->useNames.end(); ++it) + for ( QCStringList::Iterator it = scope->useNames.begin(); it != scope->useNames.end(); ++it) { useMembers->remove(*it); } delete scope; } -static void addUse(const QCString &moduleName) +static void addUse(const QCString &moduleName) { if (!scopeStack.isEmpty()) scopeStack.getLast()->useNames.append(moduleName); } -static void addLocalVar(const QCString &varName) +static void addLocalVar(const QCString &varName) { if (!scopeStack.isEmpty()) { @@ -750,7 +751,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") codifyLines(yytext); } /*-------- inner construct ---------------------------------------------------*/ - + <Start>{COMMANDS}/{BS}[,( \t\n] { // highlight /* font class is defined e.g. in doxygen.css */ startFontClass("keyword"); @@ -781,8 +782,8 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") codifyLines(yytext); endFontClass(); } -<Start>"implicit"{BS}("none"|{TYPE_SPEC}) { - startFontClass("keywordtype"); +<Start>"implicit"{BS}("none"|{TYPE_SPEC}) { + startFontClass("keywordtype"); codifyLines(yytext); endFontClass(); } @@ -792,20 +793,20 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") endFontClass(); } /*-------- use statement -------------------------------------------*/ -<Start>"use"{BS_} { - startFontClass("keywordtype"); +<Start>"use"{BS_} { + startFontClass("keywordtype"); codifyLines(yytext); endFontClass(); yy_push_state(YY_START); - BEGIN(Use); + BEGIN(Use); } <Use>"ONLY" { // TODO: rename - startFontClass("keywordtype"); + startFontClass("keywordtype"); codifyLines(yytext); endFontClass(); yy_push_state(YY_START); - BEGIN(UseOnly); - } + BEGIN(UseOnly); + } <Use>{ID} { QCString tmp = yytext; tmp = tmp.lower(); @@ -821,7 +822,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") useEntry->module = tmp; useMembers->append(tmp, useEntry); addUse(tmp); - } + } <Use,UseOnly,Import>{BS},{BS} { codifyLines(yytext); } <UseOnly,Import>{BS}&{BS}"\n" { codifyLines(yytext); g_contLineNr++; @@ -859,11 +860,11 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") /*-------- fortran module -----------------------------------------*/ <Start>("block"{BS}"data"|"program"|"module"|"interface")/{BS_}|({COMMA}{ACCESS_SPEC})|\n { // startScope(); - startFontClass("keyword"); + startFontClass("keyword"); codifyLines(yytext); endFontClass(); yy_push_state(YY_START); - BEGIN(ClassName); + BEGIN(ClassName); if (!qstricmp(yytext,"module")) currentModule="module"; } <Start>("enum")/{BS_}|{BS}{COMMA}{BS}{LANGUAGE_BIND_SPEC}|\n { // @@ -924,7 +925,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") startFontClass("keyword"); codifyLines(yytext); endFontClass(); - } + } <Start>({PREFIX}{BS_})?{SUBPROG}{BS_} { // Fortran subroutine or function found startFontClass("keyword"); codifyLines(yytext); @@ -942,7 +943,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") codifyLines(yytext); endFontClass(); } -<Subprog>"("[^)]*")" { // ignore rest of line +<Subprog>"("[^)]*")" { // ignore rest of line codifyLines(yytext); } <Subprog,Subprogend>"\n" { codifyLines(yytext); @@ -978,7 +979,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") g_code->codify(yytext); endFontClass(); } -<Start>{TYPE_SPEC}/[,:( ] { +<Start>{TYPE_SPEC}/[,:( ] { QCString typ = yytext; typ = removeRedundantWhiteSpace(typ.lower()); if (typ.startsWith("real")) YY_FTN_REJECT; @@ -989,7 +990,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") g_code->codify(yytext); endFontClass(); } -<Start>{ATTR_SPEC} { +<Start>{ATTR_SPEC} { if (QCString(yytext) == "external") { yy_push_state(YY_START); @@ -1051,7 +1052,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") if (!g_isFixedForm) { yy_push_state(YY_START); - BEGIN(DeclContLine); + BEGIN(DeclContLine); } } <DeclContLine>"\n" { // declaration not yet finished @@ -1149,7 +1150,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") yy_end = static_cast<int>(yyleng); // Actually we should see if ! on position 6, can be continuation // but the chance is very unlikely, so no effort to solve it here - docBlock+=yytext; + docBlock+=yytext; } <DocBlock>"\n" { // comment block ends at the end of this line // remove special comment (default config) @@ -1203,7 +1204,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") endFontClass(); } - /*------ preprocessor --------------------------------------------*/ + /*------ preprocessor --------------------------------------------*/ <Start>"#".*\n { if (g_isFixedForm && yy_my_start == 6) YY_FTN_REJECT; g_contLineNr++; @@ -1212,17 +1213,17 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") endFontClass(); YY_FTN_RESET } - /*------ variable references? -------------------------------------*/ + /*------ variable references? -------------------------------------*/ -<Start>"%"{BS}{ID} { // ignore references to elements +<Start>"%"{BS}{ID} { // ignore references to elements g_code->codify(yytext); } -<Start>{ID} { +<Start>{ID} { g_insideBody=TRUE; generateLink(*g_code, yytext); g_insideBody=FALSE; } - /*------ strings --------------------------------------------------*/ + /*------ strings --------------------------------------------------*/ <String>\n { // string with \n inside g_contLineNr++; g_str+=yytext; @@ -1231,15 +1232,15 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") endFontClass(); g_str = ""; YY_FTN_RESET - } -<String>\"|\' { // string ends with next quote without previous backspace + } +<String>\"|\' { // string ends with next quote without previous backspace if(yytext[0]!=stringStartSymbol) YY_FTN_REJECT; // single vs double quote g_str+=yytext; startFontClass("stringliteral"); codifyLines(g_str); endFontClass(); yy_pop_state(); - } + } <String>. {g_str+=yytext;} <*>\"|\' { /* string starts */ @@ -1268,7 +1269,7 @@ LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?") } <*>^{BS}"type"{BS}"=" { g_code->codify(yytext); } -<*>. { +<*>. { if (g_isFixedForm && yy_my_start > fixedCommentAfter) { //yy_push_state(YY_START); @@ -1328,7 +1329,7 @@ static void checkContLines(const char *s) g_hasContLine[0] = 0; } -void parseFortranCode(CodeOutputInterface &od,const char *,const QCString &s, +void parseFortranCode(CodeOutputInterface &od,const char *,const QCString &s, bool exBlock, const char *exName,FileDef *fd, int startLine,int endLine,bool inlineFragment, const MemberDef *,bool,const Definition *searchCtx, @@ -1362,7 +1363,7 @@ void parseFortranCode(CodeOutputInterface &od,const char *,const QCString &s, else g_inputLines = g_yyLineNr + countLines() - 1; - g_exampleBlock = exBlock; + g_exampleBlock = exBlock; g_exampleName = exName; g_sourceFileDef = fd; if (exBlock && fd==0) @@ -1370,7 +1371,7 @@ void parseFortranCode(CodeOutputInterface &od,const char *,const QCString &s, // create a dummy filedef for the example g_sourceFileDef = createFileDef("",exName); } - if (g_sourceFileDef) + if (g_sourceFileDef) { setCurrentDoc("l00001"); } |