@Override
  public int getStackPopCount(BaseLocalData localData, TranslateStack stack) {
    int result = 3;
    if (stack.size() >= 3) {
      result += stack.peek(3).getAsLong();
    }

    return result;
  }
 @Override
 public void translate(
     TranslateStack stack,
     List<GraphTargetItem> output,
     HashMap<Integer, String> regNames,
     HashMap<String, GraphTargetItem> variables,
     HashMap<String, GraphTargetItem> functions,
     int staticOperation,
     String path) {
   GraphTargetItem value = stack.peek();
   stack.push(new DuplicateItem(this, value));
   value.getMoreSrc().add(new GraphSourceItemPos(this, 0));
 }
Пример #3
0
  @Override
  public void translate(
      boolean isStatic,
      int scriptIndex,
      int classIndex,
      HashMap<Integer, GraphTargetItem> localRegs,
      TranslateStack stack,
      ScopeStack scopeStack,
      AVM2ConstantPool constants,
      AVM2Instruction ins,
      List<MethodInfo> method_info,
      List<GraphTargetItem> output,
      MethodBody body,
      ABC abc,
      HashMap<Integer, String> localRegNames,
      List<DottedChain> fullyQualifiedNames,
      String path,
      HashMap<Integer, Integer> localRegsAssignmentIps,
      int ip,
      HashMap<Integer, List<Integer>> refs,
      AVM2Code code) {
    int slotIndex = ins.operands[0];
    GraphTargetItem value = stack.pop();
    GraphTargetItem obj = stack.pop(); // scopeId
    GraphTargetItem objnoreg = obj;
    obj = obj.getThroughRegister();
    Multiname slotname = null;
    if (obj instanceof NewActivationAVM2Item) {
      ((NewActivationAVM2Item) obj).slots.put(slotIndex, value);
    }

    if (obj instanceof ExceptionAVM2Item) {
      slotname = constants.getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
    } else if (obj instanceof ClassAVM2Item) {
      slotname = ((ClassAVM2Item) obj).className;
    } else if (obj instanceof ThisAVM2Item) {
      slotname = ((ThisAVM2Item) obj).className;
    } else if (obj instanceof ScriptAVM2Item) {
      for (int t = 0;
          t < abc.script_info.get(((ScriptAVM2Item) obj).scriptIndex).traits.traits.size();
          t++) {
        Trait tr = abc.script_info.get(((ScriptAVM2Item) obj).scriptIndex).traits.traits.get(t);
        if (tr instanceof TraitWithSlot) {
          if (((TraitWithSlot) tr).getSlotIndex() == slotIndex) {
            slotname = tr.getName(abc);
          }
        }
      }
    } else if (obj instanceof NewActivationAVM2Item) {

      for (int t = 0; t < body.traits.traits.size(); t++) {
        if (body.traits.traits.get(t) instanceof TraitWithSlot) {
          if (((TraitWithSlot) body.traits.traits.get(t)).getSlotIndex() == slotIndex) {
            slotname = body.traits.traits.get(t).getName(abc);
          }
        }
      }
    }

    if (slotname != null) {
      if (value instanceof LocalRegAVM2Item) {
        LocalRegAVM2Item lr = (LocalRegAVM2Item) value;
        String slotNameStr = slotname.getName(constants, fullyQualifiedNames, true);
        if (localRegNames.containsKey(lr.regIndex)) {
          if (localRegNames.get(lr.regIndex).equals(slotNameStr)) {
            return; // Register with same name to slot
          }
        }
      }
    }

    if (value.getNotCoerced().getThroughDuplicate() instanceof IncrementAVM2Item) {
      GraphTargetItem inside =
          ((IncrementAVM2Item) value.getNotCoerced())
              .value
              .getThroughRegister()
              .getNotCoerced()
              .getThroughDuplicate();
      if (inside instanceof GetSlotAVM2Item) {
        GetSlotAVM2Item slotItem = (GetSlotAVM2Item) inside;
        if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
            && (slotItem.slotName == slotname)) {
          if (stack.size() > 0) {
            GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
            if (top == inside) {
              stack.pop();
              stack.push(new PostIncrementAVM2Item(ins, inside));
            } else if ((top instanceof IncrementAVM2Item)
                && (((IncrementAVM2Item) top).value == inside)) {
              stack.pop();
              stack.push(new PreIncrementAVM2Item(ins, inside));
            } else {
              output.add(new PostIncrementAVM2Item(ins, inside));
            }
          } else {
            output.add(new PostIncrementAVM2Item(ins, inside));
          }
          return;
        }
      }
    }

    if (value.getNotCoerced().getThroughDuplicate() instanceof DecrementAVM2Item) {
      GraphTargetItem inside =
          ((DecrementAVM2Item) value.getNotCoerced())
              .value
              .getThroughRegister()
              .getNotCoerced()
              .getThroughDuplicate();
      if (inside instanceof GetSlotAVM2Item) {
        GetSlotAVM2Item slotItem = (GetSlotAVM2Item) inside;
        if ((slotItem.scope.getThroughRegister() == obj.getThroughRegister())
            && (slotItem.slotName == slotname)) {
          if (stack.size() > 0) {
            GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
            if (top == inside) {
              stack.pop();
              stack.push(new PostDecrementAVM2Item(ins, inside));
            } else if ((top instanceof DecrementAVM2Item)
                && (((DecrementAVM2Item) top).value == inside)) {
              stack.pop();
              stack.push(new PreDecrementAVM2Item(ins, inside));
            } else {
              output.add(new PostDecrementAVM2Item(ins, inside));
            }
          } else {
            output.add(new PostDecrementAVM2Item(ins, inside));
          }
          return;
        }
      }
    }

    output.add(new SetSlotAVM2Item(ins, obj, slotname, value));
  }
  @Override
  public void translate(
      TranslateStack stack,
      List<GraphTargetItem> output,
      HashMap<Integer, String> regNames,
      HashMap<String, GraphTargetItem> variables,
      HashMap<String, GraphTargetItem> functions,
      int staticOperation,
      String path) {
    GraphTargetItem value = stack.pop().getThroughDuplicate();
    GraphTargetItem memberName = stack.pop();
    GraphTargetItem object = stack.pop();
    if (value instanceof IncrementActionItem) {
      GraphTargetItem obj = ((IncrementActionItem) value).object;
      if (!stack.isEmpty() && stack.peek().valueEquals(obj)) {
        stack.pop();
        stack.push(new PostIncrementActionItem(this, obj));
        return;
      }
    }
    if (value instanceof DecrementActionItem) {
      GraphTargetItem obj = ((DecrementActionItem) value).object;
      if (!stack.isEmpty() && stack.peek().valueEquals(obj)) {
        stack.pop();
        stack.push(new PostDecrementActionItem(this, obj));
        return;
      }
    }

    if (value instanceof IncrementActionItem) {
      if (((IncrementActionItem) value).object instanceof GetMemberActionItem) {
        if (((GetMemberActionItem) ((IncrementActionItem) value).object).object.equals(object)) {
          if (((GetMemberActionItem) ((IncrementActionItem) value).object)
              .memberName.equals(memberName)) {
            output.add(new PostIncrementActionItem(this, ((IncrementActionItem) value).object));
            return;
          }
        }
      }
    }
    if (value instanceof DecrementActionItem) {
      if (((DecrementActionItem) value).object instanceof GetMemberActionItem) {
        if (((GetMemberActionItem) ((DecrementActionItem) value).object)
            .object.valueEquals(object)) {
          if (((GetMemberActionItem) ((DecrementActionItem) value).object)
              .memberName.equals(memberName)) {
            output.add(new PostDecrementActionItem(this, ((DecrementActionItem) value).object));
            return;
          }
        }
      }
    }
    GraphTargetItem ret = new SetMemberActionItem(this, object, memberName, value);
    if (value instanceof StoreRegisterActionItem) {
      StoreRegisterActionItem sr = (StoreRegisterActionItem) value;
      if (sr.define) {
        value = sr.getValue();
        ((SetMemberActionItem) ret).setValue(value);
        if (value instanceof IncrementActionItem) {
          if (((IncrementActionItem) value).object instanceof GetMemberActionItem) {
            if (((GetMemberActionItem) ((IncrementActionItem) value).object)
                .valueEquals(((SetMemberActionItem) ret).getObject())) {
              ret = new PreIncrementActionItem(this, ((IncrementActionItem) value).object);
            }
          }
        } else if (value instanceof DecrementActionItem) {
          if (((DecrementActionItem) value).object instanceof GetMemberActionItem) {
            if (((GetMemberActionItem) ((DecrementActionItem) value).object)
                .valueEquals(((SetMemberActionItem) ret).getObject())) {
              ret = new PreDecrementActionItem(this, ((DecrementActionItem) value).object);
            }
          }
        } else {
          sr.temporary = true;
          ((SetMemberActionItem) ret).setValue(sr);
        }
        variables.put(
            "__register" + sr.register.number, new TemporaryRegister(sr.register.number, ret));
        return;
      }
    }
    output.add(ret);
  }
  @Override
  public void translate(
      TranslateStack stack,
      List<GraphTargetItem> output,
      HashMap<Integer, String> regNames,
      HashMap<String, GraphTargetItem> variables,
      HashMap<String, GraphTargetItem> functions,
      int staticOperation,
      String path) {
    GraphTargetItem value = stack.pop();
    RegisterNumber rn = new RegisterNumber(registerNumber);
    if (regNames.containsKey(registerNumber)) {
      rn.name = regNames.get(registerNumber);
    }
    value.getMoreSrc().add(new GraphSourceItemPos(this, 0));
    if (variables.containsKey("__register" + registerNumber)) {
      if (variables.get("__register" + registerNumber) instanceof TemporaryRegister) {
        variables.remove("__register" + registerNumber);
      }
    }
    boolean define = !variables.containsKey("__register" + registerNumber);
    if (regNames.containsKey(registerNumber)) {
      define = false;
    }
    variables.put("__register" + registerNumber, value);
    if (value instanceof DirectValueActionItem) {
      if (((DirectValueActionItem) value).value instanceof RegisterNumber) {
        if (((RegisterNumber) ((DirectValueActionItem) value).value).number == registerNumber) {
          stack.push(value);
          return;
        }
      }
    }
    if (value instanceof StoreRegisterActionItem) {
      if (((StoreRegisterActionItem) value).register.number == registerNumber) {
        stack.push(value);
        return;
      }
    }

    if (value instanceof IncrementActionItem) {
      GraphTargetItem obj = ((IncrementActionItem) value).object;
      if (!stack.isEmpty()) {
        if (stack.peek().valueEquals(obj)) {
          stack.pop();
          stack.push(new PostIncrementActionItem(this, obj));
          stack.push(obj);
          return;
        }
      }
    }
    if (value instanceof DecrementActionItem) {
      GraphTargetItem obj = ((DecrementActionItem) value).object;
      if (!stack.isEmpty()) {
        if (stack.peek().valueEquals(obj)) {
          stack.pop();
          stack.push(new PostDecrementActionItem(this, obj));
          stack.push(obj);
          return;
        }
      }
    }
    stack.push(new StoreRegisterActionItem(this, rn, value, define));
  }