Skip to content

Commit

Permalink
Merge branch 'development' into #1259-unset-property
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Apr 23, 2021
2 parents 06b5b80 + 7dda56b commit 0e6473d
Show file tree
Hide file tree
Showing 30 changed files with 642 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org).
## [Unreleased]
### Fixed
- Fixed nullable array [#1094](https://github.com/zephir-lang/zephir/issues/1094)
- Fixed default value detection with Reflection (only PHP 8.0) [#1134](https://github.com/zephir-lang/zephir/issues/1134)
- Updated supported list of class entries for PHP date extension [#2226](https://github.com/zephir-lang/zephir/issues/2226)

### Added
- Added support syntax assign-bitwise operators [#1103](https://github.com/zephir-lang/zephir/issues/1103)

## [0.13.2] - 2021-04-10
### Fixed
Expand Down
63 changes: 53 additions & 10 deletions Library/ArgInfoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ArgInfoDefinition
/**
* @var ClassMethodParameters|null
*/
private ?ClassMethodParameters $parameters = null;
private ?ClassMethodParameters $parameters;

/**
* @var CodePrinter
Expand Down Expand Up @@ -228,14 +228,38 @@ private function renderEnd(): void
switch ("{$flag}:".$parameter['data-type']) {
case '0:array':
case '1:array':
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_ARRAY_INFO(%d, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter)
)
);
if (!isset($parameter['default'])) {
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_ARRAY_INFO(%d, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter)
)
);
} else {
$this->codePrinter->output('#if PHP_VERSION_ID >= 80000');
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(%d, %s, IS_ARRAY, %d, %s)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter),
$this->defaultArrayValue($parameter),
)
);
$this->codePrinter->output('#else');
// `ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE` does not exist in PHP 7.4
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_ARRAY_INFO(%d, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter)
)
);
$this->codePrinter->output('#endif');
}
break;
case '0:variable':
case '1:variable':
Expand Down Expand Up @@ -333,6 +357,25 @@ private function hasParameters(): bool
return null !== $this->parameters && \count($this->parameters->getParameters()) > 0;
}

private function defaultArrayValue(array $parameter): string
{
if ($parameter['default']['type'] === 'empty-array') {
return '"[]"';
}

// TODO: Come back later
/**
* It seems that it is impossible to pass default array with some data inside.
* Only empty array, even if manually specify not empty array - it will be ignored,
* for example:
*
* `ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, someDefaultData, IS_ARRAY, 0, "[\"key\" => \"value\"]")`
*
* Output of default value will be `[]` during method call.
*/
return '"[]"';
}

private function allowNull(array $parameter): bool
{
if (!isset($parameter['default']) || !\is_array($parameter['default'])) {
Expand All @@ -348,7 +391,7 @@ private function allowNull(array $parameter): bool

private function passByReference(array $parameter)
{
return isset($parameter['reference']) ? $parameter['reference'] : 0;
return $parameter['reference'] ?? 0;
}

private function getReturnType(): string
Expand Down
23 changes: 23 additions & 0 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -1912,16 +1912,39 @@ public function getClassEntryByClassName(
$classEntry = 'php_pdo_get_exception()';
break;

/**
* PHP Ext Date
*/
case 'datetimeinterface':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_interface_ce()';
break;

case 'datetime':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_date_ce()';
break;

case 'datetimeimmutable':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_immutable_ce()';
break;

case 'datetimezone':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_timezone_ce()';
break;

case 'dateinterval':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_interval_ce()';
break;

case 'dateperiod':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_period_ce()';
break;

/**
* PHP Ext session
*/
Expand Down
17 changes: 17 additions & 0 deletions Library/Expression/Builder/Operators/AssignVariableOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ class AssignVariableOperator extends AbstractOperator
// %=
const OPERATOR_MOD = 'mod-assign';

// &=
const OPERATOR_BITWISE_AND = 'bitwise-and-assign';

// |=
const OPERATOR_BITWISE_OR = 'bitwise-or-assign';

// ^=
const OPERATOR_BITWISE_XOR = 'bitwise-xor-assign';

// <<=
const OPERATOR_BITWISE_SHIFTLEFT = 'bitwise-shiftleft-assign';

// >>=
const OPERATOR_BITWISE_SHIFTRIGHT = 'bitwise-shiftright-assign';



private $variable;
private $operator = self::OPERATOR_ASSIGN;
private $expression;
Expand Down
57 changes: 57 additions & 0 deletions Library/Statements/LetStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
use Zephir\Statements\Let\StaticPropertySub as LetStaticPropertySub;
use Zephir\Statements\Let\Variable as LetVariable;
use Zephir\Statements\Let\VariableAppend as LetVariableAppend;
use Zephir\Expression\Builder\BuilderFactory;
use Zephir\Expression\Builder\Operators\AssignVariableOperator;
use Zephir\Expression\Builder\Operators\BinaryOperator;

/**
* LetStatement.
Expand Down Expand Up @@ -88,6 +91,12 @@ public function compile(CompilationContext $compilationContext)
* Incr/Decr assignments don't require an expression
*/
if (isset($assignment['expr'])) {
/**
* Replace on direct-assignment if this bitwise-assignment
* TODO: Replace on supported native bitwise-assignment
*/
$assignment = $this->replaceAssignBitwiseOnDirect($assignment);

$expr = new Expression($assignment['expr']);

switch ($assignment['assign-type']) {
Expand Down Expand Up @@ -256,4 +265,52 @@ public function compile(CompilationContext $compilationContext)
}
}
}

/**
* @param array $assignment
* @return array
* @throws CompilerException
*/
protected function replaceAssignBitwiseOnDirect(array $assignment): array
{
switch ($assignment['operator']) {
case AssignVariableOperator::OPERATOR_BITWISE_AND:
$operator = BinaryOperator::OPERATOR_BITWISE_AND;
break;

case AssignVariableOperator::OPERATOR_BITWISE_OR:
$operator = BinaryOperator::OPERATOR_BITWISE_OR;
break;

case AssignVariableOperator::OPERATOR_BITWISE_XOR:
$operator = BinaryOperator::OPERATOR_BITWISE_XOR;
break;

case AssignVariableOperator::OPERATOR_BITWISE_SHIFTLEFT:
$operator = BinaryOperator::OPERATOR_BITWISE_SHIFT_LEFT;
break;

case AssignVariableOperator::OPERATOR_BITWISE_SHIFTRIGHT:
$operator = BinaryOperator::OPERATOR_BITWISE_SHIFT_RIGHT;
break;

default:
return $assignment;
}

if ($assignment['assign-type'] !== 'variable') {
throw new CompilerException("Operator '" . $assignment['operator'] . "' is not supported assign-type: " . $assignment['assign-type']);
}

$builderExpr = BuilderFactory::getInstance();

$leftExpression = $builderExpr->variable($assignment['variable']);

$assignment['expr'] = $builderExpr->operators()
->binary($operator, $leftExpression, $builderExpr->raw($assignment['expr']))
->build();

$assignment['operator'] = AssignVariableOperator::OPERATOR_ASSIGN;
return $assignment;
}
}
3 changes: 3 additions & 0 deletions ext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ if test "$PHP_STUB" = "yes"; then
stub/invokes/invokeprotected.zep.c
stub/invokes/invokeprotectedcomplex.zep.c
stub/issettest.zep.c
stub/issue1134.zep.c
stub/issue1404.zep.c
stub/issue1521.zep.c
stub/issue2165/issue.zep.c
stub/issue663.zep.c
stub/issue887.zep.c
stub/issue893.zep.c
stub/issue914.zep.c
stub/issues.zep.c
stub/json.zep.c
Expand Down Expand Up @@ -171,6 +173,7 @@ if test "$PHP_STUB" = "yes"; then
stub/pregmatch.zep.c
stub/properties/app.zep.c
stub/properties/extendspublicproperties.zep.c
stub/properties/getobjectvars.zep.c
stub/properties/privateproperties.zep.c
stub/properties/propertyarray.zep.c
stub/properties/propertyupdate.zep.c
Expand Down
4 changes: 2 additions & 2 deletions ext/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (PHP_STUB != "no") {
}

ADD_SOURCES(configure_module_dirname + "/stub/invokes", "abstractprotected.zep.c abstractinvoker.zep.c abstractinvokercomplex.zep.c invokeprotected.zep.c invokeprotectedcomplex.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arraymanipulation.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issue663.zep.c issue887.zep.c issue914.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c reflection.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spl.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c 13__closure.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arraymanipulation.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1134.zep.c issue1404.zep.c issue1521.zep.c issue663.zep.c issue887.zep.c issue893.zep.c issue914.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c reflection.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spl.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c 13__closure.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/issue2165", "issueextendinterface.zep.c issueinterface.zep.c issue.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db", "exception.zep.c", "stub");
Expand All @@ -21,7 +21,7 @@ if (PHP_STUB != "no") {
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db/query", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/scopes", "hasprivatemethod.zep.c scopetesterinterface.zep.c abstractclass.zep.c abstractclassmagic.zep.c privatescopetester.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/ooimpl", "zbeginning.zep.c abeginning.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/properties", "publicproperties.zep.c app.zep.c extendspublicproperties.zep.c privateproperties.zep.c propertyarray.zep.c propertyupdate.zep.c protectedproperties.zep.c staticprivateproperties.zep.c staticpropertyarray.zep.c staticprotectedproperties.zep.c staticpublicproperties.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/properties", "publicproperties.zep.c app.zep.c extendspublicproperties.zep.c getobjectvars.zep.c privateproperties.zep.c propertyarray.zep.c propertyupdate.zep.c protectedproperties.zep.c staticprivateproperties.zep.c staticpropertyarray.zep.c staticprotectedproperties.zep.c staticpublicproperties.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/bench", "foo.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/builtin", "arraymethods.zep.c charmethods.zep.c intmethods.zep.c stringmethods.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/constructors", "issue1803.zep.c", "stub");
Expand Down
6 changes: 6 additions & 0 deletions ext/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ zend_class_entry *stub_invoke_ce;
zend_class_entry *stub_invokes_invokeprotected_ce;
zend_class_entry *stub_invokes_invokeprotectedcomplex_ce;
zend_class_entry *stub_issettest_ce;
zend_class_entry *stub_issue1134_ce;
zend_class_entry *stub_issue1404_ce;
zend_class_entry *stub_issue1521_ce;
zend_class_entry *stub_issue2165_issue_ce;
zend_class_entry *stub_issue663_ce;
zend_class_entry *stub_issue887_ce;
zend_class_entry *stub_issue893_ce;
zend_class_entry *stub_issue914_ce;
zend_class_entry *stub_issues_ce;
zend_class_entry *stub_json_ce;
Expand Down Expand Up @@ -199,6 +201,7 @@ zend_class_entry *stub_pdostatement_ce;
zend_class_entry *stub_pregmatch_ce;
zend_class_entry *stub_properties_app_ce;
zend_class_entry *stub_properties_extendspublicproperties_ce;
zend_class_entry *stub_properties_getobjectvars_ce;
zend_class_entry *stub_properties_privateproperties_ce;
zend_class_entry *stub_properties_propertyarray_ce;
zend_class_entry *stub_properties_propertyupdate_ce;
Expand Down Expand Up @@ -348,11 +351,13 @@ static PHP_MINIT_FUNCTION(stub)
ZEPHIR_INIT(Stub_Invokes_InvokeProtected);
ZEPHIR_INIT(Stub_Invokes_InvokeProtectedComplex);
ZEPHIR_INIT(Stub_IssetTest);
ZEPHIR_INIT(Stub_Issue1134);
ZEPHIR_INIT(Stub_Issue1404);
ZEPHIR_INIT(Stub_Issue1521);
ZEPHIR_INIT(Stub_Issue2165_Issue);
ZEPHIR_INIT(Stub_Issue663);
ZEPHIR_INIT(Stub_Issue887);
ZEPHIR_INIT(Stub_Issue893);
ZEPHIR_INIT(Stub_Issue914);
ZEPHIR_INIT(Stub_Issues);
ZEPHIR_INIT(Stub_Json);
Expand Down Expand Up @@ -420,6 +425,7 @@ static PHP_MINIT_FUNCTION(stub)
ZEPHIR_INIT(Stub_Pregmatch);
ZEPHIR_INIT(Stub_Properties_App);
ZEPHIR_INIT(Stub_Properties_ExtendsPublicProperties);
ZEPHIR_INIT(Stub_Properties_GetObjectVars);
ZEPHIR_INIT(Stub_Properties_PrivateProperties);
ZEPHIR_INIT(Stub_Properties_PropertyArray);
ZEPHIR_INIT(Stub_Properties_PropertyUpdate);
Expand Down
3 changes: 3 additions & 0 deletions ext/stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@
#include "stub/invokes/invokeprotected.zep.h"
#include "stub/invokes/invokeprotectedcomplex.zep.h"
#include "stub/issettest.zep.h"
#include "stub/issue1134.zep.h"
#include "stub/issue1404.zep.h"
#include "stub/issue1521.zep.h"
#include "stub/issue2165/issue.zep.h"
#include "stub/issue663.zep.h"
#include "stub/issue887.zep.h"
#include "stub/issue893.zep.h"
#include "stub/issue914.zep.h"
#include "stub/issues.zep.h"
#include "stub/json.zep.h"
Expand Down Expand Up @@ -166,6 +168,7 @@
#include "stub/pregmatch.zep.h"
#include "stub/properties/app.zep.h"
#include "stub/properties/extendspublicproperties.zep.h"
#include "stub/properties/getobjectvars.zep.h"
#include "stub/properties/privateproperties.zep.h"
#include "stub/properties/propertyarray.zep.h"
#include "stub/properties/propertyupdate.zep.h"
Expand Down
12 changes: 12 additions & 0 deletions ext/stub/arrayaccesstest.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e6473d

Please sign in to comment.