From 5171de54bf4029c4a51ee759cdb3b1d045ebffe6 Mon Sep 17 00:00:00 2001 From: brian Date: Sat, 29 May 2004 05:38:44 +0000 Subject: [PATCH] better error for modification attempts after finish() darcs-hash:20040529053844-24bed-fdabea93c8fe73ec86614322e4d976ee28e56148.gz --- src/org/ibex/classgen/MethodGen.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/ibex/classgen/MethodGen.java b/src/org/ibex/classgen/MethodGen.java index 36523f3..6603ebd 100644 --- a/src/org/ibex/classgen/MethodGen.java +++ b/src/org/ibex/classgen/MethodGen.java @@ -4,7 +4,10 @@ import java.io.*; import java.util.*; public class MethodGen implements CGConst { - private final static boolean EMIT_NOPS = true; + private final static boolean EMIT_NOPS = false; + + private static final int NO_CODE = -1; + private static final int FINISHED = -2; private final CPGen cp; private final String name; @@ -75,7 +78,8 @@ public class MethodGen implements CGConst { private final void grow() { if(size == capacity) grow(size+1); } private final void grow(int newCap) { - if(capacity == -1) throw new IllegalStateException("method can't have code"); + if(capacity == NO_CODE) throw new IllegalStateException("method can't have code"); + if(capacity == FINISHED) throw new IllegalStateException("method has been finished"); if(newCap <= capacity) return; newCap = Math.max(newCap,capacity == 0 ? 256 : capacity*2); @@ -264,7 +268,7 @@ public class MethodGen implements CGConst { } private void _finish() throws IOException { - if(size == -1) return; + if(size == FINISHED) return; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutput o = new DataOutputStream(baos); @@ -464,7 +468,7 @@ public class MethodGen implements CGConst { o.writeShort(((CPGen.Ent)thrownExceptions.get(e.nextElement())).getIndex()); attrs.add("Exceptions",baos.toByteArray()); - size = -1; + size = capacity = FINISHED; } public void dump(DataOutput o) throws IOException { -- 1.7.10.4