Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getUses and getDefs #258

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public final List<ValueBox> getUseBoxes() {
return Collections.emptyList();
}

// new method
@Override
public final List<Value> getUses() {
return Collections.emptyList();
}

@Override
public void accept(Visitor sw) {
((JimpleValueVisitor) sw).caseLocal(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public interface Value extends Acceptor, EquivTo {
*/
List<ValueBox> getUseBoxes();

// new method
/** Returns a List Values which are used by (ie contained within) this Value. */
List<Value> getUses();

/** Returns the Soot type of this Value. */
Type getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ default List<ValueBox> getUseBoxes() {
return Collections.emptyList();
}

@Override
default List<Value> getUses() {
return Collections.emptyList();
}

@Override
default boolean equivTo(Object o, JimpleComparator comparator) {
return comparator.caseConstant(this, o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ public abstract class AbstractBinopExpr implements Expr {
private final ValueBox op1Box;
private final ValueBox op2Box;

// new attributes
private Value op1;
private Value op2;

AbstractBinopExpr(ValueBox op1Box, ValueBox op2Box) {
this.op1Box = op1Box;
this.op2Box = op2Box;

// new attributes
this.op1 = op1Box.getValue();
this.op2 = op2Box.getValue();
}

public Value getOp1() {
Expand Down Expand Up @@ -69,6 +77,16 @@ public final List<ValueBox> getUseBoxes() {
return list;
}

// new method
@Override
public final List<Value> getUses() {
List<Value> list = new ArrayList<>(op1.getUses());
list.add(op1);
list.addAll(op2.getUses());
list.add(op2);
return list;
}

@Override
public boolean equivTo(Object o, JimpleComparator comparator) {
return comparator.caseAbstractBinopExpr(this, o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public abstract class AbstractInstanceInvokeExpr extends AbstractInvokeExpr {

private final ValueBox baseBox;

// new attribute
private Value base;

AbstractInstanceInvokeExpr(ValueBox baseBox, MethodSignature methodSig, ValueBox[] argBoxes) {
super(methodSig, argBoxes);
this.baseBox = baseBox;
// new attribute
this.base = baseBox.getValue();
}

public Value getBase() {
Expand All @@ -66,6 +71,23 @@ public List<ValueBox> getUseBoxes() {
return list;
}

// new method
@Override
public List<Value> getUses() {
List<Value> list = new ArrayList<>();
// getArgs in super class must be modified (not yet)
List<Value> args = getArgs();
if (args != null) {
list.addAll(args);
for (Value arg : args) {
list.addAll(arg.getUses());
}
}
list.addAll(base.getUses());
list.add(base);
return list;
}

@Override
public void accept(Visitor sw) {
((ExprVisitor) sw).caseInstanceInvokeExpr(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public abstract class AbstractInvokeExpr implements Expr {

private final MethodSignature methodSignature;
private final ValueBox[] argBoxes;
// new attribute
private Value[] args;

protected AbstractInvokeExpr(MethodSignature method, ValueBox[] argBoxes) {
this.methodSignature = method;
this.argBoxes = argBoxes.length == 0 ? null : argBoxes;

// new attribute
this.args = Arrays.stream(argBoxes).map(ValueBox::getValue).toArray(Value[]::new);
}

public MethodSignature getMethodSignature() {
Expand Down Expand Up @@ -94,6 +99,20 @@ public List<ValueBox> getUseBoxes() {
return list;
}

// new method
@Override
public List<Value> getUses() {
if (args == null) {
return Collections.emptyList();
}
List<Value> list = new ArrayList<>();
Collections.addAll(list, args);
for (Value arg : args) {
list.addAll(arg.getUses());
}
return list;
}

protected void argBoxesToString(StringBuilder builder) {
if (argBoxes != null) {
final int len = argBoxes.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@

public abstract class AbstractUnopExpr implements Expr {
private final ValueBox opBox;
// new attribute
private Value op;

AbstractUnopExpr(ValueBox opBox) {
this.opBox = opBox;
// new attribute
this.op = opBox.getValue();
}

public Value getOp() {
Expand All @@ -54,4 +58,12 @@ public final List<ValueBox> getUseBoxes() {

return list;
}

@Override
public final List<Value> getUses() {
List<Value> list = new ArrayList<>(op.getUses());
list.add(op);

return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public final class JCastExpr implements Expr, Copyable {

private final ValueBox opBox;
private final Type type;
// new attribute
private final Value op;

public JCastExpr(Value op, Type type) {
this.opBox = Jimple.newImmediateBox(op);
this.type = type;
// new attribute
this.op = op;
}

@Override
Expand Down Expand Up @@ -90,6 +94,15 @@ public final List<ValueBox> getUseBoxes() {
return list;
}

// new method
@Override
public final List<Value> getUses() {
List<Value> list = new ArrayList<>(op.getUses());
list.add(op);

return list;
}

@Override
public Type getType() {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ public final class JInstanceOfExpr implements Expr, Copyable {
private final ValueBox opBox;
private final Type checkType;

// new attribute
private Value op;

public JInstanceOfExpr(Value op, Type checkType) {
this.opBox = Jimple.newImmediateBox(op);
this.checkType = checkType;
// new attribute;
this.op = op;
}

@Override
Expand Down Expand Up @@ -91,6 +96,13 @@ public final List<ValueBox> getUseBoxes() {

return list;
}
// new method
@Override
public final List<Value> getUses() {
List<Value> list = new ArrayList<>(op.getUses());
list.add(op);
return list;
}

@Override
public Type getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ public final class JNewArrayExpr implements Expr, Copyable {
private final Type baseType;
private final ValueBox sizeBox;
private final IdentifierFactory identifierFactory;
// new attribute
private Value size;

public JNewArrayExpr(Type baseType, Value size, IdentifierFactory identifierFactory) {
this.baseType = baseType;
this.sizeBox = Jimple.newImmediateBox(size);
this.identifierFactory = identifierFactory;
// new attribute
this.size = size;
}

private static Type simplify(Type baseType, IdentifierFactory identifierFactory) {
Expand Down Expand Up @@ -122,6 +126,14 @@ public final List<ValueBox> getUseBoxes() {
return useBoxes;
}

// new method
@Override
public final List<Value> getUses() {
List<Value> uses = new ArrayList<>(size.getUses());
uses.add(size);
return uses;
}

/** Returns an instance of ArrayType(). */
@Override
public Type getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import de.upb.swt.soot.core.jimple.Jimple;
import de.upb.swt.soot.core.jimple.basic.JimpleComparator;
import de.upb.swt.soot.core.jimple.basic.Value;
import de.upb.swt.soot.core.jimple.basic.ValueBox;
import de.upb.swt.soot.core.jimple.visitor.ExprVisitor;
import de.upb.swt.soot.core.jimple.visitor.Visitor;
Expand Down Expand Up @@ -85,6 +86,12 @@ public List<ValueBox> getUseBoxes() {
return Collections.emptyList();
}

// new method
@Override
public List<Value> getUses() {
return Collections.emptyList();
}

@Override
public void accept(Visitor sw) {
((ExprVisitor) sw).caseNewExpr(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import de.upb.swt.soot.core.util.Copyable;
import de.upb.swt.soot.core.util.printer.StmtPrinter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
Expand All @@ -45,6 +46,8 @@ public final class JNewMultiArrayExpr implements Expr, Copyable {

private final ArrayType baseType;
private final ValueBox[] sizeBoxes;
// new attribute
private Value[] sizes;

/**
* Initiates a JNewMultiArrayExpr.
Expand All @@ -58,6 +61,8 @@ public JNewMultiArrayExpr(ArrayType type, List<? extends Value> sizes) {
for (int i = 0; i < sizes.size(); i++) {
sizeBoxes[i] = Jimple.newImmediateBox(sizes.get(i));
}
// new attribute
this.sizes = Arrays.stream(sizeBoxes).map(ValueBox::getValue).toArray(Value[]::new);
}

@Override
Expand Down Expand Up @@ -148,6 +153,17 @@ public final List<ValueBox> getUseBoxes() {
return list;
}

// new method
@Override
public final List<Value> getUses() {
List<Value> list = new ArrayList<>();
Collections.addAll(list, sizes);
for (Value size : sizes) {
list.addAll(size.getUses());
}
return list;
}

@Override
public Type getType() {
return baseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public final class JArrayRef implements ConcreteRef, Copyable {
private final ValueBox indexBox;
private final IdentifierFactory identifierFactory;

// new attributes
private Value base;
private Value index;

public JArrayRef(Value base, Value index, IdentifierFactory identifierFactory) {
this(Jimple.newLocalBox(base), Jimple.newImmediateBox(index), identifierFactory);
}
Expand All @@ -55,6 +59,9 @@ private JArrayRef(ValueBox baseBox, ValueBox indexBox, IdentifierFactory identif
this.baseBox = baseBox;
this.indexBox = indexBox;
this.identifierFactory = identifierFactory;
// new attributes;
this.base = baseBox.getValue();
this.index = indexBox.getValue();
}

private Type determineType(IdentifierFactory identifierFactory) {
Expand Down Expand Up @@ -139,6 +146,16 @@ public List<ValueBox> getUseBoxes() {
return useBoxes;
}

// new method
@Override
public List<Value> getUses() {
List<Value> list = new ArrayList<>(base.getUses());
list.add(base);
list.addAll(index.getUses());
list.add(index);
return list;
}

@Override
public Type getType() {
return determineType(identifierFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package de.upb.swt.soot.core.jimple.common.ref;

import de.upb.swt.soot.core.jimple.basic.JimpleComparator;
import de.upb.swt.soot.core.jimple.basic.Value;
import de.upb.swt.soot.core.jimple.basic.ValueBox;
import de.upb.swt.soot.core.jimple.visitor.Visitor;
import de.upb.swt.soot.core.types.Type;
Expand Down Expand Up @@ -67,6 +68,11 @@ public void toString(StmtPrinter up) {
public final List<ValueBox> getUseBoxes() {
return Collections.emptyList();
}
// new method
@Override
public final List<Value> getUses() {
return Collections.emptyList();
}

@Override
public Type getType() {
Expand Down
Loading