Skip to content

Commit 8ab6d15

Browse files
committed
リファクタリングを実施した
1 parent 205409b commit 8ab6d15

File tree

6 files changed

+49
-472
lines changed

6 files changed

+49
-472
lines changed

cobc/codegen.c

Lines changed: 32 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,7 @@ joutput_line (const char *fmt, ...)
354354
if(joutput_target) {
355355
if(joutput_buffered) {
356356
joutput_prefix ();
357-
//本当は以下のように書きたいがうまく行かないので
358-
//va_start (ap, fmt);
359-
//joutput (fmt, ap);
360-
//va_end (ap);
361357

362-
// joutputのコードを直接引っ張ってきた
363358
va_start (ap, fmt);
364359
size = vsprintf (joutput_temp_buffer, fmt, ap);
365360
va_end (ap);
@@ -1849,36 +1844,18 @@ joutput_initialize_literal (cb_tree x, struct cb_field *f, struct cb_literal *l)
18491844
return;
18501845
}
18511846
if (l->size >= f->size) {
1852-
//TODO 要テスト
1853-
//joutput_prefix ();
1854-
//joutput ("LIBCOB.memcpy (");
1855-
//joutput_data (x);
1856-
//joutput (", ");
1857-
//joutput_string (l->data, f->size);
1858-
//joutput (", %d);\n", f->size);
1859-
joutput_prefix ();
1847+
joutput_prefix ();
18601848
joutput_data (x);
18611849
joutput ("memcpy (");
18621850
joutput_string (l->data, f->size);
18631851
joutput (".getBytes(), %d);\n", f->size);
1864-
18651852
return;
18661853
}
18671854
i = f->size / l->size;
18681855
i_counters[0] = 1;
18691856

1870-
//TODO 要テスト
1871-
//joutput_line ("for (i0 = 0; i0 < %u; i0++)", (unsigned int)i);
1872-
//joutput_indent (" {");
1873-
//joutput_prefix ();
1874-
//joutput ("LIBCOB.memcpy (");
1875-
//joutput_data (x);
1876-
//joutput (" + (i0 * %u), ", (unsigned int)l->size);
1877-
//joutput_string (l->data, l->size);
1878-
//joutput (", %u);\n", (unsigned int)l->size);
1879-
//joutput_indent (" }");
1880-
1881-
joutput_line ("for (i0 = 0; i0 < %u; i0++)", (unsigned int)i);
1857+
1858+
joutput_line ("for (i0 = 0; i0 < %u; i0++)", (unsigned int)i);
18821859
joutput_indent (" {");
18831860
joutput_prefix ();
18841861
joutput_data (x);
@@ -1891,13 +1868,6 @@ joutput_initialize_literal (cb_tree x, struct cb_field *f, struct cb_literal *l)
18911868
n = f->size % l->size;
18921869
if (n) {
18931870
joutput_prefix ();
1894-
//TODO 要テスト
1895-
//joutput ("LIBCOB.memcpy (");
1896-
//joutput_data (x);
1897-
//joutput (" + (i0 * %u), ", (unsigned int)l->size);
1898-
//joutput_string (l->data, n);
1899-
//joutput (", %u);\n", (unsigned int)n);
1900-
19011871
joutput_data (x);
19021872
joutput (".getSubDataStorage(i0 * %u).memcpy(", (unsigned int)l->size);
19031873
joutput_string (l->data, n);
@@ -2520,10 +2490,6 @@ joutput_call (struct cb_call *p)
25202490
case CB_CALL_BY_REFERENCE:
25212491
if (CB_NUMERIC_LITERAL_P (x) || CB_BINARY_OP_P (x)) {
25222492
joutput_line ("CobolCallDataContent content_%d = new CobolCallDataContent(8);", (int)n);
2523-
//joutput_line ("\tpublic CobolDataStorage data = new CobolDataStorage(8);");
2524-
//joutput_line ("\tpublic long datall;");
2525-
//joutput_line ("\tpublic int dataint;");
2526-
//joutput_line ("};");
25272493
} else if (CB_CAST_P (x)) {
25282494
joutput_line ("void *ptr_%d;", (int)n);
25292495
}
@@ -2533,9 +2499,8 @@ joutput_call (struct cb_call *p)
25332499
joutput_line ("void *ptr_%d;", (int)n);
25342500
} else if (CB_TREE_TAG (x) != CB_TAG_INTRINSIC &&
25352501
x != cb_null && !(CB_CAST_P (x))) {
2536-
joutput_prefix();
2502+
joutput_prefix();
25372503
joutput ("CobolCallDataContent content_%d = new CobolCallDataContent (", (int)n);
2538-
//joutput ("\tpublic CobolDataStorage data = new CobolDataStorage(");
25392504
if (CB_NUMERIC_LITERAL_P (x) ||
25402505
CB_BINARY_OP_P (x) || CB_CAST_P(x)) {
25412506
joutput ("8");
@@ -2547,9 +2512,6 @@ joutput_call (struct cb_call *p)
25472512
}
25482513
}
25492514
joutput_line (");");
2550-
//joutput_line ("\tlong datall;");
2551-
//joutput_line ("\tint dataint;");
2552-
//joutput_line ("};");
25532515
}
25542516
break;
25552517
}
@@ -2977,24 +2939,18 @@ joutput_goto (struct cb_goto *p)
29772939
} else if (p->target == NULL) {
29782940
needs_exit_prog = 1;
29792941
if (cb_flag_implicit_init) {
2980-
//joutput_line ("goto exit_program;");
2981-
//joutput_line ("CobolGoBackException.throwException(0);");
2982-
joutput_line("entryFunc(-10);");
2983-
joutput_line("if(true) return false;");
2942+
joutput_line("entryFunc(-10);");
2943+
joutput_line("if(true) return false;");
29842944
} else {
29852945
joutput_line ("if (!CobolModule.isQueueEmpty()) {");
2986-
joutput_line (" entryFunc(-10);");
2987-
joutput_line (" if(true) return false;");
2988-
joutput_line ("}");
2989-
//joutput_line (" goto exit_program;");
2990-
//joutput_line (" CobolGoBackException.throwException(0);");
2946+
joutput_line (" entryFunc(-10);");
2947+
joutput_line (" if(true) return false;");
2948+
joutput_line ("}");
29912949
}
29922950
} else if (p->target == cb_int1) {
29932951
needs_exit_prog = 1;
2994-
//joutput_line ("goto exit_program;");
2995-
//joutput_line ("CobolGoBackException.throwException(0);");
2996-
joutput_line("entryFunc(-10);");
2997-
joutput_line("if(true) return false;");
2952+
joutput_line("entryFunc(-10);");
2953+
joutput_line("if(true) return false;");
29982954
} else {
29992955
joutput_goto_1 (p->target);
30002956
}
@@ -3168,11 +3124,7 @@ joutput_perform (struct cb_perform *p)
31683124
}
31693125
break;
31703126
case CB_PERFORM_ONCE:
3171-
//joutput_line("do {");
3172-
//joutput_indent_level += 2;
31733127
joutput_perform_once (p);
3174-
//joutput_indent_level -= 2;
3175-
//joutput_line("} while(false);");
31763128
break;
31773129
case CB_PERFORM_TIMES:
31783130
joutput_prefix ();
@@ -3576,17 +3528,8 @@ joutput_stmt (cb_tree x)
35763528
}
35773529
}
35783530

3579-
//ggggg
35803531
if (lp->need_begin) {
35813532
joutput_next_buffer(lp->id);
3582-
//int tmp = joutput_buffered;
3583-
//joutput_buffered = 0;
3584-
//joutput_line ("LABEL_%d();", lp->id);
3585-
//joutput_buffered = tmp;
3586-
3587-
//JavaではLabelを使用しないので削除した
3588-
//joutput_newline ();
3589-
//joutput_line ("%s%d:;", CB_PREFIX_LABEL, lp->id);
35903533
}
35913534
if (cb_flag_trace) {
35923535
if (lp->is_section) {
@@ -3677,10 +3620,10 @@ joutput_stmt (cb_tree x)
36773620
/* Numeric assignment */
36783621
joutput_prefix ();
36793622

3680-
int tmp_flag = integer_reference_flag;
3681-
integer_reference_flag = 1;
3623+
int tmp_flag = integer_reference_flag;
3624+
integer_reference_flag = 1;
36823625
joutput_integer (ap->var);
3683-
integer_reference_flag = tmp_flag;
3626+
integer_reference_flag = tmp_flag;
36843627
joutput (".set(");
36853628
++index_read_flag;
36863629
joutput_integer (ap->val);
@@ -3701,10 +3644,10 @@ joutput_stmt (cb_tree x)
37013644

37023645
int tmp_flag = integer_reference_flag;
37033646
integer_reference_flag = 1;
3704-
joutput_integer (ap->var);
3647+
joutput_integer (ap->var);
37053648
integer_reference_flag = tmp_flag;
37063649

3707-
joutput (".set(");
3650+
joutput (".set(");
37083651

37093652
f = cb_field(ap->var);
37103653
if(f->usage == CB_USAGE_BINARY ||
@@ -3875,8 +3818,6 @@ joutput_file_initialization (struct cb_file *f)
38753818
}
38763819
joutput_line ("if (%s%s == null)", CB_PREFIX_KEYS, f->cname);
38773820
joutput_indent ("{");
3878-
/*joutput_line ("%s%s = cob_malloc (sizeof (struct cob_file_key) * %d);",
3879-
CB_PREFIX_KEYS, f->cname, nkeys);*/
38803821
joutput_line ("%s%s = new CobolFileKey[%d];",
38813822
CB_PREFIX_KEYS, f->cname, nkeys);
38823823
joutput_line ("for (int i=0; i<%d; ++i)", nkeys);
@@ -4503,8 +4444,8 @@ joutput_internal_function (struct cb_program *prog, cb_tree parameter_list)
45034444
}
45044445

45054446
joutput_line ("this.initialized = true;");
4506-
joutput_indent_level -= 2;
4507-
joutput_line ("}");
4447+
joutput_indent_level -= 2;
4448+
joutput_line ("}");
45084449
//if (prog->flag_chained) {
45094450
// joutput (" } else {\n");
45104451
// joutput_line (" cob_fatal_error (COB_FERROR_CHAINING);");
@@ -4853,9 +4794,6 @@ joutput_internal_function (struct cb_program *prog, cb_tree parameter_list)
48534794
//joutput_line ("\tgoto LRET_initextern;/*1*/");
48544795
}
48554796

4856-
//output_indent ("}");
4857-
//output_newline ();
4858-
48594797
joutput_line ("/* Program return */");
48604798
joutput_prefix ();
48614799
joutput ("return ");
@@ -5384,7 +5322,7 @@ void joutput_declare_member_variables(struct cb_program *prog, cb_tree parameter
53845322
CB_PREFIX_BASE, cb_field (CB_VALUE (l))->id);
53855323
}
53865324

5387-
/* External items */
5325+
/* External items */
53885326
for (f = prog->working_storage; f; f = f->sister) {
53895327
if (f->flag_external) {
53905328
strcpy (name, f->name);
@@ -5468,7 +5406,7 @@ joutput_label_function()
54685406
joutput_line("public boolean LABEL_DEFAULT() throws CobolRuntimeException, CobolGoBackException, CobolStopRunException {");
54695407
} else if(buf.label == L_initextern_addr) {
54705408
joutput_line("public boolean LABEL_%d() {", buf.label);
5471-
} else {
5409+
} else {
54725410
joutput_line("public boolean LABEL_%d() throws CobolRuntimeException, CobolGoBackException, CobolStopRunException {", buf.label);
54735411
}
54745412

@@ -5495,13 +5433,13 @@ joutput_entry_function()
54955433
joutput_line("case %d:", buf.label);
54965434
joutput_line("continueFlag = LABEL_%d();", buf.label);
54975435
}
5498-
if(i < joutput_buffer_list_index && joutput_buffer_list[i + 1].label == 1) {
5499-
joutput_line("return;");
5500-
} else {
5501-
joutput_line("if(!continueFlag) break;", buf.label);
5502-
}
5436+
if(i < joutput_buffer_list_index && joutput_buffer_list[i + 1].label == 1) {
5437+
joutput_line("return;");
5438+
} else {
5439+
joutput_line("if(!continueFlag) break;", buf.label);
5440+
}
55035441
}
5504-
joutput_line("case -10: break;");
5442+
joutput_line("case -10: break;");
55055443
joutput_indent_level -= 4;
55065444
joutput_line(" }");
55075445
joutput_line("}");
@@ -5626,7 +5564,7 @@ codegen (struct cb_program *prog, const int nested, char** program_id_list)
56265564
joutput_target = yyout;
56275565
char java_file_name[64];
56285566
sprintf(java_file_name, "%s.java", prog->program_id);
5629-
*program_id_list = prog->program_id;
5567+
*program_id_list = prog->program_id;
56305568
joutput_target = fopen(java_file_name, "w");
56315569

56325570
if (!nested) {
@@ -5986,11 +5924,11 @@ codegen (struct cb_program *prog, const int nested, char** program_id_list)
59865924
joutput_indent ("(byte)0xE1, (byte)0x8F, (byte)0x46, (byte)0x75, (byte)0xFD, (byte)0xEB, (byte)0xEE, (byte)0xED,");
59875925
joutput_indent ("(byte)0x90, (byte)0xEF, (byte)0xB3, (byte)0xFB, (byte)0xB9, (byte)0xEA, (byte)0xBB, (byte)0xFF");
59885926

5989-
joutput_indent_level -= 2;
5927+
joutput_indent_level -= 2;
59905928
joutput_indent ("};\n");
59915929

59925930
i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
5993-
joutput(" ");
5931+
joutput(" ");
59945932
joutput
59955933
("private static AbstractCobolField f_ebcdic = CobolFieldFactori.makeField(256, new CobolDataStorage(cob_ebcdic), %s%d);\n",
59965934
CB_PREFIX_ATTR, i);
@@ -6033,11 +5971,11 @@ codegen (struct cb_program *prog, const int nested, char** program_id_list)
60335971
joutput_indent ("(byte)0x30, (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x37,");
60345972
joutput_indent ("(byte)0x38, (byte)0x39, (byte)0xDB, (byte)0xFB, (byte)0x9A, (byte)0xF4, (byte)0xEA, (byte)0xFF");
60355973

6036-
joutput_indent_level -= 2;
5974+
joutput_indent_level -= 2;
60375975
joutput_indent ("};\n");
60385976

60395977
i = lookup_attr (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL, 0);
6040-
joutput(" ");
5978+
joutput(" ");
60415979
joutput
60425980
("private static AbstractCobolField f_ebcdic_ascii = CobolFieldFactory.makeField(256, new CobolDataStorage(cob_ebcdic_ascii), %s%d);\n",
60435981
CB_PREFIX_ATTR, i);
@@ -6046,7 +5984,7 @@ codegen (struct cb_program *prog, const int nested, char** program_id_list)
60465984
if (gen_native) {
60475985
joutput_indent ("\n/* NATIVE table */\n");
60485986
joutput_indent ("private static final byte[] cob_native = {");
6049-
joutput_indent_level += 2;
5987+
joutput_indent_level += 2;
60505988
joutput_indent ("(byte)0, (byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7,");
60515989
joutput_indent ("(byte)8, (byte)9, (byte)10, (byte)11, (byte)12, (byte)13, (byte)14, (byte)15,");
60525990
joutput_indent ("(byte)16, (byte)17, (byte)18, (byte)19, (byte)20, (byte)21, (byte)22, (byte)23,");

libcobj/src/jp/osscons/opensourcecobol/libcobj/data/AbstractCobolField.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -756,22 +756,6 @@ private AbstractCobolField numericFieldToNumericDisplayField(AbstractCobolField
756756
return field;
757757
}
758758

759-
/*public int compareInt(int n) {
760-
CobolDecimal cobD1 = this.getDecimal();
761-
CobolDecimal cobD2 = new CobolDecimal(n);
762-
cobD2.setScale(0);
763-
return cobD1.compareTo(cobD2);
764-
}
765-
766-
protected int compareChar(int c) {
767-
int sign = this.getSign();
768-
int ret = commonCmpc(this.getDataStorage(), c, this.getSize());
769-
if(this.getAttribute().isTypeNumericPacked()) {
770-
this.putSign(sign);
771-
}
772-
return ret;
773-
}*/
774-
775759
/**
776760
* libcob/common.cのcommon_cmpcの実装
777761
* @param s1

libcobj/src/jp/osscons/opensourcecobol/libcobj/data/CobolDecimal.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -721,30 +721,4 @@ public static void numByteMemcpy(CobolDataStorage s1, int s1StartIndex, CobolDat
721721
s1.setByte(i1++, s2.getByte(i2++));
722722
} while(--size != 0);
723723
}
724-
725-
/*
726-
CobolDataStorage data = f.getDataStorage();
727-
int firstDataIndex = f.getFirstDataIndex();
728-
int size = f.getFieldSize();
729-
730-
if(data.getByte(firstDataIndex) == 255) {
731-
this.value = BigDecimal.TEN.pow(size);
732-
this.setScale(f.getAttribute().getScale());
733-
return;
734-
}
735-
736-
if(data.getByte(firstDataIndex) == 255) {
737-
this.value = BigDecimal.TEN.pow(size);
738-
this.value = this.value.negate();
739-
this.setScale(f.getAttribute().getScale());
740-
return;
741-
}
742-
743-
int sign = f.getSign();
744-
int i = 0;
745-
while(size > 1 && data.getByte(firstDataIndex + i) == '0') {
746-
size--;
747-
i++;
748-
}
749-
*/
750724
}

0 commit comments

Comments
 (0)