7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : ./CSL/GuardedDependencies.hs
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzDescription : Guarded Dependency Store
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzCopyright : (c) Ewaryst Schulz, DFKI Bremen 2011
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzLicense : GPLv2 or higher, see LICENSE.txt
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzMaintainer : Ewaryst.Schulz@dfki.de
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzStability : experimental
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzPortability : portable
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzDefinition of guarded dependencies resulting from the use of extended
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzparameters.
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz-}
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzmodule CSL.GuardedDependencies
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport Common.AS_Annotation
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport Common.Doc
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport Common.DocUtils
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport CSL.AS_BASIC_CSL
ee3bb87ab2da52ee1ad0c6675ea8b699b0af9ddcEwaryst Schulzimport CSL.ASUtils
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport CSL.Sign as Sign
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport CSL.EPRelation
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport Control.Monad
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport qualified Data.Set as Set
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzimport qualified Data.Map as Map
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz-- ** Datatypes and guarded definitions
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder{- | A guard consists of the guard range and the corresponding expression
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroedertogether with a name, a set of not propagated parameters and a set of
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederconstrained parameters (in the extended parameter specification) -}
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzdata Guard a = Guard { range :: a
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , definition :: EXPRESSION
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , assName :: String
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , filtered :: Set.Set String
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , constrained :: Set.Set String }
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzprettyGuard :: (a -> Doc) -> Guard a -> Doc
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzprettyGuard f g = f (range g) <+> text "-->" <+> pretty (definition g)
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzinstance Functor Guard where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz fmap f (Guard x e an fs ct) = Guard (f x) e an fs ct
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzinstance Pretty a => Pretty (Guard a) where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz pretty = prettyGuard pretty
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzinstance Pretty a => Show (Guard a) where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz show = show . pretty
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder{- | A guarded constant consists of the argument list (for function definitions)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederand a list of guard-expressions -}
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzdata Guarded a = Guarded { argvars :: [String]
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , guards :: [Guard a] }
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz{- Comment it in if needed later
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzundefinedGuard :: String -> a -> Guard a
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzundefinedGuard s x = Guard { range = x
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , definition = err
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , assName = err
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , filtered = err
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , constrained = err }
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz where err = error $ "undefinedGuard: " ++ s
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzundefinedGuarded :: String -> a -> Guarded a
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzundefinedGuarded s x = Guarded { argvars = []
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz , guards = [undefinedGuard s x] }
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz-}
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzprettyGuarded :: (a -> Doc) -> Guarded a -> Doc
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzprettyGuarded f grdd = vcat $ map (prettyGuard f) $ guards grdd
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzinstance Functor Guarded where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz fmap f grdd = grdd { guards = map (fmap f) $ guards grdd }
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzinstance Pretty a => Pretty (Guarded a) where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz pretty = prettyGuarded pretty
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulzinstance Pretty a => Show (Guarded a) where
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz show = show . pretty
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulztype GuardedMap a = Map.Map String (Guarded a)
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
76408af596b604997cabe1ebde1caaa43f58b1e6Ewaryst SchulzaddAssignment :: String -> OpDecl -> EXPRESSION -> GuardedMap [EXTPARAM]
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz -> GuardedMap [EXTPARAM]
76408af596b604997cabe1ebde1caaa43f58b1e6Ewaryst SchulzaddAssignment n (OpDecl sc epl al _) def m =
76408af596b604997cabe1ebde1caaa43f58b1e6Ewaryst Schulz let combf x y | argvars x == argvars y = y { guards = guards y ++ guards x }
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz | otherwise =
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz error "addAssignment: the argument vars does not match."
76408af596b604997cabe1ebde1caaa43f58b1e6Ewaryst Schulz grd = Guarded (map varDeclName al) [uncurry (Guard epl def n)
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz $ filteredConstrainedParams epl]
76408af596b604997cabe1ebde1caaa43f58b1e6Ewaryst Schulz in Map.insertWith combf (simpleName $ OpUser sc) grd m
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder{- TODO:
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz 1. analysis for missing definitions and undeclared extparams
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz 2. Integrating extparam domain definitions
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz 3. check for each constant if the Guards exhaust the extparam domain (in splitAS)
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz-}
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz-- | Splits the Commands into the AssignmentStore and a program sequence
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzsplitAS :: [Named CMD] -> (GuardedMap [EXTPARAM], [Named CMD])
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst SchulzsplitAS cl =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder let f nc (m, l) = case sentence nc of
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz Ass c def -> (addAssignment (senAttr nc) c def m, l)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder _ -> (m, nc : l)
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz in foldr f (Map.empty, []) cl