Copyright : (c) Christian Maeder, Uni Bremen 2004-2005
Maintainer : luecke@informatik.uni-bremen.de
static analysis of hybrid logic parts
instance TermExtension H_FORMULA where
freeVarsOfExt sign (BoxOrDiamond _ _ f _) = freeVars sign f
freeVarsOfExt sign (At _ f _ ) = freeVars sign f
freeVarsOfExt sign (Univ _ f _) = freeVars sign f
freeVarsOfExt sign (Exist _ f _) = freeVars sign f
:: (BASIC_SPEC H_BASIC_ITEM H_SIG_ITEM H_FORMULA,
Sign H_FORMULA HybridSign, GlobalAnnos)
-> Result (BASIC_SPEC H_BASIC_ITEM H_SIG_ITEM H_FORMULA,
ExtSign (Sign H_FORMULA HybridSign) Symbol,
[Named (FORMULA H_FORMULA)])
basicAnalysis minExpForm ana_H_BASIC_ITEM ana_H_SIG_ITEM ana_Mix
ana_Mix :: Mix H_BASIC_ITEM H_SIG_ITEM H_FORMULA HybridSign
{ getSigIds = ids_H_SIG_ITEM
, putParen = mapH_FORMULA
, mixResolve = resolveH_FORMULA
-- rigid ops will also be part of the CASL signature
ids_H_SIG_ITEM :: H_SIG_ITEM -> IdSets
ids_H_SIG_ITEM si = let e =
Set.empty in case si of
(unite2 $ map (ids_OP_ITEM . item) al, e)
Rigid_pred_items _ al _ ->
((e, e),
Set.unions $ map (ids_PRED_ITEM . item) al)
mapMODALITY :: MODALITY -> MODALITY
mapMODALITY m = case m of
Term_mod t -> Term_mod $ mapTerm mapH_FORMULA t
mapH_FORMULA :: H_FORMULA -> H_FORMULA
mapH_FORMULA (BoxOrDiamond b m f ps) =
BoxOrDiamond b (mapMODALITY m) (mapFormula mapH_FORMULA f) ps
mapH_FORMULA (At n f ps) = At n (mapFormula mapH_FORMULA f) ps
mapH_FORMULA (Univ n f ps) = Univ n (mapFormula mapH_FORMULA f) ps
mapH_FORMULA (Exist n f ps) = Exist n (mapFormula mapH_FORMULA f) ps
mapH_FORMULA (Here n ps) = Here n ps
resolveMODALITY :: MixResolve MODALITY
resolveMODALITY ga ids m = case m of
Term_mod t -> fmap Term_mod $ resolveMixTrm mapH_FORMULA
resolveH_FORMULA ga ids t
resolveH_FORMULA :: MixResolve H_FORMULA
resolveH_FORMULA ga ids cf = case cf of
BoxOrDiamond b m f ps -> do
nm <- resolveMODALITY ga ids m
nf <- resolveMixFrm mapH_FORMULA resolveH_FORMULA ga ids f
return (BoxOrDiamond b nm nf ps)
nf <- resolveMixFrm mapH_FORMULA resolveH_FORMULA ga ids f
nf <- resolveMixFrm mapH_FORMULA resolveH_FORMULA ga ids f
nf <- resolveMixFrm mapH_FORMULA resolveH_FORMULA ga ids f
Here n ps -> return (Here n ps)
minExpForm :: Min H_FORMULA HybridSign
let minMod md ps = case md of
Simple_mod i -> minMod (Term_mod (Mixfix_token i)) ps
t2 <- oneExpTerm minExpForm s t
supers = supersortsOf srt s
then Result [mkDiag Error
("unknown term modality sort '"
++ showId srt "' for term") t ]
then return $ Simple_mod tm
[mkDiag Error "unknown modality" tm]
Application (Op_name (Id [tm] [] _)) [] _ ->
then return $ Simple_mod tm
minNom (Simple_nom n) = if
Map.member n (nomies $ extendedInfo s)
then return (Simple_nom n)
else Result [mkDiag Error "unknown nominal" n]
[mkDiag Error "collision on nominals" n] $ Just (Simple_nom n)
[mkDiag Error "\"world\" prefixes are reserved" n] Nothing
| otherwise = return (Simple_nom n)
addUniv (Simple_nom n) = addNomId [] n
addExist (Simple_nom n ) = addNomId [] n
nf <- minExpFORMULA minExpForm s f
return (BoxOrDiamond b nm nf ps)
nf <- minExpFORMULA minExpForm s f
{- add the binder in the sign (for this formula only)
so it can be used a normal nominal -}
bs <- addUniv nn (extendedInfo s)
nf <- minExpFORMULA minExpForm (s {extendedInfo = bs}) f
{- add the binder in the sign (for this formula only)
so it can be used a normal nominal -}
bs <- addExist nn (extendedInfo s)
nf <- minExpFORMULA minExpForm (s {extendedInfo = bs}) f
ana_H_SIG_ITEM :: Ana H_SIG_ITEM H_BASIC_ITEM H_SIG_ITEM H_FORMULA HybridSign
Rigid_op_items r al ps ->
do ul <- mapM (ana_OP_ITEM minExpForm mix) al
Rigid -> mapM_ (\ aoi -> case item aoi of
mapM_ (updateExtInfo . addRigidOp (toOpType ty)) ops
Op_defn i par _ _ -> maybe (return ())
(\ ty -> updateExtInfo $ addRigidOp (toOpType ty) i)
return $ Rigid_op_items r ul ps
Rigid_pred_items r al ps ->
do ul <- mapM (ana_PRED_ITEM minExpForm mix) al
Rigid -> mapM_ (\ aoi -> case item aoi of
mapM_ (updateExtInfo . addRigidPred (toPredType ty)) ops
Pred_defn i (Pred_head args _) _ _ ->
updateExtInfo $ addRigidPred
(PredType $ sortsOfArgs args) i ) ul
return $ Rigid_pred_items r ul ps
addRigidOp :: OpType -> Id -> HybridSign -> Result HybridSign
addRigidOp ty i m = return
m { rigidOps = addOpTo i ty $ rigidOps m }
addRigidPred :: PredType -> Id -> HybridSign -> Result HybridSign
addRigidPred ty i m = return
:: Ana H_BASIC_ITEM H_BASIC_ITEM H_SIG_ITEM H_FORMULA HybridSign
ana_H_BASIC_ITEM mix bi =
newFs <- mapAnM (ana_FORMULA mix) fs
resFs <- mapAnM (return . fst) newFs
anaFs <- mapAnM (return . snd) newFs
Simple_mod_decl al fs ps -> do
mapM_ ((updateExtInfo . preAddModId) . item) al
(resFs, anaFs) <- anaHlp fs
mapM_ ((updateExtInfo . addModId anaFs) . item) al
return $ Simple_mod_decl al resFs ps
Term_mod_decl al fs ps -> do
mapM_ ((updateExtInfo . preAddModSort e) . item) al
(resFs, anaFs) <- anaHlp fs
mapM_ ((updateExtInfo . addModSort anaFs) . item) al
return $ Term_mod_decl al resFs ps
Simple_nom_decl ids fs ps -> do
mapM_ ((updateExtInfo . preAddNomId) . item) ids
(resFs, anaFs) <- anaHlp fs
mapM_ ((updateExtInfo . addNomId anaFs) . item) ids
return $ Simple_nom_decl ids resFs ps
preAddNomId :: SIMPLE_ID -> HybridSign -> Result HybridSign
Result [mkDiag Hint "repeated nominal" i] $ Just hs
then Result [mkDiag Error "\"world\" prefixes are reserved" i]
preAddModId :: SIMPLE_ID -> HybridSign -> Result HybridSign
Result [mkDiag Hint "repeated modality" i] $ Just m
addNomId :: [AnHybFORM] -> SIMPLE_ID -> HybridSign -> Result HybridSign
addModId :: [AnHybFORM] -> SIMPLE_ID -> HybridSign -> Result HybridSign
addModId frms i m = return m
preAddModSort :: Sign H_FORMULA HybridSign -> SORT -> HybridSign
Result (mkDiag Hint "repeated term modality" i : ds) $ Just m
addModSort :: [AnHybFORM] -> SORT -> HybridSign -> Result HybridSign
addModSort frms i m = return m
ana_FORMULA :: Mix H_BASIC_ITEM H_SIG_ITEM H_FORMULA HybridSign
-> FORMULA H_FORMULA -> State (Sign H_FORMULA HybridSign)
(FORMULA H_FORMULA, FORMULA H_FORMULA)
let ps = map (mkId . (: [])) $
Set.toList $ getFormPredToks f
mapM_ (addPred (emptyAnno ()) $ PredType []) ps
let Result es m = resolveFormula mapH_FORMULA
resolveH_FORMULA newGa (mixRules mix) f
n <- resultToState (minExpFORMULA minExpForm e) r
getFormPredToks :: FORMULA H_FORMULA ->
Set.Set Token
getFormPredToks frm = case frm of
Quantification _ _ f _ -> getFormPredToks f
Junction _ fs _ ->
Set.unions $ map getFormPredToks fs
Set.union (getFormPredToks f1) $ getFormPredToks f2
Negation f _ -> getFormPredToks f
Mixfix_formula t -> getTermPredToks t
ExtFORMULA (BoxOrDiamond _ _ f _) -> getFormPredToks f
ExtFORMULA (At _ f _ ) -> getFormPredToks f
ExtFORMULA (Univ _ f _ ) -> getFormPredToks f
ExtFORMULA (Exist _ f _ ) -> getFormPredToks f
Predication _ ts _ ->
Set.unions $ map getTermPredToks ts
Definedness t _ -> getTermPredToks t
Membership t _ _ -> getTermPredToks t
getTermPredToks :: TERM H_FORMULA ->
Set.Set Token
getTermPredToks trm = case trm of
Application _ ts _ ->
Set.unions $ map getTermPredToks ts
Sorted_term t _ _ -> getTermPredToks t
Cast t _ _ -> getTermPredToks t
Conditional t1 f t2 _ ->
Set.union (getTermPredToks t1) $
Set.union (getFormPredToks f) $ getTermPredToks t2
Mixfix_term ts ->
Set.unions $ map getTermPredToks ts
Mixfix_parenthesized ts _ ->
Set.unions $ map getTermPredToks ts
Mixfix_bracketed ts _ ->
Set.unions $ map getTermPredToks ts
Mixfix_braced ts _ ->
Set.unions $ map getTermPredToks ts
wPrefix = isPrefixOf "world" . tokStr