From 6f90b5d2228a1798ffe9eb7c8846a75e7c66cdb6 Mon Sep 17 00:00:00 2001 From: Adam Pippin Date: Fri, 19 Feb 2021 12:33:27 -0800 Subject: [PATCH] Bugfix: Fix processing order for functions -- deepest nodes first --- app/Cfnpp/Compiler.php | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/app/Cfnpp/Compiler.php b/app/Cfnpp/Compiler.php index 2e680eb..558b7f9 100644 --- a/app/Cfnpp/Compiler.php +++ b/app/Cfnpp/Compiler.php @@ -123,15 +123,6 @@ class Compiler implements \App\Engine\ICompile $this->pass_2($document, $options); return $this->document; - // Process each passed document - /* - foreach ($documents as $next_document) - { - $this->runMergeFunctions($document, $next_document); - $this->merge($document, $next_document); - $this->runFunctions($document); - } - */ } /** @@ -302,14 +293,12 @@ class Compiler implements \App\Engine\ICompile { $variables[] = $node->getValue(); } - /* - // TODO: Reimplement elseif ($node instanceof NodeFunctionValue && $node->getName() == 'expr') { $expression = new \App\Cfnpp\Expression\Expression($node->getValue()); $variables = array_merge($variables, $expression->getReferencedVariables()); - }*/ + } } return $variables; @@ -454,6 +443,12 @@ class Compiler implements \App\Engine\ICompile */ protected function runFunctions(Node $node): void { + $children = $node->getChildren(); + foreach ($children as $child) + { + $this->runFunctions($child); + } + if ($node->isFunctionParent() && isset($this->functions[$node[0]->getName()])) { $function_node = $node[0]; @@ -471,12 +466,6 @@ class Compiler implements \App\Engine\ICompile return; } } - - $children = $node->getChildren(); - foreach ($children as $child) - { - $this->runFunctions($child); - } } /**