Skip to content

Commit

Permalink
#2407 - Remove wrapped method getVariableCodePointer()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Aug 31, 2023
1 parent e9a8831 commit 0c1d61e
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 37 deletions.
36 changes: 12 additions & 24 deletions Library/Backend/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Backend
protected FcallManagerInterface $fcallManager;

/**
* BaseBackend constructor.
*
* @param Config $config
* @param string $kernelsPath
* @param string $templatesPath
Expand Down Expand Up @@ -135,16 +133,6 @@ public function getVariableCode(Variable $variable): string
return '&'.$variable->getName();
}

/**
* {@inheritdoc}
*
* TODO: Do we need this method at all?
*/
public function getVariableCodePointer(Variable $variable)
{
return $this->getVariableCode($variable);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -800,7 +788,7 @@ public function arrayIssetFetch(Variable $target, Variable $var, $resolvedExpr,

public function arrayIssetFetch2(Variable $target, Variable $var, $resolvedExpr, $flags, $expression, CompilationContext $context)
{
$code = $this->getVariableCodePointer($target).', '.$this->getVariableCode($var);
$code = $this->getVariableCode($target).', '.$this->getVariableCode($var);

if (!($resolvedExpr instanceof Variable)) {
if ('string' === $resolvedExpr->getType()) {
Expand Down Expand Up @@ -829,7 +817,7 @@ public function propertyIsset(Variable $var, $key, CompilationContext $context)
public function arrayUnset(Variable $variable, $exprIndex, $flags, CompilationContext $context)
{
$context->headersManager->add('kernel/array');
$variableCode = $this->getVariableCodePointer($variable);
$variableCode = $this->getVariableCode($variable);
if ('string' == $exprIndex->getType()) {
$context->codePrinter->output('zephir_array_unset_string('.$variableCode.', SL("'.$exprIndex->getCode().'"), '.$flags.');');

Expand All @@ -842,7 +830,7 @@ public function arrayUnset(Variable $variable, $exprIndex, $flags, CompilationCo
public function arrayUnset2(Variable $variable, $exprIndex, $flags, CompilationContext $context)
{
$context->headersManager->add('kernel/array');
$variableCode = $this->getVariableCodePointer($variable);
$variableCode = $this->getVariableCode($variable);
switch ($exprIndex->getType()) {
case 'int':
case 'uint':
Expand Down Expand Up @@ -1379,7 +1367,7 @@ public function initArray(Variable $variable, CompilationContext $context, ?int

public function concatSelf(Variable $variable, Variable $itemVariable, CompilationContext $context)
{
$variable = $this->getVariableCodePointer($variable);
$variable = $this->getVariableCode($variable);
$itemVariable = $this->getVariableCode($itemVariable);
$context->codePrinter->output('zephir_concat_self('.$variable.', '.$itemVariable.');');
}
Expand All @@ -1395,13 +1383,13 @@ public function updateArray(Variable $symbolVariable, $key, $value, CompilationC
switch ($key->getType()) {
case 'string':
case 'variable':
$compilationContext->codePrinter->output('zephir_array_update_zval('.$this->getVariableCodePointer($symbolVariable).', '.$this->getVariableCode($key).', '.$value.', '.$flags.');');
$compilationContext->codePrinter->output('zephir_array_update_zval('.$this->getVariableCode($symbolVariable).', '.$this->getVariableCode($key).', '.$value.', '.$flags.');');
break;

case 'int':
case 'uint':
case 'long':
$compilationContext->codePrinter->output('zephir_array_update_long('.$this->getVariableCodePointer($symbolVariable).', '.$key->getName().', '.$value.', '.$flags.' ZEPHIR_DEBUG_PARAMS_DUMMY);');
$compilationContext->codePrinter->output('zephir_array_update_long('.$this->getVariableCode($symbolVariable).', '.$key->getName().', '.$value.', '.$flags.' ZEPHIR_DEBUG_PARAMS_DUMMY);');
break;

default:
Expand All @@ -1410,11 +1398,11 @@ public function updateArray(Variable $symbolVariable, $key, $value, CompilationC
} elseif ($key instanceof CompiledExpression) {
switch ($key->getType()) {
case 'string':
$compilationContext->codePrinter->output('zephir_array_update_string('.$this->getVariableCodePointer($symbolVariable).', SL("'.$key->getCode().'"), '.$value.', '.$flags.');');
$compilationContext->codePrinter->output('zephir_array_update_string('.$this->getVariableCode($symbolVariable).', SL("'.$key->getCode().'"), '.$value.', '.$flags.');');
break;

case 'int':
$compilationContext->codePrinter->output('zephir_array_update_long('.$this->getVariableCodePointer($symbolVariable).', '.$key->getCode().', '.$value.', '.$flags.' ZEPHIR_DEBUG_PARAMS_DUMMY);');
$compilationContext->codePrinter->output('zephir_array_update_long('.$this->getVariableCode($symbolVariable).', '.$key->getCode().', '.$value.', '.$flags.' ZEPHIR_DEBUG_PARAMS_DUMMY);');
break;

case 'variable':
Expand Down Expand Up @@ -1471,7 +1459,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA
);
}
if ($isVariable && in_array($index->getType(), ['variable', 'string', 'mixed'])) {
$output = 'zephir_array_fetch('.$this->getVariableCodePointer($var).', '.$this->getVariableCode($src).', '.$this->getVariableCode($index).', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');';
$output = 'zephir_array_fetch('.$this->getVariableCode($var).', '.$this->getVariableCode($src).', '.$this->getVariableCode($index).', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');';
} else {
if ($isVariable) {
$indexAccess = $this->getVariableCode($index);
Expand All @@ -1481,7 +1469,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA
$indexAccess = 'SL("'.$indexAccess.'")';
}
}
$output = 'zephir_array_fetch_'.$type.'('.$this->getVariableCodePointer($var).', '.$this->getVariableCode($src).', '.$indexAccess.', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');';
$output = 'zephir_array_fetch_'.$type.'('.$this->getVariableCode($var).', '.$this->getVariableCode($src).', '.$indexAccess.', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');';
}

if ($useCodePrinter) {
Expand All @@ -1496,7 +1484,7 @@ public function assignArrayMulti(Variable $variable, $symbolVariable, $offsetExp
list($keys, $offsetItems, $numberParams) = $this->resolveOffsetExprs($offsetExprs, $compilationContext);

$symbol = $this->resolveValue($symbolVariable, $compilationContext, true);
$varCode = $this->getVariableCodePointer($variable);
$varCode = $this->getVariableCode($variable);
$compilationContext->codePrinter->output(
sprintf(
'zephir_array_update_multi(%s, %s, SL("%s"), %d, %s);',
Expand Down Expand Up @@ -1559,7 +1547,7 @@ public function callDynamicFunction($symbolVariable, Variable $variable, Compila
} elseif ('return_value' == $symbolVariable->getName()) {
$context->codePrinter->output('ZEPHIR_RETURN_CALL_ZVAL_FUNCTION('.$this->getVariableCode($variable).', '.$cache.', '.$cacheSlot.$paramStr.');');
} else {
$context->codePrinter->output('ZEPHIR_CALL_ZVAL_FUNCTION('.$this->getVariableCodePointer($symbolVariable).', '.$this->getVariableCode($variable).', '.$cache.', '.$cacheSlot.$paramStr.');');
$context->codePrinter->output('ZEPHIR_CALL_ZVAL_FUNCTION('.$this->getVariableCode($symbolVariable).', '.$this->getVariableCode($variable).', '.$cache.', '.$cacheSlot.$paramStr.');');
}
}

Expand Down
2 changes: 1 addition & 1 deletion Library/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ protected function _callNormal(array $expression, CompilationContext $compilatio
* We don't know the exact dynamic type returned by the method call
*/
$symbolVariable->setDynamicTypes('undefined');
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Library/MethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ public function compile(Expression $expr, CompilationContext $compilationContext
} else {
//TODO: also move to backend
if ($isExpecting) {
$symbolCode = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbolCode = $compilationContext->backend->getVariableCode($symbolVariable);
}
$variableCode = $compilationContext->backend->getVariableCode($variableVariable);
$paramCount = \count($params);
Expand Down
4 changes: 2 additions & 2 deletions Library/Operators/Other/FetchOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function compile(array $expression, CompilationContext $compilationContex
$property = $expression['right']['right']['value'];

$compilationContext->headersManager->add('kernel/object');
$symbol = $compilationContext->backend->getVariableCodePointer($variable);
$symbol = $compilationContext->backend->getVariableCode($variable);
$evalSymbol = $compilationContext->backend->getVariableCode($evalVariable);

return new CompiledExpression('bool', 'zephir_fetch_property('.$symbol.', '.$evalSymbol.', SL("'.$property.'"), PH_SILENT_CC)', $expression);
Expand Down Expand Up @@ -178,7 +178,7 @@ public function compile(array $expression, CompilationContext $compilationContex

$compilationContext->headersManager->add('kernel/object');

$symbol = $compilationContext->backend->getVariableCodePointer($variable);
$symbol = $compilationContext->backend->getVariableCode($variable);
$evalSymbol = $compilationContext->backend->getVariableCode($evalVariable);
$evalPropertySymbol = $compilationContext->backend->getVariableCode($evalVariableProperty);

Expand Down
2 changes: 1 addition & 1 deletion Library/Operators/Other/RequireOnceOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function compile(array $expression, CompilationContext $compilationContex

if ($symbolVariable) {
$codePrinter->output('ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(&'.$symbolVariable->getName().');');
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
$codePrinter->output('if (zephir_require_once_zval_ret('.$symbol.', '.$exprVar.') == FAILURE) {');
} else {
$codePrinter->output('if (zephir_require_once_zval('.$exprVar.') == FAILURE) {');
Expand Down
2 changes: 1 addition & 1 deletion Library/Operators/Other/RequireOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function compile(array $expression, CompilationContext $compilationContex

if ($symbolVariable) {
$codePrinter->output('ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(&'.$symbolVariable->getName().');');
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
$codePrinter->output('if (zephir_require_zval_ret('.$symbol.', '.$exprVar.') == FAILURE) {');
} else {
$codePrinter->output('if (zephir_require_zval('.$exprVar.') == FAILURE) {');
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/StrReplaceOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
}
}

$symbol = $context->backend->getVariableCodePointer($symbolVariable);
$symbol = $context->backend->getVariableCode($symbolVariable);

$context->codePrinter->output('zephir_fast_str_replace('.$symbol.', '.$resolvedParams[0].', '.$resolvedParams[1].', '.$resolvedParams[2].');');

Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/VarDumpOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$variable = $context->symbolTable->getVariableForRead($resolvedParam->getCode(), $context, $expression);
}

$symbol = $context->backend->getVariableCodePointer($variable);
$symbol = $context->backend->getVariableCode($variable);
$context->codePrinter->output('zephir_var_dump('.$symbol.');');
}

Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/VarExportOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$variable = $context->symbolTable->getVariableForRead($resolvedParam->getCode(), $context, $expression);
}
$variableSymbol = $context->backend->getVariableCodePointer($variable);
$variableSymbol = $context->backend->getVariableCode($variable);

/*
* let a = var_export(val);
Expand Down
8 changes: 4 additions & 4 deletions Library/StaticCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ protected function call(
}

if ($symbolVariable) {
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
}

$paramCount = count($params);
Expand Down Expand Up @@ -462,7 +462,7 @@ protected function callFromClass($methodName, array $expression, $symbolVariable
}

if ($symbolVariable) {
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
}

$paramCount = count($params);
Expand Down Expand Up @@ -556,7 +556,7 @@ protected function callFromDynamicClass($methodName, array $expression, $symbolV
$classEntry = $classEntryVariable->getName();

if ($symbolVariable) {
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
}

if (!count($params)) {
Expand Down Expand Up @@ -652,7 +652,7 @@ protected function callFromDynamicClassDynamicMethod(array $expression, $symbolV
}

if ($symbolVariable) {
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$symbol = $compilationContext->backend->getVariableCode($symbolVariable);
}

if (!count($params)) {
Expand Down

0 comments on commit 0c1d61e

Please sign in to comment.