Skip to content

Commit ce27cbf

Browse files
fix comparison of COMP data (#559)
1 parent 6ffaf17 commit ce27cbf

File tree

3 files changed

+302
-37
lines changed

3 files changed

+302
-37
lines changed

cobj/typeck.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ static const char *const bin_set_funcs[] = {NULL,
114114
"setSwpS56Binary",
115115
"setSwpS64Binary"};
116116

117-
static const char *const bin_compare_funcs[] = {
118-
"cmpU8Binary", "cmpU16Binary", "cmpU24Binary", "cmpU32Binary",
119-
"cmpU40Binary", "cmpU48Binary", "cmpU56Binary", "cmpU64Binary",
120-
"cmpS8Binary", "cmpS16Binary", "cmpS24Binary", "cmpS32Binary",
121-
"cmpS40Binary", "cmpS48Binary", "cmpS56Binary", "cmpS64Binary",
122-
"cmpU8Binary", "cmpSwpU16Binary", "cmpSwpU24Binary", "cmpSwpU32Binary",
123-
"cmpSwpU40Binary", "cmpSwpU48Binary", "cmpSwpU56Binary", "cmpSwpU64Binary",
124-
"cmpS8Binary", "cmpSwpS16Binary", "cmpSwpS24Binary", "cmpSwpS32Binary",
125-
"cmpSwpS40Binary", "cmpSwpS48Binary", "cmpSwpS56Binary", "cmpSwpS64Binary"};
126-
127117
static const char *const bin_add_funcs[] = {
128118
"addU8Binary", "addU16Binary", "addU24Binary", "addU32Binary",
129119
"addU40Binary", "addU48Binary", "addU56Binary", "addU64Binary",
@@ -2245,18 +2235,18 @@ static cb_tree cb_build_optim_cond(struct cb_binary_op *p) {
22452235
if (!fy->pic->have_sign &&
22462236
(fy->usage == CB_USAGE_BINARY || fy->usage == CB_USAGE_COMP_5 ||
22472237
fy->usage == CB_USAGE_COMP_X)) {
2248-
return cb_build_method_call_2("cmpUint", p->x,
2238+
return cb_build_method_call_2("cmpInteger", p->x,
22492239
cb_build_cast_integer(p->y));
22502240
}
22512241
}
22522242
if (CB_REF_OR_FIELD_P(p->x)) {
22532243
struct cb_field *f = cb_field(p->x);
22542244
if (!f->pic->scale && f->usage == CB_USAGE_PACKED) {
22552245
if (f->pic->digits < 10) {
2256-
return cb_build_method_call_2("cmpInt", p->x,
2246+
return cb_build_method_call_2("cmpInteger", p->x,
22572247
cb_build_cast_integer(p->y));
22582248
} else {
2259-
return cb_build_method_call_2("cmpInt", p->x,
2249+
return cb_build_method_call_2("cmpInteger", p->x,
22602250
cb_build_cast_integer(p->y));
22612251
}
22622252
}
@@ -2287,16 +2277,12 @@ static cb_tree cb_build_optim_cond(struct cb_binary_op *p) {
22872277
if (!f->pic->scale &&
22882278
(f->usage == CB_USAGE_BINARY || f->usage == CB_USAGE_COMP_5 ||
22892279
f->usage == CB_USAGE_INDEX || f->usage == CB_USAGE_COMP_X)) {
2290-
size_t n = (f->size - 1) + (8 * (f->pic->have_sign ? 1 : 0)) +
2291-
(16 * (f->flag_binary_swap ? 1 : 0));
2292-
const char *s = bin_compare_funcs[n];
2293-
if (s) {
2294-
return cb_build_method_call_2(s, cb_build_cast_address(p->x),
2295-
cb_build_cast_integer(p->y));
2296-
}
2280+
return cb_build_method_call_2("cmpInteger", p->x,
2281+
cb_build_cast_integer(p->y));
22972282
}
22982283
}
2299-
return cb_build_method_call_2("cmpInt", p->x, cb_build_cast_integer(p->y));
2284+
return cb_build_method_call_2("cmpInteger", p->x,
2285+
cb_build_cast_integer(p->y));
23002286
}
23012287

23022288
static int cb_chk_num_cond(cb_tree x, cb_tree y) {

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,10 @@ public int divRemainder(int opt) throws CobolStopRunException {
414414
}
415415

416416
/**
417-
* TODO: 準備中
418-
*
419-
* @param n TODO: 準備中
420-
* @return TODO: 準備中
417+
* 整数値との比較を行う
418+
* @deprecated 代わりにcmpIntegerを使用してください
419+
* @param n 比較対象の整数値
420+
* @return 保持する数値データの比較を行い,this&lt;nなら負の値,this==nなら0,this&gt;nなら正の値
421421
*/
422422
public int cmpInt(int n) {
423423
CobolDecimal d1 = this.getDecimal();
@@ -427,30 +427,51 @@ public int cmpInt(int n) {
427427
}
428428

429429
/**
430-
* TODO: 準備中
431-
*
432-
* @param n TODO: 準備中
433-
* @return TODO: 準備中
430+
* 整数値との比較を行う
431+
* @deprecated 代わりにcmpIntegerを使用してください
432+
* @param n 比較対象の整数値
433+
* @return 保持する数値データの比較を行い,this&lt;nなら負の値,this==nなら0,this&gt;nなら正の値
434434
*/
435435
public int cmpInt(long n) {
436436
return this.cmpInt((int) n);
437437
}
438438

439439
/**
440-
* TODO: 準備中
441-
*
442-
* @param n TODO: 準備中
443-
* @return TODO: 準備中
440+
* 整数値との比較を行う
441+
* @param n 比較対象の整数値
442+
* @return 保持する数値データの比較を行い,this&lt;nなら負の値,this==nなら0,this&gt;nなら正の値
443+
*/
444+
public int cmpInteger(long n) {
445+
CobolDecimal d1 = this.getDecimal();
446+
CobolDecimal d2 = new CobolDecimal(n);
447+
d2.setScale(0);
448+
return d1.compareTo(d2);
449+
}
450+
451+
/**
452+
* 整数値との比較を行う
453+
* @param n 比較対象の整数値
454+
* @return 保持する数値データの比較を行い,this&lt;nなら負の値,this==nなら0,this&gt;nなら正の値
455+
*/
456+
public int cmpInteger(int n) {
457+
return this.cmpInteger((long) n);
458+
}
459+
460+
/**
461+
* 整数値との比較を行う
462+
* @deprecated 代わりにcmpIntegerを使用してください
463+
* @param n 比較対象の整数値
464+
* @return 保持する数値データの比較を行い,this&lt;nなら負の値,this==nなら0,this&gt;nなら正の値
444465
*/
445466
public int cmpUint(int n) {
446467
return this.cmpInt(n);
447468
}
448469

449470
/**
450-
* TODO: 準備中
451-
*
452-
* @param n TODO: 準備中
453-
* @return TODO: 準備中
471+
* 整数値との比較を行う
472+
* @deprecated 代わりにcmpIntegerを使用してください
473+
* @param n 比較対象の整数値
474+
* @return 保持する数値データの比較を行い,this&lt;nなら負の値,this==nなら0,this&gt;nなら正の値
454475
*/
455476
public int cmpUint(long n) {
456477
return this.cmpUint((int) n);

0 commit comments

Comments
 (0)