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; }