GuardedDependencies.hs revision 7af4df794a0e0f0cb927bd9371556ad098308983
6ae232055d4d8a97267517c5e50074c2c819941and{- |
6ae232055d4d8a97267517c5e50074c2c819941andModule : $Header$
fd9abdda70912b99b24e3bf1a38f26fde908a74cndDescription : Guarded Dependency Store
fd9abdda70912b99b24e3bf1a38f26fde908a74cndCopyright : (c) Ewaryst Schulz, DFKI Bremen 2011
fd9abdda70912b99b24e3bf1a38f26fde908a74cndLicense : GPLv2 or higher, see LICENSE.txt
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andMaintainer : Ewaryst.Schulz@dfki.de
6ae232055d4d8a97267517c5e50074c2c819941andStability : experimental
6ae232055d4d8a97267517c5e50074c2c819941andPortability : portable
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc
6ae232055d4d8a97267517c5e50074c2c819941andDefinition of guarded dependencies resulting from the use of extended
6ae232055d4d8a97267517c5e50074c2c819941andparameters.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
2e545ce2450a9953665f701bb05350f0d3f26275nd-}
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
6ae232055d4d8a97267517c5e50074c2c819941andmodule CSL.GuardedDependencies
6ae232055d4d8a97267517c5e50074c2c819941and where
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen
3f08db06526d6901aa08c110b5bc7dde6bc39905ndimport Common.AS_Annotation
6ae232055d4d8a97267517c5e50074c2c819941andimport Common.Id
6ae232055d4d8a97267517c5e50074c2c819941andimport Common.Doc
6ae232055d4d8a97267517c5e50074c2c819941andimport Common.DocUtils
b43f840409794ed298e8634f6284741f193b6c4ftakashi
6ae232055d4d8a97267517c5e50074c2c819941andimport CSL.AS_BASIC_CSL
b43f840409794ed298e8634f6284741f193b6c4ftakashiimport CSL.Sign as Sign
6ae232055d4d8a97267517c5e50074c2c819941andimport CSL.EPRelation
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andimport Control.Monad
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashiimport qualified Data.Set as Set
d474d8ef01ec5c2a09341cd148851ed383c3287crbowenimport qualified Data.Map as Map
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen
6ae232055d4d8a97267517c5e50074c2c819941and-- ** Datatypes and guarded definitions
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi
b43f840409794ed298e8634f6284741f193b6c4ftakashi-- | A guard consists of the guard range and the corresponding expression
6ae232055d4d8a97267517c5e50074c2c819941and-- together with a name, a set of not propagated parameters and a set of
6ae232055d4d8a97267517c5e50074c2c819941and-- constrained parameters (in the extended parameter specification)
6ae232055d4d8a97267517c5e50074c2c819941anddata Guard a = Guard { range :: a
6ae232055d4d8a97267517c5e50074c2c819941and , definition :: EXPRESSION
6ae232055d4d8a97267517c5e50074c2c819941and , assName :: String
6ae232055d4d8a97267517c5e50074c2c819941and , filtered :: Set.Set String
6ae232055d4d8a97267517c5e50074c2c819941and , constrained :: Set.Set String }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andprettyGuard :: (a -> Doc) -> Guard a -> Doc
6ae232055d4d8a97267517c5e50074c2c819941andprettyGuard f g = f (range g) <+> text "-->" <+> pretty (definition g)
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andinstance Functor Guard where
6ae232055d4d8a97267517c5e50074c2c819941and fmap f (Guard x e an fs ct) = Guard (f x) e an fs ct
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andinstance Pretty a => Pretty (Guard a) where
6ae232055d4d8a97267517c5e50074c2c819941and pretty = prettyGuard pretty
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andinstance Pretty a => Show (Guard a) where
6ae232055d4d8a97267517c5e50074c2c819941and show = show . pretty
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and-- | A guarded constant consists of the argument list (for function definitions)
6ae232055d4d8a97267517c5e50074c2c819941and-- and a list of guard-expressions
6ae232055d4d8a97267517c5e50074c2c819941anddata Guarded a = Guarded { argvars :: [String]
6ae232055d4d8a97267517c5e50074c2c819941and , guards :: [Guard a] }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and{- Comment it in if needed later
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andundefinedGuard :: String -> a -> Guard a
6ae232055d4d8a97267517c5e50074c2c819941andundefinedGuard s x = Guard { range = x
6ae232055d4d8a97267517c5e50074c2c819941and , definition = err
6ae232055d4d8a97267517c5e50074c2c819941and , assName = err
6ae232055d4d8a97267517c5e50074c2c819941and , filtered = err
6ae232055d4d8a97267517c5e50074c2c819941and , constrained = err }
6ae232055d4d8a97267517c5e50074c2c819941and where err = error $ "undefinedGuard: " ++ s
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andundefinedGuarded :: String -> a -> Guarded a
6ae232055d4d8a97267517c5e50074c2c819941andundefinedGuarded s x = Guarded { argvars = []
6ae232055d4d8a97267517c5e50074c2c819941and , guards = [undefinedGuard s x] }
6ae232055d4d8a97267517c5e50074c2c819941and-}
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andprettyGuarded :: (a -> Doc) -> Guarded a -> Doc
6ae232055d4d8a97267517c5e50074c2c819941andprettyGuarded f grdd = vcat $ map (prettyGuard f) $ guards grdd
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andinstance Functor Guarded where
6ae232055d4d8a97267517c5e50074c2c819941and fmap f grdd = grdd { guards = map (fmap f) $ guards grdd }
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andinstance Pretty a => Pretty (Guarded a) where
6ae232055d4d8a97267517c5e50074c2c819941and pretty = prettyGuarded pretty
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andinstance Pretty a => Show (Guarded a) where
6ae232055d4d8a97267517c5e50074c2c819941and show = show . pretty
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andtype GuardedMap a = Map.Map String (Guarded a)
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andaddAssignment :: String -> EXPRESSION -> EXPRESSION -> GuardedMap [EXTPARAM]
6ae232055d4d8a97267517c5e50074c2c819941and -> GuardedMap [EXTPARAM]
6ae232055d4d8a97267517c5e50074c2c819941andaddAssignment n (Op oid@(OpUser _) epl al _) def m =
6ae232055d4d8a97267517c5e50074c2c819941and let f (Var tok) = tokStr tok
6ae232055d4d8a97267517c5e50074c2c819941and f x = error $ "addAssignment: not a variable " ++ show x
6ae232055d4d8a97267517c5e50074c2c819941and combf x y | argvars x == argvars y = y { guards = guards y ++ guards x }
6ae232055d4d8a97267517c5e50074c2c819941and | otherwise =
6ae232055d4d8a97267517c5e50074c2c819941and error "addAssignment: the argument vars does not match."
6ae232055d4d8a97267517c5e50074c2c819941and grd = Guarded (map f al) [uncurry (Guard epl def n)
6ae232055d4d8a97267517c5e50074c2c819941and $ filteredConstrainedParams epl]
b43f840409794ed298e8634f6284741f193b6c4ftakashi in Map.insertWith combf (simpleName oid) grd m
6ae232055d4d8a97267517c5e50074c2c819941and
6ae232055d4d8a97267517c5e50074c2c819941andaddAssignment _ x _ _ = error $ "unexpected assignment " ++ show x
6ae232055d4d8a97267517c5e50074c2c819941and
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi{- TODO:
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen 1. analysis for missing definitions and undeclared extparams
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen 2. Integrating extparam domain definitions
6ae232055d4d8a97267517c5e50074c2c819941and 3. check for each constant if the Guards exhaust the extparam domain (in splitAS)
205f749042ed530040a4f0080dbcb47ceae8a374rjung-}
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen
0d0ba3a410038e179b695446bb149cce6264e0abnd-- | Splits the Commands into the AssignmentStore and a program sequence
7fec19672a491661b2fe4b29f685bc7f4efa64d4ndsplitAS :: [Named CMD] -> (GuardedMap [EXTPARAM], [Named CMD])
7fec19672a491661b2fe4b29f685bc7f4efa64d4ndsplitAS cl =
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd let f nc (m,l) = case sentence nc of
6ae232055d4d8a97267517c5e50074c2c819941and Ass c def -> (addAssignment (senAttr nc) c def m, l)
_ -> (m, nc:l)
in foldr f (Map.empty, []) cl