getSymbolVariable() public method

Returns the symbol variable that must be returned by the call
public getSymbolVariable ( boolean $useTemp = false, zephir\CompilationContext $compilationContext = null ) : Variable
$useTemp boolean
$compilationContext zephir\CompilationContext
return Variable
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (isset($expression['parameters'])) {
         if (count($expression['parameters']) != 0) {
             throw new CompilerException("This function doesn't require parameters", $expression);
         }
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable) {
         if (!$symbolVariable->isVariable()) {
             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/memory');
     $context->codePrinter->output('zephir_create_symbol_table(TSRMLS_C);');
     $context->codePrinter->output('');
     return new CompiledExpression('null', null, $expression);
 }
Example #2
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 1) {
         throw new CompilerException("'uncamelize' only accepts one parameter");
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/string');
     $symbolVariable->setDynamicTypes('string');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $context->codePrinter->output('zephir_uncamelize(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 1) {
         throw new CompilerException("phalcon_get_uri only accepts three parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $context->headersManager->add('phalcon/mvc/url/utils', HeadersManager::POSITION_LAST);
     $resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('phalcon_get_uri(' . $symbol . ', ' . $resolvedParams[0] . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  *
  * @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']) != 2) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         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/array');
     $symbolVariable->setDynamicTypes('array');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     //$context->codePrinter->output('zephir_fast_array_merge(' . $symbolVariable->getName() . ', &(' . $resolvedParams[0] . '), &(' . $resolvedParams[1] . ') TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #5
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 2) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($expression['parameters'][0]['parameter']['type'] == 'string') {
         $str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']);
         unset($expression['parameters'][0]);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $context->headersManager->add('kernel/string');
     $symbolVariable->setDynamicTypes('string');
     if (isset($str)) {
         $context->codePrinter->output('zephir_fast_join_str(' . $symbolVariable->getName() . ', SL("' . $str . '"), ' . $resolvedParams[0] . ' TSRMLS_CC);');
         return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
     }
     $context->codePrinter->output('zephir_fast_join(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #6
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable) {
         if (!$symbolVariable->isVariable()) {
             throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
         }
     } else {
         $symbolVariable = $context->symbolTable->addTemp('variable', $context);
         $symbolVariable->initVariant($context);
     }
     $context->headersManager->add('kernel/string');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     /**
      * Process encode options
      */
     if (count($resolvedParams) >= 2) {
         $context->headersManager->add('kernel/operators');
         $options = 'zephir_get_intval(' . $resolvedParams[1] . ') ';
     } else {
         $options = '0 ';
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $context->codePrinter->output('zephir_json_decode(' . $symbolVariable->getName() . ', &(' . $symbolVariable->getName() . '), ' . $resolvedParams[0] . ', ' . $options . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #7
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 3) {
         if (count($expression['parameters']) == 4) {
             return false;
         }
         throw new CompilerException("'str_replace' only accepts three parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/string');
     $symbolVariable->setDynamicTypes('string');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($call->mustInitSymbolVariable()) {
         if ($symbolVariable->getName() == 'return_value') {
             $symbolVariable = $context->symbolTable->getTempVariableForWrite('variable', $context);
         } else {
             $symbolVariable->initVariant($context);
         }
     }
     $symbol = $context->backend->getVariableCodePointer($symbolVariable);
     $context->codePrinter->output('zephir_fast_str_replace(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $resolvedParams[2] . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #8
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     $numberParameters = count($expression['parameters']);
     if ($numberParameters != 1 && $numberParameters != 2) {
         throw new CompilerException("'get_class_ns' only accepts one or two parameters", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->isNotVariableAndString()) {
         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/object');
     $symbolVariable->setDynamicTypes('string');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if (!isset($resolvedParams[1])) {
         $context->codePrinter->output('zephir_get_class_ns(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', 0 TSRMLS_CC);');
     } else {
         $context->codePrinter->output('zephir_get_class_ns(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
     }
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #9
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     $charlist = 'NULL ';
     if (count($expression['parameters']) == 2) {
         if ($expression['parameters'][1]['parameter']['type'] == 'null') {
             unset($expression['parameters'][1]);
         }
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->isNotVariableAndString()) {
         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);
     if (isset($resolvedParams[1])) {
         $charlist = $resolvedParams[1];
     }
     $context->codePrinter->output('zephir_fast_trim(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $charlist . ', ' . static::$TRIM_WHERE . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (isset($expression['parameters'])) {
         $numberParameters = count($expression['parameters']);
         if ($numberParameters != 0) {
             return false;
         }
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         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/object');
     $symbolVariable->setDynamicTypes('string');
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('zephir_get_called_class(' . $symbol . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #11
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 2) {
         return false;
     }
     $context->headersManager->add('kernel/file');
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable) {
         if ($symbolVariable->isNotVariableAndString()) {
             throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
         }
     }
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($symbolVariable) {
         if ($call->mustInitSymbolVariable()) {
             $symbolVariable->initVariant($context);
         }
         $context->codePrinter->output('zephir_file_put_contents(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
         return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
     } else {
         $context->codePrinter->output('zephir_file_put_contents(NULL, ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
     }
     return new CompiledExpression('null', 'null', $expression);
 }
 /**
  *
  * @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']) != 2) {
         throw new CompilerException("'phvolt_parse_view' only accepts two parameters", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbolVariable->setDynamicTypes('array');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $context->headersManager->add('phalcon/mvc/view/engine/volt/scanner', HeadersManager::POSITION_LAST);
     $context->headersManager->add('phalcon/mvc/view/engine/volt/volt', HeadersManager::POSITION_LAST);
     $context->codePrinter->output('if (phvolt_parse_view(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC) == FAILURE) {');
     $context->codePrinter->output("\t" . 'RETURN_MM();');
     $context->codePrinter->output('}');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  *
  * @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("'phql_parse_phql' only accepts one parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbolVariable->setDynamicTypes('array');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $context->headersManager->add('phalcon/mvc/model/query/scanner', HeadersManager::POSITION_LAST);
     $context->headersManager->add('phalcon/mvc/model/query/phql', HeadersManager::POSITION_LAST);
     $call->addCallStatusFlag($context);
     $context->codePrinter->output('ZEPHIR_LAST_CALL_STATUS = phql_parse_phql(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
     $call->checkTempParameters($context);
     $call->addCallStatusOrJump($context);
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #14
0
 /**
  *
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     $call->processExpectedReturn($context);
     $args = $this->getParams($expression);
     $func = strtolower($args[0]);
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $args = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     switch ($func) {
         case 'connect':
             $other_arguments = $args[1] . ',' . $args[2];
             break;
         default:
             $args_len = count($args);
             $other_arguments = "";
             for ($i = 1; $i < $args_len; $i++) {
                 $other_arguments .= $args[$i] . ',';
             }
             $other_arguments = substr($other_arguments, 0, count($other_arguments) - 2);
             break;
     }
     $cmd = 'redis_' . $func . '(' . $symbolVariable->getName() . ',' . $other_arguments . ');';
     $context->codePrinter->output($cmd);
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #15
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) < 1 || count($expression['parameters']) > 2) {
         throw new CompilerException("'camelize' only accepts one or two parameters");
     }
     $delimiter = 'NULL ';
     if (count($expression['parameters']) == 2) {
         if ($expression['parameters'][1]['parameter']['type'] == 'null') {
             unset($expression['parameters'][1]);
         }
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         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);
     if (isset($resolvedParams[1])) {
         $delimiter = $resolvedParams[1];
     }
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('zephir_camelize(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $delimiter . ' );');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #16
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 1) {
         throw new CompilerException("phalcon_jsmin only accepts one parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $context->headersManager->add('phalcon/assets/filters/jsminifier');
     $symbolVariable->setDynamicTypes('string');
     $resolvedParams = $call->getResolvedParams($expression['parameters'], $context, $expression);
     $context->codePrinter->output('phalcon_jsmin(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  *
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         throw new CompilerException("This function requires parameters", $expression);
     }
     if (count($expression['parameters']) != 2) {
         throw new CompilerException("This function only requires two parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if (!$symbolVariable->isVariable()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     /**
      * Add the last call status to the current symbol table
      */
     $call->addCallStatusFlag($context);
     $context->headersManager->add('kernel/object');
     $symbolVariable->setDynamicTypes('object');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     /**
      * Add the last call status to the current symbol table
      */
     $call->addCallStatusFlag($context);
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('ZEPHIR_LAST_CALL_STATUS = zephir_create_instance_params(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
     $call->addCallStatusOrJump($context);
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #18
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 3) {
         throw new CompilerException("parse_annotations only accepts three parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $context->headersManager->add('owl/annotations/scanner', HeadersManager::POSITION_LAST);
     $context->headersManager->add('owl/annotations/annot', HeadersManager::POSITION_LAST);
     $symbolVariable->setDynamicTypes('array');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $context->codePrinter->output('phannot_parse_annotations(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $resolvedParams[2] . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #19
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     /* microtime has one optional parameter (get_as_float) */
     if (isset($expression['parameters']) && count($expression['parameters']) > 2) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/time');
     $symbol = $context->backend->getVariableCode($symbolVariable);
     if (!isset($expression['parameters'])) {
         $symbolVariable->setDynamicTypes('string');
         if ($call->mustInitSymbolVariable()) {
             $symbolVariable->initVariant($context);
         }
         $context->codePrinter->output('zephir_microtime(' . $symbol . ', NULL TSRMLS_CC);');
     } else {
         $symbolVariable->setDynamicTypes('double');
         $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
         if ($call->mustInitSymbolVariable()) {
             $symbolVariable->initVariant($context);
         }
         $context->codePrinter->output('zephir_microtime(' . $symbol . ', ' . $resolvedParams[0] . ' TSRMLS_CC);');
     }
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #20
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return mixed|CompiledExpression
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable) {
         if (!$symbolVariable->isVariable()) {
             throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
         }
     }
     $context->headersManager->add('kernel/variables');
     $resolvedParams = $call->getResolvedParamsAsExpr($expression['parameters'], $context, $expression);
     $resolvedParam = $resolvedParams[0];
     if (!$symbolVariable || !$symbolVariable->isVariable()) {
         /**
          * Complex expressions require a temporary variable
          */
         switch ($resolvedParam->getType()) {
             case 'array':
                 $type = 'array';
                 break;
             default:
                 $type = 'variable';
                 break;
         }
         $variable = $context->symbolTable->addTemp($type, $context);
         $variable->initVariant($context);
         $statement = new LetStatement(array('type' => 'let', 'assignments' => array(array('assign-type' => $type, 'variable' => $variable->getName(), 'operator' => 'assign', 'expr' => array('type' => $resolvedParam->getType(), 'value' => $resolvedParam->getCode(), 'file' => $expression['file'], 'line' => $expression['line'], 'char' => $expression['char']), 'file' => $expression['file'], 'line' => $expression['line'], 'char' => $expression['char']))));
         $statement->compile($context);
     } else {
         /**
          * This mark the variable as used
          */
         $variable = $context->symbolTable->getVariableForRead($resolvedParam->getCode(), $context, $expression);
     }
     $variableSymbol = $context->backend->getVariableCodePointer($variable);
     /**
      * let a = var_export(val);
      */
     if ($symbolVariable) {
         if ($symbolVariable->getName() == 'return_value') {
             $symbolVariable = $context->symbolTable->getTempVariableForWrite('variable', $context);
         } else {
             $symbolVariable->initVariant($context);
         }
         $symbol = $context->backend->getVariableCode($symbolVariable);
         $context->codePrinter->output('zephir_var_export_ex(' . $symbol . ', ' . $variableSymbol . ' TSRMLS_CC);');
         return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
     }
     $context->codePrinter->output('zephir_var_export(' . $variableSymbol . ' TSRMLS_CC);');
     return new CompiledExpression('null', 'null', $expression);
 }
Example #21
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     /** this optimizer has bugs */
     return false;
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) < 2) {
         throw new CompilerException("'substr' require two or three parameters");
     }
     /**
      * Process parameters
      */
     $lengthOffset = 2;
     if (isset($expression['parameters'][2]) && $expression['parameters'][2]['parameter']['type'] == 'int') {
         $length = $expression['parameters'][2]['parameter']['value'] . ' ';
         unset($expression['parameters'][2]);
     }
     if (isset($expression['parameters'][1]) && $expression['parameters'][1]['parameter']['type'] == 'int') {
         $from = $expression['parameters'][1]['parameter']['value'] . ' ';
         unset($expression['parameters'][1]);
         $lengthOffset = 1;
     }
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if (!isset($length) && isset($resolvedParams[$lengthOffset])) {
         $context->headersManager->add('kernel/operators');
         $length = 'zephir_get_intval(' . $resolvedParams[$lengthOffset] . ') ';
     }
     if (!isset($from) && isset($resolvedParams[1])) {
         $context->headersManager->add('kernel/operators');
         $from = 'zephir_get_intval(' . $resolvedParams[1] . ') ';
     }
     if (!isset($from)) {
         $from = '0 ';
     }
     if (!isset($length)) {
         $length = '0 ';
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->isNotVariableAndString()) {
         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');
     $context->codePrinter->output('zephir_substr(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $from . ', ' . $length . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #22
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) < 2) {
         throw new CompilerException("'explode' require two parameter");
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     /**
      * Process limit
      */
     $limit = 'LONG_MAX';
     $limitOffset = 2;
     if (count($expression['parameters']) == 3 && $expression['parameters'][2]['parameter']['type'] == 'int') {
         $limit = $expression['parameters'][2]['parameter']['value'] . ' ';
         unset($expression['parameters'][2]);
     }
     if ($expression['parameters'][0]['parameter']['type'] == 'string') {
         $str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']);
         unset($expression['parameters'][0]);
         if (count($expression['parameters']) == 2) {
             $limitOffset = 1;
         }
     }
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if (isset($resolvedParams[$limitOffset])) {
         $context->headersManager->add('kernel/operators');
         $limit = 'zephir_get_intval(' . $resolvedParams[$limitOffset] . ') ';
     }
     $context->headersManager->add('kernel/string');
     $symbolVariable->setDynamicTypes('array');
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbol = $context->backend->getVariableCode($symbolVariable);
     if (isset($str)) {
         $context->codePrinter->output('zephir_fast_explode_str(' . $symbol . ', SL("' . $str . '"), ' . $resolvedParams[0] . ', ' . $limit . ' TSRMLS_CC);');
         return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
     }
     $context->codePrinter->output('zephir_fast_explode(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $limit . ' TSRMLS_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #23
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) > 4) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/math');
     $symbolVariable->setDynamicTypes('double');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     /* Todo: move var return type -> double as with round, floor */
     $symbol = $context->backend->getVariableCode($symbolVariable);
     switch (count($expression['parameters'])) {
         /**
          * Only float $val
          */
         case 1:
             $context->codePrinter->output('zephir_round(' . $symbol . ', ' . $resolvedParams[0] . ', NULL, NULL TSRMLS_CC);');
             break;
             /**
              * float $val, int $mode
              */
         /**
          * float $val, int $mode
          */
         case 2:
             $context->codePrinter->output('zephir_round(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', NULL TSRMLS_CC);');
             break;
         default:
             $context->codePrinter->output('zephir_round(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $resolvedParams[2] . ' TSRMLS_CC);');
             break;
     }
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #24
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) < 2 || count($expression['parameters']) > 3) {
         throw new CompilerException("'substr' require two or three parameters");
     }
     /**
      * Process parameters
      */
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $params = array();
     $flags = '0';
     for ($param = 1; $param <= 2; ++$param) {
         if (!isset($expression['parameters'][$param])) {
             $params[] = '0';
             if ($param == 2) {
                 $flags = 'ZEPHIR_SUBSTR_NO_LENGTH';
             }
             continue;
         }
         if ($expression['parameters'][$param]['parameter']['type'] == 'int') {
             $params[] = $expression['parameters'][$param]['parameter']['value'] . ' ';
         } else {
             $context->headersManager->add('kernel/operators');
             $params[] = 'zephir_get_intval(' . $resolvedParams[$param] . ')';
         }
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/string');
     $symbolVariable->setDynamicTypes('string');
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('zephir_substr(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $params[0] . ', ' . $params[1] . ', ' . $flags . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #25
0
 /**
  * @param array              $expression
  * @param Call               $call
  * @param CompilationContext $context
  *
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters']) || count($expression['parameters']) > 1) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/fcall');
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $evalContext = str_replace(ZEPHIRPATH, '', $expression['file'] . ':' . $expression['line']);
     $context->codePrinter->output(sprintf('zephir_eval_php(%s, %s, "%s" TSRMLS_CC);', $resolvedParams[0], $symbolVariable->getName(), $evalContext));
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) != 2) {
         return false;
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable) {
         if (!$symbolVariable->isVariable()) {
             throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
         }
     } else {
         $symbolVariable = $context->symbolTable->addTemp('variable', $context);
         $symbolVariable->initVariant($context);
     }
     /**
      * Add the last call status to the current symbol table
      */
     $call->addCallStatusFlag($context);
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $context->headersManager->add('kernel/fcall');
     /**
      * Add the last call status to the current symbol table
      */
     $call->addCallStatusFlag($context);
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('ZEPHIR_CALL_USER_FUNC_ARRAY(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ');');
     $call->addCallStatusOrJump($context);
     return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
 }
Example #27
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters'])) {
         return false;
     }
     if (count($expression['parameters']) < 2) {
         throw new CompilerException("'strpos' require two or three parameters");
     }
     /**
      * Process offset
      */
     $offset = '0 ';
     if (count($expression['parameters']) >= 3 && $expression['parameters'][2]['parameter']['type'] == 'int') {
         $offset = $expression['parameters'][2]['parameter']['value'] . ' ';
         unset($expression['parameters'][2]);
     }
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if (count($resolvedParams) >= 3) {
         $context->headersManager->add('kernel/operators');
         $offset = 'zephir_get_intval(' . $resolvedParams[2] . ') ';
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/string');
     $symbolVariable->setDynamicTypes('int');
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbol = $context->backend->getVariableCode($symbolVariable);
     $context->codePrinter->output('zephir_fast_strpos(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $offset . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
 /**
  *
  * @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("phalcon_orm_singlequotes only accepts three parameter", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     $context->codePrinter->output('phalcon_orm_singlequotes(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ');');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
Example #29
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return bool|CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (!isset($expression['parameters']) || count($expression['parameters']) != 2) {
         throw new CompilerException("'hash_equals' requires two parameters", $expression);
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if ($symbolVariable->isNotVariableAndString()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     $context->headersManager->add('kernel/string');
     /**
      * Process parameters
      */
     $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     return new CompiledExpression('bool', 'zephir_hash_equals(' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ')', $expression);
 }
Example #30
0
 /**
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  * @return CompiledExpression|mixed
  * @throws CompilerException
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     if (isset($expression['parameters'])) {
         if (count($expression['parameters']) > 1) {
             throw new CompilerException("This function only requires one parameter", $expression);
         }
     }
     /**
      * Process the expected symbol to be returned
      */
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable(true, $context);
     if (!$symbolVariable->isVariable()) {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     /**
      * Add the last call status to the current symbol table
      */
     $call->addCallStatusFlag($context);
     $context->headersManager->add('kernel/array');
     $symbolVariable->setDynamicTypes('array');
     if (isset($expression['parameters'])) {
         $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     } else {
         $resolvedParams = null;
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $symbol = $context->backend->getVariableCode($symbolVariable);
     if ($resolvedParams) {
         $context->codePrinter->output('zephir_create_array(' . $symbol . ', zephir_get_intval(' . $resolvedParams[0] . '), 1 TSRMLS_CC);');
     } else {
         $context->codePrinter->output('zephir_create_array(' . $symbol . ', 0, 1 TSRMLS_CC);');
     }
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }