From: Matt Corallo Date: Fri, 7 Jan 2022 22:20:06 +0000 (+0000) Subject: Make array range iteration language-specific X-Git-Tag: v0.0.104.1~1^2~8 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=5e2e8f6fdee605dd8e1c674f054d64f1085691fc;p=ldk-java Make array range iteration language-specific --- diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 76510119..fb810c92 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -188,7 +188,7 @@ class TypeMappingGenerator: if "[" in ty_info.subty.java_hu_ty.split("<")[0]: # Do a bit of a dance to move any excess [] to the end to_hu_conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1] - to_hu_conv += ";\nfor (int " + idxc + " = 0; " + idxc + " < " + arr_name + ".length; " + idxc + "++) {\n" + to_hu_conv += ";\n" + self.consts.for_n_in_range(idxc, "0", arr_name + ".length") + "\n" to_hu_conv += "\t" + self.consts.var_decl_statement(subty.java_ty, conv_name, arr_name + "[" + idxc + "]") + ";\n" to_hu_conv += "\t" + subty.to_hu_conv.replace("\n", "\n\t") + "\n" to_hu_conv += "\t" + conv_name + "_arr[" + idxc + "] = " + subty.to_hu_conv_name + ";\n}" @@ -197,7 +197,8 @@ class TypeMappingGenerator: if subty.from_hu_conv is not None: hu_conv_b = "" if subty.from_hu_conv[1] != "": - hu_conv_b = "for (" + subty.java_hu_ty + " " + conv_name + ": " + arr_name + ") { " + subty.from_hu_conv[1] + "; }" + iterator = self.consts.for_n_in_arr(conv_name, arr_name, subty) + hu_conv_b = iterator[0] + subty.from_hu_conv[1] + ";" + iterator[1] from_hu_conv = (self.consts.map_hu_array_elems(arr_name, conv_name, ty_info, subty), hu_conv_b) return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, diff --git a/java_strings.py b/java_strings.py index cb23b56a..535646b9 100644 --- a/java_strings.py +++ b/java_strings.py @@ -628,6 +628,11 @@ import javax.annotation.Nullable; def var_decl_statement(self, ty_string, var_name, statement): return ty_string + " " + var_name + " = " + statement + def for_n_in_range(self, n, minimum, maximum): + return "for (int " + n + " = " + minimum + "; " + n + " < " + maximum + "; " + n + "++) {" + def for_n_in_arr(self, n, arr_name, arr_elem_ty): + return ("for (" + arr_elem_ty.java_hu_ty + " " + n + ": " + arr_name + ") { ", " }") + def get_ptr(self, var): return var + ".ptr" def set_null_skip_free(self, var): diff --git a/typescript_strings.py b/typescript_strings.py index 01096343..d76318f3 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -534,6 +534,11 @@ const decodeString = (stringPointer, free = true) => { def var_decl_statement(self, ty_string, var_name, statement): return "const " + var_name + ": " + ty_string + " = " + statement + def for_n_in_range(self, n, minimum, maximum): + return "for (var " + n + " = " + minimum + "; " + n + " < " + maximum + "; " + n + "++) {" + def for_n_in_arr(self, n, arr_name, arr_elem_ty): + return (arr_name + ".forEach((" + n + ": " + arr_elem_ty.java_hu_ty + ") => { ", " })") + def get_ptr(self, var): return "CommonBase.get_ptr_of(" + var + ")" def set_null_skip_free(self, var):