From eb92c064b33bf9f303233210b9693215b0fb7f9d Mon Sep 17 00:00:00 2001 From: albert-github Date: Sun, 4 Jan 2015 18:24:06 +0100 Subject: Fortran: fixed format position 73 and further is comment According to the Fortran standard position 73 and further on a line are comment. Until now this was not considered. --- src/fortrancode.h | 1 + src/fortrancode.l | 31 ++++++++++++++++++++------ src/fortranscanner.l | 61 ++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/src/fortrancode.h b/src/fortrancode.h index b64ede7..92e7f85 100644 --- a/src/fortrancode.h +++ b/src/fortrancode.h @@ -34,4 +34,5 @@ void parseFortranCode(CodeOutputInterface &,const char *,const QCString &, void resetFortranCodeParserState(); void codeFreeScanner(); +const int fixedCommentAfter = 72; #endif diff --git a/src/fortrancode.l b/src/fortrancode.l index 17a28c3..bf50835 100644 --- a/src/fortrancode.l +++ b/src/fortrancode.l @@ -50,6 +50,7 @@ #include "filedef.h" #include "namespacedef.h" #include "tooltip.h" +#include "fortrancode.h" // Toggle for some debugging info //#define DBG_CTX(x) fprintf x @@ -211,9 +212,14 @@ static void endFontClass() static void startFontClass(const char *s) { - endFontClass(); - g_code->startFontClass(s); - g_currentFontClass=s; + // if font class is already set don't stop and start it. + // strcmp does not like null pointers as input. + if (!g_currentFontClass || !s || strcmp(g_currentFontClass,s)) + { + endFontClass(); + g_code->startFontClass(s); + g_currentFontClass=s; + } } static void setCurrentDoc(const QCString &anchor) @@ -1179,11 +1185,22 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I } YY_FTN_RESET } -<*>^{BS}"type"{BS}"=" { g_code->codify(yytext); } +<*>^{BS}"type"{BS}"=" { g_code->codify(yytext); } -<*>. { - g_code->codify(yytext); - } +<*>. { + if (g_isFixedForm && yy_my_start > fixedCommentAfter) + { + //yy_push_state(YY_START); + //BEGIN(DocBlock); + //docBlock=yytext; + startFontClass("comment"); + codifyLines(yytext); + } + else + { + g_code->codify(yytext); + } + } <*>{LOG_OPER} { // Fortran logical comparison keywords g_code->codify(yytext); } diff --git a/src/fortranscanner.l b/src/fortranscanner.l index 3c35a7d..9b212e8 100644 --- a/src/fortranscanner.l +++ b/src/fortranscanner.l @@ -1411,11 +1411,15 @@ static const char* prepassFixedForm(const char* contents) int prevLineLength=0; int prevLineAmpOrExclIndex=-1; bool emptyLabel=TRUE; + bool commented=FALSE; + bool inSingle=FALSE; + bool inDouble=FALSE; + bool inBackslash=FALSE; int newContentsSize = strlen(contents)+3; // \000, \n (when necessary) and one spare character (to avoid reallocation) char* newContents = (char*)malloc(newContentsSize); for(int i=0, j=0;;i++,j++) { - if(j>=newContentsSize-1) { // check for one spare character, which may be eventually used below (by &) + if(j>=newContentsSize-3) { // check for spare characters, which may be eventually used below (by & and '! ') newContents = (char*)realloc(newContents, newContentsSize+1000); newContentsSize = newContentsSize+1000; } @@ -1428,9 +1432,11 @@ static const char* prepassFixedForm(const char* contents) prevLineAmpOrExclIndex=getAmpOrExclAtTheEnd(&contents[i-prevLineLength+1], prevLineLength); column=0; emptyLabel=TRUE; + commented=FALSE; newContents[j]=c; break; case ' ': + case '\t': newContents[j]=c; break; case '\000': @@ -1444,21 +1450,55 @@ static const char* prepassFixedForm(const char* contents) newContents[newContentsSize + 1] = '\000'; } return newContents; - case 'C': + case '"': + case '\'': + case '\\': + if ((column <= fixedCommentAfter) && (column!=6) && !commented) + { + // we have some special cases in respect to strings and exscaped string characters + newContents[j]=c; + if (c == '\\') + { + inBackslash = !inBackslash; + break; + } + else if (c == '\'') + { + if (!inDouble) inSingle = !inSingle; + break; + } + else if (c == '"') + { + if (!inSingle) inDouble = !inDouble; + break; + } + } + inBackslash = FALSE; case 'c': case '*': - if (column!=6) + case '!': + if ((column <= fixedCommentAfter) && (column!=6)) { emptyLabel=FALSE; if(column==1) + { newContents[j]='!'; + commented = TRUE; + } + else if ((c == '!') && !inDouble && !inSingle) + { + newContents[j]=c; + commented = TRUE; + } else + { newContents[j]=c; + } break; } default: if(column==6 && emptyLabel) { // continuation - if (c != '0') { // 0 not allowed as continuatioin character, see f95 standard paragraph 3.3.2.3 + if (c != '0') { // 0 not allowed as continuation character, see f95 standard paragraph 3.3.2.3 newContents[j]=' '; if(prevLineAmpOrExclIndex==-1) { // add & just before end of previous line @@ -1471,6 +1511,15 @@ static const char* prepassFixedForm(const char* contents) } else { newContents[j]=c; // , just handle like space } + } else if ((column > fixedCommentAfter) && !commented) { + // first non commented non blank character after position fixedCommentAfter + if (c != '!') { + // I'm not a possible start of doxygen comment + newContents[j++]='!'; + newContents[j++]=' '; // so that '<' and '>' as first character are not converted to doxygen comment + } + newContents[j]=c; + commented = TRUE; } else { newContents[j]=c; emptyLabel=FALSE; @@ -2235,7 +2284,7 @@ static void subrHandleCommentBlock(const QCString &doc,bool brief) // strip \\param or @param, so we can do some extra checking. We will add it later on again. if (!loc_doc.stripPrefix("\\param") && !loc_doc.stripPrefix("@param") - ); // Do nothing work has been done by stripPrefix + ) (void)loc_doc; // Do nothing work has been done by stripPrefix; (void)loc_doc: to overcome 'empty controlled statement' warning loc_doc.stripWhiteSpace(); // direction as defined with the declaration of the parameter @@ -2350,7 +2399,7 @@ static void subrHandleCommentBlockResult(const QCString &doc,bool brief) !loc_doc.stripPrefix("\\return") && !loc_doc.stripPrefix("@returns") && !loc_doc.stripPrefix("@return") - ); // Do nothing work has been done by stripPrefix + ) (void)loc_doc; // Do nothing work has been done by stripPrefix; (void)loc_doc: to overcome 'empty controlled statement' warning loc_doc.stripWhiteSpace(); if (loc_doc.isEmpty() || (loc_doc.lower() == argName.lower())) -- cgit v0.12 From 557ad21ce28d093044101eb8bee2c4df1621da7a Mon Sep 17 00:00:00 2001 From: albert-github Date: Sun, 4 Jan 2015 19:02:41 +0100 Subject: Fortran: fixed format position 73 and further is comment Small regression, line with 'C' (Capital C) was edited away, re-instated. --- src/fortranscanner.l | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fortranscanner.l b/src/fortranscanner.l index 9b212e8..1cfa13d 100644 --- a/src/fortranscanner.l +++ b/src/fortranscanner.l @@ -1474,6 +1474,8 @@ static const char* prepassFixedForm(const char* contents) } } inBackslash = FALSE; + // fallthrough + case 'C': case 'c': case '*': case '!': @@ -1496,6 +1498,7 @@ static const char* prepassFixedForm(const char* contents) } break; } + // fallthrough default: if(column==6 && emptyLabel) { // continuation if (c != '0') { // 0 not allowed as continuation character, see f95 standard paragraph 3.3.2.3 -- cgit v0.12