Commit 6ec3dbff authored by Camil Staps's avatar Camil Staps 🚀

Add instance links on types

parent 4d9088d4
......@@ -74,7 +74,7 @@ from CloogleDB import
:: CloogleEntry(..),
:: ModuleEntry{me_loc,me_is_core,me_is_app,me_documentation},
:: FunctionEntry{fe_loc,fe_type,fe_kind,fe_generic_vars,fe_priority,fe_representation,fe_documentation,fe_class},
:: TypeDefEntry{tde_loc},
:: TypeDefEntry{tde_loc,tde_instances},
:: ClassEntry{ce_loc,ce_instances},
:: SyntaxEntry, :: DeriveEntry,
:: InstanceEntry{ie_class,ie_types,ie_locations},
......@@ -113,30 +113,27 @@ newTemporaryDb
}
finaliseDb :: ![CloogleEntry] !TemporaryDB -> *'CDB'.CloogleDB
finaliseDb extra tdb
# db = newDB entries
# name_ngrams = foldr (uncurry index) (newNGramIndex 3 True)
[('CDB'.getName loc, i) \\ (i,e) <- entridxs, Just loc <- ['CDB'.getLocation e]]
=
{ db = db
, name_ngrams = name_ngrams
finaliseDb extra tdb =
{ db = newDB entries
, name_ngrams = foldr (uncurry index) (newNGramIndex 3 True)
[('CDB'.getName loc, i) \\ (i,e) <- entridxs, Just loc <- ['CDB'.getLocation e]]
, types = foldr (uncurry addType) zero
[(snd $ 'T'.prepare_unification False (map 'CDB'.getTypeDef typedefs) $ 'T'.removeTypeContexts t,i)
[(snd $ 'T'.prepare_unification False ['CDB'.getTypeDef td \\ TypeDefEntry td <- entries] $ 'T'.removeTypeContexts t,i)
\\ (i,FunctionEntry fe) <- entridxs, Just t <- [fe.fe_type <|> (docType =<< fe.fe_documentation)]]
, core = coreidxs
, apps = appidxs
, builtins = builtinidxs
, builtins = idxfilter \e -> fromMaybe False ('CDB'.isBuiltin <$> 'CDB'.getLocation e)
, syntax = idxfilter \e -> e=:(SyntaxEntry _)
, library_map = libmap
, module_map = modmap
}
where
entries =
entries = map link $
extra ++
[FunctionEntry fun \\ funs <- tdb.temp_functions, fun <- funs] ++
map TypeDefEntry typedefs ++
[TypeDefEntry tde \\ tds <- tdb.temp_types, tde <- tds] ++
[ModuleEntry mod \\ mod <- tdb.temp_modules] ++
map ClassEntry classes ++
[ClassEntry cls \\ clss <- tdb.temp_classes, (cls,_) <- clss] ++
[FunctionEntry
{ fun
& fe_kind=case fun.fe_kind of Function -> ClassMember; Macro -> ClassMacro
......@@ -146,20 +143,30 @@ where
_ -> False
}
\\ clss <- tdb.temp_classes, (cls,funs) <- clss, (fname,fun) <- funs] ++
[InstanceEntry {ie_class=cls,ie_types=types,ie_locations=map thd3 is} // TODO combine locations
[InstanceEntry {ie_class=cls,ie_types=types,ie_locations=map thd3 is}
\\ is=:[(cls,types,_):_] <- groupBy instanceEq
$ sortBy ((<) `on` (\(c,ts,_) -> (c,map snd ts)))
$ flatten tdb.temp_instances]
where
link :: CloogleEntry -> CloogleEntry
link (TypeDefEntry tde) = TypeDefEntry
{ tde
& tde_instances=idxfilter \e -> case e of
InstanceEntry ie -> not $ isEmpty [() \\ 'T'.Type t [] <- concatMap ('T'.subtypes o fst) ie.ie_types | t == 'CDB'.getName tde.tde_loc]
_ -> False
}
link (ClassEntry ce) = ClassEntry
{ ce
& ce_instances=idxfilter \e -> case e of
InstanceEntry ie -> ie.ie_class == 'CDB'.getName ce.ce_loc
_ -> False
}
link e = e
entridxs = zip2 [Index i \\ i <- [0..]] entries
idxfilter f = [idx \\ (idx,e) <- entridxs | f e]
idxhd = hd o idxfilter
typedefs = [td \\ tds <- tdb.temp_types, td <- tds]
classes = [{cls & ce_instances=idxfilter \e -> case e of
InstanceEntry ie -> ie.ie_class == 'CDB'.getName cls.ce_loc
_ -> False}
\\ clss <- tdb.temp_classes, (cls,_) <- clss]
coreidxs = idxfilter \e -> case 'CDB'.getLocation e of
Nothing -> False
Just l -> case ('CDB'.getLibrary l, 'CDB'.getModule l) of
......@@ -174,9 +181,6 @@ where
_ -> False
where
appmods = [(fromJust $ 'CDB'.getLibrary me.me_loc, fromJust $ 'CDB'.getModule me.me_loc) \\ me <- tdb.temp_modules | me.me_is_app]
builtinidxs = idxfilter \e -> case 'CDB'.getLocation e of
Just (Builtin _ _) -> True
_ -> False
libmap = 'M'.fromList
[(l,idxfilter \e -> case 'CDB'.getLocation e >>= 'CDB'.getLibrary of
......
......@@ -180,8 +180,13 @@ getIndex (Index n) (DB db)
= (e, DB db)
getIndices :: ![Index] !*(DB v ak a) -> *(![Entry v ak a], !*(DB v ak a))
getIndices [] db = ([], db)
getIndices [i:is] db
# (e,db) = getIndex i db
# (es,db) = getIndices is db
= ([e:es], db)
getIndices is (DB db)
# (es,db) = get is db
= (es, DB db)
where
get :: ![Index] !*{!Entry v ak a} -> *(![Entry v ak a], !*{!Entry v ak a})
get [] db = ([], db)
get [Index i:is] db
# (e,db) = db![i]
# (es,db) = get is db
= ([e:es], db)
......@@ -124,9 +124,12 @@ makeResult orgsearchtype tdes usedsyns (entry, annots) db
contextPenalty required_context = length [0 \\ (_,[]) <- required_context]
| entry =: (TypeDefEntry _)
# (TypeDefEntry tde) = entry
# (insts,db) = getIndices tde.tde_instances db
= (TypeResult (general,
{ type = concat $ print False tde.tde_typedef
, type_instances = [] // TODO
, type_instances = sortBy ((<) `on` fst3)
[(ie.ie_class, map snd ie.ie_types, map locResult ie.ie_locations)
\\ {value=InstanceEntry ie} <- insts]
, type_derivations = [] // TODO
, type_field_doc = docFields =<< tde.tde_doc
, type_constructor_doc = map ((=<<) docDescription) <$> (docConstructors =<< tde.tde_doc)
......
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