30 |
30 |
31 /** |
31 /** |
32 * IR representation for {@code break} statements. |
32 * IR representation for {@code break} statements. |
33 */ |
33 */ |
34 @Immutable |
34 @Immutable |
35 public final class BreakNode extends Statement { |
35 public final class BreakNode extends JumpStatement { |
36 |
|
37 private final IdentNode label; |
|
38 |
36 |
39 /** |
37 /** |
40 * Constructor |
38 * Constructor |
41 * |
39 * |
42 * @param lineNumber line number |
40 * @param lineNumber line number |
43 * @param token token |
41 * @param token token |
44 * @param finish finish |
42 * @param finish finish |
45 * @param label label for break or null if none |
43 * @param labelName label name for break or null if none |
46 */ |
44 */ |
47 public BreakNode(final int lineNumber, final long token, final int finish, final IdentNode label) { |
45 public BreakNode(final int lineNumber, final long token, final int finish, final String labelName) { |
48 super(lineNumber, token, finish); |
46 super(lineNumber, token, finish, labelName); |
49 this.label = label; |
|
50 } |
47 } |
51 |
48 |
52 @Override |
49 private BreakNode(final BreakNode breakNode, final LocalVariableConversion conversion) { |
53 public boolean hasGoto() { |
50 super(breakNode, conversion); |
54 return true; |
|
55 } |
51 } |
56 |
52 |
57 /** |
|
58 * Assist in IR navigation. |
|
59 * @param visitor IR navigating visitor. |
|
60 */ |
|
61 @Override |
53 @Override |
62 public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
54 public Node accept(final NodeVisitor<? extends LexicalContext> visitor) { |
63 if (visitor.enterBreakNode(this)) { |
55 if (visitor.enterBreakNode(this)) { |
64 return visitor.leaveBreakNode(this); |
56 return visitor.leaveBreakNode(this); |
65 } |
57 } |
66 |
58 |
67 return this; |
59 return this; |
68 } |
60 } |
69 |
61 |
70 /** |
62 @Override |
71 * Get the label for this break node |
63 JumpStatement createNewJumpStatement(final LocalVariableConversion conversion) { |
72 * @return label, or null if none |
64 return new BreakNode(this, conversion); |
73 */ |
|
74 public IdentNode getLabel() { |
|
75 return label; |
|
76 } |
65 } |
77 |
66 |
78 @Override |
67 @Override |
79 public void toString(final StringBuilder sb) { |
68 String getStatementName() { |
80 sb.append("break"); |
69 return "break"; |
81 |
|
82 if (label != null) { |
|
83 sb.append(' '); |
|
84 label.toString(sb); |
|
85 } |
|
86 } |
70 } |
87 } |
71 } |