Skip to content

Commit d7d68fb

Browse files
committed
Implement requested changes
1 parent 88c5cfb commit d7d68fb

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

Il2CppInterop.Generator/Contexts/RewriteGlobalContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,11 @@ public TypeRewriteContext GetNewTypeForOriginal(TypeDefinition originalType)
8787

8888
public TypeRewriteContext.TypeSpecifics JudgeSpecificsByOriginalType(TypeSignature typeRef)
8989
{
90-
if (typeRef.IsPrimitive() || typeRef is PointerTypeSignature || typeRef.FullName == "System.TypedReference")
90+
if (typeRef.IsPrimitive() || typeRef.IsPointerLike() || typeRef.FullName == "System.TypedReference")
9191
return TypeRewriteContext.TypeSpecifics.BlittableStruct;
9292
if (typeRef
9393
is CorLibTypeSignature { ElementType: ElementType.String or ElementType.Object }
9494
or ArrayBaseTypeSignature
95-
or ByReferenceTypeSignature
9695
or GenericParameterSignature
9796
or GenericInstanceTypeSignature)
9897
return TypeRewriteContext.TypeSpecifics.ReferenceType;

Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ private static Parameter GetArgument(this ILProcessor instructions, int argument
5353

5454
public static bool IsNested(this TypeSignature type) => type.DeclaringType is not null;
5555

56+
public static bool IsPointerLike(this TypeSignature type) => type is PointerTypeSignature or ByReferenceTypeSignature;
57+
58+
public static bool IsValueTypeLike(this TypeSignature type) => type.IsValueType || type.IsPointerLike();
59+
5660
public static bool IsSystemEnum(this GenericParameterConstraint constraint) => constraint.Constraint?.FullName is "System.Enum";
5761

5862
public static bool IsSystemValueType(this GenericParameterConstraint constraint) => constraint.Constraint?.FullName is "System.ValueType";

Il2CppInterop.Generator/Extensions/ILGeneratorEx.cs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ public static void EmitObjectStore(this ILProcessor body, TypeSignature original
3131
body.Add(OpCodes.Call, imports.IL2CPP_ManagedStringToIl2Cpp.Value);
3232
body.Add(OpCodes.Call, imports.WriteFieldWBarrier);
3333
}
34-
else if (originalType is PointerTypeSignature)
35-
{
36-
Debug.Assert(newType is PointerTypeSignature);
37-
38-
body.AddLoadArgument(argumentIndex);
39-
body.Add(OpCodes.Stobj, newType.ToTypeDefOrRef());
40-
body.Add(OpCodes.Pop);
41-
}
42-
else if (originalType.IsValueType)
34+
else if (originalType.IsValueTypeLike())
4335
{
4436
var typeSpecifics = enclosingType.AssemblyContext.GlobalContext.JudgeSpecificsByOriginalType(originalType);
4537
if (typeSpecifics == TypeRewriteContext.TypeSpecifics.BlittableStruct)
@@ -195,15 +187,9 @@ public static void EmitObjectToPointer(this ILProcessor body, TypeSignature orig
195187
body.Add(OpCodes.Conv_I);
196188
}
197189
}
198-
else if (originalType is PointerTypeSignature)
199-
{
200-
Debug.Assert(newType is PointerTypeSignature);
201-
202-
body.AddLoadArgumentAddress(argumentIndex);
203-
}
204-
else if (originalType.IsValueType)
190+
else if (originalType.IsValueTypeLike())
205191
{
206-
if (newType.IsValueType)
192+
if (newType.IsValueTypeLike())
207193
{
208194
if (argumentIndex == 0 && valueTypeArgument0IsAPointer)
209195
body.Add(OpCodes.Ldarg_0);
@@ -310,17 +296,9 @@ public static void EmitPointerToObject(this ILProcessor body, TypeSignature orig
310296
{
311297
// do nothing
312298
}
313-
else if (originalReturnType is PointerTypeSignature)
314-
{
315-
Debug.Assert(convertedReturnType is PointerTypeSignature);
316-
317-
body.Add(OpCodes.Ldloc, pointerVariable);
318-
if (unboxValueType) body.Add(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value);
319-
body.Add(OpCodes.Ldobj, convertedReturnType.ToTypeDefOrRef());
320-
}
321-
else if (originalReturnType.IsValueType)
299+
else if (originalReturnType.IsValueTypeLike())
322300
{
323-
if (convertedReturnType.IsValueType)
301+
if (convertedReturnType.IsValueTypeLike())
324302
{
325303
body.Add(OpCodes.Ldloc, pointerVariable);
326304
if (unboxValueType) body.Add(OpCodes.Call, imports.IL2CPP_il2cpp_object_unbox.Value);

0 commit comments

Comments
 (0)