Skip to content

Commit

Permalink
Merge pull request #139 from zephir-lang/development
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNDRmac authored Feb 12, 2022
2 parents 5b40fb0 + 796ccb0 commit 67224fa
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.lo
*.la
*.profraw
*.dep

.deps
.libs
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## [Unreleased] - xxxx-xx-xx


## [1.5.0] - 2022-02-12
### Added
- Added support for `false` return type [#137](https://github.com/phalcon/php-zephir-parser/issues/137)

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

[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.2...HEAD
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.5.0...HEAD
[1.5.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.2...v1.5.0
[1.4.2]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.1...v1.4.2
[1.4.1]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.0...v1.4.1
[1.4.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.8...v1.4.0
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.2
1.5.0
12 changes: 7 additions & 5 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
<date>2021-09-18</date>
<time>15:00:00</time>
<version>
<release>1.4.2</release>
<api>1.4.2</api>
<release>1.5.0</release>
<api>1.5.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="https://github.com/zephir-lang/php-zephir-parser/blob/development/LICENSE">MIT</license>
<notes>
Sat, Dec 1, 2021 - Zephir Parser 1.4.2
Sat, Feb 12, 2022 - Zephir Parser 1.5.0

= Changes:
= Added:

- Enabled support of PHP8.1
- Added support of `false` return type
</notes>
<contents>
<dir name="/">
Expand Down Expand Up @@ -107,6 +107,8 @@
</dir>

<dir name="return-types">
<file name="false.phpt" role="test"/>
<file name="float.phpt" role="test"/>
<file name="int.phpt" role="test"/>
<file name="mixed.phpt" role="test"/>
</dir>
Expand Down
4 changes: 4 additions & 0 deletions parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
1 change: 1 addition & 0 deletions parser/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions parser/zephir.lemon
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
175 changes: 175 additions & 0 deletions tests/functions/return-types/false.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
--TEST--
Function definition with `false` return type
--SKIPIF--
<?php include(__DIR__ . '/../../skipif.inc'); ?>
--FILE--
<?php
$code =<<<ZEP
function singleReturn() -> 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)
}
}
60 changes: 60 additions & 0 deletions tests/functions/return-types/float.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--TEST--
Function definition with `float` return type
--SKIPIF--
<?php include(__DIR__ . '/../../skipif.inc'); ?>
--FILE--
<?php
$code =<<<ZEP
function test() -> 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)
}
}
2 changes: 1 addition & 1 deletion tests/functions/return-types/int.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Function definition with mandatory return type
Function definition with `int` return type
--SKIPIF--
<?php include(__DIR__ . '/../../skipif.inc'); ?>
--FILE--
Expand Down
2 changes: 1 addition & 1 deletion tests/functions/return-types/mixed.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Function definition with void
Function definition with `mixed` return type
--SKIPIF--
<?php include(__DIR__ . '/../../skipif.inc'); ?>
--FILE--
Expand Down
2 changes: 1 addition & 1 deletion zephir_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern zend_module_entry zephir_parser_module_entry;
#define phpext_zephir_parser_ptr &zephir_parser_module_entry

#define PHP_ZEPHIR_PARSER_NAME "zephir_parser"
#define PHP_ZEPHIR_PARSER_VERSION "1.4.2"
#define PHP_ZEPHIR_PARSER_VERSION "1.5.0"
#define PHP_ZEPHIR_PARSER_AUTHOR "Zephir Team and contributors"
#define PHP_ZEPHIR_PARSER_DESCRIPTION "The Zephir Parser delivered as a C extension for the PHP language."

Expand Down

0 comments on commit 67224fa

Please sign in to comment.