diff --git a/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java b/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java index 042de828d6..ea542ebda9 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/runtime/Context.java @@ -24,6 +24,8 @@ package org.overture.interpreter.runtime; import java.io.PrintWriter; +import java.util.LinkedList; +import java.util.List; import org.overture.ast.intf.lex.ILexLocation; import org.overture.ast.intf.lex.ILexNameToken; @@ -336,18 +338,19 @@ protected String format(String indent, Context what) } /** - * This is used by the stack overflow processing in Function/OperationValue. - * It is intended to print the frame titles without recursing. - * @param out + * This is used by the stack overflow processing via Function/OperationValue. + * It is intended to print the frame titles without recursing, and to + * suppress all but the top and bottom of the (presumably large) stack. */ - - private static final int FRAMES_LIMIT = 50; + private static final int FRAMES_LIMIT = 50; // Top count + private static final int TAIL_LIMIT = 5; // Bottom count public void printStackFrames(PrintWriter out) { Context frame = this; out.print(format("\t", frame)); int count = 0; + List saved = new LinkedList(); while (frame.outer != null) { @@ -355,13 +358,32 @@ public void printStackFrames(PrintWriter out) { out.println("In context of " + frame.title + " " + frame.location); } - else if (count == FRAMES_LIMIT) + else { - out.println("..."); + saved.add(String.format("In context of " + frame.title + " " + frame.location)); } frame = frame.outer; // NB. DON'T RECURSE! } + + int skipped = saved.size(); + + if (skipped < TAIL_LIMIT) + { + for (String s: saved) + { + out.println(s); + } + } + else + { + out.println("... skipped " + (skipped - TAIL_LIMIT)); + + for (int i = skipped - TAIL_LIMIT; i < skipped; i++) + { + out.println(saved.get(i)); + } + } out.println("In context of " + frame.title); }