Commit 8297ed8a authored by Dimitri van Heesch's avatar Dimitri van Heesch

Merge pull request #172 from hansec/fortran_typdef

Fix unnecessary rules for FORTRAN user defined types
parents d501764f 2030240b
...@@ -152,6 +152,8 @@ static char stringStartSymbol; // single or double quote ...@@ -152,6 +152,8 @@ static char stringStartSymbol; // single or double quote
// declared from referenced names // declared from referenced names
static int bracketCount = 0; static int bracketCount = 0;
static bool g_endComment;
// simplified way to know if this is fixed form // simplified way to know if this is fixed form
// duplicate in fortranscanner.l // duplicate in fortranscanner.l
static bool recognizeFixedForm(const char* contents, FortranFormat format) static bool recognizeFixedForm(const char* contents, FortranFormat format)
...@@ -255,6 +257,7 @@ static void startCodeLine() ...@@ -255,6 +257,7 @@ static void startCodeLine()
g_currentDefinition = d; g_currentDefinition = d;
g_currentMemberDef = g_sourceFileDef->getSourceMember(g_yyLineNr); g_currentMemberDef = g_sourceFileDef->getSourceMember(g_yyLineNr);
g_insideBody = FALSE; g_insideBody = FALSE;
g_endComment = FALSE;
g_parmType.resize(0); g_parmType.resize(0);
g_parmName.resize(0); g_parmName.resize(0);
QCString lineAnchor; QCString lineAnchor;
...@@ -688,8 +691,7 @@ NUM_TYPE (complex|integer|logical|real) ...@@ -688,8 +691,7 @@ NUM_TYPE (complex|integer|logical|real)
LOG_OPER (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.) LOG_OPER (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.)
KIND {ARGS} KIND {ARGS}
CHAR (CHARACTER{ARGS}?|CHARACTER{BS}"*"({BS}[0-9]+|{ARGS})) CHAR (CHARACTER{ARGS}?|CHARACTER{BS}"*"({BS}[0-9]+|{ARGS}))
TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS}COMPLEX|DOUBLE{BS}PRECISION|{CHAR}|PROCEDURE) TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS}COMPLEX|DOUBLE{BS}PRECISION|{CHAR}|TYPE|CLASS|PROCEDURE)
TYPE_PREFIX ((TYPE|CLASS|PROCEDURE){BS}"(")
INTENT_SPEC intent{BS}"("{BS}(in|out|in{BS}out){BS}")" INTENT_SPEC intent{BS}"("{BS}(in|out|in{BS}out){BS}")"
ATTR_SPEC (IMPLICIT|ALLOCATABLE|DIMENSION{ARGS}|EXTERNAL|{INTENT_SPEC}|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|PRIVATE|PUBLIC|SAVE|TARGET|RECURSIVE|PURE|IMPURE|ELEMENTAL|VALUE|NOPASS|DEFERRED) ATTR_SPEC (IMPLICIT|ALLOCATABLE|DIMENSION{ARGS}|EXTERNAL|{INTENT_SPEC}|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|PRIVATE|PUBLIC|SAVE|TARGET|RECURSIVE|PURE|IMPURE|ELEMENTAL|VALUE|NOPASS|DEFERRED)
...@@ -718,7 +720,6 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -718,7 +720,6 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
%x Use %x Use
%x UseOnly %x UseOnly
%x Import %x Import
%x TypeDecl
%x Declaration %x Declaration
%x DeclContLine %x DeclContLine
%x Parameterlist %x Parameterlist
...@@ -828,7 +829,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -828,7 +829,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
g_insideBody=FALSE; g_insideBody=FALSE;
} }
/*-------- fortran module -----------------------------------------*/ /*-------- fortran module -----------------------------------------*/
<Start>("block"{BS}"data"|"program"|"module"|"type"|"interface")/{BS_}|({COMMA}({ACCESS_SPEC}|ABSTRACT|EXTENDS))|\n { // <Start>("block"{BS}"data"|"program"|"module"|"interface")/{BS_}|({COMMA}{ACCESS_SPEC})|\n { //
startScope(); startScope();
startFontClass("keyword"); startFontClass("keyword");
codifyLines(yytext); codifyLines(yytext);
...@@ -837,6 +838,14 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -837,6 +838,14 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
BEGIN(ClassName); BEGIN(ClassName);
if (!qstricmp(yytext,"module")) currentModule="module"; if (!qstricmp(yytext,"module")) currentModule="module";
} }
<Start>("type")/{BS_}|({COMMA}({ACCESS_SPEC}|ABSTRACT|EXTENDS))|\n { //
startScope();
startFontClass("keyword");
codifyLines(yytext);
endFontClass();
yy_push_state(YY_START);
BEGIN(ClassName);
}
<ClassName>{ID} { <ClassName>{ID} {
if (currentModule == "module") if (currentModule == "module")
{ {
...@@ -905,24 +914,6 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -905,24 +914,6 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
endFontClass(); endFontClass();
} }
/*-------- variable declaration ----------------------------------*/ /*-------- variable declaration ----------------------------------*/
<Start>^{BS}{TYPE_PREFIX}/{ID} {
yy_push_state(YY_START);
BEGIN(TypeDecl);
startFontClass("keywordtype");
g_code->codify(yytext);
endFontClass();
}
<TypeDecl>{ID} { // link type
g_insideBody=TRUE;
generateLink(*g_code,yytext);
g_insideBody=FALSE;
}
<TypeDecl>")" {
BEGIN(Declaration);
startFontClass("keywordtype");
g_code->codify(yytext);
endFontClass();
}
<Start>{TYPE_SPEC}/[,:( ] { <Start>{TYPE_SPEC}/[,:( ] {
yy_push_state(YY_START); yy_push_state(YY_START);
BEGIN(Declaration); BEGIN(Declaration);
...@@ -941,7 +932,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -941,7 +932,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
endFontClass(); endFontClass();
} }
<Declaration>{ID} { // local var <Declaration>{ID} { // local var
if (g_currentMemberDef && !g_currentMemberDef->isFunction()) if (g_currentMemberDef && g_currentMemberDef->isFunction() && bracketCount==0)
{ {
g_code->codify(yytext); g_code->codify(yytext);
addLocalVar(yytext); addLocalVar(yytext);
...@@ -973,7 +964,14 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -973,7 +964,14 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
YY_FTN_RESET YY_FTN_RESET
} }
<Declaration>"\n" { // end declaration line <Declaration>"\n" { // end declaration line
if (g_endComment)
{
g_endComment=FALSE;
}
else
{
codifyLines(yytext); codifyLines(yytext);
}
bracketCount = 0; bracketCount = 0;
yy_pop_state(); yy_pop_state();
YY_FTN_RESET YY_FTN_RESET
...@@ -1030,16 +1028,17 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -1030,16 +1028,17 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
docBlock+=yytext; docBlock+=yytext;
} }
<DocBlock>"\n" { // comment block ends at the end of this line <DocBlock>"\n" { // comment block ends at the end of this line
docBlock+=yytext;
// remove special comment (default config) // remove special comment (default config)
if (Config_getBool("STRIP_CODE_COMMENTS")) if (Config_getBool("STRIP_CODE_COMMENTS"))
{ {
g_yyLineNr+=((QCString)docBlock).contains('\n'); g_yyLineNr+=((QCString)docBlock).contains('\n');
g_yyLineNr+=1;
endCodeLine(); endCodeLine();
if (g_yyLineNr<g_inputLines) if (g_yyLineNr<g_inputLines)
{ {
startCodeLine(); startCodeLine();
} }
g_endComment=TRUE;
} }
else // do not remove comment else // do not remove comment
{ {
...@@ -1047,6 +1046,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -1047,6 +1046,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
codifyLines(docBlock); codifyLines(docBlock);
endFontClass(); endFontClass();
} }
unput(*yytext);
yy_pop_state(); yy_pop_state();
YY_FTN_RESET YY_FTN_RESET
} }
...@@ -1118,7 +1118,14 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I ...@@ -1118,7 +1118,14 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
<*>\n { <*>\n {
if (g_endComment)
{
g_endComment=FALSE;
}
else
{
codifyLines(yytext); codifyLines(yytext);
}
YY_FTN_RESET YY_FTN_RESET
} }
<*>. { <*>. {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment