Skip to content

Commit

Permalink
Merge pull request #974 from soot-oss/improvevisitorux
Browse files Browse the repository at this point in the history
enable to chain the acceptors with the given visitor
  • Loading branch information
kadirayk authored Aug 5, 2024
2 parents e234d1d + 4420354 commit e8381d1
Show file tree
Hide file tree
Showing 94 changed files with 279 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ public boolean equivTo(Object o, @Nonnull JimpleComparator comparator) {
}

@Override
public void accept(@Nonnull ExprVisitor exprVisitor) {}
public ExprVisitor accept(@Nonnull ExprVisitor exprVisitor) {
return exprVisitor;
}
};
CGEdgeUtil.findCallGraphEdgeType(jNewInvoke);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@
import sootup.core.types.ClassType;
import sootup.core.types.Type;

public class InstantiateClassValueVisitor extends AbstractValueVisitor<ClassType> {
public class InstantiateClassValueVisitor extends AbstractValueVisitor {

protected ClassType result = null;

public ClassType getResult() {
return result;
}

protected void setResult(ClassType result) {
this.result = result;
}

public void init() {
setResult(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import sootup.core.jimple.visitor.AbstractExprVisitor;

/** Visitor for expressions in the AST. */
class AstExprVisitor extends AbstractExprVisitor<Void> {
class AstExprVisitor extends AbstractExprVisitor {
private final PropertyGraph.Builder graphBuilder;
private final PropertyGraphNode parentNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import sootup.core.jimple.visitor.AbstractStmtVisitor;

/** Visitor for statements in the AST. */
class AstStmtVisitor extends AbstractStmtVisitor<Void> {
class AstStmtVisitor extends AbstractStmtVisitor {
private final PropertyGraph.Builder graphBuilder;
private final PropertyGraphNode parentNode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ public List<Stmt> getDefsForLocalUse(StmtGraph<?> graph, Stmt stmt) {
}

@Override
public void accept(@Nonnull ImmediateVisitor v) {
public <V extends ImmediateVisitor> V accept(@Nonnull V v) {
v.caseLocal(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public Local generateParameterLocal(@Nonnull Type type, int index) {
return this.parameterLocals.get(index);
}

private static class NamingSwitch extends AbstractTypeVisitor<StringBuilder> {
private static class NamingSwitch extends AbstractTypeVisitor {
protected StringBuilder result = null;
private int tempInt = 0;
private int tempBoolean = 0;
private int tempLong = 0;
Expand Down Expand Up @@ -171,6 +172,14 @@ public void caseUnknownType() {
public void defaultCaseType() {
throw new IllegalStateException("Unhandled Type of Local variable to Generate!");
}

public StringBuilder getResult() {
return result;
}

protected void setResult(StringBuilder result) {
this.result = result;
}
}

/** Return all locals created for the body referenced in this LocalGenrator. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseBooleanConstant(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseClassConstant(this);
return v;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseDoubleConstant(this);
return v;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseEnumConstant(this);
return v;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseFloatConstant(this);
return v;
}

public float getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseIntConstant(this);
return v;
}

public int getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseLongConstant(this);
return v;
}

public long getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ public SootClassMemberSignature<? extends SootClassMemberSubSignature> getRefere
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseMethodHandle(this);
return v;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public boolean equals(Object obj) {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseMethodType(this);
return v;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseNullConstant(this);
return v;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ConstantVisitor v) {
public <V extends ConstantVisitor> V accept(@Nonnull V v) {
v.caseStringConstant(this);
return v;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseAddExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseAndExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ public Type getType() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseCastExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseCmpExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseCmpgExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseCmplExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseDivExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ private String getNamelessSubSig(MethodSubSignature mSubSig) {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseDynamicInvokeExpr(this);
return v;
}

/** Returns a list args of type Value. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseEqExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseGeExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseGtExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public Type getCheckType() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseInstanceOfExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ public void toString(@Nonnull StmtPrinter up) {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseInterfaceInvokeExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseLeExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public PrimitiveType getType() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseLengthExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseLtExpr(this);
return v;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public final String getSymbol() {
}

@Override
public void accept(@Nonnull ExprVisitor v) {
public <V extends ExprVisitor> V accept(@Nonnull V v) {
v.caseMulExpr(this);
return v;
}

@Nonnull
Expand Down
Loading

0 comments on commit e8381d1

Please sign in to comment.