-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exceptions.hs
68 lines (63 loc) · 3.33 KB
/
Exceptions.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- This file is part of FairCheck
--
-- FairCheck is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published
-- by the Free Software Foundation, either version 3 of the License,
-- or (at your option) any later version.
--
-- FairCheck is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with FairCheck. If not, see <http://www.gnu.org/licenses/>.
--
-- Copyright 2021 Luca Padovani
-- |Representation of FairCheck-specific syntax and typing errors.
module Exceptions where
import Atoms
import Type (Type)
import Render ()
import Control.Exception (Exception)
import qualified Data.List as List
-- |The type of FairCheck exceptions.
data MyException
= ErrorSyntax String
| ErrorMultipleTypeDefinitions TypeName
| ErrorMultipleProcessDefinitions ProcessName
| ErrorMultipleNameDeclarations ChannelName
| ErrorUnknownIdentifier String String
| ErrorActionUnbounded ProcessName
| ErrorCastUnbounded ProcessName ChannelName
| ErrorSessionUnbounded ProcessName ChannelName
| ErrorTypeUnbounded ChannelName
| ErrorTypeNonContractive TypeName
| ErrorTypeMismatch ChannelName String Type
| ErrorArityMismatch ProcessName Int Int
| ErrorLabelMismatch ChannelName [Label] [Label]
| ErrorInvalidType String
| ErrorInvalidCast ChannelName Type Type
| ErrorLinearity [ChannelName]
| ErrorRuntime String
instance Exception MyException
instance Show MyException where
show (ErrorSyntax msg) = msg
show (ErrorMultipleTypeDefinitions tname) = "multiple type definitions: " ++ showWithPos tname
show (ErrorMultipleProcessDefinitions pname) = "multiple process definitions: " ++ showWithPos pname
show (ErrorUnknownIdentifier kind name) = "unknown " ++ kind ++ ": " ++ name
show (ErrorMultipleNameDeclarations u) = "multiple declarations: " ++ showWithPos u
show (ErrorTypeMismatch name e t) = "type error: " ++ showWithPos name ++ ": expected " ++ e ++ ", actual " ++ show t
show (ErrorArityMismatch pname expected actual) =
"arity mismatch for " ++ showWithPos pname ++ ": expected " ++
show expected ++ ", actual " ++ show actual
show (ErrorInvalidType msg) = "invalid type: " ++ msg
show (ErrorActionUnbounded pname) = "action-unbounded process: " ++ showWithPos pname
show (ErrorSessionUnbounded pname name) = "session-unbounded process: " ++ showWithPos pname ++ " creates " ++ showWithPos name
show (ErrorCastUnbounded pname name) = "cast-unbounded process: " ++ showWithPos pname ++ " casts " ++ showWithPos name
show (ErrorLinearity pnames) = "linearity violation: " ++ List.intercalate ", " (map showWithPos pnames)
show (ErrorInvalidCast name t s) = "invalid cast for " ++ showWithPos name ++ ": " ++ show t ++ " is not a fair subtype of " ++ show s
show (ErrorLabelMismatch name elabels alabels) = "labels mismatch for " ++ showWithPos name ++ ": expected " ++ show elabels ++ ", actual " ++ show alabels
show (ErrorTypeUnbounded name) = "unbounded type: " ++ showWithPos name
show (ErrorTypeNonContractive tname) = "non-contractive type: " ++ showWithPos tname
show (ErrorRuntime msg) = "runtime error: " ++ msg