From aae9ab408bb1b59d591cc6f866a3757be895ecd9 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Thu, 31 Oct 2024 18:25:06 +0100 Subject: [PATCH 1/3] #3221 --- NETGenerator/NETGenerator.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index bce94f33b..be7c3d07c 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -192,6 +192,7 @@ public class ILConverter : AbstractVisitor private List pinned_variables = new List(); private bool pabc_rtl_converted = false; bool has_unmanaged_resources = false; + private Dictionary non_local_variables = new Dictionary(); private void CheckLocation(SemanticTree.ILocation Location) { @@ -980,6 +981,7 @@ public void ConvertFromTree(SemanticTree.IProgramNode p, string TargetFileName, cur_unit_type = NamespacesTypes[cnns[iii]]; ConvertFunctionHeaders(cnns[iii].functions); } + if (p.InitializationCode != null) { tmp_il = il; @@ -998,8 +1000,11 @@ public void ConvertFromTree(SemanticTree.IProgramNode p, string TargetFileName, { ConvertGenericFunctionInstance(igfi); } + foreach (var item in non_local_variables) + { + ConvertNonLocalVariables(item.Key.var_definition_nodes, item.Value); + } - ConstructorBuilder unit_cci = null; @@ -3019,11 +3024,12 @@ private void ConvertFunctionHeader(ICommonFunctionNode func) funcs.Add(func); //здесь наверное дублирование MethodBuilder tmp = cur_meth; cur_meth = methb; - + //если функция не содержит вложенных процедур, то //переводим переменные как локальные if (func.functions_nodes.Length > 0) - ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); + non_local_variables[func] = frm.mb; + //ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); //переводим заголовки вложенных функций ConvertNestedFunctionHeaders(func.functions_nodes); //переводим тела вложенных функций @@ -7003,7 +7009,8 @@ private void ConvertNestedInMethodFunctionHeader(ICommonNestedInFunctionFunction MethodBuilder tmp = cur_meth; cur_meth = methb; //переводим переменные как нелокальные - ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); + non_local_variables[func] = frm.mb; + //ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); //переводим описания вложенных процедур ConvertNestedInMethodFunctionHeaders(func.functions_nodes, decl_type); foreach (ICommonNestedInFunctionFunctionNode f in func.functions_nodes) From 350d07326d149b02ea27e1d9877ac02d8c3d592c Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Thu, 31 Oct 2024 18:35:51 +0100 Subject: [PATCH 2/3] #3221 --- NETGenerator/NETGenerator.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index be7c3d07c..9524e4c94 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -192,7 +192,7 @@ public class ILConverter : AbstractVisitor private List pinned_variables = new List(); private bool pabc_rtl_converted = false; bool has_unmanaged_resources = false; - private Dictionary non_local_variables = new Dictionary(); + private Dictionary> non_local_variables = new Dictionary>(); private void CheckLocation(SemanticTree.ILocation Location) { @@ -1002,7 +1002,10 @@ public void ConvertFromTree(SemanticTree.IProgramNode p, string TargetFileName, } foreach (var item in non_local_variables) { - ConvertNonLocalVariables(item.Key.var_definition_nodes, item.Value); + tmp_il = il; + il = item.Value.Item2; + ConvertNonLocalVariables(item.Key.var_definition_nodes, item.Value.Item1); + il = tmp_il; } @@ -3028,7 +3031,7 @@ private void ConvertFunctionHeader(ICommonFunctionNode func) //если функция не содержит вложенных процедур, то //переводим переменные как локальные if (func.functions_nodes.Length > 0) - non_local_variables[func] = frm.mb; + non_local_variables[func] = new Tuple(frm.mb, il); //ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); //переводим заголовки вложенных функций ConvertNestedFunctionHeaders(func.functions_nodes); @@ -7009,7 +7012,7 @@ private void ConvertNestedInMethodFunctionHeader(ICommonNestedInFunctionFunction MethodBuilder tmp = cur_meth; cur_meth = methb; //переводим переменные как нелокальные - non_local_variables[func] = frm.mb; + non_local_variables[func] = new Tuple(frm.mb, il); //ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); //переводим описания вложенных процедур ConvertNestedInMethodFunctionHeaders(func.functions_nodes, decl_type); From 746c4ae2c26ae9aa1eeca2a09568a94953b25a33 Mon Sep 17 00:00:00 2001 From: Ivan Bondarev Date: Thu, 31 Oct 2024 21:00:42 +0100 Subject: [PATCH 3/3] #3221 --- NETGenerator/NETGenerator.cs | 49 +++++++++++++------ .../CompilationSamples/PABCExtensions.pas | 3 +- TestSuite/CompilationSamples/XLSX.pas | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 9524e4c94..bb0362e85 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -192,7 +192,8 @@ public class ILConverter : AbstractVisitor private List pinned_variables = new List(); private bool pabc_rtl_converted = false; bool has_unmanaged_resources = false; - private Dictionary> non_local_variables = new Dictionary>(); + private Dictionary>> non_local_variables = + new Dictionary>>(); private void CheckLocation(SemanticTree.ILocation Location) { @@ -979,9 +980,23 @@ public void ConvertFromTree(SemanticTree.IProgramNode p, string TargetFileName, if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name]; cur_type = NamespacesTypes[cnns[iii]]; cur_unit_type = NamespacesTypes[cnns[iii]]; - ConvertFunctionHeaders(cnns[iii].functions); + ConvertFunctionHeaders(cnns[iii].functions, false); } - + + //Переводим псевдоинстанции функций + foreach (IGenericFunctionInstance igfi in p.generic_function_instances) + { + ConvertGenericFunctionInstance(igfi); + } + + for (int iii = 0; iii < cnns.Length; iii++) + { + if (save_debug_info) doc = sym_docs[cnns[iii].Location == null ? SourceFileName : cnns[iii].Location.document.file_name]; + cur_type = NamespacesTypes[cnns[iii]]; + cur_unit_type = NamespacesTypes[cnns[iii]]; + ConvertFunctionHeaders(cnns[iii].functions, true); + } + if (p.InitializationCode != null) { tmp_il = il; @@ -995,18 +1010,14 @@ public void ConvertFromTree(SemanticTree.IProgramNode p, string TargetFileName, - //Переводим псевдоинстанции функций - foreach (IGenericFunctionInstance igfi in p.generic_function_instances) - { - ConvertGenericFunctionInstance(igfi); - } - foreach (var item in non_local_variables) + + /*foreach (var item in non_local_variables) { tmp_il = il; - il = item.Value.Item2; + il = item.Value.Item2.GetILGenerator(); ConvertNonLocalVariables(item.Key.var_definition_nodes, item.Value.Item1); il = tmp_il; - } + }*/ ConstructorBuilder unit_cci = null; @@ -2667,10 +2678,14 @@ private void ConvertTypeHeader(ICommonTypeNode value) } //перевод заголовков функций - private void ConvertFunctionHeaders(ICommonNamespaceFunctionNode[] funcs) + private void ConvertFunctionHeaders(ICommonNamespaceFunctionNode[] funcs, bool with_nested) { for (int i = 0; i < funcs.Length; i++) { + if (!with_nested && funcs[i].functions_nodes != null && funcs[i].functions_nodes.Length > 0) + continue; + if (with_nested && (funcs[i].functions_nodes == null || funcs[i].functions_nodes.Length == 0)) + continue; IStatementsListNode sl = (IStatementsListNode)funcs[i].function_code; IStatementNode[] statements = sl.statements; if (statements.Length > 0 && statements[0] is IExternalStatementNode) @@ -2736,6 +2751,7 @@ private void ConvertFunctionHeaders(ICommonNamespaceFunctionNode[] funcs) ConvertFunctionHeader(funcs[i]); } //(ssyy) 21.05.2008 + if (!with_nested) foreach (ICommonNamespaceFunctionNode ifn in funcs) { if (ifn.is_generic_function) @@ -3030,9 +3046,10 @@ private void ConvertFunctionHeader(ICommonFunctionNode func) //если функция не содержит вложенных процедур, то //переводим переменные как локальные + //if (func.functions_nodes.Length > 0) + // non_local_variables[func] = new Tuple>(frm.mb, methb, new List(funcs)); if (func.functions_nodes.Length > 0) - non_local_variables[func] = new Tuple(frm.mb, il); - //ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); + ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); //переводим заголовки вложенных функций ConvertNestedFunctionHeaders(func.functions_nodes); //переводим тела вложенных функций @@ -7012,8 +7029,8 @@ private void ConvertNestedInMethodFunctionHeader(ICommonNestedInFunctionFunction MethodBuilder tmp = cur_meth; cur_meth = methb; //переводим переменные как нелокальные - non_local_variables[func] = new Tuple(frm.mb, il); - //ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); + //non_local_variables[func] = new Tuple>(frm.mb, methb, new List(funcs)); + ConvertNonLocalVariables(func.var_definition_nodes, frm.mb); //переводим описания вложенных процедур ConvertNestedInMethodFunctionHeaders(func.functions_nodes, decl_type); foreach (ICommonNestedInFunctionFunctionNode f in func.functions_nodes) diff --git a/TestSuite/CompilationSamples/PABCExtensions.pas b/TestSuite/CompilationSamples/PABCExtensions.pas index 0a5fd23c9..8c566bcaf 100644 --- a/TestSuite/CompilationSamples/PABCExtensions.pas +++ b/TestSuite/CompilationSamples/PABCExtensions.pas @@ -411,7 +411,7 @@ function SSet(s: set of T): SortedSet; ///-- function operator implicit(a: array of integer): set of integer; extensionmethod := TypedSet.InitBy(a); -///-- +{///-- function operator implicit(a: array of real): set of real; extensionmethod := TypedSet.InitBy(a); ///-- function operator implicit(a: array of string): set of string; extensionmethod := TypedSet.InitBy(a); @@ -433,6 +433,7 @@ function operator implicit(a: array of BigInteger): set of BigInteger; extension function operator implicit(a: array of decimal): set of decimal; extensionmethod := TypedSet.InitBy(a); ///-- function operator implicit(a: array of single): set of single; extensionmethod := TypedSet.InitBy(a); +} ///-- function operator implicit(a: array of T): set of T; extensionmethod := TypedSet.InitBy(a); diff --git a/TestSuite/CompilationSamples/XLSX.pas b/TestSuite/CompilationSamples/XLSX.pas index 6459da698..25e93d4a0 100644 --- a/TestSuite/CompilationSamples/XLSX.pas +++ b/TestSuite/CompilationSamples/XLSX.pas @@ -50,7 +50,7 @@ implementation {$reference System.Xml.dll} uses System.IO.Compression; -uses System.Xml,sf; +uses System.Xml,SF; var numFmt, numBrd: List;