Skip to content

Commit

Permalink
Tidy user cancel and stack overflow again
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Nov 19, 2024
1 parent 5a97255 commit 6455805
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 1 addition & 3 deletions vdmj/src/main/java/com/fujitsu/vdmj/runtime/Breakpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public class Breakpoint implements Serializable
public static final int SOURCE = 0; // A file:line source breakpoint
public static final int FUNCTION = 1; // A function or operation name breakpoint

public static final int USER_CANCEL = 4999; // Special message for timeouts

public Breakpoint(LexLocation location)
{
this.location = location;
Expand Down Expand Up @@ -231,7 +229,7 @@ public void check(LexLocation execl, Context ctxt)

case TERMINATE:
setExecInterrupt(Breakpoint.NONE);
throw new ContextException(USER_CANCEL, "Execution cancelled", location, ctxt);
ContextException.throwUserCancel(location, ctxt);
}

ThreadState state = ctxt.threadState;
Expand Down
15 changes: 13 additions & 2 deletions vdmj/src/main/java/com/fujitsu/vdmj/runtime/ContextException.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
@SuppressWarnings("serial")
public class ContextException extends RuntimeException
{
public static final int STACK_OVERFLOW = 4998;
private static final int STACK_OVERFLOW = 4998;
private static final int USER_CANCEL = 4999;

public final LexLocation location;
public final Context ctxt;
Expand All @@ -56,13 +57,23 @@ public String toString()
return getMessage();
}

public static void throwStackOverflow(LexLocation from, Context ctxt) throws ContextException
{
throw new ContextException(STACK_OVERFLOW, "Stack overflow", from, ctxt);
}

public boolean isStackOverflow()
{
return number == STACK_OVERFLOW;
}

public static void throwUserCancel(LexLocation from, Context ctxt) throws ContextException
{
throw new ContextException(USER_CANCEL, "Execution cancelled", from, ctxt);
}

public boolean isUserCancel()
{
return number == Breakpoint.USER_CANCEL;
return number == USER_CANCEL;
}
}
6 changes: 4 additions & 2 deletions vdmj/src/main/java/com/fujitsu/vdmj/values/FunctionValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ public Value eval(
catch (StackOverflowError e)
{
clearData();
throw new ContextException(ContextException.STACK_OVERFLOW, "Stack overflow", location, ctxt);
ContextException.throwStackOverflow(location, ctxt);
return null; // No reached
}
}

Expand All @@ -366,7 +367,8 @@ public Value eval(
catch (StackOverflowError e)
{
clearData();
throw new ContextException(ContextException.STACK_OVERFLOW, "Stack overflow", location, ctxt);
ContextException.throwStackOverflow(location, ctxt);
return null; // No reached
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ public Value eval(LexLocation from, ValueList argValues, Context ctxt)
}
catch (StackOverflowError e)
{
throw new ContextException(ContextException.STACK_OVERFLOW, "Stack overflow", from, ctxt);
ContextException.throwStackOverflow(from, ctxt);
return null; // No reached
}
}

Expand Down

0 comments on commit 6455805

Please sign in to comment.