Skip to content

Commit

Permalink
fix(spgroup#31): change JInstanceFieldRef to InstanceFieldRef and JAr…
Browse files Browse the repository at this point in the history
…rayRef to ArrayRef
  • Loading branch information
barbosamaatheus committed Dec 17, 2020
1 parent cf643aa commit 307fd80
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import br.unb.cic.analysis.model.Conflict;
import br.unb.cic.analysis.model.Statement;
import soot.*;
import soot.jimple.ArrayRef;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JArrayRef;
import soot.jimple.internal.JInstanceFieldRef;
import soot.toolkits.scalar.ArraySparseSet;
import soot.toolkits.scalar.FlowSet;

Expand Down Expand Up @@ -80,13 +79,13 @@ protected FlowSet<DataFlowAbstraction> gen(Unit u, FlowSet<DataFlowAbstraction>
if (isLeftStatement(u) || isRightStatement(u)) {
Statement stmt = getStatementAssociatedWithUnit(u);
u.getDefBoxes().forEach(valueBox -> {
if (valueBox.getValue() instanceof Local){
if (valueBox.getValue() instanceof Local) {
res.add(new DataFlowAbstraction((Local) valueBox.getValue(), stmt));
} else if (valueBox.getValue() instanceof JArrayRef){
} else if (valueBox.getValue() instanceof ArrayRef) {
res.add(new DataFlowAbstraction(getArrayName(valueBox), stmt));
} else if (valueBox.getValue() instanceof StaticFieldRef) {
} else if (valueBox.getValue() instanceof StaticFieldRef) {
res.add(new DataFlowAbstraction((StaticFieldRef) valueBox.getValue(), stmt));
} else if (valueBox.getValue() instanceof JInstanceFieldRef){
} else if (valueBox.getValue() instanceof InstanceFieldRef) {
res.add(new DataFlowAbstraction(getFieldName(valueBox), stmt));
}
});
Expand Down Expand Up @@ -139,11 +138,11 @@ private void checkConflicts(Unit u, List<DataFlowAbstraction> potentialConflicti
private boolean abstractionVariableIsInIUnitDefBoxes(DataFlowAbstraction dataFlowAbstraction, Unit u) {
for (ValueBox valueBox : u.getDefBoxes()) {
Object value = valueBox.getValue();
if (value instanceof JInstanceFieldRef && dataFlowAbstraction.getFieldRef()!=null) {
if (value instanceof InstanceFieldRef && dataFlowAbstraction.getFieldRef() != null) {
return dataFlowAbstraction.getFieldRef().toString().equals(getFieldsChain(value.toString()));
} else if (value instanceof JArrayRef && value.toString().contains("$stack")) { // If contain $stack, contain a array chain
} else if (value instanceof ArrayRef && value.toString().contains("$stack")) { // If contain $stack, contain a array chain
return getVarNameFromAbstraction(dataFlowAbstraction).equals(getArrayChain(valueBox));
} else{
} else {
return getVarNameFromAbstraction(dataFlowAbstraction).equals(getVarNameFromValueBox(valueBox));
}
}
Expand Down Expand Up @@ -174,8 +173,8 @@ private String getVarNameFromValueBox(ValueBox valueBox) {
varNameValueBox = getLocalName((Local) valueBox.getValue());
} else if (valueBox.getValue() instanceof StaticFieldRef) {
varNameValueBox = getStaticName((StaticFieldRef) valueBox.getValue());
} else if (valueBox.getValue() instanceof JArrayRef) {
varNameValueBox = getArrayRefName((JArrayRef) valueBox.getValue()).toString();
} else if (valueBox.getValue() instanceof ArrayRef) {
varNameValueBox = getArrayRefName((ArrayRef) valueBox.getValue()).toString();
}
return varNameValueBox;
}
Expand Down Expand Up @@ -206,7 +205,7 @@ private String getLocalName(Local local) {
* of the variable used to assign an array;
* e.g: int[] arr = {0, 1}; --> "arr"
*/
private Value getArrayRefName(JArrayRef arrayRef) {
private Value getArrayRefName(ArrayRef arrayRef) {
return arrayRef.getBaseBox().getValue();
}

Expand All @@ -227,7 +226,7 @@ private InstanceFieldRef getFieldName(ValueBox valueBox) {
* Else, returns the Array Name
*/
private Local getArrayName(ValueBox valueBox){
Local localName = (Local) getArrayRefName((JArrayRef) valueBox.getValue());
Local localName = (Local) getArrayRefName((ArrayRef) valueBox.getValue());
if (localName.toString().contains("$stack")) {
localName.setName(getArrayChain(valueBox));
}
Expand All @@ -244,7 +243,7 @@ private String getStaticName(StaticFieldRef staticField) {
}

/*
* Returns the name of the JArrayRef
* Returns the name of the ArrayRef
* The Jimple code is divided in others units
* Example:
* static int[] y;
Expand All @@ -259,7 +258,7 @@ private String getStaticName(StaticFieldRef staticField) {
* $stack2[0] -> $stack2 = <className: int[] y> -> (STOP) -> Result: <className: int[] y>
*/
private String getArrayChain(ValueBox valueBox){
String nextKey = ((JArrayRef) valueBox.getValue()).getBase().toString();
String nextKey = ((ArrayRef) valueBox.getValue()).getBase().toString();
for (HashMap<String, StaticFieldRef> auxMap : getHashMapStatic()) {
for (String mapKey : auxMap.keySet()) {
if (mapKey.equals(nextKey)) {
Expand Down Expand Up @@ -366,7 +365,7 @@ private void generateStaticRefDictionary(Unit u, ValueBox valueBox){
}

/*
* Generates a dictionary to JInstanceFieldRef
* Generates a dictionary to InstanceFieldRef
*/
private void generateClassFieldDictionary(Statement stmt){
HashMap<String, InstanceFieldRef> auxHashMap = new HashMap<>();
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/br/unb/cic/analysis/df/ReachDefinitionAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import soot.Local;
import soot.Unit;
import soot.ValueBox;
import soot.jimple.ArrayRef;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JArrayRef;
import soot.jimple.internal.JInstanceFieldRef;
import soot.toolkits.graph.ExceptionalUnitGraph;
import soot.toolkits.scalar.ArraySparseSet;
import soot.toolkits.scalar.FlowSet;
Expand Down Expand Up @@ -205,16 +204,15 @@ protected List<Local> getUseVariables(Unit u) {
protected List<Local> getDefVariables(Unit u) {
List<Local> localDefs = new ArrayList<>();
for (ValueBox v : u.getDefBoxes()) {
if (v.getValue() instanceof Local) {
localDefs.add((Local) v.getValue());
} else if (v.getValue() instanceof JArrayRef) {
JArrayRef ref = (JArrayRef) v.getValue();
localDefs.add((Local) ref.getBaseBox().getValue());
}
else if (v.getValue() instanceof JInstanceFieldRef) {
JInstanceFieldRef ref = (JInstanceFieldRef) v.getValue();
localDefs.add((Local) ref.getBaseBox().getValue());
}
if (v.getValue() instanceof Local) {
localDefs.add((Local) v.getValue());
} else if (v.getValue() instanceof ArrayRef) {
ArrayRef ref = (ArrayRef) v.getValue();
localDefs.add((Local) ref.getBaseBox().getValue());
} else if (v.getValue() instanceof InstanceFieldRef) {
InstanceFieldRef ref = (InstanceFieldRef) v.getValue();
localDefs.add((Local) ref.getBaseBox().getValue());
}
}
return localDefs;
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/br/unb/cic/analysis/df/TaintedAnalysis.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package br.unb.cic.analysis.df;

import soot.*;
import soot.jimple.internal.JArrayRef;
import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import soot.Body;
import soot.Local;
import soot.Unit;
import soot.toolkits.scalar.ArraySparseSet;
import soot.toolkits.scalar.FlowSet;

import br.unb.cic.analysis.AbstractMergeConflictDefinition;

import java.util.List;

public class TaintedAnalysis extends ReachDefinitionAnalysis {

/**
Expand Down

0 comments on commit 307fd80

Please sign in to comment.