X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FMethodGen.java;h=50ff3af0dac1821327c8103ea81a400439b15916;hp=90edacd8f303d5a514580895625026c875c49a70;hb=536baf9b7baedf6ac82edef960ed411776cca00a;hpb=5a08820e18996e02dcf0ba12f502ba7f0bc781ea diff --git a/src/org/ibex/classgen/MethodGen.java b/src/org/ibex/classgen/MethodGen.java index 90edacd..50ff3af 100644 --- a/src/org/ibex/classgen/MethodGen.java +++ b/src/org/ibex/classgen/MethodGen.java @@ -5,20 +5,18 @@ import java.util.*; /** A class representing a method in a generated classfile @see ClassFile#addMethod */ -public class MethodGen extends Type.Class.Method.Body implements CGConst { +public class MethodGen extends Type.Class.Method.Body { private final static boolean EMIT_NOPS = false; private static final int NO_CODE = -1; public final Type.Class.Method method; - private final int flags; - private final ClassFile.AttrGen attrs; private final ClassFile.AttrGen codeAttrs; private final Vector exnTable = new Vector(); private final Hashtable thrownExceptions = new Hashtable(); - private int maxStack = 16; - private int maxLocals; + int maxStack = 16; + int maxLocals; private int size; private int capacity; @@ -30,16 +28,10 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { // Constructors ////////////////////////////////////////////////////////////////////////////// MethodGen(Type.Class.Method method, int flags) { - method.super(); - if ((flags & ~VALID_METHOD_FLAGS) != 0) throw new IllegalArgumentException("invalid flags"); + method.super(flags, new ClassFile.AttrGen()); this.method = method; - this.flags = flags; - - attrs = new ClassFile.AttrGen(); codeAttrs = new ClassFile.AttrGen(); - - if (((flags & INTERFACE) != 0) || (flags & (ABSTRACT|NATIVE)) != 0) size = capacity = -1; - + if (!isConcrete()) size = capacity = -1; maxLocals = Math.max(method.getNumArgs() + (flags&STATIC)==0 ? 1 : 0, 4); } @@ -47,16 +39,13 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { this(in.readShort(), cp.getUtf8KeyByIndex(in.readShort()), c, in, cp); } private MethodGen(short flags, String name, Type.Class c, DataInput in, ConstantPool cp) throws IOException { - this(flags, name, c.method(name+cp.getUtf8KeyByIndex(in.readShort())), c, in, cp); } + this(flags, name, c.method(name,cp.getUtf8KeyByIndex(in.readShort())), c, in, cp); } private MethodGen(short flags, String name, Type.Class.Method m, Type.Class c, DataInput in, ConstantPool cp) throws IOException { - m.super(); - this.flags = flags; - if ((flags & ~VALID_METHOD_FLAGS) != 0) throw new ClassFile.ClassReadExn("invalid flags"); - this.method = c.method(name,typeDescriptor); - this.attrs = new ClassFile.AttrGen(in,cp); + m.super(flags, new ClassFile.AttrGen(in,cp)); + this.method = m; - if ((flags & (NATIVE|ABSTRACT))==0) { + if (isConcrete()) { byte[] codeAttr = (byte[]) attrs.get("Code"); if (codeAttr == null) throw new ClassFile.ClassReadExn("code attr expected"); DataInputStream ci = new DataInputStream(new ByteArrayInputStream(codeAttr)); @@ -144,7 +133,7 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { break; } case MULTIANEWARRAY: - arg = new MultiANewArray((Type.Class)cp.getKeyByIndex(in.readUnsignedShort()),in.readUnsignedByte()); + arg = new MultiANewArray((Type.Array)cp.getKeyByIndex(in.readUnsignedShort()),in.readUnsignedByte()); break; case INVOKEINTERFACE: { ConstantPool.Ent ent = cp.getByIndex(in.readUnsignedShort()); @@ -543,9 +532,9 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { } public static class MultiANewArray { - public Type.Class type; + public Type.Array type; public int dims; - public MultiANewArray(Type.Class type, int dims) { this.type = type; this.dims = dims; } + public MultiANewArray(Type.Array type, int dims) { this.type = type; this.dims = dims; } } public static class Wide { @@ -579,7 +568,7 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { */ void finish(ConstantPool cp) { cp.addUtf8(method.name); - cp.addUtf8(method.getDescriptor()); + cp.addUtf8(method.getTypeDescriptor()); for(Enumeration e = thrownExceptions.keys();e.hasMoreElements();) cp.add(e.nextElement()); @@ -901,7 +890,7 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { o.writeShort(flags); o.writeShort(cp.getUtf8Index(method.name)); - o.writeShort(cp.getUtf8Index(method.getDescriptor())); + o.writeShort(cp.getUtf8Index(method.getTypeDescriptor())); attrs.dump(o,cp); } @@ -1007,9 +996,9 @@ public class MethodGen extends Type.Class.Method.Body implements CGConst { sb.append(i).append(": "); sb.append(OP_NAMES[op[i]&0xff]); String s = null; - if (arg[i] instanceof Type) s = ((Type)arg[i]).debugToString(); + if (arg[i] instanceof Type) s = ((Type)arg[i]).toString(); else if (arg[i] instanceof Type.Class.Member) s = ((Type.Class.Member)arg[i]).toString(); - else if (arg[i] instanceof String) s = "\"" + s + "\""; + else if (arg[i] instanceof String) s = "\"" + arg[i] + "\""; else if (arg[i] != null) s = arg[i].toString(); if (s != null) sb.append(" ").append(s); sb.append("\n");