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

Removed graphbuilding and visitors package + structured graphs package

parent eca0b61b
No related branches found
No related tags found
1 merge request!16Add more graphs and generalize CFG and control dependence creation
Showing
with 39 additions and 122 deletions
......@@ -4,11 +4,12 @@ import org.jgrapht.io.Attribute;
import org.jgrapht.io.DefaultAttribute;
import tfm.arcs.Arc;
import tfm.graphs.augmented.ACFG;
import tfm.graphs.cfg.CFG;
import java.util.Map;
/**
* An edge of the {@link tfm.graphs.CFG}, representing the direct
* An edge of the {@link CFG}, representing the direct
* flow of control. It connects two instructions if, when the source
* is executed, one of the possible next instructions is the destination.
*/
......
package tfm.arcs.pdg;
import tfm.arcs.Arc;
import tfm.graphs.pdg.PDG;
import tfm.graphs.sdg.SDG;
/**
* An arc used in the {@link tfm.graphs.PDG} and {@link tfm.graphs.SDG}
* An arc used in the {@link PDG} and {@link SDG}
* used to represent control dependence between two nodes. The traditional definition of
* control dependence is: a node {@code a} is <it>control dependent</it> on node
* {@code b} if and only if {@code b} alters the number of times {@code a} is executed.
......
......@@ -3,12 +3,14 @@ package tfm.arcs.pdg;
import org.jgrapht.io.Attribute;
import org.jgrapht.io.DefaultAttribute;
import tfm.arcs.Arc;
import tfm.graphs.pdg.PDG;
import tfm.graphs.sdg.SDG;
import java.util.Map;
import java.util.Objects;
/**
* An arc used in the {@link tfm.graphs.PDG} and {@link tfm.graphs.SDG},
* An arc used in the {@link PDG} and {@link SDG},
* representing the declaration of some data linked to its usage (of that value).
* There is data dependency between two nodes if and only if (1) the source <it>may</it>
* declare a variable, (2) the destination <it>may</it> use it, and (3) there is a
......
package tfm.exec;
import tfm.graphs.CFG;
import tfm.graphs.cfg.CFG;
public class CFGLog extends GraphLog<CFG> {
public CFGLog() {
......
......@@ -3,10 +3,10 @@ package tfm.exec;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
import tfm.graphs.CFG;
import tfm.graphs.cfg.CFG;
import tfm.graphs.Graph;
import tfm.graphs.PDG;
import tfm.graphs.SDG;
import tfm.graphs.pdg.PDG;
import tfm.graphs.sdg.SDG;
import tfm.utils.Logger;
import tfm.utils.Utils;
......
package tfm.exec;
import tfm.graphs.PDG;
import tfm.graphs.pdg.PDG;
import tfm.nodes.GraphNode;
import tfm.utils.Logger;
......
package tfm.exec;
import tfm.graphs.SDG;
import tfm.graphs.sdg.SDG;
public class SDGLog extends GraphLog<SDG> {
public SDGLog() {
......
package tfm.graphbuilding;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.MethodDeclaration;
import tfm.graphs.CFG;
import tfm.graphs.Graph;
import tfm.graphs.PDG;
import tfm.graphs.SDG;
public abstract class GraphOptions<G extends Graph> {
public abstract G empty();
public G fromASTNode(Node node) {
G emptyGraph = empty();
buildGraphWithSpecificVisitor(emptyGraph, node);
return emptyGraph;
}
protected abstract void buildGraphWithSpecificVisitor(G emptyGraph, Node node);
}
class CFGOptions extends GraphOptions<CFG> {
@Override
public CFG empty() {
return new CFG();
}
@Override
protected void buildGraphWithSpecificVisitor(CFG emptyGraph, Node node) {
if (node instanceof MethodDeclaration) {
emptyGraph.build((MethodDeclaration) node);
} else {
for (Node n : node.getChildNodes())
buildGraphWithSpecificVisitor(emptyGraph, n);
}
}
}
class PDGOptions extends GraphOptions<PDG> {
@Override
public PDG empty() {
return new PDG();
}
@Override
protected void buildGraphWithSpecificVisitor(PDG emptyGraph, Node node) {
if (node instanceof MethodDeclaration) {
emptyGraph.build((MethodDeclaration) node);
} else {
for (Node n : node.getChildNodes())
buildGraphWithSpecificVisitor(emptyGraph, n);
}
}
}
class SDGOptions extends GraphOptions<SDG> {
@Override
public SDG empty() {
return new SDG();
}
@Override
protected void buildGraphWithSpecificVisitor(SDG emptyGraph, Node node) {
if (node instanceof CompilationUnit)
emptyGraph.build(new NodeList<>(((CompilationUnit) node)));
else
throw new IllegalStateException("The node needs to be a CompilationUnit");
}
}
\ No newline at end of file
package tfm.graphbuilding;
import tfm.graphs.CFG;
import tfm.graphs.PDG;
import tfm.graphs.SDG;
public class Graphs {
public static final GraphOptions<CFG> CFG = new CFGOptions();
public static final GraphOptions<PDG> PDG = new PDGOptions();
public static final GraphOptions<SDG> SDG = new SDGOptions();
}
\ No newline at end of file
package tfm.graphs.augmented;
import tfm.arcs.cfg.ControlFlowArc;
import tfm.graphs.CFG;
import tfm.graphs.CFGBuilder;
import tfm.graphs.cfg.CFG;
import tfm.graphs.cfg.CFGBuilder;
import tfm.nodes.GraphNode;
public class ACFG extends CFG {
......
......@@ -6,7 +6,7 @@ import com.github.javaparser.ast.expr.BooleanLiteralExpr;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitor;
import tfm.graphs.CFGBuilder;
import tfm.graphs.cfg.CFGBuilder;
import tfm.nodes.GraphNode;
import tfm.utils.ASTUtils;
......
package tfm.graphs.augmented;
import tfm.graphs.PDG;
import tfm.graphs.pdg.PDG;
public class APDG extends PDG {
public APDG() {
......
package tfm.graphs;
package tfm.graphs.cfg;
import com.github.javaparser.ast.body.MethodDeclaration;
import tfm.arcs.Arc;
import tfm.arcs.cfg.ControlFlowArc;
import tfm.graphs.GraphWithRootNode;
import tfm.nodes.GraphNode;
import tfm.utils.NodeNotFoundException;
......
package tfm.graphs;
package tfm.graphs.cfg;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
......
package tfm.visitors.pdg;
package tfm.graphs.pdg;
import tfm.arcs.Arc;
import tfm.graphs.CFG;
import tfm.graphs.PDG;
import tfm.graphs.cfg.CFG;
import tfm.graphs.pdg.PDG;
import tfm.graphs.augmented.PPDG;
import tfm.nodes.GraphNode;
import tfm.nodes.NodeFactory;
......
package tfm.visitors.pdg;
package tfm.graphs.pdg;
import com.github.javaparser.ast.stmt.*;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import tfm.graphs.CFG;
import tfm.graphs.PDG;
import tfm.graphs.cfg.CFG;
import tfm.graphs.pdg.PDG;
import tfm.nodes.GraphNode;
import tfm.variables.VariableExtractor;
import java.util.Optional;
import java.util.Set;
public class DataDependencyBuilder extends VoidVisitorAdapter<Void> {
class DataDependencyBuilder extends VoidVisitorAdapter<Void> {
private CFG cfg;
private PDG pdg;
......
package tfm.graphs;
package tfm.graphs.pdg;
import com.github.javaparser.ast.body.MethodDeclaration;
import tfm.arcs.Arc;
import tfm.arcs.pdg.ControlDependencyArc;
import tfm.arcs.pdg.DataDependencyArc;
import tfm.graphs.GraphWithRootNode;
import tfm.graphs.Sliceable;
import tfm.graphs.cfg.CFG;
import tfm.nodes.GraphNode;
import tfm.slicing.Slice;
import tfm.slicing.SlicingCriterion;
......
package tfm.graphs;
package tfm.graphs.pdg;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.stmt.BlockStmt;
import tfm.visitors.pdg.ControlDependencyBuilder;
import tfm.visitors.pdg.DataDependencyBuilder;
import tfm.graphs.cfg.CFG;
/**
* Populates a {@link PDG}, given a complete {@link CFG}, an empty {@link PDG} and an AST root node.
......
package tfm.visitors.sdg;
package tfm.graphs.sdg;
import tfm.graphs.SDG;
public class MethodCallReplacer {
class MethodCallReplacer {
private SDG sdg;
......
package tfm.visitors.sdg;
package tfm.graphs.sdg;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
......@@ -9,7 +9,7 @@ import com.github.javaparser.ast.expr.VariableDeclarationExpr;
import com.github.javaparser.ast.stmt.ExpressionStmt;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import tfm.graphs.PDG;
import tfm.graphs.pdg.PDG;
import tfm.nodes.GraphNode;
import tfm.utils.Context;
import tfm.utils.Logger;
......@@ -19,7 +19,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
public class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {
class MethodCallReplacerVisitor extends VoidVisitorAdapter<Context> {
private PDG pdg;
......
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