-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
97 additions
and
11 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
58 changes: 58 additions & 0 deletions
58
smojol-toolkit/src/main/java/org/smojol/analysis/graph/GraphPatternMatcher.java
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,58 @@ | ||
package org.smojol.analysis.graph; | ||
|
||
import com.mojo.woof.GraphSDK; | ||
import lombok.Getter; | ||
import org.eclipse.lsp.cobol.core.CobolParser; | ||
import org.smojol.common.flowchart.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GraphPatternMatcher implements FlowNodeVisitor { | ||
private final GraphSDK sdk; | ||
@Getter | ||
private final List<List<FlowNode>> matches = new ArrayList<>(); | ||
private List<FlowNode> currentMatch = new ArrayList<>(); | ||
|
||
public GraphPatternMatcher(GraphSDK sdk) { | ||
this.sdk = sdk; | ||
} | ||
|
||
@Override | ||
public void visit(FlowNode node, List<FlowNode> outgoingNodes, List<FlowNode> incomingNodes, VisitContext context, FlowNodeService nodeService) { | ||
System.out.println(String.format("Visiting %s", node)); | ||
if (node.type() == FlowNodeType.SENTENCE && node.astChildren().size() == 1 && node.astChildren().getFirst().type() == FlowNodeType.MOVE) { | ||
registerMove(node); | ||
return; | ||
} | ||
if (currentMatch.isEmpty()) return; | ||
matches.add(currentMatch); | ||
currentMatch = new ArrayList<>(); | ||
} | ||
|
||
private void registerMove(FlowNode node) { | ||
currentMatch.add(node); | ||
} | ||
|
||
@Override | ||
public void visitParentChildLink(FlowNode parent, FlowNode internalTreeRoot, VisitContext ctx, FlowNodeService nodeService) { | ||
} | ||
|
||
@Override | ||
public void visitParentChildLink(FlowNode parent, FlowNode internalTreeRoot, VisitContext ctx, FlowNodeService nodeService, FlowNodeCondition hideStrategy) { | ||
} | ||
|
||
@Override | ||
public void visitControlTransfer(FlowNode from, FlowNode to, VisitContext visitContext) { | ||
} | ||
|
||
@Override | ||
public FlowNodeVisitor newScope(FlowNode enclosingScope) { | ||
return this; | ||
} | ||
|
||
@Override | ||
public void group(FlowNode root) { | ||
|
||
} | ||
} |
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
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
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