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


PHP Expr::getType方法代码示例

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


在下文中一共展示了Expr::getType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compileExpr

 protected function compileExpr(Op\Expr $op, $indent)
 {
     $phi = '';
     foreach ($op->result->usages as $usage) {
         if ($usage instanceof Op\Phi) {
             $phi .= $indent . $this->getVarName($usage->result) . " = " . $this->getVarName($op->result) . ";\n";
         }
     }
     $result = '';
     switch ($op->getType()) {
         case 'Expr_ArrayDimFetch':
             $var = $this->getVarName($op->var);
             $dim = $this->getVarName($op->dim);
             $result = $this->getVarName($op->result);
             switch ($this->mapToCType($op->var->type)) {
                 case 'zend_string*':
                     assert($this->mapToCType($op->dim->type) === 'zend_long');
                     $safety = $indent . "if ({$dim} < 0 || {$dim} >= ZSTR_LEN({$var})) {\n";
                     $safety .= $indent . "\t{$result} = ZSTR_EMPTY_ALLOC();\n";
                     $safety .= $indent . "\tzend_error(E_NOTICE, \"Uninitialized string offset: %pd\", {$dim});\n";
                     $safety .= $indent . "} else if (CG(one_char_string)[(unsigned char) ZSTR_VAL({$var})[{$dim}]]) {\n";
                     $safety .= $indent . "\t{$result} = CG(one_char_string)[(unsigned char) ZSTR_VAL({$var})[{$dim}]];\n";
                     $safety .= $indent . "} else {\n";
                     $safety .= $indent . "\t{$result} = zend_string_init(ZSTR_VAL({$var}) + {$dim}, 1, 0);\n";
                     $safety .= $indent . "\tfree_{$result} = 1;\n";
                     $safety .= $indent . "}\n{$phi}";
                     return $safety;
                 case 'HashTable*':
                     $dimType = $this->mapToCType($op->dim->type);
                     $resultType = $this->mapToCType($op->result->type);
                     if ($dimType === 'zend_long') {
                         $safety = $indent . "do {\n";
                         $safety .= $indent . "\tzval* tmp = zend_hash_index_find({$var}, {$dim});\n";
                         $safety .= $indent . "\tif (tmp == NULL) {\n";
                         if ($resultType === 'zval') {
                             $safety .= $indent . "\t\tZVAL_NULL(&{$result});\n";
                             $safety .= $indent . "\t\tzend_error(E_NOTICE, \"Uninitialized offset: %pd\", {$dim});\n";
                             $safety .= $indent . "\t} else {\n";
                             $safety .= $indent . "\t\t{$result} = *tmp;\n";
                             $safety .= $indent . "\t}\n";
                             $safety .= $indent . "} while(0);\n";
                             return $safety;
                         } else {
                             $typeInfo = $this->getTypeInfo($resultType);
                             $safety .= $indent . "\t\t" . $typeInfo['default']($result) . ";\n";
                             $safety .= $indent . "\t\tzend_error(E_NOTICE, \"Uninitialized offset: %pd\", {$dim});\n";
                             $safety .= $indent . "\t} else if (Z_TYPE_P(tmp) != {$typeInfo['ztype']}) {\n";
                             $safety .= $indent . "\t\tzend_throw_error(NULL, \"Offset is not an {$typeInfo['stringtype']}: %pd\", {$dim});\n";
                             $safety .= $indent . "\t} else {\n";
                             $safety .= $indent . "\t\t{$result} = {$typeInfo['ztypefetch']}(tmp);\n";
                             $safety .= $indent . "\t}\n";
                             $safety .= $indent . "} while(0); \n";
                             return $safety;
                         }
                     }
                 default:
                     throw new \LogicException("Unknown array dim fetch type {$op->var->type}");
             }
             break;
         case 'Expr_Assign':
             $result = $this->getVarName($op->var) . ' = ' . $this->getVarName($op->expr);
             foreach ($op->var->usages as $usage) {
                 if ($usage instanceof Op\Phi) {
                     $phi .= $indent . $this->getVarName($usage->result) . " = " . $this->getVarName($op->var) . ";\n";
                 }
             }
             break;
         case 'Expr_BinaryOp_BitwiseAnd':
             $result = $this->getVarName($op->left) . " & " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_BitwiseOr':
             $result = $this->getVarName($op->left) . " | " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_BitwiseXor':
             $result = $this->getVarName($op->left) . " ^ " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Coalesce':
             throw new \LogicException("TODO");
             break;
         case 'Expr_BinaryOp_Concat':
             $result = $this->getVarName($op->left) . " . " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Div':
             $result = $this->getVarName($op->left) . " / " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Equal':
             throw new \LogicException("TODO");
             break;
         case 'Expr_BinaryOp_Greater':
             $result = $this->getVarName($op->left) . " > " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_GreaterOrEqual':
             $result = $this->getVarName($op->left) . " >= " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Identical':
             throw new \LogicException("TODO");
             break;
         case 'Expr_BinaryOp_LogicalXor':
             throw new \LogicException("TODO");
             break;
//.........这里部分代码省略.........
开发者ID:krakjoe,项目名称:php-compiler,代码行数:101,代码来源:PECL.php

示例2: compileExpr

 protected function compileExpr(Op\Expr $op, $indent)
 {
     $phi = '';
     $result = '';
     switch ($op->getType()) {
         case 'Expr_ArrayDimFetch':
             $result = $this->getVarName($op->var) . "[" . $this->getVarName($op->dim) . "]";
             break;
         case 'Expr_Assign':
             $result = $this->getVarName($op->var) . ' = ' . $this->getVarName($op->expr);
             foreach ($op->var->usages as $usage) {
                 if ($usage instanceof Op\Phi) {
                     $phi .= $indent . $this->getVarName($usage->result) . " = " . $this->getVarName($op->var) . ";\n";
                 }
             }
             break;
         case 'Expr_BinaryOp_BitwiseAnd':
             $result = $this->getVarName($op->left) . " & " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_BitwiseOr':
             $result = $this->getVarName($op->left) . " | " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_BitwiseXor':
             $result = $this->getVarName($op->left) . " ^ " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Coalesce':
             $result = $this->getVarName($op->left) . " ?? " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Concat':
             $result = $this->getVarName($op->left) . " . " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Div':
             $result = $this->getVarName($op->left) . " / " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Equal':
             $result = $this->getVarName($op->left) . " == " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Greater':
             $result = $this->getVarName($op->left) . " > " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_GreaterOrEqual':
             $result = $this->getVarName($op->left) . " >= " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Identical':
             $result = $this->getVarName($op->left) . " === " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_LogicalXor':
             $result = $this->getVarName($op->left) . " XOR " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Minus':
             $result = $this->getVarName($op->left) . " - " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Mod':
             $result = $this->getVarName($op->left) . " % " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Mul':
             $result = $this->getVarName($op->left) . " * " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_NotEqual':
             $result = $this->getVarName($op->left) . " != " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_NotIdentical':
             $result = $this->getVarName($op->left) . " !== " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Plus':
             $result = $this->getVarName($op->left) . " + " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Pow':
             $result = $this->getVarName($op->left) . " ** " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_ShiftLeft':
             $result = $this->getVarName($op->left) . " << " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_ShiftRight':
             $result = $this->getVarName($op->left) . " >> " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Smaller':
             $result = $this->getVarName($op->left) . " < " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_SmallerOrEqual':
             $result = $this->getVarName($op->left) . " <= " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Spaceship':
             $result = $this->getVarName($op->left) . " <=> " . $this->getVarName($op->right);
             break;
         case 'Expr_Cast_Array':
             $result = "(array) " . $this->getVarName($op->expr);
             break;
         case 'Expr_Cast_Bool':
             $result = "(bool) " . $this->getVarName($op->expr);
             break;
         case 'Expr_Cast_Double':
             $result = "(float) " . $this->getVarName($op->expr);
             break;
         case 'Expr_Cast_Int':
             $result = "(int) " . $this->getVarName($op->expr);
             break;
         case 'Expr_Cast_Object':
             $result = "(object) " . $this->getVarName($op->expr);
             break;
//.........这里部分代码省略.........
开发者ID:ircmaxell,项目名称:php-compiler,代码行数:101,代码来源:PHP.php


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