Commit d481ef7c authored by Camil Staps's avatar Camil Staps
Browse files

Cleanup CloogleDB

parent 326e1882
......@@ -23,19 +23,22 @@ from TypeTree import :: TypeTree
* A storage for function types, class definitions, type definitions, etc.
*/
:: *CloogleDB =
{ db :: !*DB CloogleEntry AnnotationKey Annotation
, name_ngrams :: !NGramIndex Index
, types :: !TypeTree Index
, core :: ![Index]
, apps :: ![Index]
, builtins :: ![Index]
, syntax :: ![Index]
, library_map :: !Map Name [Index]
, module_map :: !Map Name [Index]
, derive_map :: !Map Name [Index] //* Map generic names to DeriveEntries
, instance_map :: !Map Name [Index] //* Map class names to DeriveEntries
{ db :: !*DB CloogleEntry AnnotationKey Annotation //* Core data
, name_ngrams :: !NGramIndex Index //* Name ngrams
, types :: !TypeTree Index //* Types, map to FunctionEntries
, core :: ![Index] //* Entries in core modules
, apps :: ![Index] //* Entries in app modules
, builtins :: ![Index] //* Entries in Clean core
, syntax :: ![Index] //* SyntaxEntries
, library_map :: !Map Name [Index] //* Entries by library name
, module_map :: !Map Name [Index] //* Entries by module name
, derive_map :: !Map Name [Index] //* DeriveEntries by generic name
, instance_map :: !Map Name [Index] //* InstanceEntries by class name
}
/**
* Information about a {{`CloogleDB`}}. Can be retrieved with {{`dbStats`}}.
*/
:: CloogleDBStats =
{ n_modules :: Int
, n_functions :: Int
......@@ -49,9 +52,12 @@ from TypeTree import :: TypeTree
, n_syntax_constructs :: Int
}
/**
* Annotations to store during search.
*/
:: AnnotationKey
= MatchingNGrams
| UnifierSize
= MatchingNGrams //* For name search, the number of matching ngrams
| UnifierSize //* For type search, the 'size' of the unifier
:: Annotation
= IntAnnot Int
......@@ -61,6 +67,9 @@ instance < AnnotationKey
fromIntAnnot :: Annotation -> Int
/**
* Wrapper around different kinds of entries to store all in one database.
*/
:: CloogleEntry
= FunctionEntry FunctionEntry
| TypeDefEntry TypeDefEntry
......@@ -219,21 +228,19 @@ mergeTypeDefEntries :: TypeDefEntry TypeDefEntry -> TypeDefEntry
toClass :: Location [String] Bool TypeContext (Maybe ClassDoc) -> ClassEntry
classContext :: ClassEntry -> [TypeRestriction]
/**
* Synchronise the database. Should be called after updating data, to update
* derived information.
* @param Number of times to resync
* @param The database
* @result The new database
*/
syncDB :: !Int !*CloogleDB -> *CloogleDB
saveDB :: *CloogleDB *File -> *(*CloogleDB, *File)
openDB :: !*File -> *(!Maybe *CloogleDB, !*File)
/**
* Reset the database (count everything as included again).
*/
resetDB :: !*CloogleDB -> *CloogleDB
dbStats :: !*CloogleDB -> *(CloogleDBStats, *CloogleDB)
/**
* Write the type tree as dot graph to a file.
*/
writeTypeTree :: !*CloogleDB !*File -> *(*CloogleDB, *File)
getIndex :: !Index !*CloogleDB -> *(Entry CloogleEntry AnnotationKey Annotation, *CloogleDB)
......
......@@ -227,9 +227,6 @@ toClass loc vs meta cc doc
classContext :: ClassEntry -> [TypeRestriction]
classContext ce = ce.ce_context
syncDB :: !Int !*CloogleDB -> *CloogleDB
syncDB _ db = db
saveDB :: *CloogleDB *File -> *(*CloogleDB, *File)
saveDB wrapper=:{db,name_ngrams,types,core,apps,builtins,syntax,library_map,module_map,derive_map,instance_map} f
# (db,f) = 'DB'.saveDB db f
......@@ -252,38 +249,38 @@ openDB :: !*File -> *(!Maybe *CloogleDB, !*File)
openDB f
# ((ok,db),f) = appFst isJustU $ 'DB'.openDB f
| not ok = (Nothing, f)
# ((ok,name_ngrams),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,types),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,core),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,apps),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,builtins),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,syntax),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)
# ((ok,derive_map),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
# ((ok,instance_map),f) = appFst isJustU $ read f
| not ok = (Nothing, f)
= (Just
# (name_ngrams,f) = read f
# (types,f) = read f
# (core,f) = read f
# (apps,f) = read f
# (builtins,f) = read f
# (syntax,f) = read f
# (library_map,f) = read f
# (module_map,f) = read f
# (derive_map,f) = read f
# (instance_map,f) = read f
= (
name_ngrams >>= \name_ngrams ->
types >>= \types ->
core >>= \core ->
apps >>= \apps ->
builtins >>= \builtins ->
syntax >>= \syntax ->
library_map >>= \library_map ->
module_map >>= \module_map ->
derive_map >>= \derive_map ->
instance_map >>= \instance_map -> Just
{ db=fromJust db
, name_ngrams=fromJust name_ngrams
, types=fromJust types
, core=fromJust core
, apps=fromJust apps
, builtins=fromJust builtins
, syntax=fromJust syntax
, library_map=fromJust library_map
, module_map=fromJust module_map
, derive_map=fromJust derive_map
, instance_map=fromJust instance_map
, name_ngrams=name_ngrams
, types=types
, core=core
, apps=apps
, builtins=builtins
, syntax=syntax
, library_map=library_map
, module_map=module_map
, derive_map=derive_map
, instance_map=instance_map
}, f)
where
read :: *File -> *(Maybe a, *File) | JSONDecode{|*|} a
......@@ -293,6 +290,9 @@ where
# (line,f) = freadline f
= (fromJSON (fromString line), f)
(>>=) Nothing _ = Nothing // Overridden to deal with uniqueness
(>>=) (Just x) f = f x
resetDB :: !*CloogleDB -> *CloogleDB
resetDB wrap=:{db} = {wrap & db='DB'.resetDB db}
......
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