From 862d8004d6413ffaea30cc56b04c8ac243574ccd Mon Sep 17 00:00:00 2001 From: Bogdan Voloshin Date: Wed, 23 May 2018 20:06:20 +0300 Subject: [PATCH] Find spot for typeclass template params inferrence and add required params for inference function --- CodeExamples/SimpleTypeclassesImplementation.pas | 2 +- .../convertion_data_and_alghoritms.cs | 2 +- TreeConverter/TreeConversion/syntax_tree_visitor.cs | 4 ++-- TreeConverter/TreeRealization/generics.cs | 13 +++++++++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CodeExamples/SimpleTypeclassesImplementation.pas b/CodeExamples/SimpleTypeclassesImplementation.pas index d52619a93..7a0556eb6 100644 --- a/CodeExamples/SimpleTypeclassesImplementation.pas +++ b/CodeExamples/SimpleTypeclassesImplementation.pas @@ -186,7 +186,7 @@ begin var l1 := Arr(1,3,5,7,8); var l2 := Arr(1,3,5,7,8); - writeln(ArrayEq&[integer](l1, l2)); + writeln(ArrayEq(l1, l2)); end; begin diff --git a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs index 97f374184..734718bbe 100644 --- a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs +++ b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs @@ -1846,7 +1846,7 @@ namespace PascalABCCompiler.TreeConverter { function_node inst = generic_convertions.DeduceFunction(func, parameters, - is_alone_method_defined, loc, syntax_nodes_parameters); + is_alone_method_defined, syntax_tree_visitor.context, loc, syntax_nodes_parameters); if (inst == null) { set_of_possible_functions.remove_at(i); diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index ae90df2fa..6db2e0e9c 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -1384,7 +1384,7 @@ namespace PascalABCCompiler.TreeConverter function_node inst = null; try { - inst = generic_convertions.DeduceFunction(cmfn, parameters, true, loc); + inst = generic_convertions.DeduceFunction(cmfn, parameters, true, context, loc); } catch { @@ -1473,7 +1473,7 @@ namespace PascalABCCompiler.TreeConverter function_node inst = null; try { - inst = generic_convertions.DeduceFunction(cfn, parameters, true, loc); + inst = generic_convertions.DeduceFunction(cfn, parameters, true, context, loc); } catch { diff --git a/TreeConverter/TreeRealization/generics.cs b/TreeConverter/TreeRealization/generics.cs index a2b210935..da81a1bfd 100644 --- a/TreeConverter/TreeRealization/generics.cs +++ b/TreeConverter/TreeRealization/generics.cs @@ -735,7 +735,7 @@ namespace PascalABCCompiler.TreeRealization return result; } - public static function_node DeduceFunction(function_node func, expressions_list fact, bool alone, location loc, List syntax_nodes_parameters = null) + public static function_node DeduceFunction(function_node func, expressions_list fact, bool alone, compilation_context context, location loc, List syntax_nodes_parameters = null) { parameter_list formal = func.parameters; int formal_count = formal.Count; @@ -832,8 +832,11 @@ namespace PascalABCCompiler.TreeRealization } var continue_trying_to_infer_types = true; - Dictionary formal_delegates = null; + Dictionary formal_delegates = null; + var testIsTypeclassRestricted = func.Attributes?.Any(x => x.AttributeType.name == "__TypeclassRestrictedFunctionAttribute"); + var isTypeclassRestricted = testIsTypeclassRestricted.HasValue && testIsTypeclassRestricted.Value; + var typeclasses = func.get_generic_params_list().Where(t => t.Attributes != null && t.Attributes.Any(a => a.AttributeType != null && a.AttributeType.name == "__TypeclassGenericParameter")); while (continue_trying_to_infer_types) //Продолжаем пытаться вычислить типы до тех пор пока состояние о выведенных типах не будет отличаться от состояния на предыдущей итерации { var previous_deduce_state = deduced // Текущее состояние выведенных на данный момент типов. Простой список индексов с уже выведенными типами из массива deduced @@ -916,6 +919,12 @@ namespace PascalABCCompiler.TreeRealization } } } + + if (isTypeclassRestricted) + { + //context.CurrentScope.SymbolTable + } + var current_deduce_state = deduced //текущее состояние выведенных типов .Select((t, ii) => new {Type = t, Index = ii}) .Where(t => t.Type != null)