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.org
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cloogle
cloogle.org
Commits
15d3ff45
Verified
Commit
15d3ff45
authored
Feb 01, 2017
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend: module search
parent
b7859b73
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
15 deletions
+60
-15
README.md
README.md
+5
-4
backend/Cloogle.dcl
backend/Cloogle.dcl
+10
-2
backend/Cloogle.icl
backend/Cloogle.icl
+5
-2
backend/CloogleServer.icl
backend/CloogleServer.icl
+27
-7
backend/TypeDB.dcl
backend/TypeDB.dcl
+2
-0
backend/TypeDB.icl
backend/TypeDB.icl
+11
-0
No files found.
README.md
View file @
15d3ff45
...
...
@@ -92,8 +92,8 @@ fields:
An array of search results. A result is an array of three elements. The first
determines the kind of result. It may be `FunctionResult`, `TypeResult`,
`ClassResult`
or `MacroResult`. The second contains general data, in
particular the following fields:
`ClassResult`
, `MacroResult` or `ModuleResult`. The second contains general
data, in
particular the following fields:
* `library`
* `modul`: the module the result was found in (not a typo)
...
...
@@ -104,8 +104,9 @@ fields:
The third element of the array contains data specific to the kind of result.
It is easiest to look in `backend/Cloogle.dcl` at the types
`FunctionResultExtras`, `TypeResultExtras`, `ClassResultExtras` and
`MacroResultExtras` to get an idea of the fields that may be returned.
`FunctionResultExtras`, `TypeResultExtras`, `ClassResultExtras`,
`MacroResultExtras` and `ModuleResultExtras` to get an idea of the fields
that may be returned.
-
`more_available`
...
...
backend/Cloogle.dcl
View file @
15d3ff45
...
...
@@ -30,6 +30,7 @@ from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
|
TypeResult
TypeResult
|
ClassResult
ClassResult
|
MacroResult
MacroResult
|
ModuleResult
ModuleResult
::
BasicResult
=
{
library
::
String
...
...
@@ -72,6 +73,11 @@ from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
,
macro_representation
::
String
}
::
ModuleResult
:==
(
BasicResult
,
ModuleResultExtras
)
::
ModuleResultExtras
=
{
module_is_core
::
Bool
}
::
LocationResult
:==
(
String
,
String
,
Maybe
Int
,
Maybe
Int
)
::
StrUnifier
:==
([(
String
,
String
)],
[(
String
,
String
)])
...
...
@@ -81,9 +87,11 @@ from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
::
ShortClassResult
=
{
cls_name
::
String
,
cls_vars
::
[
String
]
}
derive
JSONEncode
Request
,
Response
,
Result
,
ShortClassResult
,
BasicResult
,
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
,
ModuleResultExtras
derive
JSONDecode
Request
,
Response
,
Result
,
ShortClassResult
,
BasicResult
,
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
,
ModuleResultExtras
instance
zero
Request
instance
zero
Response
...
...
backend/Cloogle.icl
View file @
15d3ff45
...
...
@@ -5,9 +5,11 @@ import Text
import
Text
.
JSON
derive
JSONEncode
Request
,
Response
,
Result
,
ShortClassResult
,
BasicResult
,
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
,
ModuleResultExtras
derive
JSONDecode
Request
,
Response
,
Result
,
ShortClassResult
,
BasicResult
,
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
FunctionResultExtras
,
TypeResultExtras
,
ClassResultExtras
,
MacroResultExtras
,
ModuleResultExtras
instance
zero
Request
where
...
...
@@ -46,6 +48,7 @@ where
basic
(
TypeResult
(
br
,_))
=
br
basic
(
ClassResult
(
br
,_))
=
br
basic
(
MacroResult
(
br
,_))
=
br
basic
(
ModuleResult
(
br
,_))
=
br
err
::
Int
String
->
Response
err
c
m
=
{
return
=
c
...
...
backend/CloogleServer.icl
View file @
15d3ff45
...
...
@@ -188,18 +188,18 @@ where
#
mbType
=
prepare_unification
True
<$>
(
unify
>>=
parseType
o
fromString
)
// Search normal functions
#
filts
=
catMaybes
[
(\
t
_
->
isUnifiable
t
)
<$>
mbType
,
(\
n
loc
_
->
isNameMatch
(
size
n
*
2
/
3
)
n
loc
)
<$>
name
,
(\
n
loc
_
->
isNameMatch
(
size
n
*
2
/
3
)
n
$
getName
loc
)
<$>
name
]
#
funs
=
map
(\
f
->
makeFunctionResult
name
mbType
Nothing
f
db
)
$
findFunction``
filts
db
// Search macros
#
macros
=
case
(
isNothing
mbType
,
name
)
of
(
True
,
Just
n
)
=
findMacro`
(\
loc
_
->
isNameMatch
(
size
n
*
2
/
3
)
n
loc
)
db
(
True
,
Just
n
)
=
findMacro`
(\
loc
_
->
isNameMatch
(
size
n
*
2
/
3
)
n
$
getName
loc
)
db
_
=
[]
#
macros
=
map
(\(
lhs
,
rhs
)
->
makeMacroResult
name
lhs
rhs
)
macros
// Search class members
#
filts
=
catMaybes
[
(\
t
_
_
_
_->
isUnifiable
t
)
<$>
mbType
,
(\
n
(
Location
lib
mod
_
_
_)
_
_
f
_
->
isNameMatch
(
size
n
*
2
/
3
)
n
(
Location
lib
mod
Nothing
Nothing
f
)
)
<$>
name
(
size
n
*
2
/
3
)
n
f
)
<$>
name
]
#
members
=
findClassMembers``
filts
db
#
members
=
map
(\(
Location
lib
mod
line
iclline
cls
,
vs
,_,
f
,
et
)
->
makeFunctionResult
name
mbType
...
...
@@ -217,8 +217,28 @@ where
(
True
,
Just
c
)
=
findClass`
(\
loc
_
_
_
->
toLowerCase
(
getName
loc
)
==
c
)
db
_
=
[]
#
classes
=
map
(
flip
makeClassResult
db
)
classes
// Search modules
#
modules
=
case
(
mbType
,
name
)
of
(
Nothing
,
Just
n
)
=
findModule`
(\_
m
_
->
isNameMatch
(
size
n
*
2
/
3
)
n
m
)
db
_
=
[]
#
modules
=
map
(
makeModuleResult
name
)
modules
// Merge results
=
sort
$
funs
++
members
++
types
++
classes
++
macros
=
sort
$
funs
++
members
++
types
++
classes
++
macros
++
modules
makeModuleResult
::
(
Maybe
String
)
(
Library
,
Module
,
ModuleInfo
)
->
Result
makeModuleResult
mbName
(
lib
,
mod
,
info
)
=
ModuleResult
(
{
library
=
lib
,
modul
=
mod
,
filename
=
modToFilename
mod
,
dcl_line
=
Nothing
,
icl_line
=
Nothing
,
distance
=
levenshtein`
mod
(
fromJust
mbName
)
,
builtin
=
Nothing
}
,
{
module_is_core
=
info
.
is_core
}
)
makeClassResult
::
(
Location
,
[
TypeVar
],
ClassContext
,
[(
Name
,
ExtendedType
)])
TypeDB
->
Result
...
...
@@ -395,9 +415,9 @@ where
isUnifiable
::
Type
ExtendedType
->
Bool
isUnifiable
t1
(
ET
t2
_)
=
isJust
(
unify
[]
t1
(
prepare_unification
False
t2
))
isNameMatch
::
!
Int
!
String
Location
->
Bool
isNameMatch
maxdist
n1
loc
#
(
n1
,
n2
)
=
({
toLower
c
\\
c
<-:
n1
},
{
toLower
c
\\
c
<-:
getName
loc
})
isNameMatch
::
!
Int
!
String
!
String
->
Bool
isNameMatch
maxdist
n1
name
#
(
n1
,
n2
)
=
({
toLower
c
\\
c
<-:
n1
},
{
toLower
c
\\
c
<-:
name
})
=
n1
==
""
||
indexOf
n1
n2
<>
-1
||
levenshtein
[
c
\\
c
<-:
n1
]
[
c
\\
c
<-:
n2
]
<=
maxdist
isModMatch
::
![
String
]
Location
->
Bool
...
...
backend/TypeDB.dcl
View file @
15d3ff45
...
...
@@ -54,6 +54,7 @@ classCount :: TypeDB -> Int
instanceCount
::
TypeDB
->
Int
typeCount
::
TypeDB
->
Int
deriveCount
::
TypeDB
->
Int
moduleCount
::
TypeDB
->
Int
filterLocations
::
(
Location
->
Bool
)
TypeDB
->
TypeDB
...
...
@@ -104,6 +105,7 @@ putDerivationss :: [(Name, [(Type, Location)])] TypeDB -> TypeDB
getModule
::
Library
Module
TypeDB
->
Maybe
ModuleInfo
putModule
::
Library
Module
ModuleInfo
TypeDB
->
TypeDB
findModule`
::
(
Library
Module
ModuleInfo
->
Bool
)
TypeDB
->
[(
Library
,
Module
,
ModuleInfo
)]
searchExact
::
Type
TypeDB
->
[(
Location
,
ExtendedType
)]
...
...
backend/TypeDB.icl
View file @
15d3ff45
...
...
@@ -122,6 +122,9 @@ typeCount {typemap} = mapSize typemap
deriveCount
::
TypeDB
->
Int
deriveCount
{
derivemap
}
=
sum
$
map
length
$
elems
derivemap
moduleCount
::
TypeDB
->
Int
moduleCount
{
modulemap
}
=
mapSize
modulemap
filterLocations
::
(
Location
->
Bool
)
TypeDB
->
TypeDB
filterLocations
f
db
...
...
@@ -132,6 +135,7 @@ filterLocations f db
,
typemap
=
filterLoc
db
.
typemap
,
instancemap
=
filtInstLocs
<$>
db
.
instancemap
,
derivemap
=
filtInstLocs
<$>
db
.
derivemap
,
modulemap
=
filtModules
db
.
modulemap
}
where
filterLoc
::
((
Map
Location
a
)
->
Map
Location
a
)
...
...
@@ -145,6 +149,9 @@ where
where
ls`
=
filter
f
ls
filtModules
::
((
Map
(
Library
,
Module
)
a
)
->
Map
(
Library
,
Module
)
a
)
filtModules
=
filterWithKey
(\(
l
,
m
)
_
->
f
(
Location
l
m
Nothing
Nothing
undef
))
getFunction
::
Location
TypeDB
->
Maybe
ExtendedType
getFunction
loc
{
functionmap
}
=
get
loc
functionmap
...
...
@@ -282,6 +289,10 @@ getModule lib mod {modulemap} = get (lib,mod) modulemap
putModule
::
Library
Module
ModuleInfo
TypeDB
->
TypeDB
putModule
lib
mod
info
db
=
{
db
&
modulemap
=
put
(
lib
,
mod
)
info
db
.
modulemap
}
findModule`
::
(
Library
Module
ModuleInfo
->
Bool
)
TypeDB
->
[(
Library
,
Module
,
ModuleInfo
)]
findModule`
f
{
modulemap
}
=
map
(\((
l
,
m
),
i
)
->
(
l
,
m
,
i
))
$
toList
$
filterWithKey
(
uncurry
f
)
modulemap
newDb
::
TypeDB
newDb
=
zero
...
...
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