From 2de39d6d9f2ccdc371d86ec25e25e7e59869d0ea Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 12 Feb 2023 20:11:19 +0100 Subject: [PATCH 1/2] Implement unchecked parameter types See https://github.com/xp-framework/compiler/issues/119#issuecomment-1427022356 --- src/main/php/lang/ast/syntax/PHP.class.php | 8 ++++- .../php/lang/ast/types/IsUnchecked.class.php | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 src/main/php/lang/ast/types/IsUnchecked.class.php diff --git a/src/main/php/lang/ast/syntax/PHP.class.php b/src/main/php/lang/ast/syntax/PHP.class.php index 4eff29c..7512274 100755 --- a/src/main/php/lang/ast/syntax/PHP.class.php +++ b/src/main/php/lang/ast/syntax/PHP.class.php @@ -71,6 +71,7 @@ IsLiteral, IsMap, IsNullable, + IsUnchecked, IsUnion, IsValue }; @@ -1338,7 +1339,12 @@ private function parameters($parse) { $promote= null; } - $type= $this->type($parse); + if ('@' === $parse->token->value) { + $parse->forward(); + $type= new IsUnchecked($this->type($parse)); + } else { + $type= $this->type($parse); + } if ('...' !== $parse->token->value) { $variadic= false; diff --git a/src/main/php/lang/ast/types/IsUnchecked.class.php b/src/main/php/lang/ast/types/IsUnchecked.class.php new file mode 100755 index 0000000..eb253db --- /dev/null +++ b/src/main/php/lang/ast/types/IsUnchecked.class.php @@ -0,0 +1,32 @@ +element= $element; + } + + /** @return string */ + public function literal() { return $this->element->literal(); } + + /** @return string */ + public function name() { return $this->element->name(); } + + /** + * Compare + * + * @param var $value + * @return int + */ + public function compareTo($value) { + return $value instanceof self ? $this->element->compareTo($value->element) : 1; + } +} \ No newline at end of file From f73f51b4154ca849467806134492a93cace9e85f Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 12 Feb 2023 20:17:40 +0100 Subject: [PATCH 2/2] Move unchecked parsing to type() --- src/main/php/lang/ast/syntax/PHP.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/php/lang/ast/syntax/PHP.class.php b/src/main/php/lang/ast/syntax/PHP.class.php index 7512274..aacc31d 100755 --- a/src/main/php/lang/ast/syntax/PHP.class.php +++ b/src/main/php/lang/ast/syntax/PHP.class.php @@ -1116,6 +1116,11 @@ public function list($parse, $end, $kind) { } public function type($parse, $optional= true) { + if ('@' === $parse->token->value) { + $parse->forward(); + return new IsUnchecked($this->type($parse, false)); + } + $t= $this->type0($parse, $optional); // Check for union and intersection types (which cannot be mixed @@ -1339,12 +1344,7 @@ private function parameters($parse) { $promote= null; } - if ('@' === $parse->token->value) { - $parse->forward(); - $type= new IsUnchecked($this->type($parse)); - } else { - $type= $this->type($parse); - } + $type= $this->type($parse); if ('...' !== $parse->token->value) { $variadic= false;