Exemplo n.º 1
0
  public void showCard(final String name, final Trait trait) {
    CardLayout layout = (CardLayout) innerPanel.getLayout();
    layout.show(innerPanel, name);
    boolean b = cardMap.get(name) instanceof TraitDetail;
    buttonsPanel.setVisible(b);

    TraitDetail newDetail = null;
    if (b) {
      newDetail = (TraitDetail) cardMap.get(name);
    }
    for (JComponent v : cardMap.values()) {
      if (v instanceof TraitDetail) {
        if (v != newDetail) {
          TraitDetail oldDetail = (TraitDetail) v;
          oldDetail.setActive(false);
        }
      }
    }
    if (newDetail != null) {
      newDetail.setActive(true);
    }

    selectedCard = name;
    selectedLabel.setText(selectedCard);
    if (trait == null) {
      traitNameLabel.setText("-");
    } else {
      if (abcPanel != null) {
        traitNameLabel.setText(
            trait.getName(abcPanel.abc).getName(abcPanel.abc.constants, null, false));
      }
    }
  }
Exemplo n.º 2
0
  public void showCard(final String name, final Trait trait) {
    View.execInEventDispatch(
        () -> {
          CardLayout layout = (CardLayout) innerPanel.getLayout();
          layout.show(innerPanel, name);
          boolean b = cardMap.get(name) instanceof TraitDetail;
          boolean drun;
          synchronized (this) {
            buttonsShouldBeShown = b;
            drun = debugRunning;
          }
          buttonsPanel.setVisible(b && !drun);

          TraitDetail newDetail = null;
          if (b) {
            newDetail = (TraitDetail) cardMap.get(name);
          }
          for (JComponent v : cardMap.values()) {
            if (v instanceof TraitDetail) {
              if (v != newDetail) {
                TraitDetail oldDetail = (TraitDetail) v;
                oldDetail.setActive(false);
              }
            }
          }
          if (newDetail != null) {
            newDetail.setActive(true);
          }

          selectedCard = name;
          selectedLabel.setText(selectedCard);
          if (trait == null) {
            traitNameLabel.setText("-");
          } else {
            if (abcPanel != null) {
              traitNameLabel.setText(
                  trait.getName(abcPanel.abc).getName(abcPanel.abc.constants, null, false));
            }
          }
        });
  }
Exemplo n.º 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));
  }
Exemplo n.º 4
0
  private void addTraitButtonActionPerformed(ActionEvent evt) {
    int class_index = decompiledTextArea.getClassIndex();
    if (class_index < 0) {
      return;
    }
    if (newTraitDialog == null) {
      newTraitDialog = new NewTraitDialog();
    }
    int void_type =
        abc.constants.getPublicQnameId(
            "void", true); // abc.constants.forceGetMultinameId(new Multiname(Multiname.QNAME,
    // abc.constants.forceGetStringId("void"), abc.constants.forceGetNamespaceId(new
    // Namespace(Namespace.KIND_PACKAGE, abc.constants.forceGetStringId("")), 0), -1,
    // -1, new ArrayList<Integer>()));
    int int_type =
        abc.constants.getPublicQnameId(
            "int", true); // abc.constants.forceGetMultinameId(new Multiname(Multiname.QNAME,
    // abc.constants.forceGetStringId("int"), abc.constants.forceGetNamespaceId(new
    // Namespace(Namespace.KIND_PACKAGE, abc.constants.forceGetStringId("")), 0), -1,
    // -1, new ArrayList<Integer>()));

    Trait t = null;
    int kind;
    int nskind;
    String name = null;
    boolean isStatic;
    Multiname m;

    boolean again = false;
    loopm:
    do {
      if (again) {
        View.showMessageDialog(
            null,
            AppStrings.translate("error.trait.exists").replace("%name%", name),
            AppStrings.translate("error"),
            JOptionPane.ERROR_MESSAGE);
      }
      again = false;
      if (newTraitDialog.showDialog() != AppDialog.OK_OPTION) {
        return;
      }
      kind = newTraitDialog.getTraitType();
      nskind = newTraitDialog.getNamespaceKind();
      name = newTraitDialog.getTraitName();
      isStatic = newTraitDialog.getStatic();
      m =
          new Multiname(
              Multiname.QNAME,
              abc.constants.getStringId(name, true),
              abc.constants.getNamespaceId(
                  new Namespace(nskind, abc.constants.getStringId("", true)), 0, true),
              0,
              0,
              new ArrayList<>());
      int mid = abc.constants.getMultinameId(m);
      if (mid == 0) {
        break;
      }
      for (Trait tr : abc.class_info.get(class_index).static_traits.traits) {
        if (tr.name_index == mid) {
          again = true;
          break;
        }
      }

      for (Trait tr : abc.instance_info.get(class_index).instance_traits.traits) {
        if (tr.name_index == mid) {
          again = true;
          break;
        }
      }
    } while (again);
    switch (kind) {
      case Trait.TRAIT_GETTER:
      case Trait.TRAIT_SETTER:
      case Trait.TRAIT_METHOD:
        TraitMethodGetterSetter tm = new TraitMethodGetterSetter();
        MethodInfo mi =
            new MethodInfo(
                new int[0],
                void_type,
                abc.constants.getStringId(name, true),
                0,
                new ValueKind[0],
                new int[0]);
        int method_info = abc.addMethodInfo(mi);
        tm.method_info = method_info;
        MethodBody body = new MethodBody();
        body.method_info = method_info;
        body.init_scope_depth = 1;
        body.max_regs = 1;
        body.max_scope_depth = 1;
        body.max_stack = 1;
        body.exceptions = new ABCException[0];
        AVM2Code code = new AVM2Code();
        code.code.add(new AVM2Instruction(0, new GetLocal0Ins(), new int[0]));
        code.code.add(new AVM2Instruction(0, new PushScopeIns(), new int[0]));
        code.code.add(new AVM2Instruction(0, new ReturnVoidIns(), new int[0]));
        body.setCode(code);
        Traits traits = new Traits();
        traits.traits = new ArrayList<>();
        body.traits = traits;
        abc.addMethodBody(body);
        mi.setBody(body);
        t = tm;
        break;
      case Trait.TRAIT_SLOT:
      case Trait.TRAIT_CONST:
        TraitSlotConst ts = new TraitSlotConst();
        ts.type_index = int_type;
        ts.value_kind = ValueKind.CONSTANT_Int;
        ts.value_index = abc.constants.getIntId(0, true);
        t = ts;
        break;
    }
    if (t != null) {
      t.kindType = kind;
      t.name_index = abc.constants.getMultinameId(m, true);
      int traitId;
      if (isStatic) {
        traitId = abc.class_info.get(class_index).static_traits.addTrait(t);
      } else {
        traitId =
            abc.class_info.get(class_index).static_traits.traits.size()
                + abc.instance_info.get(class_index).instance_traits.addTrait(t);
      }
      reload();
      decompiledTextArea.gotoTrait(traitId);
    }
  }