Skip to content

Commit 0ef3d55

Browse files
committed
Add support for Kotlin unsigned array types.
1 parent 7508321 commit 0ef3d55

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,16 @@ static string GetPrimitiveClass (Type type)
232232
return "F";
233233
if (type == typeof (int))
234234
return "I";
235+
if (type == typeof (uint))
236+
return "I";
235237
if (type == typeof (long))
236238
return "J";
239+
if (type == typeof (ulong))
240+
return "J";
237241
if (type == typeof (short))
238242
return "S";
243+
if (type == typeof (ushort))
244+
return "S";
239245
if (type == typeof (bool))
240246
return "Z";
241247
return null;

src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,20 @@ static string GetKotlinType (string jvmType, string kotlinClass)
302302
// Handle erasure of Kotlin unsigned types
303303
if (jvmType == "I" && kotlinClass == "kotlin/UInt;")
304304
return "uint";
305+
if (jvmType == "[I" && kotlinClass == "kotlin/UIntArray;")
306+
return "uint[]";
305307
if (jvmType == "S" && kotlinClass == "kotlin/UShort;")
306308
return "ushort";
309+
if (jvmType == "[S" && kotlinClass == "kotlin/UShortArray;")
310+
return "ushort[]";
307311
if (jvmType == "J" && kotlinClass == "kotlin/ULong;")
308312
return "ulong";
313+
if (jvmType == "[J" && kotlinClass == "kotlin/ULongArray;")
314+
return "ulong[]";
309315
if (jvmType == "B" && kotlinClass == "kotlin/UByte;")
310316
return "ubyte";
317+
if (jvmType == "[B" && kotlinClass == "kotlin/UByteArray;")
318+
return "ubyte[]";
311319

312320
return null;
313321
}

tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ public bool IsKotlinNameMangled {
8787
if (method.JavaName.IndexOf ("-impl") >= 0)
8888
return true;
8989

90-
var index = method.JavaName.IndexOf ('-');
91-
92-
// `add-V5j3Lk8` is always a 7 character hashcode
93-
return index >= 0 && method.JavaName.Length - index == 8;
90+
return method.JavaName.Length >= 8 && method.JavaName [method.JavaName.Length - 8] == '-';
9491
}
9592

9693
return false;

tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,25 @@ public string[] PreCallback (CodeGenerationOptions opt, string var_name, bool ow
122122

123123
public string[] PreCall (CodeGenerationOptions opt, string var_name)
124124
{
125-
return new string[] { String.Format ("IntPtr {0} = JNIEnv.NewArray ({1});", opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name)), opt.GetSafeIdentifier (var_name)) };
125+
126+
return new string[] { String.Format ("IntPtr {0} = JNIEnv.NewArray ({2}{1});", opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name)), opt.GetSafeIdentifier (var_name), GetPreCallCast ()) };
126127
}
127128

128129
public bool NeedsPrep { get { return true; } }
130+
131+
string GetPreCallCast ()
132+
{
133+
switch (sym.FullName) {
134+
case "uint":
135+
return "(int[])(object)";
136+
case "ushort":
137+
return "(short[])(object)";
138+
case "ulong":
139+
return "(long[])(object)";
140+
default:
141+
return string.Empty;
142+
}
143+
}
129144
}
130145
}
131146

tools/generator/Java.Interop.Tools.Generator.Transformation/KotlinFixups.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ private static void FixMethodName (Method method)
4949
// We want to remove the hyphen and anything afterwards to fix mangled names,
5050
// but a previous step converted it to an underscore. Remove the final
5151
// underscore and anything after it.
52-
var index = method.Name.LastIndexOf ('_');
52+
var index = method.Name.IndexOf ("_impl");
5353

54-
method.Name = method.Name.Substring (0, index);
54+
if (index >= 0)
55+
method.Name = method.Name.Substring (0, index);
56+
else
57+
method.Name = method.Name.Substring (0, method.Name.Length - 8);
5558
}
5659
}
5760
}

0 commit comments

Comments
 (0)