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


PHP Utils::addSlashes方法代码示例

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


在下文中一共展示了Utils::addSlashes方法的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);
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:40,代码来源:ImplodeOptimizer.php

示例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);
     }
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:60,代码来源:ThrowStatement.php

示例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);
 }
开发者ID:gvanbeck,项目名称:zephir,代码行数:57,代码来源:ExplodeOptimizer.php

示例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);
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:25,代码来源:MemstrOptimizer.php

示例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);
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:25,代码来源:MethodExistsOptimizer.php

示例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);
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:27,代码来源:FunctionExistsOptimizer.php

示例7: declareConstant

 public function declareConstant($type, $name, $value, CompilationContext $context)
 {
     $ce = $context->classDefinition->getClassEntry($context);
     $dType = null;
     switch ($type) {
         case 'bool':
             $value = $value == 'false' ? '0' : 1;
             break;
         case 'long':
         case 'int':
             $dType = 'long';
             break;
         case 'double':
             break;
         case 'string':
         case 'char':
             if ($type == 'string' || $type == 'char') {
                 $value = "\"" . Utils::addSlashes($value) . "\"";
             }
             $dType = 'string';
             break;
     }
     if (!isset($dType)) {
         $dType = $type;
     }
     if ($dType == 'null') {
         $context->codePrinter->output('zephir_declare_class_constant_null(' . $ce . ', SL("' . $name . '"));');
     } else {
         $context->codePrinter->output('zephir_declare_class_constant_' . $dType . '(' . $ce . ', SL("' . $name . '"), ' . $value . ');');
     }
 }
开发者ID:Mrhjx2,项目名称:zephir,代码行数:31,代码来源:Backend.php

示例8: 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);
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:66,代码来源:PropertyDynamicAccess.php

示例9: 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') {
开发者ID:Jvbzephir,项目名称:zephir,代码行数:67,代码来源:ReturnStatement.php

示例10: 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);
//.........这里部分代码省略.........
开发者ID:chet0xhenry,项目名称:zephir,代码行数:101,代码来源:Call.php

示例11: compile

 /**
  * Produce the code to register a class constant
  *
  * @param CompilationContext $compilationContext
  * @throws CompilerException
  * @throws Exception
  */
 public function compile(CompilationContext $compilationContext)
 {
     if ($this->value['type'] == 'static-constant-access') {
         $name = $this->value['left']['value'] . '::' . $this->value['right']['value'];
         if (defined($name)) {
             $value = constant($name);
             if (is_int($value)) {
                 $this->value['type'] = 'int';
                 $this->value['value'] = $value;
             } elseif (is_float($value)) {
                 $this->value['type'] = 'double';
                 $this->value['value'] = $value;
             } elseif (is_bool($value)) {
                 $this->value['type'] = 'bool';
                 if (!$value) {
                     $this->value['value'] = 'false';
                 } else {
                     $this->value['value'] = 'true';
                 }
             } elseif (is_string($value)) {
                 $this->value['type'] = 'string';
                 $this->value['value'] = $value;
             } elseif (is_null($value)) {
                 $this->value['type'] = 'null';
             }
         }
     }
     switch ($this->value['type']) {
         case 'constant':
             $constant = new Constants();
             $compiledExpression = $constant->compile($this->value, $compilationContext);
             $this->value['type'] = $compiledExpression->getType();
             $this->value['value'] = $compiledExpression->getCode();
             /**
              * With no-break this will be broken (unexpected), use re-compile for new type pass
              * @todo review variant without break
              */
             $this->compile($compilationContext);
             break;
         case 'long':
         case 'int':
             $compilationContext->codePrinter->output("zend_declare_class_constant_long(" . $compilationContext->classDefinition->getClassEntry($compilationContext) . ", SL(\"" . $this->getName() . "\"), " . $this->value['value'] . " TSRMLS_CC);");
             break;
         case 'double':
             $compilationContext->codePrinter->output("zend_declare_class_constant_double(" . $compilationContext->classDefinition->getClassEntry($compilationContext) . ", SL(\"" . $this->getName() . "\"), " . $this->value['value'] . " TSRMLS_CC);");
             break;
         case 'bool':
             if ($this->value['value'] == 'false') {
                 $compilationContext->codePrinter->output("zend_declare_class_constant_bool(" . $compilationContext->classDefinition->getClassEntry($compilationContext) . ", SL(\"" . $this->getName() . "\"), 0 TSRMLS_CC);");
             } else {
                 $compilationContext->codePrinter->output("zend_declare_class_constant_bool(" . $compilationContext->classDefinition->getClassEntry($compilationContext) . ", SL(\"" . $this->getName() . "\"), 1 TSRMLS_CC);");
             }
             break;
         case 'string':
         case 'char':
             $compilationContext->codePrinter->output("zend_declare_class_constant_string(" . $compilationContext->classDefinition->getClassEntry($compilationContext) . ", SL(\"" . $this->getName() . "\"), \"" . Utils::addSlashes($this->value['value']) . "\" TSRMLS_CC);");
             break;
         case 'null':
             $compilationContext->codePrinter->output("zend_declare_class_constant_null(" . $compilationContext->classDefinition->getClassEntry($compilationContext) . ", SL(\"" . $this->getName() . "\") TSRMLS_CC);");
             break;
         default:
             throw new CompilerException('Type "' . $this->value['type'] . '" is not supported.');
     }
 }
开发者ID:noikiy,项目名称:public,代码行数:71,代码来源:ClassConstant.php

示例12: declareProperty

 /**
  * Declare class property with default value
  *
  * @param CompilationContext $compilationContext
  * @param $type
  * @param $value
  * @throws CompilerException
  */
 protected function declareProperty(CompilationContext $compilationContext, $type, $value)
 {
     $codePrinter = $compilationContext->codePrinter;
     if (is_object($value)) {
         //fix this
         return;
     }
     switch ($type) {
         case 'long':
         case 'int':
             $codePrinter->output("zend_declare_property_long(" . $compilationContext->classDefinition->getClassEntry() . ", SL(\"" . $this->getName() . "\"), " . $value . ", " . $this->getVisibilityAccesor() . " TSRMLS_CC);");
             break;
         case 'double':
             $codePrinter->output("zend_declare_property_double(" . $compilationContext->classDefinition->getClassEntry() . ", SL(\"" . $this->getName() . "\"), " . $value . ", " . $this->getVisibilityAccesor() . " TSRMLS_CC);");
             break;
         case 'bool':
             $codePrinter->output("zend_declare_property_bool(" . $compilationContext->classDefinition->getClassEntry() . ", SL(\"" . $this->getName() . "\"), " . $this->getBooleanCode($value) . ", " . $this->getVisibilityAccesor() . " TSRMLS_CC);");
             break;
         case Types::CHAR:
         case Types::STRING:
             $codePrinter->output("zend_declare_property_string(" . $compilationContext->classDefinition->getClassEntry() . ", SL(\"" . $this->getName() . "\"), \"" . Utils::addSlashes($value, true, $type) . "\", " . $this->getVisibilityAccesor() . " TSRMLS_CC);");
             break;
         case 'array':
         case 'empty-array':
         case 'null':
             $codePrinter->output("zend_declare_property_null(" . $compilationContext->classDefinition->getClassEntry() . ", SL(\"" . $this->getName() . "\"), " . $this->getVisibilityAccesor() . " TSRMLS_CC);");
             break;
         default:
             throw new CompilerException('Unknown default type: ' . $type, $this->original);
     }
 }
开发者ID:noikiy,项目名称:public,代码行数:39,代码来源:ClassProperty.php

示例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();
//.........这里部分代码省略.........
开发者ID:edin,项目名称:zephir,代码行数:101,代码来源:Call.php

示例14: compileStringTraverse

 /**
  * Compiles traversing of string values
  * - Evaluated expression must be a string
  * - Every key must be an integer or compatible
  * - Every value must be a char/integer or compatible
  *
  * @param array $expression
  * @param CompilationContext $compilationContext
  * @param Variable $exprVariable
  */
 public function compileStringTraverse($expression, CompilationContext $compilationContext, $exprVariable)
 {
     $codePrinter = $compilationContext->codePrinter;
     /**
      * Initialize 'key' variable
      */
     if (isset($this->_statement['key'])) {
         if ($this->_statement['key'] != '_') {
             $keyVariable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['key'], $compilationContext, $this->_statement['expr']);
             switch ($keyVariable->getType()) {
                 case 'int':
                 case 'uint':
                 case 'long':
                 case 'ulong':
                 case 'char':
                 case 'uchar':
                     break;
                 default:
                     throw new CompilerException("Cannot use variable: " . $this->_statement['key'] . " type: " . $keyVariable->getType() . " as key in string traversal", $this->_statement['expr']);
             }
         } else {
             $keyVariable = $compilationContext->symbolTable->getTempVariableForWrite('int', $compilationContext);
             $keyVariable->increaseUses();
         }
         $keyVariable->setMustInitNull(true);
         $keyVariable->setIsInitialized(true, $compilationContext, $this->_statement);
     }
     /**
      * Initialize 'value' variable
      */
     if (isset($this->_statement['value'])) {
         if ($this->_statement['value'] != '_') {
             $variable = $compilationContext->symbolTable->getVariableForWrite($this->_statement['value'], $compilationContext, $this->_statement['expr']);
             switch ($variable->getType()) {
                 case 'int':
                 case 'uint':
                 case 'long':
                 case 'ulong':
                 case 'char':
                 case 'uchar':
                     break;
                 default:
                     throw new CompilerException("Cannot use variable: " . $this->_statement['value'] . " type: " . $variable->getType() . " as value in string traversal", $this->_statement['expr']);
             }
         } else {
             $variable = $compilationContext->symbolTable->getTempVariableForWrite('char', $compilationContext);
             $variable->increaseUses();
         }
         $variable->setMustInitNull(true);
         $variable->setIsInitialized(true, $compilationContext, $this->_statement);
     }
     $tempVariable = $compilationContext->symbolTable->addTemp('long', $compilationContext);
     /**
      * Create a temporary value to store the constant string
      */
     if ($expression->getType() == 'string') {
         $constantVariable = $compilationContext->symbolTable->getTempLocalVariableForWrite('variable', $compilationContext, $this->_statement);
         $compilationContext->backend->assignString($constantVariable, Utils::addSlashes($expression->getCode()), $compilationContext, true, false);
         $stringVariable = $constantVariable;
     } else {
         $stringVariable = $exprVariable;
     }
     $stringVariableCode = $compilationContext->backend->getVariableCode($stringVariable);
     if ($this->_statement['reverse']) {
         $codePrinter->output('for (' . $tempVariable->getName() . ' = Z_STRLEN_P(' . $stringVariableCode . '); ' . $tempVariable->getName() . ' >= 0; ' . $tempVariable->getName() . '--) {');
     } else {
         $codePrinter->output('for (' . $tempVariable->getName() . ' = 0; ' . $tempVariable->getName() . ' < Z_STRLEN_P(' . $stringVariableCode . '); ' . $tempVariable->getName() . '++) {');
     }
     if (isset($this->_statement['key'])) {
         $codePrinter->output("\t" . $keyVariable->getName() . ' = ' . $tempVariable->getName() . '; ');
     }
     $compilationContext->headersManager->add('kernel/operators');
     $codePrinter->output("\t" . $variable->getName() . ' = ZEPHIR_STRING_OFFSET(' . $stringVariableCode . ', ' . $tempVariable->getName() . ');');
     /**
      * Variables are initialized in a different way inside cycle
      */
     $compilationContext->insideCycle++;
     /**
      * Compile statements in the 'for' block
      */
     if (isset($this->_statement['statements'])) {
         $st = new StatementsBlock($this->_statement['statements']);
         $st->isLoop(true);
         if (isset($this->_statement['key'])) {
             $st->getMutateGatherer()->increaseMutations($this->_statement['key']);
         }
         $st->getMutateGatherer()->increaseMutations($this->_statement['value']);
         $st->compile($compilationContext);
     }
     $compilationContext->insideCycle--;
//.........这里部分代码省略.........
开发者ID:jxw7733,项目名称:zephir,代码行数:101,代码来源:ForStatement.php

示例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);
         }
     }
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:66,代码来源:EchoStatement.php


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