|
29 | 29 | import org.testng.Assert;
|
30 | 30 | import org.testng.annotations.Test;
|
31 | 31 |
|
| 32 | +import java.lang.reflect.code.analysis.SSA; |
32 | 33 | import java.lang.reflect.code.op.CoreOps;
|
33 | 34 | import java.lang.reflect.code.Op;
|
34 | 35 | import java.lang.reflect.code.interpreter.Interpreter;
|
@@ -119,6 +120,82 @@ public void testCatchFinally() {
|
119 | 120 | }
|
120 | 121 |
|
121 | 122 |
|
| 123 | + @CodeReflection |
| 124 | + public static void tryCatchFinallyBreak(IntConsumer c, int i) { |
| 125 | + a: try { |
| 126 | + try { |
| 127 | + if (i == 0) { |
| 128 | + break a; |
| 129 | + } |
| 130 | + c.accept(0); |
| 131 | + } catch (IllegalStateException e) { |
| 132 | + if (i == 1) { |
| 133 | + break a; |
| 134 | + } |
| 135 | + c.accept(1); |
| 136 | + } finally { |
| 137 | + if (i == 2) { |
| 138 | + break a; |
| 139 | + } |
| 140 | + c.accept(2); |
| 141 | + } |
| 142 | + if (i == 3) { |
| 143 | + break a; |
| 144 | + } |
| 145 | + c.accept(3); |
| 146 | + } catch (IllegalStateException e) { |
| 147 | + if (i == 4) { |
| 148 | + break a; |
| 149 | + } |
| 150 | + c.accept(4); |
| 151 | + } finally { |
| 152 | + if (i == 5) { |
| 153 | + break a; |
| 154 | + } |
| 155 | + c.accept(5); |
| 156 | + } |
| 157 | + c.accept(6); |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void testCatchFinallyBreak() { |
| 162 | + CoreOps.FuncOp f = getFuncOp("tryCatchFinallyBreak"); |
| 163 | + |
| 164 | + f.writeTo(System.out); |
| 165 | + |
| 166 | + CoreOps.FuncOp lf = f.transform((block, op) -> { |
| 167 | + if (op instanceof Op.Lowerable lop) { |
| 168 | + return lop.lower(block); |
| 169 | + } else { |
| 170 | + block.op(op); |
| 171 | + return block; |
| 172 | + } |
| 173 | + }); |
| 174 | + |
| 175 | + lf.writeTo(System.out); |
| 176 | + |
| 177 | + for (int ra = -1; ra < 6; ra++) { |
| 178 | + int fra = ra; |
| 179 | + |
| 180 | + Consumer<IntConsumer> test = testConsumer( |
| 181 | + c -> Interpreter.invoke(MethodHandles.lookup(), lf, c, fra), |
| 182 | + c -> tryCatchFinallyBreak(c, fra) |
| 183 | + ); |
| 184 | + |
| 185 | + test.accept(i -> {}); |
| 186 | + for (int ea = 0; ea < 6; ea++) { |
| 187 | + int fea = ea; |
| 188 | + test.accept(i -> { |
| 189 | + if (i == fea) throw new IllegalStateException(); |
| 190 | + }); |
| 191 | + test.accept(i -> { |
| 192 | + if (i == fea) throw new RuntimeException(); |
| 193 | + }); |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + |
122 | 199 | @CodeReflection
|
123 | 200 | public static void tryForLoop(IntConsumer c) {
|
124 | 201 | for (int i = 0; i < 8; i++) {
|
|
0 commit comments