Skip to content

Commit 5d4952f

Browse files
committed
temp: CANCEL ALL
1 parent 3564cbf commit 5d4952f

File tree

3 files changed

+192
-7
lines changed

3 files changed

+192
-7
lines changed

cobj/codegen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6121,6 +6121,7 @@ void codegen(struct cb_program *prog, const int nested, char **program_id_list,
61216121

61226122
joutput_line("@Override");
61236123
joutput_line("public int run(CobolDataStorage... argStorages) {");
6124+
joutput_line(" CobolResolve.pushCallStackList(\"%s\");", prog->program_id);
61246125
joutput_line(" return %s_(0, argStorages);", prog->program_id);
61256126
joutput_line("}\n");
61266127

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package jp.osscons.opensourcecobol.libcobj.call;
2+
3+
public class CobolCallStackList {
4+
private CobolCallStackList parent;
5+
private CobolCallStackList children;
6+
private CobolCallStackList sister;
7+
private String name;
8+
9+
/** コンストラクタ */
10+
public CobolCallStackList() {
11+
this.parent = null;
12+
this.children = null;
13+
this.sister = null;
14+
this.name = null;
15+
}
16+
17+
/** コンストラクタ */
18+
public CobolCallStackList(String name) {
19+
this.parent = null;
20+
this.children = null;
21+
this.sister = null;
22+
this.name = name;
23+
}
24+
25+
public CobolCallStackList getParent() {
26+
return parent;
27+
}
28+
29+
public void setParent(CobolCallStackList parent) {
30+
this.parent = parent;
31+
}
32+
33+
public CobolCallStackList getChildren() {
34+
return children;
35+
}
36+
37+
public void setChildren(CobolCallStackList children) {
38+
this.children = children;
39+
}
40+
41+
public CobolCallStackList getSister() {
42+
return sister;
43+
}
44+
45+
public void setSister(CobolCallStackList sister) {
46+
this.sister = sister;
47+
}
48+
49+
public String getName() {
50+
return name;
51+
}
52+
53+
public void setName(String name) {
54+
this.name = name;
55+
}
56+
}

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

Lines changed: 135 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ public class CobolResolve {
205205
cobException.put(0x1609, "EC-XML-RANGE");
206206
}
207207

208+
/** コールスタックリストのヘッド */
209+
private static CobolCallStackList callStackListHead = null;
210+
211+
/** 現在のコールスタックリスト */
212+
private static CobolCallStackList currentCallStackList = null;
213+
208214
/**
209215
* 下記の環境変数を読み込み、CobolResolve内で定義されたメソッドの動作が変わる。<br>
210216
* 環境変数COB_LOAD_CASEにLOWERが指定されているときは、resolveメソッドに渡された引数を小文字に変換してから処理を開始する。<br>
@@ -484,13 +490,13 @@ public static void cancel(String name) {
484490
/**
485491
* callTableに保存されているすべてのCallRunnableのインスタンスのcancelメソッドを呼び出す
486492
*/
487-
public static void cancelAll() {
488-
for (CobolRunnable runnable : callTable.values()) {
489-
if (runnable.isActive() == false) {
490-
runnable.cancel();
491-
}
492-
}
493-
}
493+
// public static void cancelAll() {
494+
// for (CobolRunnable runnable : callTable.values()) {
495+
// if (runnable.isActive() == false) {
496+
// runnable.cancel();
497+
// }
498+
// }
499+
// }
494500

495501
/**
496502
* 指定のプログラムのcancelメソッドを呼び出す
@@ -520,4 +526,126 @@ public static void cobCancel(String name) throws CobolStopRunException {
520526
runner.cancel();
521527
}
522528
}
529+
530+
/**
531+
* コールスタックリストを初期化する
532+
*/
533+
private static void initCallStackList() {
534+
if (callStackListHead == null) {
535+
callStackListHead = new CobolCallStackList();
536+
}
537+
currentCallStackList = callStackListHead;
538+
}
539+
540+
/**
541+
* 新しいコールスタックリストを作成する
542+
*
543+
* @param name プログラム名
544+
* @return 作成したコールスタックリスト
545+
*/
546+
private static CobolCallStackList createCallStackList(String name) {
547+
CobolCallStackList newList = new CobolCallStackList(name);
548+
newList.setParent(currentCallStackList);
549+
currentCallStackList = newList;
550+
return newList;
551+
}
552+
553+
/**
554+
* 指定されたコールスタックリストとその子孫すべてをキャンセルする(再帰的)
555+
*
556+
* @param p キャンセル対象のコールスタックリスト
557+
*/
558+
private static void cancelCallStackList(CobolCallStackList p) {
559+
if (p == null) {
560+
// プログラムがない場合は何もしない
561+
return;
562+
}
563+
564+
// このプログラムをキャンセル
565+
String programName = p.getName();
566+
if (programName != null) {
567+
CobolRunnable runnable = callTable.get(programName);
568+
if (runnable != null && !runnable.isActive()) {
569+
runnable.cancel();
570+
}
571+
}
572+
573+
// 子要素を再帰的にキャンセル
574+
if (p.getChildren() != null) {
575+
cancelCallStackList(p.getChildren());
576+
}
577+
578+
// 兄弟要素を再帰的にキャンセル
579+
CobolCallStackList s = p.getSister();
580+
while (s != null) {
581+
cancelCallStackList(s);
582+
s = s.getSister();
583+
}
584+
}
585+
586+
/**
587+
* コールスタックにプログラムをプッシュする
588+
*
589+
* @param name プログラム名
590+
*/
591+
public static void pushCallStackList(String name) {
592+
if (currentCallStackList == null) {
593+
initCallStackList();
594+
}
595+
596+
CobolCallStackList p = currentCallStackList.getChildren();
597+
if (p == null) {
598+
currentCallStackList.setChildren(createCallStackList(name));
599+
return;
600+
}
601+
602+
if (p.getName().equals(name)) {
603+
currentCallStackList = p;
604+
return;
605+
}
606+
607+
if (p.getSister() == null) {
608+
p.setSister(createCallStackList(name));
609+
return;
610+
}
611+
612+
p = p.getSister();
613+
while (true) {
614+
if (p.getName().equals(name)) {
615+
currentCallStackList = p;
616+
return;
617+
}
618+
if (p.getSister() == null) {
619+
break;
620+
}
621+
p = p.getSister();
622+
}
623+
624+
currentCallStackList.setSister(createCallStackList(name));
625+
}
626+
627+
/**
628+
* コールスタックから一つ戻る(ポップ)
629+
*/
630+
public static void popCallStackList() {
631+
if (currentCallStackList != null) {
632+
currentCallStackList = currentCallStackList.getParent();
633+
}
634+
}
635+
636+
/**
637+
* 現在のコールスタックの子要素すべてをキャンセルする
638+
*
639+
* @throws CobolRuntimeException 現在のスタックがnullの場合
640+
*/
641+
public static void cancelAll() throws CobolRuntimeException {
642+
if (currentCallStackList == null) {
643+
throw new CobolRuntimeException(
644+
CobolRuntimeException.COBOL_FATAL_ERROR,
645+
"Call to 'cancelAll' current stack is NULL");
646+
// initCallStackList();
647+
// return;
648+
}
649+
cancelCallStackList(currentCallStackList.getChildren());
650+
}
523651
}

0 commit comments

Comments
 (0)