diff --git a/jode/jode/type/IntegerType.java b/jode/jode/type/IntegerType.java index 03014fa..acc8041 100644 --- a/jode/jode/type/IntegerType.java +++ b/jode/jode/type/IntegerType.java @@ -28,87 +28,106 @@ import jode.GlobalOptions; * ints whose value is in byte resp. short range. They may be * converted to B resp. S, but sometimes need an explicit cast. * - * @author Jochen Hoenicke */ + * @author Jochen Hoenicke + */ public class IntegerType extends Type { - public static final int IT_I = 0x01; - public static final int IT_C = 0x02; - public static final int IT_S = 0x04; - public static final int IT_B = 0x08; - public static final int IT_Z = 0x10; + /* Order does matter: + * First type that is possible (and hinted) will be taken. + */ + public static final int IT_Z = 0x01; + public static final int IT_I = 0x02; + public static final int IT_C = 0x04; + public static final int IT_S = 0x08; + public static final int IT_B = 0x10; public static final int IT_cS = 0x20; public static final int IT_cB = 0x40; private static final int NUM_TYPES = 7; private static final int[] subTypes = { + /*Z*/ IT_Z, /*I*/ IT_I|IT_C|IT_S|IT_B/*|IT_cS|IT_cB*/, /*C*/ IT_C, /*S*/ IT_S|IT_B/*|IT_cS|IT_cB*/, /*B*/ IT_B/*|IT_cB*/, - /*Z*/ IT_Z, /*cS*/IT_cS|IT_cB, /*cB*/IT_cB }; private static final int[] superTypes = { + /*Z*/ IT_Z, /*I*/ IT_I, /*C*/ IT_I|IT_C, /*S*/ IT_I|IT_S, /*B*/ IT_I|IT_S|IT_B, - /*Z*/ IT_Z, /*cS*/IT_I|IT_C|IT_S|IT_cS, /*cB*/IT_I|IT_C|IT_S|IT_B|IT_cS|IT_cB }; private static final Type[] simpleTypes = { + new IntegerType(IT_Z), new IntegerType(IT_I), new IntegerType(IT_C), new IntegerType(IT_S), new IntegerType(IT_B), - new IntegerType(IT_Z), new IntegerType(IT_cS), new IntegerType(IT_cB) }; private static final String[] typeNames = { - "I","C","S","B","Z","cS","cB" + "Z","I","C","S","B","s","b" }; - - + int possTypes; - int strongHint = 0; - int weakHint = 0; + int hintTypes; /** * Create a new type with the given type. */ public IntegerType(int types) { + this(types, types); + } + + public IntegerType(int types, int hints) { super(TC_INTEGER); possTypes = types; + hintTypes = hints; } - + public Type getHint() { - int hint = ((possTypes & IT_Z) != 0 ? IT_Z - : strongHint != 0 ? strongHint - : weakHint != 0 ? weakHint - : possTypes); + int hint = possTypes & hintTypes; + if (hint == 0) + hint = possTypes; int i = 0; - for (int it = 0x1; (it & hint) == 0; it <<= 1) + while ((hint & 1) == 0) { + hint >>= 1; i++; + } return simpleTypes[i]; } - private int getSubTypes() { + public Type getCanonic() { + int types = possTypes; + int i = 0; + while ((types >>= 1) != 0) { + i++; + } + return simpleTypes[i]; + } + + private static int getSubTypes(int types) { int result = 0; for (int i=0; i < NUM_TYPES; i++) { - if (((1<