Skip to content

Commit 921c770

Browse files
authored
Add EXCEPTION-FILE and EXCEPTION-LOCATION (#218)
1 parent 22febeb commit 921c770

File tree

10 files changed

+248
-5
lines changed

10 files changed

+248
-5
lines changed

libcobj/src/jp/osscons/opensourcecobol/libcobj/call/CobolResolve.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ public class CobolResolve {
4141

4242
/** プログラム名とCobolRunnableインスタンスの対応表 */
4343
private static Map<String, CobolRunnable> callTable;
44+
4445
/** ポインタ(UUID)のCobolRunnableインスタンスの対応表 */
4546
private static Map<UUID, String> pointerTable;
47+
4648
/** 名前の変換方法(小文字か大文字)を示す変数 */
4749
private static int name_convert;
50+
4851
// TODO resolve_pathsの利用方法
4952
/** システムで設定された区切り文字で区切られた0個以上のパス 動的に読み込むクラスファイルを検索する場所を示す. */
5053
private static List<String> resolve_paths;
54+
5155
/** システムで設定された区切り文字で区切られた0個以上のパス 動的に読み込むクラスファイルを検索するパッケージ名を示す. */
5256
private static List<String> package_paths;
5357

libcobj/src/jp/osscons/opensourcecobol/libcobj/common/CobolIntrinsic.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import jp.osscons.opensourcecobol.libcobj.exceptions.CobolExceptionId;
3333
import jp.osscons.opensourcecobol.libcobj.exceptions.CobolRuntimeException;
3434
import jp.osscons.opensourcecobol.libcobj.exceptions.CobolStopRunException;
35+
import jp.osscons.opensourcecobol.libcobj.file.CobolFile;
3536

3637
public class CobolIntrinsic {
3738

@@ -45,6 +46,8 @@ public class CobolIntrinsic {
4546
private static AbstractCobolField currField = null;
4647
private static AbstractCobolField[] calcField = new AbstractCobolField[DEPTH_LEVEL];
4748
private static Random random = new Random();
49+
private static byte[] localeBuff;
50+
private static final byte[] byteArray00 = "00".getBytes();
4851

4952
/** libcob/intrinsicのmake_double_entryの実装 */
5053
private static void makeDoubleEntry() {
@@ -1892,4 +1895,87 @@ public static AbstractCobolField funcDayToYyyyddd(int params, AbstractCobolField
18921895
currField.setInt(year);
18931896
return currField;
18941897
}
1898+
1899+
/**
1900+
* cob_intr_exception_fileの実装
1901+
*
1902+
* @return
1903+
*/
1904+
public static AbstractCobolField funcExceptionFile() {
1905+
int flen;
1906+
byte[] data;
1907+
1908+
CobolFieldAttribute attr =
1909+
new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null);
1910+
AbstractCobolField field = CobolFieldFactory.makeCobolField(0, (CobolDataStorage) null, attr);
1911+
if (CobolRuntimeException.getException() == 0
1912+
|| (CobolRuntimeException.getExceptionCode() & 0x0500) != 0x0500) {
1913+
field.setSize(2);
1914+
makeFieldEntry(field);
1915+
currField.memcpy(byteArray00, 2);
1916+
} else {
1917+
flen = CobolFile.errorFile.getSelectName().length();
1918+
field.setSize(flen + 2);
1919+
makeFieldEntry(field);
1920+
data = new byte[2 + flen];
1921+
System.arraycopy(CobolFile.errorFile.getFileStatus(), 0, data, 0, 2);
1922+
System.arraycopy(CobolFile.errorFile.getSelectName().getBytes(), 0, data, 2, flen);
1923+
currField.setDataStorage(new CobolDataStorage(data));
1924+
}
1925+
return currField;
1926+
}
1927+
1928+
/**
1929+
* cob_intr_exception_locationの実装
1930+
*
1931+
* @return
1932+
*/
1933+
public static AbstractCobolField funcExceptionLocation() {
1934+
String buff;
1935+
1936+
CobolFieldAttribute attr =
1937+
new CobolFieldAttribute(CobolFieldAttribute.COB_TYPE_ALPHANUMERIC, 0, 0, 0, null);
1938+
AbstractCobolField field = CobolFieldFactory.makeCobolField(0, (CobolDataStorage) null, attr);
1939+
currField = field;
1940+
if (CobolRuntimeException.getException() != 1
1941+
|| CobolRuntimeException.getOrigProgramId() == null) {
1942+
field.setSize(1);
1943+
makeFieldEntry(field);
1944+
currField.getDataStorage().setByte(0, ' ');
1945+
return currField;
1946+
}
1947+
if (CobolRuntimeException.getOrigSection() != null
1948+
&& CobolRuntimeException.getOrigParagragh() != null) {
1949+
buff =
1950+
String.format(
1951+
"%s; %s OF %s; %d",
1952+
CobolRuntimeException.getOrigProgramId(),
1953+
CobolRuntimeException.getOrigParagragh(),
1954+
CobolRuntimeException.getOrigSection(),
1955+
CobolRuntimeException.getOrigLine());
1956+
} else if (CobolRuntimeException.getOrigSection() != null) {
1957+
buff =
1958+
String.format(
1959+
"%s; %s; %d",
1960+
CobolRuntimeException.getOrigProgramId(),
1961+
CobolRuntimeException.getOrigSection(),
1962+
CobolRuntimeException.getOrigLine());
1963+
} else if (CobolRuntimeException.getOrigParagragh() != null) {
1964+
buff =
1965+
String.format(
1966+
"%s; %s; %d",
1967+
CobolRuntimeException.getOrigProgramId(),
1968+
CobolRuntimeException.getOrigParagragh(),
1969+
CobolRuntimeException.getOrigLine());
1970+
} else {
1971+
buff =
1972+
String.format(
1973+
"%s; ; %d",
1974+
CobolRuntimeException.getOrigProgramId(), CobolRuntimeException.getOrigLine());
1975+
}
1976+
localeBuff = buff.getBytes();
1977+
field.setSize(localeBuff.length);
1978+
currField.setDataStorage(new CobolDataStorage(localeBuff));
1979+
return currField;
1980+
}
18951981
}

libcobj/src/jp/osscons/opensourcecobol/libcobj/common/CobolUtil.java

100644100755
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class CobolUtil {
6161

6262
public static String sourceFile;
6363
public static int sourceLine;
64+
public static String currProgramId;
65+
public static String currSection;
66+
public static String currParagraph;
6467

6568
abstract class HandlerList {
6669
public HandlerList next = null;
@@ -691,6 +694,10 @@ public static void setLocation(
691694
String progId, String sfile, int sline, String csect, String cpara, String cstatement) {
692695
CobolUtil.sourceFile = sfile;
693696
CobolUtil.sourceLine = sline;
697+
currProgramId = progId;
698+
currSection = csect;
699+
currParagraph = cpara;
700+
sourceLine = sline;
694701
if (CobolUtil.lineTrace) {
695702
System.err.println(
696703
String.format(
@@ -741,4 +748,20 @@ public static byte[] stringToBytes(String s) {
741748
public static byte[] toBytes(byte... bytes) {
742749
return bytes;
743750
}
751+
752+
public static String getCurrProgramId() {
753+
return currProgramId;
754+
}
755+
756+
public static String getCurrSection() {
757+
return currSection;
758+
}
759+
760+
public static String getCurrParagraph() {
761+
return currParagraph;
762+
}
763+
764+
public static int getSourceLine() {
765+
return sourceLine;
766+
}
744767
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
public abstract class AbstractCobolField {
3232
/** データを格納に使用するバイト配列の長さ */
3333
protected int size;
34+
3435
/** データを格納するバイト配列を扱うオブジェクト */
3536
protected CobolDataStorage dataStorage;
37+
3638
/** 変数に関する様々な情報を保持するオブジェクト(符号付か,COMP-3指定かなど) */
3739
protected CobolFieldAttribute attribute;
3840

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class CobolDataStorage {
2828

2929
/** データを保存するバイト配列 */
3030
private byte[] data;
31+
3132
/** このクラスの扱うデータが保存する領域のバイト配列中での相対位置 */
3233
private int index;
3334

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ public class CobolFieldAttribute {
5656

5757
/** 変数の種類 */
5858
private int type;
59+
5960
/** 数値の時,桁数を示す */
6061
private int digits;
62+
6163
/** 数値の時,スケールを示す */
6264
private int scale;
65+
6366
/** 様々なフラグ */
6467
private int flags;
68+
6569
/** PICTURE句の文字列 */
6670
private String pic;
6771

libcobj/src/jp/osscons/opensourcecobol/libcobj/exceptions/CobolRuntimeException.java

100644100755
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@
1919
package jp.osscons.opensourcecobol.libcobj.exceptions;
2020

2121
import java.util.List;
22+
import jp.osscons.opensourcecobol.libcobj.common.CobolUtil;
2223

2324
/** 実行時エラーを示す例外 */
2425
public class CobolRuntimeException extends RuntimeException {
2526
public static int code;
27+
public static int cob_got_exception = 0;
28+
public static String cob_orig_program_id;
29+
public static String cob_orig_section;
30+
public static String cob_orig_paragraph;
31+
public static int cob_orig_line = 0;
2632

2733
public static final int COBOL_FITAL_ERROR = 9000;
2834

2935
public static List<RuntimeErrorHandler> hdlrs = null;
3036

3137
/** エラー番号 */
3238
private int errorCode;
39+
3340
/** エラーメッセージ */
3441
private String message;
3542

@@ -70,6 +77,35 @@ public void printStackTrace() {
7077

7178
public static void setException(int id) {
7279
code = CobolExceptionTabCode.code[id];
80+
cob_got_exception = 1;
81+
cob_orig_line = CobolUtil.getSourceLine();
82+
cob_orig_program_id = CobolUtil.getCurrProgramId();
83+
cob_orig_section = CobolUtil.getCurrSection();
84+
cob_orig_paragraph = CobolUtil.getCurrParagraph();
7385
// TODO common.c実装に残りをやる
7486
}
87+
88+
public static int getExceptionCode() {
89+
return code;
90+
}
91+
92+
public static int getException() {
93+
return cob_got_exception;
94+
}
95+
96+
public static String getOrigProgramId() {
97+
return cob_orig_program_id;
98+
}
99+
100+
public static String getOrigSection() {
101+
return cob_orig_section;
102+
}
103+
104+
public static String getOrigParagragh() {
105+
return cob_orig_paragraph;
106+
}
107+
108+
public static int getOrigLine() {
109+
return cob_orig_line;
110+
}
75111
}

libcobj/src/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java

100644100755
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public class CobolFile {
184184
CobolExceptionId.COB_EC_I_O,
185185
CobolExceptionId.COB_EC_I_O_IMP
186186
};
187-
protected String select_name;
187+
public String select_name;
188188
public byte[] file_status;
189189
protected AbstractCobolField assign;
190190
protected AbstractCobolField record;
@@ -219,6 +219,8 @@ public class CobolFile {
219219
protected char file_version;
220220

221221
protected static String runtime_buffer;
222+
protected static String name;
223+
protected static byte[] status;
222224

223225
public Linage getLinorkeyptr() {
224226
return this.linorkeyptr;
@@ -747,6 +749,7 @@ public void open(int mode, int sharing, AbstractCobolField fnstatus) {
747749
return;
748750
}
749751
}
752+
750753
// protected long start;
751754
// protected long end;
752755

@@ -1519,4 +1522,14 @@ public void cob_delete_file(AbstractCobolField fnstatus) {
15191522
}
15201523
}
15211524
}
1525+
1526+
public String getSelectName() {
1527+
// CobolFile cobolFile = new CobolFile();
1528+
return this.select_name;
1529+
}
1530+
1531+
public byte[] getFileStatus() {
1532+
// CobolFile cobolFile = new CobolFile();
1533+
return this.file_status;
1534+
}
15221535
}

libcobj/src/jp/osscons/opensourcecobol/libcobj/file/IndexedCursor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,34 @@ enum CursorReadOption {
5757
public final class IndexedCursor {
5858
/** a cursor to the top direction */
5959
private Optional<ResultSet> backwardCursor;
60+
6061
/** a cursor to the bottom direction */
6162
private Optional<ResultSet> forwardCursor;
63+
6264
/** a connection to the SQLite database */
6365
private Connection conn;
66+
6467
/** firstFetch is true if and only if the cursor has not read any data yet */
6568
private boolean firstFetch;
69+
6670
/** a position in buffers that stores the read data */
6771
private int cursorIndex;
72+
6873
/** one of COB_EQ, COB_LT, COB_LE, COB_GT, COB_GE in CobolIndexedFile.java */
6974
private int comparator;
75+
7076
/** isDuplicate is true if and only if the table key allows duplicates */
7177
private boolean isDuplicate;
78+
7279
/** a key */
7380
private byte[] key;
81+
7482
/** forwardBuffer stores data located to the bottom direction from the first read position */
7583
List<FetchResult> forwardBuffer;
84+
7685
/** bakckwardBuffer stores data located to the first direction from the first read position */
7786
List<FetchResult> backwardBuffer;
87+
7888
/** the index of the table */
7989
private int tableIndex;
8090

0 commit comments

Comments
 (0)