Skip to content

Commit 0812eac

Browse files
Fix invalid Java code generation for fields after OCCURS DEPENDING ON (#799)
* fix: fix invalid Java code generation for fields after OCCURS DEPENDING ON * test: add test for OCCURS DEPENDING ON with complex-odo option * apply Copilot review * fix: codegen.c * test: add test for complex-odo.at --------- Co-authored-by: Yutaro Sakamoto <mail@yutaro-sakamoto.com>
1 parent b010d8b commit 0812eac

5 files changed

Lines changed: 364 additions & 7 deletions

File tree

cobj/codegen.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static int gen_native = 0;
6969
static int gen_custom = 0;
7070
static int field_iteration = 0;
7171
static int screenptr = 0;
72+
static int integer_reference_flag = 0;
7273

7374
static int i_counters[COB_MAX_SUBSCRIPTS];
7475

@@ -882,25 +883,38 @@ static void joutput_base(struct cb_field *f) {
882883
top->flag_base = 1;
883884
}
884885

885-
if (joutput_field_storage(f, top) && f->offset != 0) {
886+
if (joutput_field_storage(f, top) && f->offset != 0 &&
887+
!cb_field_variable_address(f)) {
886888
joutput(".getSubDataStorage(%d)", f->offset);
887889
}
888890

889891
if (cb_field_variable_address(f)) {
892+
int first_term = 1;
893+
joutput(".getSubDataStorage(");
890894
for (p = f->parent; p; f = f->parent, p = f->parent) {
891895
for (p = p->children; p != f; p = p->sister) {
892896
struct cb_field *v = cb_field_variable_size(p);
897+
898+
if (!first_term) {
899+
joutput(" + ");
900+
}
901+
first_term = 0;
902+
893903
if (v) {
894-
joutput(" + %d + ", v->offset - p->offset);
904+
joutput("%d + ", v->offset - p->offset);
895905
if (v->size != 1) {
896906
joutput("%d * ", v->size);
897907
}
908+
int tmp_flag = integer_reference_flag;
909+
integer_reference_flag = 0;
898910
joutput_integer(v->occurs_depending);
911+
integer_reference_flag = tmp_flag;
899912
} else {
900-
joutput(" + %d", p->size * p->occurs_max);
913+
joutput("%d", p->size * p->occurs_max);
901914
}
902915
}
903916
}
917+
joutput(")");
904918
}
905919
}
906920

@@ -1254,7 +1268,6 @@ static void joutput_const_identifier(struct literal_list *l) {
12541268
/*
12551269
* Integer
12561270
*/
1257-
static int integer_reference_flag = 0;
12581271
static void joutput_integer(cb_tree x) {
12591272
struct cb_binary_op *p;
12601273
struct cb_cast *cp;
@@ -5286,7 +5299,7 @@ static void joutput_init_method(struct cb_program *prog) {
52865299
char *base_name = get_java_identifier_base(entry->top);
52875300
joutput("%s", base_name);
52885301
free(base_name);
5289-
if (entry->f->offset != 0) {
5302+
if (entry->f->offset != 0 && !cb_field_variable_address(entry->f)) {
52905303
joutput(".getSubDataStorage(%d)", entry->f->offset);
52915304
}
52925305
joutput(";\n");

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ misc_DEPENDENCIES = \
268268
misc.src/display-inspect-sign.at \
269269
misc.src/comp1-comp2.at \
270270
misc.src/variable-length-file.at \
271-
misc.src/convert-string-concat.at
271+
misc.src/convert-string-concat.at \
272+
misc.src/complex-odo.at
272273

273274
EXTRA_DIST = $(srcdir)/package.m4 \
274275
$(TESTS) \

tests/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,8 @@ misc_DEPENDENCIES = \
817817
misc.src/display-inspect-sign.at \
818818
misc.src/comp1-comp2.at \
819819
misc.src/variable-length-file.at \
820-
misc.src/convert-string-concat.at
820+
misc.src/convert-string-concat.at \
821+
misc.src/complex-odo.at
821822

822823
EXTRA_DIST = $(srcdir)/package.m4 \
823824
$(TESTS) \

tests/misc.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ m4_include([display-inspect-sign.at])
5858
m4_include([comp1-comp2.at])
5959
m4_include([variable-length-file.at])
6060
m4_include([convert-string-concat.at])
61+
m4_include([complex-odo.at])

0 commit comments

Comments
 (0)