The main goal of this work is to develop a Java slicer. This is done by building a System Dependence Graph of the program being sliced
Find Main class (tfm/exec), modify static fields of the class (the program being analyzed, the graph to build, etc.) and execute it. You will find the output in tfm/out as a png image
Find Slice class (tfm/slicing), set the program path and execute. The sliced program will be in tfm/out
Graphs are built using a library called JGraphT.
The main class is the Graph class, which extends from JGraphT's DefaultDirectedGraph class. This class includes some general interest methods (like toString, etc.)
Every graph has a set of nodes and arrows. GraphNode and Arc classes are used to represent them respectively.
A set of visitors is implemented for many things, such as graph building, data dependence building, etc... (available in tfm/visitors)
A bunch of programs are written in tfm/programs, you can write more there.
Some naive testing is implemented in the tfm/validation folder. Currently, a PDG can be compared with a program to check their equality.
Some util methods are available in tfm/utils (such as AST utils, logger, etc.)
Forget about the tfm/scopes folder, it was an idea I had to discard and it has to be deleted.
-
Graphs (
tfm/graphs)- CFGGraph
- PDGGraph
- SDGGraph
-
Nodes (
tfm/nodes)CFGNode, PDGNode, SDGNode(Deprecated)- GraphNode
- MethodCallNode (idk if this is necessary, maybe it can be deleted)
-
Arcs (
tfm/arcs)- ControlFlowArc
- DataDependencyArc
- ControlDependencyArc
-
Visitors (
tfm/visitors)- CFGBuilder
PDGVisitor(Deprecated, it was an intent to build a PDG with no CFG needed)- PDGBuilder
- ControlDependencyBuilder
- DataDependencyBuilder
- SDGBuilder (Probably deprecated)
- NewSDGBuilder -Work in progress-
- MethodCallReplacerVisitor (Replaces method call nodes with in and out variable nodes) -Work in progress-
- CFG: Done!
- PDG: Done!
- SDG: PDGs are built for each method
- Expressions (ExpressionStmt)
- If (IfStmt)
- While, DoWhile (WhileStmt, DoStmt)
- For, Foreach (ForStmt, ForeachStmt)
- Switch (SwitchStmt, SwitchEntryStmt)
- Break (BreakStmt)
- Continue (ContinueStmt)
- Replace method call nodes with in and out variables nodes and build arrows for them
- Build summary arrows
- Switch to a (much) better graph library like JGraphT. It also supports graph visualization (done).
- Performance review
- Make a test suite (test graph building, slicing, etc.)
- Add support to more Java language features (lambdas, etc.)
public class Example {
public CFG buildCFG(File programFile) {
// Always disable attribution of comments, just in case
JavaParser.getStaticConfiguration().setAttributeComments(false);
Node astRoot = JavaParser.parse(programFile);
Optional<MethodDeclaration> optMethod = astRoot.findFirst(MethodDeclaration.class);
if (!optMethod.isPresent)
throw new RuntimeException("No method could be found");
// Creates a new graph representing the program
CFG cfg = new CFG();
cfg.build(optMethod.get());
return cfg;
}
}public class Example {
public PDGGraph getSlice(File program, SlicingCriterion slicingCriterion) {
// Always disable attribution of comments, just in case
JavaParser.getStaticConfiguration().setAttributeComments(false);
Node astRoot = JavaParser.parse(programFile);
Optional<MethodDeclaration> optMethod = astRoot.findFirst(MethodDeclaration.class);
if (!optMethod.isPresent)
throw new RuntimeException("No method could be found");
// Creates a new graph representing the program
PDG pdg = new PDG();
pdg.build(optMethod.get());
// Slice PDG
return pdg.slice(slicingCriterion);
}
}- Branches:
master(only for stable versions)develop(main branch)<issue number>-name
- Discover a new feature/fix
- Open an issue describing it and assign it
- Create a new branch from
developwith the same name as the issue number (e.g. for issue #12 the new branch is called12) - Write the solution to the issue
- Once resolved, open a pull request from the issue branch to
developbranch - Finally, when pull request is merged, remove branch