Skip to content

Commit bd330cd

Browse files
New feature PROCEDURE DIVISION CHAINING (#796)
* feat: add new feature PROCEDURE DIVISION CHAINING * fix: CobolChainSetup -> chainSetup * test: add test for PROCEDURE DIVISION CHAINING
1 parent ee93012 commit bd330cd

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

cobj/codegen.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ static void joutput_initialize_one(struct cb_initialize *p, cb_tree x) {
23132313
/* CHAINING */
23142314
if (f->flag_chained) {
23152315
joutput_prefix();
2316-
joutput("cob_chain_setup (");
2316+
joutput("CobolUtil.chainSetUp (");
23172317
joutput_data(x);
23182318
joutput(", %d, %d);\n", f->param_num, f->size);
23192319
return;
@@ -5863,9 +5863,19 @@ static void joutput_declare_member_variables(struct cb_program *prog,
58635863
joutput_line("private AbstractCobolField %s;", field_name);
58645864
free(field_name);
58655865
}
5866-
char *base_name = get_java_identifier_base(cp->field);
5867-
joutput_line("private CobolDataStorage %s;", base_name);
5868-
free(base_name);
5866+
int in_base = 0;
5867+
struct base_list *bl;
5868+
for (bl = base_cache; bl; bl = bl->next) {
5869+
if (bl->f == cp->field) {
5870+
in_base = 1;
5871+
break;
5872+
}
5873+
}
5874+
if (!in_base) {
5875+
char *base_name = get_java_identifier_base(cp->field);
5876+
joutput_line("private CobolDataStorage %s;", base_name);
5877+
free(base_name);
5878+
}
58695879
}
58705880
}
58715881

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,32 @@ public static int getSourceLine() {
702702
public static String getSourceStatement() {
703703
return sourceStatement;
704704
}
705+
706+
/**
707+
* コマンドライン引数からCHAININGパラメータを設定する。
708+
*
709+
* @param data CHAININGパラメータのデータストレージ
710+
* @param parm パラメータのインデックス (1始まり)
711+
* @param size データストレージのサイズ
712+
*/
713+
public static void chainSetUp(CobolDataStorage data, int parm, int size) {
714+
data.memset((byte) ' ', size);
715+
// C版ではcob_argvのインデックス0にプログラム名が含まれるため、cob_argv[parm]で引数を取得する。
716+
// Javaではcommand_lineArgsにプログラム名が含まれないため、parm - 1を使用する。
717+
int index = parm - 1;
718+
if (CobolUtil.commandLineArgs != null && index < CobolUtil.commandLineArgs.length) {
719+
byte[] argBytes =
720+
CobolUtil.commandLineArgs[index].getBytes(AbstractCobolField.charSetSJIS);
721+
int len = argBytes.length;
722+
if (len <= size) {
723+
data.memcpy(argBytes, len);
724+
} else {
725+
data.memcpy(argBytes, size);
726+
}
727+
}
728+
// C版ではcob_call_params = cob_argc - 1 (プログラム名を除外)。
729+
// JavaではcommandLineArgs.lengthが既にプログラム名を除外した値になっている。
730+
CobolCallParams.callParams =
731+
(CobolUtil.commandLineArgs != null) ? CobolUtil.commandLineArgs.length : 0;
732+
}
705733
}

tests/run.src/extensions.at

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ X = X Y = 56 Z = 34
868868
AT_CLEANUP
869869

870870
AT_SETUP([PROCEDURE DIVISION CHAINING ...])
871-
AT_CHECK([${SKIP_TEST}])
872871

873872
AT_DATA([prog.cob], [
874873
IDENTIFICATION DIVISION.
@@ -888,11 +887,31 @@ AT_DATA([prog.cob], [
888887

889888
AT_CHECK([${COMPILE} prog.cob])
890889

890+
AT_CHECK([java prog], [0],
891+
[ @&t@
892+
@&t@
893+
])
894+
891895
AT_CHECK([java prog X ABCD], [0],
892896
[X
893897
ABCD
894898
])
895899

900+
AT_CHECK([java prog XY ABCDE], [0],
901+
[X
902+
ABCD
903+
])
904+
905+
AT_CHECK([java prog XY ABC], [0],
906+
[X
907+
ABC @&t@
908+
])
909+
910+
AT_CHECK([java prog 'XY' 'ABCD!!'], [0],
911+
[X
912+
ABCD
913+
])
914+
896915
AT_CLEANUP
897916

898917

0 commit comments

Comments
 (0)