-
Notifications
You must be signed in to change notification settings - Fork 26
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
2045 cfg implement abs int driver #2050
Open
mayanje
wants to merge
21
commits into
develop
Choose a base branch
from
2045_CFGImplement_AbsIntDriver
base: develop
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 9 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
24bd256
WI #2045 Implement Abstract Interpretation
mayanje 8b88898
WI #2045 make public MultiBranchContext
mayanje 494b9d8
WI #2045 comment change
mayanje 7ae0f3c
WI #2045 Add missing file
mayanje 7e780a9
WI #2045 Change review
mayanje 95f2622
WI #2045 better handling 1 branch in multi branch case.
mayanje dc9a4c4
WI #2045 Change Review
mayanje c673a8a
WI #2045 Change Review
mayanje a840251
WI #2045 Change Review
mayanje 7f8af6b
WI #2045 Add comment on the default execution performed.
mayanje 203b206
WI #2045 Enhance abstract execution scheme with cyclic threshold
mayanje 7c56456
WI #2045 Change review
mayanje 10e4bfc
WI #2045 Add comments and missing node closure instruction.
mayanje a049ba1
WI #2045 Change Review
mayanje 98d7aaa
WI #2045 Rename variables
mayanje bac7556
WI #2045 Change Review
mayanje 1f74bae
WI #2045 Add comment
mayanje 3fb6d9d
WI #2045 Simplify abstract interpretation class (#2093)
fm-117 b2f208a
WI #2045 Add cyclic execution threshold information as methods
mayanje 80c5473
WI #2045 Use null-able return type for cyclic execution threshold value.
mayanje 9014b0d
WI #2045 Use a single method.
mayanje 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
117 changes: 117 additions & 0 deletions
117
TypeCobol.Analysis.Test/BasicAbstractInterpretationTest.cs
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,117 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using TypeCobol.Compiler.CodeModel; | ||
using TypeCobol.Compiler.Nodes; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using TypeCobol.Analysis.Graph; | ||
|
||
using static TypeCobol.Analysis.Test.CfgTestUtils; | ||
|
||
namespace TypeCobol.Analysis.Test | ||
{ | ||
/// <summary> | ||
/// These are basic tests for control from instructions. | ||
/// </summary> | ||
[TestClass] | ||
public class BasicAbstractInterpretationTest | ||
{ | ||
/// <summary> | ||
/// This is a template method for a simple test on a source file | ||
/// containing a single program. | ||
/// Performs parsing, diagnostics comparison and CFG comparison. | ||
/// </summary> | ||
/// <remarks> | ||
/// All parameters are optional, by default : | ||
/// - input is BasicCfgInstrs\[CallerMethod].cbl | ||
/// - expected result is BasicCfgInstrs\[CallerMethod].int | ||
/// - CFG building mode is Standard | ||
/// - fullInstruction is True | ||
/// </remarks> | ||
/// <param name="inputDirectoryPath">Full path to the directory containing the input source file.</param> | ||
/// <param name="inputFileName">Name of the input source file without extension.</param> | ||
/// <param name="inputExtension">Extension of the input source file including the '.'.</param> | ||
/// <param name="expectedResultDirectoryPath">Full path to the directory containing the expected result file.</param> | ||
/// <param name="expectedResultFileName">Name of the expected result file without extension.</param> | ||
/// <param name="expectedResultExtension">Extension of the expected result file including the '.'.</param> | ||
/// <param name="mode">CFG Building mode.</param> | ||
/// <param name="fullInstruction">True to use full instruction during dot generation.</param> | ||
private void TestTemplate( | ||
string inputDirectoryPath = null, | ||
[CallerMemberName] string inputFileName = null, | ||
string inputExtension = ".cbl", | ||
string expectedResultDirectoryPath = null, | ||
[CallerMemberName] string expectedResultFileName = null, | ||
string expectedResultExtension = ".int", | ||
CfgBuildingMode mode = CfgBuildingMode.Standard, | ||
bool fullInstruction = true) | ||
{ | ||
string inputFilePath = Path.Combine(inputDirectoryPath ?? BasicCfgInstrs, inputFileName + inputExtension); | ||
Assert.IsTrue(File.Exists(inputFilePath), $"Input file '{inputFilePath}' does not exist."); | ||
|
||
string expectedResultFilePath = Path.Combine(expectedResultDirectoryPath ?? BasicCfgInstrs, expectedResultFileName + expectedResultExtension); | ||
Assert.IsTrue(File.Exists(expectedResultFilePath), $"Expected results file '{expectedResultFilePath}' does not exist."); | ||
|
||
var graphs = ParseCompareDiagnostics<object>(inputFilePath, mode); | ||
Assert.IsTrue(graphs.Count == 1); //single program | ||
var cfg = graphs[0]; | ||
Assert.IsNull(cfg.ParentGraph); | ||
Assert.IsTrue(cfg.ProgramOrFunctionNode is Program); | ||
Assert.IsNull(cfg.NestedGraphs); | ||
GenAbstractInterpretCfgAndCompare(cfg, inputFilePath, expectedResultFilePath, fullInstruction); | ||
} | ||
|
||
[TestMethod] | ||
public void IfThen0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenElse0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenNested0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenNested1() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenNested2() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenElseCascade0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenElseNested1() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenNextSentence0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenElseNextSentence0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenElseNextSentence1() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void IfThenElseNextSentence2() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void Evaluate0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void EvaluateMultiWhen0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void EvaluateNoOther0() => TestTemplate(); | ||
[TestMethod] | ||
public void MixPerformEvaluateIf0() => TestTemplate(); | ||
[TestMethod] | ||
public void ComplexGotoPara0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void Declaratives0() => TestTemplate(); | ||
|
||
[TestMethod] | ||
public void Declaratives1() => TestTemplate(); | ||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
TypeCobol.Analysis.Test/BasicCfgInstrs/ComplexGotoPara0.int
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,34 @@ | ||
Entering block : 0 | ||
Leaving block : 0 | ||
Entering block : 1 | ||
DISPLAY 'IN PARA-A' | ||
GO TO PARA-C | ||
Leaving block : 1 | ||
Entering block : 4 | ||
DISPLAY 'IN PARA-C ' | ||
Leaving block : 4 | ||
Entering block : 5 | ||
GO TO PARA-E PARA-F PARA-G DEPENDING ON m | ||
Leaving block : 5 | ||
Entering block : 10 | ||
DISPLAY 'IN PARA-G ' | ||
Leaving block : 10 | ||
Entering block : 11 | ||
GOBACK | ||
Leaving block : 11 | ||
Entering block : 9 | ||
DISPLAY 'IN PARA-F ' | ||
Leaving block : 9 | ||
Entering block : 8 | ||
DISPLAY 'IN PARA-E ' | ||
Leaving block : 8 | ||
Entering block : 6 | ||
Leaving block : 6 | ||
Entering block : 7 | ||
DISPLAY 'IN PARA-D ' | ||
Leaving block : 7 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=12; NodeCount=10; ControlSubgraphCount=0; HighCyclomaticComplexity=4; HighEssentialComplexityPath=4} |
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,21 @@ | ||
Entering block : 0 | ||
Leaving block : 0 | ||
Entering block : 4 | ||
Leaving block : 4 | ||
Entering block : 5 | ||
DISPLAY "TOTO" | ||
Leaving block : 5 | ||
Entering block : 1 | ||
USE FOR DEBUGGING ON ALL PROCEDURES. | ||
Leaving block : 1 | ||
Entering block : 2 | ||
display DEBUG-NAME | ||
Leaving block : 2 | ||
Entering block : 3 | ||
EXIT | ||
Leaving block : 3 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=5; NodeCount=6; ControlSubgraphCount=0; HighCyclomaticComplexity=1; HighEssentialComplexityPath=1} |
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,74 @@ | ||
Entering block : 0 | ||
Leaving block : 0 | ||
Entering block : 17 | ||
USE FOR DEBUGGING ON ALL PROCEDURES. | ||
Leaving block : 17 | ||
Entering block : 18 | ||
Leaving block : 18 | ||
Entering block : 19 | ||
PERFORM COMP-FOOT-CALC | ||
VARYING IDX FROM +1 BY +1 | ||
UNTIL IDX > +6 | ||
Leaving block : 19 | ||
Entering block : 20 | ||
Leaving block : 20 | ||
Entering block : 21 | ||
GO TO COMP-FOOT-EXIT | ||
Leaving block : 21 | ||
Entering block : 25 | ||
EXIT | ||
Leaving block : 25 | ||
Entering block : 13 | ||
USE FOR DEBUGGING ON ALL PROCEDURES. | ||
Leaving block : 13 | ||
Entering block : 14 | ||
MOVE NUM(3) TO NBJ(3) | ||
Leaving block : 14 | ||
Entering block : 15 | ||
MOVE NBJ(4) TO NUM(4) | ||
Leaving block : 15 | ||
Entering block : 16 | ||
EXIT | ||
Leaving block : 16 | ||
Entering block : 9 | ||
USE FOR DEBUGGING ON ALL PROCEDURES. | ||
Leaving block : 9 | ||
Entering block : 10 | ||
MOVE NUM(1) TO NBJ(1) | ||
Leaving block : 10 | ||
Entering block : 11 | ||
MOVE NBJ(2) TO NUM(2) | ||
Leaving block : 11 | ||
Entering block : 12 | ||
EXIT | ||
Leaving block : 12 | ||
Entering block : 26 | ||
Leaving block : 26 | ||
Entering block : 1 | ||
USE FOR DEBUGGING ON ALL PROCEDURES. | ||
Leaving block : 1 | ||
Entering block : 2 | ||
SET IDX to 1 | ||
Leaving block : 2 | ||
Entering block : 3 | ||
SEARCH ELEM | ||
Leaving block : 3 | ||
Entering block : 6 | ||
Leaving block : 6 | ||
Entering block : 7 | ||
display "--------------------------------------" | ||
Leaving block : 7 | ||
Entering block : 8 | ||
EXIT | ||
Leaving block : 8 | ||
Entering block : 4 | ||
when NBJ(IDX) = 28 | ||
Entering block : 5 | ||
display NUM(IDX) "/" LIB(IDX) | ||
Leaving block : 5 | ||
Leaving block : 4 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=28; NodeCount=24; ControlSubgraphCount=1; HighCyclomaticComplexity=6; HighEssentialComplexityPath=5} |
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,41 @@ | ||
Entering block : 0 | ||
EVALUATE menu-input | ||
WHEN "0" | ||
Entering block : 1 | ||
DISPLAY "OPTION 0" | ||
Leaving block : 1 | ||
Entering block : 2 | ||
WHEN "1" THRU "9" | ||
Entering block : 3 | ||
DISPLAY "OPTION 1-9" | ||
Leaving block : 3 | ||
Entering block : 4 | ||
WHEN "R" | ||
Entering block : 5 | ||
DISPLAY "OPTION R" | ||
Leaving block : 5 | ||
Entering block : 6 | ||
WHEN "X" | ||
Entering block : 7 | ||
DISPLAY "OPTION X" | ||
Leaving block : 7 | ||
Entering block : 8 | ||
DISPLAY "NO OPTION" | ||
Leaving block : 8 | ||
Leaving block : 6 | ||
Entering block : 9 | ||
Leaving block : 9 | ||
Leaving block : 4 | ||
Entering block : 10 | ||
Leaving block : 10 | ||
Leaving block : 2 | ||
Entering block : 11 | ||
Leaving block : 11 | ||
Leaving block : 0 | ||
Entering block : 12 | ||
Leaving block : 12 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=16; NodeCount=13; ControlSubgraphCount=4; HighCyclomaticComplexity=5; HighEssentialComplexityPath=1} |
37 changes: 37 additions & 0 deletions
37
TypeCobol.Analysis.Test/BasicCfgInstrs/EvaluateMultiWhen0.int
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,37 @@ | ||
Entering block : 0 | ||
EVALUATE menu-input | ||
WHEN 'A' | ||
WHEN 'B' | ||
WHEN 'C' | ||
WHEN 'D' | ||
Entering block : 1 | ||
DISPLAY "OPTION [A-B]" | ||
Leaving block : 1 | ||
Entering block : 2 | ||
WHEN "E" | ||
Entering block : 3 | ||
DISPLAY "OPTION E" | ||
Leaving block : 3 | ||
Entering block : 4 | ||
WHEN "F" | ||
WHEN "G" | ||
Entering block : 5 | ||
DISPLAY "OPTION F and G" | ||
Leaving block : 5 | ||
Entering block : 6 | ||
DISPLAY "BAD OPTION" | ||
Leaving block : 6 | ||
Leaving block : 4 | ||
Entering block : 7 | ||
Leaving block : 7 | ||
Leaving block : 2 | ||
Entering block : 8 | ||
Leaving block : 8 | ||
Leaving block : 0 | ||
Entering block : 9 | ||
Leaving block : 9 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=12; NodeCount=10; ControlSubgraphCount=3; HighCyclomaticComplexity=4; HighEssentialComplexityPath=1} |
39 changes: 39 additions & 0 deletions
39
TypeCobol.Analysis.Test/BasicCfgInstrs/EvaluateNoOther0.int
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,39 @@ | ||
Entering block : 0 | ||
EVALUATE menu-input | ||
WHEN "0" | ||
Entering block : 1 | ||
DISPLAY "OPTION 0" | ||
Leaving block : 1 | ||
Entering block : 2 | ||
WHEN "1" THRU "9" | ||
Entering block : 3 | ||
DISPLAY "OPTION 1-9" | ||
Leaving block : 3 | ||
Entering block : 4 | ||
WHEN "R" | ||
Entering block : 5 | ||
DISPLAY "OPTION R" | ||
Leaving block : 5 | ||
Entering block : 6 | ||
WHEN "X" | ||
Entering block : 7 | ||
DISPLAY "OPTION X" | ||
Leaving block : 7 | ||
Leaving block : 6 | ||
Entering block : 8 | ||
Leaving block : 8 | ||
Leaving block : 4 | ||
Entering block : 9 | ||
Leaving block : 9 | ||
Leaving block : 2 | ||
Entering block : 10 | ||
Leaving block : 10 | ||
Leaving block : 0 | ||
Entering block : 11 | ||
DISPLAY "MAYBE NO OPTIONS" | ||
Leaving block : 11 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=15; NodeCount=12; ControlSubgraphCount=4; HighCyclomaticComplexity=5; HighEssentialComplexityPath=1} |
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,14 @@ | ||
Entering block : 0 | ||
IF A = 10 THEN | ||
Entering block : 1 | ||
DISPLAY "A = 10" | ||
DISPLAY "RIGHT ?" | ||
Leaving block : 1 | ||
Leaving block : 0 | ||
Entering block : 2 | ||
Leaving block : 2 | ||
|
||
======= | ||
METRICS | ||
======= | ||
{EdgeCount=3; NodeCount=3; ControlSubgraphCount=1; HighCyclomaticComplexity=2; HighEssentialComplexityPath=1} |
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.
This program gives the following result when run:
So is the result of the file the reflect of a running program or something else ?
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.
A CFG reflect all possible executions of a program. But in reality this can represent exponential possibilities, so Abstract interpretation can only be view of a subset of all possibilities.
But the most important thing here we are just implementing a driver, we don't evaluate variable value to decide for instance what to do in the instruction GO TO PARA-E PARA-F PARA-G DEPENDING ON m
depending on the value of m.
We are not intrepreting the COBOL program.
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.
The comment on the default execution performed is added. 7f8af6b
Not all possible execution paths can be followed, in this default implementation. But it is the base for other execution scheme.
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.
What about this code:
Paragraph
ADD-ITEM
is called outside of anIF
statement (just before the goback), and our custom quality rule must detect it.Does this PR handle this case?
On my execution I get:
which is not clear for me if the paragraph
ADD-ITEM
if the driver will pass on it 2 times.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.
Yes this the result:
--- Diagnostics ---
Line 9[12,27] <47, Warning, CodeAnalysis> - [Qualis] Protect table index increment (Incremented table index indX was not conditionnaly protected by IF or PERFORM UNTIL clause.)
Line 24[12,25] <47, Warning, CodeAnalysis> - [Qualis] Protect table index increment (Incremented table index indX was not conditionnaly protected by IF or PERFORM UNTIL clause.)
That is to say:
MOVE 0 TO IDX2
and
ADD 1 TO Idx2
Are detected.