From 922d9c1c89655b2198d0d05830d22be72958e621 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 7 May 2025 02:12:28 +0000 Subject: [PATCH 1/3] fix: conversion of variables of fd external --- cobj/codegen.c | 85 ++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index b6a22d51..6c4d9f24 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -840,13 +840,7 @@ static void joutput_base(struct cb_field *f) { // EDIT /* Base name */ if (top->flag_external) { - strcpy(name, top->name); - char *nmp; - for (nmp = name; *nmp; nmp++) { - if (*nmp == '-') { - *nmp = '_'; - } - } + strcpy_identifier_cobol_to_java(name, top->name); } else { register_data_storage_list(f, top); } @@ -2249,9 +2243,7 @@ static void joutput_initialize_fp(cb_tree x, struct cb_field *f) { } static void joutput_initialize_external(cb_tree x, struct cb_field *f) { - unsigned char *p; cb_tree file; - char name[COB_MINI_BUFF]; joutput_prefix(); joutput_data(x); @@ -2260,22 +2252,10 @@ static void joutput_initialize_external(cb_tree x, struct cb_field *f) { f->size); } else if (f->storage == CB_STORAGE_FILE) { file = CB_TREE(f->file); - strcpy(name, CB_FILE(file)->record->name); - for (p = (unsigned char *)name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", name, - f->size); + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", + CB_FILE(file)->record->name, f->size); } else { - strcpy(name, f->name); - for (p = (unsigned char *)name; *p; p++) { - if (islower(*p)) { - *p = (unsigned char)toupper(*p); - } - } - joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", name, + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", f->name, f->size); } } @@ -4401,13 +4381,11 @@ static void joutput_internal_function(struct cb_program *prog, cb_tree l; struct cb_field *f; struct cb_file *fl; - char *p; int i; // int n; int parmnum = 0; // int seen = 0; // int anyseen; - char name[COB_MINI_BUFF]; /* Program function */ // output ("static int\n%s_ (const int entry", prog->program_id); @@ -4654,15 +4632,11 @@ static void joutput_internal_function(struct cb_program *prog, for (l = prog->file_list; l; l = CB_CHAIN(l)) { f = CB_FILE(CB_VALUE(l))->record; if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput_line("%s%s = CobolExternal.getStorageAddress (\"%s\", %d);", - CB_PREFIX_BASE, name, name, - CB_FILE(CB_VALUE(l))->record_max); + joutput_prefix(); + joutput_base(f); + joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->name, + CB_FILE(CB_VALUE(l))->record_max); + joutput_newline(); } } joutput_initial_values(prog->working_storage); @@ -4752,15 +4726,10 @@ static void joutput_internal_function(struct cb_program *prog, for (l = prog->file_list; l; l = CB_CHAIN(l)) { f = CB_FILE(CB_VALUE(l))->record; if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput_line("%s%s = CobolExternal.getStorageAddress (\"%s\", %d);", - CB_PREFIX_BASE, name, name, - CB_FILE(CB_VALUE(l))->record_max); + joutput_prefix(); + joutput_base(f); + joutput_line(" = CobolExternal.getStorageAddress (\"%s\", %d);", + f->name, CB_FILE(CB_VALUE(l))->record_max); } } joutput_initial_values(prog->working_storage); @@ -5492,8 +5461,6 @@ static void joutput_declare_member_variables(struct cb_program *prog, struct base_list *blp; const char *prevprog; struct cb_field *f; - char *p; - char name[COB_MINI_BUFF]; /* CobolDecimal型変数の宣言 */ if (prog->decimal_index_max) { @@ -5611,27 +5578,21 @@ static void joutput_declare_member_variables(struct cb_program *prog, /* External items */ for (f = prog->working_storage; f; f = f->sister) { if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput("private CobolDataStorage\t%s%s = null;", CB_PREFIX_BASE, name); - joutput(" /* %s */\n", f->name); + joutput_prefix(); + joutput("private CobolDataStorage "); + joutput_base(f); + joutput(" = null; /* %s */", f->name); + joutput_newline(); } } for (l = prog->file_list; l; l = CB_CHAIN(l)) { f = CB_FILE(CB_VALUE(l))->record; if (f->flag_external) { - strcpy(name, f->name); - for (p = name; *p; p++) { - if (*p == '-') { - *p = '_'; - } - } - joutput("private CobolDataStorage\t%s%s = null;", CB_PREFIX_BASE, name); - joutput(" /* %s */\n", f->name); + joutput_prefix(); + joutput("private CobolDataStorage "); + joutput_base(f); + joutput(" = null; /* %s */", f->name); + joutput_newline(); } } From c1c61480b90eaddcc6240294fc5d9b7860de80a2 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 7 May 2025 07:27:37 +0000 Subject: [PATCH 2/3] test: add tests --- tests/misc.src/fd-external.at | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tests/misc.src/fd-external.at b/tests/misc.src/fd-external.at index 78c01f25..59376c1e 100644 --- a/tests/misc.src/fd-external.at +++ b/tests/misc.src/fd-external.at @@ -66,3 +66,105 @@ AT_CHECK([java prog], [0], ]) AT_CLEANUP + +AT_SETUP([FD EXTERNAL nihongo]) + +AT_DATA([prog1.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog1. + environment division. + input-output section. + file-control. + select f assign to 'file.txt' + organization is line sequential + access mode is sequential. + DATA DIVISION. + file section. + fd f is external. + 01 ab|P pic x(5). + working-storage section. + 01 ab|Q pic x(5) external. + PROCEDURE DIVISION. + initialize ab|P. + initialize ab|Q. + + open output f. + call "sub". + close f. + + open input f. + read f. + close f. + + display ab|P. + display ab|Q. + STOP RUN. +]) + +AT_DATA([prog2.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog2 is initial. + + environment division. + input-output section. + file-control. + select f assign to 'file.txt' + organization is line sequential + access mode is sequential. + DATA DIVISION. + file section. + fd f is external. + 01 ab|P pic x(5). + working-storage section. + 01 ab|Q pic x(5) external. + PROCEDURE DIVISION. + initialize ab|P. + initialize ab|Q. + + open output f. + call "sub". + close f. + + open input f. + read f. + close f. + + display ab|P. + display ab|Q. + STOP RUN. +]) + +AT_DATA([sub.cbl], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. sub. + environment division. + input-output section. + file-control. + select f assign to "file.txt" + organization is line sequential + access mode is sequential. + DATA DIVISION. + file section. + fd f is external. + 01 ab|P pic x(5). + working-storage section. + 01 ab|Q pic x(5) external. + PROCEDURE DIVISION. + move "abcde" to ab|P. + write ab|P. + move "12345" to ab|Q. + goback. +]) + +AT_CHECK([${COBJ} prog1.cbl prog2.cbl sub.cbl]) +AT_CHECK([java prog1], [0], +[abcde +12345 +]) + +AT_CHECK([java prog2], [0], +[abcde +12345 +]) + +AT_CLEANUP From 89ae5a1287c2e0285e0b448a8b94a035aef68ea7 Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Wed, 7 May 2025 07:57:06 +0000 Subject: [PATCH 3/3] fix: fix joutput_base slightly --- cobj/codegen.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cobj/codegen.c b/cobj/codegen.c index 6c4d9f24..dc90d557 100644 --- a/cobj/codegen.c +++ b/cobj/codegen.c @@ -839,9 +839,8 @@ static void joutput_base(struct cb_field *f) { // EDIT /* Base name */ - if (top->flag_external) { - strcpy_identifier_cobol_to_java(name, top->name); - } else { + strcpy_identifier_cobol_to_java(name, top->name); + if (!top->flag_external) { register_data_storage_list(f, top); }