Skip to content

Commit

Permalink
Java std cleanup (#11829)
Browse files Browse the repository at this point in the history
* damage report

* unused, maybe

* more

* remove java.lang.String hacks

* remove java.NativeString

* restore CI

* Revert "remove java.NativeString"

This reverts commit fde3552.

* Revert "remove java.lang.String hacks"

This reverts commit 109a116.
  • Loading branch information
Simn authored Nov 21, 2024
1 parent 5b757af commit b6b8925
Show file tree
Hide file tree
Showing 83 changed files with 433 additions and 1,536 deletions.
8 changes: 4 additions & 4 deletions src/codegen/javaModern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,13 @@ module SignatureConverter = struct

and convert_signature ctx p jsig =
match jsig with
| TByte -> mk_type_path (["java"; "types"], "Int8") [] p
| TChar -> mk_type_path (["java"; "types"], "Char16") [] p
| TByte -> mk_type_path (["jvm"], "Int8") [] p
| TChar -> mk_type_path (["jvm"], "Char16") [] p
| TDouble -> mk_type_path ([], "Float") [] p
| TFloat -> mk_type_path ([], "Single") [] p
| TInt -> mk_type_path ([], "Int") [] p
| TLong -> mk_type_path (["haxe"], "Int64") [] p
| TShort -> mk_type_path (["java"; "types"], "Int16") [] p
| TShort -> mk_type_path (["jvm"], "Int16") [] p
| TBool -> mk_type_path ([], "Bool") [] p
| TObject ( (["haxe";"root"], name), args ) -> mk_type_path ([], name) (List.map (convert_arg ctx p) args) p
| TObject ( (["java";"lang"], "Object"), [] ) -> mk_type_path ([], "Dynamic") [] p
Expand All @@ -693,7 +693,7 @@ module SignatureConverter = struct
| _ -> die "" __LOC__ in
mk_type_path (pack, name ^ "$" ^ String.concat "$" (List.map fst inners)) (List.map (fun param -> convert_arg ctx p param) actual_param) p
| TObjectInner (pack, inners) -> die "" __LOC__
| TArray (jsig, _) -> mk_type_path (["java"], "NativeArray") [ TPType (convert_signature ctx p jsig,p) ] p
| TArray (jsig, _) -> mk_type_path (["jvm"], "NativeArray") [ TPType (convert_signature ctx p jsig,p) ] p
| TMethod _ -> failwith "TMethod cannot be converted directly into Complex Type"
| TTypeParameter s ->
try
Expand Down
2 changes: 1 addition & 1 deletion src/filters/capturedVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let captured_vars com e =
| Jvm ->
let cnativearray =
match (List.find (fun md -> match md with
| TClassDecl ({ cl_path = ["java"],"NativeArray" }) -> true
| TClassDecl ({ cl_path = ["jvm"],"NativeArray" }) -> true
| _ -> false
) com.types)
with TClassDecl cl -> cl | _ -> die "" __LOC__
Expand Down
24 changes: 12 additions & 12 deletions src/generators/genjvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ open NativeSignatures

let jsignature_of_path path = match path with
| [],"Bool" -> TBool
| ["java"],"Int8" -> TByte
| ["java"],"Int16" -> TShort
| ["jvm"],"Int8" -> TByte
| ["jvm"],"Int16" -> TShort
| [],"Int" -> TInt
| ["haxe"],"Int32" -> TInt
| ["haxe"],"Int64" -> TLong
| ["java"],"Int64" -> TLong
| ["java"],"Char16" -> TChar
| ["jvm"],"Int64" -> TLong
| ["jvm"],"Char16" -> TChar
| [],"Single" -> TFloat
| [],"Float" -> TDouble
| [],"Dynamic" -> object_sig
Expand Down Expand Up @@ -183,7 +183,7 @@ let rec jsignature_of_type gctx stack t =
| TInst({cl_path = (["haxe";"root"],"Array")},[t]) ->
let t = get_boxed_type (jsignature_of_type t) in
TObject((["haxe";"root"],"Array"),[TType(WNone,t)])
| TInst({cl_path = (["java"],"NativeArray")},[t]) ->
| TInst({cl_path = (["jvm"],"NativeArray")},[t]) ->
TArray(jsignature_of_type t,None)
| TInst({cl_kind = KTypeParameter ttp; cl_path = (_,name)},_) ->
begin match get_constraints ttp with
Expand Down Expand Up @@ -745,7 +745,7 @@ class texpr_to_jvm
| FInstance({cl_path = (["java";"lang"],"String")},_,{cf_name = "length"}) ->
self#texpr rvalue_any e1;
jm#invokevirtual string_path "length" (method_sig [] (Some TInt))
| FInstance({cl_path = (["java"],"NativeArray")},_,{cf_name = "length"}) ->
| FInstance({cl_path = (["jvm"],"NativeArray")},_,{cf_name = "length"}) ->
self#texpr rvalue_any e1;
let vtobj = self#vtype e1.etype in
code#arraylength vtobj;
Expand Down Expand Up @@ -858,7 +858,7 @@ class texpr_to_jvm
apply (fun () -> code#dup_x2;);
jm#expect_reference_type;
jm#invokevirtual c.cl_path "__set" (method_sig [TInt;object_sig] None);
| TInst({cl_path = (["java"],"NativeArray")},[t]) ->
| TInst({cl_path = (["jvm"],"NativeArray")},[t]) ->
let vte = self#vtype t in
let vta = self#vtype e1.etype in
self#texpr rvalue_any e1;
Expand Down Expand Up @@ -1635,9 +1635,9 @@ class texpr_to_jvm
| _ ->
die "" __LOC__
end
| TIdent "__array__" | TField(_,FStatic({cl_path = (["java"],"NativeArray")},{cf_name = "make"})) ->
| TIdent "__array__" | TField(_,FStatic({cl_path = (["jvm"],"NativeArray")},{cf_name = "make"})) ->
begin match follow tr with
| TInst({cl_path = (["java"],"NativeArray")},[t]) ->
| TInst({cl_path = (["jvm"],"NativeArray")},[t]) ->
let jsig = self#vtype t in
self#new_native_array jsig el;
Some (array_sig jsig)
Expand Down Expand Up @@ -2047,7 +2047,7 @@ class texpr_to_jvm
else self#read (fun () -> self#cast_expect ret e.etype) e1 fa;
| TCall(e1,el) ->
self#call ret e.etype e1 el
| TNew({cl_path = (["java"],"NativeArray")},[t],[e1]) ->
| TNew({cl_path = (["jvm"],"NativeArray")},[t],[e1]) ->
self#texpr (if need_val ret then rvalue_any else RVoid) e1;
(* Technically this could throw... but whatever *)
if need_val ret then ignore(NativeArray.create jm#get_code jc#get_pool (jsignature_of_type gctx t))
Expand Down Expand Up @@ -2103,7 +2103,7 @@ class texpr_to_jvm
jm#cast TInt;
jm#invokevirtual c.cl_path "__get" (method_sig [TInt] (Some object_sig));
self#cast e.etype
| TInst({cl_path = (["java"],"NativeArray")},[t]) ->
| TInst({cl_path = (["jvm"],"NativeArray")},[t]) ->
self#texpr rvalue_any e1;
let vt = self#vtype e1.etype in
let vte = self#vtype t in
Expand Down Expand Up @@ -2648,7 +2648,7 @@ class tclass_to_jvm gctx c = object(self)
load();
jm#putstatic (["haxe";"root"],"Sys") "_args" (TArray(string_sig,None))
end;
jm#invokestatic (["haxe"; "java"], "Init") "init" (method_sig [] None);
jm#invokestatic (["haxe"; "jvm"], "Jvm") "init" (method_sig [] None);
self#generate_expr gctx None jc jm e SCNone MStatic;
if not jm#is_terminated then jm#return

Expand Down
2 changes: 1 addition & 1 deletion src/optimization/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let api_inline ctx c field params p =
Some (Texpr.Builder.fcall (eJsSyntax()) "instanceof" [o;t] tbool p)
| (["haxe";"ds";"_Vector"],"Vector_Impl_"),("fromArrayCopy"),[{ eexpr = TArrayDecl args } as edecl] -> (try
let platf = match ctx.com.platform with
| Jvm -> "java"
| Jvm -> "jvm"
| _ -> raise Exit
in
let mpath = if field = "fromArrayCopy" then
Expand Down
2 changes: 1 addition & 1 deletion src/typing/strictMeta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let rec kind_of_type_against ctx t_want e_have =
unify ctx e.etype t_want e.epos
end;
e
| TInst({cl_path = (["java"],"NativeArray")},[t1]) ->
| TInst({cl_path = (["jvm"],"NativeArray")},[t1]) ->
begin match fst e_have with
| EArrayDecl el ->
let el = List.map (kind_of_type_against ctx t1) el in
Expand Down
2 changes: 1 addition & 1 deletion std/StringTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ class StringTools {
}

#if java
private static inline function _charAt(str:String, idx:Int):java.StdTypes.Char16
private static inline function _charAt(str:String, idx:Int):jvm.Char16
return (cast str : java.NativeString).charAt(idx);
#end

Expand Down
4 changes: 2 additions & 2 deletions std/haxe/EnumTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ extern class EnumTools {
return Type.getEnumConstructs(e);
}

#if (java && jvm)
#if jvm
@:noCompletion
extern static function values<T>(en:Enum<T>):java.NativeArray<java.lang.Enum<T>>;
extern static function values<T>(en:Enum<T>):jvm.NativeArray<java.lang.Enum<T>>;
#end
}

Expand Down
4 changes: 2 additions & 2 deletions std/haxe/ds/Vector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private typedef VectorData<T> =
#elseif neko
neko.NativeArray<T>
#elseif java
java.NativeArray<T>
jvm.NativeArray<T>
#elseif lua
lua.Table<Int, T>
#elseif eval
Expand Down Expand Up @@ -280,7 +280,7 @@ abstract Vector<T>(VectorData<T>) {
#elseif flash10
return fromData(flash.Vector.ofArray(array));
#elseif java
return fromData(java.Lib.nativeArray(array, false));
return fromData(jvm.NativeArray.ofArray(array));
#elseif cpp
return cast array.copy();
#elseif js
Expand Down
2 changes: 1 addition & 1 deletion std/haxe/io/BytesData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef BytesData = flash.utils.ByteArray;
#elseif cpp
typedef BytesData = Array<cpp.UInt8>;
#elseif java
typedef BytesData = java.NativeArray<java.StdTypes.Int8>;
typedef BytesData = jvm.NativeArray<jvm.Int8>;
#elseif python
typedef BytesData = python.Bytearray;
#elseif js
Expand Down
11 changes: 1 addition & 10 deletions std/haxe/rtti/Meta.hx
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,13 @@ class Meta {
return (meta == null || meta.obj == null) ? {} : meta.obj;
}

// Could move this to Type.hx?
private static function isInterface(t:Dynamic):Bool {
#if java
return java.Lib.toNativeType(t).isInterface();
#else
throw "Something went wrong";
#end
}

private static function getMeta(t:Dynamic):MetaObject {
#if php
return php.Boot.getMeta(t.phpClassName);
#elseif java
var ret = Reflect.field(t, "__meta__");
if (ret == null && Std.isOfType(t, Class)) {
if (isInterface(t)) {
if (jvm.NativeTools.NativeClassTools.native(t).isInterface()) {
var name = Type.getClassName(t),
cls = Type.resolveClass(name + '_HxMeta');
if (cls != null)
Expand Down
44 changes: 0 additions & 44 deletions std/java/Boot.hx

This file was deleted.

33 changes: 0 additions & 33 deletions std/java/Init.hx

This file was deleted.

Loading

0 comments on commit b6b8925

Please sign in to comment.