Verified Commit bcf47e56 authored by Camil Staps's avatar Camil Staps 🙂

Merge branch 'function-usages'

parents e12095f1 7c5e0a80
Subproject commit 1a9e842bb4c58ec4ff270b843d878f3fce8e0c22
Subproject commit 25b5f828ddb77a10482ba69b5f35f34c45779cc8
Subproject commit 14b0de79519cdaf0830f6b4f8051bca068e4c673
Subproject commit d052c6fb6fcbff6316f913892f310ce476e5bf0b
......@@ -102,6 +102,7 @@ derive JSONDecode CloogleEntry
, fe_documentation :: !Maybe FunctionDoc //* Documentation on this entry
, fe_class :: !Maybe Index //* The class, for class members
, fe_derivations :: !Maybe [Index] //* The DerivaionEntries
, fe_usages :: ![Index] //* FunctionEntries where the implementation uses this function
}
/**
......
......@@ -98,6 +98,7 @@ where
, fe_documentation = Nothing
, fe_class = Nothing
, fe_derivations = Nothing
, fe_usages = []
}
instance zero ModuleEntry
......@@ -456,9 +457,11 @@ filterUsages names wrap=:{db,name_map}
# db = 'DB'.searchIndices Intersect (sort [(i,[(ExactResult,1)]) \\ is <- idxss, i <- is]) db
// For all lists of entries, the corresponding usages
# (entriess,db) = mapSt 'DB'.getIndices idxss db
# usagess = map (foldr1 mergeUnion o map \e -> getUsages e.value) entriess
# usagess = map (foldr mergeUnion [] o map \e -> getUsages e.value) entriess
// AND all usages together
# usages = foldr1 mergeIntersect usagess
# usages = case usagess of
[] -> []
us -> foldr1 mergeIntersect us
# db = 'DB'.searchIndices AddExcluded [(u,[]) \\ u <- usages] db
= {wrap & db=db}
where
......@@ -466,6 +469,7 @@ where
getUsages (TypeDefEntry tde) = tde.tde_usages
getUsages (ClassEntry ce) = ce.ce_usages
getUsages (ModuleEntry me) = me.me_usages
getUsages (FunctionEntry fe) = fe.fe_usages
getUsages _ = []
// Efficient union on sorted lists
......
......@@ -4,6 +4,8 @@ definition module CloogleDBFactory
* Functions to populate a database using the Clean compiler frontend
*/
from Data.Set import :: Set
import CloogleDB
:: TemporaryDB
......@@ -69,15 +71,15 @@ indexModule :: !Bool !String !Module !Library
* - The module
*/
findModuleContents :: !Bool !String !*World
-> *( ![(LocationInModule, FunctionEntry)]
, ![(LocationInModule, FunctionEntry)]
, ![(LocationInModule, FunctionEntry)]
-> *( ![(LocationInModule, FunctionEntry, Set String)]
, ![(LocationInModule, FunctionEntry, Set String)]
, ![(LocationInModule, FunctionEntry, Set String)]
, ![(LocationInModule, TypeDefEntry)]
, ![(LocationInModule, ClassEntry, [(String, FunctionEntry)])]
, ![(LocationInModule, ClassEntry, [(String, FunctionEntry, Set String)])]
, ![(Name, [(Type, String)], LocationInModule)]
, ![(Name, [(Type, String, LocationInModule)])]
, ![(Name, Type, String, LocationInModule)]
, !(Name, ModuleEntry, [String])
, !(Name, ModuleEntry, Set String)
, !*World
)
......
This diff is collapsed.
......@@ -73,7 +73,7 @@ getEntries :: *(DB v ak a) -> *([(v, Map ak a)], *DB v ak a)
/**
* An in-place map over all entries (also the excluded ones).
*/
mapInPlace :: (v -> v) *(DB v ak a) -> *(DB v ak a)
mapInPlace :: (Int v -> v) *(DB v ak a) -> *(DB v ak a)
/**
* Linear search for entries. The search function returns whether the entry
......
......@@ -7,7 +7,7 @@ import StdInt
import StdString
import StdTuple
from Data.Func import $
from Data.Func import $, hyperstrict
import Data.Functor
import Data.Map
import Data.Maybe
......@@ -23,7 +23,7 @@ instance == Index where == (Index a) (Index b) = a == b
instance < Index where < (Index a) (Index b) = a < b
newDB :: [v] -> *DB v ak a
newDB vs = DB {{value=v,included=True,annotations=newMap} \\ v <- vs}
newDB vs = DB {{value=hyperstrict v,included=True,annotations=newMap} \\ v <- vs}
saveDB :: *(DB v ak a) *File -> *(*DB v ak a, *File) | JSONEncode{|*|} v
saveDB (DB db) f
......@@ -98,15 +98,17 @@ where
# (r,es) = collect (i-1) es
= (if e.included [(e.value,e.annotations):r] r, es)
mapInPlace :: (v -> v) *(DB v ak a) -> *(DB v ak a)
mapInPlace :: (Int v -> v) *(DB v ak a) -> *(DB v ak a)
mapInPlace f (DB db)
# (s,db) = usize db
= DB (upd (s-1) db)
= DB (upd 0 s db)
where
upd -1 es = es
upd i es
# (e,es) = es![i]
= upd (i-1) {es & [i]={e & value=f e.value}}
//upd :: !Int !Int !*{!Entry v ak a} -> *{!Entry v ak a}
upd i s es
| i == s = es
#! (e,es) = es![i]
#! e & value = hyperstrict $ f i e.value
= upd (i+1) s {es & [i]=e}
search :: !SearchMode (v -> (Bool, [(ak, a)])) *(DB v ak a) -> *DB v ak a | ==, < ak
search mode f (DB db)
......
definition module Idents
from StdClass import class Eq
from StdList import isMember, removeDup
from StdOverloaded import class ==
from Data.Set import :: Set
from syntax import :: ParsedDefinition
:: Idents =
{ locals :: Set String
, globals :: Set String
}
:: IdentContext
= ICExpression
| ICPattern
class idents t :: IdentContext t -> Idents
instance idents [t] | idents t
instance idents ParsedDefinition
implementation module Idents
from Data.List import concatMap
from Data.Set import :: Set, newSet, union, unions, difference, fromList
import syntax
removeLocalGlobals :: Idents -> Idents
removeLocalGlobals ids = {ids & globals=difference ids.globals ids.locals}
noLocals :: Idents -> Idents
noLocals ids = {ids & locals=newSet}
instance zero Idents
where
zero =
{ locals = newSet
, globals = newSet
}
instance + Idents
where
+ a b = removeLocalGlobals
{ locals = union a.locals b.locals
, globals = union a.globals b.globals
}
instance idents [t] | idents t
where
idents c xs = removeLocalGlobals
{ locals = unions [x.locals \\ x <- xids]
, globals = unions [x.globals \\ x <- xids]
}
where xids = map (idents c) xs
instance idents (Optional a) | idents a
where
idents _ No = zero
idents c (Yes x) = idents c x
instance idents String
where
idents ICExpression s = {zero & globals=fromList [s]}
idents ICPattern s = {zero & locals= fromList [s]}
instance idents Ident where idents c id = idents c id.id_name
instance idents ParsedDefinition
where
idents c pd = case pd of
PD_Function _ id _ args rhs _ ->
idents ICPattern id +
noLocals (idents ICPattern args + idents ICExpression rhs)
PD_NodeDef _ e rhs -> idents ICPattern e + idents ICExpression rhs
PD_Type _ -> abort "idents PD_Type\n"
// PD_Type ptd -> abort "idents PD_Type\n"
PD_TypeSpec _ _ _ _ _ -> zero
PD_Class _ _ -> abort "idents PD_Class\n"
// PD_Class ClassDef [ParsedDefinition]
PD_Instance _ -> abort "idents PD_Instance\n"
// PD_Instance ParsedInstanceAndMembers
// PD_Instances [ParsedInstanceAndMembers]
// PD_Import [ParsedImport]
// PD_ImportedObjects [ImportedObject]
// PD_ForeignExport !Ident !{#Char} !Int !Bool /* if stdcall */
// PD_Generic GenericDef
// PD_GenericCase GenericCaseDef Ident
// PD_Derive [GenericCaseDef]
// PD_Documentation DocType String
// PD_Erroneous
instance idents ParsedExpr
where
idents c pe = case pe of
PE_List pes -> idents c pes
PE_Ident id -> idents c id
PE_Basic b -> idents c b
PE_Bound _ -> zero
PE_Lambda _ args rhs _ -> noLocals (idents ICPattern args + idents ICExpression rhs)
PE_Tuple es -> idents c es
PE_Record init _ fields -> idents c init + idents c [f.bind_src \\ f <- fields]
PE_ArrayPattern _ -> abort "idents PE_ArrayPattern\n"
//(PE_ArrayPattern ![ElemAssignment]
PE_UpdateComprehension base (PE_Update _ sels new) _ qs -> noLocals (idents ICExpression [base,new] + idents ICExpression sels + idents ICPattern qs)
PE_ArrayDenot _ es -> idents c es
PE_Selection _ e s -> idents c e + idents c s
PE_Update b s e -> idents c b + idents c s + idents c e
PE_Case _ pe alts -> idents c pe + idents c alts
PE_If _ b t e -> idents c [b,t,e] + idents c "if"
PE_Let locals e -> noLocals (idents ICPattern locals + idents ICExpression e)
PE_ListCompr _ _ e qs -> noLocals (idents ICPattern qs + idents ICExpression e)
PE_ArrayCompr _ e qs -> noLocals (idents ICPattern qs + idents ICExpression e)
PE_Sequ s -> idents c s
PE_WildCard -> zero
PE_Matches _ e p _ -> idents ICPattern e + idents ICPattern p
PE_QualifiedIdent _ s -> idents c s
PE_ABC_Code _ _ -> zero
PE_Any_Code _ _ _ -> zero
PE_DynamicPattern pe _ -> idents c pe
PE_Dynamic pe _ -> idents c pe + idents c "dynamic"
PE_Generic id _ -> idents c id
//(PE_TypeSignature !ArrayKind !ParsedExpr
PE_Empty -> zero
_ -> abort "idents ParsedExpr\n"
instance idents BasicValue
where
idents _ b = case b of
BVB b -> idents ICExpression (toString b)
_ -> zero
instance idents Rhs
where
idents ICExpression rhs = noLocals (idents ICExpression rhs.rhs_alts + idents ICPattern rhs.rhs_locals)
instance idents LocalDefs
where
idents c (LocalParsedDefs defs) = idents c defs
idents _ _ = abort "idents LocalDefs\n"
instance idents OptGuardedAlts
where
idents ICExpression alts = case alts of
UnGuardedExpr e -> idents ICExpression e
GuardedAlts es oth -> idents ICExpression es + idents ICExpression oth
instance idents ExprWithLocalDefs
where
idents ICExpression e = noLocals (idents ICExpression e.ewl_locals + idents ICExpression e.ewl_expr)
// NOTE ewl_nodes?
instance idents GuardedExpr
where
idents ICExpression e = idents ICExpression e.alt_guard + idents ICExpression e.alt_expr
// NOTE alt_nodes?
instance idents CaseAlt
where
idents ICExpression a = noLocals (idents ICPattern a.calt_pattern + idents ICExpression a.calt_rhs)
instance idents Qualifier
where
idents ICPattern q =
idents ICPattern q.qual_generators +
idents ICPattern q.qual_let_defs +
idents ICExpression q.qual_filter
instance idents Generator
where
idents ICPattern g = idents ICPattern g.gen_pattern + idents ICExpression g.gen_expr
instance idents Sequence
where
idents ICExpression s = case s of
SQ_FromThen _ a b -> idents ICExpression [a,b]
SQ_FromThenTo _ a b c -> idents ICExpression [a,b]
SQ_From _ a -> idents ICExpression a
SQ_FromTo _ a b -> idents ICExpression [a,b]
instance idents ParsedSelection
where
idents c ps = case ps of
PS_Record id _ -> idents c id
PS_QualifiedRecord _ s _ -> idents c s
PS_Array e -> idents c e
PS_Erroneous -> zero
//import StdMisc
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