Commit bef7c290 authored by John van Groningen's avatar John van Groningen

extend preliminary implementation of deriving instances with default class...

extend preliminary implementation of deriving instances with default class members that will be derived using the specified generic function on instantiation
parent dcf06742
This diff is collapsed.
......@@ -164,6 +164,8 @@ getBelongingSymbols (Declaration {decl_kind=STE_Imported STE_Class def_mod_index
# default_member_indexes = createArray n_members -1
default_member_indexes & [class_member_n] = 0
-> add_more_default_class_member_macros (class_member_n+1) [|default_class_member_macro_ident_and_index] 1 default_member_indexes dcl_modules
DeriveDefault generic_ident generic_index
-> add_default_class_member_macros (class_member_n+1) dcl_modules
| size class_macro_members==0
= (BS_Members class_members,dcl_modules)
= (BS_MembersAndMacros class_members class_macro_members {} {},dcl_modules)
......@@ -179,6 +181,8 @@ getBelongingSymbols (Declaration {decl_kind=STE_Imported STE_Class def_mod_index
# default_class_members = [|default_class_member_macro_ident_and_index:default_class_members]
default_member_indexes & [class_member_n] = default_member_n
-> add_more_default_class_member_macros (class_member_n+1) default_class_members (default_member_n+1) default_member_indexes dcl_modules
DeriveDefault generic_ident generic_index
-> add_more_default_class_member_macros (class_member_n+1) default_class_members default_member_n default_member_indexes dcl_modules
# default_class_members = {default_class_member\\default_class_member<-reverse default_class_members}
= (BS_MembersAndMacros class_members class_macro_members default_member_indexes default_class_members,dcl_modules)
= (members,dcl_modules)
......
......@@ -233,6 +233,8 @@ where
compare_default_implementations NoMemberDefault NoMemberDefault = True
compare_default_implementations (MacroMemberDefault _) (MacroMemberDefault _) = True
compare_default_implementations (DeriveDefault generic_ident1 generic_index1) (DeriveDefault generic_ident2 generic_index2)
= generic_index1==generic_index2 && generic_ident1==generic_ident2
compare_default_implementations _ _ = False
sort_clas_macro_members class_macro_members
......
......@@ -294,19 +294,20 @@ solveExplicitImports expl_imp_indices_ikh modules_in_component_set importing_mod
-> ([Declaration { decl_ident = ds_ident, decl_pos = position,
decl_kind = STE_Imported STE_Member def_mod_index,
decl_index = ds_index } : decls_accu], dcl_modules)
BS_MembersAndMacros class_members macro_members default_member_indexes default_macros
BS_MembersAndMacros class_members macro_members _ default_macros
| belong_nr<size class_members
# {ds_ident, ds_index} = class_members.[belong_nr]
# decl = Declaration { decl_ident = ds_ident, decl_pos = position,
decl_kind = STE_Imported STE_Member def_mod_index,
decl_index = ds_index }
-> ([decl : decls_accu], dcl_modules)
| belong_nr<size class_members+size macro_members
# {mm_ident,mm_index} = macro_members.[belong_nr-size class_members]
# belong_nr=belong_nr-size class_members
| belong_nr<size macro_members
# {mm_ident,mm_index} = macro_members.[belong_nr]
-> ([Declaration { decl_ident = mm_ident, decl_pos = position,
decl_kind = STE_Imported (STE_DclMacroOrLocalMacroFunction []) def_mod_index,
decl_index = mm_index } : decls_accu], dcl_modules)
# {mm_ident,mm_index} = default_macros.[belong_nr-(size class_members+size macro_members)]
# {mm_ident,mm_index} = default_macros.[belong_nr-size macro_members]
-> ([Declaration { decl_ident = mm_ident, decl_pos = position,
decl_kind = STE_Imported (STE_DclMacroOrLocalMacroFunction []) def_mod_index,
decl_index = mm_index } : decls_accu], dcl_modules)
......@@ -838,8 +839,14 @@ instance check_completeness Let where
) ccs
instance check_completeness MemberDef where
check_completeness {me_type} cci ccs
= check_completeness me_type cci ccs
check_completeness {me_type,me_default_implementation} cci ccs
= check_completeness me_default_implementation cci (check_completeness me_type cci ccs)
instance check_completeness MemberDefault where
check_completeness (DeriveDefault generic_ident {gi_module,gi_index}) cci ccs
= check_whether_ident_is_imported generic_ident gi_module gi_index STE_Generic cci ccs
check_completeness _ _ ccs
= ccs
instance check_completeness (Optional x) | check_completeness x where
check_completeness (Yes x) cci ccs
......
......@@ -268,9 +268,9 @@ isGlobalContext parseContext :== parseContext bitand cGlobalContext <> 0 // not
isDclContext parseContext :== parseContext bitand cICLContext == 0
isIclContext parseContext :== parseContext bitand cICLContext <> 0 // not (isDclContext parseContext)
isNotClassOrInstanceDefsContext parseContext :== parseContext bitand ClassOrInstanceDefsContext == 0
isGlobalOrClassDefsContext parseContext :== parseContext bitand GlobalOrClassDefsContext <> 0
isInstanceDefsContext parseContext :== parseContext bitand InstanceDefsContext <> 0
isClassOrInstanceDefsContext parseContext :== parseContext bitand ClassOrInstanceDefsContext <> 0
isGlobalOrClassDefsContext parseContext :== parseContext bitand GlobalOrClassDefsContext <> 0
isInstanceDefsContext parseContext :== parseContext bitand InstanceDefsContext <> 0
isNotClassDefsContext parseContext :== parseContext bitand ClassDefsContext == 0
cWantIclFile :== True
......@@ -456,7 +456,7 @@ where
| isGlobalContext parseContext
# (gendef, pState) = wantDeriveDefinition parseContext pos pState
= (True, gendef, pState)
| isInstanceDefsContext parseContext
| isClassOrInstanceDefsContext parseContext
# (derive_instance_def, pState) = wantDeriveInstanceDefinition parseContext pos pState
= (True, derive_instance_def, pState)
= (False,abort "no def(2)",parseError "definition" No "derive declarations are only at the global level" pState)
......@@ -547,7 +547,7 @@ where
localsExpected = ~ ss_useLayout
(rhs, _, pState) = wantRhs localsExpected (ruleDefiningRhsSymbol parseContext (isNotEmpty args)) (tokenBack pState)
| isLocalContext parseContext
| isNotClassOrInstanceDefsContext parseContext
| not (isClassOrInstanceDefsContext parseContext)
= (PD_NodeDef pos (combine_args args) rhs, pState)
= (PD_NodeDef pos (combine_args args) rhs, parseError "RHS" No "<class or instance definition>" pState)
= (PD_NodeDef pos (combine_args args) rhs, parseError "RHS" No "<global definition>" pState)
......@@ -560,7 +560,7 @@ where
want_rhs_of_def parseContext (Yes (name, False), []) definingToken pos pState
# code_allowed = definingToken == EqualToken
| isIclContext parseContext && isLocalContext parseContext && (definingToken == EqualToken || (definingToken == DefinesColonToken && isGlobalContext parseContext)) &&
/* PK isLowerCaseName name.id_name && */ isNotClassOrInstanceDefsContext parseContext
not (isClassOrInstanceDefsContext parseContext)
# (token, pState) = nextToken FunctionContext pState
| code_allowed && token == CodeToken
# (rhs, pState) = wantCodeRhs pState
......
......@@ -1542,12 +1542,23 @@ where
check_symbols_of_class_members [PD_TypeSpec pos name prio opt_type=:(Yes type=:{st_context,st_arity}) specials : defs] type_context macro_count ca
# (bodies, fun_kind, defs, ca) = collectFunctionBodies name st_arity prio FK_Unknown defs ca
| bodies=:[]
# mem_def = { me_ident = name, me_type = { type & st_context = [type_context : st_context ]}, me_pos = pos, me_priority = prio,
me_default_implementation = NoMemberDefault,
me_offset = NoIndex, me_class_vars = [], me_class = { glob_module = NoIndex, glob_object = NoIndex}, me_type_ptr = nilPtr }
(mem_defs,mem_macros,default_members_without_type,macro_members,new_macro_count,ca)
= check_symbols_of_class_members defs type_context macro_count ca
= ([mem_def : mem_defs],mem_macros,default_members_without_type,macro_members,new_macro_count,ca)
# type & st_context = [type_context : st_context]
= case defs of
[PD_DeriveInstanceMember pos member_ident generic_ident:defs]
| member_ident.id_name==name.id_name
# mem_def = { me_ident = name, me_type = type, me_pos = pos, me_priority = prio,
me_default_implementation = DeriveDefault generic_ident {gi_module=NoIndex,gi_index=NoIndex},
me_offset = NoIndex, me_class_vars = [], me_class = {glob_module = NoIndex, glob_object = NoIndex}, me_type_ptr = nilPtr }
(mem_defs,mem_macros,default_members_without_type,macro_members,new_macro_count,ca)
= check_symbols_of_class_members defs type_context macro_count ca
-> ([mem_def : mem_defs],mem_macros,default_members_without_type,macro_members,new_macro_count,ca)
_
# mem_def = { me_ident = name, me_type = type, me_pos = pos, me_priority = prio,
me_default_implementation = NoMemberDefault,
me_offset = NoIndex, me_class_vars = [], me_class = {glob_module = NoIndex, glob_object = NoIndex}, me_type_ptr = nilPtr }
(mem_defs,mem_macros,default_members_without_type,macro_members,new_macro_count,ca)
= check_symbols_of_class_members defs type_context macro_count ca
-> ([mem_def : mem_defs],mem_macros,default_members_without_type,macro_members,new_macro_count,ca)
= case fun_kind of
FK_Macro
# macro = MakeNewImpOrDefFunction name st_arity bodies FK_Macro prio opt_type pos
......@@ -1598,6 +1609,8 @@ where
macro = MakeNewImpOrDefFunction macro_ident fun_arity bodies FK_Macro prio No fun_pos
macro_member = {mm_ident=macro_ident,mm_index=macro_count}
-> (mem_defs,[macro : mem_macros],[(name,macro_member,fun_pos) : default_members_without_type],macro_members,new_macro_count,ca)
check_symbols_of_class_members [PD_DeriveInstanceMember pos _ _ : defs] type_context macro_count ca
= check_symbols_of_class_members defs type_context macro_count (postParseError pos "member type missing" ca)
check_symbols_of_class_members [def : _] type_context macro_count ca
= abort "postparse.check_symbols_of_class_members: unknown def" // <<- def
check_symbols_of_class_members [] type_context macro_count ca
......
......@@ -401,7 +401,7 @@ cNameLocationDependent :== True
:: ClassDefInfos :== {# .{! [TypeKind]}}
:: MemberDefault = NoMemberDefault | MacroMemberDefault !MacroMember
:: MemberDefault = NoMemberDefault | MacroMemberDefault !MacroMember | DeriveDefault !Ident !GlobalIndex
:: MemberDef =
{ me_ident :: !Ident
......
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