Skip to content
Permalink
Browse files

Tidied up optimizers.

  • Loading branch information...
SidRoberts authored and Németh Balázs committed Apr 30, 2019
1 parent a738e02 commit c9e33155fdddaf91dbd52856e1ee021ef09d1989
@@ -35,7 +35,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
}
if (count($expression['parameters']) != 1) {
throw new CompilerException("phalcon_cssmin only accepts one parameter", $expression);
throw new CompilerException(
"phalcon_cssmin only accepts one parameter",
$expression
);
}
/**
@@ -44,21 +47,36 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
$expression
);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('phalcon/assets/filters/cssminifier');
$symbolVariable->setDynamicTypes('string');
$resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
$resolvedParams = $call->getResolvedParams(
$expression['parameters'],
$context,
$expression
);
$context->codePrinter->output('phalcon_cssmin(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
$context->codePrinter->output(
'phalcon_cssmin(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);'
);
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}
@@ -41,7 +41,10 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
}
if (count($expression['parameters']) != 1) {
throw new CompilerException("phalcon_escape_css only accepts one parameter", $expression);
throw new CompilerException(
"phalcon_escape_css only accepts one parameter",
$expression
);
}
/**
@@ -50,6 +53,7 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
@@ -63,9 +67,20 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$context->headersManager->add('kernel/filter');
$resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
$context->codePrinter->output('zephir_escape_css(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ');');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
$resolvedParams = $call->getResolvedParams(
$expression['parameters'],
$context,
$expression
);
$context->codePrinter->output(
'zephir_escape_css(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ');'
);
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}
@@ -36,13 +36,15 @@ class PhalconEscapeJsOptimizer extends OptimizerAbstract
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 1) {
throw new CompilerException("phalcon_escape_js only accepts one parameter", $expression);
throw new CompilerException(
"phalcon_escape_js only accepts one parameter",
$expression
);
}
/**
@@ -51,8 +53,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
$expression
);
}
if ($call->mustInitSymbolVariable()) {
@@ -61,12 +67,22 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$context->headersManager->add('kernel/filter');
$resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
$resolvedParams = $call->getResolvedParams(
$expression['parameters'],
$context,
$expression
);
$symbol = $context->backend->getVariableCode($symbolVariable);
$context->codePrinter->output('zephir_escape_js(' . $symbol . ', ' . $resolvedParams[0] . ');');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
$context->codePrinter->output(
'zephir_escape_js(' . $symbol . ', ' . $resolvedParams[0] . ');'
);
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}
@@ -30,13 +30,15 @@ class PhalconFilterAlphanumOptimizer extends OptimizerAbstract
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 1) {
throw new CompilerException("phalcon_filter_alphanum only accepts one parameter", $expression);
throw new CompilerException(
"phalcon_filter_alphanum only accepts one parameter",
$expression
);
}
/**
@@ -45,8 +47,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
$expression
);
}
if ($call->mustInitSymbolVariable()) {
@@ -55,11 +61,22 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$context->headersManager->add('kernel/filter');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
$resolvedParams = $call->getReadOnlyResolvedParams(
$expression['parameters'],
$context,
$expression
);
$symbol = $context->backend->getVariableCode($symbolVariable);
$context->codePrinter->output('zephir_filter_alphanum(' . $symbol . ', ' . $resolvedParams[0] . ');');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
$context->codePrinter->output(
'zephir_filter_alphanum(' . $symbol . ', ' . $resolvedParams[0] . ');'
);
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}
@@ -44,8 +44,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
$expression
);
}
if ($call->mustInitSymbolVariable()) {
@@ -56,9 +60,18 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$symbolVariable->setDynamicTypes('array');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
$resolvedParams = $call->getReadOnlyResolvedParams(
$expression['parameters'],
$context,
$expression
);
//$context->codePrinter->output('zephir_fast_array_merge(' . $symbolVariable->getName() . ', &(' . $resolvedParams[0] . '), &(' . $resolvedParams[1] . ') TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}
@@ -21,7 +21,6 @@
class PhalconGetUriOptimizer extends OptimizerAbstract
{
/**
* @param array $expression
* @param Call $call
@@ -32,13 +31,15 @@ class PhalconGetUriOptimizer extends OptimizerAbstract
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 1) {
throw new CompilerException("phalcon_get_uri only accepts three parameter", $expression);
throw new CompilerException(
"phalcon_get_uri only accepts three parameter",
$expression
);
}
/**
@@ -47,22 +48,39 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
$expression
);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$context->headersManager->add('phalcon/url/utils', HeadersManager::POSITION_LAST);
$context->headersManager->add(
'phalcon/url/utils',
HeadersManager::POSITION_LAST
);
$resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
$resolvedParams = $call->getResolvedParams(
$expression['parameters'],
$context,
$expression
);
$symbol = $context->backend->getVariableCode($symbolVariable);
$context->codePrinter->output('phalcon_get_uri(' . $symbol . ', ' . $resolvedParams[0] . ');');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
$context->codePrinter->output(
'phalcon_get_uri(' . $symbol . ', ' . $resolvedParams[0] . ');'
);
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}
@@ -20,7 +20,6 @@
class PhalconIsBasicCharsetOptimizer extends OptimizerAbstract
{
/**
* @param array $expression
* @param Call $call
@@ -31,13 +30,15 @@ class PhalconIsBasicCharsetOptimizer extends OptimizerAbstract
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 1) {
throw new CompilerException("phalcon_is_basic_charset only accepts one parameter", $expression);
throw new CompilerException(
"phalcon_is_basic_charset only accepts one parameter",
$expression
);
}
/**
@@ -46,8 +47,12 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
throw new CompilerException(
"Returned values by functions can only be assigned to variant variables",
$expression
);
}
if ($call->mustInitSymbolVariable()) {
@@ -56,12 +61,22 @@ public function optimize(array $expression, Call $call, CompilationContext $cont
$context->headersManager->add('kernel/filter');
$resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
$resolvedParams = $call->getResolvedParams(
$expression['parameters'],
$context,
$expression
);
$symbol = $context->backend->getVariableCode($symbolVariable);
$context->codePrinter->output('zephir_is_basic_charset(' . $symbol . ', ' . $resolvedParams[0] . ');');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
$context->codePrinter->output(
'zephir_is_basic_charset(' . $symbol . ', ' . $resolvedParams[0] . ');'
);
return new CompiledExpression(
'variable',
$symbolVariable->getRealName(),
$expression
);
}
}

0 comments on commit c9e3315

Please sign in to comment.
You can’t perform that action at this time.