diff --git a/core/src/main/java/org/teavm/ast/analysis/LocationGraphBuilder.java b/core/src/main/java/org/teavm/ast/analysis/LocationGraphBuilder.java index 2ea8e54ae..175e87532 100644 --- a/core/src/main/java/org/teavm/ast/analysis/LocationGraphBuilder.java +++ b/core/src/main/java/org/teavm/ast/analysis/LocationGraphBuilder.java @@ -23,6 +23,7 @@ import com.carrotsearch.hppc.ObjectIntHashMap; import com.carrotsearch.hppc.ObjectIntMap; import java.util.ArrayList; import java.util.Arrays; +import java.util.BitSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -59,7 +60,11 @@ public final class LocationGraphBuilder { Visitor visitor = new Visitor(); node.acceptVisitor(visitor); Graph graph = visitor.builder.build(); - TextLocation[][] locations = propagate(visitor.locations.toArray(new TextLocation[0]), graph); + for (int terminal : visitor.nodes) { + visitor.terminalNodes.set(terminal); + } + TextLocation[][] locations = propagate(visitor.locations.toArray(new TextLocation[0]), graph, + visitor.terminalNodes); Map> builder = new LinkedHashMap<>(); for (int i = 0; i < graph.size(); ++i) { @@ -70,6 +75,11 @@ public final class LocationGraphBuilder { } } } + if (visitor.terminalNodes.get(i)) { + for (TextLocation loc : locations[i]) { + builder.computeIfAbsent(loc, k -> new LinkedHashSet<>()).add(null); + } + } } Map result = new LinkedHashMap<>(); @@ -79,7 +89,7 @@ public final class LocationGraphBuilder { return result; } - private static TextLocation[][] propagate(TextLocation[] locations, Graph graph) { + private static TextLocation[][] propagate(TextLocation[] locations, Graph graph, BitSet terminal) { List> result = new ArrayList<>(); boolean[] stop = new boolean[graph.size()]; IntDeque queue = new IntArrayDeque(); @@ -117,6 +127,7 @@ public final class LocationGraphBuilder { IdentifiedStatement defaultContinueTarget; GraphBuilder builder = new GraphBuilder(); List locations = new ArrayList<>(); + BitSet terminalNodes = new BitSet(); @Override protected void afterVisit(Expr expr) { @@ -265,6 +276,9 @@ public final class LocationGraphBuilder { public void visit(ReturnStatement statement) { super.visit(statement); setLocation(statement.getLocation()); + for (int node : nodes) { + terminalNodes.set(node); + } nodes = EMPTY; } diff --git a/core/src/main/java/org/teavm/debugging/Debugger.java b/core/src/main/java/org/teavm/debugging/Debugger.java index 1f92e36f6..59876b807 100644 --- a/core/src/main/java/org/teavm/debugging/Debugger.java +++ b/core/src/main/java/org/teavm/debugging/Debugger.java @@ -108,6 +108,7 @@ public class Debugger { return jsStep(enterMethod); } Set successors = new HashSet<>(); + boolean first = true; for (CallFrame frame : callStack) { boolean exits; String script = frame.getOriginalLocation().getScript(); @@ -129,7 +130,13 @@ public class Debugger { if (!exits) { break; } - enterMethod = true; + enterMethod = false; + if (!first && frame.getLocation() != null) { + for (GeneratedLocation location : debugInfo.getGeneratedLocations(frame.getLocation())) { + successors.add(new JavaScriptLocation(script, location.getLine(), location.getColumn())); + } + } + first = false; } List> jsBreakpointPromises = new ArrayList<>();