Skip to content

Commit be73506

Browse files
committed
Fix GraphViz printer
1 parent 55c0db4 commit be73506

File tree

1 file changed

+2
-46
lines changed

1 file changed

+2
-46
lines changed

lib/PHPCfg/Printer/GraphViz.php

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace PHPCfg\Printer;
1313

1414
use PHPCfg\Func;
15-
use PHPCfg\Printer;
15+
use PHPCfg\Printer\Printer;
1616
use PHPCfg\Script;
1717
use phpDocumentor\GraphViz\Edge;
1818
use phpDocumentor\GraphViz\Graph;
@@ -46,7 +46,7 @@ public function printScript(Script $script): string
4646
$this->printFuncWithHeader($func, $graph, 'func_' . ++$i . '_');
4747
}
4848

49-
return (string) $graph;
49+
return (string) $graph . "\n";
5050
}
5151

5252
public function printFunc(Func $func): string
@@ -57,50 +57,6 @@ public function printFunc(Func $func): string
5757
return (string) $graph;
5858
}
5959

60-
public function printVars(Func $func): string
61-
{
62-
$graph = Graph::create('vars');
63-
foreach ($this->options['graph'] as $name => $value) {
64-
$setter = 'set' . $name;
65-
$graph->{$setter}($value);
66-
}
67-
$rendered = $this->render($func->cfg);
68-
$nodes = new SplObjectStorage();
69-
foreach ($rendered['varIds'] as $var) {
70-
if (empty($var->ops) && empty($var->usages)) {
71-
continue;
72-
}
73-
$id = $rendered['varIds'][$var];
74-
$output = $this->renderOperand($var);
75-
$nodes[$var] = $this->createNode('var_' . $id, $output);
76-
$graph->setNode($nodes[$var]);
77-
}
78-
foreach ($rendered['varIds'] as $var) {
79-
foreach ($var->ops as $write) {
80-
$b = $write->getAttribute('block');
81-
foreach ($write->getVariableNames() as $varName => $vs) {
82-
if (! is_array($vs)) {
83-
$vs = [$vs];
84-
}
85-
foreach ($vs as $v) {
86-
if (! $v || $write->isWriteVariable($varName) || ! $nodes->contains($v)) {
87-
continue;
88-
}
89-
$edge = $this->createEdge($nodes[$v], $nodes[$var]);
90-
if ($b) {
91-
$edge->setlabel('Block<' . $rendered['blockIds'][$b] . '>' . $write->getType() . ':' . $varName);
92-
} else {
93-
$edge->setlabel($write->getType() . ':' . $varName);
94-
}
95-
$graph->link($edge);
96-
}
97-
}
98-
}
99-
}
100-
101-
return (string) $graph;
102-
}
103-
10460
protected function printFuncWithHeader(Func $func, Graph $graph, $prefix): void
10561
{
10662
$name = $func->getScopedName();

0 commit comments

Comments
 (0)