本文整理汇总了PHP中Zephir\Variable::hasAnyDynamicType方法的典型用法代码示例。如果您正苦于以下问题:PHP Variable::hasAnyDynamicType方法的具体用法?PHP Variable::hasAnyDynamicType怎么用?PHP Variable::hasAnyDynamicType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zephir\Variable
的用法示例。
在下文中一共展示了Variable::hasAnyDynamicType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));');
}
示例2: 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));');
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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':
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, 'null', $compilationContext);
break;
case 'bool':
$codePrinter->output('if (' . $resolvedExpr->getBooleanCode() . ') {');
$codePrinter->increaseLevel();
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, 'true', $compilationContext);
$codePrinter->decreaseLevel();
$codePrinter->output('} else {');
$codePrinter->increaseLevel();
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, 'false', $compilationContext);
$codePrinter->decreaseLevel();
$codePrinter->output('}');
break;
case 'char':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
$compilationContext->backend->assignLong($tempVariable, '\'' . $resolvedExpr->getCode() . '\'', $compilationContext);
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, $tempVariable, $compilationContext);
if ($tempVariable->isTemporal()) {
$tempVariable->setIdle(true);
}
break;
case 'int':
case 'long':
case 'uint':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
$compilationContext->backend->assignLong($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, $tempVariable, $compilationContext);
if ($tempVariable->isTemporal()) {
$tempVariable->setIdle(true);
}
break;
case 'double':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
$compilationContext->backend->assignDouble($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, $tempVariable, $compilationContext);
if ($tempVariable->isTemporal()) {
$tempVariable->setIdle(true);
}
break;
case 'string':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext, true);
$compilationContext->backend->assignString($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->assignArrayProperty($symbolVariable, $property, null, $tempVariable, $compilationContext);
if ($tempVariable->isTemporal()) {
$tempVariable->setIdle(true);
}
break;
case 'array':
$variableExpr = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
//.........这里部分代码省略.........
示例6: assign
/**
* Compiles foo->{x} = {expr}
*
* @param string $variable
* @param Variable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
*/
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->getType() != 'variable') {
throw new CompilerException("Variable type '" . $symbolVariable->getType() . "' cannot be used as object", $statement);
}
$propertyName = $statement['property'];
$propertyVariable = $compilationContext->symbolTable->getVariableForRead($propertyName, $compilationContext, $statement);
if ($propertyVariable->isNotVariableAndString()) {
throw new CompilerException("Cannot use variable type '" . $propertyVariable->getType() . "' to update object property", $statement);
}
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate static property '" . $compilationContext->classDefinition->getCompleteName() . "::" . $propertyName . "' because it is not initialized", $statement);
}
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " as an object", $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 update property on non-object dynamic property', 'non-valid-objectupdate', $statement);
}
$codePrinter = $compilationContext->codePrinter;
$compilationContext->headersManager->add('kernel/object');
$propertyVariableName = $compilationContext->symbolTable->getVariable($propertyName);
switch ($resolvedExpr->getType()) {
case 'null':
if ($variable == 'this') {
$codePrinter->output('zephir_update_property_this(this_ptr, Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);');
}
break;
case 'int':
case 'long':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$codePrinter->output('ZVAL_LONG(' . $tempVariable->getName() . ', ' . $resolvedExpr->getBooleanCode() . ');');
if ($variable == 'this') {
$codePrinter->output('zephir_update_property_this(this_ptr, Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ' . $tempVariable->getName() . ' TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ' . $tempVariable->getName() . ' TSRMLS_CC);');
}
break;
case 'string':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$codePrinter->output('ZVAL_STRING(' . $tempVariable->getName() . ', "' . $resolvedExpr->getCode() . '", 1);');
if ($variable == 'this') {
$codePrinter->output('zephir_update_property_this(this_ptr, Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ' . $tempVariable->getName() . ' TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ' . $tempVariable->getName() . ' TSRMLS_CC);');
}
break;
case 'bool':
if ($variable == 'this') {
if ($resolvedExpr->getBooleanCode() == '1') {
$codePrinter->output('zephir_update_property_this(this_ptr, Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_this(this_ptr, Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);');
}
} else {
if ($resolvedExpr->getBooleanCode() == '1') {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);');
}
}
break;
case 'empty-array':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$codePrinter->output('array_init(' . $tempVariable->getName() . ');');
if ($variable == 'this') {
$codePrinter->output('zephir_update_property_this(this_ptr, Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ' . $tempVariable->getName() . ' TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', Z_STRVAL_P(' . $propertyVariableName->getName() . '), Z_STRLEN_P(' . $propertyVariableName->getName() . '), ' . $tempVariable->getName() . ' TSRMLS_CC);');
}
break;
case 'variable':
$variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
switch ($variableVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'char':
case 'uchar':
//.........这里部分代码省略.........
示例7: 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':
//.........这里部分代码省略.........
示例8: _assignPropertyArrayMultipleIndex
/**
* Compiles x->y[a][b][] = {expr} (multiple offset assignment)
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
* @throws CompilerException
*/
protected function _assignPropertyArrayMultipleIndex($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement)
{
$codePrinter = $compilationContext->codePrinter;
$property = $statement['property'];
$compilationContext->headersManager->add('kernel/object');
/**
* Create a temporal zval (if needed)
*/
$variableExpr = $this->_getResolvedArrayItem($resolvedExpr, $compilationContext);
if (count($statement['index-expr']) > 16) {
throw new CompilerException("Too many array indexes", $statement);
}
/**
* 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);
}
$offsetExprs[] = $resolvedIndex;
}
/**
* Check if the property 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);
}
}
}
}
$offsetExprs[] = 'a';
$compilationContext->backend->assignPropertyArrayMulti($symbolVariable, $variableExpr, $property, $offsetExprs, $compilationContext);
}
示例9: _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');
//.........这里部分代码省略.........
示例10: assign
/**
* Compiles foo->x = {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)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Variable type '" . $symbolVariable->getType() . "' cannot be used as object", $statement);
}
$propertyName = $statement['property'];
$className = $compilationContext->classDefinition->getCompleteName();
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate static property '" . $className . "::" . $propertyName . "' because it is not initialized", $statement);
}
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " as an object", $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'))) {
$compilationContext->logger->warning('Possible attempt to update property on non-object dynamic property', 'non-valid-objectupdate', $statement);
}
/**
* Try to check if property is implemented on related object
*/
if ($variable == 'this') {
if (!$compilationContext->classDefinition->hasProperty($propertyName)) {
throw new CompilerException("Property '" . $propertyName . "' is not defined on class '" . $className . "'", $statement);
}
}
$codePrinter = $compilationContext->codePrinter;
$compilationContext->headersManager->add('kernel/object');
switch ($resolvedExpr->getType()) {
case 'null':
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, 'null', $compilationContext);
break;
case 'int':
case 'long':
case 'uint':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext);
switch ($statement['operator']) {
case 'mul-assign':
case 'sub-assign':
case 'add-assign':
switch ($statement['operator']) {
case 'mul-assign':
$functionName = 'ZEPHIR_MUL_ASSIGN';
break;
case 'sub-assign':
$functionName = 'ZEPHIR_SUB_ASSIGN';
break;
case 'add-assign':
$functionName = 'ZEPHIR_ADD_ASSIGN';
break;
}
$resolvedVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$compilationContext->backend->assignLong($resolvedVariable, $resolvedExpr->getBooleanCode(), $compilationContext);
$codePrinter->output($functionName . '(' . $compilationContext->backend->getVariableCode($tempVariable) . ', ' . $compilationContext->backend->getVariableCode($resolvedVariable) . ')');
break;
case 'assign':
$tempVariable->initNonReferenced($compilationContext);
$compilationContext->backend->assignLong($tempVariable, $resolvedExpr->getBooleanCode(), $compilationContext);
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for object property: " . $tempVariable->getType(), $statement);
}
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
$tempVariable->setIdle(true);
break;
case 'char':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext);
switch ($statement['operator']) {
case 'assign':
$tempVariable->initNonReferenced($compilationContext);
$compilationContext->backend->assignLong($tempVariable, '\'' . $resolvedExpr->getBooleanCode() . '\'', $compilationContext);
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for object property: " . $tempVariable->getType(), $statement);
}
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
$tempVariable->setIdle(true);
break;
case 'double':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext);
switch ($statement['operator']) {
case 'mul-assign':
case 'sub-assign':
case 'add-assign':
//.........这里部分代码省略.........
示例11: assign
/**
* Compiles foo->x = {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)
{
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
}
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Variable type '" . $symbolVariable->getType() . "' cannot be used as object", $statement);
}
$propertyName = $statement['property'];
$className = $compilationContext->classDefinition->getCompleteName();
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate static property '" . $className . "::" . $propertyName . "' because it is not initialized", $statement);
}
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " as an object", $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'))) {
$compilationContext->logger->warning('Possible attempt to update property on non-object dynamic property', 'non-valid-objectupdate', $statement);
}
/**
* Try to check if property is implemented on related object
*/
if ($variable == 'this') {
if (!$compilationContext->classDefinition->hasProperty($propertyName)) {
throw new CompilerException("Property '" . $propertyName . "' is not defined on class '" . $className . "'", $statement);
}
}
$codePrinter = $compilationContext->codePrinter;
$compilationContext->headersManager->add('kernel/object');
switch ($resolvedExpr->getType()) {
case 'null':
if ($variable == 'this') {
$codePrinter->output('zephir_update_property_this(this_ptr, SL("' . $propertyName . '"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', SL("' . $propertyName . '"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);');
}
break;
case 'int':
case 'long':
case 'uint':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext);
switch ($statement['operator']) {
case 'mul-assign':
case 'sub-assign':
case 'add-assign':
switch ($statement['operator']) {
case 'mul-assign':
$functionName = 'ZEPHIR_MUL_ASSIGN';
break;
case 'sub-assign':
$functionName = 'ZEPHIR_SUB_ASSIGN';
break;
case 'add-assign':
$functionName = 'ZEPHIR_ADD_ASSIGN';
break;
}
$resolvedVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$codePrinter->output('ZVAL_LONG(' . $resolvedVariable->getName() . ', ' . $resolvedExpr->getBooleanCode() . ');');
$codePrinter->output($functionName . '(' . $tempVariable->getName() . ', ' . $resolvedVariable->getName() . ')');
break;
case 'assign':
$tempVariable->initNonReferenced($compilationContext);
$codePrinter->output('ZVAL_LONG(' . $tempVariable->getName() . ', ' . $resolvedExpr->getBooleanCode() . ');');
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for object property: " . $tempVariable->getType(), $statement);
}
if ($variable == 'this') {
$codePrinter->output('zephir_update_property_this(this_ptr, SL("' . $propertyName . '"), ' . $tempVariable->getName() . ' TSRMLS_CC);');
} else {
$codePrinter->output('zephir_update_property_zval(' . $symbolVariable->getName() . ', SL("' . $propertyName . '"), ' . $tempVariable->getName() . ' TSRMLS_CC);');
}
$tempVariable->setIdle(true);
break;
case 'char':
$tempVariable = $compilationContext->symbolTable->getTempNonTrackedVariable('variable', $compilationContext);
switch ($statement['operator']) {
case 'assign':
$tempVariable->initNonReferenced($compilationContext);
$codePrinter->output('ZVAL_LONG(' . $tempVariable->getName() . ', \'' . $resolvedExpr->getBooleanCode() . '\');');
break;
default:
throw new CompilerException("Operator '" . $statement['operator'] . "' is not supported for object property: " . $tempVariable->getType(), $statement);
}
if ($variable == 'this') {
//.........这里部分代码省略.........
示例12: assign
/**
* Compiles foo[y] = {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)
{
/**
* 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 can be used as arrays
*/
if ($symbolVariable->isNotVariableAndArray()) {
throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
}
if ($symbolVariable->getType() == 'variable') {
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);
}
}
/**
* Choose one-offset or multiple-offset functions
*/
if (count($statement['index-expr']) == 1) {
$this->_assignArrayIndexSingle($variable, $symbolVariable, $resolvedExpr, $compilationContext, $statement);
} else {
$this->_assignArrayIndexMultiple($variable, $symbolVariable, $resolvedExpr, $compilationContext, $statement);
}
}
示例13: _assignPropertyArraySingleIndex
/**
* Compiles x->y[z] = {expr} (single offset assignment)
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
* @throws CompilerException
*/
protected function _assignPropertyArraySingleIndex($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement)
{
$codePrinter = $compilationContext->codePrinter;
$property = $statement['property'];
$compilationContext->headersManager->add('kernel/object');
/**
* Only string/variable/int
*/
$indexExpression = new Expression($statement['index-expr'][0]);
$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);
}
if ($resolvedIndex->getType() == 'variable') {
$indexVariable = $compilationContext->symbolTable->getVariableForRead($resolvedIndex->getCode(), $compilationContext, $statement);
switch ($indexVariable->getType()) {
case 'string':
case 'int':
case 'uint':
case 'ulong':
case 'long':
case 'variable':
break;
default:
throw new CompilerException("Variable: " . $indexVariable->getType() . " cannot be used as index without cast", $statement);
}
if ($indexVariable->getType() == 'variable') {
if ($indexVariable->hasDifferentDynamicType(array('undefined', 'int', 'string'))) {
$compilationContext->logger->warning('Possible attempt to use non string/long dynamic variable as array index', 'invalid-array-offset', $statement);
}
}
}
switch ($resolvedIndex->getType()) {
case 'int':
case 'uint':
case 'long':
$indexVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_LONG(' . $indexVariable->getName() . ', ' . $resolvedIndex->getCode() . ');');
break;
case 'string':
$indexVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_STRING(' . $indexVariable->getName() . ', "' . $resolvedIndex->getCode() . '", 1);');
break;
case 'variable':
$variableIndex = $compilationContext->symbolTable->getVariableForRead($resolvedIndex->getCode(), $compilationContext, $statement['index-expr']);
switch ($variableIndex->getType()) {
case 'int':
case 'uint':
case 'long':
$indexVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $statement);
$codePrinter->output('ZVAL_LONG(' . $indexVariable->getName() . ', ' . $variableIndex->getName() . ');');
break;
}
break;
}
/**
* 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);
}
}
}
//.........这里部分代码省略.........
示例14: assign
/**
* Compiles foo->{"x"} = {expr}
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
* @throws CompilerException
* @throws \Exception
*/
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->getType() != 'variable') {
throw new CompilerException("Variable type '" . $symbolVariable->getType() . "' cannot be used as object", $statement);
}
$propertyName = $statement['property'];
if (!is_string($propertyName)) {
throw new CompilerException("Expected string to update object property, " . gettype($propertyName) . " received", $statement);
}
if (!$symbolVariable->isInitialized()) {
throw new CompilerException("Cannot mutate static property '" . $compilationContext->classDefinition->getCompleteName() . "::" . $propertyName . "' because it is not initialized", $statement);
}
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " as an object", $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 update property on non-object dynamic property', 'non-valid-objectupdate', $statement);
}
$codePrinter = $compilationContext->codePrinter;
$compilationContext->headersManager->add('kernel/object');
switch ($resolvedExpr->getType()) {
case 'null':
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, 'null', $compilationContext);
break;
case 'int':
case 'long':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$compilationContext->backend->assignLong($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
break;
case 'string':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$compilationContext->backend->assignString($tempVariable, $resolvedExpr->getCode(), $compilationContext);
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
break;
case 'bool':
if ($resolvedExpr->getBooleanCode() == '1') {
$value = 'true';
} else {
if ($resolvedExpr->getBooleanCode() == '0') {
$value = 'false';
} else {
throw new \Exception("?");
}
}
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $value, $compilationContext);
break;
case 'empty-array':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$compilationContext->backend->initArray($tempVariable, $compilationContext);
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
break;
case 'array':
$variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $variableVariable, $compilationContext);
break;
case 'variable':
$variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement);
switch ($variableVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'char':
case 'uchar':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$compilationContext->backend->assignLong($tempVariable, $variableVariable, $compilationContext);
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
break;
case 'bool':
$tempVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext);
$compilationContext->backend->assignBool($tempVariable, $variableVariable, $compilationContext);
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $tempVariable, $compilationContext);
break;
case 'string':
case 'variable':
case 'array':
$compilationContext->backend->updateProperty($symbolVariable, $propertyName, $resolvedExpr, $compilationContext);
if ($symbolVariable->isTemporal()) {
$symbolVariable->setIdle(true);
//.........这里部分代码省略.........
示例15: _assignPropertyArrayMultipleIndex
/**
* Compiles x->y[a][b][] = {expr} (multiple offset assignment)
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
* @throws CompilerException
*/
protected function _assignPropertyArrayMultipleIndex($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, array $statement)
{
$codePrinter = $compilationContext->codePrinter;
$property = $statement['property'];
$compilationContext->headersManager->add('kernel/object');
/**
* Create a temporal zval (if needed)
*/
$variableExpr = $this->_getResolvedArrayItem($resolvedExpr, $compilationContext);
if (count($statement['index-expr']) > 16) {
throw new CompilerException("Too many array indexes", $statement);
}
/**
* 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);
}
$offsetExprs[] = $resolvedIndex;
}
/**
* Check if the property 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);
}
}
}
}
$keys = '';
$numberParams = 0;
$offsetItems = array();
foreach ($offsetExprs as $offsetExpr) {
switch ($offsetExpr->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$keys .= 'l';
$offsetItems[] = $offsetExpr->getCode();
$numberParams++;
break;
case 'string':
$keys .= 's';
$offsetItems[] = 'SL("' . $offsetExpr->getCode() . '")';
$numberParams += 2;
break;
case 'variable':
$variableIndex = $compilationContext->symbolTable->getVariableForRead($offsetExpr->getCode(), $compilationContext, $statement);
switch ($variableIndex->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$keys .= 'l';
$offsetItems[] = $variableIndex->getName();
$numberParams++;
break;
case 'string':
//.........这里部分代码省略.........