Verified Commit ed7e5eed authored by Camil Staps's avatar Camil Staps 🚀

Add usages for modules (imports in icl)

parent dd1c2803
......@@ -124,6 +124,7 @@ derive JSONDecode CloogleEntry
, me_is_core :: !Bool //* Whether this is a core module (e.g. the os* modules in ObjectIO and TCPIP)
, me_is_app :: !Bool //* Whether this module is not actually a library but an app
, me_documentation :: !Maybe ModuleDoc //* Documentation on this module
, me_usages :: ![Index] //* Modules importing this module
}
/**
......
......@@ -107,6 +107,7 @@ where
, me_is_core=False
, me_is_app=False
, me_documentation=Nothing
, me_usages=[]
}
instance print (Name, FunctionEntry)
......@@ -464,6 +465,7 @@ where
getUsages :: !CloogleEntry -> [Index]
getUsages (TypeDefEntry tde) = tde.tde_usages
getUsages (ClassEntry ce) = ce.ce_usages
getUsages (ModuleEntry me) = me.me_usages
getUsages _ = []
// Efficient union on sorted lists
......
......@@ -77,7 +77,7 @@ findModuleContents :: !Bool !String !*World
, ![(Name, [(Type, String)], LocationInModule)]
, ![(Name, [(Type, String, LocationInModule)])]
, ![(Name, Type, String, LocationInModule)]
, !(Name, ModuleEntry)
, !(Name, ModuleEntry, [String])
, !*World
)
......
......@@ -45,7 +45,7 @@ from syntax import :: ClassDef{class_args,class_context,class_ident,class_pos},
:: Optional(Yes,No), :: SymbolPtr, :: Ptr, :: SymbolTableEntry{ste_doc},
:: ParsedDefinition(PD_Class,PD_Derive,PD_Function,PD_Generic,PD_Instance,
PD_Instances,PD_Type,PD_TypeSpec,PD_Documentation,PD_GenericCase,
PD_NodeDef),
PD_NodeDef,PD_Import),
:: ParsedExpr(PE_Ident,PE_List),
:: ParsedInstance{pi_ident,pi_pos,pi_types},
:: ParsedInstanceAndMembers{pim_pi}, :: ParsedModule, :: ParsedTypeDef,
......@@ -54,8 +54,9 @@ from syntax import :: ClassDef{class_args,class_context,class_ident,class_pos},
AbstractTypeSpec,NewTypeCons,MoreConses),
:: SymbolTable, :: SymbolTableEntry, :: SymbolType, :: Type, :: BITVECT,
:: TypeContext, :: TypeDef{td_ident,td_pos,td_rhs}, :: TypeVar,
:: ParsedConstructor{pc_doc}, :: ParsedSelector{ps_doc}, :: DocType,
:: OptionalDoc
:: ParsedConstructor{pc_doc}, :: ParsedSelector{ps_doc},
:: ParsedImport, :: Import{import_module},
:: DocType, :: OptionalDoc
import CoclUtils
import qualified Type as T
......@@ -73,7 +74,7 @@ from CloogleDB import
:: Location(Location,Builtin,NoLocation),
:: CleanLangReportLocation,
:: CloogleEntry(..),
:: ModuleEntry{me_loc,me_is_core,me_is_app,me_documentation},
:: ModuleEntry{..},
:: FunctionEntry{..},
:: TypeDefEntry{tde_loc,tde_instances,tde_derivations,tde_usages},
:: ClassEntry{ce_loc,ce_instances,ce_is_meta,ce_members,ce_usages},
......@@ -102,7 +103,7 @@ from Doc import :: ModuleDoc, :: FunctionDoc{..}, :: ClassDoc, :: TypeDoc{..},
, temp_types :: ![['CDB'.TypeDefEntry]]
, temp_derivations :: ![[(!'CDB'.Name, ![(!'CDB'.Type, !String, !'CDB'.Location)])]]
, temp_class_derivations :: ![[(!'CDB'.Name, !'CDB'.Type, !String, !'CDB'.Location)]]
, temp_modules :: ![ModuleEntry]
, temp_modules :: ![(ModuleEntry, [String])]
}
newTemporaryDB :: TemporaryDB
......@@ -187,12 +188,22 @@ where
DeriveEntry de -> de.de_generic == 'CDB'.getName fe.fe_loc
_ -> False
}
link _ (ModuleEntry me) = ModuleEntry
{ me
& me_usages=idxfilter` \e -> case e of
ModuleEntry me -> case find (\(mod,_) -> mod.me_loc == me.me_loc) tdb.temp_modules of
Nothing -> False
Just (_,imps) -> isMember name imps
_ -> False
}
where
name = 'CDB'.getName me.me_loc
link _ e = e
entries` = map Right (
extra ++
[FunctionEntry fun \\ funs <- tdb.temp_functions, fun <- funs] ++
[TypeDefEntry tde \\ tds <- tdb.temp_types, tde <- tds] ++
[ModuleEntry mod \\ mod <- tdb.temp_modules] ++
[ModuleEntry mod \\ (mod,_) <- tdb.temp_modules] ++
map ClassEntry classes ++
[FunctionEntry
{ fun
......@@ -264,25 +275,25 @@ where
(Just l, Just m) -> isMember (l,m) coremods
_ -> False
where
coremods = [(fromJust $ 'CDB'.getLibrary me.me_loc, fromJust $ 'CDB'.getModule me.me_loc) \\ me <- tdb.temp_modules | me.me_is_core]
coremods = [(fromJust $ 'CDB'.getLibrary me.me_loc, fromJust $ 'CDB'.getModule me.me_loc) \\ (me,_) <- tdb.temp_modules | me.me_is_core]
appidxs = idxfilter \e -> case 'CDB'.getLocation e of
Nothing -> False
Just l -> case ('CDB'.getLibrary l, 'CDB'.getModule l) of
(Just l, Just m) -> isMember (l,m) appmods
_ -> False
where
appmods = [(fromJust $ 'CDB'.getLibrary me.me_loc, fromJust $ 'CDB'.getModule me.me_loc) \\ me <- tdb.temp_modules | me.me_is_app]
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]
where libs = removeDup [fromJust ('CDB'.getLibrary me.me_loc) \\ (me,_) <- tdb.temp_modules]
modmap = 'M'.fromList
[(m,idxfilter \e -> case 'CDB'.getLocation e >>= 'CDB'.getModule of
Nothing -> False
Just m` -> m == m`) \\ m <- mods]
where mods = removeDup [fromJust ('CDB'.getModule me.me_loc) \\ me <- tdb.temp_modules]
where mods = removeDup [fromJust ('CDB'.getModule me.me_loc) \\ (me,_) <- tdb.temp_modules]
synonymmap = 'M'.fromList
$ map (\syns=:[(t,_):_] -> (t,map snd syns))
......@@ -334,7 +345,7 @@ indexModule :: !Bool !String !'CDB'.Module !'CDB'.Library
!(String 'CDB'.ModuleEntry -> 'CDB'.ModuleEntry) !TemporaryDB !*World
-> *(!TemporaryDB, !*World)
indexModule include_locals root mod lib modf db w
#! (functions,macros,generics,typedefs,clss,insts,derivs,clsderivs,(modname,modentry),w)
#! (functions,macros,generics,typedefs,clss,insts,derivs,clsderivs,(modname,modentry,imports),w)
= findModuleContents include_locals (root </> lib </> mkdir mod) w
#! typedefs = [{td & tde_loc=castLoc modname loc} \\ (loc,td) <- typedefs]
#! lib = lib % (0, size lib - size modname + size mod - 1)
......@@ -350,7 +361,7 @@ indexModule include_locals root mod lib modf db w
, temp_instances = [castLocThd3 modname insts:db.temp_instances]
, temp_derivations = [map (appSnd (castLocThd3 modname)) derivs:db.temp_derivations]
, temp_class_derivations = [castLocFrth modname clsderivs:db.temp_class_derivations]
, temp_modules = [modf mod {modentry & me_loc=Location lib modname dclpath (Just 1) (Just 1) modname}:db.temp_modules]
, temp_modules = [(modf mod {modentry & me_loc=Location lib modname dclpath (Just 1) (Just 1) modname},imports):db.temp_modules]
}
= (db,w)
where
......@@ -377,7 +388,7 @@ findModuleContents :: !Bool !String !*World
, ![('CDB'.Name, [('CDB'.Type, String)], LocationInModule)]
, ![('CDB'.Name, [('CDB'.Type, String, LocationInModule)])]
, ![('CDB'.Name, 'CDB'.Type, String, LocationInModule)]
, !('CDB'.Name, 'CDB'.ModuleEntry)
, !('CDB'.Name, 'CDB'.ModuleEntry, [String])
, !*World
)
findModuleContents include_locals path w
......@@ -387,6 +398,7 @@ findModuleContents include_locals path w
Right dcl -> (dcl.mod_defs, dcl.mod_ident.id_name)
#! (icl,icl_symbols,w) = readModule True w
#! icl = case icl of Left _ -> []; Right icl -> icl.mod_defs
#! imports = [i.import_module.id_name \\ PD_Import is <- icl, i <- is]
#! contents=:(functions,rules,generics,typedefs,clss,insts,derivs,clsderivs) =
( combine cmpLocFst joinLocFst pd_typespecs dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_rewriterules dcl dcl_symbols icl icl_symbols
......@@ -410,7 +422,7 @@ findModuleContents include_locals path w
, filter (hasDcl o (\(_,_,_,x)->x)) clsderivs
) with hasDcl loc = isJust loc.dcl_line
#! rules = filter (\(r,_) -> not $ any (\(l,_)->fromJust l.name == fromJust r.name) functions) rules
= (functions,rules,generics,typedefs,clss,insts,derivs,clsderivs,(modname,pd_module dcl),w)
= (functions,rules,generics,typedefs,clss,insts,derivs,clsderivs,(modname,pd_module dcl,imports),w)
where
combine :: (a a -> Bool) (a a -> a)
(Bool [ParsedDefinition] SymbolTable -> [a])
......
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