Skip to content

Commit

Permalink
#2407 - Remove all usages of isZE3() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Aug 31, 2023
1 parent 03a1676 commit ed4ed64
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 86 deletions.
22 changes: 3 additions & 19 deletions Library/Backends/ZendEngine2/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ class Backend extends BaseBackend
{
protected $name = 'ZendEngine2';

/**
* {@inheritdoc}
*
* @return bool
*/
public function isZE3()
{
return false;
}

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -963,12 +953,8 @@ public function checkStrictType($type, $var, CompilationContext $context)
$conditions[] = $cond.'IS_LONG';
break;
case 'bool':
if (!$this->isZE3()) {
$conditions[] = $cond.'IS_BOOL';
} else {
$conditions[] = $cond.'IS_TRUE';
$conditions[] = $cond.'IS_FALSE';
}
$conditions[] = $cond.'IS_TRUE';
$conditions[] = $cond.'IS_FALSE';
break;
case 'double':
$conditions[] = $cond.'IS_DOUBLE';
Expand Down Expand Up @@ -1031,9 +1017,7 @@ public function checkStrictType($type, $var, CompilationContext $context)
$codePrinter->output('if (EXPECTED(Z_TYPE_P('.$parameterCode.') == IS_STRING)) {');
$codePrinter->increaseLevel();
$targetVar = $var['name'];
if ($this->isZE3()) {
$targetVar = '&'.$targetVar;
}
$targetVar = '&'.$targetVar;
$codePrinter->output('zephir_get_strval('.$targetVar.', '.$var['name'].'_param);');
$codePrinter->decreaseLevel();
$codePrinter->output('} else {');
Expand Down
10 changes: 0 additions & 10 deletions Library/Backends/ZendEngine3/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ class Backend extends BackendZendEngine2
{
protected $name = 'ZendEngine3';

/**
* {@inheritdoc}
*
* @return bool
*/
public function isZE3()
{
return true;
}

/**
* {@inheritdoc}
*
Expand Down
7 changes: 0 additions & 7 deletions Library/BaseBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ public function __construct(Config $config, $kernelsPath, $templatesPath)
$this->templatesPath = $templatesPath;
}

/**
* TODO: This should not be used, temporary (until its completely refactored).
*
* @return bool
*/
abstract public function isZE3();

public function getName()
{
return $this->name;
Expand Down
20 changes: 3 additions & 17 deletions Library/Cache/StaticMethodCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,13 @@ public function get(CompilationContext $compilationContext, $method, bool $allow
}
}

$mustBeCached = false;
if (!$compilationContext->insideCycle) {
if (!($method instanceof ReflectionMethod)) {
$classDefinition = $method->getClassDefinition();
if (!$classDefinition->isBundled() && $allowNtsCache) {
$mustBeCached = !$compilationContext->backend->isZE3();
} else {
if (!$method->isPrivate() && !$method->isFinal()) {
return 'NULL, 0';
}
}
} else {
if (!$method->isPrivate() && !$method->isFinal()) {
return 'NULL, 0';
}
}
if (!$compilationContext->insideCycle && !$method->isPrivate() && !$method->isFinal()) {
return 'NULL, 0';
}

$functionCache = $compilationContext->symbolTable->getTempVariableForWrite('zephir_fcall_cache_entry', $compilationContext);

if ($method->isPrivate() || $method->isFinal() || $mustBeCached) {
if ($method->isPrivate() || $method->isFinal()) {
$cacheSlot = SlotsCache::getMethodSlot($method);
} else {
$cacheSlot = '0';
Expand Down
12 changes: 4 additions & 8 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,8 @@ public function compile(CompilationContext $compilationContext): void
$compilationContext
);

$argInfo->setBooleanDefinition($this->compiler->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL');
$argInfo->setRichFormat($this->compiler->backend->isZE3());
$argInfo->setBooleanDefinition('_IS_BOOL');
$argInfo->setRichFormat(true);

$argInfo->render();
}
Expand All @@ -1314,9 +1314,7 @@ public function compile(CompilationContext $compilationContext): void
foreach ($methods as $method) {
if (self::TYPE_CLASS === $this->getType()) {
if (!$method->isInternal()) {
$richFormat = $this->compiler->backend->isZE3() &&
$method->isReturnTypesHintDetermined() &&
$method->areReturnTypesCompatible();
$richFormat = $method->isReturnTypesHintDetermined() && $method->areReturnTypesCompatible();

if ($richFormat || $method->hasParameters()) {
$codePrinter->output(
Expand Down Expand Up @@ -1358,9 +1356,7 @@ public function compile(CompilationContext $compilationContext): void
}
}
} else {
$richFormat = $this->compiler->backend->isZE3() &&
$method->isReturnTypesHintDetermined() &&
$method->areReturnTypesCompatible();
$richFormat = $method->isReturnTypesHintDetermined() && $method->areReturnTypesCompatible();

if ($method->isStatic()) {
if ($richFormat || $method->hasParameters()) {
Expand Down
18 changes: 6 additions & 12 deletions Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1690,19 +1690,15 @@ public function compile(CompilationContext $compilationContext): void
case 'mixed':
$symbol = $symbolTable->addVariable($parameter['data-type'], $parameter['name'], $compilationContext);
/* TODO: Move this to the respective backend, which requires refactoring how this works */
if ($compilationContext->backend->isZE3()) {
$symbol->setIsDoublePointer(true);
$substituteVars[$parameter['name']] = $symbolTable->addVariable('variable', $parameter['name'].'_sub', $compilationContext);
}
$symbol->setIsDoublePointer(true);
$substituteVars[$parameter['name']] = $symbolTable->addVariable('variable', $parameter['name'].'_sub', $compilationContext);
break;

default:
$symbol = $symbolTable->addVariable($parameter['data-type'], $parameter['name'], $compilationContext);
$symbolParam = $symbolTable->addVariable('variable', $parameter['name'].'_param', $compilationContext);
/* TODO: Move this to the respective backend, which requires refactoring how this works */
if ($compilationContext->backend->isZE3()) {
$symbolParam->setIsDoublePointer(true);
}
$symbolParam->setIsDoublePointer(true);

if ('string' == $parameter['data-type'] || 'array' == $parameter['data-type']) {
$symbol->setMustInitNull(true);
Expand Down Expand Up @@ -1928,11 +1924,9 @@ public function compile(CompilationContext $compilationContext): void
$targetVar = $compilationContext->symbolTable->getVariableForWrite($name, $compilationContext);
$initCode .= "\t".$compilationContext->backend->ifVariableValueUndefined($targetVar, $compilationContext, false, false).PHP_EOL;

if ($compilationContext->backend->isZE3()) {
if ($targetVar->isDoublePointer() && isset($substituteVars[$parameter['name']])) {
$substituteVar = $substituteVars[$parameter['name']];
$initCode .= "\t\t".$targetVar->getName().' = &'.$substituteVar->getName().';'.PHP_EOL;
}
if ($targetVar->isDoublePointer() && isset($substituteVars[$parameter['name']])) {
$substituteVar = $substituteVars[$parameter['name']];
$initCode .= "\t\t".$targetVar->getName().' = &'.$substituteVar->getName().';'.PHP_EOL;
}
$initCode .= $this->assignDefaultValue($parameter, $compilationContext);

Expand Down
8 changes: 3 additions & 5 deletions Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1884,17 +1884,15 @@ public function generateFunctionInformation(): array

$headerPrinter->output('PHP_FUNCTION('.$funcName.');');

$argInfo->setBooleanDefinition($this->backend->isZE3() ? '_IS_BOOL' : 'IS_BOOL');
$argInfo->setRichFormat($this->backend->isZE3());
$argInfo->setBooleanDefinition('_IS_BOOL');
$argInfo->setRichFormat(true);

$argInfo->render();

/** Generate FE's */
$paramData = 'NULL';

$richFormat = $this->backend->isZE3() &&
$func->isReturnTypesHintDetermined() &&
$func->areReturnTypesCompatible();
$richFormat = $func->isReturnTypesHintDetermined() && $func->areReturnTypesCompatible();

if ($richFormat || $func->hasParameters()) {
$paramData = $argInfoName;
Expand Down
3 changes: 1 addition & 2 deletions Library/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,11 @@ protected function markReferences(
if ($numberParameters > 0) {
$n = 1;
$funcParameters = $reflector->getParameters();
$isZendEngine3 = $compilationContext->backend->isZE3();
foreach ($funcParameters as $parameter) {
if ($numberParameters >= $n) {
if ($parameter->isPassedByReference()) {
/* TODO hack, fix this better */
if ($isZendEngine3 && '&' == $parameters[$n - 1][0]) {
if ('&' === $parameters[$n - 1][0]) {
$parameters[$n - 1] = substr($parameters[$n - 1], 1);
}

Expand Down
2 changes: 1 addition & 1 deletion Library/Operators/Other/InstanceOfOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private function prepareBackendSpecificCode($variable, CompilationContext $conte
{
return strtr('Z_STRVAL_P(:p:name), Z_STRLEN_P(:p:name)', [
':name' => $variable,
':p' => $context->backend->isZE3() ? '&' : '',
':p' => '&',
]);
}
}
6 changes: 1 addition & 5 deletions Library/Statements/TryCatchStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ public function compile(CompilationContext $compilationContext)
$variable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $compilationContext);
}

if ($compilationContext->backend->isZE3()) {
$assignExceptionVarStmt = $exprBuilder->statements()->rawC('ZEPHIR_CPY_WRT(&'.$variable->getName().', &'.$exc_var->getName().');');
} else {
$assignExceptionVarStmt = $exprBuilder->statements()->rawC('ZEPHIR_CPY_WRT('.$variable->getName().', '.$exc_var->getName().');');
}
$assignExceptionVarStmt = $exprBuilder->statements()->rawC('ZEPHIR_CPY_WRT(&'.$variable->getName().', &'.$exc_var->getName().');');

/*
* TODO:, use a builder here
Expand Down

0 comments on commit ed4ed64

Please sign in to comment.