/** * Executes the operator * * @param array $expression * @param CompilationContext $compilationContext * @return CompiledExpression * @throws CompilerException */ public function compile(array $expression, CompilationContext $compilationContext) { if (!isset($expression['parameters'])) { throw new CompilerException("Invalid 'parameters' for new-type", $expression); } switch ($expression['internal-type']) { case 'array': $compilationContext->headersManager->add('kernel/array'); $functionName = 'create_array'; break; case 'string': $compilationContext->headersManager->add('kernel/string'); $functionName = 'create_string'; break; default: throw new CompilerException("Cannot build instance of type", $expression); } $builder = new FunctionCallBuilder($functionName, $expression['parameters'], 1, $expression['file'], $expression['line'], $expression['char']); /** * Implicit type coercing */ $castBuilder = new CastOperatorBuilder($expression['internal-type'], $builder); $expression = new Expression($castBuilder->get()); $expression->setReadOnly($this->_readOnly); return $expression->compile($compilationContext); }
/** * @param array $expression * @param CompilationContext $compilationContext * @return CompiledExpression * @throws CompilerException */ public function compile(array $expression, CompilationContext $compilationContext) { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']); } if (!isset($expression['right'])) { throw new CompilerException("Invalid 'right' operand for 'irange' expression", $expression['right']); } $builder = new FunctionCallBuilder('range', array(array('parameter' => $expression['left']), array('parameter' => $expression['right']))); /** * Implicit type coercing */ $castBuilder = new CastOperatorBuilder('array', $builder); $expression = new Expression($castBuilder->get()); $expression->setReadOnly($this->_readOnly); return $expression->compile($compilationContext); }