StatAna.hs revision 0e25a738b51db1508b2abc35ed1b6dcae3842d66
0d03aadb6c364ae976af4c904aa3625d2512d101sfModule : $Header$
0d03aadb6c364ae976af4c904aa3625d2512d101sfCopyright : DFKI GmbH 2009
0d03aadb6c364ae976af4c904aa3625d2512d101sfLicense : GPLv2 or higher, see LICENSE.txt
0d03aadb6c364ae976af4c904aa3625d2512d101sfMaintainer : codruta.liliana@gmail.com
0d03aadb6c364ae976af4c904aa3625d2512d101sfStability : experimental
0d03aadb6c364ae976af4c904aa3625d2512d101sfPortability : portable
0d03aadb6c364ae976af4c904aa3625d2512d101sfstatic analysis of modal logic parts
0d03aadb6c364ae976af4c904aa3625d2512d101sfimport qualified Common.Lib.MapSet as MapSet
0d03aadb6c364ae976af4c904aa3625d2512d101sfimport qualified Data.Map as Map
0d03aadb6c364ae976af4c904aa3625d2512d101sfimport qualified Data.Set as Set
0d03aadb6c364ae976af4c904aa3625d2512d101sfinstance TermExtension EM_FORMULA where
0d03aadb6c364ae976af4c904aa3625d2512d101sf freeVarsOfExt sign frm = case frm of
0d03aadb6c364ae976af4c904aa3625d2512d101sf BoxOrDiamond _ m _ _ f _ ->
0d03aadb6c364ae976af4c904aa3625d2512d101sf Set.union (freeModVars sign m) $ freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf Hybrid _ _ f _ -> freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf UntilSince _ f1 f2 _ -> Set.union (freeVars sign f1) $ freeVars sign f2
0d03aadb6c364ae976af4c904aa3625d2512d101sf PathQuantification _ f _ -> freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf StateQuantification _ _ f _ -> freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf NextY _ f _ -> freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf FixedPoint _ _ f _ -> freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf ModForm (ModDefn _ _ _ afs _) ->
0d03aadb6c364ae976af4c904aa3625d2512d101sf Set.unions $ map (freeVars sign . item)
0d03aadb6c364ae976af4c904aa3625d2512d101sf $ concatMap (frameForms . item) afs
0d03aadb6c364ae976af4c904aa3625d2512d101sffreeModVars :: Sign EM_FORMULA e -> MODALITY -> Set.Set (VAR, SORT)
0d03aadb6c364ae976af4c904aa3625d2512d101sffreeModVars sign md = case md of
0d03aadb6c364ae976af4c904aa3625d2512d101sf SimpleMod _ -> Set.empty
0d03aadb6c364ae976af4c904aa3625d2512d101sf TermMod t -> freeTermVars sign t
0d03aadb6c364ae976af4c904aa3625d2512d101sf ModOp _ m1 m2 -> Set.union (freeModVars sign m1) $ freeModVars sign m2
0d03aadb6c364ae976af4c904aa3625d2512d101sf TransClos m -> freeModVars sign m
0d03aadb6c364ae976af4c904aa3625d2512d101sf Guard f -> freeVars sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sfbasicEModalAnalysis
0d03aadb6c364ae976af4c904aa3625d2512d101sf :: (BASIC_SPEC EM_BASIC_ITEM EM_SIG_ITEM EM_FORMULA
0d03aadb6c364ae976af4c904aa3625d2512d101sf , Sign EM_FORMULA EModalSign, GlobalAnnos)
0d03aadb6c364ae976af4c904aa3625d2512d101sf -> Result (BASIC_SPEC EM_BASIC_ITEM EM_SIG_ITEM EM_FORMULA
0d03aadb6c364ae976af4c904aa3625d2512d101sf , ExtSign (Sign EM_FORMULA EModalSign) Symbol
0d03aadb6c364ae976af4c904aa3625d2512d101sf , [Named (FORMULA EM_FORMULA)])
0d03aadb6c364ae976af4c904aa3625d2512d101sfbasicEModalAnalysis =
0d03aadb6c364ae976af4c904aa3625d2512d101sf basicAnalysis frmTypeAna basItemStatAna sigItemStatAna mixfixAna
0d03aadb6c364ae976af4c904aa3625d2512d101sffrmTypeAna :: Min EM_FORMULA EModalSign
0d03aadb6c364ae976af4c904aa3625d2512d101sffrmTypeAna sign form = let
0d03aadb6c364ae976af4c904aa3625d2512d101sf checkMod term_mod = case term_mod of
0d03aadb6c364ae976af4c904aa3625d2512d101sf SimpleMod s_id ->
0d03aadb6c364ae976af4c904aa3625d2512d101sf if tokStr s_id == emptyS
0d03aadb6c364ae976af4c904aa3625d2512d101sf || Set.member (simpleIdToId s_id) (modalities $ extendedInfo sign)
0d03aadb6c364ae976af4c904aa3625d2512d101sf then return $ SimpleMod s_id
0d03aadb6c364ae976af4c904aa3625d2512d101sf else Result [mkDiag Error "unknown modality" s_id]
0d03aadb6c364ae976af4c904aa3625d2512d101sf $ Just $ SimpleMod s_id
0d03aadb6c364ae976af4c904aa3625d2512d101sf ModOp o md1 md2 -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_md1 <- checkMod md1
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_md2 <- checkMod md2
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ ModOp o new_md1 new_md2
0d03aadb6c364ae976af4c904aa3625d2512d101sf TransClos md -> fmap TransClos $ checkMod md
0d03aadb6c364ae976af4c904aa3625d2512d101sf Guard frm -> fmap Guard $ minExpFORMULA frmTypeAna sign frm
0d03aadb6c364ae976af4c904aa3625d2512d101sf TermMod t -> let
0d03aadb6c364ae976af4c904aa3625d2512d101sf ms = modalities $ extendedInfo sign
0d03aadb6c364ae976af4c904aa3625d2512d101sf t2 <- oneExpTerm frmTypeAna sign t
0d03aadb6c364ae976af4c904aa3625d2512d101sf let srt = sortOfTerm t2
0d03aadb6c364ae976af4c904aa3625d2512d101sf trm = TermMod t2
0d03aadb6c364ae976af4c904aa3625d2512d101sf supers = supersortsOf srt sign
0d03aadb6c364ae976af4c904aa3625d2512d101sf if Set.null $ Set.intersection (Set.insert srt supers) ms
0d03aadb6c364ae976af4c904aa3625d2512d101sf then Result [mkDiag Error
0d03aadb6c364ae976af4c904aa3625d2512d101sf ("unknown term modality sort '"
0d03aadb6c364ae976af4c904aa3625d2512d101sf ++ showId srt "' for term") t ]
0d03aadb6c364ae976af4c904aa3625d2512d101sf $ Just trm
0d03aadb6c364ae976af4c904aa3625d2512d101sf else return trm
0d03aadb6c364ae976af4c904aa3625d2512d101sf in case t of
0d03aadb6c364ae976af4c904aa3625d2512d101sf Mixfix_token tm ->
0d03aadb6c364ae976af4c904aa3625d2512d101sf if Set.member (simpleIdToId tm) ms
0d03aadb6c364ae976af4c904aa3625d2512d101sf || tokStr tm == emptyS
0d03aadb6c364ae976af4c904aa3625d2512d101sf then return $ SimpleMod tm
0d03aadb6c364ae976af4c904aa3625d2512d101sf else Result
0d03aadb6c364ae976af4c904aa3625d2512d101sf [mkDiag Error "unknown modality" tm]
0d03aadb6c364ae976af4c904aa3625d2512d101sf $ Just $ SimpleMod tm
0d03aadb6c364ae976af4c904aa3625d2512d101sf Application (Op_name (Id [tm] [] _)) [] _ ->
0d03aadb6c364ae976af4c904aa3625d2512d101sf if Set.member (simpleIdToId tm) ms
0d03aadb6c364ae976af4c904aa3625d2512d101sf then return $ SimpleMod tm
0d03aadb6c364ae976af4c904aa3625d2512d101sf checkFrame (FrameForm vs fs r) = do
0d03aadb6c364ae976af4c904aa3625d2512d101sf nfs <- mapAnM (minExpFORMULA frmTypeAna sign . mkForall vs) fs
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ FrameForm [] nfs r
0d03aadb6c364ae976af4c904aa3625d2512d101sf in case form of
0d03aadb6c364ae976af4c904aa3625d2512d101sf BoxOrDiamond choice md leq_geq number f pos -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_md <- checkMod md
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f <- minExpFORMULA frmTypeAna sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf if number >= 0
0d03aadb6c364ae976af4c904aa3625d2512d101sf then return $ BoxOrDiamond choice new_md leq_geq number new_f pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf else Result [mkDiag Error "negative number grading" number]
0d03aadb6c364ae976af4c904aa3625d2512d101sf $ Just $ BoxOrDiamond choice new_md leq_geq number new_f pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf Hybrid choice nm f pos -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f <- minExpFORMULA frmTypeAna sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf if Set.member nm (nominals $ extendedInfo sign)
0d03aadb6c364ae976af4c904aa3625d2512d101sf then return $ Hybrid choice nm new_f pos
3d27420bf1f5d019774995b66e3ba0955de6df6csf else Result [mkDiag Error "unknown nominal" nm]
3d27420bf1f5d019774995b66e3ba0955de6df6csf $ Just $ Hybrid choice nm new_f pos
3d27420bf1f5d019774995b66e3ba0955de6df6csf UntilSince choice f1 f2 pos -> do
3d27420bf1f5d019774995b66e3ba0955de6df6csf new_f1 <- minExpFORMULA frmTypeAna sign f1
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f2 <- minExpFORMULA frmTypeAna sign f2
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ UntilSince choice new_f1 new_f2 pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf PathQuantification choice f pos -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f <- minExpFORMULA frmTypeAna sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ PathQuantification choice new_f pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf StateQuantification t_dir choice f pos -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f <- minExpFORMULA frmTypeAna sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ StateQuantification t_dir choice new_f pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf NextY choice f pos -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f <- minExpFORMULA frmTypeAna sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ NextY choice new_f pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf FixedPoint choice fpvar f pos -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_f <- minExpFORMULA frmTypeAna sign f
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ FixedPoint choice fpvar new_f pos
0d03aadb6c364ae976af4c904aa3625d2512d101sf ModForm (ModDefn is_time isTerm anno_list forms pos) -> do
0d03aadb6c364ae976af4c904aa3625d2512d101sf new_forms <- mapAnM checkFrame forms
0d03aadb6c364ae976af4c904aa3625d2512d101sf return $ ModForm $ ModDefn is_time isTerm anno_list new_forms pos
0d03aadb6c364ae976af4c904aa3625d2512d101sfanaFrameForm :: Mix b s EM_FORMULA EModalSign -> FrameForm
0d03aadb6c364ae976af4c904aa3625d2512d101sf -> State (Sign EM_FORMULA EModalSign) (FrameForm, FrameForm)
0d03aadb6c364ae976af4c904aa3625d2512d101sfanaFrameForm mix ff@(FrameForm vs fs r) = if null fs then do
0d03aadb6c364ae976af4c904aa3625d2512d101sf mapM_ addVars vs
0d03aadb6c364ae976af4c904aa3625d2512d101sf return (ff, ff)
0d03aadb6c364ae976af4c904aa3625d2512d101sf (resFs, fufs) <- anaLocalVarForms (anaFORMULA mix) vs fs r
0d03aadb6c364ae976af4c904aa3625d2512d101sf return (FrameForm vs resFs r, FrameForm [] fufs r)
put e { varMap = Map.empty }
in if Set.member tmi srts then
if Set.member tmi tm
else let sps = Set.difference tm $ supersortsOf tmi fullSign in
if Set.null sps
then return sgn { termMods = Set.insert tmi tm }
if Set.member tmi tm
else if Set.size tm >= 1
else return sgn { time_modalities = Set.insert tmi tm }
if Set.member mi m then
else return sgn { modalities = Set.insert mi m }
if Set.member ni n then
else return sgn { nominals = Set.insert ni n }
sgn { flexPreds = MapSet.insert i typ $ flexPreds sgn }
extraSigItems s = let e = Set.empty in case s of
((e, e), Set.unions $ map (ids_PRED_ITEM . item) annoted_list)
let mix2 = extendMix (Map.keysSet $ varMap sig) mix
let pm2 = Set.fold
(\ t -> MapSet.insert (simpleIdToId t) (PredType []))
getEFormPredToks :: EM_FORMULA -> Set.Set Token
Set.union (getFormPredToks f1) (getFormPredToks f2)
ModForm _ -> Set.empty
getFormPredToks :: FORMULA EM_FORMULA -> Set.Set Token
Mixfix_formula (Mixfix_token t) -> Set.singleton t