Commit 4675ccc3 authored by Camil Staps's avatar Camil Staps 🚀

Add filtering on libraries and modules

parent a7e1dca0
......@@ -28,6 +28,8 @@ from TypeTree import :: TypeTree
, types :: !TypeTree Index
, core :: ![Index]
, apps :: ![Index]
, library_map :: !Map Name [Index]
, module_map :: !Map Name [Index]
}
:: AnnotationKey
......@@ -213,6 +215,8 @@ filterDB :: (CloogleEntry -> Bool) !*CloogleDB -> *CloogleDB
filterLocations :: (Location -> Bool) !*CloogleDB -> *CloogleDB
excludeCore :: !*CloogleDB -> *CloogleDB
excludeApps :: !*CloogleDB -> *CloogleDB
filterLibraries :: ![Name] !*CloogleDB -> *CloogleDB
filterModules :: ![Name] !*CloogleDB -> *CloogleDB
filterName :: !String !*CloogleDB -> *CloogleDB
filterUnifying :: !Type !*CloogleDB -> *CloogleDB
......
......@@ -20,7 +20,8 @@ from Data.Func import $, on, `on`
import Data.Functor
import Data.Generics.GenLexOrd
import Data.Graphviz
from Data.List import foldr1, groupBy, intercalate, intersect, tails, instance Functor []
from Data.List import concatMap, foldr1, groupBy, intercalate, intersect,
tails, instance Functor []
from Data.Map import :: Map(..), elems, filterWithKey, foldrNoKey,
foldrWithKey, fromList, get, mapSize, alter, mapWithKey, newMap, put,
toAscList, toList, instance Functor (Map k)
......@@ -224,12 +225,14 @@ syncDB :: !Int !*CloogleDB -> *CloogleDB
syncDB _ db = db
saveDB :: *CloogleDB *File -> *(*CloogleDB, *File)
saveDB wrapper=:{db,name_ngrams,types,core,apps} f
saveDB wrapper=:{db,name_ngrams,types,core,apps,library_map,module_map} f
# (db,f) = 'DB'.saveDB db f
# f = write name_ngrams f
# f = write types f
# f = write core f
# f = write apps f
# f = write library_map f
# f = write module_map f
= ({wrapper & db=db}, f)
where
write :: a *File -> *File | JSONEncode{|*|} a
......@@ -247,15 +250,19 @@ openDB f
| not ok = (Nothing, f)
# ((ok,apps),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,library_map),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,module_map),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
= (Just
{ db=fromJust db
, name_ngrams=fromJust name_ngrams
, types=fromJust types
, core=fromJust core
, apps=fromJust apps
}
, f
)
, library_map=fromJust library_map
, module_map=fromJust module_map
}, f)
where
read :: *File -> *(Maybe a, *File) | JSONDecode{|*|} a
read f
......@@ -295,6 +302,20 @@ excludeApps wrap=:{db,apps}
# db = 'DB'.unsearchIndices apps db
= {wrap & db=db}
filterLibraries :: ![Name] !*CloogleDB -> *CloogleDB
filterLibraries ss wrap=:{db,library_map}
# db = 'DB'.searchIndices (map (flip tuple []) idxs) db
= {wrap & db=db}
where
idxs = foldr merge [] $ catMaybes $ map (flip get library_map) ss
filterModules :: ![Name] !*CloogleDB -> *CloogleDB
filterModules ss wrap=:{db,module_map}
# db = 'DB'.searchIndices (map (flip tuple []) idxs) db
= {wrap & db=db}
where
idxs = foldr merge [] $ catMaybes $ map (flip get module_map) ss
filterName :: !String !*CloogleDB -> *CloogleDB
filterName s wrap=:{db,name_ngrams}
# db = 'DB'.searchIndices indices db
......
......@@ -124,6 +124,8 @@ finaliseDb tdb
\\ (i,FunctionEntry fe) <- entridxs, Just t <- [fe.fe_type <|> (docType =<< fe.fe_documentation)]]
, core = coreidxs
, apps = appidxs
, library_map = libmap
, module_map = modmap
}
where
collectNames = 'DB'.scan (\i v ivs -> case 'CDB'.getLocation v of
......@@ -173,6 +175,17 @@ where
where
appmods = [(fromJust $ 'CDB'.getLibrary me.me_loc, fromJust $ 'CDB'.getModule me.me_loc) \\ me <- tdb.temp_modules | me.me_is_app]
libmap = 'M'.fromList
[(l,idxfilter \e -> case 'CDB'.getLocation e >>= 'CDB'.getLibrary of
Nothing -> False
Just l` -> l == l`) \\ l <- libs]
where libs = removeDup [fromJust ('CDB'.getLibrary me.me_loc) \\ me <- tdb.temp_modules]
modmap = 'M'.fromList
[(m,idxfilter \e -> case 'CDB'.getLocation e >>= 'CDB'.getLibrary of
Nothing -> False
Just m` -> m == m`) \\ m <- mods]
where mods = removeDup [fromJust ('CDB'.getModule me.me_loc) \\ me <- tdb.temp_modules]
instanceEq :: (String, [('CDB'.Type, a)], b) (String, [('CDB'.Type, a)], b) -> Bool
instanceEq (s, ts, _) (s2, ts2, _) = s == s2 && map fst ts == map fst ts2
......
......@@ -147,19 +147,14 @@ where
unsearchIndices :: ![Index] !*(DB v ak a) -> *DB v ak a
unsearchIndices idxs (DB db)
# (s,db) = usize db
# db = upd 0 (s-1) idxs db
# db = upd idxs db
= (DB db)
where
upd :: !Int !Int ![Index] !*{!Entry v ak a} -> *{!Entry v ak a}
upd i s _ es | i > s = es
upd i s [] es = es
upd i s allidxs=:[Index idx:idxs] es
# (e,es) = es![i]
# e & included = e.included && not remove
= upd (i+1) s (if remove idxs allidxs) {es & [i]=e}
where
remove = i == idx
upd :: ![Index] !*{!Entry v ak a} -> *{!Entry v ak a}
upd [] es = es
upd [Index i:is] es
# (e,es) = es![i]
= upd is {es & [i].included=False}
getIndex :: !Index !*(DB v ak a) -> *(!Entry v ak a, !*(DB v ak a))
getIndex (Index n) (DB db)
......
......@@ -34,11 +34,11 @@ search {unify,name,className,typeName,modules,libraries,page,include_builtins,in
# cdb = if include_core cdb (excludeCore cdb)
# cdb = if include_apps cdb (excludeApps cdb)
# cdb = case libraries of
(Just ls) = filterLocations (isLibMatch ls) cdb
Nothing = cdb
Just ls -> filterLibraries ls cdb
Nothing -> cdb
# cdb = case modules of
(Just ms) = filterLocations (isModMatch ms) cdb
Nothing = cdb
Just ms -> filterModules ms cdb
Nothing -> cdb
# cdb = if include_builtins id (filterLocations (not o isBuiltin)) cdb
# cdb = case typeName of
Nothing -> cdb
......
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