php Zephir-Expression类(方法)实例源码

下面列出了php Zephir-Expression 类(方法)源码代码实例,从而了解它的用法。

作者:chet0xhenr    项目:zephi   
/**
  * Compiles foo[y][x][] = {expr} (multiple offset)
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext
  * @param array $statement
  */
 protected function _assignArrayIndexMultiple($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     $codePrinter = $compilationContext->codePrinter;
     $offsetExprs = array();
     foreach ($statement['index-expr'] as $indexExpr) {
         $expression = new Expression($indexExpr);
         $expression->setReadOnly(true);
         $exprIndex = $expression->compile($compilationContext);
         switch ($exprIndex->getType()) {
             case 'int':
             case 'uint':
             case 'long':
             case 'ulong':
             case 'string':
             case 'variable':
                 break;
             default:
                 throw new CompilerException("Index: " . $exprIndex->getType() . " cannot be used as array index in assignment without cast", $indexExpr);
         }
         $offsetExprs[] = $exprIndex;
     }
     $compilationContext->headersManager->add('kernel/array');
     /**
      * Create a temporal zval (if needed)
      */
     $symbolVariable = $this->_getResolvedArrayItem($resolvedExpr, $compilationContext);
     $targetVariable = $compilationContext->symbolTable->getVariableForWrite($variable, $compilationContext, $statement);
     $offsetExprs[] = 'a';
     $compilationContext->backend->assignArrayMulti($targetVariable, $symbolVariable, $offsetExprs, $compilationContext);
 }

作者:Jvbzephi    项目:zephi   
/**
  * @param array $expression
  * @param CompilationContext $compilationContext
  * @return CompiledExpression
  * @throws CompilerException
  */
 public function compile(array $expression, CompilationContext $compilationContext)
 {
     $expr = new Expression($expression['left']);
     $expr->setReadOnly(true);
     $expr->setExpectReturn(true);
     $exprPath = $expr->compile($compilationContext);
     if ($exprPath->getType() == 'variable') {
         $exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression);
         if ($exprVariable->getType() == 'variable') {
             if ($exprVariable->hasDifferentDynamicType(array('undefined', 'string'))) {
                 $compilationContext->logger->warning('Possible attempt to use invalid type as path in "require" operator', 'non-valid-require', $expression);
             }
         }
     }
     $symbolVariable = false;
     if ($this->isExpecting()) {
         $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
     }
     $compilationContext->headersManager->add('kernel/memory');
     $compilationContext->headersManager->add('kernel/require');
     $codePrinter = $compilationContext->codePrinter;
     if ($symbolVariable) {
         $codePrinter->output('ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(&' . $symbolVariable->getName() . ');');
         $codePrinter->output('if (zephir_require_zval_ret(&' . $symbolVariable->getName() . ', ' . $exprPath->getCode() . ' TSRMLS_CC) == FAILURE) {');
     } else {
         $codePrinter->output('if (zephir_require_zval(' . $exprPath->getCode() . ' TSRMLS_CC) == FAILURE) {');
     }
     $codePrinter->output("\t" . 'RETURN_MM_NULL();');
     $codePrinter->output('}');
     if ($symbolVariable) {
         return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
     }
     return new CompiledExpression('null', null, $expression);
 }

作者:zhao590    项目:zephi   
/**
  * @param CompilationContext $compilationContext
  * @throws CompilerException
  */
 public function compile(CompilationContext $compilationContext)
 {
     $expression = array('type' => 'require', 'left' => $this->_statement['expr'], 'file' => $this->_statement['file'], 'line' => $this->_statement['line'], 'char' => $this->_statement['char']);
     $expr = new Expression($expression);
     $expr->setExpectReturn(false, null);
     $expr->compile($compilationContext);
 }

作者:chet0xhenr    项目:zephi   
/**
  * @param $expression
  * @param CompilationContext $compilationContext
  * @return CompiledExpression
  * @throws CompilerException
  * @throws Exception
  */
 public function compile($expression, CompilationContext $compilationContext)
 {
     if (!isset($expression['left'])) {
         throw new CompilerException("Missing left part of the expression", $expression);
     }
     $leftExpr = new Expression($expression['left']);
     $leftExpr->setReadOnly($this->_readOnly);
     $left = $leftExpr->compile($compilationContext);
     switch ($left->getType()) {
         case 'bool':
         case 'int':
         case 'uint':
         case 'long':
         case 'ulong':
             return new CompiledExpression('int', '~(' . $left->getCode() . ')', $expression);
         case 'variable':
             $variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
             switch ($variable->getType()) {
                 case 'bool':
                 case 'int':
                 case 'uint':
                 case 'long':
                     return new CompiledExpression('int', '~' . $variable->getName(), $expression);
                 case 'variable':
                     $compilationContext->headersManager->add('kernel/operators');
                     return new CompiledExpression('int', '~zephir_get_intval(' . $variable->getName() . ')', $expression);
                 default:
                     throw new CompilerException("Unknown type: " . $variable->getType(), $expression);
             }
             break;
         default:
             throw new CompilerException("Unknown type: " . $left->getType(), $expression);
     }
 }

作者:zhao590    项目:zephi   
/**
  * Compiles x::y[a][b] = {expr} (multiple offset assignment)
  *
  * @param string $variable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext,
  * @param array $statement
  */
 protected function _assignStaticPropertyArrayMultipleIndex($classEntry, $property, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     $codePrinter = $compilationContext->codePrinter;
     $property = $statement['property'];
     $compilationContext->headersManager->add('kernel/object');
     /**
      * Create a temporal zval (if needed)
      */
     $variableExpr = $this->_getResolvedArrayItem($resolvedExpr, $compilationContext);
     /**
      * Only string/variable/int
      */
     $offsetExprs = array();
     foreach ($statement['index-expr'] as $indexExpr) {
         $indexExpression = new Expression($indexExpr);
         $resolvedIndex = $indexExpression->compile($compilationContext);
         switch ($resolvedIndex->getType()) {
             case 'string':
             case 'int':
             case 'uint':
             case 'ulong':
             case 'long':
             case 'variable':
                 break;
             default:
                 throw new CompilerException("Expression: " . $resolvedIndex->getType() . " cannot be used as index without cast", $statement['index-expr']);
         }
         $offsetExprs[] = $resolvedIndex;
     }
     $compilationContext->backend->assignStaticPropertyArrayMulti($classEntry, $variableExpr, $property, $offsetExprs, $compilationContext);
     if ($variableExpr->isTemporal()) {
         $variableExpr->setIdle(true);
     }
 }

作者:chet0xhenr    项目:zephi   
/**
  * 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);
 }

作者:edi    项目:zephi   
/**
  * Compile expression
  *
  * @param $expression
  * @param CompilationContext $compilationContext
  * @return CompiledExpression
  * @throws CompilerException
  * @throws Exception
  */
 public function compile($expression, CompilationContext $compilationContext)
 {
     if (!isset($expression['left'])) {
         throw new \Exception("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':
                     return new CompiledExpression('variable', $variable->getName(), $expression);
                 default:
                     throw new CompilerException("Cannot operate plus with variable of '" . $left->getType() . "' type");
             }
             break;
         default:
             throw new CompilerException("Cannot operate plus with '" . $left->getType() . "' type");
     }
 }

作者:Jvbzephi    项目:zephi   
/**
  * @param array $expression
  * @param CompilationContext $compilationContext
  * @return CompiledExpression
  * @throws CompilerException
  */
 public function compile(array $expression, CompilationContext $compilationContext)
 {
     $compilationContext->headersManager->add('kernel/object');
     $exprVariable = new Expression($expression['left']);
     $exprVariable->setReadOnly(true);
     $exprVariable->setExpectReturn(true);
     $exprCompiledVariable = $exprVariable->compile($compilationContext);
     if ($exprCompiledVariable->getType() != 'variable') {
         throw new CompilerException("Expression type: " . $exprCompiledVariable->getType() . " cannot be used as array", $expression);
     }
     $clonedVariable = $compilationContext->symbolTable->getVariableForRead($exprCompiledVariable->getCode(), $compilationContext, $expression);
     if ($clonedVariable->getType() != 'variable') {
         throw new CompilerException("Variable type: " . $exprVariable->getType() . " cannot be cloned");
     }
     if ($clonedVariable->hasDifferentDynamicType(array('undefined', 'object', 'null'))) {
         $compilationContext->logger->warning('Possible attempt to use non array in "clone" operator', 'non-valid-clone', $expression);
     }
     $symbolVariable = $this->getExpected($compilationContext, $expression);
     if (!$symbolVariable->isVariable()) {
         throw new CompilerException("Objects can only be cloned into dynamic variables", $expression);
     }
     $symbolVariable->setDynamicTypes('object');
     $symbolVariable->setIsInitialized(true, $compilationContext, $expression);
     /* Inherit the dynamic type data from the cloned object */
     $symbolVariable->setDynamicTypes($clonedVariable->getDynamicTypes());
     $symbolVariable->setClassTypes($clonedVariable->getClassTypes());
     $compilationContext->codePrinter->output('if (zephir_clone(' . $symbolVariable->getName() . ', ' . $clonedVariable->getName() . ' TSRMLS_CC) == FAILURE) {');
     $compilationContext->codePrinter->output("\t" . 'RETURN_MM();');
     $compilationContext->codePrinter->output('}');
     return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
 }

作者:chet0xhenr    项目:zephi   
/**
  * 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)
 {
     $exprBuilder = BuilderFactory::getInstance();
     $functionCall = $exprBuilder->statements()->functionCall('sprintf', array($exprBuilder->literal(Types::STRING, '%X'), $caller))->setFile($expression['file'])->setLine($expression['line'])->setChar($expression['char']);
     $expression = new Expression($functionCall->build());
     return $expression->compile($compilationContext);
 }

作者:NumbDa    项目:zephi   
/**
  * Resolves the access to a property in an object
  *
  * @param array $expression
  * @param CompilationContext $compilationContext
  * @return \CompiledExpression
  */
 public function compile($expression, CompilationContext $compilationContext)
 {
     $codePrinter = $compilationContext->codePrinter;
     $propertyAccess = $expression;
     $expr = new Expression($propertyAccess['left']);
     $exprVariable = $expr->compile($compilationContext);
     switch ($exprVariable->getType()) {
         case 'variable':
             $variableVariable = $compilationContext->symbolTable->getVariableForRead($exprVariable->getCode(), $compilationContext, $expression);
             switch ($variableVariable->getType()) {
                 case 'variable':
                     break;
                 default:
                     throw new CompilerException("Variable type: " . $variableVariable->getType() . " cannot be used as object", $propertyAccess['left']);
             }
             break;
         default:
             throw new CompilerException("Cannot use expression: " . $exprVariable->getType() . " as an object", $propertyAccess['left']);
     }
     switch ($propertyAccess['right']['type']) {
         case 'variable':
             $propertyVariable = $compilationContext->symbolTable->getVariableForRead($propertyAccess['right']['value'], $compilationContext, $expression);
             break;
         case 'string':
             $propertyVariable = $compilationContext->symbolTable->getTempVariableForWrite('string', $compilationContext);
             $statement = new LetStatement(array('type' => 'let', 'assignments' => array(array('assign-type' => 'variable', 'variable' => $propertyVariable->getName(), 'operator' => 'assign', 'expr' => $expression['right']))));
             $statement->compile($compilationContext);
             break;
         default:
             throw new CompilerException("Variable type: " . $propertyAccess['right']['type'] . " cannot be used as object", $propertyAccess['left']);
     }
     /**
      * Resolves the symbol that expects the value
      */
     if ($this->_expecting) {
         if ($this->_expectingVariable) {
             $symbolVariable = $this->_expectingVariable;
             if ($symbolVariable->getName() != 'return_value') {
                 $symbolVariable->observeVariant($compilationContext);
             } else {
                 $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
             }
         } else {
             $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
         }
     }
     /**
      * Variable that receives a property value must be polymorphic
      */
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Cannot use variable: " . $symbolVariable->getType() . " to assign property value", $expression);
     }
     /**
      * At this point, we don't know the exact dynamic type fetched from the property
      */
     $symbolVariable->setDynamicTypes('undefined');
     $compilationContext->headersManager->add('kernel/object');
     $codePrinter->output('zephir_read_property_zval(&' . $symbolVariable->getName() . ', ' . $variableVariable->getName() . ', ' . $propertyVariable->getName() . ', PH_NOISY_CC);');
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }

作者:chet0xhenr    项目:zephi   
/**
  * Resolves the access to a property in an object
  *
  * @param array $expression
  * @param CompilationContext $compilationContext
  * @return \CompiledExpression
  */
 public function compile($expression, CompilationContext $compilationContext)
 {
     $codePrinter = $compilationContext->codePrinter;
     $propertyAccess = $expression;
     $expr = new Expression($propertyAccess['left']);
     $exprVariable = $expr->compile($compilationContext);
     switch ($exprVariable->getType()) {
         case 'variable':
             $variableVariable = $compilationContext->symbolTable->getVariableForRead($exprVariable->getCode(), $compilationContext, $expression);
             switch ($variableVariable->getType()) {
                 case 'variable':
                     break;
                 default:
                     throw new CompilerException("Variable type: " . $variableVariable->getType() . " cannot be used as object", $propertyAccess['left']);
             }
             break;
         default:
             throw new CompilerException("Cannot use expression: " . $exprVariable->getType() . " as an object", $propertyAccess['left']);
     }
     switch ($propertyAccess['right']['type']) {
         case 'variable':
             $propertyVariable = $compilationContext->symbolTable->getVariableForRead($propertyAccess['right']['value'], $compilationContext, $expression);
             break;
         case 'string':
             $propertyVariable = null;
             break;
         default:
             throw new CompilerException("Variable type: " . $propertyAccess['right']['type'] . " cannot be used as object", $propertyAccess['left']);
     }
     /**
      * Resolves the symbol that expects the value
      */
     if ($this->_expecting) {
         if ($this->_expectingVariable) {
             $symbolVariable = $this->_expectingVariable;
             if ($symbolVariable->getName() != 'return_value') {
                 $symbolVariable->observeVariant($compilationContext);
             } else {
                 $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
             }
         } else {
             $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
         }
     }
     /**
      * Variable that receives a property value must be polymorphic
      */
     if ($symbolVariable && !$symbolVariable->isVariable()) {
         throw new CompilerException("Cannot use variable: " . $symbolVariable->getType() . " to assign property value", $expression);
     }
     /**
      * At this point, we don't know the exact dynamic type fetched from the property
      */
     $symbolVariable->setDynamicTypes('undefined');
     $compilationContext->headersManager->add('kernel/object');
     $property = $propertyVariable ? $propertyVariable : Utils::addSlashes($expression['right']['value']);
     $compilationContext->backend->fetchProperty($symbolVariable, $variableVariable, $property, false, $compilationContext, false);
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }

作者:chet0xhenr    项目:zephi   
/**
  * @param CompilationContext $compilationContext
  * @throws CompilerException
  */
 public function compile(CompilationContext $compilationContext)
 {
     $compilationContext->headersManager->add('kernel/exception');
     $codePrinter = $compilationContext->codePrinter;
     $statement = $this->_statement;
     $expr = $statement['expr'];
     /**
      * This optimizes throw new Exception("hello")
      */
     if (!$compilationContext->insideTryCatch) {
         if (isset($expr['class']) && isset($expr['parameters']) && count($expr['parameters']) == 1 && $expr['parameters'][0]['parameter']['type'] == 'string') {
             $className = Utils::getFullName($expr['class'], $compilationContext->classDefinition->getNamespace(), $compilationContext->aliasManager);
             if ($compilationContext->compiler->isClass($className)) {
                 $classDefinition = $compilationContext->compiler->getClassDefinition($className);
                 $message = $expr['parameters'][0]['parameter']['value'];
                 $class = $classDefinition->getClassEntry();
                 $this->throwStringException($codePrinter, $class, $message, $statement['expr']);
                 return;
             } else {
                 if ($compilationContext->compiler->isBundledClass($className)) {
                     $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, $compilationContext, true);
                     if ($classEntry) {
                         $message = $expr['parameters'][0]['parameter']['value'];
                         $this->throwStringException($codePrinter, $classEntry, $message, $statement['expr']);
                         return;
                     }
                 }
             }
         } else {
             if (in_array($expr['type'], array('string', 'char', 'int', 'double'))) {
                 $class = $compilationContext->classDefinition->getClassEntryByClassName('Exception', $compilationContext);
                 $this->throwStringException($codePrinter, $class, $expr['value'], $expr);
                 return;
             }
         }
     }
     $throwExpr = new Expression($expr);
     $resolvedExpr = $throwExpr->compile($compilationContext);
     if (!in_array($resolvedExpr->getType(), array('variable', 'string'))) {
         throw new CompilerException("Expression '" . $resolvedExpr->getType() . '" cannot be used as exception', $expr);
     }
     $variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $expr);
     if (!in_array($variableVariable->getType(), array('variable', 'string'))) {
         throw new CompilerException("Variable '" . $variableVariable->getType() . "' cannot be used as exception", $expr);
     }
     $variableCode = $compilationContext->backend->getVariableCode($variableVariable);
     $codePrinter->output('zephir_throw_exception_debug(' . $variableCode . ', "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ' TSRMLS_CC);');
     if (!$compilationContext->insideTryCatch) {
         $codePrinter->output('ZEPHIR_MM_RESTORE();');
         $codePrinter->output('return;');
     } else {
         $codePrinter->output('goto try_end_' . $compilationContext->currentTryCatch . ';');
         $codePrinter->outputBlankLine();
     }
     if ($variableVariable->isTemporal()) {
         $variableVariable->setIdle(true);
     }
 }

作者:NumbDa    项目:zephi   
/**
  * @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);
 }

作者:Mrhjx    项目:zephi   
/**
  * @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']);
     }
     $functionCall = BuilderFactory::getInstance()->statements()->functionCall('gettype', array($expression['left']));
     $expression = new Expression($functionCall->build());
     return $expression->compile($compilationContext);
 }

作者:NumbDa    项目:zephi   
/**
  * @param CompilationContext $compilationContext
  * @throws CompilerException
  */
 public function compile(CompilationContext $compilationContext)
 {
     $compilationContext->headersManager->add('kernel/exception');
     $codePrinter = $compilationContext->codePrinter;
     $statement = $this->_statement;
     $expr = $statement['expr'];
     /**
      * This optimizes throw new Exception("hello")
      */
     if (!$compilationContext->insideTryCatch) {
         if (isset($expr['class'])) {
             if (isset($expr['parameters']) && count($expr['parameters']) == 1) {
                 if ($expr['parameters'][0]['parameter']['type'] == 'string') {
                     $className = Utils::getFullName($expr['class'], $compilationContext->classDefinition->getNamespace(), $compilationContext->aliasManager);
                     if ($compilationContext->compiler->isClass($className)) {
                         $classDefinition = $compilationContext->compiler->getClassDefinition($className);
                         $message = $expr['parameters'][0]['parameter']['value'];
                         $codePrinter->output('ZEPHIR_THROW_EXCEPTION_DEBUG_STR(' . $classDefinition->getClassEntry() . ', "' . Utils::addSlashes($message, true, Types::STRING) . '", "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ');');
                         $codePrinter->output('return;');
                         return;
                     } else {
                         if ($compilationContext->compiler->isInternalClass($className)) {
                             $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, true);
                             if ($classEntry) {
                                 $message = $expr['parameters'][0]['parameter']['value'];
                                 $codePrinter->output('ZEPHIR_THROW_EXCEPTION_DEBUG_STR(' . $classEntry . ', "' . Utils::addSlashes($message, true, Types::STRING) . '", "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ');');
                                 $codePrinter->output('return;');
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     $throwExpr = new Expression($expr);
     $resolvedExpr = $throwExpr->compile($compilationContext);
     if ($resolvedExpr->getType() != 'variable') {
         throw new CompilerException("Expression '" . $resolvedExpr->getType() . '" cannot be used as exception', $expr);
     }
     $variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $expr);
     if ($variableVariable->getType() != 'variable') {
         throw new CompilerException("Variable '" . $variableVariable->getType() . "' cannot be used as exception", $expr);
     }
     $codePrinter->output('zephir_throw_exception_debug(' . $variableVariable->getName() . ', "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ' TSRMLS_CC);');
     if (!$compilationContext->insideTryCatch) {
         $codePrinter->output('ZEPHIR_MM_RESTORE();');
         $codePrinter->output('return;');
     } else {
         $codePrinter->output('goto try_end_' . $compilationContext->insideTryCatch . ';');
         $codePrinter->outputBlankLine();
     }
     if ($variableVariable->isTemporal()) {
         $variableVariable->setIdle(true);
     }
 }

作者:edi    项目:zephi   
/**
  * @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);
 }

作者:chet0xhenr    项目:zephi   
/**
  * @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']);
     }
     $exprBuilder = Expression\Builder\BuilderFactory::getInstance();
     /**
      * Implicit type coercing
      */
     $castBuilder = $exprBuilder->operators()->cast(Types::ARRAY_, $exprBuilder->statements()->functionCall('range', array($expression['left'], $expression['right'])));
     $expression = new Expression($castBuilder->build());
     $expression->setReadOnly($this->_readOnly);
     return $expression->compile($compilationContext);
 }

作者:NumbDa    项目:zephi   
/**
  * 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);
 }

作者:NumbDa    项目:zephi   
/**
  *
  * @param array $expression
  * @param \CompilationContext $compilationContext
  * @return \CompiledExpression
  */
 public function compile($expression, CompilationContext $compilationContext)
 {
     $compilationContext->headersManager->add('kernel/operators');
     if (!isset($expression['left'])) {
         throw new CompilerException("Invalid 'left' operand for 'empty' expression", $expression['left']);
     }
     $leftExpr = new Expression($expression['left']);
     $leftExpr->setReadOnly(true);
     $left = $leftExpr->compile($compilationContext);
     if ($left->getType() != 'variable') {
         throw new CompilerException("'empty' operand only can be a variable", $expression['left']);
     }
     $variableLeft = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
     if ($variableLeft->isNotVariableAndString()) {
         throw new CompilerException("Only dynamic/string variables can be used in 'empty' operators", $expression['left']);
     }
     return new CompiledExpression('bool', 'ZEPHIR_IS_EMPTY(' . $variableLeft->getName() . ')', $expression);
 }

作者:chet0xhenr    项目:zephi   
/**
  * @param CompilationContext $compilationContext
  * @throws CompilerException
  */
 public function compile(CompilationContext $compilationContext)
 {
     $compilationContext->headersManager->add('kernel/array');
     $expression = $this->_statement['expr'];
     $flags = 'PH_SEPARATE';
     if ($expression['type'] == 'list') {
         $expression = $expression['left'];
     }
     switch ($expression['type']) {
         case 'array-access':
             $expr = new Expression($expression['left']);
             $expr->setReadOnly(true);
             $exprVar = $expr->compile($compilationContext);
             $variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->_statement);
             $expr = new Expression($expression['right']);
             $expr->setReadOnly(true);
             $exprIndex = $expr->compile($compilationContext);
             break;
         case 'property-access':
             $expr = new Expression($expression['left']);
             $expr->setReadOnly(true);
             $exprVar = $expr->compile($compilationContext);
             $variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->_statement);
             $variableCode = $compilationContext->backend->getVariableCode($variable);
             $compilationContext->headersManager->add('kernel/object');
             $compilationContext->codePrinter->output('zephir_unset_property(' . $variableCode . ', "' . $expression['right']['value'] . '" TSRMLS_CC);');
             return true;
         case 'property-dynamic-access':
             //@todo fix it
         //@todo fix it
         default:
             throw new CompilerException('Cannot use expression type: ' . $expression['type'] . ' in "unset"', $expression);
     }
     if (!in_array($variable->getType(), array('variable', 'array'))) {
         throw new CompilerException('Cannot use variable type: ' . $variable->gettype() . ' in "unset"', $expression['left']);
     }
     if ($variable->hasDifferentDynamicType(array('undefined', 'array', 'object', 'null'))) {
         $compilationContext->logger->warning('Possible attempt to use non array/object in unset operator', 'non-valid-unset', $expression['left']);
     }
     $compilationContext->backend->arrayUnset($variable, $exprIndex, $flags, $compilationContext);
 }


问题


面经


文章

微信
公众号

扫码关注公众号