Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 31 additions & 56 deletions cobj/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,40 +853,32 @@ static void joutput_base(struct cb_field *f) {
// EDIT
/* Base name */
strcpy_identifier_cobol_to_java(name, top->name);
if (!top->flag_external) {
register_data_storage_list(f, top);
}

register_data_storage_list(f, top);

if (!top->flag_base) {
if (!top->flag_external) {
if (!top->flag_local || top->flag_is_global) {
bl = cobc_malloc(sizeof(struct base_list));
bl->f = top;
bl->curr_prog = excp_current_program_id;
bl->next = base_cache;
base_cache = bl;
if (!top->flag_local || top->flag_is_global) {
bl = cobc_malloc(sizeof(struct base_list));
bl->f = top;
bl->curr_prog = excp_current_program_id;
bl->next = base_cache;
base_cache = bl;
} else {
if (current_prog->flag_global_use) {
joutput_local("unsigned char\t\t*%s%s = NULL;", CB_PREFIX_BASE, name);
joutput_local("\t/* %s */\n", top->name);
joutput_local("static unsigned char\t*save_%s%s;\n", CB_PREFIX_BASE,
name);
} else {
if (current_prog->flag_global_use) {
joutput_local("unsigned char\t\t*%s%s = NULL;", CB_PREFIX_BASE, name);
joutput_local("unsigned char\t\t*%s%s = NULL;", CB_PREFIX_BASE, name);
joutput_local("\t/* %s */\n", top->name);
joutput_local("static unsigned char\t*save_%s%s;\n", CB_PREFIX_BASE,
name);
} else {
joutput_local("unsigned char\t*%s%s = NULL;", CB_PREFIX_BASE, name);
joutput_local("\t/* %s */\n", top->name);
}
joutput_local("unsigned char\t*%s%s = NULL;", CB_PREFIX_BASE, name);
joutput_local("\t/* %s */\n", top->name);
}
}
top->flag_base = 1;
}

if (top->flag_external) {
joutput("%s%s", CB_PREFIX_BASE, name);
} else {
if (joutput_field_storage(f, top) && f->offset != 0) {
joutput(".getSubDataStorage(%d)", f->offset);
}
if (joutput_field_storage(f, top) && f->offset != 0) {
joutput(".getSubDataStorage(%d)", f->offset);
}

if (cb_field_variable_address(f)) {
Expand Down Expand Up @@ -2260,14 +2252,14 @@ static void joutput_initialize_external(cb_tree x, struct cb_field *f) {
joutput_prefix();
joutput_data(x);
if (f->ename) {
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", f->ename,
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->ename,
f->size);
} else if (f->storage == CB_STORAGE_FILE) {
file = CB_TREE(f->file);
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n",
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);",
CB_FILE(file)->record->name, f->size);
} else {
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);\n", f->name,
joutput(" = CobolExternal.getStorageAddress (\"%s\", %d);", f->name,
f->size);
}
}
Expand Down Expand Up @@ -2597,12 +2589,6 @@ static void joutput_initialize(struct cb_initialize *p) {
int c;

f = cb_field(p->var);
if (f->flag_external) {
joutput_initialize_external(p->var, f);
if (!p->flag_statement) {
return;
}
}
switch (initialize_type(p, f, 1)) {
case INITIALIZE_NONE:
break;
Expand All @@ -2622,6 +2608,7 @@ static void joutput_initialize(struct cb_initialize *p) {
break;
}
}

/*
* SEARCH
*/
Expand Down Expand Up @@ -4240,6 +4227,10 @@ static void joutput_initial_values(struct cb_field *p) {
if (p->flag_no_init && !p->count) {
continue;
}
/* EXTERNAL items */
if (p->flag_external) {
continue;
}
int tmp_flag = integer_reference_flag;
integer_reference_flag = 1;
joutput_stmt(cb_build_initialize(x, cb_true, NULL, def, 0),
Expand Down Expand Up @@ -5079,6 +5070,11 @@ static void joutput_init_method(struct cb_program *prog) {
joutput_prefix();
joutput("%s = new CobolDataStorage(%d);", base_name,
blp->f->memory_size);
}

if (blp->f->flag_external) {
joutput_initialize_external(cb_build_field_reference(blp->f, NULL),
blp->f);
} else {
joutput_prefix();
joutput("%s = new CobolDataStorage(%d);", base_name,
Expand Down Expand Up @@ -5594,27 +5590,6 @@ static void joutput_declare_member_variables(struct cb_program *prog,
joutput("\n");
}

/* External items */
for (f = prog->working_storage; f; f = f->sister) {
if (f->flag_external) {
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) {
joutput_prefix();
joutput("private CobolDataStorage ");
joutput_base(f);
joutput(" = null; /* %s */", f->name);
joutput_newline();
}
}

/* AbstractCobolField型変数の宣言(非定数) */
if (field_cache) {
joutput_line("/* Fields */\n");
Expand Down
73 changes: 69 additions & 4 deletions tests/run.src/miscellaneous.at
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ AT_CLEANUP


AT_SETUP([EXTERNAL data item])
AT_CHECK([${SKIP_TEST}])

AT_DATA([callee.cob], [
IDENTIFICATION DIVISION.
Expand Down Expand Up @@ -122,7 +121,7 @@ AT_DATA([caller.cob], [

AT_CHECK([${COMPILE_MODULE} callee.cob])
AT_CHECK([${COMPILE} caller.cob])
AT_CHECK([java prog], [0],
AT_CHECK([${RUN_MODULE} caller], [0],
[Hello
World
])
Expand All @@ -131,7 +130,6 @@ AT_CLEANUP


AT_SETUP([EXTERNAL AS data item])
AT_CHECK([${SKIP_TEST}])

AT_DATA([callee.cob], [
IDENTIFICATION DIVISION.
Expand Down Expand Up @@ -168,14 +166,81 @@ AT_DATA([caller.cob], [

AT_CHECK([${COMPILE_MODULE} callee.cob])
AT_CHECK([${COMPILE} caller.cob])
AT_CHECK([java prog], [0],
AT_CHECK([${RUN_MODULE} caller], [0],
[Extrn
Hello
World
])

AT_CLEANUP

AT_SETUP([EXTERNAL group data item])

AT_DATA([prog.cbl], [
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A EXTERNAL.
03 A1 PIC X(5).
03 A2 PIC X(3).
03 A3.
05 A3-1 PIC 9(1).
05 A3-2 PIC 9(1).
PROCEDURE DIVISION.
MOVE "HELLO" TO A1.
MOVE "ABC" TO A2.
MOVE 12 TO A3.

DISPLAY A.
DISPLAY A1.
DISPLAY A2.
DISPLAY A3.

MOVE "DEF" TO A2.
DISPLAY A.

CALL "sub".

MOVE 5 TO A3-2.

DISPLAY A.

STOP RUN.
])

AT_DATA([sub.cbl], [
IDENTIFICATION DIVISION.
PROGRAM-ID. sub.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A EXTERNAL.
03 A1 PIC X(5).
03 A2 PIC X(3).
03 A3.
05 A3-1 PIC 9(1).
05 A3-2 PIC 9(1).
PROCEDURE DIVISION.
DISPLAY A.
MOVE 34 TO A3.
MOVE "WORLD" TO A1.
GOBACK.
])

AT_CHECK([${COBJ} prog.cbl])
AT_CHECK([${COBJ} sub.cbl])
AT_CHECK([java prog], [0],
[HELLOABC12
HELLO
ABC
12
HELLODEF12
HELLODEF12
WORLDDEF35
])

AT_CLEANUP


AT_SETUP([java command validation])

Expand Down