diff --git a/CompilerForCAP/gap/LogicTemplates.gi b/CompilerForCAP/gap/LogicTemplates.gi index cf7b974cbd..0fc66c126f 100644 --- a/CompilerForCAP/gap/LogicTemplates.gi +++ b/CompilerForCAP/gap/LogicTemplates.gi @@ -60,13 +60,6 @@ InstallGlobalFunction( CAP_JIT_INTERNAL_ENHANCE_LOGIC_TEMPLATE, function ( templ od; - if IsBound( template.variable_filters ) and Length( template.variable_names ) <> Length( template.variable_filters ) then - - # COVERAGE_IGNORE_NEXT_LINE - Error( "the length of the record entries variable_names and variable_filters of a logic template must be equal" ); - - fi; - if Last( NormalizedWhitespace( template.src_template ) ) = ';' then # COVERAGE_IGNORE_NEXT_LINE @@ -112,6 +105,20 @@ InstallGlobalFunction( CAP_JIT_INTERNAL_ENHANCE_LOGIC_TEMPLATE, function ( templ fi; + if Length( template.variable_names ) <> Length( template.variable_filters ) then + + # COVERAGE_IGNORE_NEXT_LINE + Error( "the length of the record entries variable_names and variable_filters of a logic template must be equal" ); + + fi; + + if not ForAll( template.variable_filters, f -> IsFilter( f ) or IsRecord( f ) ) then + + # COVERAGE_IGNORE_NEXT_LINE + Error( "the entries of variable_filters must be filters or records" ); + + fi; + # default new funcs: none if not IsBound( template.new_funcs ) then @@ -643,7 +650,7 @@ InstallGlobalFunction( CAP_JIT_INTERNAL_TREE_MATCHES_TEMPLATE_TREE, function ( t end; result_func := function ( template_tree, result, keys, tree ) - local var_number, filter, key; + local var_number, filter_or_data_type, key; if debug then # COVERAGE_IGNORE_BLOCK_START @@ -668,30 +675,67 @@ InstallGlobalFunction( CAP_JIT_INTERNAL_TREE_MATCHES_TEMPLATE_TREE, function ( t if not IsBound( variables[var_number] ) then - filter := variable_filters[var_number]; + filter_or_data_type := variable_filters[var_number]; - if IsIdenticalObj( filter, IsObject ) or (IsBound( tree.data_type ) and IsSpecializationOfFilter( filter, tree.data_type.filter )) then - - variables[var_number] := tree; + if IsRecord( filter_or_data_type ) then - if debug then - # COVERAGE_IGNORE_BLOCK_START - Display( "matched via variable1" ); - Display( true ); - # COVERAGE_IGNORE_BLOCK_END + if IsBound( tree.data_type ) and tree.data_type = filter_or_data_type then + + variables[var_number] := tree; + + if debug then + # COVERAGE_IGNORE_BLOCK_START + Display( "matched via new variable with data type" ); + Display( true ); + # COVERAGE_IGNORE_BLOCK_END + fi; + + return true; + + else + + if debug then + # COVERAGE_IGNORE_BLOCK_START + Display( "type could not be inferred or did not match" ); + # COVERAGE_IGNORE_BLOCK_END + fi; + + return false; + fi; - return true; - else + elif IsFilter( filter_or_data_type ) then - if debug then - # COVERAGE_IGNORE_BLOCK_START - Display( "type could not be inferred or did not match" ); - # COVERAGE_IGNORE_BLOCK_END + if IsIdenticalObj( filter_or_data_type, IsObject ) or (IsBound( tree.data_type ) and IsSpecializationOfFilter( filter_or_data_type, tree.data_type.filter )) then + + variables[var_number] := tree; + + if debug then + # COVERAGE_IGNORE_BLOCK_START + Display( "matched via new variable with filter" ); + Display( true ); + # COVERAGE_IGNORE_BLOCK_END + fi; + + return true; + + else + + if debug then + # COVERAGE_IGNORE_BLOCK_START + Display( "type could not be inferred or did not match" ); + # COVERAGE_IGNORE_BLOCK_END + fi; + + return false; + fi; - return false; + else + + # COVERAGE_IGNORE_NEXT_LINE + Error( "this should never happen" ); fi; @@ -699,7 +743,7 @@ InstallGlobalFunction( CAP_JIT_INTERNAL_TREE_MATCHES_TEMPLATE_TREE, function ( t if debug then # COVERAGE_IGNORE_BLOCK_START - Display( "matched via variable2" ); + Display( "matched via existing variable" ); Display( CapJitIsEqualForEnhancedSyntaxTrees( variables[var_number], tree ) ); # COVERAGE_IGNORE_BLOCK_END fi;