Skip to content

Commit

Permalink
Add GetClassNsOptimizer.php
Browse files Browse the repository at this point in the history
  • Loading branch information
carvajaldiazeduar committed Nov 25, 2013
1 parent f13e939 commit f2c68b5
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions Library/Optimizers/FunctionCall/GetClassNsOptimizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| http://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

/**
* GetClassNsOptimizer
*
* Optimizes calls to 'get_class_ns' using internal function
*/
class GetClassNsOptimizer
{
/**
*
* @param array $expression
* @param Call $call
* @param CompilationContext $context
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}

if (count($expression['parameters']) != 1) {
throw new CompilerException("'get_class_ns' only accepts one parameter");
}

/**
* Process the expected symbol to be returned
*/
$call->processExpectedReturn($context);

$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->getType() != 'variable' && $symbolVariable->getType() != 'string') {
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);
$context->codePrinter->output('zephir_get_class_ns(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', 0);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}

}

0 comments on commit f2c68b5

Please sign in to comment.