private function prioritizeFromEntryNode(GraphNode $entry) { $worklist = array(); $worklist[] = array($entry, $entry->getAstNode()->getAttribute('position', 0)); while (!empty($worklist)) { list($current, ) = array_shift($worklist); /** @var $current GraphNode */ if (null !== $current->getAttribute('priority')) { continue; } $current->setAttribute('priority', ++$this->priorityCounter); foreach ($current->getOutEdges() as $edge) { /** @var $edge GraphEdge */ $destNode = $edge->getDest(); // Implicit return is always the last node. if ($this->graph->isImplicitReturn($destNode)) { $position = $this->astPositionCounter + 1; } else { $position = $destNode->getAstNode()->getAttribute('position'); if (null === $position) { throw new \RuntimeException(NodeUtil::getStringRepr($destNode->getAstNode()) . ' has no position.'); } } $worklist[] = array($destNode, $position); } usort($worklist, function ($a, $b) { return $a[1] - $b[1]; }); } }