本文整理汇总了PHP中Zephir\Expression::setReadOnly方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::setReadOnly方法的具体用法?PHP Expression::setReadOnly怎么用?PHP Expression::setReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zephir\Expression
的用法示例。
在下文中一共展示了Expression::setReadOnly方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compile
/**
* Executes the operator
*
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(array $expression, CompilationContext $compilationContext)
{
if (!isset($expression['parameters'])) {
throw new CompilerException("Invalid 'parameters' for new-type", $expression);
}
switch ($expression['internal-type']) {
case 'array':
$compilationContext->headersManager->add('kernel/array');
$functionName = 'create_array';
break;
case 'string':
$compilationContext->headersManager->add('kernel/string');
$functionName = 'create_string';
break;
default:
throw new CompilerException("Cannot build instance of type", $expression);
}
$builder = new FunctionCallBuilder($functionName, $expression['parameters'], 1, $expression['file'], $expression['line'], $expression['char']);
/**
* Implicit type coercing
*/
$castBuilder = new CastOperatorBuilder($expression['internal-type'], $builder);
$expression = new Expression($castBuilder->get());
$expression->setReadOnly($this->_readOnly);
return $expression->compile($compilationContext);
}
示例2: compile
/**
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(array $expression, CompilationContext $compilationContext)
{
$expr = new Expression($expression['left']);
$expr->setReadOnly(true);
$expr->setExpectReturn(true);
$exprPath = $expr->compile($compilationContext);
if ($exprPath->getType() == 'variable') {
$exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression);
if ($exprVariable->getType() == 'variable') {
if ($exprVariable->hasDifferentDynamicType(array('undefined', 'string'))) {
$compilationContext->logger->warning('Possible attempt to use invalid type as path in "require" operator', 'non-valid-require', $expression);
}
}
}
$symbolVariable = false;
if ($this->isExpecting()) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
}
$compilationContext->headersManager->add('kernel/memory');
$compilationContext->headersManager->add('kernel/require');
$codePrinter = $compilationContext->codePrinter;
if ($symbolVariable) {
$codePrinter->output('ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(&' . $symbolVariable->getName() . ');');
$codePrinter->output('if (zephir_require_zval_ret(&' . $symbolVariable->getName() . ', ' . $exprPath->getCode() . ' TSRMLS_CC) == FAILURE) {');
} else {
$codePrinter->output('if (zephir_require_zval(' . $exprPath->getCode() . ' TSRMLS_CC) == FAILURE) {');
}
$codePrinter->output("\t" . 'RETURN_MM_NULL();');
$codePrinter->output('}');
if ($symbolVariable) {
return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
}
return new CompiledExpression('null', null, $expression);
}
示例3: compile
/**
* Compile expression
*
* @param $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
* @throws Exception
*/
public function compile($expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new \Exception("Missing left part of the expression");
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly($this->_readOnly);
$left = $leftExpr->compile($compilationContext);
switch ($left->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($left->getType(), '+' . $left->getCode(), $expression);
case 'variable':
$variable = $compilationContext->symbolTable->getVariable($left->getCode());
switch ($variable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($variable->getType(), '+' . $variable->getName(), $expression);
case 'variable':
return new CompiledExpression('variable', $variable->getName(), $expression);
default:
throw new CompilerException("Cannot operate plus with variable of '" . $left->getType() . "' type");
}
break;
default:
throw new CompilerException("Cannot operate plus with '" . $left->getType() . "' type");
}
}
示例4: _assignArrayIndexMultiple
/**
* Compiles foo[y][x][] = {expr} (multiple offset)
*
* @param string $variable
* @param ZephirVariable $symbolVariable
* @param CompiledExpression $resolvedExpr
* @param CompilationContext $compilationContext
* @param array $statement
*/
protected function _assignArrayIndexMultiple($variable, ZephirVariable $symbolVariable, CompiledExpression $resolvedExpr, CompilationContext $compilationContext, $statement)
{
$codePrinter = $compilationContext->codePrinter;
$offsetExprs = array();
foreach ($statement['index-expr'] as $indexExpr) {
$expression = new Expression($indexExpr);
$expression->setReadOnly(true);
$exprIndex = $expression->compile($compilationContext);
switch ($exprIndex->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'string':
case 'variable':
break;
default:
throw new CompilerException("Index: " . $exprIndex->getType() . " cannot be used as array index in assignment without cast", $indexExpr);
}
$offsetExprs[] = $exprIndex;
}
$compilationContext->headersManager->add('kernel/array');
/**
* Create a temporal zval (if needed)
*/
$symbolVariable = $this->_getResolvedArrayItem($resolvedExpr, $compilationContext);
$targetVariable = $compilationContext->symbolTable->getVariableForWrite($variable, $compilationContext, $statement);
$offsetExprs[] = 'a';
$compilationContext->backend->assignArrayMulti($targetVariable, $symbolVariable, $offsetExprs, $compilationContext);
}
示例5: compile
/**
* @param $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
* @throws Exception
*/
public function compile($expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new CompilerException("Missing left part of the expression", $expression);
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly($this->_readOnly);
$left = $leftExpr->compile($compilationContext);
switch ($left->getType()) {
case 'bool':
case 'int':
case 'uint':
case 'long':
case 'ulong':
return new CompiledExpression('int', '~(' . $left->getCode() . ')', $expression);
case 'variable':
$variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
switch ($variable->getType()) {
case 'bool':
case 'int':
case 'uint':
case 'long':
return new CompiledExpression('int', '~' . $variable->getName(), $expression);
case 'variable':
$compilationContext->headersManager->add('kernel/operators');
return new CompiledExpression('int', '~zephir_get_intval(' . $variable->getName() . ')', $expression);
default:
throw new CompilerException("Unknown type: " . $variable->getType(), $expression);
}
break;
default:
throw new CompilerException("Unknown type: " . $left->getType(), $expression);
}
}
示例6: compile
/**
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(array $expression, CompilationContext $compilationContext)
{
$compilationContext->headersManager->add('kernel/object');
$exprVariable = new Expression($expression['left']);
$exprVariable->setReadOnly(true);
$exprVariable->setExpectReturn(true);
$exprCompiledVariable = $exprVariable->compile($compilationContext);
if ($exprCompiledVariable->getType() != 'variable') {
throw new CompilerException("Expression type: " . $exprCompiledVariable->getType() . " cannot be used as array", $expression);
}
$clonedVariable = $compilationContext->symbolTable->getVariableForRead($exprCompiledVariable->getCode(), $compilationContext, $expression);
if ($clonedVariable->getType() != 'variable') {
throw new CompilerException("Variable type: " . $exprVariable->getType() . " cannot be cloned");
}
if ($clonedVariable->hasDifferentDynamicType(array('undefined', 'object', 'null'))) {
$compilationContext->logger->warning('Possible attempt to use non array in "clone" operator', 'non-valid-clone', $expression);
}
$symbolVariable = $this->getExpected($compilationContext, $expression);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Objects can only be cloned into dynamic variables", $expression);
}
$symbolVariable->setDynamicTypes('object');
$symbolVariable->setIsInitialized(true, $compilationContext, $expression);
/* Inherit the dynamic type data from the cloned object */
$symbolVariable->setDynamicTypes($clonedVariable->getDynamicTypes());
$symbolVariable->setClassTypes($clonedVariable->getClassTypes());
$compilationContext->codePrinter->output('if (zephir_clone(' . $symbolVariable->getName() . ', ' . $clonedVariable->getName() . ' TSRMLS_CC) == FAILURE) {');
$compilationContext->codePrinter->output("\t" . 'RETURN_MM();');
$compilationContext->codePrinter->output('}');
return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
}
示例7: compile
/**
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(array $expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']);
}
if (!isset($expression['right'])) {
throw new CompilerException("Invalid 'right' operand for 'irange' expression", $expression['right']);
}
$exprBuilder = Expression\Builder\BuilderFactory::getInstance();
/**
* Implicit type coercing
*/
$castBuilder = $exprBuilder->operators()->cast(Types::ARRAY_, $exprBuilder->statements()->functionCall('range', array($expression['left'], $expression['right'])));
$expression = new Expression($castBuilder->build());
$expression->setReadOnly($this->_readOnly);
return $expression->compile($compilationContext);
}
示例8: compile
/**
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
*/
public function compile(array $expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']);
}
if (!isset($expression['right'])) {
throw new CompilerException("Invalid 'right' operand for 'irange' expression", $expression['right']);
}
$builder = new FunctionCallBuilder('range', array(array('parameter' => $expression['left']), array('parameter' => $expression['right'])));
/**
* Implicit type coercing
*/
$castBuilder = new CastOperatorBuilder('array', $builder);
$expression = new Expression($castBuilder->get());
$expression->setReadOnly($this->_readOnly);
return $expression->compile($compilationContext);
}
示例9: compile
/**
*
* @param array $expression
* @param \CompilationContext $compilationContext
* @return \CompiledExpression
*/
public function compile($expression, CompilationContext $compilationContext)
{
$compilationContext->headersManager->add('kernel/operators');
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'empty' expression", $expression['left']);
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly(true);
$left = $leftExpr->compile($compilationContext);
if ($left->getType() != 'variable') {
throw new CompilerException("'empty' operand only can be a variable", $expression['left']);
}
$variableLeft = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
if ($variableLeft->isNotVariableAndString()) {
throw new CompilerException("Only dynamic/string variables can be used in 'empty' operators", $expression['left']);
}
return new CompiledExpression('bool', 'ZEPHIR_IS_EMPTY(' . $variableLeft->getName() . ')', $expression);
}
示例10: compile
/**
* @param CompilationContext $compilationContext
* @throws CompilerException
*/
public function compile(CompilationContext $compilationContext)
{
$compilationContext->headersManager->add('kernel/array');
$expression = $this->_statement['expr'];
$flags = 'PH_SEPARATE';
if ($expression['type'] == 'list') {
$expression = $expression['left'];
}
switch ($expression['type']) {
case 'array-access':
$expr = new Expression($expression['left']);
$expr->setReadOnly(true);
$exprVar = $expr->compile($compilationContext);
$variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->_statement);
$expr = new Expression($expression['right']);
$expr->setReadOnly(true);
$exprIndex = $expr->compile($compilationContext);
break;
case 'property-access':
$expr = new Expression($expression['left']);
$expr->setReadOnly(true);
$exprVar = $expr->compile($compilationContext);
$variable = $compilationContext->symbolTable->getVariableForWrite($exprVar->getCode(), $compilationContext, $this->_statement);
$variableCode = $compilationContext->backend->getVariableCode($variable);
$compilationContext->headersManager->add('kernel/object');
$compilationContext->codePrinter->output('zephir_unset_property(' . $variableCode . ', "' . $expression['right']['value'] . '" TSRMLS_CC);');
return true;
case 'property-dynamic-access':
//@todo fix it
//@todo fix it
default:
throw new CompilerException('Cannot use expression type: ' . $expression['type'] . ' in "unset"', $expression);
}
if (!in_array($variable->getType(), array('variable', 'array'))) {
throw new CompilerException('Cannot use variable type: ' . $variable->gettype() . ' in "unset"', $expression['left']);
}
if ($variable->hasDifferentDynamicType(array('undefined', 'array', 'object', 'null'))) {
$compilationContext->logger->warning('Possible attempt to use non array/object in unset operator', 'non-valid-unset', $expression['left']);
}
$compilationContext->backend->arrayUnset($variable, $exprIndex, $flags, $compilationContext);
}
示例11: compile
public function compile($expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new CompilerException("Invalid 'left' operand for 'unlikely' expression", $expression['left']);
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly(true);
$left = $leftExpr->compile($compilationContext);
if ($left->getType() == 'bool') {
return new CompiledExpression('bool', 'unlikely(' . $left->getCode() . ')', $expression);
}
if ($left->getType() == 'variable') {
$variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']);
switch ($variable->getType()) {
case 'bool':
return new CompiledExpression('bool', 'unlikely(' . $variable->getName() . ')', $expression);
default:
return new CompiledExpression('bool', 'unlikely(zephir_is_true(' . $variable->getName() . '))', $expression);
}
}
throw new CompilerException("Cannot use expression type: '" . $left->getType() . "' in 'unlikely' operator", $expression['left']);
}
示例12: compile
/**
* Compile expression
*
* @param $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
* @throws CompilerException
* @throws Exception
*/
public function compile($expression, CompilationContext $compilationContext)
{
if (!isset($expression['left'])) {
throw new \Exception("Missing left part of the expression");
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly($this->_readOnly);
$left = $leftExpr->compile($compilationContext);
switch ($left->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($left->getType(), '-' . $left->getCode(), $expression);
case 'variable':
$variable = $compilationContext->symbolTable->getVariable($left->getCode());
switch ($variable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
return new CompiledExpression($variable->getType(), '-' . $variable->getName(), $expression);
case 'variable':
$compilationContext->headersManager->add('kernel/operators');
$compilationContext->codePrinter->output('zephir_negate(' . $compilationContext->backend->getVariableCode($variable) . ' TSRMLS_CC);');
return new CompiledExpression('variable', $variable->getName(), $expression);
default:
throw new CompilerException("Cannot operate minus with variable of '" . $left->getType() . "' type");
}
break;
default:
throw new CompilerException("Cannot operate minus with '" . $left->getType() . "' type");
}
}
示例13: compileTypeHint
/**
*
*
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
*/
public function compileTypeHint($expression, CompilationContext $compilationContext)
{
$expr = new Expression($expression['right']);
$expr->setReadOnly(true);
$resolved = $expr->compile($compilationContext);
if ($resolved->getType() != 'variable') {
throw new CompilerException("Type-Hints only can be applied to dynamic variables", $expression);
}
$symbolVariable = $compilationContext->symbolTable->getVariableForRead($resolved->getCode(), $compilationContext, $expression);
if (!$symbolVariable->isVariable()) {
throw new CompilerException("Type-Hints only can be applied to dynamic variables", $expression);
}
$symbolVariable->setDynamicTypes('object');
$symbolVariable->setClassTypes($compilationContext->getFullName($expression['left']['value']));
return $resolved;
}
示例14: compile
/**
* Compiles a reference to a value
*
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
*/
public function compile($expression, CompilationContext $compilationContext)
{
/**
* Resolves the symbol that expects the value
*/
if ($this->_expecting) {
if ($this->_expectingVariable) {
$symbolVariable = $this->_expectingVariable;
if ($symbolVariable->getType() != 'variable') {
throw new CompilerException("Cannot use variable type: " . $symbolVariable->getType() . " to store a reference", $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
$leftExpr = new Expression($expression['left']);
$leftExpr->setReadOnly($this->_readOnly);
$left = $leftExpr->compile($compilationContext);
switch ($left->getType()) {
case 'variable':
case 'string':
case 'object':
case 'array':
case 'callable':
break;
default:
throw new CompilerException("Cannot obtain a reference from type: " . $left->getType(), $expression);
}
$leftVariable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression);
switch ($leftVariable->getType()) {
case 'variable':
case 'string':
case 'object':
case 'array':
case 'callable':
break;
default:
throw new CompilerException("Cannot obtain reference from variable type: " . $leftVariable->getType(), $expression);
}
$symbolVariable->setMustInitNull(true);
$compilationContext->symbolTable->mustGrownStack(true);
$symbolVariable->increaseVariantIfNull();
$compilationContext->codePrinter->output('ZEPHIR_MAKE_REFERENCE(' . $symbolVariable->getName() . ', ' . $leftVariable->getName() . ');');
return new CompiledExpression('reference', $symbolVariable->getRealName(), $expression);
}
示例15: optimize
/**
* Optimizes expressions
*
* @param $exprRaw
* @param CompilationContext $compilationContext
* @return bool|string
* @throws CompilerException
*/
public function optimize($exprRaw, CompilationContext $compilationContext)
{
$conditions = $this->optimizeNot($exprRaw, $compilationContext);
if ($conditions !== false) {
return $conditions;
}
/**
* Discard first level parentheses
*/
if ($exprRaw['type'] == 'list') {
$expr = new Expression($exprRaw['left']);
} else {
$expr = new Expression($exprRaw);
}
$expr->setReadOnly(true);
$expr->setEvalMode(true);
$compiledExpression = $expr->compile($compilationContext);
/**
* Possible corrupted expression?
*/
if (!is_object($compiledExpression)) {
throw new CompilerException('Corrupted expression: ' . $exprRaw['type'], $exprRaw);
}
/**
* Generate the condition according to the value returned by the evaluated expression
*/
switch ($compiledExpression->getType()) {
case 'null':
$this->_unreachable = true;
return '0';
case 'int':
case 'uint':
case 'long':
case 'ulong':
case 'double':
$code = $compiledExpression->getCode();
if (is_numeric($code)) {
if ($code == '1') {
$this->_unreachableElse = true;
} else {
$this->_unreachable = true;
}
}
return $code;
case 'char':
case 'uchar':
return $compiledExpression->getCode();
case 'bool':
$code = $compiledExpression->getBooleanCode();
if ($code == '1') {
$this->_unreachableElse = true;
} else {
if ($code == '0') {
$this->_unreachable = true;
}
}
return $code;
case 'variable':
$variableRight = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $exprRaw);
$possibleValue = $variableRight->getPossibleValue();
if (is_object($possibleValue)) {
$possibleValueBranch = $variableRight->getPossibleValueBranch();
if ($possibleValueBranch instanceof Branch) {
/**
* Check if the possible value was assigned in the root branch
*/
if ($possibleValueBranch->getType() == Branch::TYPE_ROOT) {
if ($possibleValue instanceof LiteralCompiledExpression) {
switch ($possibleValue->getType()) {
case 'null':
$this->_unreachable = true;
break;
case 'bool':
if ($possibleValue->getBooleanCode() == '0') {
$this->_unreachable = true;
} else {
$this->_unreachableElse = true;
}
break;
case 'int':
if (!intval($possibleValue->getCode())) {
$this->_unreachable = true;
} else {
$this->_unreachableElse = true;
}
break;
case 'double':
if (!floatval($possibleValue->getCode())) {
$this->_unreachable = true;
} else {
$this->_unreachableElse = true;
}
//.........这里部分代码省略.........