本文整理汇总了PHP中Zephir\Utils类的典型用法代码示例。如果您正苦于以下问题:PHP Utils类的具体用法?PHP Utils怎么用?PHP Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: optimize
/**
* @param array $expression
* @param Call $call
* @param CompilationContext $context
* @return bool|CompiledExpression|mixed
* @throws CompilerException
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 2) {
return false;
}
/**
* Process the expected symbol to be returned
*/
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable();
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
if ($expression['parameters'][0]['parameter']['type'] == 'string') {
$str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']);
unset($expression['parameters'][0]);
}
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
$context->headersManager->add('kernel/string');
$symbolVariable->setDynamicTypes('string');
if (isset($str)) {
$context->codePrinter->output('zephir_fast_join_str(' . $symbolVariable->getName() . ', SL("' . $str . '"), ' . $resolvedParams[0] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
$context->codePrinter->output('zephir_fast_join(' . $symbolVariable->getName() . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
示例2: compile
/**
* @param CompilationContext $compilationContext
* @throws CompilerException
*/
public function compile(CompilationContext $compilationContext)
{
$compilationContext->headersManager->add('kernel/exception');
$codePrinter = $compilationContext->codePrinter;
$statement = $this->_statement;
$expr = $statement['expr'];
/**
* This optimizes throw new Exception("hello")
*/
if (!$compilationContext->insideTryCatch) {
if (isset($expr['class'])) {
if (isset($expr['parameters']) && count($expr['parameters']) == 1) {
if ($expr['parameters'][0]['parameter']['type'] == 'string') {
$className = Utils::getFullName($expr['class'], $compilationContext->classDefinition->getNamespace(), $compilationContext->aliasManager);
if ($compilationContext->compiler->isClass($className)) {
$classDefinition = $compilationContext->compiler->getClassDefinition($className);
$message = $expr['parameters'][0]['parameter']['value'];
$codePrinter->output('ZEPHIR_THROW_EXCEPTION_DEBUG_STR(' . $classDefinition->getClassEntry() . ', "' . Utils::addSlashes($message, true, Types::STRING) . '", "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ');');
$codePrinter->output('return;');
return;
} else {
if ($compilationContext->compiler->isInternalClass($className)) {
$classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, true);
if ($classEntry) {
$message = $expr['parameters'][0]['parameter']['value'];
$codePrinter->output('ZEPHIR_THROW_EXCEPTION_DEBUG_STR(' . $classEntry . ', "' . Utils::addSlashes($message, true, Types::STRING) . '", "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ');');
$codePrinter->output('return;');
return;
}
}
}
}
}
}
}
$throwExpr = new Expression($expr);
$resolvedExpr = $throwExpr->compile($compilationContext);
if ($resolvedExpr->getType() != 'variable') {
throw new CompilerException("Expression '" . $resolvedExpr->getType() . '" cannot be used as exception', $expr);
}
$variableVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $expr);
if ($variableVariable->getType() != 'variable') {
throw new CompilerException("Variable '" . $variableVariable->getType() . "' cannot be used as exception", $expr);
}
$codePrinter->output('zephir_throw_exception_debug(' . $variableVariable->getName() . ', "' . Compiler::getShortUserPath($statement['expr']['file']) . '", ' . $statement['expr']['line'] . ' TSRMLS_CC);');
if (!$compilationContext->insideTryCatch) {
$codePrinter->output('ZEPHIR_MM_RESTORE();');
$codePrinter->output('return;');
} else {
$codePrinter->output('goto try_end_' . $compilationContext->insideTryCatch . ';');
$codePrinter->outputBlankLine();
}
if ($variableVariable->isTemporal()) {
$variableVariable->setIdle(true);
}
}
示例3: optimize
/**
* @param array $expression
* @param Call $call
* @param CompilationContext $context
* @return bool|CompiledExpression|mixed
* @throws CompilerException
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) < 2) {
throw new CompilerException("'explode' require two parameter");
}
/**
* Process the expected symbol to be returned
*/
$call->processExpectedReturn($context);
$symbolVariable = $call->getSymbolVariable(true, $context);
if ($symbolVariable->isNotVariableAndString()) {
throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
}
/**
* Process limit
*/
$limit = 'LONG_MAX';
$limitOffset = 2;
if (count($expression['parameters']) == 3 && $expression['parameters'][2]['parameter']['type'] == 'int') {
$limit = $expression['parameters'][2]['parameter']['value'] . ' ';
unset($expression['parameters'][2]);
}
if ($expression['parameters'][0]['parameter']['type'] == 'string') {
$str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']);
unset($expression['parameters'][0]);
if (count($expression['parameters']) == 2) {
$limitOffset = 1;
}
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if (isset($resolvedParams[$limitOffset])) {
$context->headersManager->add('kernel/operators');
$limit = 'zephir_get_intval(' . $resolvedParams[$limitOffset] . ') ';
}
$context->headersManager->add('kernel/string');
$symbolVariable->setDynamicTypes('array');
if ($call->mustInitSymbolVariable()) {
$symbolVariable->initVariant($context);
}
$symbol = $context->backend->getVariableCode($symbolVariable);
if (isset($str)) {
$context->codePrinter->output('zephir_fast_explode_str(' . $symbol . ', SL("' . $str . '"), ' . $resolvedParams[0] . ', ' . $limit . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
$context->codePrinter->output('zephir_fast_explode(' . $symbol . ', ' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', ' . $limit . ' TSRMLS_CC);');
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
示例4: optimize
/**
* @param array $expression
* @param Call $call
* @param CompilationContext $context
* @return bool|CompiledExpression|mixed
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 2) {
return false;
}
if ($expression['parameters'][1]['parameter']['type'] == 'string') {
$str = Utils::addSlashes($expression['parameters'][1]['parameter']['value']);
unset($expression['parameters'][1]);
}
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
$context->headersManager->add('kernel/string');
if (isset($str)) {
return new CompiledExpression('bool', 'zephir_memnstr_str(' . $resolvedParams[0] . ', SL("' . $str . '"), "' . Compiler::getShortUserPath($expression['file']) . '", ' . $expression['line'] . ')', $expression);
}
return new CompiledExpression('bool', 'zephir_memnstr(' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ', "' . Compiler::getShortUserPath($expression['file']) . '", ' . $expression['line'] . ')', $expression);
}
示例5: optimize
/**
* @param array $expression
* @param Call $call
* @param CompilationContext $context
* @return bool|CompiledExpression|mixed
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 2) {
return false;
}
if ($expression['parameters'][1]['parameter']['type'] == 'string') {
$str = Utils::addSlashes($expression['parameters'][1]['parameter']['value']);
unset($expression['parameters'][1]);
}
$context->headersManager->add('kernel/object');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if (isset($str)) {
return new CompiledExpression('bool', '(zephir_method_exists_ex(' . $resolvedParams[0] . ', SS("' . strtolower($str) . '") TSRMLS_CC) == SUCCESS)', $expression);
}
return new CompiledExpression('bool', '(zephir_method_exists(' . $resolvedParams[0] . ', ' . $resolvedParams[1] . ' TSRMLS_CC) == SUCCESS)', $expression);
}
示例6: optimize
/**
* @param array $expression
* @param Call $call
* @param CompilationContext $context
* @return bool|CompiledExpression|mixed
*/
public function optimize(array $expression, Call $call, CompilationContext $context)
{
if (!isset($expression['parameters'])) {
return false;
}
if (count($expression['parameters']) != 1) {
return false;
}
if ($expression['parameters'][0]['parameter']['type'] == 'string') {
$str = Utils::addSlashes($expression['parameters'][0]['parameter']['value']);
unset($expression['parameters'][0]);
}
$context->headersManager->add('kernel/object');
$resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
if (isset($str)) {
/* TODO: Solve this macro stuff better, move to backend */
$macro = $context->backend->isZE3() ? 'SL' : 'SS';
return new CompiledExpression('bool', '(zephir_function_exists_ex(' . $macro . '("' . strtolower($str) . '") TSRMLS_CC) == SUCCESS)', $expression);
}
return new CompiledExpression('bool', '(zephir_function_exists(' . $resolvedParams[0] . ' TSRMLS_CC) == SUCCESS)', $expression);
}
示例7: compile
//.........这里部分代码省略.........
throw new CompilerException("Returning type: " . $resolvedExpr->getType() . " but this type is not compatible with return-type hints declared in the method", $statement['expr']);
}
break;
case 'bool':
if (!$currentMethod->areReturnTypesBoolCompatible()) {
throw new CompilerException("Returning type: " . $resolvedExpr->getType() . " but this type is not compatible with return-type hints declared in the method", $statement['expr']);
}
break;
case 'variable':
break;
}
break;
}
}
switch ($resolvedExpr->getType()) {
case 'null':
$codePrinter->output('RETURN_MM_NULL();');
break;
case 'int':
case 'uint':
case 'long':
case 'char':
case 'uchar':
$codePrinter->output('RETURN_MM_LONG(' . $resolvedExpr->getCode() . ');');
break;
case 'bool':
$codePrinter->output('RETURN_MM_BOOL(' . $resolvedExpr->getBooleanCode() . ');');
break;
case 'double':
$codePrinter->output('RETURN_MM_DOUBLE(' . $resolvedExpr->getCode() . ');');
break;
case 'string':
case 'istring':
$codePrinter->output('RETURN_MM_STRING("' . Utils::addSlashes($resolvedExpr->getCode()) . '", 1);');
break;
case 'array':
if ($resolvedExpr->getCode() != 'return_value') {
$codePrinter->output('RETURN_CTOR(' . $resolvedExpr->getCode() . ');');
} else {
$codePrinter->output('RETURN_MM();');
}
break;
case 'variable':
if (!isset($symbolVariable)) {
$symbolVariable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $statement['expr']);
}
switch ($symbolVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'char':
case 'uchar':
$codePrinter->output('RETURN_MM_LONG(' . $symbolVariable->getName() . ');');
break;
case 'double':
$codePrinter->output('RETURN_MM_DOUBLE(' . $symbolVariable->getName() . ');');
break;
case 'string':
case 'array':
$codePrinter->output('RETURN_CTOR(' . $resolvedExpr->getCode() . ');');
break;
case 'bool':
$codePrinter->output('RETURN_MM_BOOL(' . $symbolVariable->getName() . ');');
break;
case 'variable':
if ($symbolVariable->getName() == 'this_ptr') {
示例8: getReadOnlyResolvedParams
/**
* Resolve parameters using zvals in the stack and without allocating memory for constants
*
* @param array $parameters
* @param CompilationContext $compilationContext
* @param array $expression
* @return array
*/
public function getReadOnlyResolvedParams($parameters, CompilationContext $compilationContext, array $expression)
{
$codePrinter = $compilationContext->codePrinter;
$exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression, true);
$params = array();
$types = array();
$dynamicTypes = array();
foreach ($exprParams as $compiledExpression) {
$expression = $compiledExpression->getOriginal();
switch ($compiledExpression->getType()) {
case 'null':
$params[] = $compilationContext->backend->resolveValue('null', $compilationContext);
$types[] = 'null';
$dynamicTypes[] = 'null';
break;
case 'int':
case 'uint':
case 'long':
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true);
$compilationContext->backend->assignLong($parameterVariable, $compiledExpression->getCode(), $compilationContext);
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'char':
case 'uchar':
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true);
$compilationContext->backend->assignLong($parameterVariable, '\'' . $compiledExpression->getCode() . '\'', $compilationContext);
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'double':
$parameterVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true);
$codePrinter->output('ZVAL_DOUBLE(&' . $parameterVariable->getName() . ', ' . $compiledExpression->getCode() . ');');
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'bool':
if ($compiledExpression->getCode() == 'true') {
$params[] = $compilationContext->backend->resolveValue('true', $compilationContext);
} else {
if ($compiledExpression->getCode() == 'false') {
$params[] = $compilationContext->backend->resolveValue('false', $compilationContext);
} else {
throw new Exception('?');
}
}
$types[] = 'bool';
$dynamicTypes[] = 'bool';
break;
case 'ulong':
case 'string':
case 'istring':
if ($compilationContext->backend->getName() == 'ZendEngine2') {
$parameterVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
} else {
$parameterVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
}
$compilationContext->backend->assignString($parameterVariable, Utils::addSlashes($compiledExpression->getCode()), $compilationContext, true, false);
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'array':
$parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
$params[] = $compilationContext->backend->getVariableCode($parameterVariable);
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'variable':
$parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
switch ($parameterVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true);
$codePrinter->output('ZVAL_LONG(&' . $parameterTempVariable->getName() . ', ' . $compiledExpression->getCode() . ');');
$params[] = '&' . $parameterTempVariable->getName();
$types[] = $parameterTempVariable->getType();
$dynamicTypes[] = $parameterTempVariable->getType();
$this->_temporalVariables[] = $parameterTempVariable;
break;
case 'char':
case 'uchar':
$parameterTempVariable = $compilationContext->backend->getScalarTempVariable('variable', $compilationContext, true);
//.........这里部分代码省略.........
示例9: generateFunctionInformation
public function generateFunctionInformation()
{
$headerPrinter = new CodePrinter();
$entryPrinter = new CodePrinter();
/**
* Create argument info
*/
foreach ($this->functionDefinitions as $func) {
$funcName = $func->getInternalName();
$argInfoName = 'arginfo_' . strtolower($funcName);
$headerPrinter->output('PHP_FUNCTION(' . $funcName . ');');
$parameters = $func->getParameters();
if (count($parameters)) {
$headerPrinter->output('ZEND_BEGIN_ARG_INFO_EX(' . $argInfoName . ', 0, 0, ' . $func->getNumberOfRequiredParameters() . ')');
foreach ($parameters->getParameters() as $parameter) {
switch ($parameter['data-type']) {
case 'array':
$headerPrinter->output("\t" . 'ZEND_ARG_ARRAY_INFO(0, ' . $parameter['name'] . ', ' . (isset($parameter['default']) ? 1 : 0) . ')');
break;
case 'variable':
if (isset($parameter['cast'])) {
switch ($parameter['cast']['type']) {
case 'variable':
$value = $parameter['cast']['value'];
$headerPrinter->output("\t" . 'ZEND_ARG_OBJ_INFO(0, ' . $parameter['name'] . ', ' . Utils::escapeClassName($compilationContext->getFullName($value)) . ', ' . (isset($parameter['default']) ? 1 : 0) . ')');
break;
default:
throw new Exception('Unexpected exception');
}
} else {
$headerPrinter->output("\t" . 'ZEND_ARG_INFO(0, ' . $parameter['name'] . ')');
}
break;
default:
$headerPrinter->output("\t" . 'ZEND_ARG_INFO(0, ' . $parameter['name'] . ')');
break;
}
}
$headerPrinter->output('ZEND_END_ARG_INFO()');
$headerPrinter->outputBlankLine();
}
/** Generate FE's */
$paramData = count($parameters) ? $argInfoName : 'NULL';
if ($func->isGlobal()) {
$entryPrinter->output('ZEND_NAMED_FE(' . $func->getName() . ', ZEND_FN(' . $funcName . '), ' . $paramData . ')');
} else {
$entryPrinter->output('ZEND_NS_NAMED_FE("' . str_replace('\\', '\\\\', $func->getNamespace()) . '", ' . $func->getName() . ', ZEND_FN(' . $funcName . '), ' . $paramData . ')');
}
}
$entryPrinter->output('ZEND_FE_END');
return array($headerPrinter->getOutput(), $entryPrinter->getOutput());
}
示例10: optimize
/**
* Tries to find specific an specialized optimizer for function calls
*
* @param string $funcName
* @param array $expression
* @param Call $call
* @param CompilationContext $compilationContext
*/
protected function optimize($funcName, array $expression, Call $call, CompilationContext $compilationContext)
{
$optimizer = false;
/**
* Check if the optimizer is already cached
*/
if (!isset(self::$_optimizers[$funcName])) {
$camelizeFunctionName = Utils::camelize($funcName);
/**
* Check every optimizer directory for an optimizer
*/
foreach (self::$_optimizerDirectories as $directory) {
$path = $directory . DIRECTORY_SEPARATOR . $camelizeFunctionName . 'Optimizer.php';
if (file_exists($path)) {
require_once $path;
$className = 'Zephir\\Optimizers\\FunctionCall\\' . $camelizeFunctionName . 'Optimizer';
if (!class_exists($className, false)) {
throw new \Exception('Class ' . $className . ' cannot be loaded');
}
$optimizer = new $className();
if (!$optimizer instanceof OptimizerAbstract) {
throw new \Exception('Class ' . $className . ' must be instance of OptimizerAbstract');
}
break;
}
}
self::$_optimizers[$funcName] = $optimizer;
} else {
$optimizer = self::$_optimizers[$funcName];
}
if ($optimizer) {
return $optimizer->optimize($expression, $call, $compilationContext);
}
return false;
}
示例11: assignDefaultValue
//.........这里部分代码省略.........
}
break;
default:
throw new CompilerException("Default parameter value type: " . $parameter['default']['type'] . " cannot be assigned to variable(bool)", $parameter);
}
break;
case 'string':
$compilationContext->symbolTable->mustGrownStack(true);
$compilationContext->headersManager->add('kernel/memory');
switch ($parameter['default']['type']) {
case 'static-constant-access':
/**
* Now I can write code for easy use on Expression because code in this method don't write with codePrinter ;(
* @todo Rewrite all to codePrinter
*/
$symbolVariable = $compilationContext->symbolTable->getVariableForWrite($parameter['name'], $compilationContext, $parameter['default']);
$expression = new Expression($parameter['default']);
$expression->setExpectReturn(true, $symbolVariable);
$compiledExpression = $expression->compile($compilationContext);
if ($compiledExpression->getType() != 'string') {
throw new CompilerException("Default parameter value type: " . $compiledExpression->getType() . " cannot be assigned to variable(string)", $parameter);
}
$parameter['default']['type'] = $compiledExpression->getType();
$parameter['default']['value'] = $compiledExpression->getCode();
$compilationContext->codePrinter = $oldCodePrinter;
return $this->assignDefaultValue($parameter, $compilationContext);
break;
case 'null':
$compilationContext->backend->initVar($paramVariable, $compilationContext);
$compilationContext->backend->assignString($paramVariable, null, $compilationContext);
break;
case 'string':
$compilationContext->backend->initVar($paramVariable, $compilationContext);
$compilationContext->backend->assignString($paramVariable, Utils::addSlashes($parameter['default']['value'], true), $compilationContext);
break;
default:
throw new CompilerException("Default parameter value type: " . $parameter['default']['type'] . " cannot be assigned to variable(string)", $parameter);
}
break;
case 'array':
$compilationContext->symbolTable->mustGrownStack(true);
$compilationContext->headersManager->add('kernel/memory');
switch ($parameter['default']['type']) {
case 'null':
$compilationContext->backend->initVar($paramVariable, $compilationContext);
$compilationContext->backend->initArray($paramVariable, $compilationContext, null);
break;
case 'empty-array':
case 'array':
$compilationContext->backend->initVar($paramVariable, $compilationContext);
$compilationContext->backend->initArray($paramVariable, $compilationContext, null);
break;
default:
throw new CompilerException("Default parameter value type: " . $parameter['default']['type'] . " cannot be assigned to variable(array)", $parameter);
}
break;
case 'variable':
$symbolVariable = $compilationContext->symbolTable->getVariableForWrite($parameter['name'], $compilationContext, $parameter['default']);
switch ($parameter['default']['type']) {
case 'static-constant-access':
/**
* Now I can write code for easy use on Expression because code in this method don't write with codePrinter ;(
* @todo Rewrite all to codePrinter
*/
$expression = new Expression($parameter['default']);
$expression->setExpectReturn(true, $symbolVariable);
示例12: throwStringException
/**
* Throws an exception escaping the data
*
* @param CodePrinter $printer
* @param string $class
* @param string $message
* @param array $expression
*/
private function throwStringException(CodePrinter $printer, $class, $message, $expression)
{
$message = Utils::addSlashes($message);
$path = Compiler::getShortUserPath($expression['file']);
$printer->output(sprintf('ZEPHIR_THROW_EXCEPTION_DEBUG_STR(%s, "%s", "%s", %s);', $class, $message, $path, $expression['line']));
$printer->output('return;');
}
示例13: getReadOnlyResolvedParams
/**
* Resolve parameters using zvals in the stack and without allocating memory for constants
*
* @param array $parameters
* @param CompilationContext $compilationContext
* @param array $expression
* @return array
*/
public function getReadOnlyResolvedParams($parameters, CompilationContext $compilationContext, array $expression)
{
$codePrinter = $compilationContext->codePrinter;
$exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression, true);
$params = array();
$types = array();
$dynamicTypes = array();
foreach ($exprParams as $compiledExpression) {
$expression = $compiledExpression->getOriginal();
switch ($compiledExpression->getType()) {
case 'null':
$params[] = 'ZEPHIR_GLOBAL(global_null)';
$types[] = 'null';
$dynamicTypes[] = 'null';
break;
case 'int':
case 'uint':
case 'long':
$parameterVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
$codePrinter->output('ZVAL_LONG(&' . $parameterVariable->getName() . ', ' . $compiledExpression->getCode() . ');');
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'char':
case 'uchar':
$parameterVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
$codePrinter->output('ZVAL_LONG(&' . $parameterVariable->getName() . ', \'' . $compiledExpression->getCode() . '\');');
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'double':
$parameterVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
$codePrinter->output('ZVAL_DOUBLE(&' . $parameterVariable->getName() . ', ' . $compiledExpression->getCode() . ');');
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'bool':
if ($compiledExpression->getCode() == 'true') {
$params[] = 'ZEPHIR_GLOBAL(global_true)';
} else {
if ($compiledExpression->getCode() == 'false') {
$params[] = 'ZEPHIR_GLOBAL(global_false)';
} else {
throw new Exception('?');
}
}
$types[] = 'bool';
$dynamicTypes[] = 'bool';
break;
case 'ulong':
case 'string':
case 'istring':
$parameterVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
$codePrinter->output('ZVAL_STRING(&' . $parameterVariable->getName() . ', "' . Utils::addSlashes($compiledExpression->getCode()) . '", 0);');
$this->_temporalVariables[] = $parameterVariable;
$params[] = '&' . $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'array':
$parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
$params[] = $parameterVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
break;
case 'variable':
$parameterVariable = $compilationContext->symbolTable->getVariableForRead($compiledExpression->getCode(), $compilationContext, $expression);
switch ($parameterVariable->getType()) {
case 'int':
case 'uint':
case 'long':
case 'ulong':
$parameterTempVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
$codePrinter->output('ZVAL_LONG(&' . $parameterTempVariable->getName() . ', ' . $compiledExpression->getCode() . ');');
$params[] = '&' . $parameterTempVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
$this->_temporalVariables[] = $parameterTempVariable;
break;
case 'char':
case 'uchar':
$parameterTempVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $expression);
$codePrinter->output('ZVAL_LONG(&' . $parameterTempVariable->getName() . ', ' . $compiledExpression->getCode() . ');');
$params[] = '&' . $parameterTempVariable->getName();
$types[] = $parameterVariable->getType();
$dynamicTypes[] = $parameterVariable->getType();
//.........这里部分代码省略.........
示例14: compile
/**
* Resolves the access to a property in an object
*
* @param array $expression
* @param CompilationContext $compilationContext
* @return \CompiledExpression
*/
public function compile($expression, CompilationContext $compilationContext)
{
$codePrinter = $compilationContext->codePrinter;
$propertyAccess = $expression;
$expr = new Expression($propertyAccess['left']);
$exprVariable = $expr->compile($compilationContext);
switch ($exprVariable->getType()) {
case 'variable':
$variableVariable = $compilationContext->symbolTable->getVariableForRead($exprVariable->getCode(), $compilationContext, $expression);
switch ($variableVariable->getType()) {
case 'variable':
break;
default:
throw new CompilerException("Variable type: " . $variableVariable->getType() . " cannot be used as object", $propertyAccess['left']);
}
break;
default:
throw new CompilerException("Cannot use expression: " . $exprVariable->getType() . " as an object", $propertyAccess['left']);
}
switch ($propertyAccess['right']['type']) {
case 'variable':
$propertyVariable = $compilationContext->symbolTable->getVariableForRead($propertyAccess['right']['value'], $compilationContext, $expression);
break;
case 'string':
$propertyVariable = null;
break;
default:
throw new CompilerException("Variable type: " . $propertyAccess['right']['type'] . " cannot be used as object", $propertyAccess['left']);
}
/**
* Resolves the symbol that expects the value
*/
if ($this->_expecting) {
if ($this->_expectingVariable) {
$symbolVariable = $this->_expectingVariable;
if ($symbolVariable->getName() != 'return_value') {
$symbolVariable->observeVariant($compilationContext);
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
}
} else {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext, $expression);
}
}
/**
* Variable that receives a property value must be polymorphic
*/
if ($symbolVariable && !$symbolVariable->isVariable()) {
throw new CompilerException("Cannot use variable: " . $symbolVariable->getType() . " to assign property value", $expression);
}
/**
* At this point, we don't know the exact dynamic type fetched from the property
*/
$symbolVariable->setDynamicTypes('undefined');
$compilationContext->headersManager->add('kernel/object');
$property = $propertyVariable ? $propertyVariable : Utils::addSlashes($expression['right']['value']);
$compilationContext->backend->fetchProperty($symbolVariable, $variableVariable, $property, false, $compilationContext, false);
return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
}
示例15: compile
/**
* @param CompilationContext $compilationContext
* @throws CompilerException
*/
public function compile(CompilationContext $compilationContext)
{
foreach ($this->_statement['expressions'] as $echoExpr) {
$expr = new Expression($echoExpr);
$expr->setReadOnly(true);
$resolvedExpr = $expr->compile($compilationContext);
switch ($resolvedExpr->getType()) {
case 'int':
$compilationContext->codePrinter->output('php_printf("%d", ' . $resolvedExpr->getCode() . ');');
break;
case 'bool':
$compilationContext->codePrinter->output('php_printf("%s", ' . $resolvedExpr->getBooleanCode() . ' ? "1": "");');
break;
case 'double':
$compilationContext->codePrinter->output('php_printf("%f", ' . $resolvedExpr->getCode() . ');');
break;
case 'char':
case 'uchar':
$compilationContext->codePrinter->output('php_printf("%c", \'' . $resolvedExpr->getCode() . '\');');
break;
case 'long':
$compilationContext->codePrinter->output('php_printf("%ld", ' . $resolvedExpr->getCode() . ');');
break;
case 'string':
$compilationContext->codePrinter->output('php_printf("' . Utils::addSlashes($resolvedExpr->getCode()) . '");');
break;
case 'null':
break;
case 'variable':
$variable = $compilationContext->symbolTable->getVariableForRead($resolvedExpr->getCode(), $compilationContext, $echoExpr);
switch ($variable->getType()) {
case 'int':
$compilationContext->codePrinter->output('php_printf("%d", ' . $variable->getName() . ');');
break;
case 'long':
$compilationContext->codePrinter->output('php_printf("%ld", ' . $variable->getName() . ');');
break;
case 'double':
$compilationContext->codePrinter->output('php_printf("%f", ' . $variable->getName() . ');');
break;
case 'uchar':
case 'char':
$compilationContext->codePrinter->output('php_printf("%c", ' . $variable->getName() . ');');
break;
case 'bool':
$compilationContext->codePrinter->output('php_printf("%s", ' . $variable->getName() . ' ? "1": "");');
break;
case 'string':
case 'variable':
$compilationContext->codePrinter->output('zend_print_zval(' . $variable->getName() . ', 0);');
break;
case 'null':
break;
default:
throw new CompilerException("Unknown type: " . $variable->getType(), $echoExpr);
}
break;
default:
throw new CompilerException("Unknown type: " . $resolvedExpr->getType(), $echoExpr);
}
}
}