Verified Commit d7190db2 authored by Camil Staps's avatar Camil Staps 🚀

Generalise macros to all function definitions without type

parent 6f24443f
......@@ -56,8 +56,8 @@ indexModule :: !Bool !String !Module !Library
* @param Whether local definitions (that only exist in the icl) should be indexed.
* @param The path to the module, without .icl or .dcl
* @result A tuple of:
* - Function definitions
* - Macro definitions
* - Function type specifications
* - Macro definitions and other functions that do not have a type
* - Generic function definitions
* - Constructor function definitions
* - Record field function definitions
......
......@@ -39,8 +39,10 @@ from syntax import :: ClassDef{class_args,class_context,class_ident,class_pos},
:: Ident{id_name,id_info}, :: LineNr, :: Module{mod_defs,mod_ident},
:: Optional(Yes,No), :: SymbolPtr, :: Ptr, :: SymbolTableEntry{ste_doc},
:: ParsedDefinition(PD_Class,PD_Derive,PD_Function,PD_Generic,PD_Instance,
PD_Instances,PD_Type,PD_TypeSpec,PD_Documentation,PD_GenericCase),
:: ParsedExpr, :: ParsedInstance{pi_ident,pi_pos,pi_types},
PD_Instances,PD_Type,PD_TypeSpec,PD_Documentation,PD_GenericCase,
PD_NodeDef),
:: ParsedExpr(PE_Ident,PE_List),
:: ParsedInstance{pi_ident,pi_pos,pi_types},
:: ParsedInstanceAndMembers{pim_pi}, :: ParsedModule, :: ParsedTypeDef,
:: Position(FunPos,LinePos,NoPos), :: Priority, :: Rhs, :: ATypeVar,
:: RhsDefsOfType(ConsList,ExtensibleConses,SelectorList,TypeSpec,EmptyRhs,
......@@ -144,7 +146,7 @@ indexModule :: !Bool !String !'DB'.Module !'DB'.Library
!(String 'DB'.ModuleEntry -> 'DB'.ModuleEntry) !TemporaryDB !*World
-> *(!TemporaryDB, !*World)
indexModule include_locals root mod lib modf db w
#! (functions, macros, generics, typedefs, clss, insts, derivs, clsderivs, (modname, modentry), w)
#! (functions,macros,generics,typedefs,clss,insts,derivs,clsderivs,(modname,modentry),w)
= findModuleContents include_locals (root </> lib </> mkdir mod) w
#! lib = lib % (0, size lib - size modname + size mod - 1)
#! db =
......@@ -201,21 +203,21 @@ findModuleContents include_locals path w
Right dcl -> (dcl.mod_defs, dcl.mod_ident.id_name)
#! (icl,icl_symbols,w) = readModule True w
#! icl = case icl of Left _ -> []; Right icl -> icl.mod_defs
#! contents=:(functions,macros,generics,typedefs,clss,insts,derivs,clsderivs) =
( combine cmpLocFst joinLocFst pd_typespecs dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_macros dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_generics dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_types dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_classes dcl dcl_symbols icl icl_symbols
, combine cmpInsts joinInsts pd_instances dcl dcl_symbols icl icl_symbols
#! contents=:(functions,rules,generics,typedefs,clss,insts,derivs,clsderivs) =
( combine cmpLocFst joinLocFst pd_typespecs dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_rewriterules dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_generics dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst pd_types dcl dcl_symbols icl icl_symbols
, combine cmpLocFst joinLocFst 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
)
#! (functions,macros,generics,typedefs,clss,insts,derivs,clsderivs) =
#! (functions,rules,generics,typedefs,clss,insts,derivs,clsderivs) =
if include_locals
contents
( filter (hasDcl o fst) functions
, filter (hasDcl o fst) macros
, filter (hasDcl o fst) rules
, filter (hasDcl o fst) generics
, filter (hasDcl o fst) typedefs
, filter (hasDcl o fst) clss
......@@ -223,7 +225,8 @@ findModuleContents include_locals path w
, filter (not o isEmpty o snd) (map (appSnd (filter (hasDcl o thd3))) derivs)
, filter (hasDcl o (\(_,_,_,x)->x)) clsderivs
) with hasDcl loc = isJust loc.dcl_line
= (functions,macros,generics,typedefs,clss,insts,derivs,clsderivs,(modname,pd_module dcl),w)
#! rules = filter (\(r,_) -> not $ any (\(l,_)->fromJust l.name == fromJust r.name) functions) rules
= (functions,rules,generics,typedefs,clss,insts,derivs,clsderivs,(modname,pd_module dcl),w)
where
combine :: (a a -> Bool) (a a -> a)
(Bool [ParsedDefinition] SymbolTable -> [a])
......@@ -238,12 +241,14 @@ where
unionBy :: (a a -> Bool) (a a -> a) [a] [a] -> [a]
unionBy eq join xs [] = xs
unionBy eq join xs [y:ys] = case partition (eq y) xs of
([], xs) -> [y :unionBy eq join xs ys]
([], xs) -> [y:unionBy eq join xs ys]
(found,xs) -> let (foundys,ys`) = partition (eq y) ys in
[foldr join y (found ++ foundys):unionBy eq join xs ys`]
cmpLocFst :: (LocationInModule, a) (LocationInModule, a) -> Bool
cmpLocFst (x,_) (y,_) = x.name == y.name
cmpLoc x y = x.name == y.name
cmpLocFst :: ((LocationInModule, a) (LocationInModule, a) -> Bool)
cmpLocFst = on cmpLoc fst
joinLocFst (la,x) (lb,_) = (joinLoc la lb,x)
cmpInsts :: (a, b, LocationInModule) (a, b, LocationInModule) -> Bool | == a & == b
......@@ -276,8 +281,8 @@ where
}
pd_module _ = zero
pd_macros :: !Bool ![ParsedDefinition] SymbolTable -> [(LocationInModule, 'DB'.FunctionEntry)]
pd_macros dcl defs st
pd_rewriterules :: !Bool ![ParsedDefinition] SymbolTable -> [(LocationInModule, 'DB'.FunctionEntry)]
pd_rewriterules dcl defs st
= [( setLine dcl pos {zero & name=Just id.id_name}
, let doc = findDoc parseFunctionDoc id st in
{ zero
......@@ -287,7 +292,7 @@ where
, fe_priority=findPrio id >>= 'T'.toMaybePriority
, fe_documentation=doc
}
) \\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- defs]
) \\ pd=:(PD_Function pos id isinfix args rhs _) <- defs]
where
priostring :: Ident -> String
priostring id = case findTypeSpec id defs of
......@@ -348,7 +353,7 @@ where
pd_classes dcl defs st
= [ let
typespecs = pd_typespecs True clsdefs st
macros = [(n,r) \\ ({name=Just n},{fe_representation=Just r}) <- pd_macros dcl 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
......
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