diff --git a/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java b/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java index 62c95cb3d..aef99bbb6 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java +++ b/teavm-core/src/main/java/org/teavm/debugging/DebugInformation.java @@ -178,24 +178,6 @@ public class DebugInformation { return null; } - public GeneratedLocation getNearestCallSite(GeneratedLocation location) { - int keyIndex = indexByKey(callSiteMapping, location); - if (keyIndex < 0) { - keyIndex = 0; - } - while (keyIndex < callSiteMapping.values.length) { - int valueIndex = callSiteMapping.values[keyIndex]; - if (valueIndex >= 0) { - MethodReference method = getExactMethod(valueIndex); - if (method != null) { - return new GeneratedLocation(callSiteMapping.lines[keyIndex], callSiteMapping.columns[keyIndex]); - } - } - ++keyIndex; - } - return null; - } - public MethodReference getCallSite(GeneratedLocation location) { int keyIndex = indexByKey(callSiteMapping, location); if (keyIndex < 0) { diff --git a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java index 6f148b6f5..0929833a0 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java @@ -103,11 +103,7 @@ public class Debugger { DebugInformation debugInfo = debugInformationMap.get(script); if (frame.getLocation() != null && debugInfo != null) { exits = false; - MethodReference callMethod = null; - GeneratedLocation callSiteLoc = debugInfo.getNearestCallSite(genLoc); - if (callSiteLoc != null) { - callMethod = debugInfo.getCallSite(callSiteLoc); - } + MethodReference callMethod = debugInfo.getCallSite(genLoc); exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet(), successors); if (enterMethod && callMethod != null) { diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index e89f37d5e..3a192a373 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -52,6 +52,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext private DebugInformationEmitter debugEmitter = new DummyDebugInformationEmitter(); private Deque locationStack = new ArrayDeque<>(); private DeferredCallSite lastCallSite; + private DeferredCallSite prevCallSite; private static class InjectorHolder { public final Injector injector; @@ -601,11 +602,13 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext if (statement.getLocation() != null) { pushLocation(statement.getLocation()); } + prevCallSite = debugEmitter.emitCallSite(); if (statement.getLeftValue() != null) { statement.getLeftValue().acceptVisitor(this); writer.ws().append("=").ws(); } statement.getRightValue().acceptVisitor(this); + debugEmitter.emitEmptyCallSite(); writer.append(";").softNewLine(); if (statement.getLocation() != null) { popLocation(); @@ -634,8 +637,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext if (statement.getCondition().getLocation() != null) { pushLocation(statement.getCondition().getLocation()); } + prevCallSite = debugEmitter.emitCallSite(); writer.append("if").ws().append("("); statement.getCondition().acceptVisitor(this); + debugEmitter.emitEmptyCallSite(); writer.append(")").ws().append("{").softNewLine().indent(); if (statement.getCondition().getLocation() != null) { popLocation(); @@ -670,8 +675,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext if (statement.getId() != null) { writer.append(statement.getId()).append(": "); } + prevCallSite = debugEmitter.emitCallSite(); writer.append("switch").ws().append("("); statement.getValue().acceptVisitor(this); + debugEmitter.emitEmptyCallSite(); writer.append(")").ws().append("{").softNewLine().indent(); for (SwitchClause clause : statement.getClauses()) { for (int condition : clause.getConditions()) { @@ -704,7 +711,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext } writer.append("while").ws().append("("); if (statement.getCondition() != null) { + prevCallSite = debugEmitter.emitCallSite(); statement.getCondition().acceptVisitor(this); + debugEmitter.emitEmptyCallSite(); } else { writer.append("true"); } @@ -783,7 +792,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext writer.append("return"); if (statement.getResult() != null) { writer.append(' '); + prevCallSite = debugEmitter.emitCallSite(); statement.getResult().acceptVisitor(this); + debugEmitter.emitEmptyCallSite(); } writer.append(";").softNewLine(); if (statement.getLocation() != null) { @@ -801,8 +812,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext pushLocation(statement.getLocation()); } writer.append("$rt_throw("); + prevCallSite = debugEmitter.emitCallSite(); statement.getException().acceptVisitor(this); writer.append(");").softNewLine(); + debugEmitter.emitEmptyCallSite(); if (statement.getLocation() != null) { popLocation(); } @@ -1299,16 +1312,15 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext String className = naming.getNameFor(expr.getMethod().getClassName()); String name = naming.getNameFor(expr.getMethod()); String fullName = naming.getFullNameFor(expr.getMethod()); - DeferredCallSite callSite = null; + DeferredCallSite callSite = prevCallSite; boolean shouldEraseCallSite = lastCallSite == null; + if (lastCallSite == null) { + lastCallSite = callSite; + } switch (expr.getType()) { case STATIC: - callSite = debugEmitter.emitCallSite(); - if (lastCallSite == null) { - lastCallSite = callSite; - } writer.append(fullName).append("("); - debugEmitter.emitEmptyCallSite(); + prevCallSite = debugEmitter.emitCallSite(); for (int i = 0; i < expr.getArguments().size(); ++i) { if (i > 0) { writer.append(",").ws(); @@ -1318,12 +1330,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext writer.append(')'); break; case SPECIAL: - callSite = debugEmitter.emitCallSite(); - if (lastCallSite == null) { - lastCallSite = callSite; - } writer.append(fullName).append("("); - debugEmitter.emitEmptyCallSite(); + prevCallSite = debugEmitter.emitCallSite(); expr.getArguments().get(0).acceptVisitor(this); for (int i = 1; i < expr.getArguments().size(); ++i) { writer.append(",").ws(); @@ -1333,12 +1341,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext break; case DYNAMIC: expr.getArguments().get(0).acceptVisitor(this); - callSite = debugEmitter.emitCallSite(); - if (lastCallSite == null) { - lastCallSite = callSite; - } writer.append(".").append(name).append("("); - debugEmitter.emitEmptyCallSite(); + prevCallSite = debugEmitter.emitCallSite(); for (int i = 1; i < expr.getArguments().size(); ++i) { if (i > 1) { writer.append(",").ws(); @@ -1348,12 +1352,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext writer.append(')'); break; case CONSTRUCTOR: - callSite = debugEmitter.emitCallSite(); - if (lastCallSite == null) { - lastCallSite = callSite; - } writer.append(className).append(".").append(name).append("("); - debugEmitter.emitEmptyCallSite(); + prevCallSite = debugEmitter.emitCallSite(); for (int i = 0; i < expr.getArguments().size(); ++i) { if (i > 0) { writer.append(",").ws();