private void fixTypes1(ArrayList scc, TypeData kind) throws NotFoundException { int size = scc.size(); for (int i = 0; i < size; i++) { TypeVar cv = (TypeVar)scc.get(i); TypeData kind2 = kind.getArrayType(-cv.dimension); if (kind2.isBasicType() == null) cv.fixedType = kind2.getName(); else { cv.lowers.clear(); cv.lowers.add(kind2); cv.is2WordType = kind2.is2WordType(); } } }
private int[] fillStackMap(int num, int offset, int[] data, TypeData[] types) { int realNum = diffSize(types, offset, offset + num); ConstPool cp = cpool; int[] tags = new int[realNum]; int j = 0; for (int i = 0; i < num; i++) { TypeData td = types[offset + i]; tags[j] = td.getTypeTag(); data[j] = td.getTypeData(cp); if (td.is2WordType()) i++; j++; } return tags; }
public static void aastore(TypeData array, TypeData value, ClassPool cp) throws BadBytecode { if (array instanceof AbsTypeVar) if (!value.isNullType()) ((AbsTypeVar)array).merge(ArrayType.make(value)); if (value instanceof AbsTypeVar) if (array instanceof AbsTypeVar) ArrayElement.make(array); // should call value.setType() later. else if (array instanceof ClassName) { if (!array.isNullType()) { String type = ArrayElement.typeName(array.getName()); value.setType(type, cp); } } else throw new BadBytecode("bad AASTORE: " + array); }
public void resetNumLocals() { if (localsTypes != null) { int nl = localsTypes.length; while (nl > 0 && localsTypes[nl - 1].isBasicType() == TypeTag.TOP) { if (nl > 1) { if (localsTypes[nl - 2].is2WordType()) break; } --nl; } numLocals = nl; } }
for (int j = 0; j < size2; j++) { TypeData td = (TypeData)tds.get(j); TypeData d = td.getArrayType(tvar.dimension); BasicType bt = d.isBasicType(); if (kind == null) { if (bt == null) { if (d.isUninit()) break; if (bt == null && !d.isNullType()) lowersSet.add(d.getName()); is2WordType = kind.is2WordType(); // necessary? fixTypes1(scc, kind);
public static TypeData make(TypeData array) throws BadBytecode { if (array instanceof ArrayType) return ((ArrayType)array).elementType(); else if (array instanceof AbsTypeVar) return new ArrayElement((AbsTypeVar)array); else if (array instanceof ClassName) if (!array.isNullType()) return new ClassName(typeName(array.getName())); throw new BadBytecode("bad AASTORE: " + array); }
/** * Sets the type name of this object type. If the given type name is * a subclass of the current type name, then the given name becomes * the name of this object type. * * @param className dot-separated name unless the type is an array type. */ private static void setType(TypeData td, String className, ClassPool cp) throws BadBytecode { td.setType(className, cp); }
private int doXSTORE(int index, TypeData type) { stackTop--; localsTypes[index] = type; if (type.is2WordType()) { stackTop--; localsTypes[index + 1] = TOP; } return 2; }
/** * Finds the most specific common super class of the given classes * by considering array types. */ public static CtClass commonSuperClassEx(CtClass one, CtClass two) throws NotFoundException { if (one == two) return one; else if (one.isArray() && two.isArray()) { CtClass ele1 = one.getComponentType(); CtClass ele2 = two.getComponentType(); CtClass element = commonSuperClassEx(ele1, ele2); if (element == ele1) return one; else if (element == ele2) return two; else return one.getClassPool().get(element == null ? "java.lang.Object" : element.getName() + "[]"); } else if (one.isPrimitive() || two.isPrimitive()) return null; // TOP else if (one.isArray() || two.isArray()) // but !(one.isArray() && two.isArray()) return one.getClassPool().get("java.lang.Object"); else return commonSuperClass(one, two); }
public int getTypeData(ConstPool cp) { return type.getTypeData(cp); } public BasicType isBasicType() { return type.isBasicType(); }
public int getTypeTag() { return type.getTypeTag(); } public int getTypeData(ConstPool cp) { return type.getTypeData(cp); }
public String getName() { return type.getName(); }
public boolean isNullType() { if (fixedType == null) return ((TypeData)lowers.get(0)).isNullType(); else return false; }
private int doInvokeMethod(int pos, byte[] code, boolean notStatic) throws BadBytecode { int i = ByteArray.readU16bit(code, pos + 1); String desc = cpool.getMethodrefType(i); checkParamTypes(desc, 1); if (notStatic) { String className = cpool.getMethodrefClassName(i); TypeData target = stackTypes[--stackTop]; if (target instanceof TypeData.UninitTypeVar && target.isUninit()) constructorCalled(target, ((TypeData.UninitTypeVar)target).offset()); else if (target instanceof TypeData.UninitData) constructorCalled(target, ((TypeData.UninitData)target).offset()); target.setType(className, classPool); } pushMemberType(desc); return 3; }
private void constructorCalled(TypeData target, int offset) { target.constructorCalled(offset); for (int i = 0; i < stackTop; i++) stackTypes[i].constructorCalled(offset); for (int i = 0; i < localsTypes.length; i++) localsTypes[i].constructorCalled(offset); }
private void fixTypes(byte[] code, TypedBlock[] blocks) throws NotFoundException, BadBytecode { ArrayList preOrder = new ArrayList(); int len = blocks.length; int index = 0; for (int i = 0; i < len; i++) { TypedBlock block = blocks[i]; if (block.alreadySet()) { // if block is not dead code int n = block.localsTypes.length; for (int j = 0; j < n; j++) index = block.localsTypes[j].dfs(preOrder, index, classPool); n = block.stackTop; for (int j = 0; j < n; j++) index = block.stackTypes[j].dfs(preOrder, index, classPool); } } }
for (int j = 0; j < size2; j++) { TypeData td = tds.get(j); TypeData d = td.getArrayType(tvar.dimension); BasicType bt = d.isBasicType(); if (kind == null) { if (bt == null) { if (d.isUninit()) break; if (bt == null && !d.isNullType()) lowersSet.add(d.getName()); is2WordType = kind.is2WordType(); // necessary? fixTypes1(scc, kind);
static TypeData make(TypeData element) throws BadBytecode { if (element instanceof ArrayElement) return ((ArrayElement)element).arrayType(); else if (element instanceof AbsTypeVar) return new ArrayType((AbsTypeVar)element); else if (element instanceof ClassName) if (!element.isNullType()) return new ClassName(typeName(element.getName())); throw new BadBytecode("bad AASTORE: " + element); }
public void setType(String s, ClassPool cp) throws BadBytecode { type.setType(s, cp); }
private static int diffSize(TypeData[] types, int offset, int len) { int num = 0; while (offset < len) { TypeData td = types[offset++]; num++; if (td.is2WordType()) offset++; } return num; }