|
| 1 | +{- | |
| 2 | +Copyright : (c) Runtime Verification, 2020 |
| 3 | +License : NCSA |
| 4 | +
|
| 5 | +-} |
| 6 | + |
| 7 | +module Kore.Log.ErrorRuleMergeDuplicateLabel |
| 8 | + ( ErrorRuleMergeDuplicateLabel |
| 9 | + , errorRuleMergeDuplicateLabel |
| 10 | + ) where |
| 11 | + |
| 12 | +import Prelude.Kore |
| 13 | + |
| 14 | +import Control.Exception |
| 15 | + ( Exception (..) |
| 16 | + , throw |
| 17 | + ) |
| 18 | +import qualified Control.Lens as Lens |
| 19 | +import Data.Generics.Product |
| 20 | + ( field |
| 21 | + ) |
| 22 | +import Data.Generics.Wrapped |
| 23 | + ( _Unwrapped |
| 24 | + ) |
| 25 | +import Data.Text |
| 26 | + ( Text |
| 27 | + ) |
| 28 | +import qualified Generics.SOP as SOP |
| 29 | +import qualified GHC.Generics as GHC |
| 30 | + |
| 31 | +import Kore.Attribute.SourceLocation |
| 32 | + ( SourceLocation (..) |
| 33 | + ) |
| 34 | +import Kore.Internal.TermLike |
| 35 | + ( VariableName |
| 36 | + ) |
| 37 | +import Kore.Step.RulePattern |
| 38 | + ( RewriteRule (..) |
| 39 | + ) |
| 40 | +import Log |
| 41 | +import Pretty |
| 42 | + ( Pretty (..) |
| 43 | + ) |
| 44 | +import qualified Pretty |
| 45 | + |
| 46 | +data ErrorRuleMergeDuplicateLabel = |
| 47 | + ErrorRuleMergeDuplicateLabel |
| 48 | + { locations :: [SourceLocation] |
| 49 | + , ruleLabel :: Text |
| 50 | + } |
| 51 | + deriving (Show) |
| 52 | + deriving (GHC.Generic) |
| 53 | + deriving anyclass (SOP.Generic, SOP.HasDatatypeInfo) |
| 54 | + |
| 55 | +instance Exception ErrorRuleMergeDuplicateLabel where |
| 56 | + toException = toException . SomeEntry |
| 57 | + fromException exn = |
| 58 | + fromException exn >>= fromEntry |
| 59 | + |
| 60 | +instance Entry ErrorRuleMergeDuplicateLabel where |
| 61 | + entrySeverity _ = Error |
| 62 | + helpDoc _ = |
| 63 | + "error thrown during rule merging when\ |
| 64 | + \ multiple rules have the same label" |
| 65 | + |
| 66 | +instance Pretty ErrorRuleMergeDuplicateLabel where |
| 67 | + pretty ErrorRuleMergeDuplicateLabel { locations , ruleLabel } = |
| 68 | + Pretty.vsep |
| 69 | + $ ["The rules at the following locations:"] |
| 70 | + <> fmap (Pretty.indent 4 . pretty) locations |
| 71 | + <> [ Pretty.indent 2 "all have the following label:" |
| 72 | + , Pretty.indent 4 (pretty ruleLabel) |
| 73 | + ] |
| 74 | + |
| 75 | +errorRuleMergeDuplicateLabel :: [RewriteRule VariableName] -> Text -> a |
| 76 | +errorRuleMergeDuplicateLabel rules ruleLabel = |
| 77 | + throw ErrorRuleMergeDuplicateLabel { locations, ruleLabel } |
| 78 | + where |
| 79 | + locations = |
| 80 | + Lens.view |
| 81 | + ( _Unwrapped |
| 82 | + . field @"attributes" |
| 83 | + . field @"sourceLocation" |
| 84 | + ) |
| 85 | + <$> rules |
0 commit comments