From af3a0876a2d5984da9997331710af0b4b4db7c49 Mon Sep 17 00:00:00 2001 From: brian Date: Sun, 3 Jul 2005 20:35:35 +0000 Subject: [PATCH] some more sanity checks on expression types darcs-hash:20050703203535-24bed-0421ff39d099384f3e2d4caca8aec0636aac7fea.gz --- src/org/ibex/classgen/JSSA.java | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/org/ibex/classgen/JSSA.java b/src/org/ibex/classgen/JSSA.java index d304d0f..92d31f0 100644 --- a/src/org/ibex/classgen/JSSA.java +++ b/src/org/ibex/classgen/JSSA.java @@ -191,20 +191,33 @@ public class JSSA extends MethodGen implements CGConst { public class Cast extends Expr { final Expr e; final Type t; - public Cast(Expr e, Type t) { this.e = e; this.t = t; } + public Cast(Expr e, Type t) { + if(e.getType().isRef() != t.isRef()) throw new IllegalArgumentException("invalid cast"); + // FEATURE: Check that one is a subclass of the other if it is a ref + this.e = e; + this.t = t; + } public Type getType() { return t; } } public class InstanceOf extends Expr { final Expr e; - final Type t; - public InstanceOf(Expr e, Type t) { this.e = e; this.t = t; } + final Type.Ref t; + public InstanceOf(Expr e, Type.Ref t) { + if(!e.getType().isRef()) throw new IllegalArgumentException("can't do an instanceof check on a non-ref"); + this.e = e; + this.t = t; + } public Type getType() { return Type.BOOLEAN; } } public class Throw extends Op { public final Expr e; - public Throw(Expr e) { this.e = e; } + public Throw(Expr e) { + if(!e.getType().isRef()) throw new IllegalArgumentException("can't throw a non ref"); + // FEATURE: CHeck that it is a subclass of Throwable + this.e = e; + } } public class Branch extends Op { @@ -527,8 +540,8 @@ public class JSSA extends MethodGen implements CGConst { // Runtime Type information ////////////////////////////////////////////////////////////////////////////// - case CHECKCAST: push(new Cast(pop(), (Type)arg)); return null; - case INSTANCEOF: push(new InstanceOf(pop(), (Type)arg)); return null; + case CHECKCAST: push(new Cast(pop(), (Type.Ref)arg)); return null; + case INSTANCEOF: push(new InstanceOf(pop(), (Type.Ref)arg)); return null; case LDC: case LDC_W: case LDC2_W: push(new Constant(arg)); return null; -- 1.7.10.4