added ThrowExceptionInstruction
(to store throw expression in it)
This commit is contained in:
@@ -77,9 +77,12 @@ public interface JetControlFlowBuilder {
|
|||||||
JetElement getCurrentSubroutine();
|
JetElement getCurrentSubroutine();
|
||||||
@Nullable
|
@Nullable
|
||||||
JetElement getReturnSubroutine();
|
JetElement getReturnSubroutine();
|
||||||
|
|
||||||
void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine);
|
void returnValue(@NotNull JetExpression returnExpression, @NotNull JetElement subroutine);
|
||||||
|
|
||||||
void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine);
|
void returnNoValue(@NotNull JetElement returnExpression, @NotNull JetElement subroutine);
|
||||||
|
|
||||||
|
void throwException(@NotNull JetThrowExpression throwExpression);
|
||||||
|
|
||||||
void write(@NotNull JetElement assignment, @NotNull JetElement lValue);
|
void write(@NotNull JetElement assignment, @NotNull JetElement lValue);
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public void throwException(@NotNull JetThrowExpression throwExpression) {
|
||||||
|
assert builder != null;
|
||||||
|
builder.throwException(throwExpression);
|
||||||
|
}
|
||||||
|
|
||||||
public Label getEntryPoint(@NotNull JetElement labelElement) {
|
public Label getEntryPoint(@NotNull JetElement labelElement) {
|
||||||
assert builder != null;
|
assert builder != null;
|
||||||
return builder.getEntryPoint(labelElement);
|
return builder.getEntryPoint(labelElement);
|
||||||
@@ -131,7 +136,7 @@ public class JetControlFlowBuilderAdapter implements JetControlFlowBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoopInfo enterLoop(@NotNull JetExpression expression, Label loopExitPoint, Label conditionEntryPoint) {
|
public LoopInfo enterLoop(@NotNull JetExpression expression, @Nullable Label loopExitPoint, Label conditionEntryPoint) {
|
||||||
assert builder != null;
|
assert builder != null;
|
||||||
return builder.enterLoop(expression, loopExitPoint, conditionEntryPoint);
|
return builder.enterLoop(expression, loopExitPoint, conditionEntryPoint);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,7 +418,9 @@ public class JetControlFlowProcessor {
|
|||||||
for (int i = 0; i < catchClausesSize - 1; i++) {
|
for (int i = 0; i < catchClausesSize - 1; i++) {
|
||||||
catchLabels.add(builder.createUnboundLabel("catch " + i));
|
catchLabels.add(builder.createUnboundLabel("catch " + i));
|
||||||
}
|
}
|
||||||
builder.nondeterministicJump(catchLabels);
|
if (!catchLabels.isEmpty()) {
|
||||||
|
builder.nondeterministicJump(catchLabels);
|
||||||
|
}
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
for (JetCatchClause catchClause : catchClauses) {
|
for (JetCatchClause catchClause : catchClauses) {
|
||||||
if (!isFirst) {
|
if (!isFirst) {
|
||||||
@@ -781,7 +783,7 @@ public class JetControlFlowProcessor {
|
|||||||
if (thrownExpression != null) {
|
if (thrownExpression != null) {
|
||||||
value(thrownExpression, false);
|
value(thrownExpression, false);
|
||||||
}
|
}
|
||||||
builder.jumpToError();
|
builder.throwException(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ public class InstructionVisitor {
|
|||||||
visitJump(instruction);
|
visitJump(instruction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void visitThrowExceptionInstruction(ThrowExceptionInstruction instruction) {
|
||||||
|
visitJump(instruction);
|
||||||
|
}
|
||||||
|
|
||||||
public void visitNondeterministicJump(NondeterministicJumpInstruction instruction) {
|
public void visitNondeterministicJump(NondeterministicJumpInstruction instruction) {
|
||||||
visitInstruction(instruction);
|
visitInstruction(instruction);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-2
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.cfg.pseudocode;
|
package org.jetbrains.jet.lang.cfg.pseudocode;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.cfg.*;
|
import org.jetbrains.jet.lang.cfg.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
|
||||||
@@ -184,7 +185,8 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
BlockInfo blockInfo = allBlocks.get(i);
|
BlockInfo blockInfo = allBlocks.get(i);
|
||||||
if (blockInfo instanceof BreakableBlockInfo) {
|
if (blockInfo instanceof BreakableBlockInfo) {
|
||||||
BreakableBlockInfo breakableBlockInfo = (BreakableBlockInfo) blockInfo;
|
BreakableBlockInfo breakableBlockInfo = (BreakableBlockInfo) blockInfo;
|
||||||
if (jumpTarget == breakableBlockInfo.getExitPoint() || jumpTarget == breakableBlockInfo.getEntryPoint()) {
|
if (jumpTarget == breakableBlockInfo.getExitPoint() || jumpTarget == breakableBlockInfo.getEntryPoint()
|
||||||
|
|| jumpTarget == error) {
|
||||||
for (int j = finallyBlocks.size() - 1; j >= 0; j--) {
|
for (int j = finallyBlocks.size() - 1; j >= 0; j--) {
|
||||||
finallyBlocks.get(j).generateFinallyBlock();
|
finallyBlocks.get(j).generateFinallyBlock();
|
||||||
}
|
}
|
||||||
@@ -310,15 +312,21 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jumpToError() {
|
public void jumpToError() {
|
||||||
|
handleJumpInsideTryFinally(error);
|
||||||
add(new UnconditionalJumpInstruction(error));
|
add(new UnconditionalJumpInstruction(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enterTryFinally(@NotNull GenerationTrigger generationTrigger) {
|
public void enterTryFinally(@NotNull GenerationTrigger generationTrigger) {
|
||||||
allBlocks.push(new TryFinallyBlockInfo(generationTrigger));
|
allBlocks.push(new TryFinallyBlockInfo(generationTrigger));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public void throwException(@NotNull JetThrowExpression expression) {
|
||||||
|
handleJumpInsideTryFinally(error);
|
||||||
|
add(new ThrowExceptionInstruction(expression, error));
|
||||||
|
}
|
||||||
|
|
||||||
public void exitTryFinally() {
|
public void exitTryFinally() {
|
||||||
BlockInfo pop = allBlocks.pop();
|
BlockInfo pop = allBlocks.pop();
|
||||||
assert pop instanceof TryFinallyBlockInfo;
|
assert pop instanceof TryFinallyBlockInfo;
|
||||||
|
|||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.cfg.pseudocode;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.cfg.Label;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetThrowExpression;
|
||||||
|
|
||||||
|
public class ThrowExceptionInstruction extends AbstractJumpInstruction implements JetElementInstruction {
|
||||||
|
private final JetThrowExpression expression;
|
||||||
|
|
||||||
|
public ThrowExceptionInstruction(@NotNull JetThrowExpression expression, @NotNull Label errorLabel) {
|
||||||
|
super(errorLabel);
|
||||||
|
this.expression = expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public JetExpression getElement() {
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "throw (" + expression.getText() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(InstructionVisitor visitor) {
|
||||||
|
visitor.visitThrowExceptionInstruction(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AbstractJumpInstruction createCopy(@NotNull Label newLabel) {
|
||||||
|
return new ThrowExceptionInstruction(expression, newLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,5 +5,5 @@ fun foo() {
|
|||||||
|
|
||||||
if (x == null) throw bar(<!TYPE_MISMATCH!>x<!>)
|
if (x == null) throw bar(<!TYPE_MISMATCH!>x<!>)
|
||||||
throw bar(x)
|
throw bar(x)
|
||||||
throw <!UNREACHABLE_CODE!>bar(x)<!>
|
<!UNREACHABLE_CODE!>throw bar(x)<!>
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user