Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Cloogle
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cloogle
Cloogle
Commits
2286219b
Verified
Commit
2286219b
authored
Jan 14, 2018
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added usages for type definitions (clean-cloogle/cloogle.org#52)
parent
94fd5cfa
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
36 deletions
+56
-36
CloogleDB.dcl
CloogleDB.dcl
+8
-9
CloogleDB.icl
CloogleDB.icl
+19
-9
CloogleDBFactory.icl
CloogleDBFactory.icl
+7
-3
Search.dcl
Search.dcl
+1
-1
Search.icl
Search.icl
+20
-13
libcloogle
libcloogle
+1
-1
No files found.
CloogleDB.dcl
View file @
2286219b
...
...
@@ -23,7 +23,7 @@ from TypeTree import :: TypeTree
* A storage for function types, class definitions, type definitions, etc.
*/
::
*
CloogleDB
=
{
db
::
!*
DB
CloogleEntry
AnnotationKey
Annotation
//* Core data
{
db
::
!*
DB
CloogleEntry
AnnotationKey
Int
//* Core data
,
name_ngrams
::
!
NGramIndex
Index
//* Name ngrams
,
name_map
::
!
Map
Name
[
Index
]
//* For exact name search
,
types
::
!
TypeTree
Index
//* Types, map to FunctionEntries
...
...
@@ -59,15 +59,11 @@ from TypeTree import :: TypeTree
::
AnnotationKey
=
MatchingNGrams
//* For name search, the number of matching ngrams
|
UnifierSize
//* For type search, the 'size' of the unifier
::
Annotation
=
IntAnnot
Int
|
ExactResult
//* 1 if this was an exact match found with filterExactName
instance
==
AnnotationKey
instance
<
AnnotationKey
fromIntAnnot
::
Annotation
->
Int
/**
* Wrapper around different kinds of entries to store all in one database.
*/
...
...
@@ -116,6 +112,7 @@ derive JSONDecode CloogleEntry
,
tde_doc
::
!
Maybe
TypeDoc
//* Documentation on the TypeDef
,
tde_instances
::
![
Index
]
//* Instances of this type
,
tde_derivations
::
![
Index
]
//* Derivations of this type
,
tde_usages
::
![
Index
]
//* FunctionEntries using the type
}
/**
...
...
@@ -244,8 +241,8 @@ dbStats :: !*CloogleDB -> *(CloogleDBStats, *CloogleDB)
*/
writeTypeTree
::
!*
CloogleDB
!*
File
->
*(*
CloogleDB
,
*
File
)
getIndex
::
!
Index
!*
CloogleDB
->
*(
Entry
CloogleEntry
AnnotationKey
Annotation
,
*
CloogleDB
)
getIndices
::
![
Index
]
!*
CloogleDB
->
*([
Entry
CloogleEntry
AnnotationKey
Annotation
],
*
CloogleDB
)
getIndex
::
!
Index
!*
CloogleDB
->
*(
Entry
CloogleEntry
AnnotationKey
Int
,
*
CloogleDB
)
getIndices
::
![
Index
]
!*
CloogleDB
->
*([
Entry
CloogleEntry
AnnotationKey
Int
],
*
CloogleDB
)
filterDB
::
(
CloogleEntry
->
Bool
)
!*
CloogleDB
->
*
CloogleDB
excludeCore
::
!*
CloogleDB
->
*
CloogleDB
...
...
@@ -258,8 +255,10 @@ filterName :: !String !*CloogleDB -> *CloogleDB
filterExactName
::
!
String
!*
CloogleDB
->
*
CloogleDB
filterUnifying
::
!
Type
!*
CloogleDB
->
*
CloogleDB
extendToUsages
::
!*
CloogleDB
->
*
CloogleDB
allTypeSynonyms
::
!*
CloogleDB
->
*(
Map
Name
[
TypeDef
],
*
CloogleDB
)
getInstances
::
!
Name
!*
CloogleDB
->
*([
InstanceEntry
],
*
CloogleDB
)
getDerivations
::
!
Name
!*
CloogleDB
->
*([
DeriveEntry
],
*
CloogleDB
)
getEntries
::
!*
CloogleDB
->
*([(
CloogleEntry
,
Map
AnnotationKey
Annotation
)],
*
CloogleDB
)
getEntries
::
!*
CloogleDB
->
*([(
CloogleEntry
,
Map
AnnotationKey
Int
)],
*
CloogleDB
)
CloogleDB.icl
View file @
2286219b
...
...
@@ -58,9 +58,6 @@ where
derive
gLexOrd
AnnotationKey
instance
<
AnnotationKey
where
<
a
b
=
(
a
=?=
b
)
===
LT
fromIntAnnot
::
Annotation
->
Int
fromIntAnnot
(
IntAnnot
i
)
=
i
derive
JSONEncode
ClassDoc
,
ClassEntry
,
ClassMemberDoc
,
CloogleEntry
,
Constructor
,
ConstructorDoc
,
DeriveEntry
,
FunctionDoc
,
FunctionEntry
,
InstanceEntry
,
Location
,
ModuleDoc
,
ModuleEntry
,
Priority
,
RecordField
,
...
...
@@ -198,6 +195,7 @@ toTypeDefEntry loc td doc =
,
tde_doc
=
doc
,
tde_instances
=[]
,
tde_derivations
=[]
,
tde_usages
=[]
}
getTypeDef
::
TypeDefEntry
->
TypeDef
...
...
@@ -334,12 +332,12 @@ writeTypeTree db=:{types} f
#
f
=
f
<<<
concat
(
printDigraph
(
typeTreeToGraphviz
types
))
=
(
db
,
f
)
getIndex
::
!
Index
!*
CloogleDB
->
*(
Entry
CloogleEntry
AnnotationKey
Annotation
,
*
CloogleDB
)
getIndex
::
!
Index
!*
CloogleDB
->
*(
Entry
CloogleEntry
AnnotationKey
Int
,
*
CloogleDB
)
getIndex
idx
wrap
=:{
db
}
#
(
e
,
db
)
=
'
DB
'.
getIndex
idx
db
=
(
e
,
{
wrap
&
db
=
db
})
getIndices
::
![
Index
]
!*
CloogleDB
->
*([
Entry
CloogleEntry
AnnotationKey
Annotation
],
*
CloogleDB
)
getIndices
::
![
Index
]
!*
CloogleDB
->
*([
Entry
CloogleEntry
AnnotationKey
Int
],
*
CloogleDB
)
getIndices
idxs
wrap
=:{
db
}
#
(
es
,
db
)
=
'
DB
'.
getIndices
idxs
db
=
(
es
,
{
wrap
&
db
=
db
})
...
...
@@ -387,7 +385,7 @@ filterName s wrap=:{db,name_ngrams,syntax}
#
db
=
'
DB
'.
searchWithIndices
syntaxSearch
syntax
db
=
{
wrap
&
db
=
db
}
where
indices
=
[(
i
,[(
MatchingNGrams
,
IntAnnot
n
)])
\\
(
i
,
n
)
<-
'
NGrams
'.
search
s
name_ngrams
]
indices
=
[(
i
,[(
MatchingNGrams
,
n
)])
\\
(
i
,
n
)
<-
'
NGrams
'.
search
s
name_ngrams
]
syntaxSearch
::
CloogleEntry
->
(
Bool
,
[
a
])
syntaxSearch
(
SyntaxEntry
se
)
=
(
any
(
flip
patternMatches
s
)
se
.
syntax_patterns
,
[])
...
...
@@ -412,7 +410,7 @@ where
filterExactName
::
!
String
!*
CloogleDB
->
*
CloogleDB
filterExactName
n
wrap
=:{
db
,
name_map
}
#
db
=
'
DB
'.
searchIndices
Intersect
[(
i
,[])
\\
i
<-
idxs
]
db
#
db
=
'
DB
'.
searchIndices
Intersect
[(
i
,[
(
ExactResult
,
1
)
])
\\
i
<-
idxs
]
db
=
{
wrap
&
db
=
db
}
where
idxs
=
fromMaybe
[]
$
get
n
name_map
...
...
@@ -424,7 +422,7 @@ filterUnifying t wrap=:{db,types}
where
idxs
=
sortBy
((<)
`
on`
fst
)
[(
idx
,
annot
)
\\
(
t
,
u
,
idxs
)
<-
findUnifying
t
types
,
annot
<-
[[(
UnifierSize
,
IntAnnot
(
unifierSize
u
)
)]]
,
annot
<-
[[(
UnifierSize
,
unifierSize
u
)]]
,
idx
<-
idxs
]
unifierSize
::
Unifier
->
Int
...
...
@@ -444,6 +442,18 @@ where
typeComplexity
(
Arrow
(
Just
t
))
=
5.0
+
typeComplexity
t
typeComplexity
(
Arrow
Nothing
)
=
5.0
extendToUsages
::
!*
CloogleDB
->
*
CloogleDB
extendToUsages
wrap
#
(
es
,
wrap
=:{
db
})
=
getEntries
wrap
#
idxs
=
removeDup
$
foldr
merge
[]
$
map
getUsages
es
#
db
=
'
DB
'.
searchIndices
AddExcluded
[(
i
,[])
\\
i
<-
idxs
]
db
=
{
wrap
&
db
=
db
}
where
getUsages
::
!(
CloogleEntry
,
a
)
->
[
Index
]
getUsages
(
e
,_)
=
case
e
of
TypeDefEntry
tde
->
tde
.
tde_usages
_
->
[]
allTypeSynonyms
::
!*
CloogleDB
->
*(
Map
Name
[
TypeDef
],
*
CloogleDB
)
allTypeSynonyms
wrap
=:{
db
}
#
(
es
,
db
)
=
'
DB
'.
allEntries
db
...
...
@@ -471,7 +481,7 @@ getDerivations c wrap=:{db,derive_map}
where
idxs
=
get
c
derive_map
getEntries
::
!*
CloogleDB
->
*([(
CloogleEntry
,
Map
AnnotationKey
Annotation
)],
*
CloogleDB
)
getEntries
::
!*
CloogleDB
->
*([(
CloogleEntry
,
Map
AnnotationKey
Int
)],
*
CloogleDB
)
getEntries
wrap
=:{
db
}
#
(
es
,
db
)
=
'
DB
'.
getEntries
db
=
(
es
,
{
wrap
&
db
=
db
})
CloogleDBFactory.icl
View file @
2286219b
...
...
@@ -75,7 +75,7 @@ from CloogleDB import
::
CloogleEntry
(..),
::
ModuleEntry
{
me_loc
,
me_is_core
,
me_is_app
,
me_documentation
},
::
FunctionEntry
{..},
::
TypeDefEntry
{
tde_loc
,
tde_instances
,
tde_derivations
},
::
TypeDefEntry
{
tde_loc
,
tde_instances
,
tde_derivations
,
tde_usages
},
::
ClassEntry
{
ce_loc
,
ce_instances
,
ce_is_meta
,
ce_members
},
classContext
,
::
TypeRestriction
,
::
SyntaxEntry
,
::
DeriveEntry
,
...
...
@@ -150,12 +150,16 @@ where
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
==
'T'
.
td_name
('
CDB
'.
getTypeDef
tde
)
]
InstanceEntry
ie
->
not
$
isEmpty
[()
\\
'T'
.
Type
t
_
<-
concatMap
(
'T'
.
subtypes
o
fst
)
ie
.
ie_types
|
t
==
name
]
_
->
False
,
tde_derivations
=
idxfilter
\
e
->
case
e
of
DeriveEntry
{
de_type
=
'T'
.
Type
t
_}
->
t
==
'T'
.
td_name
('
CDB
'.
getTypeDef
tde
)
DeriveEntry
{
de_type
=
'T'
.
Type
t
_}
->
t
==
name
_
->
False
,
tde_usages
=
idxfilter
\
e
->
case
e
of
FunctionEntry
{
fe_type
=
Just
t
}
->
or
[
True
\\
'T'
.
Type
t
_
<-
'T'
.
subtypes
t
|
t
==
name
]
_
->
False
}
with
name
=
'T'
.
td_name
$
'
CDB
'.
getTypeDef
tde
link
i
(
ClassEntry
ce
)
=
ClassEntry
{
ce
&
ce_instances
=
idxfilter
\
e
->
case
e
of
...
...
Search.dcl
View file @
2286219b
...
...
@@ -5,7 +5,7 @@ definition module Search
*/
from
Cloogle
import
::
Request
,
::
Result
from
CloogleDB
import
::
CloogleDB
,
::
Annotation
,
::
Annotation
Key
,
::
CloogleEntry
from
CloogleDB
import
::
CloogleDB
,
::
AnnotationKey
,
::
CloogleEntry
from
DB
import
::
DB
/**
...
...
Search.icl
View file @
2286219b
...
...
@@ -27,10 +27,11 @@ import Cloogle
import
Doc
search
::
!
Request
!*
CloogleDB
->
*([
Result
],
*
CloogleDB
)
search
{
unify
,
name
,
className
,
typeName
,
modules
,
libraries
,
page
,
include_builtins
,
include_core
,
include_apps
}
cdb
#
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
)
search
{
unify
,
name
,
className
,
typeName
,
using
,
modules
,
libraries
,
page
,
include_builtins
,
include_core
,
include_apps
}
cdb
#
include_builtins
=
fromMaybe
DEFAULT_INCLUDE_BUILTINS
include_builtins
#
include_core
=
fromMaybe
DEFAULT_INCLUDE_CORE
include_core
#
include_apps
=
fromMaybe
DEFAULT_INCLUDE_APPS
include_apps
#
using
=
fromMaybe
False
using
#
cdb
=
if
include_core
cdb
(
excludeCore
cdb
)
#
cdb
=
if
include_apps
cdb
(
excludeApps
cdb
)
#
cdb
=
case
libraries
of
...
...
@@ -40,15 +41,15 @@ search {unify,name,className,typeName,modules,libraries,page,include_builtins,in
Just
ms
->
filterModules
ms
cdb
Nothing
->
cdb
#
cdb
=
if
include_builtins
includeBuiltins
excludeBuiltins
cdb
#
cdb
=
case
name
<|>
typeName
<|>
className
of
Nothing
->
cdb
Just
n
->
if
exact
filterExactName
filterName
n
cdb
#
cdb
=
case
typeName
of
Nothing
->
cdb
Just
n
->
filterDB
(\
ce
->
ce
=:(
TypeDefEntry
_))
$
filterExactName
n
cdb
Just
n
->
filterDB
(\
ce
->
ce
=:(
TypeDefEntry
_))
cdb
#
cdb
=
case
className
of
Nothing
->
cdb
Just
n
->
filterDB
(\
ce
->
ce
=:(
ClassEntry
_))
$
filterExactName
n
cdb
#
cdb
=
case
name
of
Nothing
->
cdb
Just
name
->
filterName
name
cdb
Just
n
->
filterDB
(\
ce
->
ce
=:(
ClassEntry
_))
cdb
#
(
allsyns
,
cdb
)
=
allTypeSynonyms
cdb
#
mbPreppedType
=
prepare_unification
True
allsyns
<$>
(
unify
>>=
parseType
o
fromString
)
#
usedSynonyms
=
'
Foldable
'.
concat
(
fst
<$>
mbPreppedType
)
...
...
@@ -56,12 +57,15 @@ search {unify,name,className,typeName,modules,libraries,page,include_builtins,in
#
cdb
=
case
mbType
of
Nothing
->
cdb
Just
t
->
filterUnifying
t
cdb
#
cdb
=
if
using
(
extendToUsages
cdb
)
cdb
#
(
es
,
cdb
)
=
getEntries
cdb
#
(
es
,
cdb
)
=
mapSt
(
makeResult
mbType
allsyns
usedSynonyms
)
es
cdb
=
(
sort
es
,
cdb
)
where
exact
=
or
[
isJust
using
,
isJust
typeName
,
isJust
className
]
makeResult
::
(
Maybe
Type
)
(
Map
String
[
TypeDef
])
[
TypeDef
]
(
CloogleEntry
,
Map
AnnotationKey
Annotation
)
*
CloogleDB
(
CloogleEntry
,
Map
AnnotationKey
Int
)
*
CloogleDB
->
*(
Result
,
*
CloogleDB
)
makeResult
orgsearchtype
allsyns
usedsyns
(
entry
,
annots
)
db
|
entry
=:
(
FunctionEntry
_)
...
...
@@ -86,7 +90,7 @@ makeResult orgsearchtype allsyns usedsyns (entry, annots) db
{
general
&
distance
=
toInt
$
kindPenalty
fe
.
fe_kind
*
toReal
(
general
.
distance
+
sum
[
fromMaybe
0
$
contextPenalty
<$>
required_context
,
fromMaybe
0
$
fromIntAnnot
<$>
'M'
.
get
UnifierSize
annots
,
fromMaybe
0
$
'M'
.
get
UnifierSize
annots
,
length
usedsyns
])
,
documentation
=
docDescription
=<<
fe
.
fe_documentation
...
...
@@ -249,8 +253,11 @@ where
}
distance
=
sum
[
case
'M'
.
get
MatchingNGrams
annots
of
Nothing
->
100
Just
(
IntAnnot
n
)
->
100
-
toInt
(
toReal
n
*
100.0
/
toReal
(
size
$
getName
$
fromJust
mbLoc
))
Nothing
->
0
Just
n
->
0
-
toInt
(
toReal
n
*
100.0
/
toReal
(
size
$
getName
$
fromJust
mbLoc
))
,
case
'M'
.
get
ExactResult
annots
of
Just
1
->
-1
_
->
0
]
locResult
::
Location
->
LocationResult
...
...
libcloogle
@
510d8829
Compare
04ca6f21
...
510d8829
Subproject commit
04ca6f2158881c65bcec32d1a9c6d521a1316181
Subproject commit
510d882972d6f51ce89e78bcdada688b6410fbf9
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment