-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from cnescatlab/develop
Release 5.1.0
- Loading branch information
Showing
76 changed files
with
6,596 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
fortran77-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/************************************************************************************************/ | ||
/* i-Code CNES is a static code analyzer. */ | ||
/* This software is a free software, under the terms of the Eclipse Public License version 1.0. */ | ||
/* http://www.eclipse.org/legal/epl-v10.html */ | ||
/************************************************************************************************/ | ||
/***************************************************************************************/ | ||
/* This file is used to generate a rule checker for COM.FLOW.CheckArguments rule.*/ | ||
/* For further information on this, we advise you to refer to RNC manuals. */ | ||
/* As many comments have been done on the ExampleRule.lex file, this file */ | ||
/* will restrain its comments on modifications. */ | ||
/* */ | ||
/***************************************************************************************/ | ||
package fr.cnes.icode.fortran77.rules; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.File; | ||
import java.util.List; | ||
import java.util.LinkedList; | ||
import fr.cnes.icode.data.AbstractChecker; | ||
import fr.cnes.icode.data.CheckResult; | ||
import fr.cnes.icode.exception.JFlexException; | ||
%% | ||
%class COMFLOWCheckArguments | ||
%extends AbstractChecker | ||
%public | ||
%column | ||
%line | ||
%ignorecase | ||
%function run | ||
%yylexthrow JFlexException | ||
%type List<CheckResult> | ||
%state COMMENT, NAMING, NEW_LINE, LINE, AVOID, YYINITIAL, ARGUMENTS_DEF | ||
COMMENT_WORD = \! | c | C | \* | ||
PROCEDURES = PROCEDURE | procedure | SUBROUTINE | subroutine | FUNCTION | function | ||
PROG = PROGRAM | program | ||
MOD = MODULE | module | ||
INTER = INTERFACE | interface | ||
TYPE = {PROG} | {MOD} | {INTER} | ||
VAR = [a-zA-Z][a-zA-Z0-9\_]* | ||
STRING = \'[^\']*\' | \"[^\"]*\" | ||
SPACE = [\ \r\t\f] | ||
END = END | end | ||
INITARG = \( | ||
FINARG = \) | ||
COMA = \, | ||
|
||
%{ | ||
String location = "MAIN PROGRAM"; | ||
private String parsedFileName; | ||
int arguments = 1; | ||
boolean procStarted = false; | ||
boolean nameRead = false; | ||
|
||
public COMFLOWCheckArguments(){ | ||
} | ||
|
||
@Override | ||
public void setInputFile(final File file) throws FileNotFoundException { | ||
super.setInputFile(file); | ||
this.parsedFileName = file.toString(); | ||
this.zzReader = new FileReader(new File(file.getAbsolutePath())); | ||
} | ||
|
||
private void checkArgumentsProcedure() { | ||
if(procStarted && arguments > 5) { | ||
this.setError(location,"This procedure contains more than 5 arguments: " + arguments, yyline+1); | ||
} | ||
procStarted = false; | ||
nameRead = false; | ||
} | ||
|
||
%} | ||
%eofval{ | ||
return getCheckResults(); | ||
%eofval} | ||
%eofclose | ||
%% | ||
/************************/ | ||
|
||
/************************/ | ||
/* COMMENT STATE */ | ||
/************************/ | ||
<COMMENT> | ||
{ | ||
\n {yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* AVOID STATE */ | ||
/************************/ | ||
<AVOID> \n {yybegin(NEW_LINE);} | ||
<AVOID> . {} | ||
/************************/ | ||
/* NAMING STATE */ | ||
/************************/ | ||
<NAMING> | ||
{ | ||
{VAR} {yybegin(AVOID);} | ||
\n {yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* YYINITIAL STATE */ | ||
/************************/ | ||
<YYINITIAL> | ||
{ | ||
{COMMENT_WORD} {yybegin(COMMENT);} | ||
{STRING} {yybegin(LINE);} | ||
{TYPE} {yybegin(NAMING);} | ||
{END} {yybegin(AVOID);} | ||
{PROCEDURES} {location = yytext(); procStarted = true; yybegin(ARGUMENTS_DEF);} | ||
{SPACE} {} | ||
\n {yybegin(NEW_LINE);} | ||
. {yybegin(LINE);} | ||
} | ||
/************************/ | ||
/* ARGUMENTS_DEF STATE */ | ||
/************************/ | ||
<ARGUMENTS_DEF> | ||
{ | ||
{VAR} {if(!nameRead) {location = location + " " + yytext(); nameRead = true;}} | ||
{INITARG} {arguments = 1;} | ||
{COMA} {arguments++;} | ||
{FINARG} {checkArgumentsProcedure(); yybegin(AVOID);} | ||
\n {if(procStarted == false) yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* NEW_LINE STATE */ | ||
/************************/ | ||
<NEW_LINE> | ||
{ | ||
{COMMENT_WORD} {yybegin(COMMENT);} | ||
{STRING} {yybegin(LINE);} | ||
{TYPE} {yybegin(NAMING);} | ||
{END} {yybegin(AVOID);} | ||
{PROCEDURES} {location = yytext(); procStarted = true; yybegin(ARGUMENTS_DEF);} | ||
{SPACE} {} | ||
\n {yybegin(NEW_LINE);} | ||
. {yybegin(LINE);} | ||
} | ||
/************************/ | ||
/* LINE STATE */ | ||
/************************/ | ||
<LINE> | ||
{ | ||
{COMMENT_WORD} {} | ||
{STRING} {} | ||
{TYPE} {yybegin(NAMING);} | ||
{END} {yybegin(AVOID);} | ||
{PROCEDURES} {location = yytext(); procStarted = true; yybegin(ARGUMENTS_DEF);} | ||
{VAR} {} | ||
\n {yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* ERROR STATE */ | ||
/************************/ | ||
[^] { | ||
|
||
final String errorMessage = "Analysis failure : Your file could not be analyzed. Please verify that it was encoded in an UNIX format."; | ||
throw new JFlexException(this.getClass().getName(), parsedFileName, errorMessage, yytext(), yyline, yycolumn); | ||
} |
154 changes: 154 additions & 0 deletions
154
fortran77-rules/src/main/resources/lex/COMMETComplexitySimplified.lex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/************************************************************************************************/ | ||
/* i-Code CNES is a static code analyzer. */ | ||
/* This software is a free software, under the terms of the Eclipse Public License version 1.0. */ | ||
/* http://www.eclipse.org/legal/epl-v10.html */ | ||
/************************************************************************************************/ | ||
/********************************************************************************************/ | ||
/* This file is used to generate a rule checker for COM.MET.ComplexitySimplified rule. */ | ||
/* For further information on this, we advise you to refer to RNC manuals. */ | ||
/* As many comments have been done on the ExampleRule.lex file, this file */ | ||
/* will restrain its comments on modifications. */ | ||
/* */ | ||
/********************************************************************************************/ | ||
package fr.cnes.icode.fortran77.rules; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.File; | ||
import java.util.List; | ||
import java.util.LinkedList; | ||
import fr.cnes.icode.data.AbstractChecker; | ||
import fr.cnes.icode.data.CheckResult; | ||
import fr.cnes.icode.exception.JFlexException; | ||
%% | ||
%class COMMETComplexitySimplified | ||
%extends AbstractChecker | ||
%public | ||
%column | ||
%line | ||
%function run | ||
%yylexthrow JFlexException | ||
%type List<CheckResult> | ||
%state COMMENT, NAMING, NEW_LINE, LINE, AVOID | ||
COMMENT_WORD = \! | c | C | \* | ||
FUNC = FUNCTION | function | ||
PROC = PROCEDURE | procedure | ||
SUB = SUBROUTINE | subroutine | ||
PROG = PROGRAM | program | ||
MOD = MODULE | module | ||
INTER = INTERFACE | interface | ||
TYPE = {PROG} | {MOD} | {INTER} | ||
PROCEDURES = {FUNC} | {PROC} | {SUB} | ||
UNION = \.AND\. | \.and\. | \.OR\. | \.or\. | ||
CICLO = DO | do | IF | if | ELSE[\ ]*IF | else[\ ]*if | ||
CLOSING = END[\ ]*IF | end[\ ]*if | END[\ ]*DO | end[\ ]*do | ||
VAR = [a-zA-Z][a-zA-Z0-9\_]* | ||
END = END | end | ||
STRING = \'[^\']*\' | \"[^\"]*\" | ||
|
||
%{ | ||
String location = "MAIN PROGRAM"; | ||
private String parsedFileName; | ||
int numCyclomatic = 1; | ||
int procedureLine = 0; | ||
|
||
public COMMETComplexitySimplified(){ | ||
} | ||
|
||
@Override | ||
public void setInputFile(final File file) throws FileNotFoundException { | ||
super.setInputFile(file); | ||
this.parsedFileName = file.toString(); | ||
this.zzReader = new FileReader(new File(file.getAbsolutePath())); | ||
} | ||
|
||
private void checkTotalComplexity() { | ||
if(numCyclomatic > 20 ) { | ||
setError(location,"The cyclomatic complexity of this function is more than 20: " +numCyclomatic, procedureLine+1); | ||
} | ||
} | ||
|
||
%} | ||
%eofval{ | ||
return getCheckResults(); | ||
%eofval} | ||
%eofclose | ||
%% | ||
/************************/ | ||
|
||
/************************/ | ||
/* COMMENT STATE */ | ||
/************************/ | ||
<COMMENT> | ||
{ | ||
\n {yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* AVOID STATE */ | ||
/************************/ | ||
<AVOID> \n {yybegin(NEW_LINE);} | ||
<AVOID> . {} | ||
/************************/ | ||
/* NAMING STATE */ | ||
/************************/ | ||
<NAMING> | ||
{ | ||
{VAR} {location = location + " " + yytext(); yybegin(AVOID);} | ||
\n {yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* YYINITIAL STATE */ | ||
/************************/ | ||
<YYINITIAL> | ||
{ | ||
{COMMENT_WORD} {yybegin(COMMENT);} | ||
{STRING} {yybegin(LINE);} | ||
{TYPE} {yybegin(AVOID);} | ||
{PROCEDURES} {numCyclomatic = 1; location = yytext(); procedureLine = yyline; yybegin(NAMING);} | ||
\n {yybegin(NEW_LINE);} | ||
. {yybegin(LINE);} | ||
} | ||
/************************/ | ||
/* NEW_LINE STATE */ | ||
/************************/ | ||
<NEW_LINE> | ||
{ | ||
{COMMENT_WORD} {yybegin(COMMENT);} | ||
{STRING} {yybegin(LINE);} | ||
{TYPE} {yybegin(AVOID);} | ||
{PROCEDURES} {numCyclomatic = 1; location = yytext(); procedureLine = yyline; yybegin(NAMING);} | ||
{CICLO} {numCyclomatic++; yybegin(LINE);} | ||
{UNION} {numCyclomatic++; yybegin(LINE);} | ||
{CLOSING} {yybegin(LINE);} | ||
{END} {checkTotalComplexity();} | ||
{VAR} {yybegin(LINE);} | ||
\n {} | ||
. {yybegin(LINE);} | ||
} | ||
/************************/ | ||
/* LINE STATE */ | ||
/************************/ | ||
<LINE> | ||
{ | ||
{COMMENT_WORD} {yybegin(COMMENT);} | ||
{STRING} {} | ||
{TYPE} {yybegin(AVOID);} | ||
{PROCEDURES} {numCyclomatic = 1; location = yytext(); procedureLine = yyline; yybegin(NAMING);} | ||
{CICLO} {numCyclomatic++;} | ||
{UNION} {numCyclomatic++;} | ||
{CLOSING} {} | ||
{END} {checkTotalComplexity();} | ||
{VAR} {} | ||
\n {yybegin(NEW_LINE);} | ||
. {} | ||
} | ||
/************************/ | ||
/* ERROR STATE */ | ||
/************************/ | ||
[^] { | ||
|
||
final String errorMessage = "Analysis failure : Your file could not be analyzed. Please verify that it was encoded in an UNIX format."; | ||
throw new JFlexException(this.getClass().getName(), parsedFileName, | ||
errorMessage, yytext(), yyline, yycolumn); | ||
} |
Oops, something went wrong.