/** * @param $expression * @param CompilationContext $compilationContext * @return bool|CompiledExpression * @throws CompilerException */ public function compile($expression, CompilationContext $compilationContext) { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'typeof' expression", $expression['left']); } $builder = new FunctionCallBuilder('gettype', array(array('parameter' => $expression['left']))); $expression = new Expression($builder->get()); return $expression->compile($compilationContext); }
/** * Intercepts calls to built-in methods * * @param string $methodName * @param object $caller * @param CompilationContext $compilationContext * @param Call $call * @param array $expression * @throws CompilerException * @return bool|\Zephir\CompiledExpression */ public function invokeMethod($methodName, $caller, CompilationContext $compilationContext, Call $call, array $expression) { if (method_exists($this, $methodName)) { return $this->{$methodName}($caller, $compilationContext, $call, $expression); } if (isset($this->methodMap[$methodName])) { if (isset($expression['parameters'])) { $parameters = $expression['parameters']; array_unshift($parameters, array('parameter' => $caller)); } else { $parameters = array(array('parameter' => $caller)); } $builder = new FunctionCallBuilder($this->methodMap[$methodName], $parameters, FunctionCall::CALL_NORMAL, $expression['file'], $expression['line'], $expression['char']); $expression = new Expression($builder->get()); return $expression->compile($compilationContext); } throw new CompilerException(sprintf('Method "%s" is not a built-in method of type "%s"', $methodName, $this->getTypeName()), $expression); }
/** * Intercepts calls to built-in methods * * @param string $methodName * @param object $caller * @param CompilationContext $compilationContext * @param Call $call * @param array $expression * @throws CompilerException * @return bool|\Zephir\CompiledExpression */ public function invokeMethod($methodName, $caller, CompilationContext $compilationContext, Call $call, array $expression) { /** * Checks first whether the method exist in the array type definition */ if (method_exists($this, $methodName)) { return $this->{$methodName}($caller, $compilationContext, $call, $expression); } /** * Check the method map */ if (isset($this->methodMap[$methodName])) { $paramNumber = $this->getNumberParam($methodName); if ($paramNumber == 0) { if (isset($expression['parameters'])) { $parameters = $expression['parameters']; array_unshift($parameters, array('parameter' => $caller)); } else { $parameters = array(array('parameter' => $caller)); } } else { if (isset($expression['parameters'])) { $parameters = array(); foreach ($expression['parameters'] as $number => $parameter) { if ($number == $paramNumber) { $parameters[] = null; } $parameters[] = $parameter; } $parameters[$paramNumber] = array('parameter' => $caller); } else { $parameters = array(array('parameter' => $caller)); } } $builder = new FunctionCallBuilder($this->methodMap[$methodName], $parameters, FunctionCall::CALL_NORMAL, $expression['file'], $expression['line'], $expression['char']); $expression = new Expression($builder->get()); return $expression->compile($compilationContext); } throw new CompilerException(sprintf('Method "%s" is not a built-in method of type "%s"', $methodName, $this->getTypeName()), $expression); }
/** * Transforms calls to method "toHex" to sprintf('%X') call * * @param object $caller * @param CompilationContext $compilationContext * @param Call $call * @param array $expression * @return bool|mixed|\Zephir\CompiledExpression */ public function toHex($caller, CompilationContext $compilationContext, Call $call, array $expression) { $builder = new FunctionCallBuilder('sprintf', array(array('parameter' => array('type' => 'string', 'value' => '%X')), array('parameter' => $caller)), FunctionCall::CALL_NORMAL, $expression['file'], $expression['line'], $expression['char']); $expression = new Expression($builder->get()); return $expression->compile($compilationContext); }
/** * Transforms calls to method "join" to function calls to "join" * * @param object $caller * @param CompilationContext $compilationContext * @param Call $call * @param array $expression * @return bool|\Zephir\CompiledExpression */ public function join($caller, CompilationContext $compilationContext, Call $call, array $expression) { $builder = new FunctionCallBuilder('join', array_merge($expression['parameters'], array(array('parameter' => $caller))), FunctionCall::CALL_NORMAL, $expression['file'], $expression['line'], $expression['char']); $expression = new Expression($builder->get()); return $expression->compile($compilationContext); }