SignCSP.hs revision 8c6b80162937eae0fe868c3b52bda6b50a153478
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder{-# LANGUAGE TypeSynonymInstances #-}
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederDescription : CspCASL signatures
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederCopyright : (c) Markus Roggenbach and Till Mossakowski and Uni Bremen 2004
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederMaintainer : M.Roggenbach@swansea.ac.uk
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederStability : provisional
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederPortability : portable
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maedersignatures for CSP-CASL
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maederimport qualified CspCASL.LocalTop as LocalTop
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maederimport Common.Lib.Rel (Rel, predecessors)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederimport qualified Data.Map as Map
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederimport qualified Data.Set as Set
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maedertype ChanNameMap = Map.Map CHANNEL_NAME (Set.Set SORT)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maedertype ProcNameMap = Map.Map PROCESS_NAME (Set.Set ProcProfile)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maedertype ProcVarMap = Map.Map SIMPLE_ID SORT
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maedertype ProcVarList = [(SIMPLE_ID, SORT)]
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder-- | Add a process name and its profile to a process name map. exist.
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederaddProcNameToProcNameMap :: PROCESS_NAME -> ProcProfile ->
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder ProcNameMap -> ProcNameMap
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederaddProcNameToProcNameMap name profile pm =
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder let l = Map.findWithDefault Set.empty name pm
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder in Map.insert name (Set.insert profile l) pm
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- | Test if a simple process name with a profile is in the process name map.
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederisNameInProcNameMap :: PROCESS_NAME -> ProcProfile -> ProcNameMap -> Bool
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederisNameInProcNameMap name profile pm =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder let l = Map.findWithDefault Set.empty name pm
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder{- | Given a simple process name and a required number of parameters, find a
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederunqiue profile with that many parameters if possible. If this is not possible
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder(i.e., name does not exist, or no profile with the required number of
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederarguments or not unique profile for the required number of arguments), then
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederthe functions returns a failed result with a helpful error message. failure. -}
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedergetUniqueProfileInProcNameMap :: PROCESS_NAME -> Int -> ProcNameMap ->
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder Result ProcProfile
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian MaedergetUniqueProfileInProcNameMap name numParams pm =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder let profiles = Map.findWithDefault Set.empty name pm
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder isMatch (ProcProfile argSorts _) =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder length argSorts == numParams
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder matchedProfiles = Set.filter isMatch profiles
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder in case Set.toList matchedProfiles of
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder [] -> mkError ("Process name not in signature with "
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder ++ show numParams ++ " parameters:") name
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder [p] -> return p
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder _ -> mkError ("Process name not unique in signature with "
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder ++ show numParams ++ " parameters:") name
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseProcs :: Rel SORT -> CspSign -> CspSign
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseProcs r s = s { procSet = closeProcNameMapSortRel r $ procSet s }
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder{- | Close a proc name map under a sub-sort relation. Assumes all the proc
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederprofile's comms are in the sub sort relation and simply makes the comms
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maederdownward closed under the sub-sort relation. -}
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseProcNameMapSortRel :: Rel SORT -> ProcNameMap -> ProcNameMap
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseProcNameMapSortRel sig =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder Map.map (Set.map $ closeProcProfileSortRel sig)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder{- | Close a profile under a sub-sort relation. Assumes the proc profile's
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maedercomms are in the sub sort relation and simply makes the comms downward closed
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maederunder the sub-sort relation. -}
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian MaedercloseProcProfileSortRel :: Rel SORT -> ProcProfile -> ProcProfile
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseProcProfileSortRel sig (ProcProfile argSorts comms) =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder ProcProfile argSorts (closeCspCommAlpha sig comms)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- Close a communication alphabet under CASL subsort
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseCspCommAlpha :: Rel SORT -> CommAlpha -> CommAlpha
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseCspCommAlpha sr =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder Set.unions . Set.toList . Set.map (closeOneCspComm sr)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- Close one CommType under CASL subsort
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseOneCspComm :: Rel SORT -> CommType -> CommAlpha
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercloseOneCspComm sr x = let
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder mkTypedChan c s = CommTypeChan $ TypedChanName c s
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder subsorts s' =
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder Set.singleton s' `Set.union` predecessors sr s'
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder CommTypeSort s ->
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder Set.map CommTypeSort (subsorts s)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder CommTypeChan (TypedChanName c s) ->
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder Set.map CommTypeSort (subsorts s)
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder `Set.union` Set.map (mkTypedChan c) (subsorts s)
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder{- Will probably be useful, but doesn't appear to be right now.
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- Extract the sorts from a process alphabet
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederprocAlphaSorts :: CommAlpha -> Set.Set SORT
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian MaederprocAlphaSorts a = stripMaybe $ Set.map justSort a
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder where justSort n = case n of
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder (CommTypeSort s) -> Just s
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- Extract the typed channel names from a process alphabet
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederprocAlphaChans :: CommAlpha -> Set.Set TypedChanName
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederprocAlphaChans a = stripMaybe $ Set.map justChan a
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder where justChan n = case n of
8d97ef4f234681b11bb5924bd4d03adef858d2d2Christian Maeder (CommTypeChan c) -> Just c
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- Given a set of Maybes, filter to keep only the Justs
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederstripMaybe :: Ord a => Set.Set (Maybe a) -> Set.Set a
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaederstripMaybe x = Set.fromList $ Maybe.catMaybes $ Set.toList x
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian Maeder-- Close a set of sorts under a subsort relation
acabd9ab36e1870f6f02c513bcfbfd10ffd118e0Christian MaedercspSubsortCloseSorts :: CspCASLSign -> Set.Set SORT -> Set.Set SORT
Set.unions subsort_sets
{ chans = Map.empty
, procSet = Map.empty }
diags' = LocalTop.checkLocalTops rel
mapSetToList = concatMap (\ (c, ts) -> map (\ t -> (c, t)) $ Set.toList ts)
TERMs i.e. constructed via the TERM constructor Qual_var. -}