Skip to content

Commit 1f90ff3

Browse files
committed
Tag fixes and modifies to call_cache
1 parent 332e29c commit 1f90ff3

File tree

1 file changed

+48
-66
lines changed

1 file changed

+48
-66
lines changed

cobc/codegen.c

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct field_list {
120120
struct call_list {
121121
struct call_list *next;
122122
const char *call_name;
123+
const char *method_sig;
123124
};
124125

125126
#define COB_RETURN_INT 0
@@ -397,17 +398,18 @@ lookup_source (const char *p)
397398
}
398399

399400
static void
400-
lookup_java_call(const char *p)
401+
lookup_java_call(const char *p, const char *signature)
401402
{
402403
struct call_list *clp;
403404

404405
for (clp = call_java_cache; clp; clp = clp->next) {
405-
if (strcmp (p, clp->call_name) == 0) {
406+
if (strcmp (p, clp->call_name) == 0 && strcmp(signature, clp->method_sig) == 0) {
406407
return;
407408
}
408409
}
409410
clp = cobc_parse_malloc (sizeof (struct call_list));
410411
clp->call_name = p;
412+
clp->method_sig = signature;
411413
clp->next = call_java_cache;
412414
call_java_cache = clp;
413415
}
@@ -7098,9 +7100,9 @@ output_java_call (struct cb_call *p)
70987100
char *last_dot;
70997101
char *method_name;
71007102
const char *class_name;
7101-
char method_signature[256] = "(";
7103+
char method_signature[2048] = "(";
71027104
char* mangled;
7103-
struct cb_tree *ptr;
7105+
struct cb_tree_common *ptr;
71047106

71057107
mangled = strdup(class_and_method_name);
71067108
for (size_t i = 0; i < strlen(mangled) + 1; i++) {
@@ -7110,43 +7112,31 @@ output_java_call (struct cb_call *p)
71107112
last_dot = strrchr(class_and_method_name, '.');
71117113
if (last_dot == NULL) {
71127114
cobc_err_msg (_("malformed call '%s' to a Java method"), class_and_method_name);
7113-
COBC_ABORT ();
7115+
return;
71147116
}
71157117

71167118
*last_dot = '\0';
71177119
method_name = last_dot + 1;
71187120
class_name = class_and_method_name;
71197121

7120-
for(ptr = p->args; ptr != NULL; ptr = ptr->next) {
7122+
for (int i = 0; (ptr = ((struct cb_tree_common **)p->args)[i]) != NULL; i++) {
71217123
switch(CB_TREE_TAG(ptr)) {
71227124
case CB_TAG_INTEGER:
71237125
strcat(method_signature, "I");
71247126
break;
7125-
case CB_TAG_LONG:
7126-
strcat(method_signature, "J");
7127-
break;
7128-
case CB_TAG_FLOAT:
7127+
case CB_USAGE_FLOAT:
71297128
strcat(method_signature, "F");
71307129
break;
7131-
case CB_TAG_DOUBLE:
7130+
case CB_USAGE_DOUBLE:
71327131
strcat(method_signature, "D");
71337132
break;
7134-
case CB_TAG_BOOLEAN:
7133+
case CB_CLASS_BOOLEAN:
71357134
strcat(method_signature, "Z");
71367135
break;
7137-
case CB_TAG_BYTE:
7138-
strcat(method_signature, "B");
7139-
break;
7140-
case CB_TAG_SHORT:
7141-
strcat(method_signature, "S");
7142-
break;
7143-
case CB_TAG_CHAR:
7144-
strcat(method_signature, "C");
7145-
break;
71467136
case CB_TAG_STRING:
71477137
strcat(method_signature, "Ljava/lang/String;");
71487138
break;
7149-
case CB_TAG_OBJECT:
7139+
case CB_USAGE_OBJECT:
71507140
strcat(method_signature, "Ljava/lang/Object;");
71517141
break;
71527142
case CB_TAG_LITERAL:
@@ -7156,64 +7146,56 @@ output_java_call (struct cb_call *p)
71567146
strcat(method_signature, "Ljava/lang/String;");
71577147
}
71587148
break;
7159-
case CB_TAG_ARRAY:
7160-
switch(CB_TREE_TAG(CB_TREE(ptr)->next)) {
7161-
case CB_TAG_INTEGER:
7162-
strcat(method_signature, "[I");
7163-
break;
7164-
case CB_TAG_LONG:
7165-
strcat(method_signature, "[J");
7166-
break;
7167-
case CB_TAG_FLOAT:
7168-
strcat(method_signature, "[F");
7169-
break;
7170-
case CB_TAG_DOUBLE:
7171-
strcat(method_signature, "[D");
7172-
break;
7173-
case CB_TAG_BOOLEAN:
7174-
strcat(method_signature, "[Z");
7175-
break;
7176-
case CB_TAG_BYTE:
7177-
strcat(method_signature, "[B");
7178-
break;
7179-
case CB_TAG_SHORT:
7180-
strcat(method_signature, "[S");
7181-
break;
7182-
case CB_TAG_CHAR:
7183-
strcat(method_signature, "[C");
7184-
break;
7185-
case CB_TAG_STRING:
7186-
strcat(method_signature, "[Ljava/lang/String;");
7187-
break;
7188-
case CB_TAG_OBJECT:
7189-
strcat(method_signature, "[Ljava/lang/Object;");
7190-
break;
7191-
default:
7192-
cobc_err_msg(_("Unsupported array type in Java method call"));
7193-
COBC_ABORT();
7194-
}
7195-
break;
7196-
default:
7197-
cobc_err_msg(_("Unsupported argument type in Java method call"));
7198-
COBC_ABORT();
7199-
}
7149+
case CB_TAG_LIST:
7150+
{
7151+
struct cb_tree_common **list_elements = (struct cb_tree_common **) ptr;
7152+
for (int j = 0; list_elements[j] != NULL; j++) {
7153+
switch (CB_TREE_TAG(list_elements[j])) {
7154+
case CB_TAG_INTEGER:
7155+
strcat(method_signature, "[I");
7156+
break;
7157+
case CB_USAGE_FLOAT:
7158+
strcat(method_signature, "[F");
7159+
break;
7160+
case CB_USAGE_DOUBLE:
7161+
strcat(method_signature, "[D");
7162+
break;
7163+
case CB_CLASS_BOOLEAN:
7164+
strcat(method_signature, "[Z");
7165+
break;
7166+
case CB_TAG_STRING:
7167+
strcat(method_signature, "[Ljava/lang/String;");
7168+
break;
7169+
case CB_USAGE_OBJECT:
7170+
strcat(method_signature, "[Ljava/lang/Object;");
7171+
break;
7172+
default:
7173+
cobc_err_msg(_("Unsupported array type in Java method call"));
7174+
COBC_ABORT();
7175+
}
7176+
}
7177+
}
7178+
break;
7179+
default:
7180+
cobc_err_msg(_("Unsupported argument type in Java method call"));
7181+
COBC_ABORT();
7182+
}
72007183
}
72017184

72027185
strcat(method_signature, ")V");
72037186

7204-
lookup_java_call(mangled);
7187+
lookup_java_call(mangled, method_signature);
72057188
output_line("if (call_java_%s == NULL)", mangled);
72067189
output_block_open();
72077190

72087191
output_prefix();
72097192
output_line("call_java_%s = ", mangled);
7210-
output("cob_resolve_java(\"%s\", \"%s\", \"()V\");", class_name, method_name, method_signature);
7193+
output("cob_resolve_java(\"%s\", \"%s\", \"%s\", \"()V\");", class_name, method_name, method_signature);
72117194
output_newline ();
72127195
output_prefix ();
72137196
output_line("cob_call_java(call_java_%s);\n", mangled);
72147197
output_newline();
72157198
output_block_close();
7216-
cobc_free(mangled);
72177199
}
72187200

72197201
static void

0 commit comments

Comments
 (0)