Skip to content

Commit 692b726

Browse files
Improve constant representaion (#768)
* chore: improve representaions of CobolFieldAttribute.type * chore: improve the representation of data flags * chore: add comments generations * add: CobolFieldAttribute.COB_FLAG_NOT_SPECIFIED * chore: add new lines * refactor: replace magic numbers * chore: format output code * refactor: use joutput_flags
1 parent 53e45ad commit 692b726

2 files changed

Lines changed: 115 additions & 4 deletions

File tree

cobj/codegen.c

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5027,6 +5027,92 @@ static void *list_cache_sort(void *inlist,
50275027
}
50285028
}
50295029

5030+
/**
5031+
* typeの値をCobolFieldAttributeの定数名に変換する
5032+
*/
5033+
static const char *get_type_constant_name(int type) {
5034+
switch (type) {
5035+
case COB_TYPE_UNKNOWN:
5036+
return "CobolFieldAttribute.COB_TYPE_UNKNOWN";
5037+
case COB_TYPE_GROUP:
5038+
return "CobolFieldAttribute.COB_TYPE_GROUP";
5039+
case COB_TYPE_BOOLEAN:
5040+
return "CobolFieldAttribute.COB_TYPE_BOOLEAN";
5041+
case COB_TYPE_NUMERIC_DISPLAY:
5042+
return "CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY";
5043+
case COB_TYPE_NUMERIC_BINARY:
5044+
return "CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY";
5045+
case COB_TYPE_NUMERIC_PACKED:
5046+
return "CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED";
5047+
case COB_TYPE_NUMERIC_FLOAT:
5048+
return "CobolFieldAttribute.COB_TYPE_NUMERIC_FLOAT";
5049+
case COB_TYPE_NUMERIC_DOUBLE:
5050+
return "CobolFieldAttribute.COB_TYPE_NUMERIC_DOUBLE";
5051+
case COB_TYPE_NUMERIC_EDITED:
5052+
return "CobolFieldAttribute.COB_TYPE_NUMERIC_EDITED";
5053+
case COB_TYPE_ALPHANUMERIC:
5054+
return "CobolFieldAttribute.COB_TYPE_ALPHANUMERIC";
5055+
case COB_TYPE_ALPHANUMERIC_ALL:
5056+
return "CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL";
5057+
case COB_TYPE_ALPHANUMERIC_EDITED:
5058+
return "CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_EDITED";
5059+
case COB_TYPE_NATIONAL:
5060+
return "CobolFieldAttribute.COB_TYPE_NATIONAL";
5061+
case COB_TYPE_NATIONAL_EDITED:
5062+
return "CobolFieldAttribute.COB_TYPE_NATIONAL_EDITED";
5063+
case COB_TYPE_NATIONAL_ALL:
5064+
return "CobolFieldAttribute.COB_TYPE_NATIONAL_ALL";
5065+
default:
5066+
return "CobolFieldAttribute.COB_TYPE_UNKNOWN";
5067+
}
5068+
}
5069+
5070+
/**
5071+
* flagsの値をCobolFieldAttributeのフラグ定数名の組み合わせとして出力する
5072+
* additional_indent: 2番目以降のフラグの前に付ける追加インデントのスペース数
5073+
*/
5074+
static void joutput_flags(int flags) {
5075+
if (flags == 0) {
5076+
joutput("CobolFieldAttribute.COB_FLAG_NOT_SPECIFIED");
5077+
return;
5078+
}
5079+
5080+
int first = 1;
5081+
int indent_increased = 0;
5082+
5083+
if (flags & COB_FLAG_HAVE_SIGN) {
5084+
joutput("CobolFieldAttribute.COB_FLAG_HAVE_SIGN");
5085+
first = 0;
5086+
}
5087+
5088+
#define HANDLE_FLAG(flag) \
5089+
if (flags & flag) { \
5090+
if (!first) { \
5091+
joutput_newline(); \
5092+
if (!indent_increased) { \
5093+
joutput_indent_level += 2; \
5094+
indent_increased = 1; \
5095+
} \
5096+
joutput_prefix(); \
5097+
joutput("| "); \
5098+
} \
5099+
joutput("CobolFieldAttribute." #flag); \
5100+
first = 0; \
5101+
}
5102+
5103+
HANDLE_FLAG(COB_FLAG_SIGN_SEPARATE)
5104+
HANDLE_FLAG(COB_FLAG_SIGN_LEADING)
5105+
HANDLE_FLAG(COB_FLAG_BLANK_ZERO)
5106+
HANDLE_FLAG(COB_FLAG_JUSTIFIED)
5107+
HANDLE_FLAG(COB_FLAG_BINARY_SWAP)
5108+
HANDLE_FLAG(COB_FLAG_REAL_BINARY)
5109+
HANDLE_FLAG(COB_FLAG_IS_POINTER)
5110+
5111+
if (indent_increased) {
5112+
joutput_indent_level -= 2;
5113+
}
5114+
}
5115+
50305116
/**
50315117
* メンバ変数の初期化を行うメソッドinitを出力する
50325118
*/
@@ -5270,9 +5356,29 @@ static void joutput_init_method(struct cb_program *prog) {
52705356
attr_cache = attr_list_reverse(attr_cache);
52715357
for (j = attr_cache; j; j = j->next) {
52725358
joutput_prefix();
5273-
joutput("%s%d = ", CB_PREFIX_ATTR, j->id);
5274-
joutput("new CobolFieldAttribute (%d, %d, %d, %d, ", j->type, j->digits,
5275-
j->scale, j->flags);
5359+
joutput("%s%d = new CobolFieldAttribute(", CB_PREFIX_ATTR, j->id);
5360+
joutput_newline();
5361+
joutput_indent_level += 2;
5362+
// type
5363+
joutput_prefix();
5364+
joutput("%s,", get_type_constant_name(j->type));
5365+
joutput_newline();
5366+
// digits
5367+
joutput_prefix();
5368+
joutput("/* digits= */ %d,", j->digits);
5369+
joutput_newline();
5370+
// scale
5371+
joutput_prefix();
5372+
joutput("/* scale= */ %d,", j->scale);
5373+
joutput_newline();
5374+
// flags
5375+
joutput_prefix();
5376+
joutput_flags(j->flags);
5377+
joutput(",");
5378+
joutput_newline();
5379+
// pic
5380+
joutput_prefix();
5381+
joutput("/* pic= */ ");
52765382
if (j->pic) {
52775383
joutput("\"");
52785384
unsigned char *s;
@@ -5288,7 +5394,9 @@ static void joutput_init_method(struct cb_program *prog) {
52885394
} else {
52895395
joutput("null");
52905396
}
5291-
joutput(");\n");
5397+
joutput(");");
5398+
joutput_newline();
5399+
joutput_indent_level -= 2;
52925400
}
52935401
}
52945402

libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/data/CobolFieldAttribute.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class CobolFieldAttribute {
7373

7474
/* field flags */
7575

76+
/** TODO: 準備中 */
77+
public static final int COB_FLAG_NOT_SPECIFIED = 0x00;
78+
7679
/** TODO: 準備中 */
7780
public static final int COB_FLAG_HAVE_SIGN = 0x01;
7881

0 commit comments

Comments
 (0)