当前位置: 首页>>代码示例>>PHP>>正文


PHP Zephir\Variable类代码示例

本文整理汇总了PHP中Zephir\Variable的典型用法代码示例。如果您正苦于以下问题:PHP Variable类的具体用法?PHP Variable怎么用?PHP Variable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Variable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: assign

 /**
  * Compiles {var} = {expr}
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext,
  * @param array $statement
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     $codePrinter = $compilationContext->codePrinter;
     $codePrinter->output('if (zephir_set_symbol(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getCode() . ' TSRMLS_CC) == FAILURE){');
     $codePrinter->output('  return;');
     $codePrinter->output('}');
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:16,代码来源:ExportSymbol.php

示例2: getRealCalledMethod

 /**
  * Examine internal class information and returns the method called
  *
  * @param CompilationContext $compilationContext
  * @param Variable $caller
  * @param string $methodName
  * @return array
  */
 private function getRealCalledMethod(CompilationContext $compilationContext, Variable $caller, $methodName)
 {
     $compiler = $compilationContext->compiler;
     $numberPoly = 0;
     $method = null;
     if ($caller->getRealName() == 'this') {
         $classDefinition = $compilationContext->classDefinition;
         if ($classDefinition->hasMethod($methodName)) {
             $numberPoly++;
             $method = $classDefinition->getMethod($methodName);
         }
     } else {
         $classTypes = $caller->getClassTypes();
         foreach ($classTypes as $classType) {
             if ($compiler->isClass($classType) || $compiler->isInterface($classType) || $compiler->isBundledClass($classType) || $compiler->isBundledInterface($classType)) {
                 if ($compiler->isInterface($classType)) {
                     continue;
                 }
                 if ($compiler->isClass($classType)) {
                     $classDefinition = $compiler->getClassDefinition($classType);
                 } else {
                     $classDefinition = $compiler->getInternalClassDefinition($classType);
                 }
                 if (!$classDefinition) {
                     continue;
                 }
                 if ($classDefinition->hasMethod($methodName) && !$classDefinition->isInterface()) {
                     $numberPoly++;
                     $method = $classDefinition->getMethod($methodName);
                 }
             }
         }
     }
     return array($numberPoly, $method);
 }
开发者ID:edin,项目名称:zephir,代码行数:43,代码来源:MethodCall.php

示例3: assign

 /**
  * Compiles obj->x++
  *
  * @param string $variable
  * @param string $property
  * @param ZephirVariable $symbolVariable
  * @param CompilationContext $compilationContext
  * @param array $statement
  */
 public function assign($variable, $property, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     /**
      * Arrays must be stored in the HEAP
      */
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     /**
      * Only dynamic variables can be used as arrays
      */
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
     }
     if ($symbolVariable->hasAnyDynamicType('unknown')) {
         throw new CompilerException("Cannot use non-initialized variable as an object", $statement);
     }
     /**
      * Trying to use a non-object dynamic variable as object
      */
     if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'object', 'null'))) {
         $compilationContext->logger->warning('Possible attempt to increment non-object dynamic variable', 'non-object-update', $statement);
     }
     $compilationContext->headersManager->add('kernel/object');
     $compilationContext->codePrinter->output('RETURN_ON_FAILURE(zephir_property_incr(' . $symbolVariable->getName() . ', SL("' . $property . '") TSRMLS_CC));');
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:41,代码来源:ObjectPropertyIncr.php

示例4: assign

 /**
  * Compiles obj->x++
  *
  * @param string $variable
  * @param string $property
  * @param ZephirVariable $symbolVariable
  * @param CompilationContext $compilationContext
  * @param array $statement
  */
 public function assign($variable, $property, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     /**
      * Arrays must be stored in the HEAP
      */
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     /**
      * Only dynamic variables can be used as arrays
      */
     if (!$symbolVariable->isVariable()) {
         throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
     }
     if ($symbolVariable->hasAnyDynamicType('unknown')) {
         throw new CompilerException("Cannot use non-initialized variable as an object", $statement);
     }
     /**
      * Trying to use a non-object dynamic variable as object
      */
     if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'object', 'null'))) {
         $compilationContext->logger->warning('Possible attempt to increment non-object dynamic variable', 'non-object-update', $statement);
     }
     /**
      * Check if the variable to update is defined
      */
     if ($symbolVariable->getRealName() == 'this') {
         $classDefinition = $compilationContext->classDefinition;
         if (!$classDefinition->hasProperty($property)) {
             throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement);
         }
         $propertyDefinition = $classDefinition->getProperty($property);
     } else {
         /**
          * If we know the class related to a variable we could check if the property
          * is defined on that class
          */
         if ($symbolVariable->hasAnyDynamicType('object')) {
             $classType = current($symbolVariable->getClassTypes());
             $compiler = $compilationContext->compiler;
             if ($compiler->isClass($classType)) {
                 $classDefinition = $compiler->getClassDefinition($classType);
                 if (!$classDefinition) {
                     throw new CompilerException("Cannot locate class definition for class: " . $classType, $statement);
                 }
                 if (!$classDefinition->hasProperty($property)) {
                     throw new CompilerException("Class '" . $classType . "' does not have a property called: '" . $property . "'", $statement);
                 }
             }
         }
     }
     $compilationContext->headersManager->add('kernel/object');
     $compilationContext->codePrinter->output('RETURN_ON_FAILURE(zephir_property_incr(' . $symbolVariable->getName() . ', SL("' . $property . '") TSRMLS_CC));');
 }
开发者ID:zhao5908,项目名称:zephir,代码行数:69,代码来源:ObjectPropertyIncr.php

示例5: assign

 /**
  * Compiles {var} = {expr}
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext,
  * @param array $statement
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     $codePrinter = $compilationContext->codePrinter;
     $variable = $compilationContext->symbolTable->getTempVariable('variable', $compilationContext, $statement);
     $variable->setMustInitNull(true);
     $letStatement = new LetStatement(array('type' => 'let', 'assignments' => array(array('assign-type' => 'variable', 'variable' => $variable->getName(), 'operator' => 'assign', 'expr' => array('type' => $resolvedExpr->getType(), 'value' => $resolvedExpr->getCode(), 'file' => $statement['file'], 'line' => $statement['line'], 'char' => $statement['char']), 'file' => $statement['file'], 'line' => $statement['line'], 'char' => $statement['char']))));
     $letStatement->compile($compilationContext);
     $codePrinter->output('if (zephir_set_symbol(' . $symbolVariable->getName() . ', ' . $variable->getName() . ' TSRMLS_CC) == FAILURE){');
     $codePrinter->output("\t" . 'return;');
     $codePrinter->output('}');
 }
开发者ID:edin,项目名称:zephir,代码行数:20,代码来源:ExportSymbol.php

示例6: assign

 /**
  * Compiles foo[y][] = {expr}
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext
  * @param array $statement
  * @throws CompilerException
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     /**
      * Arrays must be stored in the HEAP
      */
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     if ($symbolVariable->isReadOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
     }
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     /**
      * Only dynamic variables and arrays can be used as arrays
      */
     if ($symbolVariable->isNotVariableAndArray()) {
         throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
     }
     if ($symbolVariable->hasAnyDynamicType('unknown')) {
         throw new CompilerException("Cannot use non-initialized variable as an object", $statement);
     }
     /**
      * Trying to use a non-object dynamic variable as object
      */
     if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'array', 'null'))) {
         $compilationContext->logger->warning('Possible attempt to update index on a non-array dynamic variable', 'non-array-update', $statement);
     }
     $this->_assignArrayIndexMultiple($variable, $symbolVariable, $resolvedExpr, $compilationContext, $statement);
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:44,代码来源:ArrayIndexAppend.php

示例7: assign

 /**
  * Compiles x--
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompilationContext $compilationContext
  * @param array $statement
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     if ($symbolVariable->isReadOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
     }
     $codePrinter = $compilationContext->codePrinter;
     switch ($symbolVariable->getType()) {
         case 'int':
         case 'uint':
         case 'long':
         case 'ulong':
         case 'double':
         case 'char':
         case 'uchar':
             $codePrinter->output($variable . '--;');
             break;
         case 'variable':
             /**
              * Variable is probably not initialized here
              */
             if ($symbolVariable->hasAnyDynamicType('unknown')) {
                 throw new CompilerException("Attempt to increment uninitialized variable", $statement);
             }
             /**
              * Decrement non-numeric variables could be expensive
              */
             if (!$symbolVariable->hasAnyDynamicType(array('undefined', 'int', 'long', 'double', 'uint'))) {
                 $compilationContext->logger->warning('Possible attempt to decrement non-numeric dynamic variable', 'non-valid-decrement', $statement);
             }
             $compilationContext->headersManager->add('kernel/operators');
             if ($symbolVariable->isLocalOnly()) {
                 $codePrinter->output('zephir_decrement(&' . $variable . ');');
             } else {
                 $symbolVariable->separate($compilationContext);
                 $codePrinter->output('zephir_decrement(' . $variable . ');');
             }
             break;
         default:
             throw new CompilerException("Cannot decrement variable: " . $symbolVariable->getType(), $statement);
     }
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:52,代码来源:Decr.php

示例8: assign

 /**
  * Compiles x++
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompilationContext $compilationContext
  * @param array $statement
  *
  * @throws CompilerException
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     if ($symbolVariable->isReadOnly()) {
         /**
          * @TODO implement increment of objects members
          */
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
     }
     $codePrinter =& $compilationContext->codePrinter;
     switch ($symbolVariable->getType()) {
         case 'int':
         case 'uint':
         case 'long':
         case 'ulong':
         case 'double':
         case 'char':
         case 'uchar':
             $codePrinter->output($variable . '++;');
             break;
         case 'variable':
             /**
              * Update non-numeric dynamic variables could be expensive
              */
             if (!$symbolVariable->hasAnyDynamicType(array('undefined', 'long', 'double'))) {
                 $compilationContext->logger->warning('Possible attempt to increment non-numeric dynamic variable', 'non-valid-increment', $statement);
             }
             $compilationContext->headersManager->add('kernel/operators');
             if (!$symbolVariable->isLocalOnly()) {
                 $symbolVariable->separate($compilationContext);
             }
             $symbol = $compilationContext->backend->getVariableCode($symbolVariable);
             $codePrinter->output('zephir_increment(' . $symbol . ');');
             break;
         default:
             throw new CompilerException("Cannot increment: " . $symbolVariable->getType(), $statement);
     }
 }
开发者ID:phalcon,项目名称:zephir,代码行数:50,代码来源:Incr.php

示例9: assign

 /**
  * Compiles x->y[] = foo
  *
  * @param string $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext
  * @param array $statement
  * @throws CompilerException
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     if (!$symbolVariable->isVariable()) {
         throw new CompilerException("Attempt to use variable type: " . $symbolVariable->getType() . " as object", $statement);
     }
     $codePrinter = $compilationContext->codePrinter;
     $property = $statement['property'];
     $compilationContext->headersManager->add('kernel/object');
     /**
      * Check if the variable to update is defined
      */
     if ($symbolVariable->getRealName() == 'this') {
         $classDefinition = $compilationContext->classDefinition;
         if (!$classDefinition->hasProperty($property)) {
             throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not have a property called: '" . $property . "'", $statement);
         }
         $propertyDefinition = $classDefinition->getProperty($property);
     } else {
         /**
          * If we know the class related to a variable we could check if the property
          * is defined on that class
          */
         if ($symbolVariable->hasAnyDynamicType('object')) {
             $classType = current($symbolVariable->getClassTypes());
             $compiler = $compilationContext->compiler;
             if ($compiler->isClass($classType)) {
                 $classDefinition = $compiler->getClassDefinition($classType);
                 if (!$classDefinition) {
                     throw new CompilerException("Cannot locate class definition for class: " . $classType, $statement);
                 }
                 if (!$classDefinition->hasProperty($property)) {
                     throw new CompilerException("Class '" . $classType . "' does not have a property called: '" . $property . "'", $statement);
                 }
             }
         }
     }
     switch ($resolvedExpr->getType()) {
         case 'null':
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);');
             break;
         case 'bool':
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), (' . $resolvedExpr->getBooleanCode() . ') ? ZEPHIR_GLOBAL(global_true) : ZEPHIR_GLOBAL(global_false) TSRMLS_CC);');
             break;
         case 'char':
             $tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
             $codePrinter->output('ZVAL_LONG(' . $tempVariable->getName() . ', \'' . $resolvedExpr->getCode() . '\');');
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), ' . $tempVariable->getName() . ' TSRMLS_CC);');
             if ($tempVariable->isTemporal()) {
                 $tempVariable->setIdle(true);
             }
             break;
         case 'int':
         case 'long':
         case 'uint':
             $tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
             $codePrinter->output('ZVAL_LONG(' . $tempVariable->getName() . ', ' . $resolvedExpr->getCode() . ');');
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), ' . $tempVariable->getName() . ' TSRMLS_CC);');
             if ($tempVariable->isTemporal()) {
                 $tempVariable->setIdle(true);
             }
             break;
         case 'double':
             $tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
             $codePrinter->output('ZVAL_DOUBLE(' . $tempVariable->getName() . ', ' . $resolvedExpr->getCode() . ');');
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), ' . $tempVariable->getName() . ' TSRMLS_CC);');
             if ($tempVariable->isTemporal()) {
                 $tempVariable->setIdle(true);
             }
             break;
         case 'string':
             $tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
             $codePrinter->output('ZVAL_STRING(' . $tempVariable->getName() . ', "' . $resolvedExpr->getCode() . '", 1);');
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), ' . $tempVariable->getName() . ' TSRMLS_CC);');
             if ($tempVariable->isTemporal()) {
                 $tempVariable->setIdle(true);
             }
             break;
         case 'array':
             $variableExpr = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
             $codePrinter->output('zephir_update_property_array_append(' . $symbolVariable->getName() . ', SL("' . $property . '"), ' . $variableExpr->getName() . ' TSRMLS_CC);');
             break;
         case 'variable':
             $variableExpr = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
             switch ($variableExpr->getType()) {
                 case 'int':
                 case 'long':
                 case 'uint':
//.........这里部分代码省略.........
开发者ID:Jvbzephir,项目名称:zephir,代码行数:101,代码来源:ObjectPropertyAppend.php

示例10: ifVariableValueUndefined

 public function ifVariableValueUndefined(Variable $var, CompilationContext $context, $onlyBody = false, $useCodePrinter = true)
 {
     $body = '!' . $var->getName();
     $output = 'if (' . $body . ') {';
     if ($useCodePrinter) {
         $context->codePrinter->output($output);
     }
     return $onlyBody ? $body : $output;
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:9,代码来源:Backend.php

示例11: _accessDimensionArray

 /**
  * @param array $expression
  * @param Variable $variableVariable
  * @param CompilationContext $compilationContext
  */
 protected function _accessDimensionArray($expression, Variable $variableVariable, CompilationContext $compilationContext)
 {
     $arrayAccess = $expression;
     if ($variableVariable->getType() == 'variable') {
         if ($variableVariable->hasAnyDynamicType('unknown')) {
             throw new CompilerException("Cannot use non-initialized variable as an array", $arrayAccess['left']);
         }
         /**
          * Trying to use a non-object dynamic variable as object
          */
         if ($variableVariable->hasDifferentDynamicType(array('undefined', 'array', 'null'))) {
             $compilationContext->logger->warning('Possible attempt to access array-index on a non-array dynamic variable', 'non-array-access', $arrayAccess['left']);
         }
     }
     $codePrinter = $compilationContext->codePrinter;
     /**
      * Resolves the symbol that expects the value
      */
     $readOnly = false;
     $symbolVariable = $this->_expectingVariable;
     if ($this->_readOnly) {
         if ($this->_expecting && $this->_expectingVariable) {
             /**
              * If a variable is assigned once in the method, we try to promote it
              * to a read only variable
              */
             if ($symbolVariable->getName() != 'return_value') {
                 $line = $compilationContext->symbolTable->getLastCallLine();
                 if ($line === false || $line > 0 && $line < $expression['line']) {
                     $numberMutations = $compilationContext->symbolTable->getExpectedMutations($symbolVariable->getName());
                     if ($numberMutations == 1) {
                         if ($symbolVariable->getNumberMutations() == $numberMutations) {
                             $symbolVariable->setMemoryTracked(false);
                             $readOnly = true;
                         }
                     }
                 }
             }
             /**
              * Variable is not read-only or it wasn't promoted
              */
             if (!$readOnly) {
                 if ($symbolVariable->getName() != 'return_value') {
                     $symbolVariable->observeVariant($compilationContext);
                     $this->_readOnly = false;
                 } else {
                     $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedUninitializedVariable('variable', $compilationContext, $expression);
                 }
             }
         } else {
             $symbolVariable = $compilationContext->symbolTable->getTempNonTrackedUninitializedVariable('variable', $compilationContext, $expression);
         }
     } else {
         if ($this->_expecting && $this->_expectingVariable) {
             /**
              * If a variable is assigned once in the method, we try to promote it
              * to a read only variable
              */
             if ($symbolVariable->getName() != 'return_value') {
                 $line = $compilationContext->symbolTable->getLastCallLine();
                 if ($line === false || $line > 0 && $line < $expression['line']) {
                     $numberMutations = $compilationContext->symbolTable->getExpectedMutations($symbolVariable->getName());
                     if ($numberMutations == 1) {
                         if ($symbolVariable->getNumberMutations() == $numberMutations) {
                             $symbolVariable->setMemoryTracked(false);
                             $readOnly = true;
                         }
                     }
                 }
             }
             /**
              * Variable is not read-only or it wasn't promoted
              */
             if (!$readOnly) {
                 if ($symbolVariable->getName() != 'return_value') {
                     $symbolVariable->observeVariant($compilationContext);
                     $this->_readOnly = false;
                 } else {
                     $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
                 }
             }
         } else {
             $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
         }
     }
     /**
      * Variable that receives property accesses must be polimorphic
      */
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Cannot use variable: " . $symbolVariable->getType() . " to assign array index", $expression);
     }
     /**
      * At this point, we don't know the type fetched from the index
      */
     $symbolVariable->setDynamicTypes('undefined');
//.........这里部分代码省略.........
开发者ID:NumbDai,项目名称:zephir,代码行数:101,代码来源:NativeArrayAccess.php

示例12: assign

 /**
  * Compiles foo = {expr}
  * Changes the value of a mutable variable
  *
  * @param $variable
  * @param Variable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param ReadDetector $readDetector
  * @param CompilationContext $compilationContext
  * @param $statement
  * @throws CompilerException
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, ReadDetector $readDetector, CompilationContext $compilationContext, $statement)
 {
     if ($symbolVariable->isReadOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
     }
     $codePrinter = $compilationContext->codePrinter;
     /**
      * Only initialize variables if it's direct assignment
      */
     if ($statement['operator'] == 'assign') {
         $symbolVariable->setIsInitialized(true, $compilationContext, $statement);
     } else {
         if (!$symbolVariable->isInitialized()) {
             throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
         }
     }
     /**
      * Set the assigned value to the variable as a CompiledExpression
      * We could use this expression for further analysis
      */
     $symbolVariable->setPossibleValue($resolvedExpr, $compilationContext);
     $type = $symbolVariable->getType();
     switch ($type) {
         case 'int':
         case 'uint':
         case 'long':
         case 'ulong':
         case 'char':
         case 'uchar':
             switch ($resolvedExpr->getType()) {
                 case 'null':
                     switch ($statement['operator']) {
                         case 'assign':
                             $codePrinter->output($variable . ' = 0;');
                             break;
                         case 'add-assign':
                             $codePrinter->output($variable . ' += 0;');
                             break;
                         case 'sub-assign':
                             $codePrinter->output($variable . ' -= 0;');
                             break;
                         case 'mul-assign':
                             $codePrinter->output($variable . ' *= 0;');
                             break;
                         default:
                             throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for variable type: int", $statement);
                     }
                     break;
                 case 'int':
                 case 'uint':
                 case 'long':
                 case 'ulong':
                     switch ($statement['operator']) {
                         case 'assign':
                             $codePrinter->output($variable . ' = ' . $resolvedExpr->getCode() . ';');
                             break;
                         case 'add-assign':
                             $codePrinter->output($variable . ' += ' . $resolvedExpr->getCode() . ';');
                             break;
                         case 'sub-assign':
                             $codePrinter->output($variable . ' -= ' . $resolvedExpr->getCode() . ';');
                             break;
                         case 'mul-assign':
                             $codePrinter->output($variable . ' *= ' . $resolvedExpr->getCode() . ';');
                             break;
                         case 'div-assign':
                             $codePrinter->output($variable . ' /= ' . $resolvedExpr->getCode() . ';');
                             break;
                         case 'mod-assign':
                             $codePrinter->output($variable . ' %= ' . $resolvedExpr->getCode() . ';');
                             break;
                         default:
                             throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for variable type: int", $statement);
                     }
                     break;
                 case 'char':
                 case 'uchar':
                     switch ($statement['operator']) {
                         case 'assign':
                             $codePrinter->output($variable . ' = \'' . $resolvedExpr->getCode() . '\';');
                             break;
                         case 'add-assign':
                             $codePrinter->output($variable . ' += \'' . $resolvedExpr->getCode() . '\';');
                             break;
                         case 'sub-assign':
                             $codePrinter->output($variable . ' -= \'' . $resolvedExpr->getCode() . '\';');
                             break;
                         case 'mul-assign':
//.........这里部分代码省略.........
开发者ID:NumbDai,项目名称:zephir,代码行数:101,代码来源:Variable.php

示例13: assign

 /**
  * Compiles foo[] = {expr}
  *
  * @param $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext
  * @param $statement
  * @throws CompilerException
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     if ($symbolVariable->isReadOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
     }
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
     }
     if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'array'))) {
         $compilationContext->logger->warning('Possible attempt to append elements on a non-array dynamic variable', 'non-array-append', $statement);
     }
     $codePrinter = $compilationContext->codePrinter;
     $compilationContext->headersManager->add('kernel/array');
     $type = $symbolVariable->getType();
     switch ($type) {
         case 'variable':
             switch ($resolvedExpr->getType()) {
                 case 'null':
                     $codePrinter->output('zephir_array_append(&' . $variable . ', ZEPHIR_GLOBAL(global_null), PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                     break;
                 case 'int':
                 case 'uint':
                 case 'long':
                     $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $codePrinter->output('ZVAL_LONG(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getCode() . ');');
                     $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                     $symbolVariable->setIdle(true);
                     break;
                 case 'double':
                     $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $codePrinter->output('ZVAL_DOUBLE(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getCode() . ');');
                     $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                     $symbolVariable->setIdle(true);
                     break;
                 case 'bool':
                     $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $codePrinter->output('ZVAL_BOOL(' . $symbolVariable->getName() . ', ' . $resolvedExpr->getBooleanCode() . ');');
                     $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                     $symbolVariable->setIdle(true);
                     break;
                 case 'ulong':
                 case 'string':
                     $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $codePrinter->output('ZVAL_STRING(' . $symbolVariable->getName() . ', "' . Utils::addSlashes($resolvedExpr->getCode(), true) . '", 1);');
                     $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                     $symbolVariable->setIdle(true);
                     break;
                 case 'array':
                     $exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
                     $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $exprVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                     break;
                 case 'variable':
                     $exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
                     switch ($exprVariable->getType()) {
                         case 'int':
                         case 'uint':
                         case 'long':
                             $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                             $codePrinter->output('ZVAL_LONG(' . $symbolVariable->getName() . ', ' . $exprVariable->getName() . ');');
                             $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                             $symbolVariable->setIdle(true);
                             break;
                         case 'double':
                             $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                             $codePrinter->output('ZVAL_DOUBLE(' . $symbolVariable->getName() . ', ' . $exprVariable->getName() . ');');
                             $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                             $symbolVariable->setIdle(true);
                             break;
                         case 'bool':
                             $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                             $codePrinter->output('ZVAL_BOOL(' . $symbolVariable->getName() . ', ' . $exprVariable->getName() . ');');
                             $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $symbolVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                             $symbolVariable->setIdle(true);
                             break;
                         case 'variable':
                         case 'string':
                         case 'array':
                             $codePrinter->output('zephir_array_append(&' . $variable . ', ' . $exprVariable->getName() . ', PH_SEPARATE, "' . Compiler::getShortUserPath($statement['file']) . '", ' . $statement['line'] . ');');
                             break;
                         default:
                             throw new CompilerException("Unknown type " . $exprVariable->getType(), $statement);
                     }
                     break;
                 default:
//.........这里部分代码省略.........
开发者ID:NumbDai,项目名称:zephir,代码行数:101,代码来源:VariableAppend.php

示例14: getVariableForUpdate

 /**
  * Return a variable in the symbol table, it will be used for a mutating operation
  * This method implies mutation of one of the members of the variable but no the variables it self
  *
  * @param string $name
  * @param CompilationContext $compilationContext
  * @param array $statement
  * @return Variable
  */
 public function getVariableForUpdate($name, CompilationContext $compilationContext, array $statement = null)
 {
     /**
      * Create superglobals just in time
      */
     if ($this->isSuperGlobal($name)) {
         if (!$this->hasVariable($name)) {
             /**
              * @TODO, injecting globals, initialize to null and check first?
              */
             $superVar = new Variable('variable', $name, $compilationContext->currentBranch);
             $superVar->setIsInitialized(true, $compilationContext, $statement);
             $superVar->setDynamicTypes('array');
             $superVar->increaseMutates();
             $superVar->increaseUses();
             $superVar->setIsExternal(true);
             $superVar->setUsed(true, $statement);
             $this->variables[$name] = $superVar;
             return $superVar;
         }
     }
     if (!$this->hasVariable($name)) {
         throw new CompilerException("Cannot mutate variable '" . $name . "' because it wasn't defined", $statement);
     }
     $variable = $this->getVariable($name);
     $variable->increaseUses();
     $variable->increaseMutates();
     /**
      * Saves the last place where the variable was mutated
      * We discard mutations inside loops because iterations could use the value
      * and Zephir only provides top-down compilation
      */
     $variable->setUsed(true, $statement);
     return $variable;
 }
开发者ID:Jvbzephir,项目名称:zephir,代码行数:44,代码来源:SymbolTable.php

示例15: assign

 /**
  * Compiles foo[] = {expr}
  *
  * @param $variable
  * @param ZephirVariable $symbolVariable
  * @param CompiledExpression $resolvedExpr
  * @param CompilationContext $compilationContext
  * @param $statement
  * @throws CompilerException
  */
 public function assign($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     if ($symbolVariable->isReadOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is read only", $statement);
     }
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     /**
      * Only dynamic variables and arrays can be used as arrays
      */
     if ($symbolVariable->isNotVariableAndArray()) {
         throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as an array", $statement);
     }
     if ($symbolVariable->getType() == 'variable') {
         if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'array'))) {
             $compilationContext->logger->warning('Possible attempt to append elements on a non-array dynamic variable', 'non-array-append', $statement);
         }
     }
     $codePrinter = $compilationContext->codePrinter;
     $compilationContext->headersManager->add('kernel/array');
     $type = $symbolVariable->getType();
     switch ($type) {
         case 'array':
         case 'variable':
             switch ($resolvedExpr->getType()) {
                 case 'null':
                     $compilationContext->backend->addArrayEntry($symbolVariable, null, 'null', $compilationContext, $statement);
                     break;
                 case 'int':
                 case 'uint':
                 case 'long':
                     $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $compilationContext->backend->assignLong($tempVariable, $resolvedExpr->getCode(), $compilationContext);
                     $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                     $tempVariable->setIdle(true);
                     break;
                 case 'double':
                     $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $compilationContext->backend->assignDouble($tempVariable, $resolvedExpr->getCode(), $compilationContext);
                     $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                     $tempVariable->setIdle(true);
                     break;
                 case 'bool':
                     $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $compilationContext->backend->assignBool($tempVariable, $resolvedExpr->getBooleanCode(), $compilationContext);
                     $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                     $tempVariable->setIdle(true);
                     break;
                 case 'ulong':
                 case 'string':
                     $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                     $compilationContext->backend->assignString($tempVariable, $resolvedExpr->getBooleanCode(), $compilationContext);
                     $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                     $tempVariable->setIdle(true);
                     break;
                 case 'array':
                     $exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
                     $compilationContext->backend->addArrayEntry($symbolVariable, null, $exprVariable, $compilationContext, $statement);
                     break;
                 case 'variable':
                     $exprVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
                     switch ($exprVariable->getType()) {
                         case 'int':
                         case 'uint':
                         case 'long':
                             $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                             $compilationContext->backend->assignLong($tempVariable, $exprVariable, $compilationContext);
                             $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                             $tempVariable->setIdle(true);
                             break;
                         case 'double':
                             $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                             $compilationContext->backend->assignDouble($tempVariable, $exprVariable, $compilationContext);
                             $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                             $tempVariable->setIdle(true);
                             break;
                         case 'bool':
                             $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
                             $compilationContext->backend->assignBool($tempVariable, $exprVariable, $compilationContext);
                             $compilationContext->backend->addArrayEntry($symbolVariable, null, $tempVariable, $compilationContext, $statement);
                             $tempVariable->setIdle(true);
                             break;
                         case 'variable':
                         case 'string':
                         case 'array':
                             $compilationContext->backend->addArrayEntry($symbolVariable, null, $exprVariable, $compilationContext, $statement);
//.........这里部分代码省略.........
开发者ID:chet0xhenry,项目名称:zephir,代码行数:101,代码来源:VariableAppend.php


注:本文中的Zephir\Variable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。