-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Handling of Non-Void Java Method Calls in GnuCOBOL #174
base: java-interop
Are you sure you want to change the base?
Changes from 1 commit
452d4ec
7b31a0b
332e29c
1f90ff3
da1b85d
0013016
91751c8
8de4183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7100,6 +7100,7 @@ output_java_call (struct cb_call *p) | |||||||||||
char *last_dot; | ||||||||||||
char *method_name; | ||||||||||||
const char *class_name; | ||||||||||||
char return_type_signature[32]; | ||||||||||||
char method_signature[2048] = "("; | ||||||||||||
char* mangled; | ||||||||||||
struct cb_tree_common *ptr; | ||||||||||||
|
@@ -7146,34 +7147,50 @@ output_java_call (struct cb_call *p) | |||||||||||
strcat(method_signature, "Ljava/lang/String;"); | ||||||||||||
} | ||||||||||||
break; | ||||||||||||
case CB_TAG_LIST: | ||||||||||||
{ | ||||||||||||
struct cb_tree_common **list_elements = (struct cb_tree_common **) ptr; | ||||||||||||
for (int j = 0; list_elements[j] != NULL; j++) { | ||||||||||||
switch (CB_TREE_TAG(list_elements[j])) { | ||||||||||||
case CB_TAG_INTEGER: | ||||||||||||
strcat(method_signature, "[I"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_FLOAT: | ||||||||||||
strcat(method_signature, "[F"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_DOUBLE: | ||||||||||||
strcat(method_signature, "[D"); | ||||||||||||
break; | ||||||||||||
case CB_CLASS_BOOLEAN: | ||||||||||||
strcat(method_signature, "[Z"); | ||||||||||||
break; | ||||||||||||
case CB_TAG_STRING: | ||||||||||||
strcat(method_signature, "[Ljava/lang/String;"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_OBJECT: | ||||||||||||
strcat(method_signature, "[Ljava/lang/Object;"); | ||||||||||||
break; | ||||||||||||
default: | ||||||||||||
cobc_err_msg(_("Unsupported array type in Java method call")); | ||||||||||||
COBC_ABORT(); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
case CB_TAG_LIST: | ||||||||||||
{ | ||||||||||||
struct cb_tree_common **list_elements = (struct cb_tree_common **) ptr; | ||||||||||||
int array_dimension = 1; | ||||||||||||
|
||||||||||||
while (list_elements != NULL) { | ||||||||||||
struct cb_tree_common **inner_list = NULL; | ||||||||||||
for (int j = 0; list_elements[j] != NULL; j++) { | ||||||||||||
if (CB_TREE_TAG(list_elements[j]) == CB_TAG_LIST) { | ||||||||||||
array_dimension++; | ||||||||||||
inner_list = (struct cb_tree_common **) list_elements[j]; | ||||||||||||
} else { | ||||||||||||
switch (CB_TREE_TAG(list_elements[j])) { | ||||||||||||
case CB_TAG_INTEGER: | ||||||||||||
strcat(method_signature, "[I"); | ||||||||||||
break; | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of integer we further have to check the type per usage
Note that checking the TAGs and USAGEs and CLASSes in a single Also note that
For all of the types you have (after addition of the above) there needs to be a check for the occurs attribute ("more than 1 dimension" will already be checked in the conformance checks) and if existing just add As the valid types are identical for both arguments and returning items, their generation should be moved out to a static helper function called for each of the parameters (the loop here) and the returning item below. |
||||||||||||
case CB_USAGE_FLOAT: | ||||||||||||
strcat(method_signature, "[F"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_DOUBLE: | ||||||||||||
strcat(method_signature, "[D"); | ||||||||||||
break; | ||||||||||||
case CB_CLASS_BOOLEAN: | ||||||||||||
strcat(method_signature, "[Z"); | ||||||||||||
break; | ||||||||||||
case CB_TAG_STRING: | ||||||||||||
strcat(method_signature, "[Ljava/lang/String;"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_OBJECT: | ||||||||||||
strcat(method_signature, "[Ljava/lang/Object;"); | ||||||||||||
break; | ||||||||||||
default: | ||||||||||||
cobc_err_msg(_("Unsupported array element type in Java method call")); | ||||||||||||
COBC_ABORT(); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
list_elements = inner_list; | ||||||||||||
} | ||||||||||||
|
||||||||||||
if (array_dimension > 2) { | ||||||||||||
cobc_err_msg(_("Unsupported array dimension: %d"), array_dimension); | ||||||||||||
COBC_ABORT(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those two messages should be errors in |
||||||||||||
} | ||||||||||||
} | ||||||||||||
break; | ||||||||||||
default: | ||||||||||||
|
@@ -7182,6 +7199,38 @@ output_java_call (struct cb_call *p) | |||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
if (p->call_returning == NULL) { | ||||||||||||
strcat(method_signature, ")V"); | ||||||||||||
strcpy(return_type_signature, "void"); | ||||||||||||
} else { | ||||||||||||
switch(CB_TREE_TAG(p->call_returning)) { | ||||||||||||
case CB_TAG_INTEGER: | ||||||||||||
strcat(method_signature, ")I"); | ||||||||||||
strcpy(return_type_signature, "jint"); | ||||||||||||
break; | ||||||||||||
case CB_TAG_STRING: | ||||||||||||
strcat(method_signature, ")Ljava/lang/String;"); | ||||||||||||
strcpy(return_type_signature, "jstring"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_FLOAT: | ||||||||||||
strcat(method_signature, ")F"); | ||||||||||||
strcpy(return_type_signature, "jfloat"); | ||||||||||||
break; | ||||||||||||
case CB_USAGE_DOUBLE: | ||||||||||||
strcat(method_signature, ")D"); | ||||||||||||
strcpy(return_type_signature, "jdouble"); | ||||||||||||
break; | ||||||||||||
case CB_CLASS_BOOLEAN: | ||||||||||||
strcat(method_signature, ")Z"); | ||||||||||||
strcpy(return_type_signature, "jboolean"); | ||||||||||||
break; | ||||||||||||
default: | ||||||||||||
strcat(method_signature, ")V"); | ||||||||||||
strcpy(return_type_signature, "void"); | ||||||||||||
break; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
strcat(method_signature, ")V"); | ||||||||||||
|
||||||||||||
lookup_java_call(mangled, method_signature); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,11 +79,15 @@ resolve_java (const char *class_name, | |
cls = (*env)->FindClass(env, jni_class_name); | ||
free(jni_class_name); | ||
if (!cls) { | ||
(*env)->ExceptionDescribe(env); | ||
(*env)->ExceptionClear(env); | ||
Comment on lines
+82
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine during development, needs to be adjusted later - see review on the other PR |
||
return NULL; | ||
} | ||
|
||
mid = (*env)->GetStaticMethodID(env, cls, method_name, method_signature); | ||
if (!mid) { | ||
(*env)->ExceptionDescribe(env); | ||
(*env)->ExceptionClear(env); | ||
(*env)->DeleteLocalRef(env, cls); | ||
return NULL; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
COB_MINI_BUFF
andCOB_NORMAL_BUFF
for those and down usestrncat
with the_MAX
defines