Library/Operators/Unary/MinusOperator.php
public function compile($expression, CompilationContext $compilationContext)
    {
        if (!isset($expression['left'])) {
            throw new CompilerException('Missing left part of the expression');
        }

        $leftExpr = new Expression($expression['left']);
        $leftExpr->setReadOnly($this->readOnly);
        $left = $leftExpr->compile($compilationContext);

        switch ($left->getType()) {
            case 'int':
            case 'uint':
            case 'long':
            case 'ulong':
            case 'double':
                return new CompiledExpression($left->getType(), '-'.$left->getCode(), $expression);

            case 'variable':
                $variable = $compilationContext->symbolTable->getVariable($left->getCode());
                switch ($variable->getType()) {
                    case 'int':
                    case 'uint':
                    case 'long':
                    case 'ulong':
                    case 'double':
                        return new CompiledExpression($variable->getType(), '-'.$variable->getName(), $expression);

                    case 'variable':
                        $compilationContext->headersManager->add('kernel/operators');
                        $compilationContext->codePrinter->output('zephir_negate('.$compilationContext->backend->getVariableCode($variable).' TSRMLS_CC);');

                        return new CompiledExpression('variable', $variable->getName(), $expression);

                    default:
                        throw new CompilerException("Cannot operate minus with variable of '".$left->getType()."' type");
                }
                break;

            default:
                throw new CompilerException("Cannot operate minus with '".$left->getType()."' type");
        }
    }
public function compile($expression, CompilationContext $compilationContext)
    {
        if (!isset($expression['left'])) {
            throw new CompilerException('Missing left part of the expression');
        }

        $leftExpr = new Expression($expression['left']);
        $leftExpr->setReadOnly($this->readOnly);
        $left = $leftExpr->compile($compilationContext);

        switch ($left->getType()) {
            case 'int':
            case 'uint':
            case 'long':
            case 'ulong':
            case 'double':
                return new CompiledExpression($left->getType(), '-'.$left->getCode(), $expression);

            case 'variable':
                $variable = $compilationContext->symbolTable->getVariable($left->getCode());
                switch ($variable->getType()) {
                    case 'int':
                    case 'uint':
                    case 'long':
                    case 'ulong':
                    case 'double':
                        return new CompiledExpression($variable->getType(), '-'.$variable->getName(), $expression);

                    case 'variable':
                        $compilationContext->headersManager->add('kernel/operators');
                        $compilationContext->codePrinter->output('zephir_negate('.$compilationContext->backend->getVariableCode($variable).' TSRMLS_CC);');

                        return new CompiledExpression('variable', $variable->getName(), $expression);

                    default:
                        throw new CompilerException("Cannot operate minus with variable of '".$left->getType()."' type");
                }
                break;

            default:
                throw new CompilerException("Cannot operate minus with '".$left->getType()."' type");
        }
    }
public function compile ( $ expression , CompilationContext $ compilationContext ) { if ( ! isset ( $ expression [ 'left' ] ) ) { throw new CompilerException ( 'Missing left part of the expression' ) ; } $ leftExpr = new Expression ( $ expression [ 'left' ] ) ; $ leftExpr -> setReadOnly ( $ this -> readOnly ) ; $ left = $ leftExpr -> compile ( $ compilationContext ) ; switch ( $ left -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : case 'double' : return new CompiledExpression ( $ left -> getType ( ) , '-' . $ left -> getCode ( ) , $ expression ) ; case 'variable' : $ variable = $ compilationContext -> symbolTable -> getVariable ( $ left -> getCode ( ) ) ; switch ( $ variable -> getType ( ) ) { case 'int' : case 'uint' : case 'long' : case 'ulong' : case 'double' : return new CompiledExpression ( $ variable -> getType ( ) , '-' . $ variable -> getName ( ) , $ expression ) ; case 'variable' : $ compilationContext -> headersManager -> add ( 'kernel/operators' ) ; $ compilationContext -> codePrinter -> output ( 'zephir_negate(' . $ compilationContext -> backend -> getVariableCode ( $ variable ) . ' TSRMLS_CC);' ) ; return new CompiledExpression ( 'variable' , $ variable -> getName ( ) , $ expression ) ; default : throw new CompilerException ( "Cannot operate minus with variable of '" . $ left -> getType ( ) . "' type" ) ; } break ; default : throw new CompilerException ( "Cannot operate minus with '" . $ left -> getType ( ) . "' type" ) ; } }
Compile expression.

@param $expression
@param CompilationContext $compilationContext

@throws CompilerException

@return CompiledExpression
Compile expression .