Beispiel #1
0
  @Test
  public void unitializedReads() {
    Program program = new SimpleProgramBuilder().emitRead("x").buildProgram();

    Assert.assertEquals(
        Collections.singleton((ReadInstruction) program.get(0)), program.getUninitializedReads());
  }
Beispiel #2
0
  @Test
  public void unreachable() {
    Program program = new SimpleProgramBuilder().emitRet().emitNop().buildProgram();

    Assert.assertEquals(
        Collections.singleton(program.get(1)), program.getUnreachableInstructions());
  }
Beispiel #3
0
  @Test
  public void unusedAssignments() {
    Program program = new SimpleProgramBuilder().emitWrite("x").buildProgram();

    Assert.assertEquals(
        Collections.singleton((WriteInstruction) program.get(0)), program.getUnusedAssignments());
  }
Beispiel #4
0
  @Test
  public void noExpectedReturnInTryFinallyWithReturn() {
    Program program =
        new SimpleProgramBuilder().emitTry().emitRet().emitFinally().emitEndTry().buildProgram();

    Assert.assertTrue(program.getExpectedReturns().isEmpty());
  }
  @Test
  public void simple() {
    Expression program = new NopExpression();

    Program p = new ExpressionProgramBuilder().buildProgram(program);

    Assert.assertEquals("0: end\n", p.toString());
  }
  @Test
  public void sequence() {
    SeqExpression program =
        new SeqExpression(new VariableExpression("a"), new VariableExpression("b"));

    Program p = new ExpressionProgramBuilder().buildProgram(program);

    Assert.assertEquals("0: read a\n" + "1: read b\n" + "2: end\n", p.toString());
  }
  @Test
  public void whileExpression() {
    Expression program =
        new WhileExpression(
            new VariableExpression("a"), new AssignmentExpression("b", new NopExpression()));

    Program p = new ExpressionProgramBuilder().buildProgram(program);

    Assert.assertEquals(
        "0: read a\n" + "1: ifjump 3\n" + "2: write b\n" + "3: end\n", p.toString());
  }
 public void doExecute(@NotNull final AnActionEvent event, final Map<String, Object> _params) {
   try {
     Program program =
         DataFlowManager.getInstance()
             .buildProgramFor(((SNode) MapSequence.fromMap(_params).get("node")));
     AnalysisResult<Set<WriteInstruction>> result =
         program.analyze(new ReachingDefinitionsAnalyzer());
     System.out.println(result.toString());
   } catch (Throwable t) {
     LOG.error(
         "User's action execute method failed. Action:" + "PrintReachingDefinintionsInformation",
         t);
   }
 }
  @Test
  public void ifExpression() {
    Expression program =
        new IfExpression(
            new NopExpression(),
            new AssignmentExpression("a", new NopExpression()),
            new AssignmentExpression("b", new NopExpression()));

    Program p = new ExpressionProgramBuilder().buildProgram(program);

    Assert.assertEquals(
        "0: ifjump 3\n" + "1: write a\n" + "2: jump 4\n" + "3: write b\n" + "4: end\n",
        p.toString());
  }
Beispiel #10
0
  @Test
  public void programWithTryFinally() {
    Program program =
        new SimpleProgramBuilder()
            .emitTry()
            .emitRead("x")
            .emitFinally()
            .emitRead("x")
            .emitEndTry()
            .buildProgram();

    Assert.assertEquals(
        "0: try\n" + "1: read x\n" + "2: finally\n" + "3: read x\n" + "4: endTry\n" + "5: end\n",
        program.toString());
  }
Beispiel #11
0
  @Test
  public void expectedReturns() {
    Program program = new SimpleProgramBuilder().emitNop().buildProgram();

    Assert.assertEquals(Collections.singleton(program.get(0)), program.getExpectedReturns());
  }
Beispiel #12
0
  @Test
  public void simpleProgramBuilding() {
    Program program = new SimpleProgramBuilder().emitRead("x").emitWrite("y").buildProgram();

    Assert.assertEquals("0: read x\n" + "1: write y\n" + "2: end\n", program.toString());
  }
Beispiel #13
0
  @Test
  public void writeWithReadIsNotUnusedAssignment() {
    Program program = new SimpleProgramBuilder().emitWrite("x").emitRead("x").buildProgram();

    Assert.assertTrue(program.getUnusedAssignments().isEmpty());
  }
Beispiel #14
0
  @Test
  public void expectedReturnInUnreachableCode() {
    Program program = new SimpleProgramBuilder().emitRet().emitNop().buildProgram();

    Assert.assertEquals(Collections.EMPTY_SET, program.getExpectedReturns());
  }