From 515ba686aba3374ff52dc447209723d0277f2e4a Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Sun, 31 Aug 2025 09:27:49 -0400 Subject: [PATCH 1/5] some initial work, very broken --- lib/PHPCfg/{ => Printer}/Printer.php | 100 +++++++++++------- lib/PHPCfg/Printer/Renderer.php | 28 +++++ .../Printer/Renderer/Operand/Literal.php | 52 +++++++++ .../Printer/Renderer/Operand/Temporary.php | 69 ++++++++++++ .../Printer/Renderer/Operand/Variable.php | 78 ++++++++++++++ lib/PHPCfg/Printer/Text.php | 1 - 6 files changed, 289 insertions(+), 39 deletions(-) rename lib/PHPCfg/{ => Printer}/Printer.php (87%) create mode 100644 lib/PHPCfg/Printer/Renderer.php create mode 100644 lib/PHPCfg/Printer/Renderer/Operand/Literal.php create mode 100644 lib/PHPCfg/Printer/Renderer/Operand/Temporary.php create mode 100644 lib/PHPCfg/Printer/Renderer/Operand/Variable.php diff --git a/lib/PHPCfg/Printer.php b/lib/PHPCfg/Printer/Printer.php similarity index 87% rename from lib/PHPCfg/Printer.php rename to lib/PHPCfg/Printer/Printer.php index 53572fa..7fb3754 100755 --- a/lib/PHPCfg/Printer.php +++ b/lib/PHPCfg/Printer/Printer.php @@ -9,7 +9,7 @@ * @license MIT See LICENSE at the root of the project for more info */ -namespace PHPCfg; +namespace PHPCfg\Printer; use LogicException; use PHPCfg\Operand\BoundVariable; @@ -19,6 +19,14 @@ use PHPCfg\Operand\Variable; use SplObjectStorage; use SplQueue; +use PHPCfg\Script; +use PHPCfg\Block; +use PHPCfg\Func; +use PHPCfg\Op; +use PHPCfg\Operand; +use PHPCfg\Assertion; +use RecursiveIteratorIterator; +use RecursiveDirectoryIterator; abstract class Printer { @@ -30,10 +38,49 @@ abstract class Printer private bool $renderAttributes; + protected array $renderers = []; + public function __construct(bool $renderAttributes = false) { $this->renderAttributes = $renderAttributes; + $this->loadRenderers(); $this->reset(); + + } + + public function addRenderer(Renderer $renderer, bool $prepend = false): void + { + if ($prepend) { + array_unshift($this->renderers, $renderer); + } else { + $this->renderers[] = $renderer; + } + } + + protected function loadRenderers(): void + { + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + __DIR__ . '/Renderer/', + RecursiveIteratorIterator::LEAVES_ONLY + ) + ); + $handlers = []; + foreach ($it as $file) { + if (!$file->isFile() || $file->getExtension() !== 'php') { + continue; + } + $class = str_replace(__DIR__, '', $file->getPathname()); + $class = __NAMESPACE__ . str_replace("/", "\\", $class); + $class = substr($class, 0, -4); + + if (!class_exists($class)) { + continue; + } + + $obj = new $class($this); + $this->addRenderer($obj); + } } abstract public function printScript(Script $script): string; @@ -42,9 +89,11 @@ abstract public function printFunc(Func $func): string; protected function reset(): void { - $this->varIds = new SplObjectStorage(); $this->blocks = new SplObjectStorage(); $this->blockQueue = new SplQueue(); + foreach ($this->renderers as $renderer) { + $renderer->reset(); + } } protected function getBlockId(Block $block): int @@ -52,36 +101,18 @@ protected function getBlockId(Block $block): int return $this->blocks[$block]; } - protected function renderOperand(Operand $var): string + public function renderOperand(Operand $var): string { - $type = isset($var->type) ? 'type->toString() . '>' : ''; - if ($var instanceof Literal) { - return "LITERAL{$type}(" . var_export($var->value, true) . ')'; - } - if ($var instanceof Variable) { - assert($var->name instanceof Literal); - $prefix = "{$type}$"; - - if ($var instanceof BoundVariable) { - if ($var->byRef) { - $prefix = '&$'; - } - switch ($var->scope) { - case BoundVariable::SCOPE_GLOBAL: - return "global<{$prefix}{$var->name->value}>"; - case BoundVariable::SCOPE_LOCAL: - return "local<{$prefix}{$var->name->value}>"; - case BoundVariable::SCOPE_OBJECT: - return "this<{$prefix}{$var->name->value}>"; - case BoundVariable::SCOPE_FUNCTION: - return "static<{$prefix}{$var->name->value}>"; - default: - throw new LogicException('Unknown bound variable scope'); - } + foreach ($this->renderers as $renderer) { + $result = $renderer->renderOperand($var); + if ($result !== null) { + $kind = $result['kind']; + $type = $result['type']; + unset($result['kind'], $result['type']); + return strtoupper($kind) . $type . '(' . trim(implode(" ", $result)) . ')'; } - - return $prefix . $var->name->value . $type; } + $type = isset($var->type) ? 'type->toString() . '>' : ''; if ($var instanceof Temporary) { $id = $this->getVarId($var); if ($var->original) { @@ -257,14 +288,7 @@ protected function enqueueBlock(Block $block): void } } - protected function getVarId(Operand $var) - { - if (isset($this->varIds[$var])) { - return $this->varIds[$var]; - } - return $this->varIds[$var] = $this->varIds->count() + 1; - } protected function render(Func $func) { @@ -293,14 +317,14 @@ protected function render(Func $func) $renderedBlocks[$block] = $ops; } - $varIds = $this->varIds; + //$varIds = $this->varIds; $blockIds = $this->blocks; $this->reset(); return [ 'blocks' => $renderedBlocks, 'ops' => $renderedOps, - 'varIds' => $varIds, + //'varIds' => $varIds, 'blockIds' => $blockIds, ]; } diff --git a/lib/PHPCfg/Printer/Renderer.php b/lib/PHPCfg/Printer/Renderer.php new file mode 100644 index 0000000..20d9377 --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer.php @@ -0,0 +1,28 @@ +printer = $printer; + } + + public function reset(): void {} + + public function renderOp(Op $op): ?array + { + return null; + } + + public function renderOperand(Operand $operand): ?array + { + if (!$operand instanceof Operand\Literal) { + return null; + } + + return [ + "kind" => "LITERAL", + "type" => $operand->type ? "<{$operand->type}>" : "", + "value" => var_export($operand->value, true) + ]; + } + +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php b/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php new file mode 100644 index 0000000..9baa86a --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php @@ -0,0 +1,69 @@ +printer = $printer; + $this->reset(); + } + + public function reset(): void + { + $this->varIds = new SplObjectStorage; + } + + public function renderOp(Op $op): ?array + { + return null; + } + + public function renderOperand(Operand $operand): ?array + { + if (!$operand instanceof Operand\Temporary) { + return null; + } + var_dump($operand); + return [ + "kind" => "TEMP", + "type" => $operand->type ? "<{$operand->type}>" : "", + "id" => "#" . $this->getVarId($operand), + "original" => $operand->original ? "<" . $this->printer->renderOperand($operand->original) . ">" : "", + ]; + } + + protected function getVarId(Operand $var) + { + if (isset($this->varIds[$var])) { + return $this->varIds[$var]; + } + + return $this->varIds[$var] = $this->varIds->count() + 1; + } + +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Variable.php b/lib/PHPCfg/Printer/Renderer/Operand/Variable.php new file mode 100644 index 0000000..6165ddb --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer/Operand/Variable.php @@ -0,0 +1,78 @@ +printer = $printer; + } + + public function reset(): void + {} + + public function renderOp(Op $op): ?array + { + return null; + } + + public function renderOperand(Operand $operand): ?array + { + if (!$operand instanceof Operand\Variable) { + return null; + } + + assert($operand->name instanceof Operand\Literal); + $prefix = "$"; + + if ($operand instanceof Operand\BoundVariable) { + if ($operand->byRef) { + $prefix = '&$'; + } + switch ($operand->scope) { + case Operand\BoundVariable::SCOPE_GLOBAL: + $prefix = "global $prefix"; + break; + case Operand\BoundVariable::SCOPE_LOCAL: + $prefix = "local $prefix"; + break; + case Operand\BoundVariable::SCOPE_OBJECT: + $prefix = "this $prefix"; + break; + case Operand\BoundVariable::SCOPE_FUNCTION: + $prefix = "static $prefix"; + break; + default: + throw new \LogicException('Unknown bound variable scope'); + } + } + + return [ + "kind" => "VARIABLE", + "type" => $operand->type ? "<{$operand->type}>" : "", + "name" => $prefix . $operand->name->value, + ]; + } + +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Text.php b/lib/PHPCfg/Printer/Text.php index 533616e..2e74773 100755 --- a/lib/PHPCfg/Printer/Text.php +++ b/lib/PHPCfg/Printer/Text.php @@ -12,7 +12,6 @@ namespace PHPCfg\Printer; use PHPCfg\Func; -use PHPCfg\Printer; use PHPCfg\Script; class Text extends Printer From 30735dda6506c2ca8b20ae42e2e024500c68b169 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Sun, 31 Aug 2025 15:46:09 -0400 Subject: [PATCH 2/5] More refactoring --- lib/PHPCfg/Printer/Printer.php | 21 ------------------- .../Printer/Renderer/Operand/Literal.php | 6 ++++++ .../Printer/Renderer/Operand/Temporary.php | 1 - 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/PHPCfg/Printer/Printer.php b/lib/PHPCfg/Printer/Printer.php index 7fb3754..1484c29 100755 --- a/lib/PHPCfg/Printer/Printer.php +++ b/lib/PHPCfg/Printer/Printer.php @@ -112,27 +112,6 @@ public function renderOperand(Operand $var): string return strtoupper($kind) . $type . '(' . trim(implode(" ", $result)) . ')'; } } - $type = isset($var->type) ? 'type->toString() . '>' : ''; - if ($var instanceof Temporary) { - $id = $this->getVarId($var); - if ($var->original) { - return "Var{$type}#{$id}" . '<' . $this->renderOperand($var->original) . '>'; - } - - return "Var{$type}#" . $this->getVarId($var); - } - if ($var instanceof NullOperand) { - return "NULL"; - } - if (is_array($var)) { - $result = 'array' . $type; - foreach ($var as $k => $v) { - $result .= "\n {$k}: " . $this->indent($this->renderOperand($v)); - } - - return $result; - } - return 'UNKNOWN'; } diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Literal.php b/lib/PHPCfg/Printer/Renderer/Operand/Literal.php index 7590926..2cd9bd8 100644 --- a/lib/PHPCfg/Printer/Renderer/Operand/Literal.php +++ b/lib/PHPCfg/Printer/Renderer/Operand/Literal.php @@ -38,6 +38,12 @@ public function renderOp(Op $op): ?array public function renderOperand(Operand $operand): ?array { + if ($operand instanceof Operand\NullOperand) { + // Special case of a literal + return [ + "kind" => "NULL", + ]; + } if (!$operand instanceof Operand\Literal) { return null; } diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php b/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php index 9baa86a..3fef731 100644 --- a/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php +++ b/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php @@ -48,7 +48,6 @@ public function renderOperand(Operand $operand): ?array if (!$operand instanceof Operand\Temporary) { return null; } - var_dump($operand); return [ "kind" => "TEMP", "type" => $operand->type ? "<{$operand->type}>" : "", From 55c0db495b43f8e545ddce55f24b878b7bd25f0e Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Mon, 1 Sep 2025 08:45:01 -0400 Subject: [PATCH 3/5] Fix text printer and tests --- lib/PHPCfg/Printer/Printer.php | 242 +++--------------- lib/PHPCfg/Printer/Renderer/GenericOp.php | 186 ++++++++++++++ lib/PHPCfg/Printer/Renderer/Op/Assertion.php | 55 ++++ lib/PHPCfg/Printer/Renderer/Op/Include_.php | 53 ++++ lib/PHPCfg/Printer/Renderer/Op/TraitUse.php | 76 ++++++ .../Printer/Renderer/Operand/Literal.php | 1 + src/Cli/PrintCommand.php | 2 +- test/ParserAttributesTest.php | 31 ++- test/code/and.test | 18 +- test/code/anonymous_class.test | 21 +- test/code/arrayList.test | 34 +-- test/code/arrow_fn.test | 43 ++-- test/code/assign_coalesce.test | 14 +- test/code/block.test | 4 +- test/code/cast.test | 8 +- test/code/class.test | 29 ++- test/code/classMethod_empty.test | 3 +- test/code/class_attributes.test | 39 +-- test/code/class_this.test | 9 +- test/code/class_typed_property.test | 10 +- test/code/closure.test | 51 ++-- test/code/closure_empty.test | 13 +- test/code/constDecl.test | 18 +- test/code/constFetch.test | 12 +- test/code/empty.test | 20 +- test/code/error_supress.test | 8 +- test/code/exit.test | 4 +- test/code/exit_message.test | 10 +- test/code/exprFuncCall.test | 8 +- test/code/foreach.test | 28 +- test/code/function.test | 7 +- test/code/function_attributes.test | 19 +- test/code/function_empty.test | 5 +- test/code/function_namespace.test | 7 +- test/code/function_return_type.test | 7 +- test/code/if_else.test | 2 +- test/code/if_else_if_else.test | 4 +- test/code/if_elseif_else.test | 4 +- test/code/include.test | 16 +- test/code/interface.test | 3 +- test/code/intersection_type.test | 5 +- test/code/isset.test | 10 +- test/code/labels.test | 3 +- test/code/list.test | 76 +++--- test/code/listKeys.test | 26 +- test/code/literal.test | 16 +- test/code/match.test | 14 +- test/code/match2.test | 30 +-- test/code/nested_phi.test | 52 ++-- test/code/nop.test | 6 +- test/code/nsFuncCall.test | 2 +- test/code/or.test | 18 +- test/code/property.test | 28 +- test/code/shellExec.test | 8 +- test/code/static.test | 8 +- test/code/switch.test | 2 +- test/code/switch2.test | 32 +-- test/code/ternary.test | 22 +- test/code/ternary2.test | 38 +-- test/code/throw.test | 12 +- test/code/traitUse.test | 36 +-- test/code/traitUse2.test | 13 +- test/code/try.test | 20 +- test/code/try_bodyblocks.test | 34 +-- test/code/try_bodyblocks2.test | 34 +-- test/code/try_finally.test | 10 +- test/code/try_nested.test | 24 +- test/code/type_assert.test | 56 ++-- test/code/unary.test | 24 +- test/code/unionType.test | 5 +- test/code/variablevariable.test | 112 ++++---- test/code/while.test | 4 +- test/code/yeild_from.test | 42 +-- test/code/yield.test | 61 ++--- 74 files changed, 1122 insertions(+), 885 deletions(-) create mode 100644 lib/PHPCfg/Printer/Renderer/GenericOp.php create mode 100644 lib/PHPCfg/Printer/Renderer/Op/Assertion.php create mode 100644 lib/PHPCfg/Printer/Renderer/Op/Include_.php create mode 100644 lib/PHPCfg/Printer/Renderer/Op/TraitUse.php diff --git a/lib/PHPCfg/Printer/Printer.php b/lib/PHPCfg/Printer/Printer.php index 1484c29..8e09220 100755 --- a/lib/PHPCfg/Printer/Printer.php +++ b/lib/PHPCfg/Printer/Printer.php @@ -30,19 +30,22 @@ abstract class Printer { - private SplObjectStorage $varIds; + const MODE_DEFAULT = 0b00000; + const MODE_RENDER_ATTRIBUTES = 0b00001; private SplQueue $blockQueue; private SplObjectStorage $blocks; - private bool $renderAttributes; + public bool $renderAttributes = false; protected array $renderers = []; - public function __construct(bool $renderAttributes = false) + public function __construct(int $mode = self::MODE_DEFAULT) { - $this->renderAttributes = $renderAttributes; + if ($mode & self::MODE_RENDER_ATTRIBUTES) { + $this->renderAttributes = true; + } $this->loadRenderers(); $this->reset(); @@ -115,141 +118,28 @@ public function renderOperand(Operand $var): string return 'UNKNOWN'; } - protected function renderOp(Op $op): array + public function renderOp(Op $op): array { - $result = $op->getType(); - - if ($op instanceof Op\CallableOp) { - $func = $op->getFunc(); - $result .= "<'" . $func->name . "'>"; - } - - if ($op instanceof Op\Expr\Assertion) { - $result .= '<' . $this->renderAssertion($op->assertion) . '>'; - } - - $result .= $this->renderAttributes($op->getAttributes()); - - if ($op instanceof Op\AttributableOp) { - $result .= $this->renderAttrGroups($op); - } - - if ($op instanceof Op\Stmt\Property || $op instanceof Op\Stmt\ClassMethod) { - $result .= "\n flags: " . $this->indent($this->renderFlags($op)); - } - - if ($op instanceof Op\Stmt\TraitUse) { - foreach ($op->traits as $index => $trait_) { - $result .= "\n use[$index]: " . $this->indent($this->renderOperand($trait_)); - } - foreach ($op->adaptations as $index => $adaptation) { - if ($adaptation instanceof Op\TraitUseAdaptation\Alias) { - $result .= "\n adaptation[$index]: Alias"; - if ($adaptation->trait != null) { - $result .= "\n trait:" . $this->indent($this->renderOperand($adaptation->trait)); - } - $result .= "\n method:" . $this->indent($this->renderOperand($adaptation->method)); - if ($adaptation->newName != null) { - $result .= "\n newName:" . $this->indent($this->renderOperand($adaptation->newName)); - } - if ($adaptation->newModifier != null) { - $result .= "\n newModifier:"; - if ($adaptation->isPublic()) { - $result .= "public"; - } - if ($adaptation->isPrivate()) { - $result .= "private"; - } - if ($adaptation->isProtected()) { - $result .= "protected"; - } - } - } elseif ($adaptation instanceof Op\TraitUseAdaptation\Precedence) { - $result .= "\n adaptation[$index]: Insteadof"; - if ($adaptation->trait != null) { - $result .= "\n trait:" . $this->indent($this->renderOperand($adaptation->trait)); - } - $result .= "\n method:" . $this->indent($this->renderOperand($adaptation->method)); - foreach ($adaptation->insteadof as $index2 => $insteadof) { - $result .= "\n insteadof[$index2]: " . $this->indent($this->renderOperand($insteadof)); - } - } - } - } elseif ($op instanceof Op\Expr\Include_) { - $result .= "\n type: " . $this->indent($this->renderIncludeType($op->type)); - } - - foreach ($op->getTypeNames() as $typeName => $type) { - if (is_array($type)) { - foreach ($type as $key => $subType) { - if (! $subType) { - continue; - } - $result .= "\n {$typeName}[{$key}]: "; - $result .= $this->indent($this->renderType($subType)); - } - } elseif ($type) { - $result .= "\n {$typeName}: "; - $result .= $this->indent($this->renderType($type)); - } - } - - foreach ($op->getVariableNames() as $varName => $vars) { - if (is_array($vars)) { - foreach ($vars as $key => $var) { - if (! $var) { - continue; - } - $result .= "\n {$varName}[{$key}]: "; - $result .= $this->indent($this->renderOperand($var)); - } - } elseif ($vars) { - $result .= "\n {$varName}: "; - $result .= $this->indent($this->renderOperand($vars)); - } - } - - $childBlocks = []; - foreach ($op->getSubBlocks() as $blockName => $sub) { - if (is_array($sub)) { - foreach ($sub as $key => $subBlock) { - if (! $subBlock) { - continue; - } - $this->enqueueBlock($subBlock); - $childBlocks[] = [ - 'block' => $subBlock, - 'name' => $blockName . '[' . $key . ']', - ]; - } - } elseif ($sub) { - $this->enqueueBlock($sub); - $childBlocks[] = ['block' => $sub, 'name' => $blockName]; + foreach ($this->renderers as $renderer) { + $result = $renderer->renderOp($op); + if ($result !== null) { + $kind = $result['kind']; + $childblocks = $result['childblocks']; + return [ + 'op' => $op, + 'label' => $this->renderOpLabel($result), + 'childBlocks' => $childblocks, + ]; } } return [ 'op' => $op, - 'label' => $result, + 'label' => 'UNKNOWN', 'childBlocks' => $childBlocks, ]; } - protected function renderAssertion(Assertion $assert): string - { - $kind = $assert->getKind(); - if ($assert->value instanceof Operand) { - return $kind . '(' . $this->renderOperand($assert->value) . ')'; - } - $combinator = $assert->mode === Assertion::MODE_UNION ? '|' : '&'; - $results = []; - foreach ($assert->value as $child) { - $results[] = $this->renderAssertion($child); - } - - return $kind . '(' . implode($combinator, $results) . ')'; - } - protected function indent($str, $levels = 1): string { if ($levels > 1) { @@ -259,7 +149,7 @@ protected function indent($str, $levels = 1): string return str_replace("\n", "\n ", $str); } - protected function enqueueBlock(Block $block): void + public function enqueueBlock(Block $block): void { if (! $this->blocks->contains($block)) { $this->blocks[$block] = count($this->blocks) + 1; @@ -267,8 +157,6 @@ protected function enqueueBlock(Block $block): void } } - - protected function render(Func $func) { if (null !== $func->cfg) { @@ -308,7 +196,7 @@ protected function render(Func $func) ]; } - protected function renderType(?Op\Type $type): string + public function renderType(?Op\Type $type): string { if ($type instanceof Op\Type\Mixed_) { return 'mixed'; @@ -341,85 +229,23 @@ protected function renderType(?Op\Type $type): string throw new LogicException("Unknown type rendering: " . get_class($type)); } - protected function renderIncludeType(int $type): string + public function renderOpLabel(array $desc): string { - switch ($type) { - case 1: - return "include"; - case 2: - return "include_once"; - case 3: - return "require"; - case 4: - return "require_once"; - default: - throw new LogicException("Unknown include type rendering: " . $type); - } - } - - protected function renderFlags(Op\Stmt $stmt): string - { - $result = ''; - - if ($stmt instanceof Op\Stmt\Property) { - if ($stmt->isReadOnly()) { - $result .= "readonly|"; - } - } elseif ($stmt instanceof Op\Stmt\ClassMethod) { - if ($stmt->isFinal()) { - $result .= "final|"; - } - if ($stmt->isAbstract()) { - $result .= "abstract|"; - } - } - - if ($stmt->isStatic()) { - $result .= "static|"; - } - - if ($stmt->isProtected()) { - $result .= "protected"; - } elseif ($stmt->isPrivate()) { - $result .= "private"; - } else { - $result .= "public"; - } - - return $result; - } - - public function renderAttributes(array $attributes): string - { - $result = ''; - if ($this->renderAttributes) { - foreach ($attributes as $key => $value) { - if (is_string($value) || is_numeric($value)) { - $result .= "\n attribute['" . $key . "']: " . $value; - } - } - } - - return $result; - } - - public function renderAttrGroups(Op\AttributableOp $op): string - { - $result = ''; - - foreach ($op->getAttributeGroups() as $indexGroup => $attrGroup) { - $result .= "\n attrGroup[$indexGroup]: "; - $result .= $this->indent($this->renderAttributes($attrGroup->getAttributes())); - foreach ($attrGroup->attrs as $indexAttr => $attr) { - $result .= "\n attr[$indexAttr]: "; - $result .= $this->indent($this->renderAttributes($attr->getAttributes()), 2); - $result .= "\n name: " . $this->renderOperand($attr->name); - foreach ($attr->args as $indexArg => $arg) { - $result .= "\n args[$indexArg]: " . $this->renderOperand($arg); + $result = "{$desc['kind']}"; + unset($desc['kind'], $desc['childblocks']); + foreach ($desc as $name => $val) { + if (is_array($val)) { + foreach ($val as $v) { + if (is_array($v)) { + $result .= $this->indent("\n" . implode("\n", $v)); + } else { + $result .= $this->indent("\n{$v}"); + } } + } else { + $result .= $this->indent("\n{$val}"); } } - return $result; } } diff --git a/lib/PHPCfg/Printer/Renderer/GenericOp.php b/lib/PHPCfg/Printer/Renderer/GenericOp.php new file mode 100644 index 0000000..e626af1 --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer/GenericOp.php @@ -0,0 +1,186 @@ +printer = $printer; + } + + public function reset(): void {} + + public function renderOp(Op $op): ?array + { + $result = [ + 'kind' => $op->getType(), + 'types' => [], + 'vars' => [], + 'attributes' => $this->renderAttributes($op->getAttributes()), + 'childblocks' => [], + ]; + + if ($op instanceof Op\CallableOp) { + $func = $op->getFunc(); + $result['vars'][] = "name: {$func->name}"; + } + + if ($op instanceof Op\Stmt\Property || $op instanceof Op\Stmt\ClassMethod) { + $result['vars'][] = "flags: " . $this->renderFlags($op); + } + + + foreach ($op->getTypeNames() as $typeName => $type) { + if (is_array($type)) { + foreach ($type as $key => $subType) { + if (! $subType) { + continue; + } + $result['types'][] = "{$typeName}[{$key}]: " . $this->printer->renderType($subType); + } + } elseif ($type) { + $result['types'][] = "{$typeName}: " . $this->printer->renderType($type); + } + } + + foreach ($op->getVariableNames() as $varName => $vars) { + if (is_array($vars)) { + foreach ($vars as $key => $var) { + if (! $var) { + continue; + } + $result['vars'][] = "{$varName}[{$key}]: " . $this->printer->renderOperand($var); + } + } elseif ($vars) { + $result['vars'][] = "{$varName}: " . $this->printer->renderOperand($vars); + } + } + + foreach ($op->getSubBlocks() as $blockName => $sub) { + if (is_array($sub)) { + foreach ($sub as $key => $subBlock) { + if (! $subBlock) { + continue; + } + $this->printer->enqueueBlock($subBlock); + $result['childblocks'][] = [ + 'block' => $subBlock, + 'name' => $blockName . '[' . $key . ']', + ]; + } + } elseif ($sub) { + $this->printer->enqueueBlock($sub); + $result['childblocks'][] = ['block' => $sub, 'name' => $blockName]; + } + } + + if ($op instanceof Op\AttributableOp) { + $result['attrGroups'] = $this->renderAttrGroups($op); + } + + + + return $result; + } + + public function renderOperand(Operand $operand): ?array + { + return null; + } + + + + protected function renderAttributes(array $attributes): array + { + if (!$this->printer->renderAttributes) { + return []; + } + $result = []; + foreach ($attributes as $key => $value) { + if (is_string($value) || is_numeric($value)) { + $result[] = "attribute['" . $key . "']: " . $value; + } + } + return $result; + } + + + protected function renderAttrGroups(Op\AttributableOp $op): array + { + $result = []; + foreach ($op->getAttributeGroups() as $indexGroup => $attrGroup) { + $result[$indexGroup] = []; + $result[$indexGroup][] = "attrGroup[$indexGroup]: "; + foreach ($this->renderAttributes($attrGroup->getAttributes()) as $attr) { + $result[$indexGroup][] = " {$attr}"; + } + foreach ($attrGroup->attrs as $indexAttr => $attr) { + $result[$indexGroup][] = " attr[$indexAttr]: "; + foreach ($this->renderAttributes($attr->getAttributes()) as $rendered) { + $result[$indexGroup][] = " {$rendered}"; + } + $result[$indexGroup][] = " name: " . $this->printer->renderOperand($attr->name); + foreach ($attr->args as $indexArg => $arg) { + $result[$indexGroup][] = " args[$indexArg]: " . $this->printer->renderOperand($arg); + } + } + } + + return $result; + } + + + protected function renderFlags(Op\Stmt $stmt): string + { + $result = ''; + + if ($stmt instanceof Op\Stmt\Property) { + if ($stmt->isReadOnly()) { + $result .= "readonly|"; + } + } elseif ($stmt instanceof Op\Stmt\ClassMethod) { + if ($stmt->isFinal()) { + $result .= "final|"; + } + if ($stmt->isAbstract()) { + $result .= "abstract|"; + } + } + + if ($stmt->isStatic()) { + $result .= "static|"; + } + + if ($stmt->isProtected()) { + $result .= "protected"; + } elseif ($stmt->isPrivate()) { + $result .= "private"; + } else { + $result .= "public"; + } + + return $result; + } + +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Renderer/Op/Assertion.php b/lib/PHPCfg/Printer/Renderer/Op/Assertion.php new file mode 100644 index 0000000..b11b5c8 --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer/Op/Assertion.php @@ -0,0 +1,55 @@ +renderAssertion($op->assertion); + return $result; + } + + protected function renderAssertion(CoreAssertion $assert): string + { + + if (is_array($assert->value)) { + $combinator = $assert->mode === CoreAssertion::MODE_UNION ? '|' : '&'; + + $ret = implode($combinator, array_map([$this, 'renderAssertion'], $assert->value)); + } else { + $ret = $this->printer->renderOperand($assert->value); + } + $kind = $assert->getKind(); + if ($kind === 'type' || empty($kind)) { + return $ret; + } + return "$kind({$ret})"; + + } +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Renderer/Op/Include_.php b/lib/PHPCfg/Printer/Renderer/Op/Include_.php new file mode 100644 index 0000000..6f85863 --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer/Op/Include_.php @@ -0,0 +1,53 @@ +type) { + case 1: + $result['vars'][] = "type: include"; + break; + case 2: + $result['vars'][] = "type: include_once"; + break; + case 3: + $result['vars'][] = "type: require"; + break; + case 4: + $result['vars'][] = "type: require_once"; + break; + default: + throw new LogicException("Unknown include type rendering: " . $type); + } + return $result; + } + +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php b/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php new file mode 100644 index 0000000..9fcf61b --- /dev/null +++ b/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php @@ -0,0 +1,76 @@ +traits as $index => $trait_) { + $result['vars'][] = "use[$index]: " . $this->printer->renderOperand($trait_); + } + foreach ($op->adaptations as $index => $adaptation) { + $adapt = []; + if ($adaptation instanceof Op\TraitUseAdaptation\Alias) { + $adapt[] = "adaptation[$index]: Alias"; + if ($adaptation->trait != null) { + $adapt[] = " trait: " . $this->printer->renderOperand($adaptation->trait); + } + $adapt[] = " method: " . $this->printer->renderOperand($adaptation->method); + if ($adaptation->newName != null) { + $adapt[] = " newName: " . $this->printer->renderOperand($adaptation->newName); + } + if ($adaptation->newModifier != null) { + $mod = " newModifier: "; + if ($adaptation->isPublic()) { + $mod .= "public"; + } + if ($adaptation->isPrivate()) { + $mod .= "private"; + } + if ($adaptation->isProtected()) { + $mod .= "protected"; + } + $adapt[] = $mod; + } + } elseif ($adaptation instanceof Op\TraitUseAdaptation\Precedence) { + $adapt[] = "adaptation[$index]: Insteadof"; + if ($adaptation->trait != null) { + $adapt[] = " trait: " . $this->printer->renderOperand($adaptation->trait); + } + $adapt[] = " method: " . $this->printer->renderOperand($adaptation->method); + foreach ($adaptation->insteadof as $index2 => $insteadof) { + $adapt[] = " insteadof[$index2]: " . $this->printer->renderOperand($insteadof); + } + } + $result['vars'] = array_merge($result['vars'], $adapt); + } + return $result; + } + +} \ No newline at end of file diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Literal.php b/lib/PHPCfg/Printer/Renderer/Operand/Literal.php index 2cd9bd8..6471e71 100644 --- a/lib/PHPCfg/Printer/Renderer/Operand/Literal.php +++ b/lib/PHPCfg/Printer/Renderer/Operand/Literal.php @@ -42,6 +42,7 @@ public function renderOperand(Operand $operand): ?array // Special case of a literal return [ "kind" => "NULL", + "type" => "", ]; } if (!$operand instanceof Operand\Literal) { diff --git a/src/Cli/PrintCommand.php b/src/Cli/PrintCommand.php index 34be8a9..1579360 100644 --- a/src/Cli/PrintCommand.php +++ b/src/Cli/PrintCommand.php @@ -40,7 +40,7 @@ public function execute($file, $optimize, $attributes) $script = $this->exec($file, $code, $optimize); - $dumper = new Printer\Text($attributes); + $dumper = new Printer\Text($attributes ? Printer\Printer::MODE_RENDER_ATTRIBUTES : Printer\Printer::MODE_DEFAULT); $io->write($dumper->printScript($script), true); } } diff --git a/test/ParserAttributesTest.php b/test/ParserAttributesTest.php index dc95c98..0eb27f2 100755 --- a/test/ParserAttributesTest.php +++ b/test/ParserAttributesTest.php @@ -30,7 +30,8 @@ function foo(\$a) { $expected = <<< EOF Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo Terminal_Return Function 'foo': mixed @@ -38,9 +39,9 @@ function foo(\$a) { Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<\$a> + result: TEMP(#1 ) Terminal_Return - expr: Var#1<\$a> + expr: TEMP(#1 ) EOF; $parser = new Parser((new ParserFactory())->createForNewestSupportedVersion(), null); @@ -75,7 +76,8 @@ function foowithattribute(\$a) { $expected = <<<'EOF' Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo attribute['filename']: foo.php attribute['startLine']: 2 attribute['startTokenPos']: 1 @@ -83,7 +85,8 @@ function foowithattribute(\$a) { attribute['endLine']: 4 attribute['endTokenPos']: 15 attribute['endFilePos']: 40 - Stmt_Function<'foowithattribute'> + Stmt_Function + name: foowithattribute attribute['filename']: foo.php attribute['startLine']: 6 attribute['startTokenPos']: 17 @@ -113,6 +116,9 @@ function foowithattribute(\$a) { Function 'foo': mixed Block#1 Expr_Param + declaredType: mixed + name: LITERAL('a') + result: TEMP(#1 ) attribute['filename']: foo.php attribute['startLine']: 2 attribute['startTokenPos']: 5 @@ -120,10 +126,8 @@ function foowithattribute(\$a) { attribute['endLine']: 2 attribute['endTokenPos']: 5 attribute['endFilePos']: 20 - declaredType: mixed - name: LITERAL('a') - result: Var#1<$a> Terminal_Return + expr: TEMP(#1 ) attribute['filename']: foo.php attribute['startLine']: 3 attribute['startTokenPos']: 10 @@ -131,11 +135,13 @@ function foowithattribute(\$a) { attribute['endLine']: 3 attribute['endTokenPos']: 13 attribute['endFilePos']: 38 - expr: Var#1<$a> Function 'foowithattribute': mixed Block#1 Expr_Param + declaredType: mixed + name: LITERAL('a') + result: TEMP(#1 ) attribute['filename']: foo.php attribute['startLine']: 7 attribute['startTokenPos']: 25 @@ -143,10 +149,8 @@ function foowithattribute(\$a) { attribute['endLine']: 7 attribute['endTokenPos']: 25 attribute['endFilePos']: 78 - declaredType: mixed - name: LITERAL('a') - result: Var#1<$a> Terminal_Return + expr: TEMP(#1 ) attribute['filename']: foo.php attribute['startLine']: 8 attribute['startTokenPos']: 30 @@ -154,13 +158,12 @@ function foowithattribute(\$a) { attribute['endLine']: 8 attribute['endTokenPos']: 33 attribute['endFilePos']: 96 - expr: Var#1<$a> EOF; $parser = new Parser((new ParserFactory())->createForNewestSupportedVersion(), null); $traverser = new Traverser(); $traverser->addVisitor(new Visitor\Simplifier()); - $printer = new Printer\Text(true); + $printer = new Printer\Text(Printer\Printer::MODE_RENDER_ATTRIBUTES); try { $script = $parser->parse($code, 'foo.php'); diff --git a/test/code/and.test b/test/code/and.test index 5558039..9f8877d 100755 --- a/test/code/and.test +++ b/test/code/and.test @@ -5,9 +5,9 @@ $x = a() && b(); Block#1 Expr_FuncCall name: LITERAL('a') - result: Var#1 + result: TEMP(#1) Stmt_JumpIf - cond: Var#1 + cond: TEMP(#1) if: Block#2 else: Block#3 @@ -15,19 +15,19 @@ Block#2 Parent: Block#1 Expr_FuncCall name: LITERAL('b') - result: Var#2 + result: TEMP(#2) Expr_Cast_Bool - expr: Var#2 - result: Var#3 + expr: TEMP(#2) + result: TEMP(#3) Stmt_Jump target: Block#3 Block#3 Parent: Block#2 Parent: Block#1 - Var#4 = Phi(LITERAL(false), Var#3) + TEMP(#4) = Phi(LITERAL(false), TEMP(#3)) Expr_Assign - var: Var#5<$x> - expr: Var#4 - result: Var#6 + var: TEMP(#5 ) + expr: TEMP(#4) + result: TEMP(#6) Terminal_Return \ No newline at end of file diff --git a/test/code/anonymous_class.test b/test/code/anonymous_class.test index ac6f39d..465fc6c 100644 --- a/test/code/anonymous_class.test +++ b/test/code/anonymous_class.test @@ -13,29 +13,30 @@ Block#1 stmts: Block#2 Expr_New class: LITERAL('{anonymousClass}#1') - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$var> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Stmt_Class + name: {anonymousClass}#2 attrGroup[0]: attr[0]: name: LITERAL('Attr') args[0]: LITERAL('foo') - name: {anonymousClass}#2 stmts: Block#3 Expr_New class: LITERAL('{anonymousClass}#2') - result: Var#4 + result: TEMP(#4) Expr_Assign - var: Var#5<$instance> - expr: Var#4 - result: Var#6 + var: TEMP(#5 ) + expr: TEMP(#4) + result: TEMP(#6) Terminal_Return Block#2 - Stmt_ClassMethod<'doSomething'> + Stmt_ClassMethod + name: doSomething flags: public Block#3 diff --git a/test/code/arrayList.test b/test/code/arrayList.test index 9e05e5f..33308d5 100755 --- a/test/code/arrayList.test +++ b/test/code/arrayList.test @@ -4,31 +4,31 @@ ----- Block#1 Expr_ArrayDimFetch - var: Var#1<$array> + var: TEMP(#1 ) dim: LITERAL(0) - result: Var#2 + result: TEMP(#2) Expr_Assign - var: Var#3<$a> - expr: Var#2 - result: Var#4 + var: TEMP(#3 ) + expr: TEMP(#2) + result: TEMP(#4) Expr_ArrayDimFetch - var: Var#1<$array> + var: TEMP(#1 ) dim: LITERAL(1) - result: Var#5 + result: TEMP(#5) Expr_Assign - var: Var#6<$b> - expr: Var#5 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#5) + result: TEMP(#7) Expr_ArrayDimFetch - var: Var#1<$array> + var: TEMP(#1 ) dim: LITERAL(2) - result: Var#8 + result: TEMP(#8) Expr_ArrayDimFetch - var: Var#8 + var: TEMP(#8) dim: LITERAL(0) - result: Var#9 + result: TEMP(#9) Expr_Assign - var: Var#10<$c> - expr: Var#9 - result: Var#11 + var: TEMP(#10 ) + expr: TEMP(#9) + result: TEMP(#11) Terminal_Return \ No newline at end of file diff --git a/test/code/arrow_fn.test b/test/code/arrow_fn.test index 98706d6..a9e2476 100644 --- a/test/code/arrow_fn.test +++ b/test/code/arrow_fn.test @@ -7,23 +7,24 @@ var_dump($b); ----- Block#1 Expr_Assign - var: Var#1<$b> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 - Expr_ArrowFunction<'{anonymous}#1'> - result: Var#3 + result: TEMP(#2) + Expr_ArrowFunction + name: {anonymous}#1 + result: TEMP(#3) Expr_Assign - var: Var#4<$fn> - expr: Var#3 - result: Var#5 + var: TEMP(#4 ) + expr: TEMP(#3) + result: TEMP(#5) Expr_FuncCall - name: Var#4<$fn> + name: TEMP(#4 ) args[0]: LITERAL(3) - result: Var#6 + result: TEMP(#6) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#1<$b> - result: Var#7 + args[0]: TEMP(#1 ) + result: TEMP(#7) Terminal_Return Function '{anonymous}#1': mixed @@ -31,18 +32,18 @@ Block#1 Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Expr_BinaryOp_Plus - left: Var#2<$b> + left: TEMP(#2 ) right: LITERAL(1) - result: Var#3 + result: TEMP(#3) Expr_Assign - var: Var#4<$b> - expr: Var#3 - result: Var#5 + var: TEMP(#4 ) + expr: TEMP(#3) + result: TEMP(#5) Expr_BinaryOp_Mul - left: Var#4<$b> - right: Var#1<$a> - result: Var#6 + left: TEMP(#4 ) + right: TEMP(#1 ) + result: TEMP(#6) Terminal_Return - expr: Var#6 \ No newline at end of file + expr: TEMP(#6) \ No newline at end of file diff --git a/test/code/assign_coalesce.test b/test/code/assign_coalesce.test index 27c995e..24d29d2 100644 --- a/test/code/assign_coalesce.test +++ b/test/code/assign_coalesce.test @@ -5,13 +5,13 @@ $x ??= a(); Block#1 Expr_FuncCall name: LITERAL('a') - result: Var#1 + result: TEMP(#1) Expr_BinaryOp_Coalesce - left: Var#2<$x> - right: Var#1 - result: Var#3 + left: TEMP(#2 ) + right: TEMP(#1) + result: TEMP(#3) Expr_Assign - var: Var#4<$x> - expr: Var#3 - result: Var#5 + var: TEMP(#4 ) + expr: TEMP(#3) + result: TEMP(#5) Terminal_Return \ No newline at end of file diff --git a/test/code/block.test b/test/code/block.test index 09186c5..e37c6f0 100644 --- a/test/code/block.test +++ b/test/code/block.test @@ -13,7 +13,7 @@ Block#1 Terminal_Echo expr: LITERAL('a') Expr_Assign - var: Var#1<$aaaa> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Terminal_Return diff --git a/test/code/cast.test b/test/code/cast.test index 0201bba..b902665 100644 --- a/test/code/cast.test +++ b/test/code/cast.test @@ -6,9 +6,9 @@ $a = (string) 12; Block#1 Expr_Cast_String expr: LITERAL(12) - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$a> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Terminal_Return diff --git a/test/code/class.test b/test/code/class.test index bd54506..c4a4607 100755 --- a/test/code/class.test +++ b/test/code/class.test @@ -40,29 +40,36 @@ Block#1 stmts: Block#3 Expr_New class: LITERAL('NS\\NameOfClass') - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$obj> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Terminal_Return Block#2 Block#3 - Stmt_ClassMethod<'doSomething'> + Stmt_ClassMethod + name: doSomething flags: public - Stmt_ClassMethod<'method1'> + Stmt_ClassMethod + name: method1 flags: private - Stmt_ClassMethod<'method2'> + Stmt_ClassMethod + name: method2 flags: protected - Stmt_ClassMethod<'method3'> + Stmt_ClassMethod + name: method3 flags: static|private - Stmt_ClassMethod<'method4'> + Stmt_ClassMethod + name: method4 flags: final|private - Stmt_ClassMethod<'method5'> + Stmt_ClassMethod + name: method5 flags: abstract|private - Stmt_ClassMethod<'method6'> + Stmt_ClassMethod + name: method6 flags: abstract|static|protected Function 'NS\NameOfClass::doSomething': mixed diff --git a/test/code/classMethod_empty.test b/test/code/classMethod_empty.test index 2ace762..27af6a9 100755 --- a/test/code/classMethod_empty.test +++ b/test/code/classMethod_empty.test @@ -10,7 +10,8 @@ Block#1 Terminal_Return Block#2 - Stmt_ClassMethod<'doSomething'> + Stmt_ClassMethod + name: doSomething flags: public Function 'NameOfClass::doSomething': mixed diff --git a/test/code/class_attributes.test b/test/code/class_attributes.test index f6ee55c..3d7225d 100644 --- a/test/code/class_attributes.test +++ b/test/code/class_attributes.test @@ -31,78 +31,79 @@ class NameOfClass6 { ----- Block#1 Stmt_Class + name: NameOfClass1 attrGroup[0]: attr[0]: name: LITERAL('NameOfAttribute') - name: NameOfClass1 stmts: Block#2 Stmt_Class + name: NameOfClass2 attrGroup[0]: attr[0]: name: LITERAL('ExampleAttribute') args[0]: LITERAL('foo') args[1]: LITERAL('bar') - name: NameOfClass2 stmts: Block#3 Stmt_Class + name: NameOfClass3 attrGroup[0]: attr[0]: name: LITERAL('Attr') attrGroup[1]: attr[0]: name: LITERAL('FooAttr') - name: NameOfClass3 stmts: Block#4 Stmt_Class + name: NameOfClass4 attrGroup[0]: attr[0]: name: LITERAL('Attr') attr[1]: name: LITERAL('FooAttr') - name: NameOfClass4 stmts: Block#5 Expr_ClassConstFetch class: LITERAL('Attribute') name: LITERAL('TARGET_CLASS') - result: Var#1 + result: TEMP(#1) Expr_ClassConstFetch class: LITERAL('Attribute') name: LITERAL('TARGET_METHOD') - result: Var#2 + result: TEMP(#2) Expr_BinaryOp_BitwiseOr - left: Var#1 - right: Var#2 - result: Var#3 + left: TEMP(#1) + right: TEMP(#2) + result: TEMP(#3) Stmt_Class + name: NameOfClass5 attrGroup[0]: attr[0]: name: LITERAL('Attribute') - args[0]: Var#3 - name: NameOfClass5 + args[0]: TEMP(#3) stmts: Block#6 Expr_ConstFetch name: LITERAL('null') - result: Var#4 + result: TEMP(#4) Stmt_Class + name: NameOfClass6 attrGroup[0]: attr[0]: name: LITERAL('ConstAttr') attrGroup[1]: attr[0]: name: LITERAL('FooAttribute') - args[0]: Var#4 - name: NameOfClass6 + args[0]: TEMP(#4) stmts: Block#7 Terminal_Return Block#2 - Stmt_ClassMethod<'method1'> + Stmt_ClassMethod + name: method1 + flags: private attrGroup[0]: attr[0]: name: LITERAL('ExampleAttributeMethod') args[0]: LITERAL('foo') args[1]: LITERAL('bar') - flags: private Block#3 @@ -117,11 +118,11 @@ Block#7 Function 'NameOfClass1::method1': mixed Block#1 Expr_Param + declaredType: mixed + name: LITERAL('foo') + result: TEMP(#1 ) attrGroup[0]: attr[0]: name: LITERAL('FooParamAttrib') args[0]: LITERAL('Foo1') - declaredType: mixed - name: LITERAL('foo') - result: Var#1<$foo> Terminal_Return \ No newline at end of file diff --git a/test/code/class_this.test b/test/code/class_this.test index 02e42f9..4b33043 100755 --- a/test/code/class_this.test +++ b/test/code/class_this.test @@ -13,15 +13,16 @@ Block#1 Terminal_Return Block#2 - Stmt_ClassMethod<'doSomething'> + Stmt_ClassMethod + name: doSomething flags: public Function 'NameOfClass::doSomething': mixed Block#1 Expr_MethodCall - var: this<$this> + var: VARIABLE(this $this) name: LITERAL('hello') - result: Var#1 + result: TEMP(#1) Terminal_Echo - expr: Var#1 + expr: TEMP(#1) Terminal_Return \ No newline at end of file diff --git a/test/code/class_typed_property.test b/test/code/class_typed_property.test index 4d94a48..02e020c 100755 --- a/test/code/class_typed_property.test +++ b/test/code/class_typed_property.test @@ -11,15 +11,15 @@ Block#1 stmts: Block#2 Expr_New class: LITERAL('NS\\NameOfClass') - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$obj> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Terminal_Return Block#2 Stmt_Property - flags: public declaredType: ?NS\NameOfClass + flags: public name: LITERAL('self') \ No newline at end of file diff --git a/test/code/closure.test b/test/code/closure.test index 47dd583..79ed5b4 100755 --- a/test/code/closure.test +++ b/test/code/closure.test @@ -10,29 +10,30 @@ var_dump($c); ----- Block#1 Expr_Assign - var: Var#1<$b> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Expr_Assign - var: Var#3<$c> + var: TEMP(#3 ) expr: LITERAL(2) - result: Var#4 - Expr_Closure<'{anonymous}#1'> - useVars[0]: local<$b> - useVars[1]: local<&$c> - result: Var#5 + result: TEMP(#4) + Expr_Closure + name: {anonymous}#1 + useVars[0]: VARIABLE(local $b) + useVars[1]: VARIABLE(local &$c) + result: TEMP(#5) Expr_Assign - var: Var#6<$fn> - expr: Var#5 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#5) + result: TEMP(#7) Expr_FuncCall - name: Var#6<$fn> + name: TEMP(#6 ) args[0]: LITERAL(3) - result: Var#8 + result: TEMP(#8) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#3<$c> - result: Var#9 + args[0]: TEMP(#3 ) + result: TEMP(#9) Terminal_Return Function '{anonymous}#1': mixed @@ -40,17 +41,17 @@ Block#1 Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Expr_BinaryOp_Mul - left: Var#2<$b> - right: Var#1<$a> - result: Var#3 + left: TEMP(#2 ) + right: TEMP(#1 ) + result: TEMP(#3) Expr_BinaryOp_Plus - left: Var#4<$c> - right: Var#3 - result: Var#5 + left: TEMP(#4 ) + right: TEMP(#3) + result: TEMP(#5) Expr_Assign - var: Var#6<$c> - expr: Var#5 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#5) + result: TEMP(#7) Terminal_Return \ No newline at end of file diff --git a/test/code/closure_empty.test b/test/code/closure_empty.test index ef863fd..fbb1b95 100755 --- a/test/code/closure_empty.test +++ b/test/code/closure_empty.test @@ -2,12 +2,13 @@ $fn = function($a) {}; ----- Block#1 - Expr_Closure<'{anonymous}#1'> - result: Var#1 + Expr_Closure + name: {anonymous}#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$fn> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Terminal_Return Function '{anonymous}#1': mixed @@ -15,5 +16,5 @@ Block#1 Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Terminal_Return \ No newline at end of file diff --git a/test/code/constDecl.test b/test/code/constDecl.test index 0fe37f1..599ff10 100755 --- a/test/code/constDecl.test +++ b/test/code/constDecl.test @@ -12,23 +12,23 @@ Block#1 valueBlock: Block#2 Terminal_Const name: LITERAL('B') - value: Var#1 + value: TEMP(#1) valueBlock: Block#3 Stmt_Class name: C stmts: Block#4 Expr_ConstFetch name: LITERAL('A') - result: Var#2 + result: TEMP(#2) Expr_ClassConstFetch class: LITERAL('C') name: LITERAL('D') - result: Var#3 + result: TEMP(#3) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#2 - args[1]: Var#3 - result: Var#4 + args[0]: TEMP(#2) + args[1]: TEMP(#3) + result: TEMP(#4) Terminal_Return Block#2 @@ -37,7 +37,7 @@ Block#3 Expr_BinaryOp_Plus left: LITERAL(2) right: LITERAL(2) - result: Var#1 + result: TEMP(#1) Block#4 Terminal_Const @@ -46,7 +46,7 @@ Block#4 valueBlock: Block#5 Terminal_Const name: LITERAL('E') - value: Var#5 + value: TEMP(#5) valueBlock: Block#6 Block#5 @@ -55,4 +55,4 @@ Block#6 Expr_BinaryOp_Plus left: LITERAL(4) right: LITERAL(4) - result: Var#5 \ No newline at end of file + result: TEMP(#5) \ No newline at end of file diff --git a/test/code/constFetch.test b/test/code/constFetch.test index 2ba984d..6714550 100755 --- a/test/code/constFetch.test +++ b/test/code/constFetch.test @@ -11,21 +11,21 @@ Block#1 Expr_ConstFetch nsName: LITERAL('Foo\\BAR') name: LITERAL('BAR') - result: Var#1 + result: TEMP(#1) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#1 - result: Var#2 + args[0]: TEMP(#1) + result: TEMP(#2) Expr_FuncCall name: LITERAL('var_dump') args[0]: LITERAL(true) - result: Var#3 + result: TEMP(#3) Expr_FuncCall name: LITERAL('var_dump') args[0]: LITERAL(false) - result: Var#4 + result: TEMP(#4) Expr_FuncCall name: LITERAL('var_dump') args[0]: LITERAL(NULL) - result: Var#5 + result: TEMP(#5) Terminal_Return \ No newline at end of file diff --git a/test/code/empty.test b/test/code/empty.test index 11a0114..8d3e21e 100755 --- a/test/code/empty.test +++ b/test/code/empty.test @@ -5,21 +5,21 @@ var_dump(empty($a['b'])); ----- Block#1 Expr_Empty - expr: Var#1<$a> - result: Var#2 + expr: TEMP(#1 ) + result: TEMP(#2) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#2 - result: Var#3 + args[0]: TEMP(#2) + result: TEMP(#3) Expr_ArrayDimFetch - var: Var#1<$a> + var: TEMP(#1 ) dim: LITERAL('b') - result: Var#4 + result: TEMP(#4) Expr_Empty - expr: Var#4 - result: Var#5 + expr: TEMP(#4) + result: TEMP(#5) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#5 - result: Var#6 + args[0]: TEMP(#5) + result: TEMP(#6) Terminal_Return \ No newline at end of file diff --git a/test/code/error_supress.test b/test/code/error_supress.test index 450c655..62c6be5 100755 --- a/test/code/error_supress.test +++ b/test/code/error_supress.test @@ -7,9 +7,9 @@ echo $dbname; ----- Block#1 Expr_Assign - var: Var#1<$dbname> + var: TEMP(#1 ) expr: LITERAL('database name') - result: Var#2 + result: TEMP(#2) Stmt_Jump target: Block#2 @@ -17,7 +17,7 @@ Block#2 Parent: Block#1 Expr_Print expr: LITERAL('hostname') - result: Var#3 + result: TEMP(#3) Terminal_Echo - expr: Var#1<$dbname> + expr: TEMP(#1 ) Terminal_Return \ No newline at end of file diff --git a/test/code/exit.test b/test/code/exit.test index cbb4a1c..3e25a90 100755 --- a/test/code/exit.test +++ b/test/code/exit.test @@ -5,7 +5,7 @@ echo $a; ----- Block#1 Expr_Assign - var: Var#1<$a> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Terminal_Exit diff --git a/test/code/exit_message.test b/test/code/exit_message.test index b51f403..2198894 100755 --- a/test/code/exit_message.test +++ b/test/code/exit_message.test @@ -5,12 +5,12 @@ echo $a; ----- Block#1 Expr_Assign - var: Var#1<$a> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Expr_BinaryOp_Concat left: LITERAL('Quitting with message: ') - right: Var#1<$a> - result: Var#3 + right: TEMP(#1 ) + result: TEMP(#3) Terminal_Exit - expr: Var#3 + expr: TEMP(#3) diff --git a/test/code/exprFuncCall.test b/test/code/exprFuncCall.test index 078802a..4ccd4aa 100755 --- a/test/code/exprFuncCall.test +++ b/test/code/exprFuncCall.test @@ -5,11 +5,11 @@ $a("some string"); ----- Block#1 Expr_Assign - var: Var#1<$a> + var: TEMP(#1 ) expr: LITERAL('print_r') - result: Var#2 + result: TEMP(#2) Expr_FuncCall - name: Var#1<$a> + name: TEMP(#1 ) args[0]: LITERAL('some string') - result: Var#3 + result: TEMP(#3) Terminal_Return \ No newline at end of file diff --git a/test/code/foreach.test b/test/code/foreach.test index 55bad43..d5949f4 100755 --- a/test/code/foreach.test +++ b/test/code/foreach.test @@ -6,13 +6,13 @@ foreach ($a as $b) { ----- Block#1 Expr_Array - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$a> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Iterator_Reset - var: Var#2<$a> + var: TEMP(#2 ) Stmt_Jump target: Block#2 @@ -20,24 +20,24 @@ Block#2 Parent: Block#1 Parent: Block#3 Iterator_Valid - var: Var#2<$a> - result: Var#4 + var: TEMP(#2 ) + result: TEMP(#4) Stmt_JumpIf - cond: Var#4 + cond: TEMP(#4) if: Block#3 else: Block#4 Block#3 Parent: Block#2 Iterator_Value - var: Var#2<$a> - result: Var#5 + var: TEMP(#2 ) + result: TEMP(#5) Expr_Assign - var: Var#6<$b> - expr: Var#5 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#5) + result: TEMP(#7) Terminal_Echo - expr: Var#6<$b> + expr: TEMP(#6 ) Stmt_Jump target: Block#2 diff --git a/test/code/function.test b/test/code/function.test index 6714560..bd4c3ec 100755 --- a/test/code/function.test +++ b/test/code/function.test @@ -4,7 +4,8 @@ function foo($a) { } ----- Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo Terminal_Return Function 'foo': mixed @@ -12,6 +13,6 @@ Block#1 Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Terminal_Return - expr: Var#1<$a> \ No newline at end of file + expr: TEMP(#1 ) \ No newline at end of file diff --git a/test/code/function_attributes.test b/test/code/function_attributes.test index cbd3456..27e3919 100644 --- a/test/code/function_attributes.test +++ b/test/code/function_attributes.test @@ -10,7 +10,8 @@ function foo5(){} function foo_func(#[FooParamAttrib('Foo1')] $foo) {} ----- Block#1 - Stmt_Function<'foo2'> + Stmt_Function + name: foo2 attrGroup[0]: attr[0]: name: LITERAL('ExampleAttribute') @@ -18,16 +19,18 @@ Block#1 args[1]: LITERAL('bar') Expr_ConstFetch name: LITERAL('null') - result: Var#1 - Stmt_Function<'foo5'> + result: TEMP(#1) + Stmt_Function + name: foo5 attrGroup[0]: attr[0]: name: LITERAL('ConstAttr') attrGroup[1]: attr[0]: name: LITERAL('FooAttribute') - args[0]: Var#1 - Stmt_Function<'foo_func'> + args[0]: TEMP(#1) + Stmt_Function + name: foo_func Terminal_Return Function 'foo2': mixed @@ -41,11 +44,11 @@ Block#1 Function 'foo_func': mixed Block#1 Expr_Param + declaredType: mixed + name: LITERAL('foo') + result: TEMP(#1 ) attrGroup[0]: attr[0]: name: LITERAL('FooParamAttrib') args[0]: LITERAL('Foo1') - declaredType: mixed - name: LITERAL('foo') - result: Var#1<$foo> Terminal_Return \ No newline at end of file diff --git a/test/code/function_empty.test b/test/code/function_empty.test index 18d442a..579ed54 100755 --- a/test/code/function_empty.test +++ b/test/code/function_empty.test @@ -2,7 +2,8 @@ function foo($a) {} ----- Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo Terminal_Return Function 'foo': mixed @@ -10,5 +11,5 @@ Block#1 Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Terminal_Return \ No newline at end of file diff --git a/test/code/function_namespace.test b/test/code/function_namespace.test index d94e85d..8098e77 100755 --- a/test/code/function_namespace.test +++ b/test/code/function_namespace.test @@ -5,7 +5,8 @@ function foo($a) { } ----- Block#1 - Stmt_Function<'NS\foo'> + Stmt_Function + name: NS\foo Terminal_Return Function 'NS\foo': mixed @@ -13,6 +14,6 @@ Block#1 Expr_Param declaredType: mixed name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Terminal_Return - expr: Var#1<$a> \ No newline at end of file + expr: TEMP(#1 ) \ No newline at end of file diff --git a/test/code/function_return_type.test b/test/code/function_return_type.test index 34f9fb8..7698b91 100755 --- a/test/code/function_return_type.test +++ b/test/code/function_return_type.test @@ -4,7 +4,8 @@ function foo(string $a): string { } ----- Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo Terminal_Return Function 'foo': string @@ -12,6 +13,6 @@ Block#1 Expr_Param declaredType: string name: LITERAL('a') - result: Var#1<$a> + result: TEMP(#1 ) Terminal_Return - expr: Var#1<$a> \ No newline at end of file + expr: TEMP(#1 ) \ No newline at end of file diff --git a/test/code/if_else.test b/test/code/if_else.test index a4cf183..d0d4557 100755 --- a/test/code/if_else.test +++ b/test/code/if_else.test @@ -9,7 +9,7 @@ echo "c"; ----- Block#1 Stmt_JumpIf - cond: Var#1<$a> + cond: TEMP(#1 ) if: Block#2 else: Block#3 diff --git a/test/code/if_else_if_else.test b/test/code/if_else_if_else.test index 57d15b7..b7f0a39 100755 --- a/test/code/if_else_if_else.test +++ b/test/code/if_else_if_else.test @@ -11,7 +11,7 @@ echo "d"; ----- Block#1 Stmt_JumpIf - cond: Var#1<$a> + cond: TEMP(#1 ) if: Block#2 else: Block#3 @@ -25,7 +25,7 @@ Block#2 Block#3 Parent: Block#1 Stmt_JumpIf - cond: Var#2<$b> + cond: TEMP(#2 ) if: Block#5 else: Block#6 diff --git a/test/code/if_elseif_else.test b/test/code/if_elseif_else.test index b082b67..a8478b0 100755 --- a/test/code/if_elseif_else.test +++ b/test/code/if_elseif_else.test @@ -11,7 +11,7 @@ echo "d"; ----- Block#1 Stmt_JumpIf - cond: Var#1<$a> + cond: TEMP(#1 ) if: Block#2 else: Block#3 @@ -25,7 +25,7 @@ Block#2 Block#3 Parent: Block#1 Stmt_JumpIf - cond: Var#2<$b> + cond: TEMP(#2 ) if: Block#5 else: Block#6 diff --git a/test/code/include.test b/test/code/include.test index 99b13f6..289e33a 100755 --- a/test/code/include.test +++ b/test/code/include.test @@ -6,21 +6,21 @@ require_once($foo); ----- Block#1 Expr_Include + expr: TEMP(#1 ) + result: TEMP(#2) type: include - expr: Var#1<$foo> - result: Var#2 Expr_Include + expr: TEMP(#1 ) + result: TEMP(#3) type: include_once - expr: Var#1<$foo> - result: Var#3 Expr_Include + expr: TEMP(#1 ) + result: TEMP(#4) type: require - expr: Var#1<$foo> - result: Var#4 Expr_Include + expr: TEMP(#1 ) + result: TEMP(#5) type: require_once - expr: Var#1<$foo> - result: Var#5 Terminal_Return diff --git a/test/code/interface.test b/test/code/interface.test index f9971d0..2d1cf94 100755 --- a/test/code/interface.test +++ b/test/code/interface.test @@ -11,7 +11,8 @@ Block#1 Terminal_Return Block#2 - Stmt_ClassMethod<'method'> + Stmt_ClassMethod + name: method flags: public Function 'Test::method': mixed \ No newline at end of file diff --git a/test/code/intersection_type.test b/test/code/intersection_type.test index 8fea55c..e46f732 100644 --- a/test/code/intersection_type.test +++ b/test/code/intersection_type.test @@ -4,7 +4,8 @@ function foo(array&string&null $string) { } ----- Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo Terminal_Return Function 'foo': mixed @@ -12,6 +13,6 @@ Block#1 Expr_Param declaredType: array&string&null name: LITERAL('string') - result: Var#1<$string> + result: TEMP(#1 ) Terminal_Return diff --git a/test/code/isset.test b/test/code/isset.test index 6a35644..c1eb133 100755 --- a/test/code/isset.test +++ b/test/code/isset.test @@ -6,12 +6,12 @@ if (isset($a, $b, $c)) { ----- Block#1 Expr_Isset - vars[0]: Var#1<$a> - vars[1]: Var#2<$b> - vars[2]: Var#3<$c> - result: Var#4 + vars[0]: TEMP(#1 ) + vars[1]: TEMP(#2 ) + vars[2]: TEMP(#3 ) + result: TEMP(#4) Stmt_JumpIf - cond: Var#4 + cond: TEMP(#4) if: Block#2 else: Block#3 diff --git a/test/code/labels.test b/test/code/labels.test index da814cc..d8f74ff 100755 --- a/test/code/labels.test +++ b/test/code/labels.test @@ -12,7 +12,8 @@ label: echo "C"; ----- Block#1 - Stmt_Function<'test'> + Stmt_Function + name: test Terminal_Echo expr: LITERAL('A') Stmt_Jump diff --git a/test/code/list.test b/test/code/list.test index be49278..93fca93 100755 --- a/test/code/list.test +++ b/test/code/list.test @@ -5,43 +5,43 @@ foreach ($a as list($b, $c)); ----- Block#1 Expr_ArrayDimFetch - var: Var#1<$array> + var: TEMP(#1 ) dim: LITERAL(0) - result: Var#2 + result: TEMP(#2) Expr_Assign - var: Var#3<$a> - expr: Var#2 - result: Var#4 + var: TEMP(#3 ) + expr: TEMP(#2) + result: TEMP(#4) Expr_ArrayDimFetch - var: Var#1<$array> + var: TEMP(#1 ) dim: LITERAL(2) - result: Var#5 + result: TEMP(#5) Expr_Assign - var: Var#6<$b> - expr: Var#5 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#5) + result: TEMP(#7) Expr_ArrayDimFetch - var: Var#1<$array> + var: TEMP(#1 ) dim: LITERAL(3) - result: Var#8 + result: TEMP(#8) Expr_ArrayDimFetch - var: Var#8 + var: TEMP(#8) dim: LITERAL(0) - result: Var#9 + result: TEMP(#9) Expr_Assign - var: Var#10<$c> - expr: Var#9 - result: Var#11 + var: TEMP(#10 ) + expr: TEMP(#9) + result: TEMP(#11) Expr_ArrayDimFetch - var: Var#8 + var: TEMP(#8) dim: LITERAL(1) - result: Var#12 + result: TEMP(#12) Expr_Assign - var: Var#13<$d> - expr: Var#12 - result: Var#14 + var: TEMP(#13 ) + expr: TEMP(#12) + result: TEMP(#14) Iterator_Reset - var: Var#3<$a> + var: TEMP(#3 ) Stmt_Jump target: Block#2 @@ -49,34 +49,34 @@ Block#2 Parent: Block#1 Parent: Block#3 Iterator_Valid - var: Var#3<$a> - result: Var#15 + var: TEMP(#3 ) + result: TEMP(#15) Stmt_JumpIf - cond: Var#15 + cond: TEMP(#15) if: Block#3 else: Block#4 Block#3 Parent: Block#2 Iterator_Value - var: Var#3<$a> - result: Var#16 + var: TEMP(#3 ) + result: TEMP(#16) Expr_ArrayDimFetch - var: Var#16 + var: TEMP(#16) dim: LITERAL(0) - result: Var#17 + result: TEMP(#17) Expr_Assign - var: Var#18<$b> - expr: Var#17 - result: Var#19 + var: TEMP(#18 ) + expr: TEMP(#17) + result: TEMP(#19) Expr_ArrayDimFetch - var: Var#16 + var: TEMP(#16) dim: LITERAL(1) - result: Var#20 + result: TEMP(#20) Expr_Assign - var: Var#21<$c> - expr: Var#20 - result: Var#22 + var: TEMP(#21 ) + expr: TEMP(#20) + result: TEMP(#22) Stmt_Jump target: Block#2 diff --git a/test/code/listKeys.test b/test/code/listKeys.test index 24214af..e9e4289 100755 --- a/test/code/listKeys.test +++ b/test/code/listKeys.test @@ -5,23 +5,23 @@ list('a' => $a, $key => $b) = $array; ----- Block#1 Expr_Assign - var: Var#1<$key> + var: TEMP(#1 ) expr: LITERAL('b') - result: Var#2 + result: TEMP(#2) Expr_ArrayDimFetch - var: Var#3<$array> + var: TEMP(#3 ) dim: LITERAL('a') - result: Var#4 + result: TEMP(#4) Expr_Assign - var: Var#5<$a> - expr: Var#4 - result: Var#6 + var: TEMP(#5 ) + expr: TEMP(#4) + result: TEMP(#6) Expr_ArrayDimFetch - var: Var#3<$array> - dim: Var#1<$key> - result: Var#7 + var: TEMP(#3 ) + dim: TEMP(#1 ) + result: TEMP(#7) Expr_Assign - var: Var#8<$b> - expr: Var#7 - result: Var#9 + var: TEMP(#8 ) + expr: TEMP(#7) + result: TEMP(#9) Terminal_Return \ No newline at end of file diff --git a/test/code/literal.test b/test/code/literal.test index a5143f1..1f92ac6 100644 --- a/test/code/literal.test +++ b/test/code/literal.test @@ -7,19 +7,19 @@ $d = "aaaa'')"; ----- Block#1 Expr_Assign - var: Var#1<$a> + var: TEMP(#1 ) expr: LITERAL('aaaa') - result: Var#2 + result: TEMP(#2) Expr_Assign - var: Var#3<$b> + var: TEMP(#3 ) expr: LITERAL('aaaa\')eeee') - result: Var#4 + result: TEMP(#4) Expr_Assign - var: Var#5<$c> + var: TEMP(#5 ) expr: LITERAL('aaaa\')') - result: Var#6 + result: TEMP(#6) Expr_Assign - var: Var#7<$d> + var: TEMP(#7 ) expr: LITERAL('aaaa\'\')') - result: Var#8 + result: TEMP(#8) Terminal_Return \ No newline at end of file diff --git a/test/code/match.test b/test/code/match.test index 2d302d2..64d83d5 100644 --- a/test/code/match.test +++ b/test/code/match.test @@ -18,18 +18,18 @@ Block#1 Block#2 Parent: Block#1 Expr_Assign - var: Var#1 + var: TEMP(#1) expr: LITERAL('foo') - result: Var#2 + result: TEMP(#2) Stmt_Jump target: Block#5 Block#3 Parent: Block#1 Expr_Assign - var: Var#3 + var: TEMP(#3) expr: LITERAL('bar') - result: Var#4 + result: TEMP(#4) Stmt_Jump target: Block#5 @@ -38,7 +38,7 @@ Block#4 Expr_BinaryOp_Concat left: LITERAL('baz') right: LITERAL('buz') - result: Var#5 + result: TEMP(#5) Stmt_Jump target: Block#5 @@ -46,9 +46,9 @@ Block#5 Parent: Block#2 Parent: Block#3 Parent: Block#4 - Var#6 = Phi(Var#1, Var#3, Var#5) + TEMP(#6) = Phi(TEMP(#1), TEMP(#3), TEMP(#5)) Terminal_Echo - expr: Var#6 + expr: TEMP(#6) Terminal_Return diff --git a/test/code/match2.test b/test/code/match2.test index 8a8cb8f..4cf8aa0 100644 --- a/test/code/match2.test +++ b/test/code/match2.test @@ -9,18 +9,18 @@ Block#1 Expr_BinaryOp_Identical left: LITERAL(1) right: LITERAL(10) - result: Var#1 + result: TEMP(#1) Stmt_JumpIf - cond: Var#1 + cond: TEMP(#1) if: Block#2 else: Block#3 Block#2 Parent: Block#1 Expr_Assign - var: Var#2 + var: TEMP(#2) expr: LITERAL('foo') - result: Var#3 + result: TEMP(#3) Stmt_Jump target: Block#4 @@ -29,9 +29,9 @@ Block#3 Expr_BinaryOp_Identical left: LITERAL(5) right: LITERAL(10) - result: Var#4 + result: TEMP(#4) Stmt_JumpIf - cond: Var#4 + cond: TEMP(#4) if: Block#5 else: Block#6 @@ -39,17 +39,17 @@ Block#4 Parent: Block#2 Parent: Block#5 Parent: Block#7 - Var#5 = Phi(Var#2, Var#6, Var#7) + TEMP(#5) = Phi(TEMP(#2), TEMP(#6), TEMP(#7)) Terminal_Echo - expr: Var#5 + expr: TEMP(#5) Terminal_Return Block#5 Parent: Block#3 Expr_Assign - var: Var#6 + var: TEMP(#6) expr: LITERAL('bar') - result: Var#8 + result: TEMP(#8) Stmt_Jump target: Block#4 @@ -58,13 +58,13 @@ Block#6 Expr_BinaryOp_Plus left: LITERAL(5) right: LITERAL(5) - result: Var#9 + result: TEMP(#9) Expr_BinaryOp_Identical - left: Var#9 + left: TEMP(#9) right: LITERAL(10) - result: Var#10 + result: TEMP(#10) Stmt_JumpIf - cond: Var#10 + cond: TEMP(#10) if: Block#7 else: Block#8 @@ -73,7 +73,7 @@ Block#7 Expr_BinaryOp_Concat left: LITERAL('baz') right: LITERAL('buz') - result: Var#7 + result: TEMP(#7) Stmt_Jump target: Block#4 diff --git a/test/code/nested_phi.test b/test/code/nested_phi.test index f4e94a6..d6e5edf 100755 --- a/test/code/nested_phi.test +++ b/test/code/nested_phi.test @@ -11,19 +11,19 @@ echo $a; ----- Block#1 Expr_Assign - var: Var#1<$a> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Expr_Array - keys[0]: NULL - keys[1]: NULL - keys[2]: NULL + keys[0]: NULL() + keys[1]: NULL() + keys[2]: NULL() values[0]: LITERAL(1) values[1]: LITERAL(2) values[2]: LITERAL(3) - result: Var#3 + result: TEMP(#3) Iterator_Reset - var: Var#3 + var: TEMP(#3) Stmt_Jump target: Block#2 @@ -31,48 +31,48 @@ Block#2 Parent: Block#1 Parent: Block#3 Parent: Block#5 - Var#4<$a> = Phi(Var#1<$a>, Var#5<$a>) + TEMP(#4 ) = Phi(TEMP(#1 ), TEMP(#5 )) Iterator_Valid - var: Var#3 - result: Var#6 + var: TEMP(#3) + result: TEMP(#6) Stmt_JumpIf - cond: Var#6 + cond: TEMP(#6) if: Block#3 else: Block#4 Block#3 Parent: Block#2 Iterator_Value - var: Var#3 - result: Var#7 + var: TEMP(#3) + result: TEMP(#7) Expr_Assign - var: Var#8<$b> - expr: Var#7 - result: Var#9 + var: TEMP(#8 ) + expr: TEMP(#7) + result: TEMP(#9) Expr_BinaryOp_Greater - left: Var#4<$a> + left: TEMP(#4 ) right: LITERAL(0) - result: Var#10 + result: TEMP(#10) Stmt_JumpIf - cond: Var#10 + cond: TEMP(#10) if: Block#5 else: Block#2 Block#4 Parent: Block#2 Terminal_Echo - expr: Var#4<$a> + expr: TEMP(#4 ) Terminal_Return Block#5 Parent: Block#3 Expr_BinaryOp_Plus - left: Var#4<$a> - right: Var#8<$b> - result: Var#11 + left: TEMP(#4 ) + right: TEMP(#8 ) + result: TEMP(#11) Expr_Assign - var: Var#5<$a> - expr: Var#11 - result: Var#12 + var: TEMP(#5 ) + expr: TEMP(#11) + result: TEMP(#12) Stmt_Jump target: Block#2 \ No newline at end of file diff --git a/test/code/nop.test b/test/code/nop.test index 9660bfc..522e670 100755 --- a/test/code/nop.test +++ b/test/code/nop.test @@ -6,9 +6,9 @@ echo $a; ----- Block#1 Expr_Assign - var: Var#1<$a> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Terminal_Echo - expr: Var#1<$a> + expr: TEMP(#1 ) Terminal_Return \ No newline at end of file diff --git a/test/code/nsFuncCall.test b/test/code/nsFuncCall.test index fe524a1..5006170 100755 --- a/test/code/nsFuncCall.test +++ b/test/code/nsFuncCall.test @@ -7,5 +7,5 @@ Block#1 Expr_NsFuncCall nsName: LITERAL('Foo\\call') name: LITERAL('call') - result: Var#1 + result: TEMP(#1) Terminal_Return \ No newline at end of file diff --git a/test/code/or.test b/test/code/or.test index 80d537b..8d4ec80 100755 --- a/test/code/or.test +++ b/test/code/or.test @@ -5,29 +5,29 @@ $x = a() || b(); Block#1 Expr_FuncCall name: LITERAL('a') - result: Var#1 + result: TEMP(#1) Stmt_JumpIf - cond: Var#1 + cond: TEMP(#1) if: Block#2 else: Block#3 Block#2 Parent: Block#3 Parent: Block#1 - Var#2 = Phi(LITERAL(true), Var#3) + TEMP(#2) = Phi(LITERAL(true), TEMP(#3)) Expr_Assign - var: Var#4<$x> - expr: Var#2 - result: Var#5 + var: TEMP(#4 ) + expr: TEMP(#2) + result: TEMP(#5) Terminal_Return Block#3 Parent: Block#1 Expr_FuncCall name: LITERAL('b') - result: Var#6 + result: TEMP(#6) Expr_Cast_Bool - expr: Var#6 - result: Var#3 + expr: TEMP(#6) + result: TEMP(#3) Stmt_Jump target: Block#2 \ No newline at end of file diff --git a/test/code/property.test b/test/code/property.test index 530a848..54b2559 100755 --- a/test/code/property.test +++ b/test/code/property.test @@ -24,51 +24,51 @@ Block#1 Block#2 Stmt_Property - flags: public declaredType: mixed + flags: public name: LITERAL('prop') defaultVar: LITERAL(1) defaultBlock: Block#3 Stmt_Property - flags: private declaredType: mixed + flags: private name: LITERAL('prop2') - defaultVar: Var#1 + defaultVar: TEMP(#1) defaultBlock: Block#4 Stmt_Property - flags: readonly|private declaredType: mixed + flags: readonly|private name: LITERAL('prop3') Stmt_Property - flags: readonly|private declaredType: mixed + flags: readonly|private name: LITERAL('prop4') Stmt_Property - flags: readonly|static|private declaredType: mixed + flags: readonly|static|private name: LITERAL('prop5') Stmt_Property - flags: static|public declaredType: mixed + flags: static|public name: LITERAL('prop6') Stmt_Property - flags: protected declaredType: mixed + flags: protected name: LITERAL('prop7') Expr_ConstFetch name: LITERAL('null') - result: Var#2 + result: TEMP(#2) Stmt_Property + declaredType: string + flags: private + name: LITERAL('foo5') attrGroup[0]: attr[0]: name: LITERAL('ConstAttr') attrGroup[1]: attr[0]: name: LITERAL('FooAttribute') - args[0]: Var#2 - flags: private - declaredType: string - name: LITERAL('foo5') + args[0]: TEMP(#2) Terminal_Const name: LITERAL('FOO') value: LITERAL('foo') @@ -80,6 +80,6 @@ Block#4 Expr_BinaryOp_Plus left: LITERAL(1) right: LITERAL(1) - result: Var#1 + result: TEMP(#1) Block#5 diff --git a/test/code/shellExec.test b/test/code/shellExec.test index 429e914..80cb58e 100755 --- a/test/code/shellExec.test +++ b/test/code/shellExec.test @@ -5,10 +5,10 @@ Block#1 Expr_ConcatList list[0]: LITERAL('ls ') - list[1]: Var#1<$dir> - result: Var#2 + list[1]: TEMP(#1 ) + result: TEMP(#2) Expr_FuncCall name: LITERAL('shell_exec') - args[0]: Var#2 - result: Var#3 + args[0]: TEMP(#2) + result: TEMP(#3) Terminal_Return \ No newline at end of file diff --git a/test/code/static.test b/test/code/static.test index e663d98..8aee4bb 100755 --- a/test/code/static.test +++ b/test/code/static.test @@ -4,15 +4,15 @@ echo $flag; ----- Block#1 Terminal_StaticVar - var: Var#1> - defaultVar: Var#2 + var: TEMP(#1 ) + defaultVar: TEMP(#2) defaultBlock: Block#2 Terminal_Echo - expr: Var#1> + expr: TEMP(#1 ) Terminal_Return Block#2 Parent: Block#1 Expr_ConstFetch name: LITERAL('FALSE') - result: Var#2 + result: TEMP(#2) diff --git a/test/code/switch.test b/test/code/switch.test index 9e06019..d90c58a 100755 --- a/test/code/switch.test +++ b/test/code/switch.test @@ -14,7 +14,7 @@ switch ($i) { ----- Block#1 Stmt_Switch - cond: Var#1<$i> + cond: TEMP(#1 ) cases[0]: LITERAL(0) cases[1]: LITERAL(1) cases[2]: LITERAL(2) diff --git a/test/code/switch2.test b/test/code/switch2.test index 27bdb01..5aa06e5 100755 --- a/test/code/switch2.test +++ b/test/code/switch2.test @@ -14,11 +14,11 @@ echo "D"; ----- Block#1 Expr_BinaryOp_Equal - left: Var#1<$i> - right: Var#2<$j> - result: Var#3 + left: TEMP(#1 ) + right: TEMP(#2 ) + result: TEMP(#3) Stmt_JumpIf - cond: Var#3 + cond: TEMP(#3) if: Block#2 else: Block#3 @@ -34,11 +34,11 @@ Block#2 Block#3 Parent: Block#1 Expr_BinaryOp_Equal - left: Var#1<$i> - right: Var#4<$k> - result: Var#5 + left: TEMP(#1 ) + right: TEMP(#4 ) + result: TEMP(#5) Stmt_JumpIf - cond: Var#5 + cond: TEMP(#5) if: Block#2 else: Block#5 @@ -53,11 +53,11 @@ Block#4 Block#5 Parent: Block#3 Expr_BinaryOp_Equal - left: Var#1<$i> - right: Var#6<$x> - result: Var#7 + left: TEMP(#1 ) + right: TEMP(#6 ) + result: TEMP(#7) Stmt_JumpIf - cond: Var#7 + cond: TEMP(#7) if: Block#4 else: Block#7 @@ -71,11 +71,11 @@ Block#6 Block#7 Parent: Block#5 Expr_BinaryOp_Equal - left: Var#1<$i> - right: Var#8<$y> - result: Var#9 + left: TEMP(#1 ) + right: TEMP(#8 ) + result: TEMP(#9) Stmt_JumpIf - cond: Var#9 + cond: TEMP(#9) if: Block#8 else: Block#2 diff --git a/test/code/ternary.test b/test/code/ternary.test index 8baffc8..debaa27 100755 --- a/test/code/ternary.test +++ b/test/code/ternary.test @@ -4,34 +4,34 @@ $a = $b ? $c : $d; ----- Block#1 Stmt_JumpIf - cond: Var#1<$b> + cond: TEMP(#1 ) if: Block#2 else: Block#3 Block#2 Parent: Block#1 Expr_Assign - var: Var#2 - expr: Var#3<$c> - result: Var#4 + var: TEMP(#2) + expr: TEMP(#3 ) + result: TEMP(#4) Stmt_Jump target: Block#4 Block#3 Parent: Block#1 Expr_Assign - var: Var#5 - expr: Var#6<$d> - result: Var#7 + var: TEMP(#5) + expr: TEMP(#6 ) + result: TEMP(#7) Stmt_Jump target: Block#4 Block#4 Parent: Block#2 Parent: Block#3 - Var#8 = Phi(Var#2, Var#5) + TEMP(#8) = Phi(TEMP(#2), TEMP(#5)) Expr_Assign - var: Var#9<$a> - expr: Var#8 - result: Var#10 + var: TEMP(#9 ) + expr: TEMP(#8) + result: TEMP(#10) Terminal_Return \ No newline at end of file diff --git a/test/code/ternary2.test b/test/code/ternary2.test index 79a491a..5ca3bb7 100755 --- a/test/code/ternary2.test +++ b/test/code/ternary2.test @@ -4,61 +4,61 @@ $a = $b ?: ($b ?: $c); ----- Block#1 Stmt_JumpIf - cond: Var#1<$b> + cond: TEMP(#1 ) if: Block#2 else: Block#3 Block#2 Parent: Block#1 Expr_Assign - var: Var#2 - expr: Var#1<$b> - result: Var#3 + var: TEMP(#2) + expr: TEMP(#1 ) + result: TEMP(#3) Stmt_Jump target: Block#4 Block#3 Parent: Block#1 Stmt_JumpIf - cond: Var#1<$b> + cond: TEMP(#1 ) if: Block#5 else: Block#6 Block#4 Parent: Block#2 Parent: Block#7 - Var#4 = Phi(Var#2, Var#5) + TEMP(#4) = Phi(TEMP(#2), TEMP(#5)) Expr_Assign - var: Var#6<$a> - expr: Var#4 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#4) + result: TEMP(#7) Terminal_Return Block#5 Parent: Block#3 Expr_Assign - var: Var#8 - expr: Var#1<$b> - result: Var#9 + var: TEMP(#8) + expr: TEMP(#1 ) + result: TEMP(#9) Stmt_Jump target: Block#7 Block#6 Parent: Block#3 Expr_Assign - var: Var#10 - expr: Var#11<$c> - result: Var#12 + var: TEMP(#10) + expr: TEMP(#11 ) + result: TEMP(#12) Stmt_Jump target: Block#7 Block#7 Parent: Block#5 Parent: Block#6 - Var#13 = Phi(Var#8, Var#10) + TEMP(#13) = Phi(TEMP(#8), TEMP(#10)) Expr_Assign - var: Var#5 - expr: Var#13 - result: Var#14 + var: TEMP(#5) + expr: TEMP(#13) + result: TEMP(#14) Stmt_Jump target: Block#4 \ No newline at end of file diff --git a/test/code/throw.test b/test/code/throw.test index 957b304..fa695cd 100644 --- a/test/code/throw.test +++ b/test/code/throw.test @@ -5,25 +5,25 @@ throw new \InvalidArgumentException("foo"); ----- Block#1 Stmt_JumpIf - cond: Var#1<$x> + cond: TEMP(#1 ) if: Block#2 else: Block#3 Block#2 Parent: Block#1 - Var#2 = Phi(LITERAL(true), Var#3) + TEMP(#2) = Phi(LITERAL(true), TEMP(#3)) Expr_New class: LITERAL('InvalidArgumentException') args[0]: LITERAL('foo') - result: Var#4 + result: TEMP(#4) Terminal_Throw - expr: Var#4 + expr: TEMP(#4) Block#3 Parent: Block#1 Expr_New class: LITERAL('Exception') args[0]: LITERAL('foo') - result: Var#5 + result: TEMP(#5) Terminal_Throw - expr: Var#5 + expr: TEMP(#5) diff --git a/test/code/traitUse.test b/test/code/traitUse.test index 94aeb20..d9e3317 100644 --- a/test/code/traitUse.test +++ b/test/code/traitUse.test @@ -48,15 +48,19 @@ Block#1 Terminal_Return Block#2 - Stmt_ClassMethod<'smallTalk'> + Stmt_ClassMethod + name: smallTalk flags: public - Stmt_ClassMethod<'bigTalk'> + Stmt_ClassMethod + name: bigTalk flags: public Block#3 - Stmt_ClassMethod<'smallTalk'> + Stmt_ClassMethod + name: smallTalk flags: public - Stmt_ClassMethod<'bigTalk'> + Stmt_ClassMethod + name: bigTalk flags: public Block#4 @@ -64,12 +68,12 @@ Block#4 use[0]: LITERAL('\\A') use[1]: LITERAL('\\B') adaptation[0]: Insteadof - trait:LITERAL('\\B') - method:LITERAL('smallTalk') + trait: LITERAL('\\B') + method: LITERAL('smallTalk') insteadof[0]: LITERAL('\\A') adaptation[1]: Insteadof - trait:LITERAL('\\A') - method:LITERAL('bigTalk') + trait: LITERAL('\\A') + method: LITERAL('bigTalk') insteadof[0]: LITERAL('\\B') Block#5 @@ -77,18 +81,18 @@ Block#5 use[0]: LITERAL('\\A') use[1]: LITERAL('\\B') adaptation[0]: Insteadof - trait:LITERAL('\\B') - method:LITERAL('smallTalk') + trait: LITERAL('\\B') + method: LITERAL('smallTalk') insteadof[0]: LITERAL('\\A') adaptation[1]: Insteadof - trait:LITERAL('\\A') - method:LITERAL('bigTalk') + trait: LITERAL('\\A') + method: LITERAL('bigTalk') insteadof[0]: LITERAL('\\B') adaptation[2]: Alias - trait:LITERAL('\\B') - method:LITERAL('bigTalk') - newName:LITERAL('talk') - newModifier:private + trait: LITERAL('\\B') + method: LITERAL('bigTalk') + newName: LITERAL('talk') + newModifier: private Function 'A::smallTalk': mixed Block#1 diff --git a/test/code/traitUse2.test b/test/code/traitUse2.test index 0c6d56d..05de201 100644 --- a/test/code/traitUse2.test +++ b/test/code/traitUse2.test @@ -26,23 +26,24 @@ Block#1 Terminal_Return Block#2 - Stmt_ClassMethod<'sayHello'> + Stmt_ClassMethod + name: sayHello flags: public Block#3 Stmt_TraitUse use[0]: LITERAL('\\HelloWorld') adaptation[0]: Alias - method:LITERAL('sayHello') - newModifier:protected + method: LITERAL('sayHello') + newModifier: protected Block#4 Stmt_TraitUse use[0]: LITERAL('\\HelloWorld') adaptation[0]: Alias - method:LITERAL('sayHello') - newName:LITERAL('myPrivateHello') - newModifier:private + method: LITERAL('sayHello') + newName: LITERAL('myPrivateHello') + newModifier: private Function 'HelloWorld::sayHello': mixed Block#1 diff --git a/test/code/try.test b/test/code/try.test index db006ba..0c6fd0d 100644 --- a/test/code/try.test +++ b/test/code/try.test @@ -12,8 +12,8 @@ Block#1 Stmt_Try catchTypes[0]: MyException|MyOtherException catchTypes[1]: MyException2 - catchVars[0]: Var#1<$e> - catchVars[1]: NULL + catchVars[0]: TEMP(#1 ) + catchVars[1]: NULL() body: Block#2 catch[0]: Block#3 catch[1]: Block#4 @@ -21,24 +21,24 @@ Block#1 Block#2 Parent: Block#1 - catchTarget(Var#1<$e>): Block#3 - catchTarget(NULL): Block#4 + catchTarget(TEMP(#1 )): Block#3 + catchTarget(NULL()): Block#4 Expr_New class: LITERAL('MyException') - result: Var#2 + result: TEMP(#2) Terminal_Throw - expr: Var#2 + expr: TEMP(#2) Block#3 Parent: Block#2 Expr_FuncCall name: LITERAL('get_class') - args[0]: Var#1<$e> - result: Var#3 + args[0]: TEMP(#1 ) + result: TEMP(#3) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#3 - result: Var#4 + args[0]: TEMP(#3) + result: TEMP(#4) Stmt_Jump target: Block#5 diff --git a/test/code/try_bodyblocks.test b/test/code/try_bodyblocks.test index ee70bb8..dd1449b 100644 --- a/test/code/try_bodyblocks.test +++ b/test/code/try_bodyblocks.test @@ -17,20 +17,20 @@ try { Block#1 Stmt_Try catchTypes[0]: Exception - catchVars[0]: Var#1<$e> + catchVars[0]: TEMP(#1 ) body: Block#2 catch[0]: Block#3 finally: Block#4 Block#2 Parent: Block#1 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doBar') - result: Var#2 + result: TEMP(#2) Stmt_JumpIf - cond: Var#2 + cond: TEMP(#2) if: Block#5 else: Block#6 @@ -42,9 +42,9 @@ Block#3 Parent: Block#7 Parent: Block#8 finallyTarget: Block#4 - Var#3<$e> = Phi(Var#1<$e>, Var#4<$e>, Var#5<$e>) + TEMP(#3 ) = Phi(TEMP(#1 ), TEMP(#4 ), TEMP(#5 )) Terminal_Return - expr: Var#3<$e> + expr: TEMP(#3 ) Block#4 Parent: Block#2 @@ -59,51 +59,51 @@ Block#4 Block#5 Parent: Block#2 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_New class: LITERAL('Exception') args[0]: LITERAL('foo') - result: Var#6 + result: TEMP(#6) Terminal_Throw - expr: Var#6 + expr: TEMP(#6) Block#6 Parent: Block#2 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doFoo') - result: Var#7 + result: TEMP(#7) Stmt_JumpIf - cond: Var#7 + cond: TEMP(#7) if: Block#7 else: Block#8 Block#7 Parent: Block#6 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doFi') - result: Var#8 + result: TEMP(#8) Stmt_Jump target: Block#9 Block#8 Parent: Block#6 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doFi') - result: Var#9 + result: TEMP(#9) Stmt_Jump target: Block#9 Block#9 Parent: Block#7 Parent: Block#8 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Stmt_Jump target: Block#4 \ No newline at end of file diff --git a/test/code/try_bodyblocks2.test b/test/code/try_bodyblocks2.test index be9804e..21e7ab5 100644 --- a/test/code/try_bodyblocks2.test +++ b/test/code/try_bodyblocks2.test @@ -19,20 +19,20 @@ echo "next"; Block#1 Stmt_Try catchTypes[0]: Exception - catchVars[0]: Var#1<$e> + catchVars[0]: TEMP(#1 ) body: Block#2 catch[0]: Block#3 finally: Block#4 Block#2 Parent: Block#1 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doBar') - result: Var#2 + result: TEMP(#2) Stmt_JumpIf - cond: Var#2 + cond: TEMP(#2) if: Block#5 else: Block#6 @@ -44,9 +44,9 @@ Block#3 Parent: Block#8 Parent: Block#9 finallyTarget: Block#4 - Var#3<$e> = Phi(Var#1<$e>, Var#4<$e>, Var#5<$e>) + TEMP(#3 ) = Phi(TEMP(#1 ), TEMP(#4 ), TEMP(#5 )) Terminal_Return - expr: Var#3<$e> + expr: TEMP(#3 ) Block#4 Parent: Block#2 @@ -63,24 +63,24 @@ Block#4 Block#5 Parent: Block#2 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_New class: LITERAL('Exception') args[0]: LITERAL('foo') - result: Var#6 + result: TEMP(#6) Terminal_Throw - expr: Var#6 + expr: TEMP(#6) Block#6 Parent: Block#2 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doFoo') - result: Var#7 + result: TEMP(#7) Stmt_JumpIf - cond: Var#7 + cond: TEMP(#7) if: Block#8 else: Block#9 @@ -92,28 +92,28 @@ Block#7 Block#8 Parent: Block#6 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doFi') - result: Var#8 + result: TEMP(#8) Stmt_Jump target: Block#10 Block#9 Parent: Block#6 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_FuncCall name: LITERAL('doFi') - result: Var#9 + result: TEMP(#9) Stmt_Jump target: Block#10 Block#10 Parent: Block#8 Parent: Block#9 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Stmt_Jump target: Block#4 \ No newline at end of file diff --git a/test/code/try_finally.test b/test/code/try_finally.test index facd879..59ce932 100644 --- a/test/code/try_finally.test +++ b/test/code/try_finally.test @@ -11,27 +11,27 @@ try { Block#1 Stmt_Try catchTypes[0]: Exception - catchVars[0]: Var#1<$e> + catchVars[0]: TEMP(#1 ) body: Block#2 catch[0]: Block#3 finally: Block#4 Block#2 Parent: Block#1 - catchTarget(Var#1<$e>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_New class: LITERAL('Exception') args[0]: LITERAL('foo') - result: Var#2 + result: TEMP(#2) Terminal_Throw - expr: Var#2 + expr: TEMP(#2) Block#3 Parent: Block#2 finallyTarget: Block#4 Terminal_Return - expr: Var#1<$e> + expr: TEMP(#1 ) Block#4 Parent: Block#2 diff --git a/test/code/try_nested.test b/test/code/try_nested.test index c4d5cd0..dcf61a6 100644 --- a/test/code/try_nested.test +++ b/test/code/try_nested.test @@ -19,18 +19,18 @@ try { Block#1 Stmt_Try catchTypes[0]: Exception2 - catchVars[0]: Var#1<$e2> + catchVars[0]: TEMP(#1 ) body: Block#2 catch[0]: Block#3 finally: Block#4 Block#2 Parent: Block#1 - catchTarget(Var#1<$e2>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Stmt_Try catchTypes[0]: Exception1 - catchVars[0]: Var#2<$e1> + catchVars[0]: TEMP(#2 ) body: Block#5 catch[0]: Block#6 finally: Block#7 @@ -39,9 +39,9 @@ Block#3 Parent: Block#2 Parent: Block#7 finallyTarget: Block#4 - Var#3<$e2> = Phi(Var#1<$e2>, Var#4<$e2>) + TEMP(#3 ) = Phi(TEMP(#1 ), TEMP(#4 )) Terminal_Echo - expr: Var#3<$e2> + expr: TEMP(#3 ) Stmt_Jump target: Block#4 @@ -51,13 +51,13 @@ Block#4 Parent: Block#7 Expr_ConstFetch name: LITERAL('false') - result: Var#5 + result: TEMP(#5) Terminal_Return - expr: Var#5 + expr: TEMP(#5) Block#5 Parent: Block#2 - catchTarget(Var#2<$e1>): Block#6 + catchTarget(TEMP(#2 )): Block#6 finallyTarget: Block#7 Terminal_Echo expr: LITERAL('nested try') @@ -68,17 +68,17 @@ Block#6 Parent: Block#5 finallyTarget: Block#7 Terminal_Echo - expr: Var#2<$e1> + expr: TEMP(#2 ) Stmt_Jump target: Block#7 Block#7 Parent: Block#5 Parent: Block#6 - catchTarget(Var#1<$e2>): Block#3 + catchTarget(TEMP(#1 )): Block#3 finallyTarget: Block#4 Expr_ConstFetch name: LITERAL('true') - result: Var#6 + result: TEMP(#6) Terminal_Return - expr: Var#6 \ No newline at end of file + expr: TEMP(#6) \ No newline at end of file diff --git a/test/code/type_assert.test b/test/code/type_assert.test index fcbc950..4517799 100755 --- a/test/code/type_assert.test +++ b/test/code/type_assert.test @@ -8,70 +8,74 @@ var_dump($a); Block#1 Expr_FuncCall name: LITERAL('is_int') - args[0]: Var#1<$a> - result: Var#2 + args[0]: TEMP(#1 ) + result: TEMP(#2) Stmt_JumpIf - cond: Var#2 + cond: TEMP(#2) if: Block#2 else: Block#3 Block#2 Parent: Block#1 - Expr_Assertion - expr: Var#1<$a> - result: Var#3<$a> + Expr_Assertion + expr: TEMP(#1 ) + result: TEMP(#3 ) + assert: LITERAL('int') Stmt_Jump target: Block#4 Block#3 Parent: Block#1 - Expr_Assertion - expr: Var#1<$a> - result: Var#4<$a> + Expr_Assertion + expr: TEMP(#1 ) + result: TEMP(#4 ) + assert: not(LITERAL('int')) Expr_FuncCall name: LITERAL('is_float') - args[0]: Var#4<$a> - result: Var#5 + args[0]: TEMP(#4 ) + result: TEMP(#5) Expr_Cast_Bool - expr: Var#5 - result: Var#6 + expr: TEMP(#5) + result: TEMP(#6) Stmt_Jump target: Block#4 Block#4 Parent: Block#3 Parent: Block#2 - Var#7 = Phi(LITERAL(true), Var#6) - Var#8<$a> = Phi(Var#4<$a>, Var#3<$a>) + TEMP(#7) = Phi(LITERAL(true), TEMP(#6)) + TEMP(#8 ) = Phi(TEMP(#4 ), TEMP(#3 )) Stmt_JumpIf - cond: Var#7 + cond: TEMP(#7) if: Block#5 else: Block#6 Block#5 Parent: Block#4 - Expr_Assertion<(type(LITERAL('int'))|type(LITERAL('float')))> - expr: Var#8<$a> - result: Var#9<$a> + Expr_Assertion + expr: TEMP(#8 ) + result: TEMP(#9 ) + assert: LITERAL('int')|LITERAL('float') Terminal_Echo - expr: Var#9<$a> + expr: TEMP(#9 ) Stmt_Jump target: Block#7 Block#6 Parent: Block#4 - Expr_Assertion - expr: Var#8<$a> - result: Var#10<$a> + Expr_Assertion + expr: TEMP(#8 ) + result: TEMP(#10 ) + assert: not(LITERAL('int')|LITERAL('float')) Stmt_Jump target: Block#7 Block#7 Parent: Block#5 Parent: Block#6 - Var#11<$a> = Phi(Var#9<$a>, Var#10<$a>) + TEMP(#11 ) = Phi(TEMP(#9 ), TEMP(#10 )) Expr_FuncCall name: LITERAL('var_dump') - args[0]: Var#11<$a> - result: Var#12 + args[0]: TEMP(#11 ) + result: TEMP(#12) Terminal_Return \ No newline at end of file diff --git a/test/code/unary.test b/test/code/unary.test index 3f7a71a..4a2d323 100644 --- a/test/code/unary.test +++ b/test/code/unary.test @@ -8,23 +8,23 @@ $c = ~3; Block#1 Expr_UnaryPlus expr: LITERAL(1) - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$a> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Expr_UnaryMinus expr: LITERAL(2) - result: Var#4 + result: TEMP(#4) Expr_Assign - var: Var#5<$b> - expr: Var#4 - result: Var#6 + var: TEMP(#5 ) + expr: TEMP(#4) + result: TEMP(#6) Expr_BitwiseNot expr: LITERAL(3) - result: Var#7 + result: TEMP(#7) Expr_Assign - var: Var#8<$c> - expr: Var#7 - result: Var#9 + var: TEMP(#8 ) + expr: TEMP(#7) + result: TEMP(#9) Terminal_Return \ No newline at end of file diff --git a/test/code/unionType.test b/test/code/unionType.test index 40bab59..4a53472 100644 --- a/test/code/unionType.test +++ b/test/code/unionType.test @@ -4,7 +4,8 @@ function foo(array|string|null $string) { } ----- Block#1 - Stmt_Function<'foo'> + Stmt_Function + name: foo Terminal_Return Function 'foo': mixed @@ -12,6 +13,6 @@ Block#1 Expr_Param declaredType: array|string|null name: LITERAL('string') - result: Var#1<$string> + result: TEMP(#1 ) Terminal_Return diff --git a/test/code/variablevariable.test b/test/code/variablevariable.test index 6f27d61..a43200b 100755 --- a/test/code/variablevariable.test +++ b/test/code/variablevariable.test @@ -12,94 +12,94 @@ echo $foo->{$arr}[1]; ----- Block#1 Expr_VarVar - var: Var#1<$foo> - result: Var#2 + var: TEMP(#1 ) + result: TEMP(#2) Expr_Assign - var: Var#2 + var: TEMP(#2) expr: LITERAL('bar') - result: Var#3 + result: TEMP(#3) Expr_BinaryOp_Concat - left: Var#4<$foo1> + left: TEMP(#4 ) right: LITERAL('plus') - result: Var#5 + result: TEMP(#5) Expr_BinaryOp_Concat - left: Var#5 - right: Var#6<$foo2> - result: Var#7 + left: TEMP(#5) + right: TEMP(#6 ) + result: TEMP(#7) Expr_VarVar - var: Var#7 - result: Var#8 + var: TEMP(#7) + result: TEMP(#8) Expr_Assign - var: Var#8 + var: TEMP(#8) expr: LITERAL('bar') - result: Var#9 + result: TEMP(#9) Expr_VarVar - var: Var#1<$foo> - result: Var#10 + var: TEMP(#1 ) + result: TEMP(#10) Expr_Assign - var: Var#10 + var: TEMP(#10) expr: LITERAL('bar') - result: Var#11 + result: TEMP(#11) Expr_VarVar - var: Var#12<$a> - result: Var#13 + var: TEMP(#12 ) + result: TEMP(#13) Expr_VarVar - var: Var#13 - result: Var#14 + var: TEMP(#13) + result: TEMP(#14) Expr_VarVar - var: Var#14 - result: Var#15 + var: TEMP(#14) + result: TEMP(#15) Expr_VarVar - var: Var#15 - result: Var#16 + var: TEMP(#15) + result: TEMP(#16) Expr_VarVar - var: Var#16 - result: Var#17 + var: TEMP(#16) + result: TEMP(#17) Expr_VarVar - var: Var#17 - result: Var#18 + var: TEMP(#17) + result: TEMP(#18) Expr_Assign - var: Var#18 + var: TEMP(#18) expr: LITERAL('b') - result: Var#19 + result: TEMP(#19) Expr_ArrayDimFetch - var: Var#20<$baz> + var: TEMP(#20 ) dim: LITERAL(1) - result: Var#21 + result: TEMP(#21) Expr_PropertyFetch - var: Var#1<$foo> - name: Var#21 - result: Var#22 + var: TEMP(#1 ) + name: TEMP(#21) + result: TEMP(#22) Terminal_Echo - expr: Var#22 + expr: TEMP(#22) Expr_BinaryOp_Concat - left: Var#23<$start> - right: Var#24<$end> - result: Var#25 + left: TEMP(#23 ) + right: TEMP(#24 ) + result: TEMP(#25) Expr_PropertyFetch - var: Var#1<$foo> - name: Var#25 - result: Var#26 + var: TEMP(#1 ) + name: TEMP(#25) + result: TEMP(#26) Terminal_Echo - expr: Var#26 + expr: TEMP(#26) Expr_ArrayDimFetch - var: Var#27<$arr> + var: TEMP(#27 ) dim: LITERAL(1) - result: Var#28 + result: TEMP(#28) Expr_PropertyFetch - var: Var#1<$foo> - name: Var#28 - result: Var#29 + var: TEMP(#1 ) + name: TEMP(#28) + result: TEMP(#29) Terminal_Echo - expr: Var#29 + expr: TEMP(#29) Expr_PropertyFetch - var: Var#1<$foo> - name: Var#27<$arr> - result: Var#30 + var: TEMP(#1 ) + name: TEMP(#27 ) + result: TEMP(#30) Expr_ArrayDimFetch - var: Var#30 + var: TEMP(#30) dim: LITERAL(1) - result: Var#31 + result: TEMP(#31) Terminal_Echo - expr: Var#31 + expr: TEMP(#31) Terminal_Return \ No newline at end of file diff --git a/test/code/while.test b/test/code/while.test index d19ca98..f7c0b0a 100644 --- a/test/code/while.test +++ b/test/code/while.test @@ -15,9 +15,9 @@ Block#2 Parent: Block#3 Expr_ConstFetch name: LITERAL('true') - result: Var#1 + result: TEMP(#1) Stmt_JumpIf - cond: Var#1 + cond: TEMP(#1) if: Block#3 else: Block#4 diff --git a/test/code/yeild_from.test b/test/code/yeild_from.test index 67f5b26..a52b7d8 100644 --- a/test/code/yeild_from.test +++ b/test/code/yeild_from.test @@ -12,37 +12,39 @@ function gen_zero_four() { } ----- Block#1 - Stmt_Function<'gen_one_to_three'> - Stmt_Function<'gen_zero_four'> + Stmt_Function + name: gen_one_to_three + Stmt_Function + name: gen_zero_four Terminal_Return Function 'gen_one_to_three': mixed Block#1 Expr_Assign - var: Var#1<$i> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Stmt_Jump target: Block#2 Block#2 Parent: Block#1 Parent: Block#5 - Var#3<$i> = Phi(Var#1<$i>, Var#4<$i>) + TEMP(#3 ) = Phi(TEMP(#1 ), TEMP(#4 )) Expr_BinaryOp_SmallerOrEqual - left: Var#3<$i> + left: TEMP(#3 ) right: LITERAL(3) - result: Var#5 + result: TEMP(#5) Stmt_JumpIf - cond: Var#5 + cond: TEMP(#5) if: Block#3 else: Block#4 Block#3 Parent: Block#2 Expr_Yield - key: Var#3<$i> - result: Var#6 + key: TEMP(#3 ) + result: TEMP(#6) Stmt_Jump target: Block#5 @@ -53,13 +55,13 @@ Block#4 Block#5 Parent: Block#3 Expr_BinaryOp_Plus - left: Var#3<$i> + left: TEMP(#3 ) right: LITERAL(1) - result: Var#7 + result: TEMP(#7) Expr_Assign - var: Var#4<$i> - expr: Var#7 - result: Var#8 + var: TEMP(#4 ) + expr: TEMP(#7) + result: TEMP(#8) Stmt_Jump target: Block#2 @@ -67,14 +69,14 @@ Function 'gen_zero_four': mixed Block#1 Expr_Yield key: LITERAL(0) - result: Var#1 + result: TEMP(#1) Expr_FuncCall name: LITERAL('gen_one_to_three') - result: Var#2 + result: TEMP(#2) Expr_YieldFrom - expr: Var#2 - result: Var#3 + expr: TEMP(#2) + result: TEMP(#3) Expr_Yield key: LITERAL(4) - result: Var#4 + result: TEMP(#4) Terminal_Return diff --git a/test/code/yield.test b/test/code/yield.test index 854548c..f9eebf2 100644 --- a/test/code/yield.test +++ b/test/code/yield.test @@ -11,16 +11,17 @@ foreach ($generator as $value) { } ----- Block#1 - Stmt_Function<'gen_one_to_three'> + Stmt_Function + name: gen_one_to_three Expr_FuncCall name: LITERAL('gen_one_to_three') - result: Var#1 + result: TEMP(#1) Expr_Assign - var: Var#2<$generator> - expr: Var#1 - result: Var#3 + var: TEMP(#2 ) + expr: TEMP(#1) + result: TEMP(#3) Iterator_Reset - var: Var#2<$generator> + var: TEMP(#2 ) Stmt_Jump target: Block#2 @@ -28,29 +29,29 @@ Block#2 Parent: Block#1 Parent: Block#3 Iterator_Valid - var: Var#2<$generator> - result: Var#4 + var: TEMP(#2 ) + result: TEMP(#4) Stmt_JumpIf - cond: Var#4 + cond: TEMP(#4) if: Block#3 else: Block#4 Block#3 Parent: Block#2 Iterator_Value - var: Var#2<$generator> - result: Var#5 + var: TEMP(#2 ) + result: TEMP(#5) Expr_Assign - var: Var#6<$value> - expr: Var#5 - result: Var#7 + var: TEMP(#6 ) + expr: TEMP(#5) + result: TEMP(#7) Expr_ConcatList - list[0]: Var#6<$value> + list[0]: TEMP(#6 ) list[1]: LITERAL(' ') - result: Var#8 + result: TEMP(#8) Terminal_Echo - expr: Var#8 + expr: TEMP(#8) Stmt_Jump target: Block#2 @@ -61,30 +62,30 @@ Block#4 Function 'gen_one_to_three': mixed Block#1 Expr_Assign - var: Var#1<$i> + var: TEMP(#1 ) expr: LITERAL(1) - result: Var#2 + result: TEMP(#2) Stmt_Jump target: Block#2 Block#2 Parent: Block#1 Parent: Block#5 - Var#3<$i> = Phi(Var#1<$i>, Var#4<$i>) + TEMP(#3 ) = Phi(TEMP(#1 ), TEMP(#4 )) Expr_BinaryOp_SmallerOrEqual - left: Var#3<$i> + left: TEMP(#3 ) right: LITERAL(3) - result: Var#5 + result: TEMP(#5) Stmt_JumpIf - cond: Var#5 + cond: TEMP(#5) if: Block#3 else: Block#4 Block#3 Parent: Block#2 Expr_Yield - key: Var#3<$i> - result: Var#6 + key: TEMP(#3 ) + result: TEMP(#6) Stmt_Jump target: Block#5 @@ -95,12 +96,12 @@ Block#4 Block#5 Parent: Block#3 Expr_BinaryOp_Plus - left: Var#3<$i> + left: TEMP(#3 ) right: LITERAL(1) - result: Var#7 + result: TEMP(#7) Expr_Assign - var: Var#4<$i> - expr: Var#7 - result: Var#8 + var: TEMP(#4 ) + expr: TEMP(#7) + result: TEMP(#8) Stmt_Jump target: Block#2 \ No newline at end of file From be735066dcc9f66858fea858c9bc2a35c663cd0b Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Mon, 1 Sep 2025 08:52:50 -0400 Subject: [PATCH 4/5] Fix GraphViz printer --- lib/PHPCfg/Printer/GraphViz.php | 48 ++------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/lib/PHPCfg/Printer/GraphViz.php b/lib/PHPCfg/Printer/GraphViz.php index 9e0b125..e239ff6 100644 --- a/lib/PHPCfg/Printer/GraphViz.php +++ b/lib/PHPCfg/Printer/GraphViz.php @@ -12,7 +12,7 @@ namespace PHPCfg\Printer; use PHPCfg\Func; -use PHPCfg\Printer; +use PHPCfg\Printer\Printer; use PHPCfg\Script; use phpDocumentor\GraphViz\Edge; use phpDocumentor\GraphViz\Graph; @@ -46,7 +46,7 @@ public function printScript(Script $script): string $this->printFuncWithHeader($func, $graph, 'func_' . ++$i . '_'); } - return (string) $graph; + return (string) $graph . "\n"; } public function printFunc(Func $func): string @@ -57,50 +57,6 @@ public function printFunc(Func $func): string return (string) $graph; } - public function printVars(Func $func): string - { - $graph = Graph::create('vars'); - foreach ($this->options['graph'] as $name => $value) { - $setter = 'set' . $name; - $graph->{$setter}($value); - } - $rendered = $this->render($func->cfg); - $nodes = new SplObjectStorage(); - foreach ($rendered['varIds'] as $var) { - if (empty($var->ops) && empty($var->usages)) { - continue; - } - $id = $rendered['varIds'][$var]; - $output = $this->renderOperand($var); - $nodes[$var] = $this->createNode('var_' . $id, $output); - $graph->setNode($nodes[$var]); - } - foreach ($rendered['varIds'] as $var) { - foreach ($var->ops as $write) { - $b = $write->getAttribute('block'); - foreach ($write->getVariableNames() as $varName => $vs) { - if (! is_array($vs)) { - $vs = [$vs]; - } - foreach ($vs as $v) { - if (! $v || $write->isWriteVariable($varName) || ! $nodes->contains($v)) { - continue; - } - $edge = $this->createEdge($nodes[$v], $nodes[$var]); - if ($b) { - $edge->setlabel('Block<' . $rendered['blockIds'][$b] . '>' . $write->getType() . ':' . $varName); - } else { - $edge->setlabel($write->getType() . ':' . $varName); - } - $graph->link($edge); - } - } - } - } - - return (string) $graph; - } - protected function printFuncWithHeader(Func $func, Graph $graph, $prefix): void { $name = $func->getScopedName(); From 413c5567b724de4933944911d2764c4296d03b15 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Mon, 1 Sep 2025 08:54:00 -0400 Subject: [PATCH 5/5] Fix styles --- lib/PHPCfg/Printer/GraphViz.php | 1 - lib/PHPCfg/Printer/Printer.php | 18 ++++++------------ lib/PHPCfg/Printer/Renderer.php | 7 ++----- lib/PHPCfg/Printer/Renderer/GenericOp.php | 14 +++++--------- lib/PHPCfg/Printer/Renderer/Op/Assertion.php | 15 ++++----------- lib/PHPCfg/Printer/Renderer/Op/Include_.php | 12 ++---------- lib/PHPCfg/Printer/Renderer/Op/TraitUse.php | 12 ++---------- .../Printer/Renderer/Operand/Literal.php | 12 ++++-------- .../Printer/Renderer/Operand/Temporary.php | 12 ++++-------- .../Printer/Renderer/Operand/Variable.php | 16 ++++++---------- 10 files changed, 35 insertions(+), 84 deletions(-) diff --git a/lib/PHPCfg/Printer/GraphViz.php b/lib/PHPCfg/Printer/GraphViz.php index e239ff6..e9e15b8 100644 --- a/lib/PHPCfg/Printer/GraphViz.php +++ b/lib/PHPCfg/Printer/GraphViz.php @@ -12,7 +12,6 @@ namespace PHPCfg\Printer; use PHPCfg\Func; -use PHPCfg\Printer\Printer; use PHPCfg\Script; use phpDocumentor\GraphViz\Edge; use phpDocumentor\GraphViz\Graph; diff --git a/lib/PHPCfg/Printer/Printer.php b/lib/PHPCfg/Printer/Printer.php index 8e09220..53f838c 100755 --- a/lib/PHPCfg/Printer/Printer.php +++ b/lib/PHPCfg/Printer/Printer.php @@ -12,26 +12,20 @@ namespace PHPCfg\Printer; use LogicException; -use PHPCfg\Operand\BoundVariable; -use PHPCfg\Operand\Literal; -use PHPCfg\Operand\NullOperand; -use PHPCfg\Operand\Temporary; -use PHPCfg\Operand\Variable; -use SplObjectStorage; -use SplQueue; -use PHPCfg\Script; use PHPCfg\Block; use PHPCfg\Func; use PHPCfg\Op; use PHPCfg\Operand; -use PHPCfg\Assertion; -use RecursiveIteratorIterator; +use PHPCfg\Script; use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use SplObjectStorage; +use SplQueue; abstract class Printer { - const MODE_DEFAULT = 0b00000; - const MODE_RENDER_ATTRIBUTES = 0b00001; + public const MODE_DEFAULT = 0b00000; + public const MODE_RENDER_ATTRIBUTES = 0b00001; private SplQueue $blockQueue; diff --git a/lib/PHPCfg/Printer/Renderer.php b/lib/PHPCfg/Printer/Renderer.php index 20d9377..3f58b08 100644 --- a/lib/PHPCfg/Printer/Renderer.php +++ b/lib/PHPCfg/Printer/Renderer.php @@ -11,11 +11,8 @@ namespace PHPCfg\Printer; -use PHPCfg\Func; -use PHPCfg\Script; use PHPCfg\Op; use PHPCfg\Operand; -use PHPCfg\Block; interface Renderer { @@ -24,5 +21,5 @@ public function reset(): void; public function renderOp(Op $op): ?array; public function renderOperand(Operand $operand): ?array; - -} \ No newline at end of file + +} diff --git a/lib/PHPCfg/Printer/Renderer/GenericOp.php b/lib/PHPCfg/Printer/Renderer/GenericOp.php index e626af1..df97452 100644 --- a/lib/PHPCfg/Printer/Renderer/GenericOp.php +++ b/lib/PHPCfg/Printer/Renderer/GenericOp.php @@ -11,17 +11,13 @@ namespace PHPCfg\Printer\Renderer; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; use PHPCfg\Op; use PHPCfg\Operand; -use PHPCfg\Block; +use PHPCfg\Printer\Printer; use PHPCfg\Printer\Renderer; class GenericOp implements Renderer { - protected Printer $printer; public function __construct(Printer $printer) @@ -38,7 +34,7 @@ public function renderOp(Op $op): ?array 'types' => [], 'vars' => [], 'attributes' => $this->renderAttributes($op->getAttributes()), - 'childblocks' => [], + 'childblocks' => [], ]; if ($op instanceof Op\CallableOp) { @@ -99,7 +95,7 @@ public function renderOp(Op $op): ?array $result['attrGroups'] = $this->renderAttrGroups($op); } - + return $result; } @@ -110,7 +106,7 @@ public function renderOperand(Operand $operand): ?array } - + protected function renderAttributes(array $attributes): array { if (!$this->printer->renderAttributes) { @@ -183,4 +179,4 @@ protected function renderFlags(Op\Stmt $stmt): string return $result; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Printer/Renderer/Op/Assertion.php b/lib/PHPCfg/Printer/Renderer/Op/Assertion.php index b11b5c8..1fbfb58 100644 --- a/lib/PHPCfg/Printer/Renderer/Op/Assertion.php +++ b/lib/PHPCfg/Printer/Renderer/Op/Assertion.php @@ -11,16 +11,9 @@ namespace PHPCfg\Printer\Renderer\Op; - -use PHPCfg\Printer\Renderer\GenericOp; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; -use PHPCfg\Op; -use PHPCfg\Operand; -use PHPCfg\Block; -use PHPCfg\Printer\Renderer; use PHPCfg\Assertion as CoreAssertion; +use PHPCfg\Op; +use PHPCfg\Printer\Renderer\GenericOp; class Assertion extends GenericOp { @@ -37,7 +30,7 @@ public function renderOp(Op $op): ?array protected function renderAssertion(CoreAssertion $assert): string { - + if (is_array($assert->value)) { $combinator = $assert->mode === CoreAssertion::MODE_UNION ? '|' : '&'; @@ -52,4 +45,4 @@ protected function renderAssertion(CoreAssertion $assert): string return "$kind({$ret})"; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Printer/Renderer/Op/Include_.php b/lib/PHPCfg/Printer/Renderer/Op/Include_.php index 6f85863..2bc7e8f 100644 --- a/lib/PHPCfg/Printer/Renderer/Op/Include_.php +++ b/lib/PHPCfg/Printer/Renderer/Op/Include_.php @@ -11,16 +11,8 @@ namespace PHPCfg\Printer\Renderer\Op; - -use PHPCfg\Printer\Renderer\GenericOp; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; use PHPCfg\Op; -use PHPCfg\Operand; -use PHPCfg\Block; -use PHPCfg\Printer\Renderer; -use PHPCfg\Assertion as CoreAssertion; +use PHPCfg\Printer\Renderer\GenericOp; class Include_ extends GenericOp { @@ -50,4 +42,4 @@ public function renderOp(Op $op): ?array return $result; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php b/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php index 9fcf61b..0980cd3 100644 --- a/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php +++ b/lib/PHPCfg/Printer/Renderer/Op/TraitUse.php @@ -11,16 +11,8 @@ namespace PHPCfg\Printer\Renderer\Op; - -use PHPCfg\Printer\Renderer\GenericOp; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; use PHPCfg\Op; -use PHPCfg\Operand; -use PHPCfg\Block; -use PHPCfg\Printer\Renderer; -use PHPCfg\Assertion as CoreAssertion; +use PHPCfg\Printer\Renderer\GenericOp; class TraitUse extends GenericOp { @@ -73,4 +65,4 @@ public function renderOp(Op $op): ?array return $result; } -} \ No newline at end of file +} diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Literal.php b/lib/PHPCfg/Printer/Renderer/Operand/Literal.php index 6471e71..59e3862 100644 --- a/lib/PHPCfg/Printer/Renderer/Operand/Literal.php +++ b/lib/PHPCfg/Printer/Renderer/Operand/Literal.php @@ -11,17 +11,13 @@ namespace PHPCfg\Printer\Renderer\Operand; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; use PHPCfg\Op; use PHPCfg\Operand; -use PHPCfg\Block; +use PHPCfg\Printer\Printer; use PHPCfg\Printer\Renderer; class Literal implements Renderer { - protected Printer $printer; public function __construct(Printer $printer) @@ -52,8 +48,8 @@ public function renderOperand(Operand $operand): ?array return [ "kind" => "LITERAL", "type" => $operand->type ? "<{$operand->type}>" : "", - "value" => var_export($operand->value, true) + "value" => var_export($operand->value, true), ]; } - -} \ No newline at end of file + +} diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php b/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php index 3fef731..d0f43d5 100644 --- a/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php +++ b/lib/PHPCfg/Printer/Renderer/Operand/Temporary.php @@ -11,18 +11,14 @@ namespace PHPCfg\Printer\Renderer\Operand; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; use PHPCfg\Op; use PHPCfg\Operand; -use PHPCfg\Block; +use PHPCfg\Printer\Printer; use PHPCfg\Printer\Renderer; use SplObjectStorage; class Temporary implements Renderer { - protected Printer $printer; protected SplObjectStorage $varIds; @@ -35,7 +31,7 @@ public function __construct(Printer $printer) public function reset(): void { - $this->varIds = new SplObjectStorage; + $this->varIds = new SplObjectStorage(); } public function renderOp(Op $op): ?array @@ -64,5 +60,5 @@ protected function getVarId(Operand $var) return $this->varIds[$var] = $this->varIds->count() + 1; } - -} \ No newline at end of file + +} diff --git a/lib/PHPCfg/Printer/Renderer/Operand/Variable.php b/lib/PHPCfg/Printer/Renderer/Operand/Variable.php index 6165ddb..073e091 100644 --- a/lib/PHPCfg/Printer/Renderer/Operand/Variable.php +++ b/lib/PHPCfg/Printer/Renderer/Operand/Variable.php @@ -11,17 +11,14 @@ namespace PHPCfg\Printer\Renderer\Operand; -use PHPCfg\Func; -use PHPCfg\Printer\Printer; -use PHPCfg\Script; +use LogicException; use PHPCfg\Op; use PHPCfg\Operand; -use PHPCfg\Block; +use PHPCfg\Printer\Printer; use PHPCfg\Printer\Renderer; class Variable implements Renderer { - protected Printer $printer; public function __construct(Printer $printer) @@ -29,8 +26,7 @@ public function __construct(Printer $printer) $this->printer = $printer; } - public function reset(): void - {} + public function reset(): void {} public function renderOp(Op $op): ?array { @@ -64,7 +60,7 @@ public function renderOperand(Operand $operand): ?array $prefix = "static $prefix"; break; default: - throw new \LogicException('Unknown bound variable scope'); + throw new LogicException('Unknown bound variable scope'); } } @@ -74,5 +70,5 @@ public function renderOperand(Operand $operand): ?array "name" => $prefix . $operand->name->value, ]; } - -} \ No newline at end of file + +}