本文整理汇总了PHP中Zephir\Expression::setStringOperation方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::setStringOperation方法的具体用法?PHP Expression::setStringOperation怎么用?PHP Expression::setStringOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zephir\Expression
的用法示例。
在下文中一共展示了Expression::setStringOperation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getOptimizedConcat
/**
* @param array $expression
* @param CompilationContext $compilationContext
* @param boolean $isFullString
*/
private function _getOptimizedConcat($expression, CompilationContext $compilationContext, &$isFullString)
{
$originalExpr = $expression;
$isFullString = true;
$parts = array();
while ($expression && isset($expression['left'])) {
$parts[] = $expression['right'];
if ($expression['left']['type'] == 'concat') {
$expression = $expression['left'];
} else {
$parts[] = $expression['left'];
$expression = null;
}
}
if ($expression) {
$parts[] = $expression['right'];
$parts[] = $expression['left'];
}
$key = '';
$concatParts = array();
$parts = array_reverse($parts);
foreach ($parts as $part) {
$expr = new Expression($part);
$expr->setStringOperation(true);
switch ($part['type']) {
case 'array-access':
case 'property-access':
$expr->setReadOnly(true);
break;
default:
$expr->setReadOnly($this->_readOnly);
break;
}
$compiledExpr = $expr->compile($compilationContext);
switch ($compiledExpr->getType()) {
case 'variable':
$variable = $compilationContext->symbolTable->getVariableForRead($compiledExpr->getCode(), $compilationContext, $originalExpr);
switch ($variable->getType()) {
case 'variable':
$key .= 'v';
$concatParts[] = $variable->getName();
$isFullString = false;
break;
case 'string':
$key .= 'v';
$concatParts[] = $variable->getName();
break;
case 'int':
case 'long':
$key .= 'v';
$tempVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $originalExpr);
$compilationContext->codePrinter->output('ZVAL_LONG(&' . $tempVariable->getName() . ', ' . $compiledExpr->getCode() . ');');
$concatParts[] = '&' . $tempVariable->getName();
break;
default:
throw new CompilerException("Variable type: " . $variable->getType() . " cannot be used in concat operation", $compiledExpr->getOriginal());
}
break;
case 'string':
$key .= 's';
$concatParts[] = '"' . $compiledExpr->getCode() . '"';
break;
default:
throw new CompilerException("Variable type: " . $compiledExpr->getType() . " cannot be used in concat operation", $compiledExpr->getOriginal());
}
}
$compilationContext->stringsManager->addConcatKey($key);
return array($key, join(', ', $concatParts));
}