]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/ssa/exits/Throw.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / ssa / exits / Throw.java
index 3af6a00731cf9ba8d9be957846df60a5c0df919b..b0391b96581cbe0df97d498589a862a23fe8b775 100644 (file)
@@ -10,21 +10,28 @@ 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.internal.codegen.utils.ValRefVisitor;
 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 +45,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 +67,7 @@ public class Throw extends SSAExit {
 
     @Override
     public SSAExit copy(CopyContext context) {
-        return new Throw(description);
+        return new Throw(exceptionClass, description);
     }
     
     @Override
@@ -78,4 +89,8 @@ public class Throw extends SSAExit {
     public SSABlock[] getSuccessors() {
         return SSABlock.EMPTY_ARRAY;
     }
+
+    @Override
+    public void forValRefs(ValRefVisitor visitor) {
+    }
 }