Skip to content

Commit

Permalink
Merge pull request #124 from zephir-lang/development
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
Jeckerson authored Sep 18, 2021
2 parents 4517f3b + e529246 commit 70eee9e
Show file tree
Hide file tree
Showing 21 changed files with 1,532 additions and 8 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.4.0] - 2021-09-18
### Added
- Added support for `mixed` type [#120](https://github.com/phalcon/php-zephir-parser/issues/120)
- Added support for `yield` statement [#118](https://github.com/phalcon/php-zephir-parser/issues/118)

## [1.3.8] - 2021-09-08
### Changed
- Changed CI from AppVeyor to Github Actions [#110](https://github.com/phalcon/php-zephir-parser/issues/110)
Expand Down Expand Up @@ -168,7 +173,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.3.8...HEAD
[Unreleased]: https://github.com/phalcon/php-zephir-parser/compare/v1.4.0...HEAD
[1.4.0]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.8...v1.4.0
[1.3.8]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.7...v1.3.8
[1.3.7]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.6...v1.3.7
[1.3.6]: https://github.com/phalcon/php-zephir-parser/compare/v1.3.5...v1.3.6
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

MIT License

Copyright (c) 2013-2019 Zephir Team
Copyright (c) 2013-present Zephir Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.8
1.4.0
5 changes: 5 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ if test "$PHP_ZEPHIR_PARSER" = "yes"; then
[PHP_INSTALL_HEADERS([ext/zephir_parser], $PHP_ZEPHIR_PARSER_HEADERS)])

PHP_ADD_MAKEFILE_FRAGMENT([parser.mk])

dnl Create directories because PECL can't
if test ! -d parser; then
mkdir parser
fi
fi

dnl Code Coverage -------------------------------------------------------------
Expand Down
69 changes: 69 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.10.5" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>zephir_parser</name>
<channel>pecl.php.net</channel>
<summary>Zephir code parser.</summary>
<description>Zephir Parser is a code parser, delivered as a C extension for the PHP language.</description>
<lead>
<name>Anton Vasiliev</name>
<user>jeckerson</user>
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2021-09-18</date>
<time>11:00:00</time>
<version>
<release>1.4.0</release>
<api>1.4.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, Sep 18, 2021 - Zephir Parser 1.4.0

= New features:

- Fixed issue #120: Add support for `mixed` type
- Fixed issue #118: Add support for `yield` statement
</notes>
<contents>
<dir name="/">
<dir name="parser">
<file name="parser.c" role="src"/>
<file name="scanner.c" role="src"/>

<file name="parser.h" role="src"/>
<file name="scanner.h" role="src"/>
<file name="xx.h" role="src"/>
<file name="zephir.h" role="src"/>
</dir>

<file name="config.m4" role="src"/>
<file name="config.w32" role="src"/>
<file name="zephir_parser.c" role="src"/>
<file name="zephir_parser.h" role="src"/>
<file name="CHANGELOG.md" role="doc"/>
<file name="CODE_OF_CONDUCT.md" role="doc"/>
<file name="LICENSE" role="doc"/>
<file name="NO_WARRANTY" role="doc"/>
</dir>
</contents>
<dependencies>
<required>
<php>
<min>7.0.0</min>
<max>8.0.99</max>
</php>
<pearinstaller>
<min>1.10</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>zephir_parser</providesextension>
<extsrcrelease/>
</package>
6 changes: 6 additions & 0 deletions parser/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
case XX_T_RETURN:
xx_(xx_parser, XX_RETURN, NULL, parser_status);
break;
case XX_T_YIELD:
xx_(xx_parser, XX_YIELD, NULL, parser_status);
break;
case XX_T_REQUIRE_ONCE:
xx_(xx_parser, XX_REQUIRE_ONCE, NULL, parser_status);
break;
Expand Down Expand Up @@ -444,6 +447,9 @@ void xx_parse_program(zval *return_value, char *program, size_t program_length,
case XX_T_TYPE_RESOURCE:
xx_(xx_parser, XX_TYPE_RESOURCE, NULL, parser_status);
break;
case XX_T_TYPE_MIXED:
xx_(xx_parser, XX_TYPE_MIXED, NULL, parser_status);
break;
case XX_T_TYPE_CALLABLE:
xx_(xx_parser, XX_TYPE_CALLABLE, NULL, parser_status);
break;
Expand Down
31 changes: 30 additions & 1 deletion parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ static void xx_ret_return_type_item(zval *ret, zval *type, zval *cast, int manda
static void xx_ret_type(zval *ret, int type)
{
switch (type) {

case XX_TYPE_INTEGER:
parser_get_string(ret, "int");
return;
Expand Down Expand Up @@ -587,6 +586,10 @@ static void xx_ret_type(zval *ret, int type)
parser_get_string(ret, "object");
return;

case XX_TYPE_MIXED:
parser_get_string(ret, "mixed");
return;

case XX_T_TYPE_NULL:
parser_get_string(ret, "null");
return;
Expand Down Expand Up @@ -896,6 +899,28 @@ static void xx_ret_return_statement(zval *ret, zval *expr, xx_scanner_state *sta
parser_add_int(ret, "char", state->active_char);
}

static void xx_ret_yield_statement(zval *ret, zval *expr, zval *K, zval *V, xx_scanner_state *state)
{
array_init(ret);

parser_add_str(ret, "type", "yield");
if (expr) {
parser_add_zval(ret, "expr", expr);
}

if (K) {
parser_add_zval(ret, "key", K);
}

if (V) {
parser_add_zval(ret, "value", V);
}

parser_add_str(ret, "file", state->active_file);
parser_add_int(ret, "line", state->active_line);
parser_add_int(ret, "char", state->active_char);
}

static void xx_ret_require_once_statement(zval *ret, zval *expr, xx_scanner_state *state)
{
array_init(ret);
Expand Down Expand Up @@ -1040,6 +1065,10 @@ static void xx_ret_declare_statement(zval *ret, int type, zval *variables, xx_sc
parser_add_str(ret, "data-type", "resource");
break;

case XX_T_TYPE_MIXED:
parser_add_str(ret, "data-type", "mixed");
break;

case XX_T_TYPE_OBJECT:
parser_add_str(ret, "data-type", "object");
break;
Expand Down
2 changes: 2 additions & 0 deletions parser/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define XX_T_TYPE_RESOURCE 333
#define XX_T_TYPE_NULL 334
#define XX_T_TYPE_THIS 335
#define XX_T_TYPE_MIXED 336

#define XX_T_NAMESPACE 350
#define XX_T_CLASS 351
Expand Down Expand Up @@ -98,6 +99,7 @@
#define XX_T_CATCH 398
#define XX_T_DEPRECATED 399
#define XX_T_REQUIRE_ONCE 459
#define XX_T_YIELD 460

/* Operators */
#define XX_T_AT '@'
Expand Down
12 changes: 12 additions & 0 deletions parser/scanner.re
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ int xx_get_token(xx_scanner_state *s, xx_scanner_token *token) {
return 0;
}
'mixed' {
s->active_char += sizeof("mixed")-1;
token->opcode = XX_T_TYPE_MIXED;
return 0;
}
'if' {
s->active_char += sizeof("if")-1;
token->opcode = XX_T_IF;
Expand Down Expand Up @@ -357,6 +363,12 @@ int xx_get_token(xx_scanner_state *s, xx_scanner_token *token) {
return 0;
}
'yield' {
s->active_char += sizeof("yield")-1;
token->opcode = XX_T_YIELD;
return 0;
}
'require' {
s->active_char += sizeof("require")-1;
token->opcode = XX_T_REQUIRE;
Expand Down
33 changes: 30 additions & 3 deletions parser/zephir.lemon
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ xx_parameter_type(R) ::= TYPE_RESOURCE . {
xx_ret_type(&R, XX_TYPE_RESOURCE);
}

xx_parameter_type(R) ::= TYPE_MIXED . {
xx_ret_type(&R, XX_TYPE_MIXED);
}

xx_parameter_type(R) ::= TYPE_OBJECT . {
xx_ret_type(&R, XX_TYPE_OBJECT);
}
Expand Down Expand Up @@ -982,6 +986,10 @@ xx_statement(R) ::= xx_return_statement(S) . {
R = S;
}

xx_statement(R) ::= xx_yield_statement(S) . {
R = S;
}

xx_statement(R) ::= xx_require_once_statement(S) . {
R = S;
}
Expand Down Expand Up @@ -1522,16 +1530,31 @@ xx_fetch_statement(R) ::= xx_fetch_expr(E) DOTCOMMA . {
xx_ret_fetch_statement(&R, &E, status->scanner_state);
}

/* return statement */
/* return var; */
xx_return_statement(R) ::= RETURN xx_common_expr(E) DOTCOMMA . {
xx_ret_return_statement(&R, &E, status->scanner_state);
}

/* return statement */
/* return; */
xx_return_statement(R) ::= RETURN DOTCOMMA . {
xx_ret_return_statement(&R, NULL, status->scanner_state);
}

/* yield var; */
xx_yield_statement(R) ::= YIELD xx_common_expr(E) DOTCOMMA . {
xx_ret_yield_statement(&R, &E, NULL, NULL, status->scanner_state);
}

/* yield key, val; */
xx_yield_statement(R) ::= YIELD xx_common_expr(K) COMMA xx_common_expr(V) DOTCOMMA . {
xx_ret_yield_statement(&R, NULL, &K, &V, status->scanner_state);
}

/* yield; */
xx_yield_statement(R) ::= YIELD DOTCOMMA . {
xx_ret_yield_statement(&R, NULL, NULL, NULL, status->scanner_state);
}

/* require_once statement */
xx_require_once_statement(R) ::= REQUIRE_ONCE xx_common_expr(E) DOTCOMMA . {
xx_ret_require_once_statement(&R, &E, status->scanner_state);
Expand Down Expand Up @@ -1596,6 +1619,10 @@ xx_declare_statement(R) ::= TYPE_ARRAY xx_declare_variable_list(L) DOTCOMMA . {
xx_ret_declare_statement(&R, XX_T_TYPE_ARRAY, &L, status->scanner_state);
}

xx_declare_statement(R) ::= TYPE_MIXED xx_declare_variable_list(L) DOTCOMMA . {
xx_ret_declare_statement(&R, XX_T_TYPE_MIXED, &L, status->scanner_state);
}

xx_declare_variable_list(R) ::= xx_declare_variable_list(L) COMMA xx_declare_variable(V) . {
xx_ret_list(&R, &L, &V, status->scanner_state);
}
Expand Down Expand Up @@ -1898,7 +1925,7 @@ xx_common_expr(R) ::= NULL . {
xx_ret_literal(&R, XX_T_NULL, NULL, status->scanner_state);
}

/* y = false */
/* y = true */
xx_common_expr(R) ::= TRUE . {
xx_ret_literal(&R, XX_T_TRUE, NULL, status->scanner_state);
}
Expand Down
53 changes: 53 additions & 0 deletions tests/functions/parameter-types/int.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--TEST--
Parameter type 'int'
--SKIPIF--
<?php include(__DIR__ . '/../../skipif.inc'); ?>
--FILE--
<?php
$code =<<<ZEP
function test(int value) { }
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"
["parameters"]=>
array(1) {
[0]=>
array(9) {
["type"]=>
string(9) "parameter"
["name"]=>
string(5) "value"
["const"]=>
int(0)
["data-type"]=>
string(3) "int"
["mandatory"]=>
int(0)
["reference"]=>
int(0)
["file"]=>
string(11) "(eval code)"
["line"]=>
int(1)
["char"]=>
int(25)
}
}
["file"]=>
string(11) "(eval code)"
["line"]=>
int(1)
["char"]=>
int(9)
}
}
Loading

0 comments on commit 70eee9e

Please sign in to comment.