Skip to content

Commit a1528b4

Browse files
committed
[generator] Add support for unsigned types.
1 parent 81dc9a2 commit a1528b4

File tree

24 files changed

+110
-29
lines changed

24 files changed

+110
-29
lines changed

src/Java.Interop/Java.Interop/JniArgumentValue.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public JniArgumentValue (sbyte value)
3434
b = value;
3535
}
3636

37+
public JniArgumentValue (byte value) : this ((sbyte)value) { }
38+
3739
public JniArgumentValue (char value)
3840
{
3941
this = new JniArgumentValue ();
@@ -46,18 +48,24 @@ public JniArgumentValue (short value)
4648
s = value;
4749
}
4850

51+
public JniArgumentValue (ushort value) : this ((short)value) { }
52+
4953
public JniArgumentValue (int value)
5054
{
5155
this = new JniArgumentValue ();
5256
i = value;
5357
}
5458

59+
public JniArgumentValue (uint value) : this ((int)value) { }
60+
5561
public JniArgumentValue (long value)
5662
{
5763
this = new JniArgumentValue ();
5864
j = value;
5965
}
6066

67+
public JniArgumentValue (ulong value) : this ((long) value) { }
68+
6169
public JniArgumentValue (float value)
6270
{
6371
this = new JniArgumentValue ();

tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ public void WriteMethodInvokerBody (Method method, string indent)
12121212
writer.WriteLine ("{0}{1}", indent, prep);
12131213
WriteParameterListCallArgs (method.Parameters, indent, invoker: true);
12141214
string env_method = "Call" + method.RetVal.CallMethodPrefix + "Method";
1215-
string call = "JNIEnv." + env_method + " (" +
1215+
string call = method.RetVal.ReturnCast + "JNIEnv." + env_method + " (" +
12161216
Context.ContextType.GetObjectHandleProperty ("this") + ", " + method.EscapedIdName + method.Parameters.GetCallArgs (opt, invoker: true) + ")";
12171217
if (method.IsVoid)
12181218
writer.WriteLine ("{0}{1};", indent, call);

tools/generator/Java.Interop.Tools.Generator.CodeGeneration/JavaInteropCodeGenerator.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ static string GetInvokeType (string type)
1919
case "Short": return "Int16";
2020
case "Long": return "Int64";
2121
case "Float": return "Single";
22+
case "UInt": return "Int32";
23+
case "UShort": return "Int16";
24+
case "ULong": return "Int64";
25+
case "UByte": return "SByte";
2226
default: return type;
2327
}
2428
}
@@ -171,7 +175,7 @@ internal override void WriteMethodBody (Method method, string indent, GenBase ty
171175

172176
if (!method.IsVoid) {
173177
var r = invokeType == "Object" ? "__rm.Handle" : "__rm";
174-
writer.WriteLine ("{0}return {1};", indent, method.RetVal.FromNative (opt, r, true));
178+
writer.WriteLine ("{0}return {2}{1};", indent, method.RetVal.FromNative (opt, r, true), method.RetVal.ReturnCast);
175179
}
176180

177181
indent = oldindent;
@@ -196,19 +200,21 @@ internal override void WriteFieldGetBody (Field field, string indent, GenBase ty
196200
var invoke = "Get{0}Value";
197201
invoke = string.Format (invoke, invokeType);
198202

199-
writer.WriteLine ("{0}var __v = _members.{1}.{2} (__id{3});",
203+
writer.WriteLine ("{0}var __v = {4}_members.{1}.{2} (__id{3});",
200204
indent,
201205
indirect,
202206
invoke,
203-
field.IsStatic ? "" : ", this");
207+
field.IsStatic ? "" : ", this",
208+
field.Symbol.ReturnCast);
204209

205210
if (field.Symbol.IsArray) {
206211
writer.WriteLine ("{0}return global::Android.Runtime.JavaArray<{1}>.FromJniHandle (__v.Handle, JniHandleOwnership.TransferLocalRef);", indent, opt.GetOutputName (field.Symbol.ElementType));
207212
}
208213
else if (field.Symbol.NativeType != field.Symbol.FullName) {
209-
writer.WriteLine ("{0}return {1};",
214+
writer.WriteLine ("{0}return {2}{1};",
210215
indent,
211-
field.Symbol.FromNative (opt, invokeType != "Object" ? "__v" : "__v.Handle", true));
216+
field.Symbol.FromNative (opt, invokeType != "Object" ? "__v" : "__v.Handle", true),
217+
field.Symbol.ReturnCast);
212218
} else {
213219
writer.WriteLine ("{0}return __v;", indent);
214220
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Field : ApiVersionsSupport.IApiAvailability
2323
public string Value { get; set; }
2424
public string Visibility { get; set; }
2525

26-
internal string GetMethodPrefix => (Symbol is SimpleSymbol || Symbol.IsEnum) ? StringRocks.MemberToPascalCase (Symbol.JavaName) : "Object";
26+
internal string GetMethodPrefix => TypeNameUtilities.GetCallPrefix (Symbol);
2727

2828
internal string ID => JavaName + "_jfieldId";
2929

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ protected GenBase (GenBaseSupport support)
3333
public string DefaultValue { get; set; }
3434
public bool HasVirtualMethods { get; set; }
3535

36+
public string ReturnCast => string.Empty;
37+
3638
// This means Ctors/Methods/Properties/Fields has not been populated yet.
3739
// If this type is retrieved from the SymbolTable, it will call PopulateAction
3840
// to fill in members before returning it to the user.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal string CalculateEventName (Func<string, bool> checkNameDuplicate)
108108

109109
public string EscapedCallbackName => IdentifierValidator.CreateValidIdentifier ($"cb_{JavaName}{IDSignature}", true);
110110

111-
public string EscapedIdName => "id_" + JavaName.Replace ("<", "_x60_").Replace (">", "_x62_") + IDSignature;
111+
public string EscapedIdName => IdentifierValidator.CreateValidIdentifier ($"id_{JavaName}{IDSignature}", true);
112112

113113
internal void FillReturnType ()
114114
{

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ public ReturnValue (Method owner, string java_type, string managed_type, bool is
2222
this.is_enumified = isEnumified;
2323
}
2424

25-
public string CallMethodPrefix {
26-
get {
27-
if (sym is SimpleSymbol || sym.IsEnum)
28-
return StringRocks.MemberToPascalCase (sym.JavaName);
29-
else
30-
return "Object";
31-
}
32-
}
25+
public string CallMethodPrefix => TypeNameUtilities.GetCallPrefix (sym);
3326

3427
public string DefaultValue {
3528
get { return sym.DefaultValue; }
@@ -89,6 +82,8 @@ public string RawJavaType {
8982
get { return raw_type; }
9083
}
9184

85+
public string ReturnCast => sym?.ReturnCast ?? string.Empty;
86+
9287
public string FromNative (CodeGenerationOptions opt, string var_name, bool owned)
9388
{
9489
if (!string.IsNullOrEmpty (managed_type) && (sym is ClassGen || sym is InterfaceGen)) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public bool IsArray {
6464
get { return true; }
6565
}
6666

67+
public string ReturnCast => string.Empty;
68+
6769
public string GetObjectHandleProperty (string variable)
6870
{
6971
return sym.GetObjectHandleProperty (variable);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public string ElementType {
4141
get { return null; }
4242
}
4343

44+
public string ReturnCast => string.Empty;
45+
4446
public string GetObjectHandleProperty (string variable)
4547
{
4648
return $"((global::Java.Lang.Object) {variable}).Handle";

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public bool MayHaveManagedGenericArguments {
5656
get { return true; }
5757
}
5858

59+
public string ReturnCast => string.Empty;
60+
5961
public string GetObjectHandleProperty (string variable)
6062
{
6163
return $"((global::Java.Lang.Object) {variable}).Handle";

0 commit comments

Comments
 (0)