Skip to content

Commit

Permalink
fix(spgroup#31): change JInstanceFieldRef to InstanceFieldRef
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Dec 11, 2020
1 parent 8e92a66 commit cf643aa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
10 changes: 5 additions & 5 deletions src/main/java/br/unb/cic/analysis/df/Collector.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package br.unb.cic.analysis.df;

import br.unb.cic.analysis.model.Conflict;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JInstanceFieldRef;

import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -11,7 +11,7 @@
class Collector {

private Set<Conflict> conflicts;
private Set<HashMap<String, JInstanceFieldRef>> instanceFieldDictionary;
private Set<HashMap<String, InstanceFieldRef>> instanceFieldDictionary;
private Set<HashMap<String, StaticFieldRef>> staticFieldDictionary;
private static Collector instance;

Expand All @@ -28,12 +28,12 @@ public static Collector instance() {
return instance;
}

public Set<HashMap<String, JInstanceFieldRef>> getHashJInstanceField() {
public Set<HashMap<String, InstanceFieldRef>> getHashInstanceField() {
return instanceFieldDictionary;
}

public void addHashJInstanceField(HashMap<String, JInstanceFieldRef> hash) {
instanceFieldDictionary.add(hash) ;
public void addHashInstanceField(HashMap<String, InstanceFieldRef> hash) {
instanceFieldDictionary.add(hash);
}

public Set<HashMap<String, StaticFieldRef>> getHashStaticField() {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/br/unb/cic/analysis/df/DataFlowAbstraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import br.unb.cic.analysis.model.Statement;
import soot.Local;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JInstanceFieldRef;

import java.util.*;
import java.util.Objects;

/**
* Information wee keep while traversing
Expand All @@ -14,7 +14,7 @@
public class DataFlowAbstraction {

private Local local;
private JInstanceFieldRef localField;
private InstanceFieldRef localField;
private StaticFieldRef localStaticRef;
private Statement stmt;

Expand All @@ -23,7 +23,7 @@ public DataFlowAbstraction(Local local, Statement stmt) {
this.stmt = stmt;
}

public DataFlowAbstraction(JInstanceFieldRef localField, Statement stmt) {
public DataFlowAbstraction(InstanceFieldRef localField, Statement stmt) {
this.localField = localField;
this.stmt = stmt;
}
Expand All @@ -41,9 +41,10 @@ public StaticFieldRef getLocalStaticRef() {
return localStaticRef;
}

public JInstanceFieldRef getFieldRef() {
public InstanceFieldRef getFieldRef() {
return localField;
}

public Statement getStmt() {
return stmt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import br.unb.cic.analysis.model.Conflict;
import br.unb.cic.analysis.model.Statement;
import soot.*;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JArrayRef;
import soot.jimple.internal.JInstanceFieldRef;
Expand Down Expand Up @@ -210,13 +211,13 @@ private Value getArrayRefName(JArrayRef arrayRef) {
}

/*
* If it's a JInstanceField, returns your complete name from the hashMapJInstanceField
* If it's a InstanceField, returns your complete name from the hashMapInstanceField
*/
private JInstanceFieldRef getFieldName(ValueBox valueBox){
JInstanceFieldRef fieldValue = (JInstanceFieldRef) valueBox.getValue();
private InstanceFieldRef getFieldName(ValueBox valueBox) {
InstanceFieldRef fieldValue = (InstanceFieldRef) valueBox.getValue();
if (fieldValue.toString().contains("$stack")) {
String chainName = getFieldsChain(valueBox.getValue().toString()); //return the complete chain with the FieldRef
((Local) fieldValue.getBase()).setName(chainName.replace("."+fieldValue.getField().toString(), "")); //remove the double FieldRef from jInstanceFieldValue
((Local) fieldValue.getBase()).setName(chainName.replace("." + fieldValue.getField().toString(), "")); //remove the double FieldRef from jInstanceFieldValue
}
return fieldValue;
}
Expand Down Expand Up @@ -291,15 +292,15 @@ private String getArrayChain(ValueBox valueBox){
* InitialKey($stack8.a) -> nextKey ($stack8) -> nextKey ($stack3) -> object.b has no nextKey (STOP) -> Return object chain -> Return: object.b.a.a
*/
private String getFieldsChain(String nextKey){
List<HashMap<String, JInstanceFieldRef>> auxValuesHashMap = new ArrayList<>();
List<HashMap<String, InstanceFieldRef>> auxValuesHashMap = new ArrayList<>();
auxValuesHashMap.addAll(getHashMapJInstanceField());

//If nextKey not contain $stack is because simple key
if (!(nextKey.contains("$stack"))){
return nextKey;
}

JInstanceFieldRef currentField = null;
InstanceFieldRef currentField = null;

//The second position is the field called
String currentUniqueKey = "<"+nextKey.split(".<")[1];
Expand All @@ -313,7 +314,7 @@ private String getFieldsChain(String nextKey){

Iterator iterator = auxValuesHashMap.iterator();
while (iterator.hasNext() && !isNextKey){
HashMap<String, JInstanceFieldRef> auxMap = (HashMap<String, JInstanceFieldRef>) iterator.next();
HashMap<String, InstanceFieldRef> auxMap = (HashMap<String, InstanceFieldRef>) iterator.next();
for (String mapKey : auxMap.keySet()) {
if (mapKey.equals(nextKey)) {
currentField = auxMap.get(mapKey);
Expand All @@ -339,13 +340,13 @@ private String getFieldsChain(String nextKey){


/*
* Generates the dictionary with the UseBoxes instances of JInstanceFieldRef or StaticFieldRef
* Generates the dictionary with the UseBoxes instances of InstanceFieldRef or StaticFieldRef
*/
public void generateFieldDictionary(Unit u){
for (ValueBox valueBox: u.getUseBoxes()) {
if (valueBox.getValue() instanceof JInstanceFieldRef) {
if (valueBox.getValue() instanceof InstanceFieldRef) {
generateClassFieldDictionary(getStatementAssociatedWithUnit(u));
}else if (valueBox.getValue() instanceof StaticFieldRef) {
} else if (valueBox.getValue() instanceof StaticFieldRef) {
generateStaticRefDictionary(u, valueBox);
}
}
Expand All @@ -368,20 +369,20 @@ private void generateStaticRefDictionary(Unit u, ValueBox valueBox){
* Generates a dictionary to JInstanceFieldRef
*/
private void generateClassFieldDictionary(Statement stmt){
HashMap<String, JInstanceFieldRef> auxHashMap = new HashMap<>();
HashMap<String, InstanceFieldRef> auxHashMap = new HashMap<>();
StringBuilder strKey = new StringBuilder();
for (ValueBox valueBoxKey : stmt.getUnit().getDefBoxes()) {
strKey.append(valueBoxKey.getValue().toString());
}
JInstanceFieldRef currentFieldRef = null;
InstanceFieldRef currentFieldRef = null;
for (ValueBox catchRef : stmt.getUnit().getUseBoxes()) {
if (catchRef.getValue() instanceof JInstanceFieldRef) {
currentFieldRef = (JInstanceFieldRef) catchRef.getValue();
if (catchRef.getValue() instanceof InstanceFieldRef) {
currentFieldRef = (InstanceFieldRef) catchRef.getValue();
auxHashMap.put(strKey.toString(), currentFieldRef);
}
}
if (auxHashMap.size() != 0) {
Collector.instance().addHashJInstanceField(auxHashMap);
Collector.instance().addHashInstanceField(auxHashMap);
}
}
}
42 changes: 21 additions & 21 deletions src/main/java/br/unb/cic/analysis/df/ReachDefinitionAnalysis.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package br.unb.cic.analysis.df;

import java.util.*;
import java.util.stream.Collectors;

import br.unb.cic.analysis.AbstractAnalysis;
import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import br.unb.cic.analysis.model.Conflict;
import br.unb.cic.analysis.model.Statement;
import soot.Body;
import soot.Local;
import soot.Unit;
import soot.ValueBox;
import soot.jimple.InstanceFieldRef;
import soot.jimple.StaticFieldRef;
import soot.jimple.internal.JArrayRef;
import soot.jimple.internal.JInstanceFieldRef;
Expand All @@ -18,7 +17,8 @@
import soot.toolkits.scalar.FlowSet;
import soot.toolkits.scalar.ForwardFlowAnalysis;

import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import java.util.*;
import java.util.stream.Collectors;

/**
* Intraprocedural dataflow analysis for identifying
Expand Down Expand Up @@ -176,28 +176,28 @@ protected boolean isSourceStatement(Unit d) {

protected boolean isSinkStatement(Unit d) {
return definition.getSinkStatements().stream().map(s -> s.getUnit()).collect(Collectors.toList()).contains(d);
}
}

public void clear() {
Collector.instance().clear();
}
public void clear() {
Collector.instance().clear();
}

public Set<Conflict> getConflicts() {
return Collector.instance().getConflicts();
}
public Set<Conflict> getConflicts() {
return Collector.instance().getConflicts();
}

public Set<HashMap<String, JInstanceFieldRef>> getHashMapJInstanceField() {
return Collector.instance().getHashJInstanceField();
}
public Set<HashMap<String, InstanceFieldRef>> getHashMapJInstanceField() {
return Collector.instance().getHashInstanceField();
}

public Set<HashMap<String, StaticFieldRef>> getHashMapStatic() {
return Collector.instance().getHashStaticField();
}
public Set<HashMap<String, StaticFieldRef>> getHashMapStatic() {
return Collector.instance().getHashStaticField();
}

protected List<Local> getUseVariables(Unit u) {
return u.getUseBoxes().stream()
.map(box -> box.getValue())
.filter(v -> v instanceof Local)
protected List<Local> getUseVariables(Unit u) {
return u.getUseBoxes().stream()
.map(box -> box.getValue())
.filter(v -> v instanceof Local)
.map(v -> (Local)v)
.collect(Collectors.toList());
}
Expand Down

0 comments on commit cf643aa

Please sign in to comment.