Skip to content

Commit

Permalink
Merge pull request #2206 from zephir-lang/development
Browse files Browse the repository at this point in the history
0.13.2
  • Loading branch information
AlexNDRmac authored Apr 10, 2021
2 parents 99f0e65 + 0313552 commit c23c2ab
Show file tree
Hide file tree
Showing 304 changed files with 6,053 additions and 7,228 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org).

## [Unreleased]


## [0.13.2] - 2021-04-10
### Fixed
- Fixed default value of nullable string parameter [#2180](https://github.com/zephir-lang/zephir/issues/2180)
- Fixed cast of `string` to `int` and `float` [#828](https://github.com/zephir-lang/zephir/issues/828)
- Fix `uint` cast to `unsigned int` in function params [#812](https://github.com/zephir-lang/zephir/issues/812)
- Fixed `null` strict check when variable is `string` type [#2186](https://github.com/zephir-lang/zephir/issues/2186)

## [0.13.1] - 2021-03-31
### Added
- Added jobs `-j, --jobs` option for `zephir compile` [#2174](https://github.com/zephir-lang/zephir/issues/2174)
Expand Down Expand Up @@ -447,7 +455,8 @@ and this project adheres to [Semantic Versioning](http://semver.org).
- Fixed casting resource to int (only ZendEngine 3)
[#1524](https://github.com/zephir-lang/zephir/issues/1524)

[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.13.1...HEAD
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.13.2...HEAD
[0.13.2]: https://github.com/zephir-lang/zephir/compare/0.13.0...0.13.2
[0.13.1]: https://github.com/zephir-lang/zephir/compare/0.13.0...0.13.1
[0.13.0]: https://github.com/zephir-lang/zephir/compare/0.12.21...0.13.0
[0.12.21]: https://github.com/zephir-lang/zephir/compare/0.12.20...0.12.21
Expand Down
22 changes: 14 additions & 8 deletions Library/Backends/ZendEngine2/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function declareVariables($method, $typeToVariables, CompilationContext $
$code .= ' ';
$groupVariables = [];

/*
/**
* @var Variable[]
*/
foreach ($variables as $variable) {
Expand Down Expand Up @@ -1009,10 +1009,12 @@ public function checkStrictType($type, $var, CompilationContext $context)
/* Assign param */
switch ($type) {
case 'int':
case 'uint':
case 'long':
$codePrinter->output($var['name'].' = Z_LVAL_P('.$parameterCode.');');
break;
case 'uint':
$codePrinter->output($var['name'].' = ZEND_ABS(Z_LVAL_P('.$parameterCode.'));');
break;
case 'bool':
$codePrinter->output($var['name'].' = '.$this->getBoolCode($parameterVariable, $context, false).';');
break;
Expand Down Expand Up @@ -1068,11 +1070,11 @@ public function getScalarTempVariable(
/**
* Assign value to variable helper.
*
* @param string $macro
* @param string $variableName
* @param string|Variable $value
* @param CompilationContext $context
* @param bool $useCodePrinter
* @param string $macro
* @param string $variableName
* @param string|null|Variable $value
* @param CompilationContext $context
* @param bool $useCodePrinter
*
* @return string
*/
Expand All @@ -1083,10 +1085,14 @@ protected function assignHelper(
CompilationContext $context,
bool $useCodePrinter
): string {
if ($value === null && $macro === 'ZVAL_STRING') {
return '';
}

if ($value instanceof Variable) {
$value = $value->getName();
} else {
$value = 'ZVAL_STRING' == $macro ? '"'.$value.'"' : $value;
$value = 'ZVAL_STRING' === $macro ? '"'.$value.'"' : $value;
}

$output = $macro.'('.$variableName.', '.$value.');';
Expand Down
11 changes: 5 additions & 6 deletions Library/Backends/ZendEngine3/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function getTypeDefinition($type)
return ['*', 'zend_string'];
}

$code = null;
$pointer = null;
switch ($type) {
case 'int':
Expand Down Expand Up @@ -532,10 +531,10 @@ public function getInternalSignature(ClassMethod $method, CompilationContext $co
/**
* {@inheritdoc}
*
* @param Variable $variable
* @param string|Variable $value
* @param CompilationContext $context
* @param bool $useCodePrinter
* @param Variable $variable
* @param string|null|Variable $value
* @param CompilationContext $context
* @param bool $useCodePrinter
*
* @return string
*/
Expand Down Expand Up @@ -1160,7 +1159,7 @@ public function ifVariableValueUndefined(Variable $var, CompilationContext $cont
if ($var->isDoublePointer()) {
return parent::ifVariableValueUndefined($var, $context, $useBody, $useCodePrinter);
}
$body = 'Z_TYPE_P('.$this->getVariableCode($var).') == IS_UNDEF';
$body = 'ZEPHIR_IS_EMPTY('.$this->getVariableCode($var).')';
$output = 'if ('.$body.') {';
if ($useCodePrinter) {
$context->codePrinter->output($output);
Expand Down
2 changes: 2 additions & 0 deletions Library/Backends/ZendEngine3/VariablesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class VariablesManager
* Meant for Backend::initializeVariableDefaults.
* Shouldn't called directly.
*
* TODO: Figure out why it never reached during generation.
*
* @param Variable $variable
* @param array $value
* @param Context $context
Expand Down
8 changes: 4 additions & 4 deletions Library/BaseBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ abstract public function declareConstant($type, $name, $value, CompilationContex
/**
* Assign value to variable.
*
* @param Variable $variable
* @param string|Variable $value
* @param CompilationContext $context
* @param bool $useCodePrinter
* @param Variable $variable
* @param string|null|Variable $value
* @param CompilationContext $context
* @param bool $useCodePrinter
*
* @return string
*/
Expand Down
15 changes: 6 additions & 9 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ final class ClassDefinition extends AbstractClassDefinition
protected array $constants = [];

/**
* @var array
* @var ClassMethod[]
*/
protected array $methods = [];

Expand Down Expand Up @@ -1077,8 +1077,8 @@ public function compile(CompilationContext $compilationContext): void
* The ZEPHIR_INIT_CLASS defines properties and constants exported by the class.
*/
$initClassName = $this->getCNamespace().'_'.$this->getName();
$codePrinter->output('ZEPHIR_INIT_CLASS('.$initClassName.') {');
$codePrinter->outputBlankLine();
$codePrinter->output('ZEPHIR_INIT_CLASS('.$initClassName.')');
$codePrinter->output('{');
$codePrinter->increaseLevel();

/**
Expand Down Expand Up @@ -1257,8 +1257,6 @@ public function compile(CompilationContext $compilationContext): void
}

$codePrinter->output('return SUCCESS;');

$codePrinter->outputBlankLine();
$codePrinter->decreaseLevel();

$codePrinter->output('}');
Expand All @@ -1275,12 +1273,11 @@ public function compile(CompilationContext $compilationContext): void

if (self::TYPE_CLASS === $this->getType()) {
if (!$method->isInternal()) {
$codePrinter->output('PHP_METHOD('.$this->getCNamespace().'_'.$this->getName().', '.$method->getName().') {');
$codePrinter->output('PHP_METHOD('.$this->getCNamespace().'_'.$this->getName().', '.$method->getName().')');
} else {
$codePrinter->output($compilationContext->backend->getInternalSignature($method, $compilationContext).' {');
$codePrinter->output($compilationContext->backend->getInternalSignature($method, $compilationContext));
}

$codePrinter->outputBlankLine();
$codePrinter->output('{');

if (!$method->isAbstract()) {
$method->compile($compilationContext);
Expand Down
75 changes: 19 additions & 56 deletions Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1787,45 +1787,11 @@ public function compile(CompilationContext $compilationContext): void
/**
* Round 2. Fetch the parameters in the method.
*/
$params = [];
$numberRequiredParams = 0;
$numberOptionalParams = 0;
foreach ($this->parameters->getParameters() as $parameter) {
if (isset($parameter['data-type'])) {
$dataType = $parameter['data-type'];
} else {
$dataType = 'variable';
}

switch ($dataType) {
case 'object':
case 'callable':
case 'resource':
case 'variable':
if (!$this->isInternal()) {
$params[] = '&'.$parameter['name'];
} else {
$params[] = $parameter['name'];
}
break;

default:
if (!$this->isInternal()) {
$params[] = '&'.$parameter['name'].'_param';
} else {
$params[] = $parameter['name'].'_param';
}
break;
}

if (isset($parameter['default'])) {
$optionalParams[] = $parameter;
++$numberOptionalParams;
} else {
$requiredParams[] = $parameter;
++$numberRequiredParams;
}
}
$params = $this->parameters->fetchParameters($this->isInternal);
$numberRequiredParams = $this->parameters->countRequiredParameters();
$numberOptionalParams = $this->parameters->countOptionalParameters();
$requiredParams = $this->parameters->getRequiredParameters();
$optionalParams = $this->parameters->getOptionalParameters();

/**
* Pass the write detector to the method statement block to check if the parameter
Expand All @@ -1838,11 +1804,7 @@ public function compile(CompilationContext $compilationContext): void
}

foreach ($this->parameters->getParameters() as $parameter) {
if (isset($parameter['data-type'])) {
$dataType = $parameter['data-type'];
} else {
$dataType = 'variable';
}
$dataType = $parameter['data-type'] ?? 'variable';

switch ($dataType) {
case 'variable':
Expand Down Expand Up @@ -1972,8 +1934,6 @@ public function compile(CompilationContext $compilationContext): void
$compilationContext->codePrinter = $realCodePrinter;
}
}

$code .= PHP_EOL;
}

$code .= $initCode.$initVarCode;
Expand Down Expand Up @@ -2039,17 +1999,19 @@ public function compile(CompilationContext $compilationContext): void
);
continue;
}

$compilationContext->logger->warning(
'Variable "'.$variable->getName().'" declared but not used in '.$completeName.'::'.$this->getName(),
['unused-variable-external', $variable->getOriginal()]
);
}

if ('this_ptr' != $variable->getName() && 'return_value' != $variable->getName() && 'return_value_ptr' != $variable->getName()) {
if ('this_ptr' !== $variable->getName() && 'return_value' !== $variable->getName() && 'return_value_ptr' !== $variable->getName()) {
$type = $variable->getType();
if (!isset($usedVariables[$type])) {
$usedVariables[$type] = [];
}

$usedVariables[$type][] = $variable;
}
}
Expand All @@ -2059,18 +2021,18 @@ public function compile(CompilationContext $compilationContext): void
* Warn whenever a variable is unused aside from its declaration.
*/
foreach ($symbolTable->getVariables() as $variable) {
if (true == $variable->isExternal() || $variable->isTemporal()) {
if ($variable->isExternal() || $variable->isTemporal()) {
continue;
}

if ('this_ptr' == $variable->getName() || 'return_value' == $variable->getName() || 'return_value_ptr' == $variable->getName() || 'ZEPHIR_LAST_CALL_STATUS' == $variable->getName()) {
if ('this_ptr' === $variable->getName() || 'return_value' === $variable->getName() || 'return_value_ptr' === $variable->getName() || 'ZEPHIR_LAST_CALL_STATUS' === $variable->getName()) {
continue;
}

if (!$variable->isUsed()) {
$node = $variable->getLastUsedNode();
if (is_array($node)) {
$expression = isset($node['expr']) ? $node['expr'] : $node;
$expression = $node['expr'] ?? $node;
$compilationContext->logger->warning(
'Variable "'.$variable->getName().'" assigned but not used in '.$completeName.'::'.$this->getName(),
['unused-variable', $expression]
Expand All @@ -2092,14 +2054,14 @@ public function compile(CompilationContext $compilationContext): void
* ZEND_PARSE_PARAMETERS
*/
$tempCodePrinter = new CodePrinter();
if ($this->parameters instanceof ClassMethodParameters && !empty($this->parameters->getParameters())) {
if ($this->parameters instanceof ClassMethodParameters && $this->parameters->count() > 0) {
$tempCodePrinter->output('#if PHP_VERSION_ID >= 80000');
$tempCodePrinter->output("\t".'bool is_null_true = 1;');

$tempCodePrinter->output(sprintf(
"\t".'ZEND_PARSE_PARAMETERS_START(%d, %d)',
count($requiredParams),
count($requiredParams) + count($optionalParams)
$this->parameters->countRequiredParameters(),
$this->parameters->count()
));

foreach ($requiredParams as $requiredParam) {
Expand All @@ -2115,7 +2077,6 @@ public function compile(CompilationContext $compilationContext): void
}

$tempCodePrinter->output("\t".'ZEND_PARSE_PARAMETERS_END();');
$tempCodePrinter->outputBlankLine();
$tempCodePrinter->output('#endif');
}

Expand Down Expand Up @@ -2176,7 +2137,7 @@ public function compile(CompilationContext $compilationContext): void
/**
* Restore the compilation context
*/
$oldCodePrinter->output($code);
$oldCodePrinter->output($code, false);
$compilationContext->codePrinter = $oldCodePrinter;

$compilationContext->branchManager = null;
Expand Down Expand Up @@ -2228,7 +2189,7 @@ public function hasChildReturnStatementType(array $statement): bool
} else {
$statements = $statement['statements'];
foreach ($statements as $item) {
$type = isset($item['type']) ? $item['type'] : null;
$type = $item['type'] ?? null;
if ('return' === $type || 'throw' === $type) {
return true;
}
Expand Down Expand Up @@ -2406,6 +2367,8 @@ public function detectParam(array $parameter, CompilationContext $compilationCon
break;

case 'int':
case 'uint':
case 'long':
if ($hasDefaultNull) {
$param = sprintf('Z_PARAM_LONG_OR_NULL(%s, is_null_true)', $name);
} else {
Expand Down
Loading

0 comments on commit c23c2ab

Please sign in to comment.