Copyright : (c) Christian Maeder and Uni Bremen 2003-2005
Maintainer : maeder@tzi.de
-- * extract predicate ids from As for mixfix analysis
idsOfBasicSpec :: BasicSpec -> Ids
idsOfBasicSpec (BasicSpec l) = unite $ map (idsOfBasicItem . item) l
idsOfBasicItem :: BasicItem -> Ids
idsOfBasicItem (SigItems i) = idsOfSigItems i
idsOfBasicItem (ClassItems _ l _ ) = unite $ map (idsOfClassItem . item) l
idsOfBasicItem (GenItems l _) = unite $ map (idsOfSigItems . item) l
idsOfBasicItem (Internal l _) = unite $ map (idsOfBasicItem . item) l
idsOfClassItem :: ClassItem -> Ids
idsOfClassItem (ClassItem _ l _) = unite $ map (idsOfBasicItem . item) l
idsOfSigItems :: SigItems -> Ids
idsOfSigItems (OpItems b l _) = unite $ map (idsOfOpItem b . item) l
idsOfOpItem :: OpBrand -> OpItem -> Ids
idsOfOpItem b (OpDecl os _ _ _) =
idsOfOpItem b (OpDefn (OpId i _ _) _ _ _ _ _) =
basicAnalysis :: (BasicSpec, Env, GlobalAnnos) ->
Result (BasicSpec, Env, Env, [Named Sentence])
basicAnalysis (b, e, ga) =
let (nb, ne) = runState (anaBasicSpec ga b) e
in Result (reverse $ envDiags ne) $
Just (nb, diffEnv ce e, ce, reverse $ sentences ne)
-- | is the signature empty?
isEmptyEnv :: Env -> Bool
-- | is the first argument a subsignature of the second?
isSubEnv :: Env -> Env -> Bool
isSubEnv e1 e2 = isEmptyEnv $ diffEnv e1 e2
e1 == e2 = isSubEnv e1 e2 && isSubEnv e2 e1
-- | compute difference of signatures
diffEnv :: Env -> Env -> Env
diffEnv e1 e2 = let tm = typeMap e2 in
(assumps e1) (assumps e2)
-- | compute difference of class infos
diffClass :: ClassInfo -> ClassInfo -> Maybe ClassInfo
-- | compute difference of type infos
diffType :: TypeInfo -> TypeInfo -> Maybe TypeInfo
-- | compute difference of overloaded operations
diffAss :: TypeMap -> OpInfos -> OpInfos -> Maybe OpInfos
diffAss tm (OpInfos l1) (OpInfos l2) =
let l3 = diffOps l1 l2 in
if null l3 then Nothing else Just (OpInfos l3)
n = mapOpInfo (id, expandAlias tm) o
in if any (instScheme tm 1 (opType n) . expand tm . opType) ps
-- | environment with predefined types and operations
addPreDefs e = e { typeMap = addUnit $ typeMap e
, assumps = addOps $ assumps e }
-- | environment with predefined types and operations
preEnv = addPreDefs initialEnv
-- | clean up finally accumulated environment
cleanEnv e = diffEnv initialEnv
anaBasicSpec :: GlobalAnnos -> BasicSpec -> State Env BasicSpec
anaBasicSpec ga b@(BasicSpec l) = do
Definition Pred _ -> True
_ -> False) . opInfos) newAs
newPreds = idsOfBasicSpec b
precs = mkPrecIntMap $ prec_annos newGa
put (addPreDefs e) { preIds = (precs, rels) }
ul <- mapAnM (anaBasicItem newGa) l
anaBasicItem :: GlobalAnnos -> BasicItem -> State Env BasicItem
anaBasicItem ga (SigItems i) = fmap SigItems $ anaSigItems ga Loose i
anaBasicItem ga (ClassItems inst l ps) =
do ul <- mapAnM (anaClassItem ga inst) l
return $ ClassItems inst ul ps
anaBasicItem _ (GenVarItems l ps) =
do ul <- mapM (anaddGenVarDecl True) l
return $ GenVarItems (catMaybes ul) ps
anaBasicItem ga (ProgItems l ps) =
do ul <- mapAnMaybe (anaProgEq ga) l
anaBasicItem _ (FreeDatatype l ps) =
do al <- mapAnMaybe ana1Datatype l
tys <- mapM (dataPatToType . item) al
ul <- mapAnMaybe (anaDatatype Free Plain tys) al
return $ FreeDatatype ul ps
anaBasicItem ga (GenItems l ps) =
do ul <- mapAnM (anaSigItems ga Generated) l
anaBasicItem ga (AxiomItems decls fs ps) =
do tm <- gets typeMap -- save type map
as <- gets assumps -- save vars
ds <- mapM (anaddGenVarDecl True) decls
ts <- mapM (anaFormula ga) fs
sens = map ( \ f -> (emptyName $ Formula $ mkForall newDs
(item f) ps) { senName = getRLabel f })
return $ AxiomItems newDs newFs ps
anaBasicItem ga (Internal l ps) =
do ul <- mapAnM (anaBasicItem ga) l
mkForall :: [GenVarDecl] -> Term -> Range -> Term
mkForall _vs t _ps = t -- look for a minimal quantification
-- if null vs then t else QuantifiedTerm Universal vs t ps
anaSigItems :: GlobalAnnos -> GenKind -> SigItems -> State Env SigItems
anaSigItems ga gk (TypeItems inst l ps) =
do ul <- anaTypeItems ga gk inst l
return $ TypeItems inst ul ps
anaSigItems ga _ (OpItems b l ps) =
do ul <- mapAnMaybe (anaOpItem ga b) l
-- | analyse a class item
anaClassItem :: GlobalAnnos -> Instance -> ClassItem
anaClassItem ga _ (ClassItem d l ps) =
ul <- mapAnM (anaBasicItem ga) l
return $ ClassItem cd ul ps