1 package org.simantics.scl.compiler.internal.codegen.ssa.exits;
3 import java.util.ArrayList;
5 import org.cojen.classfile.TypeDesc;
6 import org.simantics.scl.compiler.internal.codegen.continuations.Cont;
7 import org.simantics.scl.compiler.internal.codegen.continuations.ContRef;
8 import org.simantics.scl.compiler.internal.codegen.references.Val;
9 import org.simantics.scl.compiler.internal.codegen.references.ValRef;
10 import org.simantics.scl.compiler.internal.codegen.ssa.SSABlock;
11 import org.simantics.scl.compiler.internal.codegen.ssa.SSAExit;
12 import org.simantics.scl.compiler.internal.codegen.ssa.SSAFunction;
13 import org.simantics.scl.compiler.internal.codegen.utils.Constants;
14 import org.simantics.scl.compiler.internal.codegen.utils.CopyContext;
15 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
16 import org.simantics.scl.compiler.internal.codegen.utils.PrintingContext;
17 import org.simantics.scl.compiler.internal.codegen.utils.SSAValidationContext;
18 import org.simantics.scl.compiler.types.TVar;
19 import org.simantics.scl.compiler.types.Type;
20 import org.simantics.scl.runtime.exceptions.MatchingException;
22 public class Throw extends SSAExit {
24 public static final TypeDesc RuntimeException =
25 TypeDesc.forClass(RuntimeException.class);
26 public static final TypeDesc MatchingException =
27 TypeDesc.forClass(MatchingException.class);
29 TypeDesc exceptionClass;
32 public Throw(TypeDesc exceptionClass, String description) {
33 this.exceptionClass = exceptionClass;
34 this.description = description;
38 public void toString(PrintingContext context) {
39 context.append("throw\n");
40 //context.append(exception);
44 public void generateCode(MethodBuilder mb) {
45 //mb.push(exception.getBinding());
46 //cb.mapLineNumber(location);
47 mb.newObject(exceptionClass);
49 if(description == null)
50 mb.invokeConstructor(exceptionClass, Constants.EMPTY_TYPEDESC_ARRAY);
52 mb.loadConstant(description);
53 mb.invokeConstructor(exceptionClass, new TypeDesc[] {TypeDesc.STRING});
59 public void validate(SSAValidationContext context) {
63 public void destroy() {
68 public SSAExit copy(CopyContext context) {
69 return new Throw(exceptionClass, description);
73 public void replace(TVar[] vars, Type[] replacements) {
77 public void collectFreeVariables(SSAFunction function,
78 ArrayList<ValRef> vars) {
82 public Cont addParametersInFrontOf(ContRef contRef, Val[] newParameters, Val[] oldParameters,
88 public SSABlock[] getSuccessors() {
89 return SSABlock.EMPTY_ARRAY;