From 136dda8770034c4858335a45c239aed86602b13e Mon Sep 17 00:00:00 2001 From: Ivan Migalev Date: Sat, 2 Nov 2024 00:47:32 +0100 Subject: [PATCH] (RSRP-499137) ImportLogic: skip special treatment for static struct fields --- src/Refasmer/Importer/ImportLogic.cs | 23 ++++++++++++++--------- tests/Refasmer.Tests/IntegrationTests.cs | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Refasmer/Importer/ImportLogic.cs b/src/Refasmer/Importer/ImportLogic.cs index 1cfdb47..0bc1a57 100644 --- a/src/Refasmer/Importer/ImportLogic.cs +++ b/src/Refasmer/Importer/ImportLogic.cs @@ -41,31 +41,35 @@ private TypeDefinitionHandle ImportTypeDefinitionSkeleton( TypeDefinitionHandle Import(src.BaseType), NextFieldHandle(), NextMethodHandle()); Trace?.Invoke($"Imported {_reader.ToString(src)} -> {RowId(dstHandle):X}"); - + using var _ = WithLogPrefix($"[{_reader.ToString(src)}]"); var isValueType = _reader.GetFullname(src.BaseType) == "System::ValueType"; var forcePreservePrivateFields = isValueType && !Filter.OmitNonApiMembers; - List importedFields = null; - List skippedFields = null; + List importedInstanceFields = null; + List skippedInstanceFields = null; if (forcePreservePrivateFields) Trace?.Invoke($"{_reader.ToString(src)} is ValueType, all fields should be imported"); else { - importedFields = []; - skippedFields = []; + importedInstanceFields = []; + skippedInstanceFields = []; } foreach (var srcFieldHandle in src.GetFields()) { var srcField = _reader.GetFieldDefinition(srcFieldHandle); + var isStatic = (srcField.Attributes & FieldAttributes.Static) != 0; + var isForcedToInclude = forcePreservePrivateFields && !isStatic; - if (!forcePreservePrivateFields && Filter?.AllowImport(srcField, _reader) == false) + if (!isForcedToInclude && Filter?.AllowImport(srcField, _reader) == false) { Trace?.Invoke($"Not imported {_reader.ToString(srcField)}"); - skippedFields?.Add(srcField); + if (!isStatic) + skippedInstanceFields?.Add(srcField); + continue; } @@ -73,11 +77,12 @@ private TypeDefinitionHandle ImportTypeDefinitionSkeleton( TypeDefinitionHandle ImportSignatureWithHeader(srcField.Signature)); _fieldDefinitionCache.Add(srcFieldHandle, dstFieldHandle); Trace?.Invoke($"Imported {_reader.ToString(srcFieldHandle)} -> {RowId(dstFieldHandle):X}"); - importedFields?.Add(srcField); + if (!isStatic) + importedInstanceFields?.Add(srcField); } if (!forcePreservePrivateFields) - PostProcessSkippedValueTypeFields(skippedFields, importedFields); + PostProcessSkippedValueTypeFields(skippedInstanceFields, importedInstanceFields); var implementations = src.GetMethodImplementations() .Select(_reader.GetMethodImplementation) diff --git a/tests/Refasmer.Tests/IntegrationTests.cs b/tests/Refasmer.Tests/IntegrationTests.cs index 022168d..d87c900 100644 --- a/tests/Refasmer.Tests/IntegrationTests.cs +++ b/tests/Refasmer.Tests/IntegrationTests.cs @@ -29,7 +29,8 @@ public async Task CheckRefasmedType(string typeName) [TestCase("RefasmerTestAssembly.BlittableStructWithPrivateFields")] [TestCase("RefasmerTestAssembly.NonBlittableStructWithPrivateFields")] [TestCase("RefasmerTestAssembly.NonBlittableGraph")] - + [TestCase("RefasmerTestAssembly.EmptyStructWithStaticMember")] + [TestCase("RefasmerTestAssembly.NonEmptyStructWithStaticMember")] public async Task CheckRefasmedTypeOmitNonApi(string typeName) { var assemblyPath = await BuildTestAssembly();