org.kit.furia.fragment.soot
Class FragmentBuilder
java.lang.Object
org.kit.furia.fragment.soot.FragmentBuilder
public class FragmentBuilder
- extends java.lang.Object
FragmentBuilder builds new fragments out of a soot method. At first, it
creates a graph representation of the method, and from there the
fragmentation can be executed
- Author:
- Arnoldo Jose Muller Molina
Constructor Summary |
FragmentBuilder(soot.Body body,
soot.toolkits.graph.BlockGraph graph,
int maxAllowedSize,
int minAllowedSize)
|
Method Summary |
void |
fillRepetitionCounts(java.util.HashMap<java.lang.String,IntegerHolder> repetitionCounts)
Fills a hash map that contains the fragment and number of occurrences. |
int |
getHugeSlices()
|
java.lang.String |
getMethodName()
|
java.util.Map<soot.Value,soot.ValueBox> |
getSlices()
|
int |
getSmallSlices()
public String generateStringSpecial(boolean debugSlices) throws Exception {
StringBuilder result = new StringBuilder(); // if(debugSlices){
result.append("// Method: " + getMethodName() + "\n"); // } Iterator <
Value > keys = slices.keySet().iterator(); Stack < SliceAST > stack = new
Stack < SliceAST >(); while (keys.hasNext()) { Value keyValue =
keys.next(); Value value = slices.get(keyValue).getValue(); String slice =
Frimp.toQ(value); SliceAST s = SliceFactory.createSliceASTLean(slice);
s.getSize(); result.append(microSliceString(s)); } return
result.toString(); } public static void doMicroSlice(SliceAST s,
LinkedList < SliceAST > result) { if (!isPhi(s)) { result.add(s);
microSliceAux(s, result); } else { splitPhi(s, result); } } protected
static void microSliceAux(SliceAST s, LinkedList < SliceAST > res) {
SliceAST down = (SliceAST) s.getFirstChild(); boolean hadPhi = false; if
(down != null) { if (isPhi(down)) { // 1) remove it
s.setFirstChild(down.getNextSibling()); // 2) create new slices out of
down splitPhi(down, res); hadPhi = true; } else { microSliceAux(down,
res); } } SliceAST right = (SliceAST) s.getNextSibling(); if (right !=
null) { if (isPhi(right)) { // 1) remove it
s.setNextSibling(right.getNextSibling()); // 2) create new slices out of
right splitPhi(right, res); hadPhi = true; } else { microSliceAux(right,
res); } } if (hadPhi) { microSliceAux(s, res); // need to execute again } }
protected static void splitPhi(SliceAST s, LinkedList < SliceAST > res) {
SliceAST t = s.getLeftmostChild(); assert isPhi(s); while (t != null) {
SliceAST a = t; t = (SliceAST) t.getNextSibling();
a.setNextSibling(null); // we have to create a new slice doMicroSlice(a,
res); // creates new slices } } protected static boolean isPhi(SliceAST
s) { return s.getText().equals(FuriaConstructDefinitions.FURIA_fphi); }
public static String microSliceString(SliceAST s) { LinkedList < SliceAST >
result = new LinkedList < SliceAST >(); doMicroSlice(s, result); Iterator <
SliceAST > it = result.iterator(); StringBuilder res = new
StringBuilder(); while (it.hasNext()) { SliceAST t = it.next();
res.append(t.toQ()); res.append("\n"); } String r = res.toString();
assert !r.contains("p"); return r; } |
int |
getTotalSlices()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
FragmentBuilder
public FragmentBuilder(soot.Body body,
soot.toolkits.graph.BlockGraph graph,
int maxAllowedSize,
int minAllowedSize)
getSlices
public java.util.Map<soot.Value,soot.ValueBox> getSlices()
getTotalSlices
public int getTotalSlices()
getHugeSlices
public int getHugeSlices()
getMethodName
public java.lang.String getMethodName()
fillRepetitionCounts
public void fillRepetitionCounts(java.util.HashMap<java.lang.String,IntegerHolder> repetitionCounts)
throws IRException
- Fills a hash map that contains the fragment and number of occurrences.
- Parameters:
result
-
- Throws:
java.lang.Exception
IRException
getSmallSlices
public int getSmallSlices()
- public String generateStringSpecial(boolean debugSlices) throws Exception {
StringBuilder result = new StringBuilder(); // if(debugSlices){
result.append("// Method: " + getMethodName() + "\n"); // } Iterator <
Value > keys = slices.keySet().iterator(); Stack < SliceAST > stack = new
Stack < SliceAST >(); while (keys.hasNext()) { Value keyValue =
keys.next(); Value value = slices.get(keyValue).getValue(); String slice =
Frimp.toQ(value); SliceAST s = SliceFactory.createSliceASTLean(slice);
s.getSize(); result.append(microSliceString(s)); } return
result.toString(); } public static void doMicroSlice(SliceAST s,
LinkedList < SliceAST > result) { if (!isPhi(s)) { result.add(s);
microSliceAux(s, result); } else { splitPhi(s, result); } } protected
static void microSliceAux(SliceAST s, LinkedList < SliceAST > res) {
SliceAST down = (SliceAST) s.getFirstChild(); boolean hadPhi = false; if
(down != null) { if (isPhi(down)) { // 1) remove it
s.setFirstChild(down.getNextSibling()); // 2) create new slices out of
down splitPhi(down, res); hadPhi = true; } else { microSliceAux(down,
res); } } SliceAST right = (SliceAST) s.getNextSibling(); if (right !=
null) { if (isPhi(right)) { // 1) remove it
s.setNextSibling(right.getNextSibling()); // 2) create new slices out of
right splitPhi(right, res); hadPhi = true; } else { microSliceAux(right,
res); } } if (hadPhi) { microSliceAux(s, res); // need to execute again } }
protected static void splitPhi(SliceAST s, LinkedList < SliceAST > res) {
SliceAST t = s.getLeftmostChild(); assert isPhi(s); while (t != null) {
SliceAST a = t; t = (SliceAST) t.getNextSibling();
a.setNextSibling(null); // we have to create a new slice doMicroSlice(a,
res); // creates new slices } } protected static boolean isPhi(SliceAST
s) { return s.getText().equals(FuriaConstructDefinitions.FURIA_fphi); }
public static String microSliceString(SliceAST s) { LinkedList < SliceAST >
result = new LinkedList < SliceAST >(); doMicroSlice(s, result); Iterator <
SliceAST > it = result.iterator(); StringBuilder res = new
StringBuilder(); while (it.hasNext()) { SliceAST t = it.next();
res.append(t.toQ()); res.append("\n"); } String r = res.toString();
assert !r.contains("p"); return r; }
Copyright © 2008 Arnoldo Jose Muller Molina. All Rights Reserved.