StaticAna.hs revision e935423c16e00af45bffbe131f4bd9ae01853fcb
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettModule : $Header$
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettCopyright : (c) Christian Maeder and Uni Bremen 2002-2003
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettMaintainer : hets@tzi.de
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachStability : provisional
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachPortability : portable
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettCASL static analysis for basic specifications
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettFollows Chaps. III:2 and III:3 of the CASL Reference Manual.
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach{- todo: correct implementation of variables
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach (shadowing instead of overloading)
1538a6e8d77301d6de757616ffc69ee61f1482e4Andy Gimblettimport qualified Common.Lib.Map as Map
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbachimport qualified Common.Lib.Set as Set
eeaf0a8a1dc535d105904a2190f26c0835ecf429Andy GimblettcheckPlaces :: [SORT] -> Id -> [Diagnosis]
06dd4e7c29f33f6122a910719e3bd9062256e397Andy GimblettcheckPlaces args i =
1538a6e8d77301d6de757616ffc69ee61f1482e4Andy Gimblett if let n = placeCount i in n == 0 || n == length args then []
c4b2418421546a337f83332fe0db04742dcd735dAndy Gimblett else [mkDiag Error "wrong number of places" i]
a65b135c4ed7e68b2510bc218018ffa8f9a34fe8Liam O'ReillyaddOp :: OpType -> Id -> State (Sign f e) ()
6caa773a17aa8cb5b6196abbd5ede98ef01beb8aChristian Maeder do checkSorts (opRes ty : opArgs ty)
6caa773a17aa8cb5b6196abbd5ede98ef01beb8aChristian Maeder let m = opMap e
6caa773a17aa8cb5b6196abbd5ede98ef01beb8aChristian Maeder check = addDiags $ checkPlaces (opArgs ty) i
6caa773a17aa8cb5b6196abbd5ede98ef01beb8aChristian Maeder store = do put e { opMap = addOpTo i ty m }
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett addDiags [mkDiag Hint "redeclared op" i]
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett else case opKind ty of
7caf9f99d426a25d56eb7473fea1f55ce4460762Andy Gimblett Partial -> if Set.member ty {opKind = Total} l then
7caf9f99d426a25d56eb7473fea1f55ce4460762Andy Gimblett addDiags [mkDiag Warning "partially redeclared" i]
7caf9f99d426a25d56eb7473fea1f55ce4460762Andy Gimblett else store >> check
7caf9f99d426a25d56eb7473fea1f55ce4460762Andy Gimblett Total -> do store
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett if Set.member ty {opKind = Partial} l then
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett addDiags [mkDiag Hint "redeclared as total" i]
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettaddAssocOp :: OpType -> Id -> State (Sign f e) ()
e54c5af823b9775dd2c058185ea5bdf7593950faAndy GimblettaddAssocOp ty i = do
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett put e { assocOps = addOpTo i ty $ assocOps e }
eeaf0a8a1dc535d105904a2190f26c0835ecf429Andy GimblettupdateExtInfo :: (e -> Result e) -> State (Sign f e) ()
e771539425f4a0abef9f94cf4b63690f3603f682Andy GimblettupdateExtInfo upd = do
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett let re = upd $ extendedInfo s
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett case maybeResult re of
eeaf0a8a1dc535d105904a2190f26c0835ecf429Andy Gimblett Nothing -> return ()
eeaf0a8a1dc535d105904a2190f26c0835ecf429Andy Gimblett Just e -> put s { extendedInfo = e }
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett addDiags $ diags re
d9e78002fb0bf01a9b72d3d3415fdf9790bdfee8Andy GimblettaddOpTo :: Id -> OpType -> OpMap -> OpMap
eeaf0a8a1dc535d105904a2190f26c0835ecf429Andy GimblettaddOpTo k v m =
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett in case opKind v of
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett Total -> let vp = v { opKind = Partial } in
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett Map.insert k (Set.insert v $ Set.delete vp l) m
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett _ -> if Set.member v { opKind = Total } l then m
820947bd01ca952c3909eaa0366c6914c87cc1cbTill MossakowskiaddPred :: PredType -> Id -> State (Sign f e) ()
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy GimblettaddPred ty i =
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett do checkSorts $ predArgs ty
fbc0c2baf563fe5b664f0152674a8d3acecca58cAndy Gimblett let m = predMap e
e8c03c10d7987b223a9f6bfd5c0c54da21da5b86Andy Gimblett addDiags [mkDiag Hint "redeclared pred" i]
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett else do put e { predMap = Map.setInsert i ty m }
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett addDiags $ checkPlaces (predArgs ty) i
31f039ffdb33d78cb31d24b71d3155b11a323975Andy GimblettallOpIds :: Sign f e -> Set.Set Id
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettallOpIds = Set.fromDistinctAscList . Map.keys . opMap
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettaddAssocs :: GlobalAnnos -> Sign f e -> GlobalAnnos
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettaddAssocs ga e =
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett ga { assoc_annos =
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett foldr ( \ i m -> case Map.lookup i m of
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett Nothing -> Map.insert i ALeft m
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett _ -> m ) (assoc_annos ga) (Map.keys $ assocOps e) }
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettformulaIds :: Sign f e -> Set.Set Id
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettformulaIds e = let ops = allOpIds e in
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett Set.fromDistinctAscList (map simpleIdToId $ Map.keys $ varMap e)
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettallPredIds :: Sign f e -> Set.Set Id
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachallPredIds = Set.fromDistinctAscList . Map.keys . predMap
e54c5af823b9775dd2c058185ea5bdf7593950faAndy GimblettaddSentences :: [Named (FORMULA f)] -> State (Sign f e) ()
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettaddSentences ds =
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett put e { sentences = reverse ds ++ sentences e }
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett-- * traversing all data types of the abstract syntax
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblettana_BASIC_SPEC :: Resolver f => Min f e
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett -> Ana b f e -> Ana s f e -> GlobalAnnos
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett -> BASIC_SPEC b s f -> State (Sign f e) (BASIC_SPEC b s f)
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblettana_BASIC_SPEC mef ab as ga (Basic_spec al) = fmap Basic_spec $
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett mapAnM (ana_BASIC_ITEMS mef ab as ga) al
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett-- looseness of a datatype
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblettdata GenKind = Free | Generated | Loose deriving (Show, Eq, Ord)
31f039ffdb33d78cb31d24b71d3155b11a323975Andy GimblettmkForall :: [VAR_DECL] -> FORMULA f -> [Pos] -> FORMULA f
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettmkForall vl f ps = if null vl then f else
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett Quantification Universal vl f ps
8528886a04f14abe0ddf80f50c853cc25bc821cdAndy Gimblettana_BASIC_ITEMS :: Resolver f => Min f e
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett -> Ana b f e -> Ana s f e -> GlobalAnnos
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett -> BASIC_ITEMS b s f -> State (Sign f e) (BASIC_ITEMS b s f)
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblettana_BASIC_ITEMS mef ab as ga bi =
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett Sig_items sis -> fmap Sig_items $
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett ana_SIG_ITEMS mef as ga Loose sis
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett Free_datatype al ps ->
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett do let sorts = map (( \ (Datatype_decl s _ _) -> s) . item) al
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett mapM_ addSort sorts
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett mapAnM (ana_DATATYPE_DECL Free) al
7caf9f99d426a25d56eb7473fea1f55ce4460762Andy Gimblett toSortGenAx ps True $ getDataGenSig al
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett closeSubsortRel
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett Sort_gen al ps ->
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett do (gs,ul) <- ana_Generated mef as ga al
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett toSortGenAx ps False
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett (Set.unions $ map fst gs, Set.unions $ map snd gs)
e8c03c10d7987b223a9f6bfd5c0c54da21da5b86Andy Gimblett return $ Sort_gen ul ps
e8c03c10d7987b223a9f6bfd5c0c54da21da5b86Andy Gimblett Var_items il _ ->
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett do mapM_ addVars il
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett Local_var_axioms il afs ps ->
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett do e <- get -- save
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett mapM_ addVars il
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett put e -- restore
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett let preds = allPredIds sign
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett ops = formulaIds sign
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett newGa = addAssocs ga sign
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett rfs = map (anaForm mef newGa ops preds sign . item) afs
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett ds = concatMap diags rfs
e8c03c10d7987b223a9f6bfd5c0c54da21da5b86Andy Gimblett arfs = zipWith ( \ a m -> case maybeResult m of
e8c03c10d7987b223a9f6bfd5c0c54da21da5b86Andy Gimblett Nothing -> Nothing
7caf9f99d426a25d56eb7473fea1f55ce4460762Andy Gimblett Just f -> Just a { item = f }) afs rfs
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblett ufs = catMaybes arfs
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett fufs = map ( \ a -> a { item = mkForall il
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett (item a) ps } ) ufs
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett sens = map ( \ a -> NamedSen (getRLabel a) $ item a) fufs
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett addSentences sens
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett return $ Local_var_axioms il ufs ps
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett Axiom_items afs ps ->
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett do sign <- get
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett ops <- gets formulaIds
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett preds <- gets allPredIds
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett newGa <- gets $ addAssocs ga
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett let rfs = map (anaForm mef newGa ops preds sign . item) afs
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett ds = concatMap diags rfs
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett arfs = zipWith ( \ a m -> case maybeResult m of
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett Nothing -> Nothing
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett Just f -> Just a { item = f }) afs rfs
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett ufs = catMaybes arfs
e95030058b77cb83593c85aa4c506caf154f63b7Andy Gimblett sens = map ( \ a -> NamedSen (getRLabel a) $ item a) ufs
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett addSentences sens
fbc0c2baf563fe5b664f0152674a8d3acecca58cAndy Gimblett return $ Axiom_items ufs ps
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett Ext_BASIC_ITEMS b -> fmap Ext_BASIC_ITEMS $ ab ga b
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimbletttoSortGenAx :: [Pos] -> Bool ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett (Set.Set Id, Set.Set Component) -> State (Sign f e) ()
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimbletttoSortGenAx ps isFree (sorts, ops) = do
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett let sortList = Set.toList sorts
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett opSyms = map ( \ c -> Qual_op_name (compId c)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett (toOP_TYPE $ compType c) []) $ Set.toList ops
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett resType _ (Op_name _) = False
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett resType s (Qual_op_name _ t _) = res_OP_TYPE t ==s
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett getIndex s = maybe (-1) id $ findIndex (==s) sortList
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett addIndices (Op_name _) =
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett error "CASL/StaticAna: Internal error in function addIndices"
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett addIndices os@(Qual_op_name _ t _) =
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett (os,map getIndex $ args_OP_TYPE t)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett collectOps s =
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Constraint s (map addIndices $ filter (resType s) opSyms) s
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett constrs = map collectOps sortList
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett f = Sort_gen_ax constrs isFree
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett if null sortList then
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett addDiags[Diag Error "missing generated sort" (headPos ps)]
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett else return ()
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett addSentences [NamedSen ("ga_generated_" ++
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett showSepList (showString "_") showId sortList "") f]
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettana_SIG_ITEMS :: Resolver f => Min f e
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett -> Ana s f e -> GlobalAnnos -> GenKind
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett -> SIG_ITEMS s f -> State (Sign f e) (SIG_ITEMS s f)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettana_SIG_ITEMS mef as ga gk si =
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Sort_items al ps ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett do ul <- mapM (ana_SORT_ITEM mef ga) al
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett closeSubsortRel
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett return $ Sort_items ul ps
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Op_items al ps ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett do ul <- mapM (ana_OP_ITEM mef ga) al
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett return $ Op_items ul ps
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Pred_items al ps ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett do ul <- mapM (ana_PRED_ITEM mef ga) al
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett return $ Pred_items ul ps
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Datatype_items al _ ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett do let sorts = map (( \ (Datatype_decl s _ _) -> s) . item) al
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett mapM_ addSort sorts
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett mapAnM (ana_DATATYPE_DECL gk) al
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett closeSubsortRel
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Ext_SIG_ITEMS s -> fmap Ext_SIG_ITEMS $ as ga s
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettana_Generated :: Resolver f => Min f e
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett -> Ana s f e -> GlobalAnnos -> [Annoted (SIG_ITEMS s f)]
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett -> State (Sign f e)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett ([(Set.Set Id, Set.Set Component)],[Annoted (SIG_ITEMS s f)])
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettana_Generated mef as ga al = do
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett ul <- mapAnM (ana_SIG_ITEMS mef as ga Generated) al
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett return (map (getGenSig . item) ul, ul)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetGenSig :: SIG_ITEMS s f -> (Set.Set Id, Set.Set Component)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetGenSig si = case si of
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Sort_items al _ -> (Set.unions (map (getSorts . item) al), Set.empty)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Op_items al _ -> (Set.empty, Set.unions (map (getOps . item) al))
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Datatype_items dl _ -> getDataGenSig dl
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetDataGenSig :: [Annoted DATATYPE_DECL] -> (Set.Set Id, Set.Set Component)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetDataGenSig dl =
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett let alts = map (( \ (Datatype_decl s al _) -> (s, al)) . item) dl
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett sorts = map fst alts
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett mkComponent (i, ty, _) = Component i ty
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett cs = concatMap ( \ (s, al) -> concatMap (( \ a ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett map mkComponent (getConsType s a)))
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett $ map item al) alts
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetSorts :: SORT_ITEM f -> Set.Set Id
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Sort_decl il _ -> Set.fromList il
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Subsort_decl il i _ -> Set.fromList (i:il)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Subsort_defn sub _ _ _ _ -> Set.single sub
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Iso_decl il _ -> Set.fromList il
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetOps :: OP_ITEM f -> Set.Set Component
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy GimblettgetOps oi = case oi of
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Op_decl is ty _ _ ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Set.fromList $ map ( \ i -> Component i $ toOpType ty) is
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Op_defn i par _ _ -> Set.single $ Component i $ toOpType $ headToType par
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettana_SORT_ITEM :: Resolver f => Min f e
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett -> GlobalAnnos -> Annoted (SORT_ITEM f)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett -> State (Sign f e) (Annoted (SORT_ITEM f))
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettana_SORT_ITEM mef ga asi =
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett case item asi of
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett Sort_decl il _ ->
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett do mapM_ addSort il
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett Subsort_decl il i _ ->
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett do mapM_ addSort (i:il)
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett mapM_ (addSubsort i) il
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett Subsort_defn sub v super af ps ->
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett do e <- get -- save
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett put e { varMap = Map.empty }
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett addVars (Var_decl [v] super ps)
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett ops <- gets formulaIds
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett preds <- gets allPredIds
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett newGa <- gets $ addAssocs ga
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett put e -- restore
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett let Result ds mf = anaForm mef newGa ops preds sign $ item af
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett lb = getRLabel af
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett lab = if null lb then getRLabel asi else lb
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett addSubsort super sub
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett Nothing -> return asi { item = Subsort_decl [sub] super ps}
7996f5f893cc14b5e22fdb7ec90a3474ba3c51abAndy Gimblett let p = [posOfId sub]
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett pv = [tokPos v]
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett addSentences[NamedSen lab $
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett mkForall [Var_decl [v] super pv]
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett (Membership (Qual_var v super pv) sub p)
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett return asi { item = Subsort_defn sub v super af { item = f } ps}
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett Iso_decl il _ ->
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett do mapM_ addSort il
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett mapM_ ( \ i -> mapM_ (addSubsort i) il) il
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblettana_OP_ITEM :: Resolver f => Min f e -> GlobalAnnos -> Annoted (OP_ITEM f)
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett -> State (Sign f e) (Annoted (OP_ITEM f))
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblettana_OP_ITEM mef ga aoi =
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett case item aoi of
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett Op_decl ops ty il ps ->
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett do let oty = toOpType ty
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett mapM_ (addOp oty) ops
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett ul <- mapM (ana_OP_ATTR mef ga oty ops) il
d9e78002fb0bf01a9b72d3d3415fdf9790bdfee8Andy Gimblett if null $ filter ( \ i -> case i of
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett Assoc_op_attr -> True
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett _ -> False) il
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett then return ()
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett else mapM_ (addAssocOp oty) ops
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett return aoi {item = Op_decl ops ty (catMaybes ul) ps}
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett Op_defn i ohd at ps ->
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett do let ty = headToType ohd
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett lb = getRLabel at
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett lab = if null lb then getRLabel aoi else lb
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett args = case ohd of
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett Op_head _ as _ _ -> as
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett vs = map (\ (Arg_decl v s qs) -> (Var_decl v s qs)) args
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett arg = concatMap ( \ (Var_decl v s qs) ->
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett map ( \ j -> Qual_var j s qs) v) vs
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett addOp (toOpType ty) i
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett e <- get -- save
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett put e { varMap = Map.empty }
fbc0c2baf563fe5b664f0152674a8d3acecca58cAndy Gimblett mapM_ addVars vs
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett ops <- gets formulaIds
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett preds <- gets allPredIds
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett newGa <- gets $ addAssocs ga
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett put e -- restore
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett let Result ds mt = anaTerm mef newGa ops preds sign $
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett Sorted_term (item at) (res_OP_TYPE ty) ps
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett Nothing -> return aoi { item = Op_decl [i] ty [] ps }
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett Just t -> do let p = [posOfId i]
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett addSentences [NamedSen lab $
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett (Strong_equation
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett (Application (Qual_op_name i ty p) arg ps)
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett return aoi {item = Op_defn i ohd at { item = t } ps }
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettheadToType :: OP_HEAD -> OP_TYPE
9582375827616730f146b77f9d5a4fd0cc78bc47Andy GimblettheadToType (Op_head k args r ps) = Op_type k (sortsOfArgs args) r ps
9582375827616730f146b77f9d5a4fd0cc78bc47Andy GimblettsortsOfArgs :: [ARG_DECL] -> [SORT]
a731366827a80af216ce6bfd4aa6388260577791Andy GimblettsortsOfArgs = concatMap ( \ (Arg_decl l s _) -> map (const s) l)
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblettana_OP_ATTR :: Resolver f => Min f e -> GlobalAnnos
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett -> OpType -> [Id] -> (OP_ATTR f)
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett -> State (Sign f e) (Maybe (OP_ATTR f))
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblettana_OP_ATTR mef ga ty ois oa =
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett let sty = toOP_TYPE ty
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett rty = opRes ty
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett q = [posOfId rty] in
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett Unit_op_attr t ->
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett do sign <- get
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett ops <- gets allOpIds
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett preds <- gets allPredIds
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett newGa <- gets $ addAssocs ga
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett let Result ds mt = anaTerm mef newGa ops preds sign
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett (Sorted_term t rty q)
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett Nothing -> return Nothing
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett addSentences $ map (makeUnit True e ty) ois
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett addSentences $ map (makeUnit False e ty) ois
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett return $ Just $ Unit_op_attr e
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett Assoc_op_attr -> do
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett let ns = map mkSimpleId ["x", "y", "z"]
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett vs = map ( \ v -> Var_decl [v] rty q) ns
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett [v1, v2, v3] = map ( \ v -> Qual_var v rty q) ns
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett makeAssoc i = let p = [posOfId i]
9582375827616730f146b77f9d5a4fd0cc78bc47Andy Gimblett qi = Qual_op_name i sty p in
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett NamedSen ("ga_assoc_" ++ showId i "") $
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett (Strong_equation
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett (Application qi [v1, Application qi [v2, v3] p] p)
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett (Application qi [Application qi [v1, v2] p, v3] p) p) p
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett addSentences $ map makeAssoc ois
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett return $ Just oa
adce8375991a372444ab995895442dca6faf9677Andy Gimblett Comm_op_attr -> do
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett let ns = map mkSimpleId ["x", "y"]
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett atys = opArgs ty
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett vs = zipWith ( \ v t -> Var_decl [v] t (map posOfId atys) ) ns atys
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett args = map toQualVar vs
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett makeComm i = let p = [posOfId i]
a731366827a80af216ce6bfd4aa6388260577791Andy Gimblett qi = Qual_op_name i sty p in
31f039ffdb33d78cb31d24b71d3155b11a323975Andy Gimblett NamedSen ("ga_comm_" ++ showId i "") $
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett (Strong_equation
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett (Application qi args p)
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett (Application qi (reverse args) p) p) p
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett [_,_] -> addSentences $ map makeComm ois
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett _ -> addDiags [Diag Error "expecting two arguments for commutativity"
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett $ posOfId rty]
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett return $ Just oa
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett Idem_op_attr -> do
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett let v = mkSimpleId "x"
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett vd = Var_decl [v] rty q
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett qv = toQualVar vd
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett makeIdem i = let p = [posOfId i] in
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett NamedSen ("ga_idem_" ++ showId i "") $
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett mkForall [vd]
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett (Strong_equation
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett (Application (Qual_op_name i sty p) [qv, qv] p)
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett addSentences $ map makeIdem ois
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett return $ Just oa
c679188b6762edb198e353f724e77c74aa64a7e4Andy GimblettmakeUnit :: Bool -> TERM f -> OpType -> Id -> Named (FORMULA f)
c679188b6762edb198e353f724e77c74aa64a7e4Andy GimblettmakeUnit b t ty i =
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett let lab = "ga_" ++ (if b then "right" else "left") ++ "_unit_"
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett ++ showId i ""
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett v = mkSimpleId "x"
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett vty = opRes ty
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett q = [posOfId vty]
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett p = [posOfId i]
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett qv = Qual_var v vty q
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett args = [qv, t]
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett rargs = if b then args else reverse args
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett in NamedSen lab $ mkForall [Var_decl [v] vty q]
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett (Strong_equation
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett (Application (Qual_op_name i (toOP_TYPE ty) p) rargs p)
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblettana_PRED_ITEM :: Resolver f => Min f e
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett -> GlobalAnnos -> Annoted (PRED_ITEM f)
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett -> State (Sign f e) (Annoted (PRED_ITEM f))
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblettana_PRED_ITEM mef ga ap =
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett case item ap of
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett Pred_decl preds ty _ ->
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett do mapM (addPred $ toPredType ty) preds
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett Pred_defn i phd@(Pred_head args rs) at ps ->
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett do let lb = getRLabel at
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett lab = if null lb then getRLabel ap else lb
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett ty = Pred_type (sortsOfArgs args) rs
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett vs = map (\ (Arg_decl v s qs) -> (Var_decl v s qs)) args
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett arg = concatMap ( \ (Var_decl v s qs) ->
c679188b6762edb198e353f724e77c74aa64a7e4Andy Gimblett map ( \ j -> Qual_var j s qs) v) vs
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett addPred (toPredType ty) i
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett e <- get -- save
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett put e { varMap = Map.empty }
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett mapM_ addVars vs
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett ops <- gets formulaIds
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett preds <- gets allPredIds
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett newGa <- gets $ addAssocs ga
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett put e -- restore
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett let Result ds mt = anaForm mef newGa ops preds sign $ item at
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett Nothing -> return ap {item = Pred_decl [i] ty ps}
f18cf8a4e7d512a2f57365ab1e9e7fdbb98ba257Andy Gimblett let p = [posOfId i]
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett addSentences [NamedSen lab $
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (Equivalence (Predication (Qual_pred_name i ty p)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett arg p) t p) p]
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett return ap {item = Pred_defn i phd at { item = t } ps}
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett-- full function type of a selector (result sort is component sort)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettdata Component = Component { compId :: Id, compType :: OpType }
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett deriving (Show)
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblettinstance Eq Component where
d04c328b10f17ec78001a94d694f7188ebd8c03cAndy Gimblett Component i1 t1 == Component i2 t2 =
c909c215242232fe78ce335e677e6f22264a0ee9Christian Maeder (i1, opArgs t1, opRes t1) == (i2, opArgs t2, opRes t2)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblettinstance Ord Component where
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett Component i1 t1 <= Component i2 t2 =
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (i1, opArgs t1, opRes t1) <= (i2, opArgs t2, opRes t2)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblettinstance PrettyPrint Component where
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett printText0 ga (Component i ty) =
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett printText0 ga i <+> colon <> printText0 ga ty
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblettinstance PosItem Component where
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett get_pos = Just . posOfId . compId
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett-- | return list of constructors
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblettana_DATATYPE_DECL :: GenKind -> DATATYPE_DECL -> State (Sign f e) [Component]
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblettana_DATATYPE_DECL gk (Datatype_decl s al _) =
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett do ul <- mapM (ana_ALTERNATIVE s . item) al
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett let constr = catMaybes ul
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett cs = map fst constr
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett if null constr then return ()
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett else do addDiags $ checkUniqueness cs
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett let totalSels = Set.unions $ map snd constr
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett wrongConstr = filter ((totalSels /=) . snd) constr
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett addDiags $ map ( \ (c, _) -> mkDiag Error
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett ("total selectors '" ++ showSepList (showString ",")
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett showPretty (Set.toList totalSels)
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett "'\n must appear in alternative") c) wrongConstr
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett let allts = map item al
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett (alts, subs) = partition ( \ a -> case a of
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett Subsorts _ _ -> False
2f615f62c47e2c0ae9964f37f5bac6905d86f475Andy Gimblett _ -> True) allts
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett sbs = concatMap ( \ (Subsorts ss _) -> ss) subs
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett comps = concatMap (getConsType s) alts
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett ttrips = map (( \ (a, vs, t, ses) -> (a, vs, t, catSels ses))
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett . selForms1 "X" ) comps
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett sels = concatMap ( \ (_, _, _, ses) -> ses) ttrips
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett addSentences $ map makeInjective
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett $ filter ( \ (_, _, ces) -> not $ null ces)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett addSentences $ concatMap ( \ as -> map (makeDisjToSort as) sbs)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett addSentences $ makeDisjoint comps
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett addSentences $ catMaybes $ concatMap
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett map (makeUndefForm ses) ttrips) sels
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett _ -> return ()
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisjToSort :: (Id, OpType, [COMPONENTS]) -> SORT -> Named (FORMULA f)
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisjToSort a s =
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett let (c, v, t, _) = selForms1 "X" a
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett p = [posOfId s] in
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett NamedSen ("ga_disjoint_" ++ showId c "_sort_" ++ showId s "") $
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett mkForall v (Negation (Membership t s p) p) p
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeInjective :: (Id, OpType, [COMPONENTS]) -> Named (FORMULA f)
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeInjective a =
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett let (c, v1, t1, _) = selForms1 "X" a
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (_, v2, t2, _) = selForms1 "Y" a
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett p = [posOfId c]
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett in NamedSen ("ga_injective_" ++ showId c "") $
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett mkForall (v1 ++ v2)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (Equivalence (Strong_equation t1 t2 p)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (let ces = zipWith ( \ w1 w2 -> Strong_equation
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (toQualVar w1) (toQualVar w2) p) v1 v2
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett in if isSingle ces then head ces else Conjunction ces p)
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisjoint :: [(Id, OpType, [COMPONENTS])] -> [Named (FORMULA f)]
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisjoint [] = []
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisjoint (a:as) = map (makeDisj a) as ++ makeDisjoint as
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisj :: (Id, OpType, [COMPONENTS])
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett -> (Id, OpType, [COMPONENTS])
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett -> Named (FORMULA f)
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeDisj a1 a2 =
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett let (c1, v1, t1, _) = selForms1 "X" a1
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (c2, v2, t2, _) = selForms1 "Y" a2
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett p = [posOfId c1, posOfId c2]
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett in NamedSen ("ga_disjoint_" ++ showId c1 "_" ++ showId c2 "") $
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett mkForall (v1 ++ v2)
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett (Negation (Strong_equation t1 t2 p) p) p
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettcatSels :: [(Maybe Id, OpType)] -> [(Id, OpType)]
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettcatSels = map ( \ (m, t) -> (fromJust m, t)) .
5b5db1d788d5240070930175f1322dab56279f99Andy Gimblett filter ( \ (m, _) -> isJust m)
5b5db1d788d5240070930175f1322dab56279f99Andy GimblettmakeUndefForm :: (Id, OpType) -> (Id, [VAR_DECL], TERM f, [(Id, OpType)])
-> State (Sign f e) (Maybe (Component, Set.Set Component))
return $ Just (Component i ty, Set.fromList ts)
cleanSig = accSig { envDiags = [], sentences = [], varMap = Map.empty }