Skip to content
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
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Dec 14, 2022
729b1e6
Bug fix: Parsing error (IndexOutOfBoundsException) was produced when …
jverdugo-aqclab Dec 14, 2022
50108d9
Bug fix: a parsing error (IndexOutOfBoundsException) was produced whe…
jverdugo-aqclab Dec 14, 2022
8104472
Rule for checking that lines of code in a file don't exceed a thresho…
jverdugo-aqclab Dec 14, 2022
8178b61
Rule for checking that lines of code in procedures don't exceed a thr…
jverdugo-aqclab Dec 15, 2022
53bcf92
Rule ArgumentsProcedure
adiaz-aqclab Dec 15, 2022
fd38d56
Rule CyclomaticComplexity
adiaz-aqclab Dec 15, 2022
a35a601
Rule LogicUnit
adiaz-aqclab Dec 15, 2022
f3fe830
Rule PercentageComment
adiaz-aqclab Dec 15, 2022
363f560
Rule CommentVar
adiaz-aqclab Dec 20, 2022
fd9331d
Rule Header
adiaz-aqclab Dec 20, 2022
c73b574
Change new rules names to RNC rules
Mar 28, 2023
1b2592e
Change name in comment
Mar 28, 2023
8d81c1e
Update fortran77-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab Jun 2, 2023
081584c
Update fortran77-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab Jun 2, 2023
93dbf77
Update fortran77-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab Jun 2, 2023
0ff4252
Update fortran77-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab Jun 2, 2023
a733ffd
Update fortran77-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab Jun 2, 2023
446f106
Update fortran77-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab Jun 2, 2023
3bf3c33
Update fortran90-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab Jun 2, 2023
23ac9c7
Update fortran90-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab Jun 2, 2023
290cd74
Update fortran77-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab Jun 2, 2023
8e43b0c
Update fortran77-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab Jun 2, 2023
dd56e54
Update fortran90-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab Jun 2, 2023
217f47e
Update fortran90-rules/src/main/resources/lex/COMMETRatioComment.lex
jverdugo-aqclab Jun 2, 2023
8502935
Update fortran90-rules/src/main/resources/lex/COMMETLineOfCode.lex
jverdugo-aqclab Jun 2, 2023
849784b
Update fortran90-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab Jun 2, 2023
af8085a
Update fortran90-rules/src/main/resources/lex/COMMETComplexitySimplif…
jverdugo-aqclab Jun 2, 2023
ed18b31
Update fortran90-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
jverdugo-aqclab Jun 2, 2023
a66e884
Remove unused variable numTotal
jverdugo-aqclab Jun 2, 2023
5e8cac9
Header updated to reflect this rule is not defined in RNC.
jverdugo-aqclab Jun 2, 2023
8b510ac
Test cases for new rules
jverdugo-aqclab Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions fortran77-rules/src/main/resources/fortran77-rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,52 @@
<languageId>fr.cnes.icode.fortran77</languageId>
<name>F77.TYPE.Hollerith</name>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.COMPRESFileLength</class>
<id>fr.cnes.icode.fortran77.rules.COMPRESFileLength</id>
<name>COM.PRES.FileLength</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.COMMETLineOfCode</class>
<id>fr.cnes.icode.fortran77.rules.COMMETLineOfCode</id>
<name>COM.MET.LineOfCode</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.COMFLOWCheckArguments</class>
<id>fr.cnes.icode.fortran77.rules.COMFLOWCheckArguments</id>
<name>COM.FLOW.CheckArguments</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.COMMETComplexitySimplified</class>
<id>fr.cnes.icode.fortran77.rules.COMMETComplexitySimplified</id>
<name>COM.MET.ComplexitySimplified</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.F77DESIGNLogicUnit</class>
<id>fr.cnes.icode.fortran77.rules.F77DESIGNLogicUnit</id>
<name>F77.DESIGN.LogicUnit</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.COMMETRatioComment</class>
<id>fr.cnes.icode.fortran77.rules.COMMETRatioComment</id>
<name>COM.MET.RatioComment</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.COMPRESData</class>
<id>fr.cnes.icode.fortran77.rules.COMPRESData</id>
<name>COM.PRES.Data</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
<check>
<class>fr.cnes.icode.fortran77.rules.F77FILEHeader</class>
Copy link
Contributor

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

Copy link
Author

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)

<id>fr.cnes.icode.fortran77.rules.F77FILEHeader</id>
<name>F77.FILE.Header</name>
<languageId>fr.cnes.icode.fortran77</languageId>
</check>
</checkers>
163 changes: 163 additions & 0 deletions fortran77-rules/src/main/resources/lex/COMFLOWCheckArguments.lex
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 fortran77-rules/src/main/resources/lex/COMMETComplexitySimplified.lex
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);
}
Loading