Permalink
Browse files

Fix optimizers to init symbolVariable as late as possible

If a symbol variable is also included in a resolved expression,
it may be overwritten due to initVariant.
  • Loading branch information...
steffen
steffen committed May 30, 2015
1 parent 697408e commit be1dbe40b332a7328bf0598159cb27bba33a17fe
Showing with 154 additions and 180 deletions.
  1. +3 −4 Library/Optimizers/FunctionCall/AddcslashesOptimizer.php
  2. +3 −4 Library/Optimizers/FunctionCall/AddslashesOptimizer.php
  3. +3 −4 Library/Optimizers/FunctionCall/ArrayKeysOptimizer.php
  4. +3 −4 Library/Optimizers/FunctionCall/ArrayMergeOptimizer.php
  5. +4 −4 Library/Optimizers/FunctionCall/BasenameOptimizer.php
  6. +4 −3 Library/Optimizers/FunctionCall/CallUserFuncArrayOptimizer.php
  7. +4 −3 Library/Optimizers/FunctionCall/CallUserFuncOptimizer.php
  8. +3 −4 Library/Optimizers/FunctionCall/Crc32Optimizer.php
  9. +4 −4 Library/Optimizers/FunctionCall/CreateArrayOptimizer.php
  10. +3 −4 Library/Optimizers/FunctionCall/CreateInstanceOptimizer.php
  11. +4 −5 Library/Optimizers/FunctionCall/CreateInstanceParamsOptimizer.php
  12. +4 −5 Library/Optimizers/FunctionCall/EvalOptimizer.php
  13. +4 −5 Library/Optimizers/FunctionCall/ExplodeOptimizer.php
  14. +3 −3 Library/Optimizers/FunctionCall/FileGetContentsOptimizer.php
  15. +3 −3 Library/Optimizers/FunctionCall/FilePutContentsOptimizer.php
  16. +3 −5 Library/Optimizers/FunctionCall/FilemtimeOptimizer.php
  17. +3 −4 Library/Optimizers/FunctionCall/FwriteOptimizer.php
  18. +3 −4 Library/Optimizers/FunctionCall/GetClassLowerOptimizer.php
  19. +3 −4 Library/Optimizers/FunctionCall/GetClassNsOptimizer.php
  20. +3 −5 Library/Optimizers/FunctionCall/GetClassOptimizer.php
  21. +4 −4 Library/Optimizers/FunctionCall/GetNsClassOptimizer.php
  22. +4 −4 Library/Optimizers/FunctionCall/GettypeOptimizer.php
  23. +3 −4 Library/Optimizers/FunctionCall/ImplodeOptimizer.php
  24. +3 −4 Library/Optimizers/FunctionCall/JoinOptimizer.php
  25. +4 −3 Library/Optimizers/FunctionCall/JsonDecodeOptimizer.php
  26. +4 −3 Library/Optimizers/FunctionCall/JsonEncodeOptimizer.php
  27. +4 −4 Library/Optimizers/FunctionCall/Md5Optimizer.php
  28. +6 −4 Library/Optimizers/FunctionCall/MicrotimeOptimizer.php
  29. +4 −5 Library/Optimizers/FunctionCall/PowOptimizer.php
  30. +3 −3 Library/Optimizers/FunctionCall/PregMatchOptimizer.php
  31. +2 −3 Library/Optimizers/FunctionCall/PrepareVirtualPathOptimizer.php
  32. +4 −4 Library/Optimizers/FunctionCall/RoundOptimizer.php
  33. +4 −4 Library/Optimizers/FunctionCall/StrReplaceOptimizer.php
  34. +3 −4 Library/Optimizers/FunctionCall/StripcslashesOptimizer.php
  35. +3 −5 Library/Optimizers/FunctionCall/StripslashesOptimizer.php
  36. +3 −5 Library/Optimizers/FunctionCall/StrposOptimizer.php
  37. +4 −4 Library/Optimizers/FunctionCall/StrtolowerOptimizer.php
  38. +4 −4 Library/Optimizers/FunctionCall/StrtoupperOptimizer.php
  39. +3 −4 Library/Optimizers/FunctionCall/SubstrOptimizer.php
  40. +3 −4 Library/Optimizers/FunctionCall/TimeOptimizer.php
  41. +3 −5 Library/Optimizers/FunctionCall/TrimOptimizer.php
  42. +3 −4 Library/Optimizers/FunctionCall/UcfirstOptimizer.php
  43. +3 −4 Library/Optimizers/FunctionCall/UncamelizeOptimizer.php
  44. +3 −4 Library/Optimizers/FunctionCall/UniqueKeyOptimizer.php
  45. +3 −3 Library/Optimizers/FunctionCall/VarExportOptimizer.php
@@ -61,16 +61,15 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/string');
$symbolVariable->setDynamicTypes('string');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_addcslashes(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -61,16 +61,15 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/string');
$symbolVariable->setDynamicTypes('string');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_addslashes(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -60,15 +60,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/array');
$symbolVariable->setDynamicTypes('array');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_array_keys(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -59,15 +59,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/array');
$symbolVariable->setDynamicTypes('array');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_fast_array_merge(' . $symbolVariable->getName() . ', &(' . $resolvedParams[0] . '), &(' . $resolvedParams[1] . ') TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -61,14 +61,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_basename(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -58,9 +58,6 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
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->initVariant($context);
@@ -80,6 +77,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->addCallStatusFlag($context);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('ZEPHIR_CALL_USER_FUNC_ARRAY(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ');');
$call->addCallStatusOrJump($context);
@@ -58,9 +58,6 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
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->initVariant($context);
@@ -80,6 +77,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
*/
$call->addCallStatusFlag($context);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('ZEPHIR_CALL_USER_FUNC(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ');');
$call->addCallStatusOrJump($context);
@@ -59,14 +59,13 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/string');
$symbolVariable->setDynamicTypes('long');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_crc32(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ');');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -57,10 +57,6 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
/**
* Add the last call status to the current symbol table
*/
@@ -76,6 +72,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$resolvedParams = null;
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
if ($resolvedParams) {
$context->codePrinter->output('zephir_create_array(' . $symbolVariable->getName() . ', zephir_get_intval(' . $resolvedParams[0] . '), 1 TSRMLS_CC);');
} else {
@@ -59,10 +59,6 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
/**
* Add the last call status to the current symbol table
*/
@@ -74,6 +70,9 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
/**
* Add the last call status to the current symbol table
*/
@@ -58,10 +58,6 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
/**
* Add the last call status to the current symbol table
*/
@@ -72,7 +68,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$symbolVariable->setDynamicTypes('object');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
/**
* Add the last call status to the current symbol table
*/
@@ -54,14 +54,13 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/fcall');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$evalContext = str_replace(ZEPHIRPATH, '', $expression['file'] . ':' . $expression['line']);
$context->codePrinter->output(
sprintf('zephir_eval_php(%s, %s, "%s" TSRMLS_CC);', $resolvedParams[0], $symbolVariable->getName(), $evalContext)
@@ -77,10 +77,6 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
}
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if (isset($resolvedParams[$limitOffset])) {
@@ -90,7 +86,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$context->headersManager->add('kernel/string');
$symbolVariable->setDynamicTypes('array');
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
if (isset($str)) {
$context->codePrinter->output('zephir_fast_explode_str(' . $symbolVariable->getName() . ', SL("' . $str . '"), ' . $resolvedParams[0] . ', ' . $limit . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
@@ -61,12 +61,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
if ($symbolVariable) {
$context->codePrinter->output('zephir_file_get_contents(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
@@ -61,13 +61,13 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($symbolVariable) {
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_file_put_contents(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
} else {
@@ -61,14 +61,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_filemtime(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -61,14 +61,13 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($symbolVariable) {
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_fwrite(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
} else {
@@ -61,15 +61,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/object');
$symbolVariable->setDynamicTypes('string');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_get_class(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', 1 TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
@@ -61,15 +61,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/object');
$symbolVariable->setDynamicTypes('string');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
if (!isset($resolvedParams[1])) {
$context->codePrinter->output('zephir_get_class_ns(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', 0 TSRMLS_CC);');
} else {
@@ -60,16 +60,14 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('kernel/object');
$symbolVariable->setDynamicTypes('string');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->codePrinter->output('zephir_get_class(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', 0 TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
Oops, something went wrong.

0 comments on commit be1dbe4

Please sign in to comment.