Skip to content

Commit

Permalink
Implementation Fortran ENUM / ENUMERATION
Browse files Browse the repository at this point in the history
All ENUMs are anonymous as they don't have a name defined in the Fortran standard.
  • Loading branch information
albert-github committed Feb 17, 2018
1 parent b6f01ff commit f5ffd48
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 46 deletions.
90 changes: 59 additions & 31 deletions src/fortrancode.l
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ NUM_TYPE (complex|integer|logical|real)
LOG_OPER (\.and\.|\.eq\.|\.eqv\.|\.ge\.|\.gt\.|\.le\.|\.lt\.|\.ne\.|\.neqv\.|\.or\.|\.not\.)
KIND {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}|TYPE|CLASS|PROCEDURE)
TYPE_SPEC (({NUM_TYPE}({BS}"*"{BS}[0-9]+)?)|({NUM_TYPE}{KIND})|DOUBLE{BS}COMPLEX|DOUBLE{BS}PRECISION|{CHAR}|TYPE|CLASS|PROCEDURE|ENUMERATOR)

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|CONTIGUOUS|VOLATILE)
Expand All @@ -695,6 +695,7 @@ FLOW (DO|SELECT|CASE|SELECT{BS}(CASE|TYPE)|WHERE|IF|THEN|ELSE|WHILE|FORALL|
COMMANDS (FORMAT|CONTAINS|MODULE{BS_}PROCEDURE|WRITE|READ|ALLOCATE|ALLOCATED|ASSOCIATED|PRESENT|DEALLOCATE|NULLIFY|SIZE|INQUIRE|OPEN|CLOSE|FLUSH|DATA|COMMON)
IGNORE (CALL)
PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|IMPURE|PURE|ELEMENTAL)?
LANGUAGE_BIND_SPEC BIND{BS}"("{BS}C{BS}(,{BS}NAME{BS}"="{BS}"\""(.*)"\""{BS})?")"

/* | */

Expand Down Expand Up @@ -775,12 +776,12 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
BEGIN(Use);
}
<Use>"ONLY" { // TODO: rename
startFontClass("keywordtype");
codifyLines(yytext);
endFontClass();
startFontClass("keywordtype");
codifyLines(yytext);
endFontClass();
yy_push_state(YY_START);
BEGIN(UseOnly);
}
BEGIN(UseOnly);
}
<Use>{ID} {
QCString tmp = yytext;
tmp = tmp.lower();
Expand Down Expand Up @@ -835,15 +836,29 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
BEGIN(ClassName);
if (!qstricmp(yytext,"module")) currentModule="module";
}
<Start>("enum")/{BS_}|{BS}{COMMA}{BS}{LANGUAGE_BIND_SPEC}|\n { //
startScope();
startFontClass("keyword");
codifyLines(yytext);
endFontClass();
yy_push_state(YY_START);
BEGIN(ClassName);
currentClass="class";
}
<*>{LANGUAGE_BIND_SPEC} { //
startFontClass("keyword");
codifyLines(yytext);
endFontClass();
}
<Start>("type")/{BS_}|({COMMA}({ACCESS_SPEC}|ABSTRACT|EXTENDS))|\n { //
startScope();
startFontClass("keyword");
codifyLines(yytext);
endFontClass();
startScope();
startFontClass("keyword");
codifyLines(yytext);
endFontClass();
yy_push_state(YY_START);
BEGIN(ClassName);
currentClass="class";
}
BEGIN(ClassName);
currentClass="class";
}
<ClassName>{ID} {
if (currentModule == "module")
{
Expand All @@ -853,22 +868,26 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
generateLink(*g_code,yytext);
yy_pop_state();
}
<ClassName>({ACCESS_SPEC}|ABSTRACT|EXTENDS)/[,:( ] { //| variable deklaration
<ClassName>({ACCESS_SPEC}|ABSTRACT|EXTENDS)/[,:( ] { //| variable declaration
startFontClass("keyword");
g_code->codify(yytext);
endFontClass();
}
<ClassName>\n { // interface may be without name
yy_pop_state();
YY_FTN_REJECT;
}
YY_FTN_REJECT;
}
<Start>^{BS}"end"({BS_}"enum").* { // just reset currentClass, rest is done in following rule
currentClass=0;
YY_FTN_REJECT;
}
<Start>^{BS}"end"({BS_}"type").* { // just reset currentClass, rest is done in following rule
currentClass=0;
YY_FTN_REJECT;
YY_FTN_REJECT;
}
<Start>^{BS}"end"({BS_}"module").* { // just reset currentModule, rest is done in following rule
currentModule=0;
YY_FTN_REJECT;
YY_FTN_REJECT;
}
/*-------- subprog definition -------------------------------------*/
<Start>({PREFIX}{BS_})?{TYPE_SPEC}{BS_}({PREFIX}{BS_})?{BS}/{SUBPROG}{BS_} { // TYPE_SPEC is for old function style function result
Expand Down Expand Up @@ -901,7 +920,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
yy_pop_state();
YY_FTN_RESET
}
<Start>^{BS}"end"{BS}("block"{BS}"data"|{SUBPROG}|"module"|"program"|"type"|"interface")?{BS} { // Fortran subroutine or function ends
<Start>^{BS}"end"{BS}("block"{BS}"data"|{SUBPROG}|"module"|"program"|"enum"|"type"|"interface")?{BS} { // Fortran subroutine or function ends
//cout << "===> end function " << yytext << endl;
endScope();
startFontClass("keyword");
Expand All @@ -914,7 +933,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
generateLink(*g_code,yytext);
yy_pop_state();
}
<Start>^{BS}"end"{BS}("block"{BS}"data"|{SUBPROG}|"module"|"program"|"type"|"interface"){BS}/(\n|!) { // Fortran subroutine or function ends
<Start>^{BS}"end"{BS}("block"{BS}"data"|{SUBPROG}|"module"|"program"|"enum"|"type"|"interface"){BS}/(\n|!) { // Fortran subroutine or function ends
//cout << "===> end function " << yytext << endl;
endScope();
startFontClass("keyword");
Expand All @@ -934,7 +953,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
g_code->codify(yytext);
endFontClass();
}
<Declaration>({TYPE_SPEC}|{ATTR_SPEC})/[,:( ] { //| variable deklaration
<Declaration>({TYPE_SPEC}|{ATTR_SPEC})/[,:( ] { //| variable declaration
startFontClass("keywordtype");
g_code->codify(yytext);
endFontClass();
Expand All @@ -947,7 +966,7 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
endFontClass();
}
else if (g_currentMemberDef && ((g_currentMemberDef->isFunction() && (g_currentMemberDef->typeString() != QCString("subroutine"))) ||
g_currentMemberDef->isVariable()))
g_currentMemberDef->isVariable() || g_currentMemberDef->isEnumValue()))
{
generateLink(*g_code, yytext);
}
Expand All @@ -956,15 +975,15 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
g_code->codify(yytext);
addLocalVar(yytext);
}
}
<Declaration>{BS}("=>"|"="){BS} { // Procedure binding
BEGIN(DeclarationBinding);
g_code->codify(yytext);
}
<DeclarationBinding>{ID} { // Type bound procedure link
}
<Declaration>{BS}("=>"|"="){BS} { // Procedure binding
BEGIN(DeclarationBinding);
g_code->codify(yytext);
}
<DeclarationBinding>{ID} { // Type bound procedure link
generateLink(*g_code, yytext);
yy_pop_state();
}
}
<Declaration>[(] { // start of array specification
bracketCount++;
g_code->codify(yytext);
Expand Down Expand Up @@ -1029,11 +1048,20 @@ PREFIX (RECURSIVE{BS_}|IMPURE{BS_}|PURE{BS_}|ELEMENTAL{BS_}){0,3}(RECURSIVE|I
// fixed form continuation line
YY_FTN_REJECT;
}
else if (QCString(yytext).stripWhiteSpace().lower() == "type")
{
yy_push_state(YY_START);
BEGIN(Declaration);
startFontClass("keywordtype");
g_code->codify(QCString(yytext).stripWhiteSpace());
endFontClass();
g_code->codify(yytext + 4);
}
else
{
g_insideBody=TRUE;
g_insideBody=TRUE;
generateLink(*g_code, yytext);
g_insideBody=FALSE;
g_insideBody=FALSE;
}
}

Expand Down
Loading

0 comments on commit f5ffd48

Please sign in to comment.