diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleAssemblyCodeDuplicatedStructure.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleAssemblyCodeDuplicatedStructure.verified.txt index ad929c4..0e7c9c8 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleAssemblyCodeDuplicatedStructure.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleAssemblyCodeDuplicatedStructure.verified.txt @@ -44,9 +44,9 @@ { // Code size 17 (0x11) .maxstack 1 - .locals (valuetype [combinetestbed]C.type.Foo V_0) + .locals (valuetype C.type.Foo V_0) IL_0000: ldloca V_0 - IL_0004: initobj [combinetestbed]C.type.Foo + IL_0004: initobj C.type.Foo IL_000a: ldloc.0 IL_000b: call int64 [combinetestbed]C.text::foo_calc(valuetype [combinetestbed]C.type.Foo) IL_0010: ret diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate.verified.txt index f96e56a..0907467 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate.verified.txt @@ -33,20 +33,6 @@ .field public static literal int32 pork } // end of class C.type.foo -.class private abstract auto ansi sealed beforefieldinit '$' - extends [mscorlib]System.Object -{ - .class auto ansi sealed nested public foo - extends [mscorlib]System.Enum - { - .field public specialname rtspecialname int32 value__ - .field public static literal int32 beef - .field public static literal int32 pork - .field public static literal int32 chicken - } // end of class foo - -} // end of class '$' - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -62,6 +48,20 @@ } // end of class C.text +.class private abstract auto ansi sealed beforefieldinit '$' + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested public foo + extends [mscorlib]System.Enum + { + .field public specialname rtspecialname int32 value__ + .field public static literal int32 beef + .field public static literal int32 pork + .field public static literal int32 chicken + } // end of class foo + +} // end of class '$' + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate2.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate2.verified.txt index 5fb8bd0..88bd988 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate2.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate2.verified.txt @@ -38,15 +38,6 @@ } // end of class '$' -.class public auto ansi sealed C.type.foo - extends [mscorlib]System.Enum -{ - .field public specialname rtspecialname int32 value__ - .field public static literal int32 beef - .field public static literal int32 pork - .field public static literal int32 chicken -} // end of class C.type.foo - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -62,6 +53,15 @@ } // end of class C.text +.class public auto ansi sealed C.type.foo + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal int32 beef + .field public static literal int32 pork + .field public static literal int32 chicken +} // end of class C.type.foo + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate3.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate3.verified.txt index c5bb533..d484135 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate3.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedEnumrerate3.verified.txt @@ -38,6 +38,19 @@ } // end of class '$' +.class public abstract auto ansi sealed C.text + extends [mscorlib]System.Object +{ + .method public static int32 main() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } // end of method text::main + +} // end of class C.text + .class private abstract auto ansi sealed beforefieldinit '$' extends [mscorlib]System.Object { @@ -52,19 +65,6 @@ } // end of class '$' -.class public abstract auto ansi sealed C.text - extends [mscorlib]System.Object -{ - .method public static int32 main() cil managed - { - // Code size 2 (0x2) - .maxstack 8 - IL_0000: ldc.i4.0 - IL_0001: ret - } // end of method text::main - -} // end of class C.text - // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions1.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions1.verified.txt index 024c3af..6555296 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions1.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions1.verified.txt @@ -25,19 +25,6 @@ // =============== CLASS MEMBERS DECLARATION =================== -.class private abstract auto ansi sealed beforefieldinit '$' - extends [mscorlib]System.Object -{ - .method public static int32 foo(int32 A_0) cil managed - { - // Code size 2 (0x2) - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } // end of method '$'::foo - -} // end of class '$' - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -60,6 +47,19 @@ } // end of class C.text +.class private abstract auto ansi sealed beforefieldinit '$' + extends [mscorlib]System.Object +{ + .method public static int32 foo(int32 A_0) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } // end of method '$'::foo + +} // end of class '$' + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions2.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions2.verified.txt index d2007ca..27ef21b 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions2.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions2.verified.txt @@ -25,19 +25,6 @@ // =============== CLASS MEMBERS DECLARATION =================== -.class private abstract auto ansi sealed beforefieldinit '$' - extends [mscorlib]System.Object -{ - .method public static int32 foo(int32 A_0) cil managed - { - // Code size 2 (0x2) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ret - } // end of method '$'::foo - -} // end of class '$' - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -46,7 +33,7 @@ // Code size 7 (0x7) .maxstack 8 IL_0000: ldc.i4.1 - IL_0001: call int32 C.text::foo(int32) + IL_0001: call int32 '$'::foo(int32) IL_0006: ret } // end of method text::main @@ -60,6 +47,19 @@ } // end of class C.text +.class private abstract auto ansi sealed beforefieldinit '$' + extends [mscorlib]System.Object +{ + .method public static int32 foo(int32 A_0) cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } // end of method '$'::foo + +} // end of class '$' + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions3.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions3.verified.txt index bff8a92..0741847 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions3.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedFunctions3.verified.txt @@ -25,6 +25,19 @@ // =============== CLASS MEMBERS DECLARATION =================== +.class public abstract auto ansi sealed C.text + extends [mscorlib]System.Object +{ + .method public static int32 main() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } // end of method text::main + +} // end of class C.text + .class private abstract auto ansi sealed beforefieldinit '$' extends [mscorlib]System.Object { @@ -51,19 +64,6 @@ } // end of class '$' -.class public abstract auto ansi sealed C.text - extends [mscorlib]System.Object -{ - .method public static int32 main() cil managed - { - // Code size 2 (0x2) - .maxstack 8 - IL_0000: ldc.i4.1 - IL_0001: ret - } // end of method text::main - -} // end of class C.text - // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure.verified.txt index 4b6036a..82f01e5 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure.verified.txt @@ -32,19 +32,6 @@ .field public int32 v1 } // end of class C.type.foo -.class private abstract auto ansi sealed beforefieldinit '$' - extends [mscorlib]System.Object -{ - .class sequential ansi sealed nested public foo - extends [mscorlib]System.ValueType - { - .field public int32 v0 - .field public int32 v1 - .field public int32 v2 - } // end of class foo - -} // end of class '$' - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -60,6 +47,19 @@ } // end of class C.text +.class private abstract auto ansi sealed beforefieldinit '$' + extends [mscorlib]System.Object +{ + .class sequential ansi sealed nested public foo + extends [mscorlib]System.ValueType + { + .field public int32 v0 + .field public int32 v1 + .field public int32 v2 + } // end of class foo + +} // end of class '$' + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure2.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure2.verified.txt index de29dde..5b5d8b0 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure2.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure2.verified.txt @@ -37,14 +37,6 @@ } // end of class '$' -.class public sequential ansi sealed C.type.foo - extends [mscorlib]System.ValueType -{ - .field public int32 v0 - .field public int32 v1 - .field public int32 v2 -} // end of class C.type.foo - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -60,6 +52,14 @@ } // end of class C.text +.class public sequential ansi sealed C.type.foo + extends [mscorlib]System.ValueType +{ + .field public int32 v0 + .field public int32 v1 + .field public int32 v2 +} // end of class C.type.foo + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure3.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure3.verified.txt index 4791d20..04ef717 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure3.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeDuplicatedStructure3.verified.txt @@ -37,19 +37,6 @@ } // end of class '$' -.class private abstract auto ansi sealed beforefieldinit '$' - extends [mscorlib]System.Object -{ - .class sequential ansi sealed nested public foo - extends [mscorlib]System.ValueType - { - .field public int32 v0 - .field public int32 v1 - .field public int32 v2 - } // end of class foo - -} // end of class '$' - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -63,6 +50,19 @@ } // end of class C.text +.class private abstract auto ansi sealed beforefieldinit '$' + extends [mscorlib]System.Object +{ + .class sequential ansi sealed nested public foo + extends [mscorlib]System.ValueType + { + .field public int32 v0 + .field public int32 v1 + .field public int32 v2 + } // end of class foo + +} // end of class '$' + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForEnumrerate.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForEnumrerate.verified.txt index c7c17c5..261db26 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForEnumrerate.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForEnumrerate.verified.txt @@ -33,14 +33,6 @@ .field public static literal int32 pork } // end of class C.type.foo -.class public auto ansi sealed C.type.bar - extends [mscorlib]System.Enum -{ - .field public specialname rtspecialname int32 value__ - .field public static literal int32 beef - .field public static literal int32 pork -} // end of class C.type.bar - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -56,6 +48,14 @@ } // end of class C.text +.class public auto ansi sealed C.type.bar + extends [mscorlib]System.Enum +{ + .field public specialname rtspecialname int32 value__ + .field public static literal int32 beef + .field public static literal int32 pork +} // end of class C.type.bar + // ============================================================= diff --git a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForStructure.verified.txt b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForStructure.verified.txt index e80785f..759bf8e 100644 --- a/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForStructure.verified.txt +++ b/chibild/chibild.core.Tests/LinkerTests.CombinedMultipleSourceCodeForStructure.verified.txt @@ -32,13 +32,6 @@ .field public int32 v1 } // end of class C.type.foo -.class public sequential ansi sealed C.type.bar - extends [mscorlib]System.ValueType -{ - .field public int32 v0 - .field public int32 v1 -} // end of class C.type.bar - .class public abstract auto ansi sealed C.text extends [mscorlib]System.Object { @@ -54,6 +47,13 @@ } // end of class C.text +.class public sequential ansi sealed C.type.bar + extends [mscorlib]System.ValueType +{ + .field public int32 v0 + .field public int32 v1 +} // end of class C.type.bar + // ============================================================= diff --git a/chibild/chibild.core/Generating/AssemblyInputFragment.cs b/chibild/chibild.core/Generating/AssemblyInputFragment.cs index 2fb8556..b0f0c04 100644 --- a/chibild/chibild.core/Generating/AssemblyInputFragment.cs +++ b/chibild/chibild.core/Generating/AssemblyInputFragment.cs @@ -283,7 +283,7 @@ static IEnumerable IterateTypesDescendants(TypeDefinition type) } } - var types = assembly.Modules. + var targetTypes = assembly.Modules. SelectMany(module => module.Types). Where(type => type.IsPublic && @@ -291,9 +291,17 @@ static IEnumerable IterateTypesDescendants(TypeDefinition type) // Excepts all generic types because CABI does not support it. !type.HasGenericParameters). SelectMany(IterateTypesDescendants). - ToDictionary(TypeGenerator.GetCilTypeName); + ToArray(); + + var types = targetTypes. + // Combine both CABI types and .NET types. + Where(type => type.Namespace is "C.type"). + Select(type => (name: type.Name, type)). + Concat(targetTypes. + Select(type => (name: type.FullName, type))). + ToDictionary(entry => entry.name, entry => entry.type); - var targetFields = types.Values. + var targetFields = targetTypes. Where(type => type is { IsPublic: true, IsClass: true, @@ -316,7 +324,7 @@ static IEnumerable IterateTypesDescendants(TypeDefinition type) Select(field => (name: $"{field.DeclaringType.FullName}.{field.Name}", field))). ToDictionary(entry => entry.name, entry => entry.field); - var targetMethods = types.Values. + var targetMethods = targetTypes. Where(type => type is { IsPublic: true, IsClass: true, diff --git a/chibild/chibild.core/Generating/CodeGenerator_Consumer.cs b/chibild/chibild.core/Generating/CodeGenerator_Consumer.cs index 518d886..4e63dd0 100644 --- a/chibild/chibild.core/Generating/CodeGenerator_Consumer.cs +++ b/chibild/chibild.core/Generating/CodeGenerator_Consumer.cs @@ -783,16 +783,13 @@ private void ConsumeEnumeration( LookupContext context, EnumerationNode enumeration) { - // Check public type already declared another fragment. + // Check public type already declared in another fragment. var r = TypeParser.TryParse(enumeration.Name.Token, out var type); Debug.Assert(r); - if (this.ContainsTypeAndSchedule( + if (this.ContainsPriorityTypeDeclaration( context, type, - out var declaredFragment, - out var scope) && - scope == Scopes.Public && - declaredFragment != context.CurrentFragment && - declaredFragment is not ObjectInputFragment) // Will combine into one assembly. + out var declaredFragment) && + declaredFragment != context.CurrentFragment) { this.OutputTrace( enumeration.Name.Token, @@ -879,17 +876,14 @@ private void ConsumeStructure( LookupContext context, StructureNode structure) { - // Check public type already declared another fragment. + // Check public type already declared in another fragment. var r = TypeParser.TryParse(structure.Name.Token, out var type); Debug.Assert(r); - if (this.ContainsTypeAndSchedule( + if (this.ContainsPriorityTypeDeclaration( context, type, - out var declaredFragment, - out var scope) && - scope == Scopes.Public && - declaredFragment != context.CurrentFragment && - declaredFragment is not ObjectInputFragment) // Will combine into one assembly. + out var declaredFragment) && + declaredFragment != context.CurrentFragment) { this.OutputTrace( structure.Name.Token, diff --git a/chibild/chibild.core/Generating/CodeGenerator_LookupMember.cs b/chibild/chibild.core/Generating/CodeGenerator_LookupMember.cs index a917f6d..6b18665 100644 --- a/chibild/chibild.core/Generating/CodeGenerator_LookupMember.cs +++ b/chibild/chibild.core/Generating/CodeGenerator_LookupMember.cs @@ -38,22 +38,25 @@ private void DelayLookingUpAction2(Action action) ////////////////////////////////////////////////////////////// - private bool ContainsTypeAndSchedule( + private bool ContainsPriorityTypeDeclaration( LookupContext context, TypeNode type, - out InputFragment declaredFragment, - out Scopes scope) + out InputFragment declaredFragment) { - if (context.CurrentFragment?.ContainsTypeAndSchedule(type, out scope) ?? false) + // Step 1: Check on current fragment (file scoped). + if ((context.CurrentFragment?. + ContainsTypeAndSchedule(type, out var scope) ?? false) && + scope == Scopes.File) { declaredFragment = context.CurrentFragment; return true; } + // Step 2: Check on entire fragments. foreach (var fragment in context.InputFragments) { - if (fragment != context.CurrentFragment && - fragment.ContainsTypeAndSchedule(type, out scope)) + if (fragment.ContainsTypeAndSchedule(type, out scope) && + scope is Scopes.Public or Scopes.Internal) // Internal only in another object. { declaredFragment = fragment; return true; @@ -61,7 +64,6 @@ private bool ContainsTypeAndSchedule( } declaredFragment = null!; - scope = default; return false; } @@ -73,9 +75,10 @@ private bool InternalDelayLookingUpType( bool isFileScoped, Action action) { - // Step 1: Check on current fragment. - if (context.CurrentFragment?. - ContainsTypeAndSchedule(type, out _) ?? false) + // Step 1: Check on current fragment (file scoped). + if ((context.CurrentFragment?. + ContainsTypeAndSchedule(type, out var scope) ?? false) && + scope == Scopes.File) { this.DelayLookingUpAction1(() => { @@ -100,8 +103,8 @@ private bool InternalDelayLookingUpType( InputFragment? foundFragment = null; foreach (var fragment in context.InputFragments) { - if (fragment != context.CurrentFragment && - fragment.ContainsTypeAndSchedule(type, out _)) + if (fragment.ContainsTypeAndSchedule(type, out scope) && + scope is Scopes.Public or Scopes.Internal) // Internal only in another object. { // Found the symbol. foundFragment = fragment;