/** * @covers ::replace */ public function testReplaceMultipleInbound() { Helper::replace($this->v[4], $this->v[6], $this->graph); $this->assertFalse($this->graph->hasVertex($this->v[4])); $adj = $this->getValues($this->graph->successorsOf($this->v[2])); $this->assertEquals(1, count($adj)); $this->assertSame($this->v[6], $adj[0]); $adj = $this->getValues($this->graph->successorsOf($this->v[3])); $this->assertEquals(1, count($adj)); $this->assertSame($this->v[6], $adj[0]); $adj = $this->getValues($this->graph->successorsOf($this->v[6])); $this->assertEquals(1, count($adj)); $this->assertSame($this->v[5], $adj[0]); }
public function process(Vertex $vertex, Digraph $graph) { if ($vertex instanceof JitBinaryOp && $vertex->getA() instanceof Constant && $vertex->getB() instanceof Constant) { $ret = null; switch ($vertex->getKind()) { case JitBinaryOp::CONCAT: $ret = $vertex->getA()->getValue() . $vertex->getB()->getValue(); break; case JitBinaryOp::PLUS: $ret = $vertex->getA()->getValue() + $vertex->getB()->getValue(); break; case JitBinaryOp::MINUS: $ret = $vertex->getA()->getValue() - $vertex->getB()->getValue(); break; case JitBinaryOp::MUL: $ret = $vertex->getA()->getValue() * $vertex->getB()->getValue(); break; case JitBinaryOp::DIV: $ret = $vertex->getA()->getValue() / $vertex->getB()->getValue(); break; case JitBinaryOp::MOD: $ret = $vertex->getA()->getValue() % $vertex->getB()->getValue(); break; case JitBinaryOp::EQUAL: $ret = $vertex->getA()->getValue() == $vertex->getB()->getValue(); break; case JitBinaryOp::NOT_EQUAL: $ret = $vertex->getA()->getValue() != $vertex->getB()->getValue(); break; case JitBinaryOp::IDENTICAL: $ret = $vertex->getA()->getValue() == $vertex->getB()->getValue(); break; case JitBinaryOp::NOT_IDENTICAL: $ret = $vertex->getA()->getValue() !== $vertex->getB()->getValue(); break; case JitBinaryOp::GREATER: $ret = $vertex->getA()->getValue() > $vertex->getB()->getValue(); break; case JitBinaryOp::GREATER_EQUAL: $ret = $vertex->getA()->getValue() >= $vertex->getB()->getValue(); break; case JitBinaryOp::SMALLER: $ret = $vertex->getA()->getValue() < $vertex->getB()->getValue(); break; case JitBinaryOp::SMALLER_EQUAL: $ret = $vertex->getA()->getValue() <= $vertex->getB()->getValue(); break; case JitBinaryOp::BITWISE_AND: $ret = $vertex->getA()->getValue() & $vertex->getB()->getValue(); break; case JitBinaryOp::BITWISE_OR: $ret = $vertex->getA()->getValue() | $vertex->getB()->getValue(); break; case JitBinaryOp::BITWISE_XOR: $ret = $vertex->getA()->getValue() ^ $vertex->getB()->getValue(); break; case JitBinaryOp::SHIFT_LEFT: $ret = $vertex->getA()->getValue() << $vertex->getB()->getValue(); break; case JitBinaryOp::SHIFT_RIGHT: $ret = $vertex->getA()->getValue() >> $vertex->getB()->getValue(); break; } // replace binary op with assign op Helper::replace($vertex, new JitAssign(new Constant($ret), $vertex->getResult()), $graph); return true; } return false; }