Verified Commit 968da325 authored by Camil Staps's avatar Camil Staps 🚀

Also store whether a module is an app or a library

parent 889285d1
......@@ -73,6 +73,7 @@ from Doc import :: Documentation
*/
:: ModuleEntry
= { 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 Documentation //* Documentation on this module (a ModuleDoc)
}
......@@ -123,6 +124,7 @@ instance print (Name, FunctionEntry)
getName :: Location -> Name
isBuiltin :: Location -> Bool
isCore :: Location CloogleDB -> Bool
isApp :: Location CloogleDB -> Bool
toTypeDefEntry :: TypeDef (Maybe Documentation) -> TypeDefEntry
getTypeDef :: TypeDefEntry -> TypeDef
......
......@@ -96,7 +96,7 @@ where
}
instance zero ModuleEntry
where zero = {me_is_core = False, me_documentation=Nothing}
where zero = {me_is_core = False, me_is_app=False, me_documentation=Nothing}
instance print (Name, FunctionEntry)
where
......@@ -129,6 +129,12 @@ isCore (Location lib mod _ _ _) db = case getModule lib mod db of
Nothing = False
(Just b) = b.me_is_core
isApp :: Location CloogleDB -> Bool
isApp (Builtin _) _ = False
isApp (Location lib mod _ _ _) db = case getModule lib mod db of
Nothing = False
(Just b) = b.me_is_app
toTypeDefEntry :: TypeDef (Maybe Documentation) -> TypeDefEntry
toTypeDefEntry td doc = {tde_typedef=td, tde_doc=doc}
......
......@@ -18,16 +18,16 @@ finaliseDb :: !TemporaryDB !CloogleDB -> CloogleDB
* parameter, a module will not be considered.
* @param The root of the library directory (typically $CLEAN_HOME/lib).
* @param The library to look in.
* @param A function indicating if a module is part of the library core.
* @param Some auxiliary value to store with the modules.
* @param A part of the module hierarchy to look for. The empty string to look
* in the whole library, otherwise e.g. Crypto.Hash to only include modules
* in that hierarchy.
* @param The World.
* @result A list of modules found (library, module and whether it is part of
* the library core).
* @result A list of modules found (library, module, whether it is part of the
* library core, whether it is an app).
*/
findModules :: ![String] !String !Library (Module -> Bool) !String !*World
-> *(![(Library, Module, Bool)], !*World)
findModules :: ![String] !String !Library !a !String !*World
-> *(![(Library, Module, a)], !*World)
/**
* Update a database with all the information found in a module
......@@ -35,11 +35,11 @@ findModules :: ![String] !String !Library (Module -> Bool) !String !*World
* @param The root of the library directory (typically $CLEAN_HOME/lib).
* @param The module to index.
* @param The library the module to index is in.
* @param Whether this is a core module.
* @param A function to update module information (to set me_is_core, me_is_app).
* @param The old database.
* @result The new database.
*/
indexModule :: !String !Module !Library !Bool !TemporaryDB !*World
indexModule :: !String !Module !Library !(String ModuleEntry -> ModuleEntry) !TemporaryDB !*World
-> *(!TemporaryDB, !*World)
/**
......
......@@ -54,7 +54,7 @@ from Type import instance == Type,
from Cloogle import :: FunctionKind(..)
import qualified CloogleDB as DB
from CloogleDB import :: Location(Location), filterLocations,
:: ModuleEntry{me_is_core,me_documentation},
:: ModuleEntry{me_is_core,me_is_app,me_documentation},
:: FunctionEntry{fe_type,fe_kind,fe_generic_vars,fe_priority,fe_representation,fe_documentation},
instance zero FunctionEntry, instance zero ModuleEntry
from Doc import :: Documentation(FunctionDoc), :: ResultDoc, :: VarDoc,
......@@ -103,18 +103,18 @@ where
filterFun mods ('DB'.Location l m _ _ _) = isEmpty [() \\ (l`,m`,_) <- mods | l == l` && m == m`]
filterFun _ ('DB'.Builtin _) = True
// Exclude Root Library Check for core Base module
findModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World
-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)
findModules ex root lib iscore base w
// Exclude Root Library Check for core Check for app Base module
findModules :: ![String] !String !'DB'.Library !a !String !*World
-> *(![('DB'.Library, 'DB'.Module, a)], !*World)
findModules ex root lib aux base w
| any ((<>) -1 o flip indexOf path) ex = ([], w)
#! (fps, w) = readDirectory path w
| isError fps = ([], w)
#! (Ok fps) = fps
#! mods = map (\s -> let mod = basedot +++ s % (0, size s - 5) in
(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps
#! (moremodss,w) = mapSt (findModules ex root lib iscore o ((+++) basedot)) (filter isDirectory fps) w
= (removeDup (mods ++ flatten moremodss), w)
(lib, mod, aux)) $ filter included $ filter isDclModule fps
#! (moremodss,w) = mapSt (findModules ex root lib aux o ((+++) basedot)) (filter isDirectory fps) w
= (removeDupBy (\(l,m,_)->(l,m)) (mods ++ flatten moremodss), w)
where
path = root +++ "/" +++ lib +++ if (base == "") "" "/" +++ replaceSubString "." "/" base
basedot = if (base == "") "" (base +++ ".")
......@@ -128,9 +128,13 @@ where
isDirectory :: (String -> Bool)
isDirectory = not o isMember '.' o fromString
indexModule :: !String !'DB'.Module !'DB'.Library !Bool !TemporaryDB !*World
removeDupBy :: (a -> b) [a] -> [a] | Eq b
removeDupBy f [x:xs] = [x:removeDupBy f (filter ((<>) (f x) o f) xs)]
removeDupBy _ [] = []
indexModule :: !String !'DB'.Module !'DB'.Library !(String 'DB'.ModuleEntry -> 'DB'.ModuleEntry) !TemporaryDB !*World
-> *(!TemporaryDB, !*World)
indexModule root mod lib iscore db w
indexModule root mod lib modf db w
#! (Right dcl,symbols,w) = readModule False w
#! (icl,_,w) = readModule True w
#! icl = case icl of (Left _) = Nothing; (Right x) = Just x
......@@ -152,20 +156,19 @@ indexModule root mod lib iscore db w
, temp_types = [typedefs:db.temp_types]
, temp_derivations = [pd_derivations lib modname dcl.mod_defs:db.temp_derivations]
, temp_class_derivations = [pd_class_derivations lib modname dcl.mod_defs icl:db.temp_class_derivations]
, temp_modules = [(lib,modname,pd_module iscore dcl.mod_defs):db.temp_modules]
, temp_modules = [(lib,modname,pd_module (modf mod) dcl.mod_defs):db.temp_modules]
}
= (db,w)
where
mkdir :: String -> String
mkdir s = { if (c == '.') '/' c \\ c <-: s }
pd_module :: Bool ![ParsedDefinition] -> ModuleEntry
pd_module iscore [PD_Documentation _ doc:_]
= { pd_module iscore []
pd_module :: !('DB'.ModuleEntry -> 'DB'.ModuleEntry) ![ParsedDefinition] -> ModuleEntry
pd_module modf [PD_Documentation _ doc:_]
= { pd_module modf []
& me_documentation = docParseResultToMaybe $ parseModuleDoc doc
}
pd_module iscore _
= { zero & me_is_core = iscore }
pd_module modf _ = modf zero
pd_macros :: String String ![ParsedDefinition] SymbolTable
-> [('DB'.Location, 'DB'.FunctionEntry)]
......@@ -436,3 +439,6 @@ where
field_doc = case getTypeRhsDoc =<< 'DB'.getTypeDefDoc etd of
Just (RecordDoc fields) = fields ++ repeat Nothing
_ = repeat Nothing
instance == (a,b,c,d) | == a & == b & == c & == d
where == (a,b,c,d) (p,q,r,s) = a == p && b == q && c == r && d == s
......@@ -19,6 +19,12 @@ DEFAULT_INCLUDE_BUILTINS :== True
*/
DEFAULT_INCLUDE_CORE :== False
/**
* Cloogle setting: whether to include app modules if the Request has Nothing
* for the include_apps field.
*/
DEFAULT_INCLUDE_APPS :== False
/**
* Search for a request in the type database
*/
......
......@@ -26,9 +26,10 @@ import Cloogle
import Doc
search :: !Request !CloogleDB -> [Result]
search {unify,name,className,typeName,modules,libraries,page,include_builtins,include_core} db_org
search {unify,name,className,typeName,modules,libraries,page,include_builtins,include_core,include_apps} db_org
# include_builtins = fromJust (include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)
# include_core = fromJust (include_core <|> Just DEFAULT_INCLUDE_CORE)
# include_apps = fromJust (include_apps <|> Just DEFAULT_INCLUDE_APPS)
# db = db_org
# db = case libraries of
(Just ls) = filterLocations (isLibMatch ls) db
......@@ -38,6 +39,7 @@ search {unify,name,className,typeName,modules,libraries,page,include_builtins,in
Nothing = db
# db = if include_builtins id (filterLocations (not o isBuiltin)) db
# db = if include_core id (filterLocations (not o flip isCore db)) db
# db = if include_apps id (filterLocations (not o flip isApp db)) db
| isJust className
# className = fromJust className
# classes = findClass className db
......
Subproject commit 8200544a75c023e7f7c656bb90ab9bdf7a0b0813
Subproject commit 9774125cdd65ff59f2249f4553818cc7a92905d6
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