Analysis.hs revision 38fcf05bbfbd232891783fdf7c136f5efa0f095e
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndModule : $Header$
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndDescription : Abstract syntax for reduce
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndCopyright : (c) Dominik Dietrich, Ewaryst Schulz, DFKI Bremen 2010
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndLicense : GPLv2 or higher, see LICENSE.txt
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndMaintainer : Ewaryst.Schulz@dfki.de
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndStability : experimental
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndPortability : portable
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd ( splitSpec
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd , basicCSLAnalysis
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd , Guard(..)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd , Guarded(..)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd , dependencySortAS
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd , epElimination
1c28b8f24d373dfe800f9d99b9eea20fd05c1376rjung-- basicCSLAnalysis
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- ,mkStatSymbItems
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding-- ,mkStatSymbMapItem
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- ,inducedFromMorphism
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- ,inducedFromToMorphism
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- , signatureColimit
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndimport Common.Utils (mapAccumLM)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndimport CSL.Sign as Sign
1c28b8f24d373dfe800f9d99b9eea20fd05c1376rjungimport qualified Data.Tree as Tr
1c28b8f24d373dfe800f9d99b9eea20fd05c1376rjungimport qualified Data.Set as Set
1c28b8f24d373dfe800f9d99b9eea20fd05c1376rjungimport qualified Data.Map as Map
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- * Diagnosis Types and Functions
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd{- TODO: we want to proceed as follows:
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd 1. Check if all applications are valid w.r.t. the arity
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- | generates a named formula
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndwithName :: Annoted CMD -> Int -> Named CMD
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndwithName f i = (makeNamed (if label == "" then "Ax_" ++ show i
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd else label) $ item f)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd { isAxiom = not isTheorem }
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd label = getRLabel f
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd annos = r_annos f
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd isImplies' = foldl (\ y x -> isImplies x || y) False annos
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd isImplied' = foldl (\ y x -> isImplied x || y) False annos
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd isTheorem = isImplies' || isImplied'
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- | takes a signature and a formula and a number.
e20a796a53754d1850fdd062664b96a54336fc45jorton-- It analyzes the formula and returns a formula with diagnosis
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndanalyzeFormula :: Sign.Sign -> (Annoted CMD) -> Int -> Result (Named CMD)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndanalyzeFormula _ f i =
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd return $ withName f{ item = staticUpdate $ item f } i
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- | Extracts the axioms and the signature of a basic spec
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndsplitSpec :: BASIC_SPEC -> Sign.Sign -> Result (Sign.Sign, [Named CMD])
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndsplitSpec (Basic_spec specitems) sig =
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd ((newsig, _), mNCmds) <- mapAccumLM anaBasicItem (sig, 0) specitems
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd return (newsig, catMaybes mNCmds)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndanaBasicItem :: (Sign.Sign, Int) -> Annoted BASIC_ITEM
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd -> Result ((Sign.Sign, Int), Maybe (Named CMD))
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndanaBasicItem acc@(sign, i) itm =
e20a796a53754d1850fdd062664b96a54336fc45jorton case item itm of
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd Op_decl (Op_item tokens _) -> return ((addTokens sign tokens, i), Nothing)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd Var_decls _ -> return (acc, Nothing) -- TODO: implement
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd Axiom_item annocmd ->
ec607b66f38e05274fcfe9d9cce9e7b0d5acd92dnd ncmd <- analyzeFormula sign annocmd i
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd return ((sign, i+1), Just ncmd)
ec607b66f38e05274fcfe9d9cce9e7b0d5acd92dnd-- | adds the specified tokens to the signature
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndaddTokens sign tokens = let f res itm = addToSig res (simpleIdToId itm)
ec607b66f38e05274fcfe9d9cce9e7b0d5acd92dnd $ optypeFromArity 0
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd in foldl f sign tokens
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd{- | stepwise extends an initially empty signature by the basic spec bs.
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd The resulting spec contains analyzed axioms in it. The result contains:
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd (1) the basic spec
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd (2) the new signature + the added symbols
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd (3) sentences of the spec
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndbasicCSLAnalysis :: (BASIC_SPEC, Sign, a)
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd -> Result (BASIC_SPEC, ExtSign Sign Symbol, [Named CMD])
ec607b66f38e05274fcfe9d9cce9e7b0d5acd92dndbasicCSLAnalysis (bs, sig, _) =
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd (newSig, ncmds) <- splitSpec bs sig
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding $ Map.difference (items newSig) $ items sig
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd return (bs, ExtSign newSig newSyms, ncmds)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding-- | A function which regroups all updates on a CMD during the static analysis.
9f19c852d132ea20fe31ed957ca9462635e9e42bjortonstaticUpdate :: CMD -> CMD
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndstaticUpdate = handleFunAssignment . handleBinder
60e9b3f37c1362c258c50c0fa29b2187a9e1580fnd-- | Replaces the function-arguments in functional assignments by variables.
60e9b3f37c1362c258c50c0fa29b2187a9e1580fndhandleFunAssignment :: CMD -> CMD
varSet :: [EXPRESSION] -> (Set.Set String, [EXPRESSION])
(Set.insert (show v) s, Var Token{ tokStr = show v, tokPos = rg' })
in mapAccumL opToVar' Set.empty l
constsToVars :: Set.Set String -> EXPRESSION -> EXPRESSION
if Set.member (show s) env then
, filtered :: Set.Set String
, constrained :: Set.Set String } deriving Show
type GuardedMap a = Map.Map String (Guarded a)
in Map.insertWith combf s grd m
(cm, pr) = foldr f (Map.empty, []) cl
in (Map.map analyzeGuarded cm, pr)
newRg = case map (Atom . eplabel . Tr.rootLabel) sf of
dependencySortAS = Map.toList
epElimination = f Map.empty
liftM ((s, g') :) $ f (Map.insert s g' m) l
$ Map.findWithDefault (err s) s m
-- (Map.Map PIConst Int)
let i = Map.findWithDefault (err2 s) (mkPIConst s epl) pim
-> EXPRESSION -> m (Map.Map PIConst a)
extractUserDefined f e = g Map.empty e
m' = Map.insert pic v m
refineDefPartitions :: CompareIO m => Map.Map PIConst (Partition Int)
-> m (Partition (Map.Map PIConst Int))
refineDefPartition :: CompareIO m => Partition (Map.Map PIConst Int)
-> m (Partition (Map.Map PIConst Int))
liftM (fmap $ uncurry $ Map.insert c) $ refinePartition ps pm