예제 #1
0
  @Override
  public IFigure getTooltip(Object element) {
    if (element instanceof BasicBlock) {
      BasicBlock bb = (BasicBlock) element;
      IR ir = irView.getIR();
      IDocument doc = irView.getDocument();
      IMethod method = ir.getMethod();

      StringBuffer result = new StringBuffer();

      int start = bb.getFirstInstructionIndex();
      int end = bb.getLastInstructionIndex();
      SSAInstruction[] instructions = ir.getInstructions();
      for (int j = start; j <= end; j++) {
        if (instructions[j] != null) {
          int sourceLineNum = method.getLineNumber(j);
          int lineNumber = sourceLineNum - 1; // IDocument indexing is 0-based
          try {
            int lineOffset = doc.getLineOffset(lineNumber);
            int lineLength = doc.getLineLength(lineNumber);
            String sourceCode = doc.get(lineOffset, lineLength).trim();
            result.append(sourceCode);
          } catch (BadLocationException e) {
          }
          result.append("\n");
        }
      }
      return new Label(result.toString());
    }
    return null;
  }
 public Set<String> getSetOfLinesRelatedToAddedMethods() {
   Set<String> lineNumbersOfAddedMethods = new HashSet<String>();
   for (IMethod method : getAddedMethods()) {
     int getLineNumberOfFirstLineOfMethod = 0;
     try {
       getLineNumberOfFirstLineOfMethod =
           method.getLineNumber(1); // getMethodStartLineNumber(method);
     } catch (Exception e) {
     }
     lineNumbersOfAddedMethods.add(
         getClassName(method.getDeclaringClass()) + "," + getLineNumberOfFirstLineOfMethod);
   }
   return lineNumbersOfAddedMethods;
 }
예제 #3
0
  @SuppressWarnings("unchecked")
  public void setIR(IR ir) {
    this.lineToPosition = HashMapFactory.make();
    this.pcToLine = HashMapFactory.make();
    this.lineToPc = HashMapFactory.make();

    int firstLineWithPosition = NA;

    try {
      methodName.setText("IR: " + ir.getMethod());
      irLineList.clear();
      BufferedReader br = new BufferedReader(new StringReader(ir.toString()));
      int lineNum = 0;
      int position = NA;
      String line;
      while ((line = br.readLine()) != null) {
        irLineList.addElement(line);
        int pc = parseIrLine(line);
        if (pc != NA) {
          IMethod m = ir.getMethod();
          int newPosition = m.getLineNumber(pc);
          if (newPosition != -1) {
            position = newPosition;
          }
          lineToPc.put(lineNum, pc);
          pcToLine.put(pc, lineNum);

          if (position != NA) {
            lineToPosition.put(lineNum, position);
            if (firstLineWithPosition == NA) {
              firstLineWithPosition = lineNum;
            }
          }
        }
        lineNum++;
      }
    } catch (IOException e) {
      // ???
      assert false;
    }

    // focusing on the first line with position
    if (firstLineWithPosition != NA) {
      irLines.setSelectedIndex(firstLineWithPosition);
      irLines.ensureIndexIsVisible(firstLineWithPosition);
    }
  }
예제 #4
0
  /** Taken from com.ibm.wala.viz.PDFViewUtil */
  @Override
  public String getText(Object element) {
    if (element instanceof BasicBlock) {
      BasicBlock bb = (BasicBlock) element;
      IR ir = irView.getIR();

      StringBuilder result = new StringBuilder();

      int start = bb.getFirstInstructionIndex();
      int end = bb.getLastInstructionIndex();

      result.append("BB").append(bb.getNumber());

      if (bb.isEntryBlock()) {
        result.append(" (en)\n");
      } else if (bb.isExitBlock()) {
        result.append(" (ex)\n");
      }
      if (bb instanceof ExceptionHandlerBasicBlock) {
        result.append("<Handler>");
      }
      result.append("\n");

      for (Iterator<SSAPhiInstruction> it = bb.iteratePhis(); it.hasNext(); ) {
        SSAPhiInstruction phi = it.next();
        if (phi != null) {
          result.append(phi.toString(ir.getSymbolTable())).append("\n");
        }
      }
      if (bb instanceof ExceptionHandlerBasicBlock) {
        ExceptionHandlerBasicBlock ebb = (ExceptionHandlerBasicBlock) bb;
        SSAGetCaughtExceptionInstruction s = ebb.getCatchInstruction();
        if (s != null) {
          result.append(s.toString(ir.getSymbolTable())).append("\n");
        } else {
          result.append(" No catch instruction. Unreachable?\n");
        }
      }

      SSAInstruction[] instructions = ir.getInstructions();
      IMethod method = ir.getMethod();
      for (int j = start; j <= end; j++) {
        if (instructions[j] != null) {
          String x;
          int sourceLineNum = method.getLineNumber(j);
          x =
              String.format(
                  j + " [L%03d] " + instructions[j].toString(ir.getSymbolTable()), sourceLineNum);
          String padded = String.format("%1$-35s", x);
          result.append(padded);
          result.append("\n");
          result.append(SSAValuesToLocalVariables(instructions[j], j, ir));
          result.append("\n");
        }
      }
      for (Iterator<SSAPiInstruction> it = bb.iteratePis(); it.hasNext(); ) {
        SSAPiInstruction pi = it.next();
        if (pi != null) {
          result.append("           " + pi.toString(ir.getSymbolTable())).append("\n");
        }
      }
      return result.toString();
    }
    if (element instanceof EntityConnectionData) {
      return "\n";
    }
    return "";
  }