module GOOL.Drasil.CodeAnalysis (
  ExceptionType(..), Exception(loc, exc), printExc, hasLoc, exception, stdExc,
  HasException(..)
) where

-- Eq is needed so that the same exception doesn't get added multiple times 
-- to the list of exceptions for a given method.
data ExceptionType = Standard | FileNotFound | IO deriving ExceptionType -> ExceptionType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExceptionType -> ExceptionType -> Bool
$c/= :: ExceptionType -> ExceptionType -> Bool
== :: ExceptionType -> ExceptionType -> Bool
$c== :: ExceptionType -> ExceptionType -> Bool
Eq

-- Stores exception information
data Exception = Exc {
  Exception -> String
loc :: String, -- import string where the exception is defined
  Exception -> String
exc :: String -- name of the exception
}

printExc :: Exception -> String
printExc :: Exception -> String
printExc (Exc String
l String
e) = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
l then String
e else String
l forall a. [a] -> [a] -> [a]
++ String
"." forall a. [a] -> [a] -> [a]
++ String
e

hasLoc :: Exception -> Bool
hasLoc :: Exception -> Bool
hasLoc (Exc [] String
_) = Bool
False
hasLoc (Exc (Char
_:String
_) String
_) = Bool
True

exception :: String -> String -> Exception
exception :: String -> String -> Exception
exception = String -> String -> Exception
Exc

stdExc :: String -> Exception
stdExc :: String -> Exception
stdExc = String -> String -> Exception
Exc String
""

class HasException r where
  toConcreteExc :: ExceptionType -> r Exception