From: adam Date: Sun, 10 Jul 2005 03:01:59 +0000 (+0000) Subject: allow Type.Primitive as an arg to NEWARRAY X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=commitdiff_plain;h=ddf408851103280fd02c37c7afd806a94b2a3ec3 allow Type.Primitive as an arg to NEWARRAY darcs-hash:20050710030159-5007d-13fb4ff397810015ad7cd7700ed4a4d39fb124a5.gz --- diff --git a/src/org/ibex/classgen/MethodGen.java b/src/org/ibex/classgen/MethodGen.java index 50ff3af..ef40595 100644 --- a/src/org/ibex/classgen/MethodGen.java +++ b/src/org/ibex/classgen/MethodGen.java @@ -842,7 +842,9 @@ public class MethodGen extends Type.Class.Method.Body { } else if (argLength == 7) { throw new Error("should never happen - variable length instruction not explicitly handled"); } else { - int iarg = ((Integer)arg).intValue(); + int iarg = (arg instanceof Type.Primitive) + ? ((Type.Primitive)arg).toArraySpec() + : ((Integer)arg).intValue(); if (argLength == 1) { if ((opdata & OP_UNSIGNED_FLAG) != 0 ? iarg >= 256 : (iarg < -128 || iarg >= 128)) throw new ClassFile.Exn("overflow of s/u1 option"); diff --git a/src/org/ibex/classgen/Type.java b/src/org/ibex/classgen/Type.java index b84f20a..d61df3e 100644 --- a/src/org/ibex/classgen/Type.java +++ b/src/org/ibex/classgen/Type.java @@ -10,14 +10,14 @@ public abstract class Type implements CGConst { // Public API ////////////////////////////////////////////////////////////////////////////// public static final Type VOID = new Primitive("V", "void"); - public static final Type INT = new Primitive("I", "int"); - public static final Type LONG = new Primitive("J", "long"); - public static final Type BOOLEAN = new Primitive("Z", "boolean"); - public static final Type DOUBLE = new Primitive("D", "double"); - public static final Type FLOAT = new Primitive("F", "float"); - public static final Type BYTE = new Primitive("B", "byte"); - public static final Type CHAR = new Primitive("C", "char"); - public static final Type SHORT = new Primitive("S", "short"); + public static final Type INT = new Primitive("I", "int", 10); + public static final Type LONG = new Primitive("J", "long", 11); + public static final Type BOOLEAN = new Primitive("Z", "boolean", 4); + public static final Type DOUBLE = new Primitive("D", "double", 7); + public static final Type FLOAT = new Primitive("F", "float", 6); + public static final Type BYTE = new Primitive("B", "byte", 8); + public static final Type CHAR = new Primitive("C", "char", 5); + public static final Type SHORT = new Primitive("S", "short", 9); public static final Type NULL = new Null(); public static final Type.Class OBJECT = Type.Class.instance("java.lang.Object"); @@ -93,12 +93,19 @@ public abstract class Type implements CGConst { public static class Primitive extends Type { private String humanReadable; - Primitive(String descriptor, String humanReadable) { + private int arraySpec; + Primitive(String descriptor, String humanReadable) { this(descriptor, humanReadable, -1); } + Primitive(String descriptor, String humanReadable, int arraySpec) { super(descriptor); this.humanReadable = humanReadable; + this.arraySpec = arraySpec; } public String toString() { return humanReadable; } public boolean isPrimitive() { return true; } + public int toArraySpec() { + if (arraySpec < 0) throw new Error("you can't make arrays of " + this); + return arraySpec; + } } public abstract static class Ref extends Type {