ClassAna.hs revision 23f8d286586ff38a9e73052b2c7c04c62c5c638f
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till Mossakowski Authors: Christian Maeder
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski analyse given classes
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowskiimport qualified Common.Lib.Map as Map
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowskiimport qualified Common.Lib.Set as Set
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski-- ---------------------------------------------------------------------------
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski-- analyse class
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski-- ---------------------------------------------------------------------------
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski-- transitiv super classes
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski-- PRE: all superclasses and defns must be defined in ClassEnv
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till Mossakowski-- and there must be no cycle!
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till MossakowskiallSuperClasses :: ClassMap -> ClassId -> Set.Set ClassId
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill MossakowskiallSuperClasses ce ci =
be408ef9713fbbbaf7bde82618f7d3f204fe806cTill Mossakowski let recurse = Set.unions . map (allSuperClasses ce) in
da955132262baab309a50fdffe228c9efe68251dCui Jian case Map.lookup ci ce of
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till Mossakowski Just info -> (case classDefn info of
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till Mossakowski Just (Intersection cis _) -> recurse $ Set.toList cis
7474388b4c2236f8ab2327289555000268c7901aTill Mossakowski `Set.union` recurse (Set.toList $ superClasses info)
7474388b4c2236f8ab2327289555000268c7901aTill Mossakowski Nothing -> error "allSuperClasses"
7474388b4c2236f8ab2327289555000268c7901aTill MossakowskianaClassId :: ClassMap -> ClassId -> Maybe Kind
7474388b4c2236f8ab2327289555000268c7901aTill MossakowskianaClassId cMap ci =
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till Mossakowski case Map.lookup ci cMap of
da955132262baab309a50fdffe228c9efe68251dCui Jian Nothing -> Nothing
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till Mossakowski Just i -> Just $ classKind i
99249aeda5fac6f8f0b2316ca357bac898af1928Christian MaederexpandKind :: ClassMap -> Kind -> Kind
e687bd70d6e6c98d82b239e01fef4a60de6739f4Till MossakowskiexpandKind cMap (ExtClass c _ _) =
4918e2f622cfb96f9a57b7617cd18ca7e4f8b5d4Christian Maeder Intersection s _ ->
if Set.isEmpty s then star else
case anaClassId cMap $ Set.findMin s of
let cs = Set.toList s
restCs = Set.fromList $ map snd js