X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Fssa%2Fexits%2FThrow.java;h=730463ab25d1ca6016be54533714fe6112bfe65c;hp=3af6a00731cf9ba8d9be957846df60a5c0df919b;hb=9a175feb652b2b7bba7afa540831b9076be3c10e;hpb=0b72d3e4ec886838314ffeba0fa201e32c0aae3e diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Throw.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Throw.java index 3af6a0073..730463ab2 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Throw.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Throw.java @@ -10,21 +10,27 @@ import org.simantics.scl.compiler.internal.codegen.references.ValRef; import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock; import org.simantics.scl.compiler.internal.codegen.ssa.SSAExit; import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction; +import org.simantics.scl.compiler.internal.codegen.utils.Constants; import org.simantics.scl.compiler.internal.codegen.utils.CopyContext; import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder; import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext; import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; +import org.simantics.scl.runtime.exceptions.MatchingException; public class Throw extends SSAExit { - private static final TypeDesc RuntimeException = + public static final TypeDesc RuntimeException = TypeDesc.forClass(RuntimeException.class); + public static final TypeDesc MatchingException = + TypeDesc.forClass(MatchingException.class); + TypeDesc exceptionClass; String description; - public Throw(String description) { + public Throw(TypeDesc exceptionClass, String description) { + this.exceptionClass = exceptionClass; this.description = description; } @@ -38,10 +44,14 @@ public class Throw extends SSAExit { public void generateCode(MethodBuilder mb) { //mb.push(exception.getBinding()); //cb.mapLineNumber(location); - mb.newObject(RuntimeException); + mb.newObject(exceptionClass); mb.dup(); - mb.loadConstant(description); - mb.invokeConstructor(RuntimeException, new TypeDesc[] {TypeDesc.STRING}); + if(description == null) + mb.invokeConstructor(exceptionClass, Constants.EMPTY_TYPEDESC_ARRAY); + else { + mb.loadConstant(description); + mb.invokeConstructor(exceptionClass, new TypeDesc[] {TypeDesc.STRING}); + } mb.throwObject(); } @@ -56,7 +66,7 @@ public class Throw extends SSAExit { @Override public SSAExit copy(CopyContext context) { - return new Throw(description); + return new Throw(exceptionClass, description); } @Override