Skip to content

Commit

Permalink
refactor(spgroup#31): pr adjuts
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Oct 6, 2021
1 parent ce62ba7 commit 77f532e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
// TODO Do not add anything when assignments are equal.
public class InterproceduralOverrideAssignment extends SceneTransformer implements AbstractAnalysis {

private final Set<Conflict> conflicts;
private final PointsToAnalysis pointsToAnalysis;
private final List<SootMethod> traversedMethods;
private final AbstractMergeConflictDefinition definition;
private final FlowSet<DataFlowAbstraction> left;
private final FlowSet<DataFlowAbstraction> right;
private Set<Conflict> conflicts;
private PointsToAnalysis pointsToAnalysis;
private List<SootMethod> traversedMethods;
private AbstractMergeConflictDefinition definition;
private FlowSet<DataFlowAbstraction> left;
private FlowSet<DataFlowAbstraction> right;
private List<TraversedLine> stacktraceList;

private final Logger logger;
Expand Down Expand Up @@ -76,13 +76,8 @@ protected void internalTransform(String s, Map<String, String> map) {
List<SootMethod> methods = Scene.v().getEntryPoints();
methods.forEach(sootMethod -> traverse(new ArraySparseSet<>(), sootMethod, Statement.Type.IN_BETWEEN));

Set<Conflict> conflictsFilter = new HashSet<>();
filterConflicts(getConflicts(), conflictsFilter);

logger.log(Level.INFO, () -> String.format("%s", "Number of conflicts filter: " + conflictsFilter.size()));
conflictsFilter.forEach(conflict -> {
logger.log(Level.INFO, conflict.toStringAbstract());
});
Set<Conflict> conflictsFilter = filterConflicts(getConflicts());
conflictsFilter.forEach(conflict -> logger.log(Level.INFO, conflict.toStringAbstract()));

//logger.log(Level.INFO, () -> String.format("%s", "CONFLICTS: " + conflictsFilter));

Expand All @@ -97,7 +92,8 @@ protected void internalTransform(String s, Map<String, String> map) {
}); */
}

private void filterConflicts(Set<Conflict> conflictsResults, Set<Conflict> conflictsFilter) {
private Set<Conflict> filterConflicts(Set<Conflict> conflictsResults) {
Set<Conflict> conflictsFilter = new HashSet<>();
conflictsResults.forEach(conflict -> {
if (conflictsFilter.isEmpty()) {
conflictsFilter.add(conflict);
Expand All @@ -108,6 +104,7 @@ private void filterConflicts(Set<Conflict> conflictsResults, Set<Conflict> confl
}
});
});
return conflictsFilter;
}

/**
Expand Down Expand Up @@ -190,7 +187,7 @@ private FlowSet<DataFlowAbstraction> runAnalysis(FlowSet<DataFlowAbstraction> in
AssignStmt assignStmt = (AssignStmt) unit;

if (assignStmt.containsInvokeExpr()) {
return executeCallGraph(in, flowChangeTag, unit, sootMethod);
return executeCallGraph(in, flowChangeTag, unit);
}

separeteAbstraction(in);
Expand Down Expand Up @@ -221,7 +218,7 @@ In this case, this condition will be executed for the call to the foo() method a
For builders, InvokeExpression is an instance of InvokeSpecial */

} else if (unit instanceof InvokeStmt) {
return executeCallGraph(in, flowChangeTag, unit, sootMethod);
return executeCallGraph(in, flowChangeTag, unit);
}

return in;
Expand All @@ -241,11 +238,11 @@ private void separeteAbstraction(FlowSet<DataFlowAbstraction> in) {
}

private FlowSet<DataFlowAbstraction> executeCallGraph(FlowSet<DataFlowAbstraction> in,
Statement.Type flowChangeTag, Unit unit, SootMethod sootMethod) {
Statement.Type flowChangeTag, Unit unit) {
CallGraph callGraph = Scene.v().getCallGraph();
Iterator<Edge> edges = callGraph.edgesOutOf(unit);

List<FlowSet<DataFlowAbstraction>> flowSetList = new ArrayList<FlowSet<DataFlowAbstraction>>();
List<FlowSet<DataFlowAbstraction>> flowSetList = new ArrayList<>();

while (edges.hasNext()) {
Edge e = edges.next();
Expand All @@ -258,7 +255,9 @@ private FlowSet<DataFlowAbstraction> executeCallGraph(FlowSet<DataFlowAbstractio
}

FlowSet<DataFlowAbstraction> flowSetUnion = new ArraySparseSet<>();
flowSetList.forEach(flowSet -> flowSetUnion.union(flowSet));
for (FlowSet<DataFlowAbstraction> flowSet : flowSetList) {
flowSetUnion.union(flowSet);
}

return flowSetUnion;
}
Expand Down Expand Up @@ -388,7 +387,7 @@ private Statement getStatementAssociatedWithUnit(SootMethod sootMethod, Unit u,
}

private void setStackTraceInStmt(Statement stmt) {
stmt.setTraversedLine(new ArrayList<TraversedLine>(this.stacktraceList));
stmt.setTraversedLine(new ArrayList<>(this.stacktraceList));
}

private void addStackTrace(TraversedLine traversedLine) {
Expand All @@ -400,12 +399,7 @@ private void removeStackTrace(TraversedLine traversedLine) {
}

private boolean isBothUnitOrBothStatementFlow(Unit u, Statement.Type flowChangeTag) {
if (isRightUnit(u) && isInLeftStatementFlow(flowChangeTag)) {
return true;
} else if (isLeftUnit(u) && isInRightStatementFlow(flowChangeTag)) {
return true;
}
return false;
return (isRightUnit(u) && isInLeftStatementFlow(flowChangeTag)) || (isLeftUnit(u) && isInRightStatementFlow(flowChangeTag));
}

private boolean isLeftUnit(Unit u) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ private void configureSootOptions(List<String> testClasses) {
Options.v().set_include(getIncludeList());
}

@Test
public void StringArraySample() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.StringArraySample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{11}, new int[]{22});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
}

@Test
public void stacktraceConflictSample() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package br.unb.cic.analysis.samples.ioa;

public class StringArraySample {

protected static final String[] python2Keywords = {
"abs", "all", "any", "apply", "as",
"bin", "bool", "buffer", "bytearray",
"callable", "chr", "classmethod", "coerce", "compile", "complex",
"del", "delattr", "dict", "dir", "divmod", // LEFT
"enumerate", "eval", "execfile",
"file", "filter", "float", "format", "frozenset",
"getattr", "globals",
"hasattr", "hash", "help", "hex",
"id", "input", "int", "intern", "isinstance", "issubclass", "iter",
"len", "list", "locals",
"map", "max", "min", "next",
"memoryview",
"object", "oct", "open", "ord",
"pow", "print", "property",
"range", "raw_input", "reduce", "reload", "repr", "return", "reversed", "round", // RIGHT
"set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super",
"tuple", "type",
"unichr", "unicode",
"vars",
"with",
"xrange",
"zip",
"__import__",
"True", "False", "None"
};
}

0 comments on commit 77f532e

Please sign in to comment.