Skip to content

Commit 67224fa

Browse files
authored
Merge pull request #139 from zephir-lang/development
2 parents 5b40fb0 + 796ccb0 commit 67224fa

12 files changed

+272
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.lo
1010
*.la
1111
*.profraw
12+
*.dep
1213

1314
.deps
1415
.libs

CHANGELOG.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [Unreleased]
7+
## [Unreleased] - xxxx-xx-xx
8+
9+
10+
## [1.5.0] - 2022-02-12
11+
### Added
12+
- Added support for `false` return type [#137](https://github.com/phalcon/php-zephir-parser/issues/137)
813

914
## [1.4.2] - 2021-12-11
1015
### Added
@@ -181,7 +186,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
181186
### Added
182187
- Initial stable release
183188

184-
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.2...HEAD
189+
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.5.0...HEAD
190+
[1.5.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.2...v1.5.0
185191
[1.4.2]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.1...v1.4.2
186192
[1.4.1]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.0...v1.4.1
187193
[1.4.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.8...v1.4.0

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.2
1+
1.5.0

package.xml

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
<date>2021-09-18</date>
1616
<time>15:00:00</time>
1717
<version>
18-
<release>1.4.2</release>
19-
<api>1.4.2</api>
18+
<release>1.5.0</release>
19+
<api>1.5.0</api>
2020
</version>
2121
<stability>
2222
<release>stable</release>
2323
<api>stable</api>
2424
</stability>
2525
<license uri="https://github.com/zephir-lang/php-zephir-parser/blob/development/LICENSE">MIT</license>
2626
<notes>
27-
Sat, Dec 1, 2021 - Zephir Parser 1.4.2
27+
Sat, Feb 12, 2022 - Zephir Parser 1.5.0
2828

29-
= Changes:
29+
= Added:
3030

31-
- Enabled support of PHP8.1
31+
- Added support of `false` return type
3232
</notes>
3333
<contents>
3434
<dir name="/">
@@ -107,6 +107,8 @@
107107
</dir>
108108

109109
<dir name="return-types">
110+
<file name="false.phpt" role="test"/>
111+
<file name="float.phpt" role="test"/>
110112
<file name="int.phpt" role="test"/>
111113
<file name="mixed.phpt" role="test"/>
112114
</dir>

parser/parser.h

+4
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ static void xx_ret_type(zval *ret, int type)
598598
parser_get_string(ret, "this");
599599
return;
600600

601+
case XX_T_TYPE_FALSE:
602+
parser_get_string(ret, "false");
603+
return;
604+
601605
default:
602606
fprintf(stderr, "unknown type?\n");
603607
}

parser/scanner.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define XX_T_TYPE_NULL 334
4848
#define XX_T_TYPE_THIS 335
4949
#define XX_T_TYPE_MIXED 336
50+
#define XX_T_TYPE_FALSE 337
5051

5152
#define XX_T_NAMESPACE 350
5253
#define XX_T_CLASS 351

parser/zephir.lemon

+12
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,14 @@ xx_method_return_type_item(R) ::= THIS . {
702702
}
703703
}
704704

705+
xx_method_return_type_item(R) ::= FALSE . {
706+
{
707+
zval type;
708+
xx_ret_type(&type, XX_T_TYPE_FALSE);
709+
xx_ret_return_type_item(&R, &type, NULL, 0, 0, status->scanner_state);
710+
}
711+
}
712+
705713
xx_method_return_type_item(R) ::= xx_parameter_type(T) NOT . {
706714
xx_ret_return_type_item(&R, &T, NULL, 1, 0, status->scanner_state);
707715
}
@@ -950,6 +958,10 @@ xx_parameter_type(R) ::= TYPE_MIXED . {
950958
xx_ret_type(&R, XX_TYPE_MIXED);
951959
}
952960

961+
xx_parameter_type(R) ::= TYPE_FALSE . {
962+
xx_ret_type(&R, XX_TYPE_FALSE);
963+
}
964+
953965
xx_parameter_type(R) ::= TYPE_OBJECT . {
954966
xx_ret_type(&R, XX_TYPE_OBJECT);
955967
}
+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
--TEST--
2+
Function definition with `false` return type
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$code =<<<ZEP
8+
function singleReturn() -> false { return false; }
9+
10+
function unionReturn() -> int | false { return 1; }
11+
ZEP;
12+
13+
$ir = zephir_parse_file($code, '(eval code)');
14+
var_dump($ir);
15+
?>
16+
--EXPECT--
17+
array(2) {
18+
[0]=>
19+
array(7) {
20+
["type"]=>
21+
string(8) "function"
22+
["name"]=>
23+
string(12) "singleReturn"
24+
["statements"]=>
25+
array(1) {
26+
[0]=>
27+
array(5) {
28+
["type"]=>
29+
string(6) "return"
30+
["expr"]=>
31+
array(5) {
32+
["type"]=>
33+
string(4) "bool"
34+
["value"]=>
35+
string(5) "false"
36+
["file"]=>
37+
string(11) "(eval code)"
38+
["line"]=>
39+
int(1)
40+
["char"]=>
41+
int(49)
42+
}
43+
["file"]=>
44+
string(11) "(eval code)"
45+
["line"]=>
46+
int(1)
47+
["char"]=>
48+
int(51)
49+
}
50+
}
51+
["return-type"]=>
52+
array(6) {
53+
["type"]=>
54+
string(11) "return-type"
55+
["list"]=>
56+
array(1) {
57+
[0]=>
58+
array(6) {
59+
["type"]=>
60+
string(21) "return-type-parameter"
61+
["data-type"]=>
62+
string(5) "false"
63+
["mandatory"]=>
64+
int(0)
65+
["file"]=>
66+
string(11) "(eval code)"
67+
["line"]=>
68+
int(1)
69+
["char"]=>
70+
int(35)
71+
}
72+
}
73+
["void"]=>
74+
int(0)
75+
["file"]=>
76+
string(11) "(eval code)"
77+
["line"]=>
78+
int(1)
79+
["char"]=>
80+
int(35)
81+
}
82+
["file"]=>
83+
string(11) "(eval code)"
84+
["line"]=>
85+
int(3)
86+
["char"]=>
87+
int(8)
88+
}
89+
[1]=>
90+
array(7) {
91+
["type"]=>
92+
string(8) "function"
93+
["name"]=>
94+
string(11) "unionReturn"
95+
["statements"]=>
96+
array(1) {
97+
[0]=>
98+
array(5) {
99+
["type"]=>
100+
string(6) "return"
101+
["expr"]=>
102+
array(5) {
103+
["type"]=>
104+
string(3) "int"
105+
["value"]=>
106+
string(1) "1"
107+
["file"]=>
108+
string(11) "(eval code)"
109+
["line"]=>
110+
int(3)
111+
["char"]=>
112+
int(49)
113+
}
114+
["file"]=>
115+
string(11) "(eval code)"
116+
["line"]=>
117+
int(3)
118+
["char"]=>
119+
int(51)
120+
}
121+
}
122+
["return-type"]=>
123+
array(6) {
124+
["type"]=>
125+
string(11) "return-type"
126+
["list"]=>
127+
array(2) {
128+
[0]=>
129+
array(6) {
130+
["type"]=>
131+
string(21) "return-type-parameter"
132+
["data-type"]=>
133+
string(3) "int"
134+
["mandatory"]=>
135+
int(0)
136+
["file"]=>
137+
string(11) "(eval code)"
138+
["line"]=>
139+
int(3)
140+
["char"]=>
141+
int(31)
142+
}
143+
[1]=>
144+
array(6) {
145+
["type"]=>
146+
string(21) "return-type-parameter"
147+
["data-type"]=>
148+
string(5) "false"
149+
["mandatory"]=>
150+
int(0)
151+
["file"]=>
152+
string(11) "(eval code)"
153+
["line"]=>
154+
int(3)
155+
["char"]=>
156+
int(39)
157+
}
158+
}
159+
["void"]=>
160+
int(0)
161+
["file"]=>
162+
string(11) "(eval code)"
163+
["line"]=>
164+
int(3)
165+
["char"]=>
166+
int(39)
167+
}
168+
["file"]=>
169+
string(11) "(eval code)"
170+
["line"]=>
171+
int(3)
172+
["char"]=>
173+
int(8)
174+
}
175+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Function definition with `float` return type
3+
--SKIPIF--
4+
<?php include(__DIR__ . '/../../skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$code =<<<ZEP
8+
function test() -> float { }
9+
ZEP;
10+
11+
$ir = zephir_parse_file($code, '(eval code)');
12+
var_dump($ir);
13+
?>
14+
--EXPECT--
15+
array(1) {
16+
[0]=>
17+
array(6) {
18+
["type"]=>
19+
string(8) "function"
20+
["name"]=>
21+
string(4) "test"
22+
["return-type"]=>
23+
array(6) {
24+
["type"]=>
25+
string(11) "return-type"
26+
["list"]=>
27+
array(1) {
28+
[0]=>
29+
array(6) {
30+
["type"]=>
31+
string(21) "return-type-parameter"
32+
["data-type"]=>
33+
string(6) "double"
34+
["mandatory"]=>
35+
int(0)
36+
["file"]=>
37+
string(11) "(eval code)"
38+
["line"]=>
39+
int(1)
40+
["char"]=>
41+
int(27)
42+
}
43+
}
44+
["void"]=>
45+
int(0)
46+
["file"]=>
47+
string(11) "(eval code)"
48+
["line"]=>
49+
int(1)
50+
["char"]=>
51+
int(27)
52+
}
53+
["file"]=>
54+
string(11) "(eval code)"
55+
["line"]=>
56+
int(1)
57+
["char"]=>
58+
int(9)
59+
}
60+
}

tests/functions/return-types/int.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Function definition with mandatory return type
2+
Function definition with `int` return type
33
--SKIPIF--
44
<?php include(__DIR__ . '/../../skipif.inc'); ?>
55
--FILE--

tests/functions/return-types/mixed.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Function definition with void
2+
Function definition with `mixed` return type
33
--SKIPIF--
44
<?php include(__DIR__ . '/../../skipif.inc'); ?>
55
--FILE--

zephir_parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern zend_module_entry zephir_parser_module_entry;
1515
#define phpext_zephir_parser_ptr &zephir_parser_module_entry
1616

1717
#define PHP_ZEPHIR_PARSER_NAME "zephir_parser"
18-
#define PHP_ZEPHIR_PARSER_VERSION "1.4.2"
18+
#define PHP_ZEPHIR_PARSER_VERSION "1.5.0"
1919
#define PHP_ZEPHIR_PARSER_AUTHOR "Zephir Team and contributors"
2020
#define PHP_ZEPHIR_PARSER_DESCRIPTION "The Zephir Parser delivered as a C extension for the PHP language."
2121

0 commit comments

Comments
 (0)