X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FMethodGen.java;h=ba055bf78a666d700613bee7257d78adbff18e39;hp=88c35bbeaf1144e6262df98c2b6682fd2cfe3674;hb=69b2d27ebab56f1b0e4df2a3a301f4d852439e8e;hpb=50a344886756b00af0e30d548a7a86822ef7e962 diff --git a/src/org/ibex/classgen/MethodGen.java b/src/org/ibex/classgen/MethodGen.java index 88c35bb..ba055bf 100644 --- a/src/org/ibex/classgen/MethodGen.java +++ b/src/org/ibex/classgen/MethodGen.java @@ -4,20 +4,21 @@ import java.io.*; import java.util.*; /** A class representing a method in a generated classfile - @see ClassGen#addMethod */ + @see ClassFile#addMethod */ public class MethodGen implements CGConst { private final static boolean EMIT_NOPS = false; private static final int NO_CODE = -1; private static final int FINISHED = -2; - + + private final ClassFile owner; private final CPGen cp; private final String name; private final Type ret; private final Type[] args; private final int flags; - private final ClassGen.AttrGen attrs; - private final ClassGen.AttrGen codeAttrs; + private final ClassFile.AttrGen attrs; + private final ClassFile.AttrGen codeAttrs; private final Hashtable exnTable = new Hashtable(); private final Hashtable thrownExceptions = new Hashtable(); @@ -29,8 +30,41 @@ public class MethodGen implements CGConst { private byte[] op; private Object[] arg; - MethodGen(DataInput in) { throw new Error("Brian is lame"); } - MethodGen(ClassGen owner, String name, Type ret, Type[] args, int flags) { + public String toString() { StringBuffer sb = new StringBuffer(); toString(sb, ""); return sb.toString(); } + public void toString(StringBuffer sb, String constructorName) { + sb.append(ClassFile.flagsToString(flags)); + sb.append(ret); + sb.append(" "); + + if (name.equals("")) sb.append("static "); + else { + if (name.equals("")) sb.append(constructorName); + else sb.append(name); + sb.append("("); + for(int i=0; i= 65536) throw new ClassGen.Exn("method too large in size"); + if(codeSize >= 65536) throw new ClassFile.Exn("method too large in size"); o.writeShort(maxStack); o.writeShort(maxLocals); @@ -501,7 +535,7 @@ public class MethodGen implements CGConst { switch(op) { case IINC: { Pair pair = (Pair) arg; - if(pair.i1 > 255 || pair.i2 < -128 || pair.i2 > 127) throw new ClassGen.Exn("overflow of iinc arg"); + if(pair.i1 > 255 || pair.i2 < -128 || pair.i2 > 127) throw new ClassFile.Exn("overflow of iinc arg"); o.writeByte(pair.i1); o.writeByte(pair.i2); break; @@ -539,7 +573,7 @@ public class MethodGen implements CGConst { if((opdata & OP_BRANCH_FLAG) != 0) { int v = pc[((Integer)arg).intValue()] - pc[i]; if(argLength == 2) { - if(v < -32768 || v > 32767) throw new ClassGen.Exn("overflow of s2 offset"); + if(v < -32768 || v > 32767) throw new ClassFile.Exn("overflow of s2 offset"); o.writeShort(v); } else if(argLength == 4) { o.writeInt(v); @@ -556,10 +590,10 @@ public class MethodGen implements CGConst { } else { int iarg = ((Integer)arg).intValue(); if(argLength == 1) { - if(iarg < -128 || iarg >= 256) throw new ClassGen.Exn("overflow of s/u1 option"); + if(iarg < -128 || iarg >= 256) throw new ClassFile.Exn("overflow of s/u1 option"); o.writeByte(iarg); } else if(argLength == 2) { - if(iarg < -32768 || iarg >= 65536) throw new ClassGen.Exn("overflow of s/u2 option"); + if(iarg < -32768 || iarg >= 65536) throw new ClassFile.Exn("overflow of s/u2 option"); o.writeShort(iarg); } else { throw new Error("should never happen"); @@ -595,7 +629,7 @@ public class MethodGen implements CGConst { void dump(DataOutput o) throws IOException { o.writeShort(flags); o.writeShort(cp.getUtf8Index(name)); - o.writeShort(cp.getUtf8Index(getDescriptor())); + o.writeShort(cp.getUtf8Index(owner.getType().method(name, ret, args).getDescriptor())); o.writeShort(attrs.size()); attrs.dump(o); }