From d4108b7161e2e0f1b79b61fdb7d2fef7bb4fc72e Mon Sep 17 00:00:00 2001 From: eric-therond Date: Thu, 14 Apr 2022 10:07:48 +0200 Subject: [PATCH 1/2] print include type --- lib/PHPCfg/Printer.php | 3 +++ test/code/include.test | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 test/code/include.test diff --git a/lib/PHPCfg/Printer.php b/lib/PHPCfg/Printer.php index fcd4fe7..528bd88 100755 --- a/lib/PHPCfg/Printer.php +++ b/lib/PHPCfg/Printer.php @@ -129,6 +129,9 @@ protected function renderOp(Op $op) if ($op instanceof Op\Expr\Param) { $result .= "\n declaredType: " . $this->indent($this->renderType($op->declaredType)); } + if ($op instanceof Op\Expr\Include_) { + $result .= "\n type: " . $op->type; + } foreach ($op->getVariableNames() as $varName) { $vars = $op->{$varName}; diff --git a/test/code/include.test b/test/code/include.test new file mode 100755 index 0000000..0b01de3 --- /dev/null +++ b/test/code/include.test @@ -0,0 +1,26 @@ + + result: Var#2 + Expr_Include + type: 2 + expr: Var#1<$foo> + result: Var#3 + Expr_Include + type: 3 + expr: Var#1<$foo> + result: Var#4 + Expr_Include + type: 4 + expr: Var#1<$foo> + result: Var#5 + Terminal_Return + + From 7843cf82fe6176a2a48799cd27b95b7de9e3a4b2 Mon Sep 17 00:00:00 2001 From: eric-therond Date: Thu, 14 Apr 2022 13:02:18 +0200 Subject: [PATCH 2/2] use friendly strings --- lib/PHPCfg/Printer.php | 18 +++++++++++++++++- test/code/include.test | 8 ++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/PHPCfg/Printer.php b/lib/PHPCfg/Printer.php index 528bd88..100c743 100755 --- a/lib/PHPCfg/Printer.php +++ b/lib/PHPCfg/Printer.php @@ -130,7 +130,7 @@ protected function renderOp(Op $op) $result .= "\n declaredType: " . $this->indent($this->renderType($op->declaredType)); } if ($op instanceof Op\Expr\Include_) { - $result .= "\n type: " . $op->type; + $result .= "\n type: " . $this->indent($this->renderIncludeType($op->type)); } foreach ($op->getVariableNames() as $varName) { @@ -294,6 +294,22 @@ protected function renderType(?Op\Type $type): string throw new \LogicException("Unknown type rendering: " . get_class($type)); } + protected function renderIncludeType(int $type): 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 = ''; diff --git a/test/code/include.test b/test/code/include.test index 0b01de3..99b13f6 100755 --- a/test/code/include.test +++ b/test/code/include.test @@ -6,19 +6,19 @@ require_once($foo); ----- Block#1 Expr_Include - type: 1 + type: include expr: Var#1<$foo> result: Var#2 Expr_Include - type: 2 + type: include_once expr: Var#1<$foo> result: Var#3 Expr_Include - type: 3 + type: require expr: Var#1<$foo> result: Var#4 Expr_Include - type: 4 + type: require_once expr: Var#1<$foo> result: Var#5 Terminal_Return