Verified Commit 2801f19d authored by Camil Staps's avatar Camil Staps
Browse files

Resolve duplicate entries in derivemap (clean-cloogle/cloogle.org#157)

parent 7d62a7fc
......@@ -21,8 +21,8 @@ import Data.Generics.GenLexOrd
import Data.Graphviz
from Data.List import foldr1, groupBy, intercalate, intersect, tails, instance Functor []
from Data.Map import :: Map(..), elems, filterWithKey, foldrNoKey,
foldrWithKey, fromList, get, mapSize, mapWithKey, newMap, put, toAscList,
toList, instance Functor (Map k)
foldrWithKey, fromList, get, mapSize, alter, mapWithKey, newMap, put,
toAscList, toList, instance Functor (Map k)
import Data.Maybe
import Data.Tuple
import System.File
......@@ -353,8 +353,14 @@ getDerivations :: !Name !CloogleDB -> [DeriveEntry]
getDerivations gen db = mb2list (get gen db.derivemap)
putDerivation :: !Name !Type !String !Location !CloogleDB -> CloogleDB
putDerivation gen t s loc db = {db & derivemap=put gen ts db.derivemap}
where ts = removeDup [{de_type=t, de_type_representation=s, de_locations=[loc], de_isclass=False} : getDerivations gen db]
putDerivation gen t s loc db = {db & derivemap=alter update gen db.derivemap}
where
update :: (Maybe [DeriveEntry]) -> Maybe [DeriveEntry]
update Nothing = Just [{de_type=t, de_type_representation=s, de_locations=[loc], de_isclass=False}]
update (Just []) = update Nothing
update (Just [de:rest])
| de.de_type == t = Just [{de & de_locations=removeDup [loc:de.de_locations]}:rest]
| otherwise = (\des -> [de:des]) <$> update (Just rest)
putDerivations :: !Name ![(!Type, !String, !Location)] !CloogleDB -> CloogleDB
putDerivations gen ts db = foldr (\(t,s,l) db -> putDerivation gen t s l db) db ts
......@@ -401,9 +407,8 @@ syncDb 0 db =
}
where
prep = snd o prepare_unification False typedefs
with typedefs = map getTypeDef $ allTypes db
simplify t = removeTypeContexts $ snd $ resolve_synonyms typedefs t
where typedefs = map getTypeDef $ allTypes db
typedefs = map getTypeDef $ allTypes db
syncDb n db = syncDb (n-1)
{ db
& classmap = fromList clss
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment