Skip to content

Commit a7d7a61

Browse files
authored
Merge pull request #2286 from zephir-lang/development
0.14.0
2 parents 0be9ad5 + e1b0dd1 commit a7d7a61

40 files changed

+970
-595
lines changed

Diff for: .ci/install-zephir-parser.sh

-37
This file was deleted.

Diff for: .ci/run-tests.sh

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ set -eu
1414
php \
1515
-d extension=ext/modules/stub.so \
1616
vendor/bin/phpunit \
17-
--colors=always \
1817
--bootstrap tests/ext-bootstrap.php \
1918
--testsuite Extension
2019

Diff for: .ci/win-ci-tools.psm1

+4-6
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,11 @@ function InstallZephirParser {
9292
Download and install Zephir parser PHP extension
9393
#>
9494

95-
$BaseUri = "https://github.com/phalcon/php-zephir-parser/releases/download"
96-
$LocalPart = "zephir_parser_${env:PHP_ARCH}_vc${env:VC_VERSION}_php${env:PHP_MINOR}"
95+
$BaseUri = "https://github.com/zephir-lang/php-zephir-parser/releases/download"
96+
$LocalPart = "zephir-parser-php-${env:PHP_MINOR}-${env:BUILD_TYPE}-win32-vc${env:VC_VERSION}-${env:PHP_ARCH}.zip"
9797

98-
$TS = Get-ThreadSafety
99-
100-
$RemoteUrl = "${BaseUri}/v${env:PARSER_VERSION}/${LocalPart}${TS}_${env:PARSER_VERSION}-${env:PARSER_RELEASE}.zip"
101-
$DestinationPath = "C:\Downloads\${LocalPart}${TS}_${env:PARSER_VERSION}-${env:PARSER_RELEASE}.zip"
98+
$RemoteUrl = "${BaseUri}/v${env:PARSER_VERSION}/${LocalPart}"
99+
$DestinationPath = "C:\Downloads\${LocalPart}"
102100

103101
if (-not (Test-Path "${env:PHPROOT}\ext\php_zephir_parser.dll")) {
104102
if (-not [System.IO.File]::Exists($DestinationPath)) {

Diff for: .github/workflows/build-unix.yml

+5-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- development
1212

1313
env:
14-
ZEPHIR_PARSER_VERSION: v1.3.6
14+
ZEPHIR_PARSER_VERSION: 1.4.1
1515

1616
jobs:
1717
linux:
@@ -47,7 +47,7 @@ jobs:
4747
uses: shivammathur/setup-php@v2
4848
with:
4949
php-version: ${{ matrix.php }}
50-
extensions: gmp, pdo_sqlite, psr, zip
50+
extensions: gmp, pdo_sqlite, psr, zip, zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}
5151
tools: phpize, php-config
5252
coverage: xdebug
5353
# variables_order: https://github.com/zephir-lang/zephir/pull/1537
@@ -62,6 +62,8 @@ jobs:
6262
memory_limit=1G,
6363
date.timezone=UTC,
6464
xdebug.max_nesting_level=256
65+
env:
66+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6567

6668
- name: Checkout Code
6769
uses: actions/checkout@v2
@@ -98,20 +100,6 @@ jobs:
98100
sudo apt-get update --quiet --yes 1>/dev/null
99101
sudo apt-get install --no-install-recommends -q -y re2c
100102
101-
- name: Get Zephir Parser Cache Key
102-
id: pcache
103-
run: echo ::set-output name=key::$(echo -n ${ZEPHIR_PARSER_VERSION}_${CPUHASH})
104-
105-
- name: Cache Zephir Parser
106-
uses: actions/cache@v1
107-
with:
108-
path: ~/php-zephir-parser
109-
key: ${{ runner.os }}-${{ matrix.php }}-zephir-parser-${{ steps.pcache.outputs.key }}
110-
restore-keys: ${{ runner.os }}-${{ matrix.php }}-zephir-parser-
111-
112-
- name: Install Zephir Parser
113-
run: .ci/install-zephir-parser.sh
114-
115103
- name: Get Composer Cache Directory
116104
id: composer-cache
117105
run: echo ::set-output name=dir::$(composer config cache-files-dir)
@@ -125,7 +113,7 @@ jobs:
125113
${{ runner.os }}-composer-
126114
127115
- name: Install Project Dependencies for PHP
128-
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress --no-suggest
116+
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress
129117

130118
- name: Prepare Zephir Executable
131119
run: sudo ln -s "$(pwd)/zephir" /usr/local/bin/zephir

Diff for: .github/workflows/build-windows.yml

+5-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
- development
1414

1515
env:
16-
PARSER_VERSION: 1.3.6
16+
PARSER_VERSION: 1.4.1
1717
PARSER_RELEASE: 559
1818
PHP_SDK_VERSION: 2.2.0
1919
PHP_DEVPACK: C:\tools\php-devpack
@@ -67,6 +67,7 @@ jobs:
6767
xdebug.max_nesting_level=256
6868
env:
6969
PHPTS: ${{ matrix.build_type }}
70+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7071

7172
- name: Set Environment Variables
7273
run: |
@@ -119,10 +120,10 @@ jobs:
119120
InstallZephirParser
120121
121122
- name: Enable Zephir Parser
122-
run: Enable-PhpExtension -Extension 'Zephir Parser' -Path "${env:PHPROOT}"
123+
run: Enable-PhpExtension -Extension zephir_parser -Path "${env:PHPROOT}"
123124

124125
- name: Minimal Zephir Parser Load Test
125-
run: php --ri 'Zephir Parser'
126+
run: php --ri zephir_parser
126127

127128
- name: "Setup Visual Studio Command Line for PHP SDK ${{ matrix.arch }}"
128129
run: .ci\vsenv.bat -arch=${{ matrix.arch }} -host_arch=${{ matrix.arch }}
@@ -148,16 +149,8 @@ jobs:
148149
restore-keys: |
149150
${{ runner.os }}-composer-
150151
151-
- name: Setup GitHub Token
152-
shell: bash
153-
run: |
154-
# To increase the GitHub rate limit we're use GitHub authentication
155-
if [ ! -z '${{ secrets.COMPOSER_TOKEN }}' ]; then
156-
composer config github-oauth.github.com ${{ secrets.COMPOSER_TOKEN }}
157-
fi
158-
159152
- name: Install Project Dependencies
160-
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress --no-suggest
153+
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress
161154

162155
- name: Initialize Release Variables
163156
run: |

Diff for: .github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
${{ runner.os }}-composer-
4040
4141
- name: Install Project Dependencies
42-
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress --no-suggest
42+
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress
4343

4444
- name: Install Box
4545
run: |

Diff for: CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org).
66

77
## [Unreleased]
88

9+
## [0.14.0] - 2021-09-18
10+
### Added
11+
- Added support for `require_once` [#2253](https://github.com/zephir-lang/zephir/issues/2253)
12+
13+
### Changed
14+
- Bumped minimal version of Zephir Parser to `1.4.1`. [#2284](https://github.com/zephir-lang/zephir/issues/2284)
15+
916
## [0.14.0-beta.3] - 2021-08-06
1017
### Fixed
1118
- Fixed class entry generation of external class [#2261](https://github.com/zephir-lang/zephir/issues/2261)
@@ -534,7 +541,8 @@ and this project adheres to [Semantic Versioning](http://semver.org).
534541
[#1524](https://github.com/zephir-lang/zephir/issues/1524)
535542

536543

537-
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.3...HEAD
544+
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.14.0...HEAD
545+
[0.14.0]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.3...0.14.0
538546
[0.14.0-beta.3]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.2...0.14.0-beta.3
539547
[0.14.0-beta.2]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.1...0.14.0-beta.2
540548
[0.14.0-beta.1]: https://github.com/zephir-lang/zephir/compare/0.13.5...0.14.0-beta.1

Diff for: Library/Detectors/WriteDetector.php

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ public function passExpression(array $expression)
280280
case 'empty':
281281
case 'instanceof':
282282
case 'require':
283+
case 'require_once':
283284
case 'clone':
284285
case 'likely':
285286
case 'unlikely':
@@ -432,6 +433,7 @@ public function passStatementBlock(array $statements)
432433
case 'scall':
433434
case 'fcall':
434435
case 'require':
436+
case 'require_once':
435437
$this->passCall($statement['expr']);
436438
break;
437439

Diff for: Library/Expression.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
use Zephir\Operators\Other\NewInstanceTypeOperator;
5656
use Zephir\Operators\Other\RangeExclusiveOperator;
5757
use Zephir\Operators\Other\RangeInclusiveOperator;
58+
use Zephir\Operators\Other\RequireOnceOperator;
5859
use Zephir\Operators\Other\RequireOperator;
5960
use Zephir\Operators\Other\ShortTernaryOperator;
6061
use Zephir\Operators\Other\TernaryOperator;
@@ -575,6 +576,10 @@ public function compile(CompilationContext $compilationContext): CompiledExpress
575576
$compilableExpression = new RequireOperator();
576577
break;
577578

579+
case 'require_once':
580+
$compilableExpression = new RequireOnceOperator();
581+
break;
582+
578583
case 'closure':
579584
$compilableExpression = new Closure();
580585
break;
@@ -591,9 +596,6 @@ public function compile(CompilationContext $compilationContext): CompiledExpress
591596
throw new CompilerException('Unknown expression: '.$type, $expression);
592597
}
593598

594-
if (!$compilableExpression) {
595-
throw new CompilerException('Unknown expression passed as compilableExpression', $expression);
596-
}
597599
$compilableExpression->setReadOnly($this->isReadOnly());
598600
$compilableExpression->setExpectReturn($this->expecting, $this->expectingVariable);
599601

Diff for: Library/Expression/Builder/Operators/UnaryOperator.php

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class UnaryOperator extends AbstractOperator
4141
// y = require a
4242
const OPERATOR_REQUIRE = 'require';
4343

44+
// y = require_once a
45+
const OPERATOR_REQUIRE_ONCE = 'require_once';
46+
4447
// y = clone a
4548
const OPERATOR_CLONE = 'clone';
4649

Diff for: Library/Operators/Other/RequireOnceOperator.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Zephir.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Zephir\Operators\Other;
15+
16+
use Zephir\CompilationContext;
17+
use Zephir\CompiledExpression;
18+
use Zephir\Exception;
19+
use Zephir\Expression;
20+
use Zephir\Operators\BaseOperator;
21+
22+
/**
23+
* Require once.
24+
*
25+
* Includes once a plain PHP file
26+
*/
27+
class RequireOnceOperator extends BaseOperator
28+
{
29+
/**
30+
* @param array $expression
31+
* @param CompilationContext $compilationContext
32+
*
33+
* @return CompiledExpression
34+
* @throws Exception
35+
*/
36+
public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
37+
{
38+
$expr = new Expression($expression['left']);
39+
$expr->setReadOnly(true);
40+
$expr->setExpectReturn(true);
41+
42+
$exprPath = $expr->compile($compilationContext);
43+
if ('variable' === $exprPath->getType()) {
44+
$exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression);
45+
$exprVar = $compilationContext->backend->getVariableCode($exprVariable);
46+
if ('variable' === $exprVariable->getType()) {
47+
if ($exprVariable->hasDifferentDynamicType(['undefined', 'string'])) {
48+
$compilationContext->logger->warning(
49+
'Possible attempt to use invalid type as path in "require_once" operator',
50+
['non-valid-require-once', $expression]
51+
);
52+
}
53+
}
54+
} else {
55+
$exprVar = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
56+
$compilationContext->backend->assignString($exprVar, $exprPath->getCode(), $compilationContext);
57+
$exprVar = $compilationContext->backend->getVariableCode($exprVar);
58+
}
59+
60+
$symbolVariable = false;
61+
if ($this->isExpecting()) {
62+
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext);
63+
}
64+
65+
$compilationContext->headersManager->add('kernel/memory');
66+
$compilationContext->headersManager->add('kernel/require');
67+
68+
$codePrinter = $compilationContext->codePrinter;
69+
70+
if ($symbolVariable) {
71+
$codePrinter->output('ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(&'.$symbolVariable->getName().');');
72+
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
73+
$codePrinter->output('if (zephir_require_once_zval_ret('.$symbol.', '.$exprVar.') == FAILURE) {');
74+
} else {
75+
$codePrinter->output('if (zephir_require_once_zval('.$exprVar.') == FAILURE) {');
76+
}
77+
$codePrinter->output("\t".'RETURN_MM_NULL();');
78+
$codePrinter->output('}');
79+
80+
if ($symbolVariable) {
81+
return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
82+
}
83+
84+
return new CompiledExpression('null', null, $expression);
85+
}
86+
}

0 commit comments

Comments
 (0)