Skip to content

Commit 909d25e

Browse files
Implement -fshort-variable option (#61)
1 parent 4b7074e commit 909d25e

File tree

7 files changed

+65
-2
lines changed

7 files changed

+65
-2
lines changed

cobj/codegen.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ get_java_identifier_field(struct cb_field* f) {
185185
char *buf = malloc(COB_SMALL_BUFF);
186186
if(cb_flag_serial_variable) {
187187
sprintf(buf, "%s%d", CB_PREFIX_FIELD, f->id);
188+
} else if(cb_flag_short_variable) {
189+
strcpy(buf, CB_PREFIX_FIELD);
190+
strcpy_identifier_cobol_to_java(buf + strlen(CB_PREFIX_FIELD), f->name);
188191
} else {
189192
strcpy(buf, CB_PREFIX_FIELD);
190193
get_java_identifier_helper(f, buf + strlen(CB_PREFIX_FIELD));
@@ -197,6 +200,9 @@ get_java_identifier_base(struct cb_field* f) {
197200
char *buf = malloc(COB_SMALL_BUFF);
198201
if(cb_flag_serial_variable) {
199202
sprintf(buf, "%s%d", CB_PREFIX_BASE, f->id);
203+
} else if(cb_flag_short_variable) {
204+
strcpy(buf, CB_PREFIX_BASE);
205+
strcpy_identifier_cobol_to_java(buf + strlen(CB_PREFIX_BASE), f->name);
200206
} else {
201207
strcpy(buf, CB_PREFIX_BASE);
202208
get_java_identifier_helper(f, buf + strlen(CB_PREFIX_BASE));

cobj/flag-help.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ CB_FLAG (cb_flag_syntax_only, "syntax-only",
3636

3737
CB_FLAG (cb_flag_serial_variable, "serial-variable",
3838
N_("Instead of embedding COBOL variable names in Java variable names, give them serial numbers."))
39+
40+
CB_FLAG (cb_flag_short_variable, "short-variable",
41+
N_("Use short variable names in Java source code. This feature may cause compilation errors"))

cobj/flag.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ CB_FLAG (cb_flag_null_param, "null-param",
7474

7575
CB_FLAG (cb_flag_serial_variable, "serial-variable",
7676
N_("Instead of embedding COBOL variable names in Java variable names, give them serial numbers."))
77+
78+
CB_FLAG (cb_flag_short_variable, "short-variable",
79+
N_("Use short variable names in Java source code. This feature may cause compilation errors"))

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ command_line_options_DEPENDENCIES = \
150150
command-line-options.src/Wunreachable.at \
151151
command-line-options.src/ftrace-ftraceall.at \
152152
command-line-options.src/fsyntax-only.at \
153-
command-line-options.src/fserial-variable.at
153+
command-line-options.src/fserial-variable.at \
154+
command-line-options.src/fshort-variable.at
154155

155156
misc_DEPENDENCIES = \
156157
misc.src/signed-comp3.at \

tests/Makefile.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ command_line_options_DEPENDENCIES = \
689689
command-line-options.src/Wunreachable.at \
690690
command-line-options.src/ftrace-ftraceall.at \
691691
command-line-options.src/fsyntax-only.at \
692-
command-line-options.src/fserial-variable.at
692+
command-line-options.src/fserial-variable.at \
693+
command-line-options.src/fshort-variable.at
693694

694695
misc_DEPENDENCIES = \
695696
misc.src/signed-comp3.at \

tests/command-line-options.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ m4_include([Wunreachable.at])
1212
m4_include([ftrace-ftraceall.at])
1313
m4_include([fsyntax-only.at])
1414
m4_include([fserial-variable.at])
15+
m4_include([fshort-variable.at])
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
AT_SETUP([-fshort-variable])
2+
3+
AT_DATA([prog.cbl], [
4+
identification division.
5+
program-id. prog.
6+
7+
data division.
8+
working-storage section.
9+
01 aa.
10+
03 bb pic x(2) value "bb".
11+
03 cc pic x(2) value "cc".
12+
03 dd.
13+
05 ee pic x(2) value "ee".
14+
03 ff pic 9(3) USAGE COMP-3 VALUE 5.
15+
03 gg pic 9(5) USAGE COMP-3.
16+
17+
procedure division.
18+
19+
display bb.
20+
display cc.
21+
display ee.
22+
23+
move ff to gg.
24+
display gg.
25+
])
26+
27+
AT_CHECK([${COBJ} --help | grep short-variable > /dev/null], [0])
28+
29+
AT_CHECK([${COBJ} -fshort-variable prog.cbl])
30+
AT_CHECK([${RUN_MODULE} prog], [0],
31+
[bb
32+
cc
33+
ee
34+
00005
35+
])
36+
AT_CHECK([cat prog.java | grep f_bb > /dev/null], [0])
37+
AT_CHECK([cat prog.java | grep f_cc > /dev/null], [0])
38+
AT_CHECK([cat prog.java | grep f_ee > /dev/null], [0])
39+
AT_CHECK([cat prog.java | grep f_ff > /dev/null], [0])
40+
AT_CHECK([cat prog.java | grep f_gg > /dev/null], [0])
41+
42+
AT_CHECK([cat prog.java | grep f_bb_of > /dev/null], [1])
43+
AT_CHECK([cat prog.java | grep f_cc_of > /dev/null], [1])
44+
AT_CHECK([cat prog.java | grep f_ee_of > /dev/null], [1])
45+
AT_CHECK([cat prog.java | grep f_ff_of > /dev/null], [1])
46+
AT_CHECK([cat prog.java | grep f_gg_of > /dev/null], [1])
47+
48+
AT_CLEANUP

0 commit comments

Comments
 (0)