From 13b4fd3d5bd4f992b39c491fda241fd9cc6b10d2 Mon Sep 17 00:00:00 2001 From: samuraiGH <87191377+samuraiGH@users.noreply.github.com> Date: Sun, 19 Oct 2025 19:32:27 +0300 Subject: [PATCH] small refactoring (#3349) --- NETGenerator/NETGenerator.cs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 1f7e11e67..f572b3b7b 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -184,13 +184,9 @@ namespace PascalABCCompiler.NETGenerator private bool has_dereferences = false; private bool safe_block = false; private int cur_line = 0; - private bool tried_with_unmanaged_resources = false; private ISymbolDocumentWriter new_doc; - 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) { @@ -1371,8 +1367,7 @@ namespace PascalABCCompiler.NETGenerator FieldBuilder fb = cur_type.DefineField(name, helper.GetTypeReference(type).tp, FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.Literal); Type t = helper.GetTypeReference(type).tp; - // Для инстанцированных generic типов вызов .IsEnum приводит к исключению - if (!t.IsConstructedGenericType() && t.IsEnum) + if (TypeIsEnum(t)) { if (!(t is EnumBuilder)) fb.SetConstant(Enum.ToObject(t, (constant_value as IEnumConstNode).constant_value)); @@ -4714,9 +4709,8 @@ namespace PascalABCCompiler.NETGenerator il.Emit(OpCodes.Ldloc, lb); TypeInfo ti = helper.GetTypeReference(ElementValues[i].type); PushIntConst(il, i); - if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && - (ti.tp.IsConstructedGenericType() || !ti.tp.IsEnum)) // инстанцированные генерик типы бросают исключение при вызове .IsEnum - il.Emit(OpCodes.Ldelema, ti.tp); + if (ti != null && ti.tp.IsValueType && !TypeFactory.IsStandType(ti.tp) && !TypeIsEnum(ti.tp)) + il.Emit(OpCodes.Ldelema, ti.tp); ILGenerator ilb = this.il; this.il = il; ElementValues[i].visit(this); @@ -8265,6 +8259,9 @@ namespace PascalABCCompiler.NETGenerator il.Emit(OpCodes.Stsfld, fb); } + /// + /// Необходимо, тк в особых случаях прямой вызов .IsEnum приводит к исключению + /// private bool TypeIsEnum(Type T) { if (T.IsGenericType || T.IsGenericTypeDefinition || T.IsGenericParameter) @@ -11005,7 +11002,7 @@ namespace PascalABCCompiler.NETGenerator end_label = if_stack.Pop(); in_if = true; } - System.Collections.Generic.Dictionary dict; + Dictionary dict; TmpForLabel[] case_labels = GetCaseSelectors(value, jump_def_label, out dict); value.case_expression.visit(this); LocalBuilder lb = null; @@ -11244,7 +11241,7 @@ namespace PascalABCCompiler.NETGenerator } //перевод селекторов case - public void ConvertCaseVariantNode(ICaseVariantNode value, Label end_label, System.Collections.Generic.Dictionary dict) + public void ConvertCaseVariantNode(ICaseVariantNode value, Label end_label, Dictionary dict) { if (save_debug_info) { @@ -11260,11 +11257,11 @@ namespace PascalABCCompiler.NETGenerator } //сбор информации о селекторах (сортировка, группировка и т. д.) - private TmpForLabel[] GetCaseSelectors(ISwitchNode value, Label default_label, out System.Collections.Generic.Dictionary dict) + private TmpForLabel[] GetCaseSelectors(ISwitchNode value, Label default_label, out Dictionary dict) { - System.Collections.Generic.SortedDictionary sel_list = new System.Collections.Generic.SortedDictionary(); - System.Collections.Generic.Dictionary sel_range = new System.Collections.Generic.Dictionary(); - dict = new System.Collections.Generic.Dictionary(); + SortedDictionary sel_list = new SortedDictionary(); + Dictionary sel_range = new Dictionary(); + dict = new Dictionary(); //sobiraem informaciju o konstantah v case for (int i = 0; i < value.case_variants.Length; i++) {