public function serialize(ControlFlowGraph $graph) { $dot = "digraph G {\n"; $this->ids = new \SplObjectStorage(); $this->idCount = 0; $dot .= " " . $this->getId($graph->getImplicitReturn()) . " [shape=box,label=\"implicit return\",style=filled]\n"; $entryPoint = $graph->getEntryPoint(); $nodes = $graph->getNodes(); foreach ($nodes as $astNode) { $node = $nodes[$astNode]; $id = $this->getId($node); $dot .= sprintf(' %s [shape=box,label="%s"', $id, str_replace('"', '\\"', NodeUtil::getStringRepr($astNode))); if ($node === $entryPoint) { $dot .= ",style=filled"; } $dot .= "]\n"; foreach ($node->getOutEdges() as $edge) { $dot .= sprintf(" %s -> %s", $id, $this->getId($edge->getDest())); switch ($edge->getType()) { case GraphEdge::TYPE_ON_FALSE: $dot .= ' [label="false"]'; break; case GraphEdge::TYPE_ON_TRUE: $dot .= ' [label="true"]'; break; case GraphEdge::TYPE_ON_EX: $dot .= ' [label="exception"]'; break; } $dot .= "\n"; } } $dot .= "}"; return $dot; }
private function assertNotMatch($code) { $this->computeUseDef($code); $analyzedUses = $this->analysis->getUses('x', $this->def); foreach ($this->uses as $use) { if (in_array($use, $analyzedUses, true)) { $this->fail('Did not expect ' . \Scrutinizer\PhpAnalyzer\PhpParser\NodeUtil::getStringRepr($use)); } } }
private function assertNotMatch($code) { $this->computeDefUse($code); $this->assertNotSame($this->def, $this->analysis->getDefiningNode('x', $this->use), 'Found definition was not expected: ' . \Scrutinizer\PhpAnalyzer\PhpParser\NodeUtil::getStringRepr($this->def)); }
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]; }); } }
public function __toString() { $str = 'DefinitionLattice('; $defs = array(); foreach ($this->definitions as $var) { $defs[$var->getName()] = null === $this->definitions[$var] ? null : NodeUtil::getStringRepr($this->definitions[$var]->getNode()); } $str .= json_encode($defs) . ')'; return $str; }