FieldId(TypeId<D> declaringType, TypeId<V> type, String name) { if (declaringType == null || type == null || name == null) { throw new NullPointerException(); } this.declaringType = declaringType; this.type = type; this.name = name; this.nat = new CstNat(new CstString(name), new CstString(type.name)); this.constant = new CstFieldRef(declaringType.constant, nat); }
MethodId(TypeId<D> declaringType, TypeId<R> returnType, String name, TypeList parameters) { if (declaringType == null || returnType == null || name == null || parameters == null) { throw new NullPointerException(); } this.declaringType = declaringType; this.returnType = returnType; this.name = name; this.parameters = parameters; this.nat = new CstNat(new CstString(name), new CstString(descriptor(false))); this.constant = new CstMethodRef(declaringType.constant, nat); }
TypeId(String name, com.android.dx.rop.type.Type ropType) { if (name == null || ropType == null) { throw new NullPointerException(); } this.name = name; this.ropType = ropType; this.constant = CstType.intern(ropType); }
return CstKnownNull.THE_ONE; } else if (value instanceof Boolean) { return CstBoolean.make((Boolean) value); } else if (value instanceof Byte) { return CstByte.make((Byte) value); } else if (value instanceof Character) { return CstChar.make((Character) value); } else if (value instanceof Double) { return CstDouble.make(Double.doubleToLongBits((Double) value)); } else if (value instanceof Float) { return CstFloat.make(Float.floatToIntBits((Float) value)); } else if (value instanceof Integer) { return CstInteger.make((Integer) value); } else if (value instanceof Long) { return CstLong.make((Long) value); } else if (value instanceof Short) { return CstShort.make((Short) value); } else if (value instanceof String) { return new CstString((String) value); } else if (value instanceof Class) { return new CstType(TypeId.get((Class<?>) value).ropType); } else if (value instanceof TypeId) { return new CstType(((TypeId) value).ropType); } else { throw new UnsupportedOperationException("Not a constant: " + value);
private void addDependencies(DirectClassFile classFile) { for (Constant constant : classFile.getConstantPool().getEntries()) { if (constant instanceof CstType) { checkDescriptor(((CstType) constant).getClassType().getDescriptor()); } else if (constant instanceof CstFieldRef) { checkDescriptor(((CstFieldRef) constant).getType().getDescriptor()); } else if (constant instanceof CstBaseMethodRef) { checkPrototype(((CstBaseMethodRef) constant).getPrototype()); } } FieldList fields = classFile.getFields(); int nbField = fields.size(); for (int i = 0; i < nbField; i++) { checkDescriptor(fields.get(i).getDescriptor().getString()); } MethodList methods = classFile.getMethods(); int nbMethods = methods.size(); for (int i = 0; i < nbMethods; i++) { checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString())); } } private void checkPrototype(Prototype proto) {
private void addDependencies(ConstantPool pool) { for (Constant constant : pool.getEntries()) { if (constant instanceof CstType) { checkDescriptor(((CstType) constant).getClassType()); } else if (constant instanceof CstFieldRef) { checkDescriptor(((CstFieldRef) constant).getType()); } else if (constant instanceof CstMethodRef) { Prototype proto = ((CstMethodRef) constant).getPrototype(); checkDescriptor(proto.getReturnType()); StdTypeList args = proto.getParameterTypes(); for (int i = 0; i < args.size(); i++) { checkDescriptor(args.get(i)); } } } }
/** * Convert a value of an element to a {@code Constant}. * <p><strong>Warning:</strong> Array or TypeId value is not supported yet. * * @param value an annotation element value. * @return a Constant */ static Constant toConstant(Object value) { Class clazz = value.getClass(); if (clazz.isEnum()) { CstString descriptor = new CstString(TypeId.get(clazz).getName()); CstString name = new CstString(((Enum)value).name()); CstNat cstNat = new CstNat(name, descriptor); return new CstEnumRef(cstNat); } else if (clazz.isArray()) { throw new UnsupportedOperationException("Array is not supported yet"); } else if (value instanceof TypeId) { throw new UnsupportedOperationException("TypeId is not supported yet"); } else { return Constants.getConstant(value); } } }
/** {@inheritDoc} */ @Override protected int compareTo0(Constant other) { int cmp = super.compareTo0(other); if (cmp != 0) { return cmp; } CstFieldRef otherField = (CstFieldRef) other; CstString thisDescriptor = getNat().getDescriptor(); CstString otherDescriptor = otherField.getNat().getDescriptor(); return thisDescriptor.compareTo(otherDescriptor); } }
/** * Gets whether this is a reference to a class initialization * method. This is just a convenient shorthand for * {@code getNat().isClassInit()}. * * @return {@code true} iff this is a reference to an * instance initialization method */ public final boolean isClassInit() { return getNat().isClassInit(); }
/** * Returns the type of this field. * * @return {@code non-null;} the field's type */ @Override public Type getType() { return getNat().getFieldType(); }
/** * Gets whether this is a reference to an instance initialization * method. This is just a convenient shorthand for * {@code getNat().isInstanceInit()}. * * @return {@code true} iff this is a reference to an * instance initialization method */ public final boolean isInstanceInit() { return getNat().isInstanceInit(); }
public void addSupperClass(String name){ if (name.endsWith(CLASS_EXTENSION)) { classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length())); } if (name.endsWith(CLASS_EXTENSION)) { DirectClassFile classFile; try { classFile = path.getClass(name); CstType superClass = classFile.getSuperclass(); if (superClass != null) { String superClassName=superClass.getClassType().getClassName(); classNames.add(superClassName); } } catch (FileNotFoundException e) { // throw new IOException("Class " + name + // " is missing form original class path " + path, e); } } } public void addRootsV2(String name){
/** * Set an annotation element of this instance. * If there is a preexisting element with the same name, it will be * replaced by this method. * * @param element {@code non-null;} the annotation element to be set. */ public void set(Element element) { if (element == null) { throw new NullPointerException("element == null"); } CstString pairName = new CstString(element.getName()); Constant pairValue = Element.toConstant(element.getValue()); NameValuePair nameValuePair = new NameValuePair(pairName, pairValue); elements.put(element.getName(), nameValuePair); }
/** * Assigns registers to locals. From the spec: * "the N arguments to a method land in the last N registers of the * method's invocation frame, in order. Wide arguments consume two * registers. Instance methods are passed a this reference as their * first argument." * * In addition to assigning registers to each of the locals, this creates * instructions to move parameters into their initial registers. These * instructions are inserted before the code's first real instruction. */ void initializeLocals() { if (localsInitialized) { throw new AssertionError(); } localsInitialized = true; int reg = 0; for (Local<?> local : locals) { reg += local.initialize(reg); } int firstParamReg = reg; List<Insn> moveParameterInstructions = new ArrayList<Insn>(); for (Local<?> local : parameters) { CstInteger paramConstant = CstInteger.make(reg - firstParamReg); reg += local.initialize(reg); moveParameterInstructions.add(new PlainCstInsn(Rops.opMoveParam(local.type.ropType), sourcePosition, local.spec(), RegisterSpecList.EMPTY, paramConstant)); } labels.get(0).instructions.addAll(0, moveParameterInstructions); }
private void addClassWithHierachy(String classBinaryName) { if (classNames.contains(classBinaryName)) { return; } try { DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION); classNames.add(classBinaryName); CstType superClass = classFile.getSuperclass(); if (superClass != null) { addClassWithHierachy(superClass.getClassType().getClassName()); } TypeList interfaceList = classFile.getInterfaces(); int interfaceNumber = interfaceList.size(); for (int i = 0; i < interfaceNumber; i++) { addClassWithHierachy(interfaceList.getType(i).getClassName()); } } catch (FileNotFoundException e) { // Ignore: The referenced type is not in the path it must be part of the libraries. } } }
} else { CstType cstType = CstType.intern(type.ropType);
interfaces.ropTypes, new CstString(sourceFile));
addClassWithHierachy(superClass.getClassType().getClassName());