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=e2d3b68da7e09447f7a3e30d6b1f5b9e4dbb30cc;hb=69b2d27ebab56f1b0e4df2a3a301f4d852439e8e;hpb=6c44a3470c1ae5c0e54153871805e24e394a96bb diff --git a/src/org/ibex/classgen/MethodGen.java b/src/org/ibex/classgen/MethodGen.java index e2d3b68..ba055bf 100644 --- a/src/org/ibex/classgen/MethodGen.java +++ b/src/org/ibex/classgen/MethodGen.java @@ -10,7 +10,8 @@ public class MethodGen implements CGConst { 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; @@ -49,8 +50,9 @@ public class MethodGen implements CGConst { // FIXME: attrs, body } - MethodGen(CPGen cp, DataInput in) throws IOException { + MethodGen(CPGen cp, DataInput in, ClassFile owner) throws IOException { this.cp = cp; + this.owner = owner; flags = in.readShort(); name = cp.getUtf8ByIndex(in.readShort()); String descriptor = cp.getUtf8ByIndex(in.readShort()); @@ -70,21 +72,19 @@ public class MethodGen implements CGConst { this.ret = ret; this.args = args; this.flags = flags; + this.owner = owner; attrs = new ClassFile.AttrGen(cp); codeAttrs = new ClassFile.AttrGen(cp); cp.addUtf8(name); - cp.addUtf8(getDescriptor()); + cp.addUtf8(owner.getType().method(name, ret, args).getDescriptor()); if((owner.flags & ACC_INTERFACE) != 0 || (flags & (ACC_ABSTRACT|ACC_NATIVE)) != 0) size = capacity = -1; maxLocals = Math.max(args.length + (flags&ACC_STATIC)==0 ? 1 : 0, 4); } - /** Returns the descriptor string for this method */ - public String getDescriptor() { return MethodRef.getDescriptor(ret, args); } - private class ExnTableEnt { public int start; public int end; @@ -275,13 +275,15 @@ public class MethodGen implements CGConst { if(arg instanceof Long || arg instanceof Double) op = LDC2_W; break; - case INVOKEINTERFACE: - if(arg instanceof MethodRef) arg = new MethodRef.I((MethodRef)arg); + case INVOKEINTERFACE: { break; + } } int opdata = OP_DATA[op&0xff]; - if((opdata&OP_CPENT_FLAG) != 0 && !(arg instanceof CPGen.Ent)) - arg = cp.add(arg); + if((opdata&OP_CPENT_FLAG) != 0 && !(arg instanceof CPGen.Ent)) { + if (op==INVOKEINTERFACE) arg = cp.add(arg, true); + else arg = cp.add(arg); + } else if((opdata&OP_VALID_FLAG) == 0) throw new IllegalArgumentException("unknown bytecode"); this.op[pos] = op; @@ -627,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); }