X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=gen_type_mapping.py;h=504fbdc0251cea4453cec5652fe4ca311af57f50;hb=ca0aed596ddba4b859398743133c69db2c132644;hp=f4d6b380476337e0c2df21dda5558a0fbf505211;hpb=6fd82c1b987893a8c6ffd7979743196ab60e20fc;p=ldk-java diff --git a/gen_type_mapping.py b/gen_type_mapping.py index f4d6b380..504fbdc0 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -183,12 +183,8 @@ class TypeMappingGenerator: to_hu_conv = None to_hu_conv_name = None if subty.to_hu_conv is not None: - base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0] - to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", "new " + base_ty + "[" + arr_name + ".length]") - 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 = self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", self.consts.constr_hu_array(ty_info, arr_name + ".length")) + 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,15 +193,9 @@ 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] + "; }" - if subty.java_ty == "long" and subty.java_hu_ty != "long": - from_hu_conv = (arr_name + " != null ? Arrays.stream(" + arr_name + ").mapToLong(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray() : null", - hu_conv_b) - elif subty.java_ty == "long": - from_hu_conv = (arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray() : null", "/* TODO 2 " + subty.java_hu_ty + " */") - else: - from_hu_conv = (arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + subty.from_hu_conv[0] + ").toArray(" + ty_info.java_ty + "::new) : null", - hu_conv_b) + 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, arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = arg_conv_cleanup,