Example #1
0
 public function resolve(Phi $vertex, GraphState $state)
 {
     $types = [];
     foreach ($vertex->getVariables() as $value) {
         $types[] = $value->getType()->getType();
     }
     $types = array_unique($types);
     switch (count($types)) {
         case 1:
             if ($types[0] !== Type::TYPE_UNKNOWN || 0 === count($vertex->getValues())) {
                 // resolve variables to result
                 $this->removePhi($vertex, $state);
                 return true;
             }
             break;
         case 2:
             if (in_array(Type::TYPE_NUMERIC, $types)) {
                 if (in_array(Type::TYPE_LONG, $types) || in_array(Type::TYPE_DOUBLE, $types)) {
                     $this->removePhi($vertex, $state);
                     return true;
                 } elseif (in_array(Type::TYPE_BOOLEAN, $types)) {
                     $vertex->getResult()->setType(new Type(Type::TYPE_NUMERIC));
                     $this->removePhi($vertex, $state);
                     return true;
                 }
             }
             break;
     }
     return false;
 }
Example #2
0
 /**
  * @covers ::process
  */
 public function testRemoveCountedPhi()
 {
     $rule = new Phi();
     $vertex = new JitPhi($r = new Variable(new Type(Type::TYPE_DOUBLE)));
     $vertex->addValue($v = new Variable(new Type(Type::TYPE_DOUBLE)));
     $v2 = $this->getMock(Vertex\Assign::class, [], [], '', false);
     $v2->expects($this->once())->method('getResult')->will($this->returnValue($r));
     $v2->expects($this->once())->method('setResult')->with($this->identicalTo($v));
     $graph = $this->getMock(DirectedAdjacencyList::class);
     $graph->expects($this->exactly(1))->method('vertices')->will($this->returnValue(call_user_func(function () use($vertex, $v2) {
         (yield $vertex);
         (yield $v2);
     })));
     $transposed = $this->getMock(DirectedAdjacencyList::class);
     $transposed->expects($this->once())->method('successorsOf')->with($this->identicalTo($vertex))->will($this->returnValue([]));
     $graph->expects($this->once())->method('transpose')->will($this->returnValue($transposed));
     $this->assertTrue($rule->process($vertex, $graph));
 }
Example #3
0
 /**
  * @covers ::isPhiVar
  */
 public function testisPhiVarNonValue()
 {
     $this->graph->ensureArc($this->v[5], $p = new Phi(new Variable()));
     $p->addValue(new Variable());
     $this->assertFalse(Helper::isPhiVar(new Variable(), $this->graph));
 }
Example #4
0
 /**
  * @covers ::replaceVariable
  */
 public function testReplaceVariablesNeither()
 {
     $phi = new Phi($r = new Variable());
     $phi->addValue($a = new Variable());
     $phi->addValue($b = new Variable());
     $phi->replaceVariable(new Variable(), new Variable());
     $this->assertSame([$r, $a, $b], $phi->getVariables());
 }