Make array human construction language-specific
authorMatt Corallo <git@bluematt.me>
Sat, 8 Jan 2022 02:16:37 +0000 (02:16 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 8 Jan 2022 04:12:35 +0000 (04:12 +0000)
gen_type_mapping.py
java_strings.py
typescript_strings.py

index fb810c92319b6f3b9152db84b9419c1e25c60691..504fbdc0251cea4453cec5652fe4ca311af57f50 100644 (file)
@@ -183,11 +183,7 @@ 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 = 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"
index 8338bc176156b056c77c367674faa9b37ff32996..c0eddca110ad91fdae9271ca41fd825e3e21a848 100644 (file)
@@ -652,6 +652,14 @@ import javax.annotation.Nullable;
     def var_decl_statement(self, ty_string, var_name, statement):
         return ty_string + " " + var_name + " = " + statement
 
+    def constr_hu_array(self, ty_info, arr_len):
+        base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0]
+        conv = "new " + base_ty + "[" + arr_len + "]"
+        if "[" in ty_info.subty.java_hu_ty.split("<")[0]:
+            # Do a bit of a dance to move any excess [] to the end
+            conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1]
+        return conv
+
     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):
index b2a1d5286a00e6ecc57f1f71bcd6dd1d11d75a59..7022137f287b502c9ff14f5c3634e752f3766867 100644 (file)
@@ -548,6 +548,9 @@ const decodeString = (stringPointer, free = true) => {
     def init_str(self):
         return ""
 
+    def constr_hu_array(self, ty_info, arr_len):
+        return "new Array(" + arr_len + ").fill(null)"
+
     def var_decl_statement(self, ty_string, var_name, statement):
         return "const " + var_name + ": " + ty_string + " = " + statement