Skip to content

Commit

Permalink
Updated output java call
Browse files Browse the repository at this point in the history
  • Loading branch information
xevor11 committed Aug 23, 2024
1 parent 7b31a0b commit 332e29c
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -7098,7 +7098,9 @@ output_java_call (struct cb_call *p)
char *last_dot;
char *method_name;
const char *class_name;
char method_signature[256] = "(";
char* mangled;
struct cb_tree *ptr;

mangled = strdup(class_and_method_name);
for (size_t i = 0; i < strlen(mangled) + 1; i++) {
Expand All @@ -7115,18 +7117,103 @@ output_java_call (struct cb_call *p)
method_name = last_dot + 1;
class_name = class_and_method_name;

for(ptr = p->args; ptr != NULL; ptr = ptr->next) {
switch(CB_TREE_TAG(ptr)) {
case CB_TAG_INTEGER:
strcat(method_signature, "I");
break;
case CB_TAG_LONG:
strcat(method_signature, "J");
break;
case CB_TAG_FLOAT:
strcat(method_signature, "F");
break;
case CB_TAG_DOUBLE:
strcat(method_signature, "D");
break;
case CB_TAG_BOOLEAN:
strcat(method_signature, "Z");
break;
case CB_TAG_BYTE:
strcat(method_signature, "B");
break;
case CB_TAG_SHORT:
strcat(method_signature, "S");
break;
case CB_TAG_CHAR:
strcat(method_signature, "C");
break;
case CB_TAG_STRING:
strcat(method_signature, "Ljava/lang/String;");
break;
case CB_TAG_OBJECT:
strcat(method_signature, "Ljava/lang/Object;");
break;
case CB_TAG_LITERAL:
if(CB_TREE_CATEGORY(ptr) == CB_CATEGORY_NUMERIC) {
strcat(method_signature, "I");
} else if(CB_TREE_CATEGORY(ptr) == CB_CATEGORY_ALPHANUMERIC) {
strcat(method_signature, "Ljava/lang/String;");
}
break;
case CB_TAG_ARRAY:
switch(CB_TREE_TAG(CB_TREE(ptr)->next)) {
case CB_TAG_INTEGER:
strcat(method_signature, "[I");
break;
case CB_TAG_LONG:
strcat(method_signature, "[J");
break;
case CB_TAG_FLOAT:
strcat(method_signature, "[F");
break;
case CB_TAG_DOUBLE:
strcat(method_signature, "[D");
break;
case CB_TAG_BOOLEAN:
strcat(method_signature, "[Z");
break;
case CB_TAG_BYTE:
strcat(method_signature, "[B");
break;
case CB_TAG_SHORT:
strcat(method_signature, "[S");
break;
case CB_TAG_CHAR:
strcat(method_signature, "[C");
break;
case CB_TAG_STRING:
strcat(method_signature, "[Ljava/lang/String;");
break;
case CB_TAG_OBJECT:
strcat(method_signature, "[Ljava/lang/Object;");
break;
default:
cobc_err_msg(_("Unsupported array type in Java method call"));
COBC_ABORT();
}
break;
default:
cobc_err_msg(_("Unsupported argument type in Java method call"));
COBC_ABORT();
}
}

strcat(method_signature, ")V");

lookup_java_call(mangled);
output_line("if (call_java_%s == NULL)", mangled);
output_block_open();

output_prefix();
output_line("call_java_%s = ", mangled);
output("cob_resolve_java(\"%s\", \"%s\", \"()V\");", class_name, method_name);
output("cob_resolve_java(\"%s\", \"%s\", \"()V\");", class_name, method_name, method_signature);
output_newline ();
output_prefix ();
output_line("cob_call_java(call_java_%s);\n", mangled);
output_newline();
output_block_close();
cobc_free(mangled);
}

static void
Expand Down

0 comments on commit 332e29c

Please sign in to comment.