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.internal.codegen.utils.ValRefVisitor;
19 import org.simantics.scl.compiler.types.TVar;
20 import org.simantics.scl.compiler.types.Type;
21 import org.simantics.scl.runtime.exceptions.MatchingException;
23 public class Throw extends SSAExit {
25 public static final TypeDesc RuntimeException =
26 TypeDesc.forClass(RuntimeException.class);
27 public static final TypeDesc MatchingException =
28 TypeDesc.forClass(MatchingException.class);
30 TypeDesc exceptionClass;
33 public Throw(TypeDesc exceptionClass, String description) {
34 this.exceptionClass = exceptionClass;
35 this.description = description;
39 public void toString(PrintingContext context) {
40 context.append("throw\n");
41 //context.append(exception);
45 public void generateCode(MethodBuilder mb) {
46 //mb.push(exception.getBinding());
47 //cb.mapLineNumber(location);
48 mb.newObject(exceptionClass);
50 if(description == null)
51 mb.invokeConstructor(exceptionClass, Constants.EMPTY_TYPEDESC_ARRAY);
53 mb.loadConstant(description);
54 mb.invokeConstructor(exceptionClass, new TypeDesc[] {TypeDesc.STRING});
60 public void validate(SSAValidationContext context) {
64 public void destroy() {
69 public SSAExit copy(CopyContext context) {
70 return new Throw(exceptionClass, description);
74 public void replace(TVar[] vars, Type[] replacements) {
78 public void collectFreeVariables(SSAFunction function,
79 ArrayList<ValRef> vars) {
83 public Cont addParametersInFrontOf(ContRef contRef, Val[] newParameters, Val[] oldParameters,
89 public SSABlock[] getSuccessors() {
90 return SSABlock.EMPTY_ARRAY;
94 public void forValRefs(ValRefVisitor visitor) {