From d99413721294cd43f3bfa3ab1ae20188d406e796 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 21:33:02 +0000 Subject: [PATCH 1/8] #137 - Add return type `false` --- parser/parser.h | 4 ++++ parser/scanner.h | 1 + 2 files changed, 5 insertions(+) diff --git a/parser/parser.h b/parser/parser.h index 90479487..9c3426c6 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -598,6 +598,10 @@ static void xx_ret_type(zval *ret, int type) parser_get_string(ret, "this"); return; + case XX_T_TYPE_FALSE: + parser_get_string(ret, "false"); + return; + default: fprintf(stderr, "unknown type?\n"); } diff --git a/parser/scanner.h b/parser/scanner.h index 8ccb6685..f05d2a3b 100644 --- a/parser/scanner.h +++ b/parser/scanner.h @@ -47,6 +47,7 @@ #define XX_T_TYPE_NULL 334 #define XX_T_TYPE_THIS 335 #define XX_T_TYPE_MIXED 336 +#define XX_T_TYPE_FALSE 337 #define XX_T_NAMESPACE 350 #define XX_T_CLASS 351 From 49a33393ad4fd5f50d8830bd36dbfb69adeae437 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:31:19 +0000 Subject: [PATCH 2/8] #137 - Add support of single return type `false` --- parser/zephir.lemon | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/parser/zephir.lemon b/parser/zephir.lemon index 4315c280..1d7ecd8d 100644 --- a/parser/zephir.lemon +++ b/parser/zephir.lemon @@ -702,6 +702,14 @@ xx_method_return_type_item(R) ::= THIS . { } } +xx_method_return_type_item(R) ::= FALSE . { + { + zval type; + xx_ret_type(&type, XX_T_TYPE_FALSE); + xx_ret_return_type_item(&R, &type, NULL, 0, 0, status->scanner_state); + } +} + xx_method_return_type_item(R) ::= xx_parameter_type(T) NOT . { xx_ret_return_type_item(&R, &T, NULL, 1, 0, status->scanner_state); } @@ -950,6 +958,10 @@ xx_parameter_type(R) ::= TYPE_MIXED . { xx_ret_type(&R, XX_TYPE_MIXED); } +xx_parameter_type(R) ::= TYPE_FALSE . { + xx_ret_type(&R, XX_TYPE_FALSE); +} + xx_parameter_type(R) ::= TYPE_OBJECT . { xx_ret_type(&R, XX_TYPE_OBJECT); } From faae099e637c8d3fa1e1b63d7b2309840fd90bf1 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:31:27 +0000 Subject: [PATCH 3/8] #137 - Add test case --- tests/functions/return-types/false.phpt | 175 ++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 tests/functions/return-types/false.phpt diff --git a/tests/functions/return-types/false.phpt b/tests/functions/return-types/false.phpt new file mode 100644 index 00000000..9c000195 --- /dev/null +++ b/tests/functions/return-types/false.phpt @@ -0,0 +1,175 @@ +--TEST-- +Function definition with `false` return type +--SKIPIF-- + +--FILE-- + false { return false; } + +function unionReturn() -> int | false { return 1; } +ZEP; + +$ir = zephir_parse_file($code, '(eval code)'); +var_dump($ir); +?> +--EXPECT-- +array(2) { + [0]=> + array(7) { + ["type"]=> + string(8) "function" + ["name"]=> + string(12) "singleReturn" + ["statements"]=> + array(1) { + [0]=> + array(5) { + ["type"]=> + string(6) "return" + ["expr"]=> + array(5) { + ["type"]=> + string(4) "bool" + ["value"]=> + string(5) "false" + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(49) + } + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(51) + } + } + ["return-type"]=> + array(6) { + ["type"]=> + string(11) "return-type" + ["list"]=> + array(1) { + [0]=> + array(6) { + ["type"]=> + string(21) "return-type-parameter" + ["data-type"]=> + string(5) "false" + ["mandatory"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(35) + } + } + ["void"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(35) + } + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(8) + } + [1]=> + array(7) { + ["type"]=> + string(8) "function" + ["name"]=> + string(11) "unionReturn" + ["statements"]=> + array(1) { + [0]=> + array(5) { + ["type"]=> + string(6) "return" + ["expr"]=> + array(5) { + ["type"]=> + string(3) "int" + ["value"]=> + string(1) "1" + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(49) + } + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(51) + } + } + ["return-type"]=> + array(6) { + ["type"]=> + string(11) "return-type" + ["list"]=> + array(2) { + [0]=> + array(6) { + ["type"]=> + string(21) "return-type-parameter" + ["data-type"]=> + string(3) "int" + ["mandatory"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(31) + } + [1]=> + array(6) { + ["type"]=> + string(21) "return-type-parameter" + ["data-type"]=> + string(5) "false" + ["mandatory"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(39) + } + } + ["void"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(39) + } + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(3) + ["char"]=> + int(8) + } +} From 07954ac088f6379fd50cdbdfce71816ad18f45a8 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:32:01 +0000 Subject: [PATCH 4/8] #137 - Correct tests names --- tests/functions/return-types/int.phpt | 2 +- tests/functions/return-types/mixed.phpt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functions/return-types/int.phpt b/tests/functions/return-types/int.phpt index 38a6c8a9..85823992 100644 --- a/tests/functions/return-types/int.phpt +++ b/tests/functions/return-types/int.phpt @@ -1,5 +1,5 @@ --TEST-- -Function definition with mandatory return type +Function definition with `int` return type --SKIPIF-- --FILE-- diff --git a/tests/functions/return-types/mixed.phpt b/tests/functions/return-types/mixed.phpt index d85bad8d..a7f19dce 100644 --- a/tests/functions/return-types/mixed.phpt +++ b/tests/functions/return-types/mixed.phpt @@ -1,5 +1,5 @@ --TEST-- -Function definition with void +Function definition with `mixed` return type --SKIPIF-- --FILE-- From 1d07151d8aadd1057af35c764408a1225a3d4476 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:32:37 +0000 Subject: [PATCH 5/8] #137 - Add `false.phpt` into package.xml --- package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/package.xml b/package.xml index 68a2cc8c..4309e48c 100644 --- a/package.xml +++ b/package.xml @@ -107,6 +107,7 @@ + From f83c826dee6ecdd0ffb12b8ac9c3a6454ea317f5 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:33:11 +0000 Subject: [PATCH 6/8] #137 - Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ae15de42..585bf452 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.lo *.la *.profraw +*.dep .deps .libs From 44ecbbbc358a014a9ff4d834e3d1d7a11ae7af0d Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:35:29 +0000 Subject: [PATCH 7/8] #137 - Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e2354d8..c4eac242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added - xxxx-xx-xx +- Added support for `false` return type [#137](https://github.com/phalcon/php-zephir-parser/issues/137) ## [1.4.2] - 2021-12-11 ### Added From c0f2a1505ed99409238fd31ba3a457995fd863b7 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 7 Feb 2022 22:37:55 +0000 Subject: [PATCH 8/8] #137 - Add test case for `float` return type --- package.xml | 1 + tests/functions/return-types/float.phpt | 60 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/functions/return-types/float.phpt diff --git a/package.xml b/package.xml index 4309e48c..9486ab08 100644 --- a/package.xml +++ b/package.xml @@ -108,6 +108,7 @@ + diff --git a/tests/functions/return-types/float.phpt b/tests/functions/return-types/float.phpt new file mode 100644 index 00000000..f7ad09f3 --- /dev/null +++ b/tests/functions/return-types/float.phpt @@ -0,0 +1,60 @@ +--TEST-- +Function definition with `float` return type +--SKIPIF-- + +--FILE-- + float { } +ZEP; + +$ir = zephir_parse_file($code, '(eval code)'); +var_dump($ir); +?> +--EXPECT-- +array(1) { + [0]=> + array(6) { + ["type"]=> + string(8) "function" + ["name"]=> + string(4) "test" + ["return-type"]=> + array(6) { + ["type"]=> + string(11) "return-type" + ["list"]=> + array(1) { + [0]=> + array(6) { + ["type"]=> + string(21) "return-type-parameter" + ["data-type"]=> + string(6) "double" + ["mandatory"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(27) + } + } + ["void"]=> + int(0) + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(27) + } + ["file"]=> + string(11) "(eval code)" + ["line"]=> + int(1) + ["char"]=> + int(9) + } +}