Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,32 @@ public abstract class AbstractCobolField {
static CobolDataStorage lastdata = null;

static final int[] cobExp10 = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
};

/**
* moveAlphanumericToNumericで使用 C言語のgotoの代替機能を提供する
*
* @author y-sakamoto
*/
protected class GotoException extends Exception {}
protected class GotoException extends Exception {
}

/**
* コンストラクタ
*
* @param size データを格納するバイト配列の長さ
* @param size データを格納するバイト配列の長さ
* @param dataStorage データを格納するバイト配列を扱うオブジェクト
* @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど)
* @param attribute 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど)
*/
public AbstractCobolField(int size, CobolDataStorage dataStorage, CobolFieldAttribute attribute) {
this.size = size;
this.dataStorage = dataStorage;
this.attribute = attribute;
}

public AbstractCobolField() {}
public AbstractCobolField() {
}

/**
* メンバ変数dataStorageのgetter
Expand Down Expand Up @@ -129,7 +131,8 @@ public CobolDataStorage getFieldData() {
}

/**
* opensource COBOLのCOB_FIELD_DATAに相当するメソッド バイト配列の中で(符号データではなく)数値データの格納されている最小の添え字を返す opensource
* opensource COBOLのCOB_FIELD_DATAに相当するメソッド
* バイト配列の中で(符号データではなく)数値データの格納されている最小の添え字を返す opensource
* COBOLではポインタを返しているが,このメソッドは添え字を返す
*
* @return SIGN_LEADINGかつSIGN_SEPARATEなら1,それ以外は0
Expand All @@ -139,13 +142,12 @@ public int getFirstDataIndex() {
}

public byte[] getBytes() {
CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
9,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
9,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolDataStorage n = new CobolDataStorage(new byte[4], 0);
AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr);
temp.moveFrom(this);
Expand All @@ -163,13 +165,12 @@ public byte[] getBytes() {
* @return
*/
public int getInt() {
CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
9,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
9,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolDataStorage n = new CobolDataStorage(new byte[4], 0);
AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, n, attr);
temp.moveFrom(this);
Expand Down Expand Up @@ -280,7 +281,7 @@ public void setZero() {
* libcob/numeric.cのcob_addの実装 thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを加算する
*
* @param field 加算する数値を保持するフィールド
* @param opt 加算に関するオプション.詳しくはopensourceCOBOLを参照
* @param opt 加算に関するオプション.詳しくはopensourceCOBOLを参照
* @return 加算後のthisの保持する数値データ
*/
public int add(AbstractCobolField field, int opt) throws CobolStopRunException {
Expand All @@ -294,7 +295,7 @@ public int add(AbstractCobolField field, int opt) throws CobolStopRunException {
* libcob/numeric.cのcob_subの実装 thisの保持する数値データに,引数で与えられたフィールドの保持する数値データを減算する
*
* @param field 減算する数値を保持するフィールド
* @param opt 減算に関するオプション.詳しくはopensourceCOBOLを参照
* @param opt 減算に関するオプション.詳しくはopensourceCOBOLを参照
* @return 減算後のthisの保持する数値データ
*/
public int sub(AbstractCobolField field, int opt) throws CobolStopRunException {
Expand Down Expand Up @@ -619,13 +620,12 @@ public void moveFrom(String s) {
CobolDataStorage storage = new CobolDataStorage(bytes.length);
storage.memcpy(bytes);

CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_ALPHANUMERIC,
bytes.length,
0,
0,
String.format("X(%d)", bytes.length));
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_ALPHANUMERIC,
bytes.length,
0,
0,
String.format("X(%d)", bytes.length));

AbstractCobolField tmp = CobolFieldFactory.makeCobolField(bytes.length, storage, attr);
this.moveFrom(tmp);
Expand All @@ -647,13 +647,12 @@ public void moveFrom(int number) {
storage.setByte(length - 1, (byte) (storage.getByte(length - 1) + 0x40));
}

CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
length,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
"S9(10)");
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
length,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
"S9(10)");

AbstractCobolField tmp = CobolFieldFactory.makeCobolField(length, storage, attr);
this.moveFrom(tmp);
Expand All @@ -680,13 +679,12 @@ public void moveFrom(double number) {
CobolDataStorage storage = new CobolDataStorage(ss.length());
storage.memcpy(ss, ss.length());

CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
ss.length(),
scale,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
"");
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
ss.length(),
scale,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
"");

AbstractCobolField tmp = CobolFieldFactory.makeCobolField(ss.length(), storage, attr);
if (number < 0) {
Expand All @@ -707,7 +705,8 @@ public void moveFrom(double number) {
*
* @param s
*/
public void checkNumeric(String s) {}
public void checkNumeric(String s) {
}

// TODO abstract指定
/**
Expand Down Expand Up @@ -840,24 +839,22 @@ private AbstractCobolField numericFieldToNumericDisplayField(AbstractCobolField
CobolDataStorage data = new CobolDataStorage(48);
if (attr.isTypeNumeric()) {
if (!attr.isTypeNumericDisplay()) {
CobolFieldAttribute newAttr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
attr.getDigits(),
attr.getScale(),
attr.getFlags() & (~CobolFieldAttribute.COB_FLAG_HAVE_SIGN),
attr.getPic());
CobolFieldAttribute newAttr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
attr.getDigits(),
attr.getScale(),
attr.getFlags() & (~CobolFieldAttribute.COB_FLAG_HAVE_SIGN),
attr.getPic());
CobolNumericField temp = new CobolNumericField(attr.getDigits(), data, newAttr);
temp.moveFrom(field);
field = temp;
} else if (attr.isFlagHaveSign()) {
CobolFieldAttribute newAttr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
attr.getDigits(),
attr.getScale(),
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
attr.getPic());
CobolFieldAttribute newAttr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_DISPLAY,
attr.getDigits(),
attr.getScale(),
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
attr.getPic());
CobolNumericField temp = new CobolNumericField(attr.getDigits(), data, newAttr);
temp.moveFrom(field);
field = temp;
Expand Down Expand Up @@ -1021,7 +1018,8 @@ public String toString() {
}

/**
* libcob/common.cのcob_field_to_stringの実装 TODO CobolNationalFieldでオーバーライドしなくても済むように修正する.
* libcob/common.cのcob_field_to_stringの実装 TODO
* CobolNationalFieldでオーバーライドしなくても済むように修正する.
*
* @return this.dataの保持するデータを文字列にして返す.
*/
Expand All @@ -1038,13 +1036,12 @@ public String fieldToString() {

/** libcob/move.cのcob_set_intの実装 */
public void setInt(int n) {
CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
9,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
9,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolDataStorage data = new CobolDataStorage(ByteBuffer.allocate(4).putInt(n).array());
AbstractCobolField temp = CobolFieldFactory.makeCobolField(4, data, attr);
this.moveFrom(temp);
Expand All @@ -1062,10 +1059,8 @@ public void setInt(CobolDataStorage data) {
* @param size
*/
public void memcpy(byte[] src, int size) {
CobolFieldAttribute attr =
new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null);
AbstractCobolField temp =
CobolFieldFactory.makeCobolField(size, new CobolDataStorage(src), attr);
CobolFieldAttribute attr = new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null);
AbstractCobolField temp = CobolFieldFactory.makeCobolField(size, new CobolDataStorage(src), attr);
this.moveFrom(temp);
}

Expand Down Expand Up @@ -1262,14 +1257,13 @@ public int cmpAll(AbstractCobolField other) {
int sign = 0;

if ((this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_ALPHANUMERIC_ALL
|| this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_NATIONAL_ALL)
|| this.getAttribute().getType() == CobolFieldAttribute.COB_TYPE_NATIONAL_ALL)
&& this.getSize() < other.getSize()) {
int size = other.getSize();
CobolDataStorage data = other.getDataStorage();
sign = other.getSign();
CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence;
OUTSIDE:
do {
OUTSIDE: do {
while (size >= this.getSize()) {
ret = comparator.compare(this.getDataStorage(), data, this.getSize(), s);
if (ret != 0) {
Expand All @@ -1287,8 +1281,7 @@ public int cmpAll(AbstractCobolField other) {
CobolDataStorage data = this.getDataStorage();
sign = this.getSign();
CobolDataStorage s = CobolModule.getCurrentModule().collating_sequence;
OUTSIDE:
do {
OUTSIDE: do {
while (size >= other.getSize()) {
ret = comparator.compare(data, other.getDataStorage(), other.getSize(), s);
if (ret != 0) {
Expand Down Expand Up @@ -1330,15 +1323,13 @@ public int cmpSimpleStr(AbstractCobolField other) {
if (ret == 0) {
if (lf.getSize() > sf.getSize()) {
if ((lf.getAttribute().getType() & CobolFieldAttribute.COB_TYPE_NATIONAL) != 0) {
ret =
CobolUtil.isNationalPadding(
lf.getDataStorage().getSubDataStorage(sf.getSize()), lf.getSize() - sf.getSize());
ret = CobolUtil.isNationalPadding(
lf.getDataStorage().getSubDataStorage(sf.getSize()), lf.getSize() - sf.getSize());
} else {
ret =
CobolUtil.commonCmpc(
lf.getDataStorage().getSubDataStorage(sf.getSize()),
(byte) ' ',
lf.getSize() - sf.getSize());
ret = CobolUtil.commonCmpc(
lf.getDataStorage().getSubDataStorage(sf.getSize()),
(byte) ' ',
lf.getSize() - sf.getSize());
}
if (this.getSize() < other.getSize()) {
ret = -ret;
Expand Down Expand Up @@ -1454,6 +1445,7 @@ public void realPutSign(int sign) {
} else if (sign < 0) {
p.setByte(0, (byte) (b + 0x40));
}
return;
case CobolFieldAttribute.COB_TYPE_NUMERIC_PACKED:
p = this.getDataStorage().getSubDataStorage(this.size - 1);
if (sign < 0) {
Expand All @@ -1474,13 +1466,12 @@ public void realPutSign(int sign) {
*/
public long getLong() {
long n;
CobolFieldAttribute attr =
new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
18,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
CobolFieldAttribute attr = new CobolFieldAttribute(
CobolFieldAttribute.COB_TYPE_NUMERIC_BINARY,
18,
0,
CobolFieldAttribute.COB_FLAG_HAVE_SIGN,
null);
byte[] data = new byte[8];
CobolDataStorage storage = new CobolDataStorage(data);
AbstractCobolField field = CobolFieldFactory.makeCobolField(8, storage, attr);
Expand All @@ -1492,7 +1483,8 @@ public long getLongValue() {
return 0;
}

public void setLongValue(long n) {}
public void setLongValue(long n) {
}

/**
* libcob/move.cのcob_hankaku_moveの実装
Expand Down