From 80384a89ddf4e7b4c8bd5cc267925b50217b17fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 1 Nov 2020 12:33:07 +0100 Subject: [PATCH] bug fix #2335 --- Compiler/PCU/PCUFileFormatVersion.cs | 2 +- Compiler/PCU/PCUReader.cs | 97 ++++++-------- Compiler/PCU/PCUWriter.cs | 118 +++++++++--------- TestSuite/CompilationSamples/BlockFileOfT.pas | 9 ++ TestSuite/CompilationSamples/NumLibABC.pas | 8 ++ TestSuite/CompilationSamples/SF.pas | 11 ++ TestSuite/CompilationSamples/School.pas | 9 ++ TestSuite/units/u_questiondot1.pas | 7 ++ TestSuite/usesunits/use_questiondot1.pas | 7 ++ 9 files changed, 150 insertions(+), 118 deletions(-) create mode 100644 TestSuite/units/u_questiondot1.pas create mode 100644 TestSuite/usesunits/use_questiondot1.pas diff --git a/Compiler/PCU/PCUFileFormatVersion.cs b/Compiler/PCU/PCUFileFormatVersion.cs index 4284790c3..e8fce5107 100644 --- a/Compiler/PCU/PCUFileFormatVersion.cs +++ b/Compiler/PCU/PCUFileFormatVersion.cs @@ -6,6 +6,6 @@ namespace PascalABCCompiler.PCU { public static class PCUFileFormatVersion { - public static System.Int16 Version = 115; + public static System.Int16 Version = 116; } } diff --git a/Compiler/PCU/PCUReader.cs b/Compiler/PCU/PCUReader.cs index 9d5928b60..274ef6c02 100644 --- a/Compiler/PCU/PCUReader.cs +++ b/Compiler/PCU/PCUReader.cs @@ -2107,8 +2107,8 @@ namespace PascalABCCompiler.PCU //} } - private definition_node CreateInterfaceCommonType(string name, int offset) - { + private definition_node CreateInterfaceCommonType(string name, int offset) + { definition_node dn = null; if (members.TryGetValue(offset, out dn)) return dn as common_type_node; @@ -2116,7 +2116,7 @@ namespace PascalABCCompiler.PCU bool is_interface = br.ReadBoolean(); int ind = br.ReadInt32(); - + if (is_interface)//пропускаем флаг - интерфейсности { name = GetString(br.ReadInt32()); @@ -2125,10 +2125,12 @@ namespace PascalABCCompiler.PCU { name = br.ReadString(); } - //br.ReadInt32(); + //br.ReadInt32(); //Читаем, является ли тип интерфейсом bool type_is_interface = (br.ReadByte() == 1); + bool type_is_class = (br.ReadByte() == 1); + //Читаем, является ли тип делегатом bool type_is_delegate = (br.ReadByte() == 1); @@ -2164,35 +2166,28 @@ namespace PascalABCCompiler.PCU ctn.generic_params = type_params; } AddMember(ctn, offset); - - int_members.Insert(0,ctn); + + int_members.Insert(0, ctn); common_type_node saved_ctn = ctn; type_node base_type = GetTypeReference(); bool is_value_type = br.ReadBoolean(); - //Читаем поддерживаемые интерфейсы List interf_implemented = ReadImplementingInterfaces(); - //int interf_count = br.ReadInt32(); - //List interf_implemented = new List(interf_count); - //for (int i = 0; i < interf_count; i++) - //{ - // interf_implemented.Add(GetTypeReference()); - //} - constant_node low_val=null; - constant_node upper_val=null; + constant_node low_val = null; + constant_node upper_val = null; SemanticTree.type_access_level tal = (SemanticTree.type_access_level)br.ReadByte(); SemanticTree.type_special_kind tsk = (SemanticTree.type_special_kind)br.ReadByte(); ctn.SetIsSealed(br.ReadBoolean()); ctn.SetIsAbstract(br.ReadBoolean()); ctn.SetIsStatic(br.ReadBoolean()); ctn.IsPartial = br.ReadBoolean(); - + if (tsk == SemanticTree.type_special_kind.diap_type) { - low_val = CreateExpression() as constant_node; - upper_val = CreateExpression() as constant_node; + low_val = CreateExpression() as constant_node; + upper_val = CreateExpression() as constant_node; } - + if (type_is_interface) { //Добавляем ссылки на области видимости предков интерфейса @@ -2203,12 +2198,10 @@ namespace PascalABCCompiler.PCU } iscope.TopInterfaceScopeArray = interf_scopes.ToArray(); } - //ctn = new wrapped_common_type_node(this, base_type, name, tal, cun.namespaces[0], scope, null, offset); - //AddMember(ctn, offset); - //int_members.Insert(0,ctn); ctn.SetBaseType(base_type); ctn.IsInterface = type_is_interface; ctn.IsDelegate = type_is_delegate; + ctn.is_class = type_is_class; ctn.ImplementingInterfaces.AddRange(interf_implemented); ctn.internal_is_value = is_value_type; ctn.type_special_kind = tsk; @@ -2226,13 +2219,13 @@ namespace PascalABCCompiler.PCU if (CanReadObject()) elemnet_type = GetTypeReference(); ctn.element_type = elemnet_type; - if (ctn.type_special_kind != SemanticTree.type_special_kind.set_type) + if (ctn.type_special_kind != SemanticTree.type_special_kind.set_type) { - SystemLibrary.SystemLibrary.init_reference_type(ctn); + SystemLibrary.SystemLibrary.init_reference_type(ctn); } if (ctn.type_special_kind == SemanticTree.type_special_kind.set_type) { - ctn = compilation_context.AddTypeToSetTypeList(ctn); + ctn = compilation_context.AddTypeToSetTypeList(ctn); if (saved_ctn != ctn) { RemoveMember(offset, saved_ctn); @@ -2242,7 +2235,7 @@ namespace PascalABCCompiler.PCU } if (ctn.type_special_kind == SemanticTree.type_special_kind.typed_file) { - ctn = compilation_context.AddTypeToTypedFileList(ctn); + ctn = compilation_context.AddTypeToTypedFileList(ctn); if (saved_ctn != ctn) { RemoveMember(offset, saved_ctn); @@ -2252,50 +2245,45 @@ namespace PascalABCCompiler.PCU } br.ReadInt32();//comprehensive unit; ctn.attributes.AddRange(GetAttributes()); - //common_namespace_node ns = cun.namespaces[0]; byte flag = br.ReadByte(); - int def_prop_off=0; + int def_prop_off = 0; if (flag == 1) { def_prop_off = br.ReadInt32(); } - location loc= ReadDebugInfo(); + location loc = ReadDebugInfo(); ctn.loc = loc; if (type_is_delegate) { SystemLibrary.SystemLibrary.type_constructor.AddOperatorsToDelegate(ctn, loc); } - - //создаем scope для класса - //ctn = new wrapped_common_type_node(this, base_type, name, tal, ns, scope, loc, offset); - //members[offset] = ctn; - //AddMember(ctn, offset); + class_names[ctn] = AddClassMemberNames(scope); - if (flag == 1) ctn.default_property = GetPropertyNode(def_prop_off); + if (flag == 1) ctn.default_property = GetPropertyNode(def_prop_off); //ivan - if (ctn.IsEnum) + if (ctn.IsEnum) { - AddEnumOperators(ctn); - MakeTypeAsOrdinal(ctn,0,class_names.Count); - ctn.add_additional_enum_operations(); + AddEnumOperators(ctn); + MakeTypeAsOrdinal(ctn, 0, class_names.Count); + ctn.add_additional_enum_operations(); } if (ctn.type_special_kind == SemanticTree.type_special_kind.diap_type) { - type_constructor.add_convertions_to_diap(ctn,low_val,upper_val); + type_constructor.add_convertions_to_diap(ctn, low_val, upper_val); } if (ctn.type_special_kind == SemanticTree.type_special_kind.array_kind) { - if (!(ctn.element_type is compiled_type_node)) - { - type_constructor.make_array_interface(ctn); - } + if (!(ctn.element_type is compiled_type_node)) + { + type_constructor.make_array_interface(ctn); + } } if (ctn.is_value_type) { } //RestoreAllFields(ctn); - if(!waited_types_to_restore_fields.Contains(ctn)) + if (!waited_types_to_restore_fields.Contains(ctn)) waited_types_to_restore_fields.Add(ctn); if (type_is_delegate) @@ -2308,19 +2296,14 @@ namespace PascalABCCompiler.PCU dii.parameters.AddRange(invoke_method.parameters); ctn.add_internal_interface(dii); } - - /*if (ctn.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.array_wrapper) - { - bounded_array_interface bai = new bounded_array_interface(oti_indexer, ctn.element_type, cpn, oti_indexer.lower_value.type, int_arr); - ctn.add_internal_interface(bai); - }*/ + if (type_is_interface) { RestoreAllFields(ctn); } if (ctn.is_value) { - RestoreAllFields(ctn); + RestoreAllFields(ctn); } if (ctn.is_generic_type_definition) { @@ -2333,13 +2316,9 @@ namespace PascalABCCompiler.PCU } } } - /*if (ctn.type_special_kind == SemanticTree.type_special_kind.array_wrapper) - { - RestoreAllFields(ctn); - }*/ - - return ctn; - } + + return ctn; + } private void MakeTypeAsOrdinal(common_type_node ctn, int low_val, int upper_val) { diff --git a/Compiler/PCU/PCUWriter.cs b/Compiler/PCU/PCUWriter.cs index d0a3353d0..2a0289ed3 100644 --- a/Compiler/PCU/PCUWriter.cs +++ b/Compiler/PCU/PCUWriter.cs @@ -2496,23 +2496,19 @@ namespace PascalABCCompiler.PCU return sizeof(byte) + sizeof(int); } - private void VisitTypeDefinition(common_type_node type) - { + private void VisitTypeDefinition(common_type_node type) + { int offset = 0; if (is_interface == true) offset = SavePositionAndConstPool(type); - else offset = SavePositionAndImplementationPool(type); - bw.Write((byte)type.semantic_node_type); - bw.Write(is_interface); + else offset = SavePositionAndImplementationPool(type); + bw.Write((byte)type.semantic_node_type); + bw.Write(is_interface); bw.Write(type_entity_index++); - if (is_interface == true) - bw.Write(GetNameIndex(type)); - else - bw.Write(type.name); - /*if (type.base_type != null) - WriteTypeReference(type.base_type); - else*/ + if (is_interface == true) + bw.Write(GetNameIndex(type)); + else + bw.Write(type.name); - //Пишем, является ли данный класс интерфейсом if (type.IsInterface) { bw.Write((byte)1); @@ -2522,7 +2518,15 @@ namespace PascalABCCompiler.PCU bw.Write((byte)0); } - //Пишем, является ли данный класс делегатом + if (type.is_class) + { + bw.Write((byte)1); + } + else + { + bw.Write((byte)0); + } + if (type.IsDelegate) { bw.Write((byte)1); @@ -2531,7 +2535,7 @@ namespace PascalABCCompiler.PCU { bw.Write((byte)0); } - + //Является ли тип описанием дженерика if (type.is_generic_type_definition) { @@ -2552,10 +2556,7 @@ namespace PascalABCCompiler.PCU int base_class_off = (int)bw.BaseStream.Position; bw.Seek(GetSizeOfReference(type.base_type), SeekOrigin.Current); - - //(ssyy) На кой чёрт это надо? - //WriteTypeReference(SystemLibrary.SystemLibrary.object_type); - //WriteTypeReference(type.base_type); + bw.Write(type.internal_is_value); //Пишем поддерживаемые интерфейсы @@ -2563,8 +2564,8 @@ namespace PascalABCCompiler.PCU //WriteImplementingInterfaces(type); int interface_impl_off = (int)bw.BaseStream.Position; int seek_off = sizeof(int); - for (int k=0; k(a: array of T; transform: T->T) := a.Transform(transform); function H(Self: array of T): integer; extensionmethod := Self.High; +///-- +procedure __InitModule__; +begin +end; + +///-- +procedure __FinalizeModule__; +begin +end; + + end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/School.pas b/TestSuite/CompilationSamples/School.pas index 52cec2eef..ccc3f9857 100644 --- a/TestSuite/CompilationSamples/School.pas +++ b/TestSuite/CompilationSamples/School.pas @@ -755,4 +755,13 @@ end; {$endregion} +///-- +procedure __InitModule__; +begin +end; + +///-- +procedure __FinalizeModule__; +begin +end; end. \ No newline at end of file diff --git a/TestSuite/units/u_questiondot1.pas b/TestSuite/units/u_questiondot1.pas new file mode 100644 index 000000000..c426d8406 --- /dev/null +++ b/TestSuite/units/u_questiondot1.pas @@ -0,0 +1,7 @@ +unit u_questiondot1; + +type + t1 = class end; + + +end. \ No newline at end of file diff --git a/TestSuite/usesunits/use_questiondot1.pas b/TestSuite/usesunits/use_questiondot1.pas new file mode 100644 index 000000000..366799b26 --- /dev/null +++ b/TestSuite/usesunits/use_questiondot1.pas @@ -0,0 +1,7 @@ +uses u_questiondot1; + +begin + var a: t1 := nil; + var s := a?.ToString; + assert(string.IsNullOrEmpty(s)); +end. \ No newline at end of file