Commit 4c096b3d authored by Camil Staps's avatar Camil Staps 🚀

Add type/class search; added class information for class members

parent 3e468e4b
......@@ -15,7 +15,7 @@ from Type import :: Type, :: TypeVar, :: TVAssignment, :: TypeDef,
from Cloogle import :: FunctionKind, :: SyntaxExample, :: CleanLangReportLocation
from Doc import :: FunctionDoc, :: TypeDoc, :: ClassDoc, :: ModuleDoc
from DB import :: DB, :: Index
from DB import :: DB, :: Entry, :: Index
from NGramIndex import :: NGramIndex
/**
......@@ -149,6 +149,7 @@ patternMatches :: SyntaxPattern String -> Bool
:: LineNr :== Maybe Int
instance zero Location
instance == Location
instance zero FunctionEntry
instance zero ModuleEntry
......@@ -200,6 +201,9 @@ syncDB :: !Int !*CloogleDB -> *CloogleDB
saveDB :: *CloogleDB *File -> *(*CloogleDB, *File)
openDB :: !*File -> *(!Maybe *CloogleDB, !*File)
getIndex :: !Index !*CloogleDB -> *(Entry CloogleEntry AnnotationKey Annotation, *CloogleDB)
filterDB :: (CloogleEntry -> Bool) !*CloogleDB -> *CloogleDB
filterLocations :: (Location -> Bool) !*CloogleDB -> *CloogleDB
filterName :: !String !*CloogleDB -> *CloogleDB
......
......@@ -75,6 +75,13 @@ printersperse ia a bs = intercalate (print False a) (map (print ia) bs)
instance zero Location where zero = NoLocation
derive gLexOrd Location, Maybe, CleanLangReportLocation
instance < Location where < a b = (a =?= b) === LT
instance == Location
where
== (Location a b c d e f) (Location p q r s t u)
= and [a==p, b==q, c==r, d==s, e==t, f==u]
== (Builtin a _) (Builtin b _) = a == b
== NoLocation NoLocation = True
== _ _ = False
instance zero FunctionEntry
where
......@@ -180,12 +187,12 @@ isBuiltin _ = False
isCore :: !Location !*CloogleDB -> *(Bool, *CloogleDB)
isCore loc wrap=:{db,module_index} = case get loc module_index of
Nothing -> (False, wrap)
Just id -> let ({value=ModuleEntry me},db`) = getIndex id db in (me.me_is_core, {wrap & db=db`})
Just id -> let ({value=ModuleEntry me},db`) = 'DB'.getIndex id db in (me.me_is_core, {wrap & db=db`})
isApp :: !Location !*CloogleDB -> *(Bool, *CloogleDB)
isApp loc wrap=:{db,module_index} = case get loc module_index of
Nothing -> (False, wrap)
Just id -> let ({value=ModuleEntry me},db`) = getIndex id db in (me.me_is_app, {wrap & db=db`})
Just id -> let ({value=ModuleEntry me},db`) = 'DB'.getIndex id db in (me.me_is_app, {wrap & db=db`})
toTypeDefEntry :: Location TypeDef (Maybe TypeDoc) -> TypeDefEntry
toTypeDefEntry loc td doc =
......@@ -254,6 +261,14 @@ where
# (line,f) = freadline f
= (fromJSON (fromString line), f)
getIndex :: !Index !*CloogleDB -> *(Entry CloogleEntry AnnotationKey Annotation, *CloogleDB)
getIndex idx wrap=:{db}
# (e,db) = 'DB'.getIndex idx db
= (e, {wrap & db=db})
filterDB :: (CloogleEntry -> Bool) !*CloogleDB -> *CloogleDB
filterDB f db = {db & db = 'DB'.search (\v -> (f v, [])) db.db}
filterLocations :: (Location -> Bool) !*CloogleDB -> *CloogleDB
filterLocations f db =
{ db
......
......@@ -73,7 +73,7 @@ findModuleContents :: !Bool !String !*World
, ![(LocationInModule, FunctionEntry)]
, ![(LocationInModule, FunctionEntry)]
, ![(LocationInModule, TypeDefEntry)]
, ![(LocationInModule, ClassEntry)]
, ![(LocationInModule, ClassEntry, [(String, FunctionEntry)])]
, ![(Name, [(Type, String)], LocationInModule)]
, ![(Name, [(Type, String, LocationInModule)])]
, ![(Name, Type, String, LocationInModule)]
......
......@@ -15,7 +15,7 @@ import Control.Applicative
import Control.Monad
import Data.Either
import Data.Error
from Data.Func import $, mapSt, on
from Data.Func import $, mapSt, on, `on`
import Data.Functor
import Data.Generics.GenDefault
import Data.List
......@@ -61,7 +61,7 @@ import qualified Type as T
from Type import instance == Type,
class print(print), instance print Type, instance print Priority
from Cloogle import :: FunctionKind(..)
from DB import :: DB, :: Index, newDB, instance == Index
from DB import :: DB, :: Index(..), newDB, instance == Index
import qualified DB
import qualified CloogleDB as CDB
from NGramIndex import :: NGramIndex, newNGramIndex, index
......@@ -70,12 +70,13 @@ from CloogleDB import
:: Location(Location,NoLocation),
:: CloogleEntry(..),
:: ModuleEntry{me_loc,me_is_core,me_is_app,me_documentation},
:: FunctionEntry{fe_loc,fe_type,fe_kind,fe_generic_vars,fe_priority,fe_representation,fe_documentation},
:: FunctionEntry{fe_loc,fe_type,fe_kind,fe_generic_vars,fe_priority,fe_representation,fe_documentation,fe_class},
:: TypeDefEntry{tde_loc},
:: ClassEntry{ce_loc},
:: SyntaxEntry, :: DeriveEntry, :: InstanceEntry,
instance zero FunctionEntry, instance zero ModuleEntry,
class getLocation, instance getLocation CloogleEntry
class getLocation, instance getLocation CloogleEntry,
instance == Location
from Doc import :: ModuleDoc, :: FunctionDoc{..}, :: ClassDoc, :: TypeDoc{..},
:: ConstructorDoc, :: ClassMemberDoc, :: Description,
:: ParseWarning(UsedReturn,IllegalField), :: ParseError,
......@@ -88,7 +89,7 @@ from Doc import :: ModuleDoc, :: FunctionDoc{..}, :: ClassDoc, :: TypeDoc{..},
:: TemporaryDB
= { temp_functions :: ![['CDB'.FunctionEntry]]
, temp_classes :: ![['CDB'.ClassEntry]]
, temp_classes :: ![[('CDB'.ClassEntry, [(String, 'CDB'.FunctionEntry)])]]
, temp_instances :: ![[(!'CDB'.Name, ![(!'CDB'.Type, !String)], !'CDB'.Location)]]
, temp_types :: ![['CDB'.TypeDefEntry]]
, temp_derivations :: ![[(!'CDB'.Name, ![(!'CDB'.Type, !String, !'CDB'.Location)])]]
......@@ -109,11 +110,7 @@ newTemporaryDb
finaliseDb :: !TemporaryDB -> *'CDB'.CloogleDB
finaliseDb tdb
# db = newDB $
[FunctionEntry fun \\ funs <- tdb.temp_functions, fun <- funs] ++
[TypeDefEntry td \\ tds <- tdb.temp_types, td <- tds] ++
[ModuleEntry mod \\ mod <- tdb.temp_modules] ++
[ClassEntry cls \\ clss <- tdb.temp_classes, cls <- clss]
# db = newDB entries
# (names,db) = collectNames db
# name_ngrams = foldr (uncurry index) (newNGramIndex 3 True) names
= { db = db
......@@ -125,6 +122,23 @@ where
Nothing -> ivs
Just loc -> [('CDB'.getName loc, i):ivs]) []
entries =
[FunctionEntry fun \\ funs <- tdb.temp_functions, fun <- funs] ++
[TypeDefEntry td \\ tds <- tdb.temp_types, td <- tds] ++
[ModuleEntry mod \\ mod <- tdb.temp_modules] ++
[ClassEntry cls \\ clss <- tdb.temp_classes, (cls,funs) <- clss] ++
[FunctionEntry
{ fun
& fe_kind=case fun.fe_kind of Function -> ClassMember; Macro -> ClassMacro
, fe_loc='CDB'.setName fname cls.ce_loc
, fe_class=Just $ idxhd \ce -> case ce of
ClassEntry ce -> ce.ce_loc == cls.ce_loc
_ -> False
}
\\ clss <- tdb.temp_classes, (cls,funs) <- clss, (fname,fun) <- funs]
entridxs = zip2 (indexList entries) entries
idxhd f = hd [Index idx \\ (idx,e) <- entridxs | f e]
// Exclude Root Library Aux Base module
findModules :: ![String] !String !'CDB'.Library !a !String !*World
-> *(![('CDB'.Library, 'CDB'.Module, a)], !*World)
......@@ -175,7 +189,7 @@ indexModule include_locals root mod lib modf db w
, (n,f) <- constructor_functions td ++ record_functions td]
: db.temp_functions
]
, temp_classes = [[{ce & ce_loc=castLoc modname loc} \\ (loc,ce) <- clss]:db.temp_classes]
, temp_classes = [[({ce & ce_loc=castLoc modname loc}, fs) \\ (loc,ce,fs) <- clss]:db.temp_classes]
, temp_types = [[{td & tde_loc=castLoc modname loc} \\ (loc,td) <- typedefs]:db.temp_types]
, temp_instances = [castLocThd3 modname insts:db.temp_instances]
, temp_derivations = [map (appSnd (castLocThd3 modname)) derivs:db.temp_derivations]
......@@ -203,7 +217,7 @@ findModuleContents :: !Bool !String !*World
, ![(LocationInModule, 'CDB'.FunctionEntry)]
, ![(LocationInModule, 'CDB'.FunctionEntry)]
, ![(LocationInModule, 'CDB'.TypeDefEntry)]
, ![(LocationInModule, 'CDB'.ClassEntry)]
, ![(LocationInModule, 'CDB'.ClassEntry, [(String, 'CDB'.FunctionEntry)])]
, ![('CDB'.Name, [('CDB'.Type, String)], LocationInModule)]
, ![('CDB'.Name, [('CDB'.Type, String, LocationInModule)])]
, ![('CDB'.Name, 'CDB'.Type, String, LocationInModule)]
......@@ -222,7 +236,7 @@ findModuleContents include_locals path w
, combine cmpLocFst joinLocFst pd_rewriterules dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_generics dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinTypeDefs pd_types dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_classes dcl dcl_symbols icl icl_symbols
, combine cmpLocFst3 joinLocFst3 pd_classes dcl dcl_symbols icl icl_symbols
, combine cmpInsts joinInsts pd_instances dcl dcl_symbols icl icl_symbols
, combineDerivs (pd_derivations True dcl) (pd_derivations False icl)
, combine cmpClsDeriv joinClsDeriv pd_class_derivations dcl dcl_symbols icl icl_symbols
......@@ -234,7 +248,7 @@ findModuleContents include_locals path w
, filter (hasDcl o fst) rules
, filter (hasDcl o fst) generics
, filter (hasDcl o fst) typedefs
, filter (hasDcl o fst) clss
, filter (hasDcl o fst3) clss
, filter (hasDcl o thd3) insts
, filter (not o isEmpty o snd) (map (appSnd (filter (hasDcl o thd3))) derivs)
, filter (hasDcl o (\(_,_,_,x)->x)) clsderivs
......@@ -262,11 +276,17 @@ where
cmpLoc x y = x.name == y.name
cmpLocFst :: ((LocationInModule, a) (LocationInModule, a) -> Bool)
cmpLocFst = on cmpLoc fst
cmpLocFst = cmpLoc `on` fst
cmpLocFst3 :: ((LocationInModule, a, b) (LocationInModule, a, b) -> Bool)
cmpLocFst3 = cmpLoc `on` fst3
joinLocFst :: (LocationInModule, a) (LocationInModule, b) -> (LocationInModule, a)
joinLocFst (l1,a) (l2,_) = (joinLoc l1 l2, a)
joinLocFst3 :: (LocationInModule, a, b) (LocationInModule, c, d) -> (LocationInModule, a, b)
joinLocFst3 (l1,a,b) (l2,_,_) = (joinLoc l1 l2, a, b)
joinTypeDefs :: (LocationInModule, 'CDB'.TypeDefEntry) (LocationInModule, 'CDB'.TypeDefEntry) -> (LocationInModule, 'CDB'.TypeDefEntry)
joinTypeDefs (a,t) (b,u) = (joinLoc a b, 'CDB'.mergeTypeDefEntries t u)
......@@ -377,15 +397,26 @@ where
[(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\ PD_Instance {pim_pi=i} <- defs]
++ [(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\ PD_Instances pis <- defs, {pim_pi=i} <- pis]
pd_classes :: !Bool ![ParsedDefinition] SymbolTable -> [(LocationInModule, 'CDB'.ClassEntry)]
pd_classes :: !Bool ![ParsedDefinition] SymbolTable -> [(LocationInModule, 'CDB'.ClassEntry, [(String, 'CDB'.FunctionEntry)])]
pd_classes dcl defs st
= [ let typespecs = pd_typespecs True clsdefs st
= [ let
typespecs = pd_typespecs True clsdefs st
macros = [(n,r) \\ ({name=Just n},{fe_representation=Just r}) <- pd_rewriterules dcl clsdefs st]
updateRepresentation n fe
= { fe
& fe_kind=if (isNothing $ lookup n macros) fe.fe_kind Macro
, fe_representation=lookup n macros <|> fe.fe_representation
, fe_documentation=if (isSingleFunction typespecs id)
((\d -> {FunctionDoc | d & vars=[]}) <$> findDoc hideIsUsedReturn id st)
fe.fe_documentation
}
in ( setLine dcl class_pos {zero & name=Just id_name}
, 'CDB'.toClass
NoLocation
(map 'T'.toTypeVar class_args)
(flatten $ map 'T'.toTypeContext class_context)
(parseClassDoc typespecs id st)
, [(f,updateRepresentation f et) \\ ({name=Just f}, et) <- typespecs]
)
\\ PD_Class {class_ident=id=:{id_name},class_pos,class_args,class_context} clsdefs <- defs
]
......
......@@ -19,7 +19,7 @@ from Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode
*/
:: *DB v ak a
:: Index =: Index Int // This should be an abstract type
:: Index =: Index Int
:: Entry v ak a =
{ value :: !v
......
implementation module DB
import StdArray
import StdBool
import StdFile
import StdInt
import StdString
......@@ -14,8 +15,6 @@ import Text.JSON
:: *DB v ak a = DB *{!Entry v ak a}
:: Index =: Index Int
JSONEncode{|Index|} _ (Index i) = [JSONInt i]
JSONDecode{|Index|} _ [JSONInt i:l] = (Just (Index i), l)
JSONDecode{|Index|} _ l = (Nothing, l)
......@@ -141,8 +140,8 @@ where
= upd (i+1) s [] {es & [i]={e & included=False}}
upd i s allidxs=:[match=:(Index idx,k,v):idxs] es
# (e,es) = es![i]
# e & annotations = if include (put k v e.annotations) e.annotations
# e & included = include
# e & included = e.included && include
# e & annotations = if e.included (put k v e.annotations) e.annotations
= upd (i+1) s (if include idxs allidxs) {es & [i]=e}
where
include = i == idx
......
......@@ -11,7 +11,7 @@ import StdTuple
import Control.Applicative
import Control.Monad
import qualified Data.Foldable as Foldable
from Data.Func import $, on, instance Functor ((->) r)
from Data.Func import $, on, instance Functor ((->) r), mapSt
import Data.Functor
import Data.List
import qualified Data.Map as M
......@@ -20,6 +20,7 @@ import Data.Tuple
from Text import class Text(concat,indexOf,toLowerCase,split),
instance Text String, instance + String
from DB import :: Entry{value}
import CloogleDB
import Type
import Cloogle
......@@ -38,58 +39,80 @@ search {unify,name,className,typeName,modules,libraries,page,include_builtins,in
Nothing = cdb
# cdb = if include_builtins id (filterLocations (not o isBuiltin)) cdb
# (mods,cdb) = allModules cdb
# cdb = case name of
# cdb = case typeName of
Nothing -> cdb
Just _ -> filterDB (\ce -> ce=:(TypeDefEntry _)) cdb
# cdb = case className of
Nothing -> cdb
Just _ -> filterDB (\ce -> ce=:(ClassEntry _)) cdb
# cdb = case name <|> typeName <|> className of
Nothing -> cdb
Just name -> filterName name cdb
# (es,cdb) = getEntries cdb
= (sort $ map makeResult es, cdb)
# (es,cdb) = mapSt makeResult es cdb
= (sort es, cdb)
makeResult :: (CloogleEntry, Map AnnotationKey Annotation) -> Result
makeResult (entry, annots) = case entry of
FunctionEntry fe -> FunctionResult (general,
makeResult :: (CloogleEntry, Map AnnotationKey Annotation) *CloogleDB -> *(Result, *CloogleDB)
makeResult (entry, annots) db
| entry =: (FunctionEntry _)
# (FunctionEntry fe) = entry
# (cls,db) = case fe.fe_class of
Nothing -> (Nothing, db)
Just i -> case getIndex i db of
({value=ClassEntry ce}, db) -> (Just {cls_name=getName ce.ce_loc, cls_vars=ce.ce_vars}, db)
= (FunctionResult (general,
{ kind = fe.fe_kind
, func = ""
, unifier = Nothing
, required_context = Nothing
, cls = Nothing
, constructor_of = Nothing
, recordfield_of = Nothing
, generic_derivations = Nothing
, param_doc = Nothing
, generic_var_doc = Nothing
, result_doc = Nothing
, type_doc = Nothing
})
TypeDefEntry tde -> TypeResult (general,
{ type = ""
, type_instances = []
, type_derivations = []
, type_field_doc = Nothing
, type_constructor_doc = Nothing
, type_representation_doc = Nothing
})
ModuleEntry me -> ModuleResult (general,
{ module_is_core = False
})
ClassEntry ce -> ClassResult (general,
{ class_name = ""
, class_heading = ""
, class_funs = []
, class_instances = []
, class_derivations = []
})
, func = fromJust (fe.fe_representation <|> pure (concat $ print False (name,fe)))
, unifier = Nothing // TODO
, required_context = Nothing // TODO
, cls = cls
, constructor_of = Nothing // TODO
, recordfield_of = Nothing // TODO
, generic_derivations = Nothing // TODO
, param_doc = Nothing // TODO
, generic_var_doc = Nothing // TODO
, result_doc = Nothing // TODO
, type_doc = Nothing // TODO
}), db)
| entry =: (TypeDefEntry _)
# (TypeDefEntry tde) = entry
= (TypeResult (general,
{ type = concat $ print False tde.tde_typedef
, type_instances = [] // TODO
, type_derivations = [] // TODO
, type_field_doc = Nothing // TODO
, type_constructor_doc = Nothing // TODO
, type_representation_doc = Nothing // TODO
}), db)
| entry =: (ModuleEntry _)
# (ModuleEntry me) = entry
= (ModuleResult (general,
{ module_is_core = False // TODO
}), db)
| entry =: (ClassEntry _)
# (ClassEntry ce) = entry
= (ClassResult (general,
{ class_name = name
, class_heading = foldl ((+) o (flip (+) " ")) name ce.ce_vars +
if (isEmpty ce.ce_context) "" " | " + concat (print False ce.ce_context)
, class_funs = [] // TODO
, class_instances = [] // TODO
, class_derivations = [] // TODO
}), db)
// TODO
where
mbLoc = getLocation entry
name = getName $ fromJust mbLoc
general =
{ library = fromMaybe "" (getLibrary =<< mbLoc)
, modul = fromMaybe "" (getModule =<< mbLoc)
, filename = fromMaybe "" (getFilename =<< mbLoc)
, dcl_line = getDclLine =<< mbLoc
, icl_line = getIclLine =<< mbLoc
, distance = distance
, builtin = Nothing
, documentation = Nothing
, langrep_documentation = Nothing
, distance = distance // TODO
, builtin = Nothing // TODO
, documentation = Nothing // TODO
, langrep_documentation = Nothing // TODO
}
distance = sum
[ case 'M'.get MatchingNGrams annots of
......
Subproject commit 55602cf11665352faf88c7a8064803d0d19879c5
Subproject commit d7f34b39472939993fc9c0fdf0e8d9a0821c7c92
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