1
3 package jminusminus;
4
5 import java.util.ArrayList;
6
7 import static jminusminus.CLConstants.*;
8
9
12 public class JSwitchStatement extends JStatement {
13 private JExpression condition;
15
16 private ArrayList<SwitchStatementGroup> stmtGroup;
18
19
26 public JSwitchStatement(int line, JExpression condition,
27 ArrayList<SwitchStatementGroup> stmtGroup) {
28 super(line);
29 this.condition = condition;
30 this.stmtGroup = stmtGroup;
31 }
32
33
36 public JStatement analyze(Context context) {
37 return this;
39 }
40
41
44 public void codegen(CLEmitter output) {
45 }
47
48
51 public void toJSON(JSONElement json) {
52 JSONElement e = new JSONElement();
53 json.addChild("JSwitchStatement:" + line, e);
54 JSONElement e1 = new JSONElement();
55 e.addChild("Condition", e1);
56 condition.toJSON(e1);
57 for (SwitchStatementGroup group : stmtGroup) {
58 group.toJSON(e);
59 }
60 }
61 }
62
63
66 class SwitchStatementGroup {
67 private ArrayList<JExpression> switchLabels;
69
70 private ArrayList<JStatement> block;
72
73
79 public SwitchStatementGroup(ArrayList<JExpression> switchLabels, ArrayList<JStatement> block) {
80 this.switchLabels = switchLabels;
81 this.block = block;
82 }
83
84
89 public void toJSON(JSONElement json) {
90 JSONElement e = new JSONElement();
91 json.addChild("SwitchStatementGroup", e);
92 for (JExpression label : switchLabels) {
93 JSONElement e1 = new JSONElement();
94 if (label != null) {
95 e.addChild("Case", e1);
96 label.toJSON(e1);
97 } else {
98 e.addChild("Default", e1);
99 }
100 }
101 if (block != null) {
102 for (JStatement stmt : block) {
103 stmt.toJSON(e);
104 }
105 }
106 }
107 }
108