1
3 package jminusminus;
4
5 import java.util.ArrayList;
6
7 import static jminusminus.CLConstants.*;
8
9
12 class JTryStatement extends JStatement {
13 private JBlock tryBlock;
15
16 private ArrayList<JFormalParameter> parameters;
18
19 private ArrayList<JBlock> catchBlocks;
21
22 private JBlock finallyBlock;
24
25
34 public JTryStatement(int line, JBlock tryBlock, ArrayList<JFormalParameter> parameters,
35 ArrayList<JBlock> catchBlocks, JBlock finallyBlock) {
36 super(line);
37 this.tryBlock = tryBlock;
38 this.parameters = parameters;
39 this.catchBlocks = catchBlocks;
40 this.finallyBlock = finallyBlock;
41 }
42
43
46 public JTryStatement analyze(Context context) {
47 return this;
49 }
50
51
54 public void codegen(CLEmitter output) {
55 }
57
58
61 public void toJSON(JSONElement json) {
62 JSONElement e = new JSONElement();
63 json.addChild("JTryStatement:" + line, e);
64 JSONElement e1 = new JSONElement();
65 e.addChild("TryBlock", e1);
66 tryBlock.toJSON(e1);
67 if (catchBlocks != null) {
68 for (int i = 0; i < catchBlocks.size(); i++) {
69 JFormalParameter param = parameters.get(i);
70 JBlock catchBlock = catchBlocks.get(i);
71 JSONElement e2 = new JSONElement();
72 e.addChild("CatchBlock", e2);
73 String s = String.format("[\"%s\", \"%s\"]", param.name(), param.type() == null ?
74 "" : param.type().toString());
75 e2.addAttribute("parameter", s);
76 catchBlock.toJSON(e2);
77 }
78 }
79 if (finallyBlock != null) {
80 JSONElement e2 = new JSONElement();
81 e.addChild("FinallyBlock", e2);
82 finallyBlock.toJSON(e2);
83 }
84 }
85 }
86