Ejemplo n.º 1
0
 public function process(Vertex $vertex, Digraph $graph)
 {
     if ($vertex instanceof Assignment && $vertex->isIdempotent() && 1 >= $this->countUsages($vertex->getResult(), $graph)) {
         Helper::remove($vertex, $graph);
         return true;
     }
     return false;
 }
Ejemplo n.º 2
0
 public function process(Vertex $vertex, Digraph $graph)
 {
     if ($graph->inDegreeOf($vertex) === 0 && !$vertex instanceof Vertex\Function_) {
         Helper::remove($vertex, $graph);
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 public function removePhi(Phi $vertex, GraphState $state)
 {
     $graph = $state->getGraph();
     Helper::remove($vertex, $graph);
     $to = $vertex->getResult();
     foreach ($vertex->getValues() as $value) {
         foreach ($graph->vertices() as $v) {
             $v->replaceVariable($value, $to);
             if ($v instanceof Assignment && $v->getResult() === $value) {
                 $v->setResult($to);
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function process(Vertex $vertex, Digraph $graph)
 {
     if ($vertex instanceof Vertex\Phi) {
         $types = [];
         foreach ($vertex->getValues() as $value) {
             $types[] = (string) $value->getType();
         }
         $types = array_unique($types);
         if ($vertex->getResult()->getType()->isUnknown()) {
             $type = null;
             $setAll = false;
             if (count($types) === 1 && $types[0] !== 'unknown') {
                 $type = Type::normalizeType($types[0]);
             } elseif (count($types) === 2 && in_array('long', $types) && in_array('numeric', $types)) {
                 $type = new Type(Type::TYPE_LONG);
                 $setAll = true;
             } elseif (count($types) === 2 && in_array('double', $types) && in_array('numeric', $types)) {
                 $type = new Type(Type::TYPE_DOUBLE);
                 $setAll = true;
             } elseif (count($types) === 2 && in_array('bool', $types) && in_array('numeric', $types)) {
                 $type = new Type(Type::TYPE_BOOLEAN);
             }
             if ($type) {
                 $vertex->getResult()->setType($type);
                 if ($setAll) {
                     foreach ($vertex->getValues() as $value) {
                         $value->setType($type);
                     }
                 }
                 return true;
             }
         }
         if (count($vertex->getValues()) === 1) {
             // remove phi node
             list($val) = iterator_to_array($vertex->getValues());
             $result = $vertex->getResult();
             foreach ($graph->vertices() as $vtx) {
                 $vtx->replaceVariable($result, $val);
                 if ($vtx instanceof Assignment && $vtx->getResult() === $result) {
                     $vtx->setResult($val);
                 }
             }
             Helper::remove($vertex, $graph);
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * @covers ::remove
  */
 public function testRemoveMultipleInbound()
 {
     Helper::remove($this->v[4], $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[5], $adj[0]);
     $adj = $this->getValues($this->graph->successorsOf($this->v[3]));
     $this->assertEquals(1, count($adj));
     $this->assertSame($this->v[5], $adj[0]);
 }