Skip to content

Commit

Permalink
Allow to specify full data types in for variables in logic templates
Browse files Browse the repository at this point in the history
  • Loading branch information
zickgraf committed Dec 6, 2023
1 parent 28cd22a commit 1a3fca2
Showing 1 changed file with 69 additions and 25 deletions.
94 changes: 69 additions & 25 deletions CompilerForCAP/gap/LogicTemplates.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -668,38 +675,75 @@ 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

Check warning on line 682 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L682

Added line #L682 was not covered by tests

variables[var_number] := tree;

Check warning on line 684 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L684

Added line #L684 was not covered by tests

if debug then

Check warning on line 686 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L686

Added line #L686 was not covered by tests
# COVERAGE_IGNORE_BLOCK_START
Display( "matched via new variable with data type" );
Display( true );
# COVERAGE_IGNORE_BLOCK_END
fi;

Check warning on line 691 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L691

Added line #L691 was not covered by tests

return true;

Check warning on line 693 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L693

Added line #L693 was not covered by tests

else

Check warning on line 695 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L695

Added line #L695 was not covered by tests

if debug then

Check warning on line 697 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L697

Added line #L697 was not covered by tests
# COVERAGE_IGNORE_BLOCK_START
Display( "type could not be inferred or did not match" );
# COVERAGE_IGNORE_BLOCK_END
fi;

Check warning on line 701 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L701

Added line #L701 was not covered by tests

return false;

Check warning on line 703 in CompilerForCAP/gap/LogicTemplates.gi

View check run for this annotation

Codecov / codecov/patch

CompilerForCAP/gap/LogicTemplates.gi#L703

Added line #L703 was not covered by tests

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;

else

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;
Expand Down

0 comments on commit 1a3fca2

Please sign in to comment.