Skip to content

Commit

Permalink
Fix check in cb_check_conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth committed Nov 12, 2024
1 parent 35e8c3b commit caf9f31
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 2 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
2024-08-14 Nicolas Berthier <[email protected]>

* cobc.c (cobc_print_info): added note for Java interoperability
* typeck.c, tree.h (cb_check_conformance): pass call convention to deal
with calls of Java methods

2024-08-04 David Declerck <[email protected]>

Expand Down
4 changes: 2 additions & 2 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -12257,13 +12257,13 @@ call_body:
if (strncasecmp("Java.", (char *)CB_LITERAL ($3)->data, 5) == 0) {
call_conv = CB_CONV_JAVA;
}
cb_check_conformance ($3, $7, $8);
cb_check_conformance ($3, $7, $8, call_conv);
} else if (CB_REFERENCE_P ($3)) {
cb_tree ref = cb_ref ($3);
if ((CB_FIELD_P (ref) && CB_FIELD (ref)->flag_item_78)
|| CB_PROGRAM_P (ref)
|| CB_PROTOTYPE_P (ref)) {
cb_check_conformance ($3, $7, $8);
cb_check_conformance ($3, $7, $8, call_conv);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cobc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,7 @@ extern cb_tree cb_build_write_advancing_lines (cb_tree, cb_tree);
extern cb_tree cb_build_write_advancing_mnemonic (cb_tree, cb_tree);
extern cb_tree cb_build_write_advancing_page (cb_tree);
extern cb_tree cb_check_sum_field (cb_tree x);
extern void cb_check_conformance (cb_tree, cb_tree, cb_tree);
extern void cb_check_conformance (cb_tree, cb_tree, cb_tree, int);
extern void cb_emit_initiate (cb_tree rep);
extern void cb_emit_terminate (cb_tree rep);
extern void cb_emit_generate (cb_tree rep);
Expand Down
34 changes: 19 additions & 15 deletions cobc/typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -3921,7 +3921,7 @@ check_argument_conformance (struct cb_program *program, cb_tree argument_tripple

void
cb_check_conformance (cb_tree prog_ref, cb_tree using_list,
cb_tree returning)
cb_tree returning, int call_conv)
{
struct cb_program *program = NULL;
cb_tree l;
Expand All @@ -3932,6 +3932,24 @@ cb_check_conformance (cb_tree prog_ref, cb_tree using_list,
const struct cb_field *prog_returning_field;
const struct cb_field *call_returning_field;

if (call_conv == CB_CONV_JAVA && CB_LITERAL_P (prog_ref)) {
char *full_name, *class_and_method_name, *dot;
full_name = (char *)CB_LITERAL(prog_ref)->data;
class_and_method_name = full_name + 5;
dot = strchr (class_and_method_name, '.');
if (dot == NULL) {
cb_error_x (prog_ref, _("malformed Java method name '%s', "
"expected format 'Java.ClassName.methodName'"),
full_name);
return;
}
if (using_list != NULL || returning != NULL) {
CB_PENDING ("Java method call with parameters or return values");
COBC_ABORT ();
}
return;
}

/* Try to get the program referred to by prog_ref. */
program = try_get_program (prog_ref);
if (!program) {
Expand All @@ -3943,20 +3961,6 @@ cb_check_conformance (cb_tree prog_ref, cb_tree using_list,
return;
}

if (CB_LITERAL_P(prog_ref)) {
char *full_name = (char *)CB_LITERAL(prog_ref)->data;
char *class_and_method_name = full_name + 5;
char *last_dot = strrchr(class_and_method_name, '.');
if (last_dot == NULL) {
cobc_err_msg(_("Malformed Java method name '%s'"), class_and_method_name);
return;
}
if (using_list != NULL || returning != NULL) {
CB_PENDING ("Java method call with parameters or return values");
COBC_ABORT ();
}
}

/*
Check each parameter is conformant: has right type, has right
REFERENCE/VALUE phrase, has right length, etc.
Expand Down

0 comments on commit caf9f31

Please sign in to comment.