Skip to content

Commit

Permalink
fix missing mapping info
Browse files Browse the repository at this point in the history
  • Loading branch information
swissiety committed Oct 6, 2023
1 parent 2264537 commit 08b6ee4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import sootup.core.jimple.basic.Local;
import sootup.core.model.Body;
import sootup.core.types.*;
import sootup.core.util.Utils;
Expand Down Expand Up @@ -38,10 +39,10 @@ public void setup() {
public void testInvokeStmt() {
final Body.BodyBuilder builder = createMethodsBuilder("invokeStmt", "void");
Map<String, Type> map = new HashMap<>();
map.put("l0", classType);
map.put("l1", super1);
map.put("l2", PrimitiveType.getInt());
map.put("l3", sub2);
map.put("$l0", classType);
map.put("$l1", super1);
map.put("$l2", PrimitiveType.getInt());
map.put("$l3", sub2);
map.put("$stack4", sub1);
map.put("$stack5", sub2);
Typing typing = createTyping(builder.getLocals(), map);
Expand Down Expand Up @@ -69,9 +70,9 @@ public void testInvokeStmt() {
public void testAssignStmt() {
final Body.BodyBuilder builder = createMethodsBuilder("assignStmt", "void");
Map<String, Type> map = new HashMap<>();
map.put("l0", classType);
map.put("l1", Type.createArrayType(super1, 1));
map.put("l2", super1);
map.put("$l0", classType);
map.put("$l1", Type.createArrayType(super1, 1));
map.put("$l2", super1);
map.put("$stack3", sub1);
Typing typing = createTyping(builder.getLocals(), map);
CastCounter counter = new CastCounter(builder, function, hierarchy);
Expand All @@ -88,13 +89,16 @@ public void testAssignStmt() {
public void testInvokeStmtWithNewCasts() {
final Body.BodyBuilder builder = createMethodsBuilder("invokeStmt", "void");
Map<String, Type> map = new HashMap<>();
map.put("l0", classType);
map.put("l1", super1);
map.put("l2", PrimitiveType.getLong());
map.put("l3", super2);
map.put("$l0", classType);
map.put("$l1", super1);
map.put("$l2", PrimitiveType.getLong());
map.put("$l3", super2);
map.put("$stack4", sub1);
map.put("$stack5", sub2);
Typing typing = createTyping(builder.getLocals(), map);

final Set<Local> locals = builder.getLocals();

Typing typing = createTyping(locals, map);
CastCounter counter = new CastCounter(builder, function, hierarchy);
Assert.assertEquals(3, counter.getCastCount(typing));
counter.insertCastStmts(typing);
Expand Down Expand Up @@ -129,9 +133,9 @@ public void testInvokeStmtWithNewCasts() {
public void testAssignStmtWithNewCasts() {
final Body.BodyBuilder builder = createMethodsBuilder("assignStmt", "void");
Map<String, Type> map = new HashMap<>();
map.put("l0", classType);
map.put("l1", object);
map.put("l2", super1);
map.put("$l0", classType);
map.put("$l1", object);
map.put("$l2", super1);
map.put("$stack3", sub1);

Typing typing = createTyping(builder.getLocals(), map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.junit.Assert;
import sootup.core.jimple.basic.Local;
import sootup.core.model.Body;
import sootup.core.signatures.MethodSignature;
Expand Down Expand Up @@ -51,6 +52,14 @@ public Body.BodyBuilder createMethodsBuilder(String methodName, String returnTyp
}

public Typing createTyping(Set<Local> locals, Map<String, Type> map) {

final Optional<Local> foundOpt =
locals.stream()
.filter(local -> !map.containsKey(local.toString()))
.peek(i -> System.out.println("TEST: missing mapping for: " + i))
.findAny();
Assert.assertFalse(foundOpt.isPresent());

Typing typing = new Typing(locals);
for (Local l : typing.getLocals()) {
if (map.containsKey(l.getName())) {
Expand Down

0 comments on commit 08b6ee4

Please sign in to comment.