-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfixes and new rules from collaboration EUMETSAT-AQCLab #230
Open
jverdugo-aqclab
wants to merge
32
commits into
cnescatlab:master
Choose a base branch
from
jverdugo-aqclab:Eumetsat-AQCLab-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f06ee24
Bug fix: parsing errors (COM.NAME.Homonymy: Location unreachable or I…
jverdugo-aqclab 729b1e6
Bug fix: Parsing error (IndexOutOfBoundsException) was produced when …
jverdugo-aqclab 50108d9
Bug fix: a parsing error (IndexOutOfBoundsException) was produced whe…
jverdugo-aqclab 8104472
Rule for checking that lines of code in a file don't exceed a thresho…
jverdugo-aqclab 8178b61
Rule for checking that lines of code in procedures don't exceed a thr…
jverdugo-aqclab 53bcf92
Rule ArgumentsProcedure
adiaz-aqclab fd38d56
Rule CyclomaticComplexity
adiaz-aqclab a35a601
Rule LogicUnit
adiaz-aqclab f3fe830
Rule PercentageComment
adiaz-aqclab 363f560
Rule CommentVar
adiaz-aqclab fd9331d
Rule Header
adiaz-aqclab c73b574
Change new rules names to RNC rules
1b2592e
Change name in comment
8d81c1e
Update fortran77-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab 081584c
Update fortran77-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab 93dbf77
Update fortran77-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab 0ff4252
Update fortran77-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab a733ffd
Update fortran77-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab 446f106
Update fortran77-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab 3bf3c33
Update fortran90-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab 23ac9c7
Update fortran90-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab 290cd74
Update fortran77-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab 8e43b0c
Update fortran77-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab dd56e54
Update fortran90-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab 217f47e
Update fortran90-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab 8502935
Update fortran90-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab 849784b
Update fortran90-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab af8085a
Update fortran90-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab ed18b31
Update fortran90-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab a66e884
Remove unused variable numTotal
jverdugo-aqclab 5e8cac9
Header updated to reflect this rule is not defined in RNC.
jverdugo-aqclab 8b510ac
Test cases for new rules
jverdugo-aqclab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it if you decide to enhance the existing header rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending of confirmation on comment #230 (comment)