forked from phalcon/cphalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f13e939
commit f2c68b5
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |