Skip to content
Snippets Groups Projects
Commit 3e27b98f authored by Javier Costa's avatar Javier Costa
Browse files

Some fixes

parent 05a959c4
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@ package tfm.programs.pdg;
import tfm.utils.Logger;
import java.util.Arrays;
public class Example1 {
public static void main(String[] args) {
......@@ -62,4 +60,14 @@ public class Example1 {
Logger.log(e);
}
// public static void main2() {
// int x = 4;
// int z = 2;
// int p = x;
//
// int t = z * p;
//
// Logger.log(t);
// }
}
......@@ -184,29 +184,6 @@ public class CFGVisitor extends VoidVisitorAdapter<Void> {
lastParentNodes.add(switchNode);
// List<CFGNode> lastEntryParents = new ArrayList<>();
//
// switchStmt.getEntries().forEach(entry -> {
// Optional<BreakStmt> entryBreak = entry.findFirst(BreakStmt.class, breakStmt -> {
// Optional<Node> parent = breakStmt.getParentNode();
//
// return parent.isPresent() && parent.get() .equals(entry);
// });
//
// new BlockStmt(entry.getStatements()).accept(this, arg);
//
// if (entryBreak.isPresent()) {
// while (!lastParentNodes.isEmpty()) {
// lastEntryParents.add(lastParentNodes.poll());
// }
// }
//
// lastParentNodes.add(switchNode);
// });
//
// lastParentNodes.clear();
// lastParentNodes.addAll(lastEntryParents);
List<CFGNode> allEntryBreaks = new ArrayList<>();
List<CFGNode> lastEntryStatementsWithNoBreak = new ArrayList<>();
......@@ -257,9 +234,13 @@ public class CFGVisitor extends VoidVisitorAdapter<Void> {
@Override
public void visit(MethodDeclaration methodDeclaration, Void arg) {
if (!lastParentNodes.isEmpty() && Objects.equals(lastParentNodes.peek().getData(), "Stop")) {
throw new IllegalStateException("CFG is only allowed for one method, not multiple!");
}
super.visit(methodDeclaration, arg);
addNodeAndArcs("Stop", new EmptyStmt());
lastParentNodes.add(addNodeAndArcs("Stop", new EmptyStmt()));
}
private CFGNode addNodeAndArcs(String nodeData, Statement statement) {
......
package tfm.visitors;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.stmt.ExpressionStmt;
import tfm.graphs.PDGGraph;
import tfm.nodes.PDGNode;
import tfm.scopes.Scope;
import tfm.scopes.ScopeHolder;
import tfm.scopes.VariableScope;
import tfm.variables.VariableExtractor;
public class LoopDataVisitor extends PDGVisitor {
Scope<PDGNode> firstDeclarationScope;
public LoopDataVisitor(PDGGraph graph, ScopeHolder<PDGNode> scopeHolder) {
super(graph, scopeHolder);
}
@Override
public void visit(ExpressionStmt expressionStmt, ScopeHolder<PDGNode> scope) {
// new VariableExtractor()
// .setOnVariableDefinitionListener(variable -> {
// if (firstDeclarationScope != null) {
//
// }
// }).setOnVariableUseListener(variable -> {
// expressionScope.addVariableUse(variable, expressionNode);
//
// Scope<PDGNode> searchScope = scope.isVariableDefined(variable) ? scope : globalScope;
//
// searchScope.getLastDefinitions(variable)
// .forEach(variableDefinition -> graph.addDataDependencyArc(
// variableDefinition.getNode(),
// expressionNode,
// variable
// ));
// })
// .visit(expression);
}
}
package tfm.visitors;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
......@@ -39,8 +40,6 @@ public class PDGCFGVisitor extends VoidVisitorAdapter<PDGNode> {
}
public void visit(MethodDeclaration methodDeclaration, PDGNode parent) {
methodDeclaration.accept(new CFGVisitor(cfgGraph), null);
if (!methodDeclaration.getBody().isPresent())
return;
......@@ -54,4 +53,13 @@ public class PDGCFGVisitor extends VoidVisitorAdapter<PDGNode> {
DataDependencyVisitor dataDependencyVisitor = new DataDependencyVisitor(pdgGraph, cfgGraph);
blockStmt.accept(dataDependencyVisitor, null);
}
@Override
public void visit(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, PDGNode parent) {
// build CFG
classOrInterfaceDeclaration.accept(new CFGVisitor(cfgGraph), null);
// Visit normally...
super.visit(classOrInterfaceDeclaration, parent);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment