Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed JVMSetupError inside TopLevelException datatype. #1075

Merged
merged 1 commit into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/SAWScript/Crucible/JVM/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import Verifier.SAW.TypedTerm

import Verifier.SAW.Simulator.What4.ReturnTrip

import SAWScript.Exceptions
import SAWScript.Proof
import SAWScript.Prover.SolverStats
import SAWScript.TopLevel
Expand Down Expand Up @@ -813,7 +814,9 @@ data JVMSetupError
| JVMReturnUnexpected J.Type -- found
| JVMReturnTypeMismatch J.Type J.Type -- expected, found

instance X.Exception JVMSetupError
instance X.Exception JVMSetupError where
toException = topLevelExceptionToException
fromException = topLevelExceptionFromException

instance Show JVMSetupError where
show err =
Expand Down
23 changes: 23 additions & 0 deletions src/SAWScript/Exceptions.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ScopedTypeVariables #-}

module SAWScript.Exceptions
( TypeErrors(..), failTypecheck
, TopLevelException(..)
, TraceException(..)
, topLevelExceptionToException
, topLevelExceptionFromException
) where

import Control.Exception
import Data.Typeable (cast)

import What4.ProgramLoc (ProgramLoc)

Expand All @@ -31,13 +36,31 @@ data TopLevelException
| CrucibleSetupException ProgramLoc String
| OverrideMatcherException ProgramLoc String
| LLVMMethodSpecException ProgramLoc String
| forall e. Exception e => SomeTopLevelException e

instance Show TopLevelException where
show (TopLevelException _ msg) = msg
show (JavaException _ msg) = msg
show (CrucibleSetupException _ msg) = msg
show (OverrideMatcherException _ msg) = msg
show (LLVMMethodSpecException _ msg) = msg
show (SomeTopLevelException e) = show e

-- | To use a custom structured exception type that works with the
-- saw-script REPL's exception handlers and stack tracing, define
-- 'toException' as 'topLevelExceptionToException' in the custom
-- exception type's 'Exception' class instance.
topLevelExceptionToException :: Exception e => e -> SomeException
topLevelExceptionToException = toException . SomeTopLevelException

-- | To use a custom structured exception type that works with the
-- saw-script REPL's exception handlers and stack tracing, define
-- 'fromException' as 'topLevelExceptionFromException' in the custom
-- exception type's 'Exception' class instance.
topLevelExceptionFromException :: Exception e => SomeException -> Maybe e
topLevelExceptionFromException x =
do SomeTopLevelException a <- fromException x
cast a

instance Exception TopLevelException

Expand Down