Пример #1
0
  public DecompilerIfBlock(
      Block block,
      Decompiler decompiler,
      List<DecompilerBlock> thenBranch,
      List<DecompilerBlock> elseBranch,
      PrintStream infoStream) {
    super(block, decompiler);
    this.thenBranch = thenBranch;
    this.elseBranch = elseBranch;
    this.infoStream = infoStream;
    this.head = new DecompilerBasicBlock(block, decompiler, decompiler.getSchedule());

    if (!(thenBranch.isEmpty() == false
            && head.getBlock().getSuccessors().contains(thenBranch.get(0).getBlock())
        || (elseBranch.isEmpty() == false
            && head.getBlock().getSuccessors().contains(elseBranch.get(0).getBlock())))) {
      // first block of then / else MUST be a successor of the head!
      throw new AssertionError(decompiler.contexInformation);
    }
  }
Пример #2
0
  @Override
  public void printBlock(PrintStream stream, Block codeSuccessor) {
    List<DecompilerSyntaxLine> lines = head.getCode();
    for (int i = 0; i < lines.size() - 1; i++) {
      if (lines.get(i) != null) {
        String line = lines.get(i).getAsString();
        stream.println(decompiler.getIdent() + line);
      }
    }
    DecompilerIfLine ifLine = (DecompilerIfLine) lines.get(lines.size() - 1);
    if (!thenBranch.isEmpty() && block.getSuccessors().contains(thenBranch.get(0).getBlock())) {
      if (elseBranch.isEmpty()) {
        // while break:
        stream.println(decompiler.getIdent() + ifLine.getIfNegStatement());
        decompiler.ident();
        stream.println(decompiler.getIdent() + "BREAK TO " + block.getSuccessors().get(1));
        decompiler.undent();
        for (int i = 0; i < thenBranch.size(); i++) {
          if (i < thenBranch.size() - 1) {
            thenBranch.get(i).printBlock(stream, thenBranch.get(i + 1).getBlock());
          } else {
            thenBranch.get(i).printBlock(stream, codeSuccessor);
          }
        }
      } else {
        stream.println(decompiler.getIdent() + ifLine.getIfStatement() + " {");
        decompiler.ident();
        for (int i = 0; i < thenBranch.size(); i++) {
          if (i < thenBranch.size() - 1) {
            thenBranch.get(i).printBlock(stream, thenBranch.get(i + 1).getBlock());
          } else {
            thenBranch.get(i).printBlock(stream, codeSuccessor);
          }
        }
        decompiler.undent();
        stream.println(decompiler.getIdent() + "} ELSE {");
        decompiler.ident();
        for (int i = 0; i < elseBranch.size(); i++) {
          if (i < elseBranch.size() - 1) {
            elseBranch.get(i).printBlock(stream, elseBranch.get(i + 1).getBlock());
          } else {
            elseBranch.get(i).printBlock(stream, codeSuccessor);
          }
        }
        decompiler.undent();
        stream.println(decompiler.getIdent() + "}");
      }
    } else if (!elseBranch.isEmpty()
        && block.getSuccessors().contains(elseBranch.get(0).getBlock())) {
      if (thenBranch.isEmpty()) {
        // while break:
        stream.println(decompiler.getIdent() + ifLine.getIfStatement());
        decompiler.ident();
        stream.println(decompiler.getIdent() + "BREAK TO " + block.getSuccessors().get(0));
        decompiler.undent();
        for (int i = 0; i < elseBranch.size(); i++) {
          if (i < elseBranch.size() - 1) {
            elseBranch.get(i).printBlock(stream, elseBranch.get(i + 1).getBlock());
          } else {
            elseBranch.get(i).printBlock(stream, codeSuccessor);
          }
        }
      } else {
        stream.println(decompiler.getIdent() + ifLine.getIfNegStatement() + " {");
        decompiler.ident();
        for (int i = 0; i < elseBranch.size(); i++) {
          if (i < elseBranch.size() - 1) {
            elseBranch.get(i).printBlock(stream, elseBranch.get(i + 1).getBlock());
          } else {
            elseBranch.get(i).printBlock(stream, codeSuccessor);
          }
        }
        decompiler.undent();
        stream.println(decompiler.getIdent() + "} ELSE {");
        decompiler.ident();

        for (int i = 0; i < thenBranch.size(); i++) {
          if (i < thenBranch.size() - 1) {
            thenBranch.get(i).printBlock(stream, thenBranch.get(i + 1).getBlock());
          } else {
            thenBranch.get(i).printBlock(stream, codeSuccessor);
          }
        }

        decompiler.undent();
        stream.println(decompiler.getIdent() + "}");
      }
    } else {
      throw new AssertionError();
    }
  }