SignCSP.hs revision 2f35e5f6757968746dbab385be21fcae52378a3f
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzDescription : CspCASL signatures
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzCopyright : (c) Markus Roggenbach and Till Mossakowski and Uni Bremen 2004
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzMaintainer : M.Roggenbach@swansea.ac.uk
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzStability : provisional
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzPortability : portable
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzsignatures for CSP-CASL
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz-- todo: implement isInclusion, computeExt
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport CspCASL.AS_CspCASL_Process (CHANNEL_NAME, PROCESS_NAME,
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz PROCESS(..), CommAlpha(..), CommType(..), TypedChanName(..))
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport CASL.AS_Basic_CASL (FORMULA, SORT)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederimport CASL.Sign (emptySign, Sign, extendedInfo, sortRel)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport CASL.Morphism (Morphism)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Common.Id (Id, SIMPLE_ID, mkSimpleId, nullRange)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savuimport Common.Lib.Rel (predecessors)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport Control.Monad (unless)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savuimport qualified Data.Map as Map
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuimport qualified Data.Set as Set
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu-- | A process has zero or more parameter sorts, and a communication
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdata ProcProfile = ProcProfile [SORT] CommAlpha
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Eq, Show)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype ChanNameMap = Map.Map CHANNEL_NAME SORT
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype ProcNameMap = Map.Map PROCESS_NAME ProcProfile
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroedertype ProcVarMap = Map.Map SIMPLE_ID SORT
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype ProcVarList = [(SIMPLE_ID, SORT)]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- Close a communication alphabet under CASL subsort
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedercloseCspCommAlpha :: CspCASLSign -> CommAlpha -> CommAlpha
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedercloseCspCommAlpha sig = Set.unions . Set.toList . Set.map (closeOneCspComm sig)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- Close one CommType under CASL subsort
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavucloseOneCspComm :: CspCASLSign -> CommType -> CommAlpha
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavucloseOneCspComm sig x = let
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder mkTypedChan c s = CommTypeChan $ TypedChanName c s
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu subsorts s' = Set.singleton s' `Set.union` predecessors (sortRel sig) s'
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu in case x of
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu CommTypeSort s -> Set.map CommTypeSort (subsorts s)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu CommTypeChan (TypedChanName c s) -> Set.map CommTypeSort (subsorts s)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu `Set.union` Set.map (mkTypedChan c) (subsorts s)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu{- Will probably be useful, but doesn't appear to be right now.
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savu-- Extract the sorts from a process alphabet
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprocAlphaSorts :: CommAlpha -> Set.Set SORT
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprocAlphaSorts a = stripMaybe $ Set.map justSort a
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu where justSort n = case n of
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (CommTypeSort s) -> Just s
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu _ -> Nothing
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- Extract the typed channel names from a process alphabet
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuprocAlphaChans :: CommAlpha -> Set.Set TypedChanName
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederprocAlphaChans a = stripMaybe $ Set.map justChan a
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu where justChan n = case n of
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (CommTypeChan c) -> Just c
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu _ -> Nothing
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- Given a set of Maybes, filter to keep only the Justs
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederstripMaybe :: Ord a => Set.Set (Maybe a) -> Set.Set a
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavustripMaybe x = Set.fromList $ Maybe.catMaybes $ Set.toList x
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- Close a set of sorts under a subsort relation
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedercspSubsortCloseSorts :: CspCASLSign -> Set.Set SORT -> Set.Set SORT
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedercspSubsortCloseSorts sig sorts =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder where subsort_sets = Set.toList $ Set.map (cspSubsortPreds sig) sorts
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- | CSP process signature.
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savudata CspSign = CspSign
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder { chans :: ChanNameMap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , procSet :: ProcNameMap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu -- | Added for uniformity to the CASL static analysis. After
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu -- static analysis this is the empty list.
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder , ccSentences :: [Named CspCASLSen]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder } deriving (Eq, Show)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- | A CspCASL signature is a CASL signature with a CSP process
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savu-- signature in the extendedInfo part.
239330cd665aac95fcf9cf95449594c96667cbc2Robert Savutype CspCASLSign = Sign () CspSign
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederccSig2CASLSign :: CspCASLSign -> Sign () ()
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavuccSig2CASLSign sigma = sigma { extendedInfo = () }
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederccSig2CspSign :: CspCASLSign -> CspSign
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuccSig2CspSign sigma = extendedInfo sigma
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu-- | Empty CspCASL signature.
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederemptyCspCASLSign :: CspCASLSign
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuemptyCspCASLSign = emptySign emptyCspSign
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz-- | Empty CSP process signature.
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst SchulzemptyCspSign :: CspSign
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst SchulzemptyCspSign = CspSign
, procSet = Map.empty
a { chans = chans a `Map.union` chans b
, procSet = procSet a `Map.union` procSet b
{ channelMap :: Map.Map Id Id
, processMap :: Map.Map Id Id
Nothing -> error "SignCsp.composeIdMaps"
let chL = Map.toList $ channelMap cm
prL = Map.toList $ processMap cm
unless (isInj chL) $ fail "invertCspAddMorphism.channelMap"
unless (isInj prL) $ fail "invertCspAddMorphism.processMap"
{ channelMap = Map.fromList $ swap chL
, processMap = Map.fromList $ swap prL }
{ channelMap = Map.empty -- ???
, processMap = Map.empty
emptyAlphabet = Set.empty