X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FType.java;h=b84f20ae6b5b08101fa9d956cff02b042a2ec9f6;hb=d54f8660ded621af4065b8907255c162df0f6eb0;hp=7463f04a728910b4c80417556b19cae09ea44be7;hpb=5f681f726cce9463d57cc5f9554fff2ef4c2c64c;p=org.ibex.classgen.git diff --git a/src/org/ibex/classgen/Type.java b/src/org/ibex/classgen/Type.java index 7463f04..b84f20a 100644 --- a/src/org/ibex/classgen/Type.java +++ b/src/org/ibex/classgen/Type.java @@ -63,6 +63,20 @@ public abstract class Type implements CGConst { // it probably should be in Context.java return null; } + + public static Type fromArraySpec(int i) { + switch(i) { + case 4: return Type.BOOLEAN; + case 5: return Type.CHAR; + case 6: return Type.FLOAT; + case 7: return Type.DOUBLE; + case 8: return Type.BYTE; + case 9: return Type.SHORT; + case 10: return Type.INT; + case 11: return Type.LONG; + default: throw new IllegalStateException("invalid array type"); + } + } // Protected/Private ////////////////////////////////////////////////////////////////////////////// @@ -92,6 +106,7 @@ public abstract class Type implements CGConst { public abstract String toString(); public Type.Ref asRef() { return this; } public boolean isRef() { return true; } + abstract String internalForm(); } public static class Array extends Type.Ref { @@ -101,6 +116,7 @@ public abstract class Type implements CGConst { public boolean isArray() { return true; } public String toString() { return base.toString() + "[]"; } public Type getElementType() { return base; } + String internalForm() { return getDescriptor(); } } public static class Class extends Type.Ref { @@ -143,7 +159,6 @@ public abstract class Type implements CGConst { public Type.Class.Body getBody(Context cx) { return cx.resolve(this.getName()); } public abstract class Body extends HasAttributes { public abstract Type.Class.Method.Body[] methods(); - public abstract Type.Class.Field.Body addField(Type.Class.Field field, int flags); public abstract Type.Class.Field.Body[] fields(); public Body(int flags, ClassFile.AttrGen attrs) { super(flags, attrs); @@ -190,6 +205,8 @@ public abstract class Type implements CGConst { public String getName() { return name; } public abstract String getTypeDescriptor(); public abstract String toString(); + public abstract int hashCode(); + public abstract boolean equals(Object o); } public class Field extends Member { @@ -205,6 +222,15 @@ public abstract class Type implements CGConst { if ((flags & ~VALID_FIELD_FLAGS) != 0) throw new IllegalArgumentException("invalid flags"); } } + public int hashCode() { + return type.hashCode() ^ name.hashCode() ^ getDeclaringClass().hashCode(); + } + public boolean equals(Object o_) { + if(o_ == this) return true; + if(!(o_ instanceof Field)) return false; + Field o = (Field) o_; + return o.getDeclaringClass() == getDeclaringClass() && o.type == type && o.name.equals(name); + } } public class Method extends Member { @@ -228,7 +254,7 @@ public abstract class Type implements CGConst { if (name.equals("")) sb.append(Class.this.getShortName()); else - sb.append(returnType.toString()).append(".").append(name); + sb.append(returnType.toString()).append(" ").append(name); sb.append("("); for(int i=0; i