]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Throw.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / ssa / exits / Throw.java
index 3af6a00731cf9ba8d9be957846df60a5c0df919b..730463ab25d1ca6016be54533714fe6112bfe65c 100644 (file)
@@ -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