Inheritance: extends PHPCfg\Op
Beispiel #1
0
 public function __construct(array $keys, array $values, array $byRef, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->keys = $this->addReadRef($keys);
     $this->values = $this->addReadRef($values);
     $this->byRef = $byRef;
 }
Beispiel #2
0
 public function __construct(Operand $read, Operand $write, Assert $assertion, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->expr = $this->addReadRef($read);
     $this->assertion = $this->addReadRef($assertion);
     $this->result = $this->addWriteRef($write);
 }
Beispiel #3
0
 public function __construct(array $keys, array $values, array $byRef, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->keys = $keys;
     $this->values = $values;
     $this->byRef = $byRef;
 }
Beispiel #4
0
 public function __construct(Operand $name, Operand $nsName, array $args, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->nsName = $this->addReadRef($nsName);
     $this->name = $this->addReadRef($name);
     $this->args = $this->addReadRef($args);
 }
Beispiel #5
0
 public function __construct(Operand $class, Operand $name, array $args, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->class = $class;
     $this->name = $name;
     $this->args = $args;
 }
Beispiel #6
0
 public function __construct(Variable $var, Variable $name, array $args, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->var = $var;
     $this->name = $name;
     $this->args = $args;
 }
Beispiel #7
0
 public function __construct(array $params, $byRef, $returnType, Block $stmts, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->params = $params;
     $this->byRef = (bool) $byRef;
     $this->returnType = $returnType;
     $this->stmts = $stmts;
 }
Beispiel #8
0
 public function __construct(array $params, array $useVars, $byRef, $returnType, Block $stmts, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->params = $this->addReadRef($params);
     $this->useVars = $this->addReadRef($useVars);
     $this->byRef = (bool) $byRef;
     $this->returnType = $returnType;
     $this->stmts = $stmts;
 }
Beispiel #9
0
 public function __construct(Operand $name, $type, $byRef, $variadic, Operand $defaultVar = null, Block $defaultBlock = null, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->result->name = $name;
     $this->name = $name;
     $this->type = $type;
     $this->byRef = (bool) $byRef;
     $this->variadic = (bool) $variadic;
     $this->defaultVar = $defaultVar;
     $this->defaultBlock = $defaultBlock;
 }
Beispiel #10
0
 public function __construct(Operand $left, Operand $right, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->left = $left;
     $this->right = $right;
 }
Beispiel #11
0
 public function __construct(Variable $expr, $type, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->expr = $expr;
     $this->type = $type;
 }
Beispiel #12
0
 public function __construct(Operand $var, Operand $name, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->var = $var;
     $this->name = $name;
 }
Beispiel #13
0
 public function __construct(array $list, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->list = $this->addWriteRef($list);
 }
Beispiel #14
0
 public function __construct(array $vars, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->vars = $this->addReadRef($vars);
 }
Beispiel #15
0
 public function __construct(Variable $class, array $args, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->class = $class;
     $this->args = $args;
 }
Beispiel #16
0
 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;
         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':
             throw new \LogicException("TODO");
             break;
         case 'Expr_BinaryOp_NotIdentical':
             throw new \LogicException("TODO");
             break;
         case 'Expr_BinaryOp_Plus':
             $result = $this->getVarName($op->left) . " + " . $this->getVarName($op->right);
             break;
         case 'Expr_BinaryOp_Pow':
             throw new \LogicException("TODO");
             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':
             throw new \LogicException("TODO");
             break;
         case 'Expr_Print':
             $result = "1;\n" . $this->compilePrintStatement($op, $indent);
             break;
         default:
             throw new \RuntimeException("Unknown expression found: " . $op->getType());
     }
     foreach ($op->result->usages as $usage) {
         if ($usage instanceof Op\Phi) {
             $phi .= $indent . $this->getVarName($usage->result) . " = " . $this->getVarName($op->result) . ";\n";
         }
     }
     if (count($op->result->usages) === 0) {
         return $indent . $result . ";\n" . $phi;
     }
     return $indent . $this->getVarName($op->result) . " = " . $result . ";\n" . $phi;
 }
Beispiel #17
0
 public function __construct(Operand $var, $byRef, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->var = $var;
     $this->byRef = $byRef;
 }
Beispiel #18
0
 public function __construct(Operand $expr, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->expr = $expr;
 }
Beispiel #19
0
 public function __construct(Operand $left, Operand $right, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->left = $this->addReadRef($left);
     $this->right = $this->addReadRef($right);
 }
Beispiel #20
0
 public function __construct(Variable $expr, Variable $class, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->expr = $expr;
     $this->class = $class;
 }
Beispiel #21
0
 public function __construct(Operand $value = null, Operand $key = null, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->value = $this->addReadRef($value);
     $this->key = $this->addReadRef($key);
 }
Beispiel #22
0
 public function __construct(Variable $left, Variable $right, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->left = $left;
     $this->right = $right;
 }
 public function __construct(Operand $class, Operand $name, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->class = $this->addReadRef($class);
     $this->name = $this->addReadRef($name);
 }
Beispiel #24
0
 public function __construct(Operand $expr, $type, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->expr = $this->addReadRef($expr);
     $this->type = $type;
 }
Beispiel #25
0
 public function __construct(array $list, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->list = $list;
 }
Beispiel #26
0
 public function __construct(Operand $var, Operand $dim = null, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->var = $this->addReadRef($var);
     $this->dim = $this->addReadRef($dim);
 }
Beispiel #27
0
 public function __construct(Block $expr, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->expr = $this->addReadRef($expr);
 }
Beispiel #28
0
 public function __construct(Operand $var, Operand $expr, array $attributes = [])
 {
     parent::__construct($attributes);
     $this->var = $this->addWriteRef($var);
     $this->expr = $this->addReadRef($expr);
 }
Beispiel #29
0
 public function __construct(Variable $var, Variable $expr, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->var = $var;
     $this->expr = $expr;
 }
Beispiel #30
0
 public function __construct(Operand $var, Operand $dim = null, array $attributes = array())
 {
     parent::__construct($attributes);
     $this->var = $var;
     $this->dim = $dim;
 }