Skip to content

Commit

Permalink
Create implicit temporary value when an optimizer does require a retu…
Browse files Browse the repository at this point in the history
…rn value, fixing PSR2
  • Loading branch information
andresgutierrez committed Oct 24, 2014
1 parent c78fa3f commit fe25f1b
Show file tree
Hide file tree
Showing 37 changed files with 65 additions and 65 deletions.
10 changes: 8 additions & 2 deletions Library/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,17 @@ public function mustInitSymbolVariable()
/**
* Returns the symbol variable that must be returned by the call
*
* @param boolean $useTemp
* @param CompilationContext $compilationContext
* @return Variable
*/
public function getSymbolVariable()
public function getSymbolVariable($useTemp = false, CompilationContext $compilationContext = null)
{
return $this->_symbolVariable;
$symbolVariable = $this->_symbolVariable;
if ($useTemp && !is_object($symbolVariable)) {
return $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
}
return $symbolVariable;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Arithmetical/DivOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function compile($expression, CompilationContext $compilationContext)
return new CompiledExpression('double', 'zephir_safe_div_long_long(' . $left->getCode() . ', ' . $right->getCode() . ' TSRMLS_CC)', $expression);

case 'double':
return new CompiledExpression('double', 'zephir_safe_div_long_double(' . $left->getCode() . ', ' . $right->getCode() . ' TSRMLS_CC)', $expression);
return new CompiledExpression('double', 'zephir_safe_div_long_double(' . $left->getCode() . ', ' . $right->getCode() . ' TSRMLS_CC)', $expression);

case 'variable':
$variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']);
Expand Down Expand Up @@ -369,7 +369,7 @@ public function compile($expression, CompilationContext $compilationContext)
}
break;

case 'double':
case 'double':
$compilationContext->headersManager->add('kernel/operators');
if ($variableLeft->isLocalOnly()) {
$op1 = '&' . $variableLeft->getName();
Expand Down Expand Up @@ -472,7 +472,7 @@ public function compile($expression, CompilationContext $compilationContext)
return new CompiledExpression('double', 'zephir_safe_div_zval_long(' . $op1 . ', ' . $op2 . ' TSRMLS_CC)', $expression);

case 'double':
$compilationContext->headersManager->add('kernel/operators');
$compilationContext->headersManager->add('kernel/operators');
if ($variableLeft->isLocalOnly()) {
$op1 = '&' . $variableLeft->getName();
} else {
Expand Down
3 changes: 2 additions & 1 deletion Library/Optimizers/FunctionCall/AddcslashesOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);

if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
3 changes: 2 additions & 1 deletion Library/Optimizers/FunctionCall/AddslashesOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);

if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
3 changes: 2 additions & 1 deletion Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);

if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/BasenameOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable) {

if ($symbolVariable->isNotVariableAndString()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable) {
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/CamelizeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/CreateArrayOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable) {
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/EvalOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/ExplodeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable) {
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/FilemtimeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable) {
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/GetClassNsOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/GetClassOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/GetNsClassOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/GettypeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/ImplodeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
3 changes: 2 additions & 1 deletion Library/Optimizers/FunctionCall/JoinOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);

if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
15 changes: 5 additions & 10 deletions Library/Optimizers/FunctionCall/JsonEncodeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable) {
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
} else {
$symbolVariable = $context->symbolTable->addTemp('variable', $context);
$symbolVariable = $call->getSymbolVariable(true, $context);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}

Expand Down
16 changes: 6 additions & 10 deletions Library/Optimizers/FunctionCall/PregMatchOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable) {
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
} else {
$symbolVariable = $context->symbolTable->addTemp('variable', $context);
$symbolVariable = $call->getSymbolVariable(true, $context);

if (!$symbolVariable->isVariable()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}

Expand Down
14 changes: 6 additions & 8 deletions Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable) {
$symbolVariable = $call->getSymbolVariable(true, $context);

if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}

if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}

$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
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 @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/StrposOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/StrtolowerOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/StrtoupperOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/SubstrOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
3 changes: 2 additions & 1 deletion Library/Optimizers/FunctionCall/TrimOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);

if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
2 changes: 1 addition & 1 deletion Library/Optimizers/FunctionCall/UncamelizeOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
Expand Down
Loading

0 comments on commit fe25f1b

Please sign in to comment.