+ rty = java_c_types(reg_fn.group(1), None)
+ if rty is not None and rty.rust_obj is not None and reg_fn.group(2) == rty.java_hu_ty + "_new":
+ constructor_fns[rty.rust_obj] = reg_fn.group(3)
+ continue
+ arr_fn = fn_ret_arr_regex.match(line)
+ if arr_fn is not None:
+ if arr_fn.group(2).endswith("_clone"):
+ clone_fns.add(arr_fn.group(2))
+ # No object constructors return arrays, as then they wouldn't be an object constructor
+ continue
+
+# Define some manual clones...
+clone_fns.add("ThirtyTwoBytes_clone")
+write_c("static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }\n")
+
+java_c_types_none_allowed = False # C structs created by cbindgen are declared in dependency order
+
+with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java:
+
+ # Map a top-level function
+ def map_fn(line, re_match, ret_arr_len, c_call_string):
+
+ # PARSING START
+ method_return_type = re_match.group(1)
+ method_name = re_match.group(2)
+ method_comma_separated_arguments = re_match.group(3)
+ method_arguments = method_comma_separated_arguments.split(',')
+
+ is_free = method_name.endswith("_free")
+ struct_meth = method_name.split("_")[0]
+
+ return_type_info = type_mapping_generator.map_type(method_return_type, True, ret_arr_len, False, False)
+
+ argument_types = []
+ default_constructor_args = {}
+ takes_self = False
+ args_known = True
+
+ for argument_index, argument in enumerate(method_arguments):
+ argument_conversion_info = type_mapping_generator.map_type(argument, False, None, is_free, True)
+ if argument_index == 0 and argument_conversion_info.java_hu_ty == struct_meth:
+ takes_self = True
+ if argument_conversion_info.arg_conv is not None and "Warning" in argument_conversion_info.arg_conv:
+ if argument_conversion_info.rust_obj in constructor_fns:
+ assert not is_free
+ for explode_arg in constructor_fns[argument_conversion_info.rust_obj].split(','):
+ explode_arg_conv = type_mapping_generator.map_type(explode_arg, False, None, False, True)
+ if explode_arg_conv.c_ty == "void":
+ # We actually want to handle this case, but for now its only used in NetGraphMsgHandler::new()
+ # which ends up resulting in a redundant constructor - both without arguments for the NetworkGraph.
+ args_known = False
+ pass
+ if not argument_conversion_info.arg_name in default_constructor_args:
+ default_constructor_args[argument_conversion_info.arg_name] = []
+ default_constructor_args[argument_conversion_info.arg_name].append(explode_arg_conv)
+ argument_types.append(argument_conversion_info)
+
+ has_out_java_struct = ("LDK" + struct_meth in opaque_structs or "LDK" + struct_meth in trait_structs) and not is_free
+ # PARSING END
+
+ out_java.write("\t// " + line)
+
+ (out_java_delta, out_c_delta, out_java_struct_delta) = consts.map_function(argument_types, c_call_string, is_free, method_name, return_type_info, struct_meth, default_constructor_args, takes_self, args_known, has_out_java_struct, type_mapping_generator)
+
+ out_java.write(out_java_delta)
+ write_c(out_c_delta)
+
+ if has_out_java_struct:
+ out_java_struct = open(f"{sys.argv[3]}/structs/{struct_meth}{consts.file_ext}", "a")
+ out_java_struct.write(out_java_struct_delta)
+
+
+
+
+
+ def map_unitary_enum(struct_name, field_lines):
+ with open(f"{sys.argv[3]}/enums/{struct_name}{consts.file_ext}", "w") as out_java_enum:
+ unitary_enums.add(struct_name)
+ for idx, struct_line in enumerate(field_lines):
+ if idx == 0:
+ assert(struct_line == "typedef enum %s {" % struct_name)
+ elif idx == len(field_lines) - 3:
+ assert(struct_line.endswith("_Sentinel,"))
+ elif idx == len(field_lines) - 2:
+ assert(struct_line == "} %s;" % struct_name)
+ elif idx == len(field_lines) - 1:
+ assert(struct_line == "")
+ (c_out, native_file_out, native_out) = consts.native_c_unitary_enum_map(struct_name, [x.strip().strip(",") for x in field_lines[1:-3]])
+ write_c(c_out)
+ out_java_enum.write(native_file_out)
+ out_java.write(native_out)
+
+ def map_complex_enum(struct_name, union_enum_items):
+ java_hu_type = struct_name.replace("LDK", "")
+ complex_enums.add(struct_name)
+
+ enum_variants = []
+ tag_field_lines = union_enum_items["field_lines"]
+ for idx, struct_line in enumerate(tag_field_lines):
+ if idx == 0:
+ assert(struct_line == "typedef enum %s_Tag {" % struct_name)
+ elif idx == len(tag_field_lines) - 3:
+ assert(struct_line.endswith("_Sentinel,"))
+ elif idx == len(tag_field_lines) - 2:
+ assert(struct_line == "} %s_Tag;" % struct_name)
+ elif idx == len(tag_field_lines) - 1:
+ assert(struct_line == "")