Permalink
Browse files

CaseOperator - implement (int) case from string type

  • Loading branch information...
ovr committed May 7, 2015
1 parent 37630ee commit 8499e7dec9ed39918ebf8a09f21c711352126f3b
@@ -65,6 +65,23 @@ public function compile($expression, CompilationContext $compilationContext)
case 'bool':
return new CompiledExpression('int', $resolved->getBooleanCode(), $expression);
case 'string':
$compilationContext->headersManager->add('kernel/operators');
/**
* zephir_get_intval_ex use zval variable
* before use with it we create a new variable and assign value of literal
*
* @todo Optimize by creating native function for string without zval using
*/
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('string', $compilationContext);
$let = new LetVariable();
$original = $resolved->getOriginal();
$original['operator'] = 'assign';
$let->assign($symbolVariable->getName(), $symbolVariable, $resolved, new ReadDetector(), $compilationContext, $original);
return new CompiledExpression('int', 'zephir_get_intval_ex(' . $symbolVariable->getName() . ')', $expression);
case 'array':
$compilationContext->headersManager->add('kernel/operators');
$symbolVariable = $compilationContext->symbolTable->getVariableForRead($resolved->getCode(), $compilationContext, $expression);
@@ -206,7 +223,7 @@ public function compile($expression, CompilationContext $compilationContext)
case 'variable':
$compilationContext->headersManager->add('kernel/operators');
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('char', $compilationContext, $expression);
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('char', $compilationContext);
$symbolVariable = $compilationContext->symbolTable->getVariableForRead($resolved->getCode(), $compilationContext, $expression);
$compilationContext->codePrinter->output($tempVariable->getName() . ' = (char) zephir_get_intval(' . $symbolVariable->getName() . ');');
@@ -222,9 +239,9 @@ public function compile($expression, CompilationContext $compilationContext)
case 'variable':
$compilationContext->headersManager->add('kernel/operators');
$symbolVariable = $compilationContext->symbolTable->getTempVariable('string', $compilationContext, $expression);
$symbolVariable = $compilationContext->symbolTable->getTempVariable('string', $compilationContext);
$symbolVariable->setMustInitNull(true);
$symbolVariable->setIsInitialized(true, $compilationContext, $expression);
$symbolVariable->setIsInitialized(true, $compilationContext);
$symbolVariable->increaseUses();
$compilationContext->codePrinter->output('zephir_get_strval(' . $symbolVariable->getName() . ', ' . $resolved->getCode() . ');');
if ($symbolVariable->isTemporal()) {

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -48,6 +48,11 @@ class Cast
return (int) a;
}
public function testIntCastFromString()
{
return (int) "test";
}
public function testIntCastFromNull()
{
return (int) null;

0 comments on commit 8499e7d

Please sign in to comment.