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;
}
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();
}
@Override
public SSAExit copy(CopyContext context) {
- return new Throw(description);
+ return new Throw(exceptionClass, description);
}
@Override
public SSABlock[] getSuccessors() {
return SSABlock.EMPTY_ARRAY;
}
+
+ @Override
+ public void forValRefs(ValRefVisitor visitor) {
+ }
+
+ @Override
+ public void cleanup() {
+ }
}