Beispiel #1
0
 private void branch(Expr condition, BasicBlock consequentBlock, BasicBlock alternativeBlock) {
   Statement consequent = generateJumpStatement(consequentBlock);
   Statement alternative = generateJumpStatement(alternativeBlock);
   statements.add(
       Statement.cond(
           condition,
           consequent != null ? Arrays.asList(consequent) : Collections.emptyList(),
           alternative != null ? Arrays.asList(alternative) : Collections.emptyList()));
 }
 private List<Instruction> transformInvoke(InvokeInstruction insn) {
   if (insn.getType() != InvocationType.VIRTUAL) {
     return null;
   }
   MethodReference method = insn.getMethod();
   if (method.getClassName().equals(ResourceArray.class.getName())
       || method.getClassName().equals(ResourceMap.class.getName())) {
     if (method.getName().equals("keys")) {
       return transformKeys(insn);
     }
     InvokeInstruction accessInsn = new InvokeInstruction();
     accessInsn.setType(InvocationType.SPECIAL);
     ValueType[] types = new ValueType[method.getDescriptor().parameterCount() + 2];
     types[0] = ValueType.object("java.lang.Object");
     System.arraycopy(
         method.getDescriptor().getSignature(),
         0,
         types,
         1,
         method.getDescriptor().parameterCount() + 1);
     accessInsn.setMethod(
         new MethodReference(ResourceAccessor.class.getName(), method.getName(), types));
     accessInsn.getArguments().add(insn.getInstance());
     accessInsn.getArguments().addAll(insn.getArguments());
     accessInsn.setReceiver(insn.getReceiver());
     return Arrays.asList(accessInsn);
   }
   ClassReader iface = innerSource.get(method.getClassName());
   if (iface == null
       || !innerSource.isSuperType(Resource.class.getName(), iface.getName()).orElse(false)) {
     return null;
   }
   if (method.getName().startsWith("get")) {
     if (method.getName().length() > 3) {
       return transformGetterInvocation(insn, getPropertyName(method.getName().substring(3)));
     }
   } else if (method.getName().startsWith("is")) {
     if (method.getName().length() > 2) {
       return transformGetterInvocation(insn, getPropertyName(method.getName().substring(2)));
     }
   } else if (method.getName().startsWith("set")) {
     if (method.getName().length() > 3) {
       return transformSetterInvocation(insn, getPropertyName(method.getName().substring(3)));
     }
   }
   return null;
 }
  private List<Instruction> transformKeys(InvokeInstruction insn) {
    Variable tmp = program.createVariable();

    InvokeInstruction keysInsn = new InvokeInstruction();
    keysInsn.setType(InvocationType.SPECIAL);
    keysInsn.setMethod(
        new MethodReference(ResourceAccessor.class, "keys", Object.class, Object.class));
    keysInsn.getArguments().add(insn.getInstance());
    keysInsn.setReceiver(tmp);

    InvokeInstruction transformInsn = new InvokeInstruction();
    transformInsn.setType(InvocationType.SPECIAL);
    transformInsn.setMethod(
        new MethodReference(ResourceAccessor.class, "keysToStrings", Object.class, String[].class));
    transformInsn.getArguments().add(tmp);
    transformInsn.setReceiver(insn.getReceiver());

    return Arrays.asList(keysInsn, transformInsn);
  }