Commit b8d51e33 authored by Camil Staps's avatar Camil Staps 🚀

Add instances for classes

parent f0113bdb
......@@ -114,7 +114,8 @@ derive JSONDecode CloogleEntry
* Information about a class instance
*/
:: InstanceEntry
= { ie_types :: ![(Type, String)] //* The instantiated type and a string representation for each class variable
= { ie_class :: !Name //* The class
, ie_types :: ![(Type, String)] //* The instantiated type and a string representation for each class variable
, ie_locations :: ![Location] //* The places where this instance is found
}
......@@ -207,6 +208,7 @@ saveDB :: *CloogleDB *File -> *(*CloogleDB, *File)
openDB :: !*File -> *(!Maybe *CloogleDB, !*File)
getIndex :: !Index !*CloogleDB -> *(Entry CloogleEntry AnnotationKey Annotation, *CloogleDB)
getIndices :: ![Index] !*CloogleDB -> *([Entry CloogleEntry AnnotationKey Annotation], *CloogleDB)
filterDB :: (CloogleEntry -> Bool) !*CloogleDB -> *CloogleDB
filterLocations :: (Location -> Bool) !*CloogleDB -> *CloogleDB
......
......@@ -36,7 +36,7 @@ import Type
import Cloogle
from DB import :: DB, :: Index, :: Entry{..}, getIndex, getIndices,
from DB import :: DB, :: Index, :: Entry{..},
instance == Index, instance < Index
import qualified DB
import Doc
......@@ -275,6 +275,11 @@ getIndex idx wrap=:{db}
# (e,db) = 'DB'.getIndex idx db
= (e, {wrap & db=db})
getIndices :: ![Index] !*CloogleDB -> *([Entry CloogleEntry AnnotationKey Annotation], *CloogleDB)
getIndices idxs wrap=:{db}
# (es,db) = 'DB'.getIndices idxs db
= (es, {wrap & db=db})
filterDB :: (CloogleEntry -> Bool) !*CloogleDB -> *CloogleDB
filterDB f db = {db & db = 'DB'.search (\v -> (f v, [])) db.db}
......@@ -322,7 +327,7 @@ where
allModules :: !*CloogleDB -> *([ModuleEntry], *CloogleDB)
allModules wrap=:{db,module_index}
# (mods,db) = getIndices (elems module_index) db
# (mods,db) = 'DB'.getIndices (elems module_index) db
= ([me \\ {value=ModuleEntry me} <- mods], {wrap & db=db})
allTypeDefs :: !*CloogleDB -> *([TypeDefEntry], *CloogleDB)
......
......@@ -7,6 +7,7 @@ import StdFile
from StdFunc import const, flip, id, o
import StdList
import StdMisc
import StdOrdList
import StdOverloadedList
import StdString
import StdTuple
......@@ -73,8 +74,9 @@ from CloogleDB import
:: 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},
:: ClassEntry{ce_loc},
:: SyntaxEntry, :: DeriveEntry, :: InstanceEntry,
:: ClassEntry{ce_loc,ce_instances},
:: SyntaxEntry, :: DeriveEntry,
:: InstanceEntry{ie_class,ie_types,ie_locations},
instance zero FunctionEntry, instance zero ModuleEntry,
class getLocation, instance getLocation CloogleEntry,
instance == Location
......@@ -131,7 +133,7 @@ where
[FunctionEntry fun \\ funs <- tdb.temp_functions, fun <- funs] ++
map TypeDefEntry typedefs ++
[ModuleEntry mod \\ mod <- tdb.temp_modules] ++
[ClassEntry cls \\ clss <- tdb.temp_classes, (cls,funs) <- clss] ++
map ClassEntry classes ++
[FunctionEntry
{ fun
& fe_kind=case fun.fe_kind of Function -> ClassMember; Macro -> ClassMacro
......@@ -140,11 +142,23 @@ where
ClassEntry ce -> ce.ce_loc == cls.ce_loc
_ -> False
}
\\ clss <- tdb.temp_classes, (cls,funs) <- clss, (fname,fun) <- funs]
\\ 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
\\ is=:[(cls,types,_):_] <- groupBy instanceEq
$ sortBy ((<) `on` (\(c,ts,_) -> (c,map snd ts)))
$ flatten tdb.temp_instances]
entridxs = zip2 [Index i \\ i <- [0..]] entries
idxhd f = hd [idx \\ (idx,e) <- entridxs | f e]
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]
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
// Exclude Root Library Aux Base module
findModules :: ![String] !String !'CDB'.Library !a !String !*World
......
......@@ -11,7 +11,7 @@ import StdTuple
import Control.Applicative
import Control.Monad
import qualified Data.Foldable as Foldable
from Data.Func import $, on, instance Functor ((->) r), mapSt
from Data.Func import $, on, `on`, instance Functor ((->) r), mapSt
import Data.Functor
import Data.List
import qualified Data.Map as M
......@@ -138,12 +138,15 @@ makeResult orgsearchtype tdes usedsyns (entry, annots) db
}), db)
| entry =: (ClassEntry _)
# (ClassEntry ce) = entry
# (ies,db) = getIndices ce.ce_instances db
= (ClassResult (general,
{ class_name = name
, class_heading = foldl ((+) o (flip (+) " ")) name ce.ce_vars +
if (isEmpty ce.ce_context) "" " | " + concat (print False ce.ce_context)
, class_funs = [] // TODO
, class_instances = [] // TODO
, class_instances = sortBy ((<) `on` fst)
[(map snd ie.ie_types, map locResult ie.ie_locations)
\\ {value=InstanceEntry ie} <- ies]
, class_derivations = [] // TODO
}), db)
// TODO
......@@ -167,6 +170,9 @@ where
Just (IntAnnot n) -> 100 - toInt (toReal n * 100.0 / toReal (size $ getName $ fromJust mbLoc))
]
locResult :: Location -> LocationResult
locResult (Location lib mod filename dcl icl _) = (lib,mod,filename,dcl,icl)
isModMatch :: ![String] Location -> Bool
isModMatch mods (Location _ mod _ _ _ _) = isMember mod mods
isModMatch _ (Builtin _ _) = False
......
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