MCPcopy Create free account
hub / github.com/LFYSec/MScan / SwitchStmt

Class SwitchStmt

src/main/java/pascal/taie/ir/stmt/SwitchStmt.java:40–156  ·  view source on GitHub ↗

Representation of switch statement, e.g., switch (v) { case 1: ... case 2: ... default: ... }

Source from the content-addressed store, hash-verified

38 * }
39 */
40public abstract class SwitchStmt extends JumpStmt {
41
42 /**
43 * The variable holding the condition value of the switch-statement.
44 */
45 protected final Var var;
46
47 /**
48 * List of jump targets of the switch-statement, one target for each case.
49 */
50 protected List<Stmt> targets;
51
52 /**
53 * The jump target for default case.
54 */
55 protected Stmt defaultTarget;
56
57 public SwitchStmt(Var var) {
58 this.var = var;
59 }
60
61 /**
62 * @return the variable holding the condition value of the switch-statement.
63 */
64 public Var getVar() {
65 return var;
66 }
67
68 /**
69 * @return the i-th jump target (for i-th case) of the switch-statement.
70 * The indexes start from 0. Target for default case is excluded.
71 */
72 public Stmt getTarget(int i) {
73 return targets.get(i);
74 }
75
76 public void setTargets(List<Stmt> targets) {
77 this.targets = List.copyOf(targets);
78 }
79
80 /**
81 * @return all case values of the switch statement. For example,
82 * for switch statement
83 *
84 * <pre>
85 * {@code
86 * switch (x) {
87 * case 1: a = 1; break;
88 * case 3: a = 3; break;
89 * default: a = 0; break;
90 * }
91 * }
92 * </pre>
93 * <p>
94 * This API would return [1, 3].
95 */
96 public abstract List<Integer> getCaseValues();
97

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected