getVariableNames() abstract public method

abstract public getVariableNames ( )
コード例 #1
0
ファイル: Dumper.php プロジェクト: royopa/php-cfg
 private function dumpOp(Op $op)
 {
     $result = $op->getType();
     foreach ($op->getVariableNames() as $varName) {
         $result .= "\n    {$varName}: ";
         $result .= $this->indent($this->dumpOperand($op->{$varName}));
     }
     foreach ($op->getSubBlocks() as $subBlock) {
         $result .= "\n    {$subBlock}: " . $this->indent($this->dumpBlockRef($op->{$subBlock}));
     }
     return $result;
 }
コード例 #2
0
ファイル: VariableFinder.php プロジェクト: ircmaxell/php-cfg
 public function enterOp(Op $op, Block $block)
 {
     foreach ($op->getVariableNames() as $name) {
         $var = $op->{$name};
         if (!is_array($var)) {
             $var = [$var];
         }
         foreach ($var as $v) {
             if (is_null($v)) {
                 continue;
             }
             $this->variables->attach($v);
         }
     }
 }
コード例 #3
0
ファイル: Helper.php プロジェクト: ircmaxell/php-optimizer
 public static function removeUsage(Operand $var, Op $op)
 {
     foreach ($op->getVariableNames() as $varName) {
         $vars = $op->{$varName};
         $newVars = [];
         if (!is_array($vars)) {
             $vars = [$vars];
         }
         foreach ($vars as $key => $value) {
             if ($value !== $var) {
                 $newVars[$key] = $value;
             }
         }
         if (!is_array($op->{$varName})) {
             $op->{$varName} = array_shift($newVars);
         } else {
             $op->{$varName} = array_keys($newVars);
         }
     }
 }
コード例 #4
0
ファイル: Printer.php プロジェクト: ircmaxell/php-cfg
 protected function renderOp(Op $op)
 {
     $result = $op->getType();
     if ($op instanceof Op\CallableOp) {
         $func = $op->getFunc();
         $result .= "<" . $func->name . ">";
     }
     if ($op instanceof Op\Expr\Assertion) {
         $result .= "<" . $this->renderAssertion($op->assertion) . ">";
     }
     foreach ($op->getVariableNames() as $varName) {
         $vars = $op->{$varName};
         if (is_array($vars)) {
             foreach ($vars as $key => $var) {
                 if (!$var) {
                     continue;
                 }
                 $result .= "\n    {$varName}[{$key}]: ";
                 $result .= $this->indent($this->renderOperand($var));
             }
         } elseif ($vars) {
             $result .= "\n    {$varName}: ";
             $result .= $this->indent($this->renderOperand($vars));
         }
     }
     $childBlocks = [];
     foreach ($op->getSubBlocks() as $blockName) {
         $sub = $op->{$blockName};
         if (is_array($sub)) {
             foreach ($sub as $key => $subBlock) {
                 if (!$subBlock) {
                     continue;
                 }
                 $this->enqueueBlock($subBlock);
                 $childBlocks[] = ["block" => $subBlock, "name" => $blockName . "[" . $key . "]"];
             }
         } elseif ($sub) {
             $this->enqueueBlock($sub);
             $childBlocks[] = ["block" => $sub, "name" => $blockName];
         }
     }
     return ["op" => $op, "label" => $result, "childBlocks" => $childBlocks];
 }
コード例 #5
0
ファイル: Printer.php プロジェクト: RustJason/php-cfg
 protected function renderOp(Op $op)
 {
     $result = $op->getType();
     if ($op instanceof Op\CallableOp) {
         $result .= '<' . $op->name->value . '>';
         foreach ($op->getParams() as $key => $param) {
             $result .= $this->indent("\nParam[{$key}]: " . $this->renderOperand($param->result));
         }
     }
     if ($op instanceof Op\Expr\Assertion) {
         $result .= "<" . $this->renderAssertion($op->assertion) . ">";
     }
     foreach ($op->getVariableNames() as $varName) {
         $vars = $op->{$varName};
         if (!is_array($vars)) {
             $vars = [$vars];
         }
         foreach ($vars as $var) {
             if (!$var) {
                 continue;
             }
             $result .= "\n    {$varName}: ";
             $result .= $this->indent($this->renderOperand($var));
         }
     }
     $childBlocks = [];
     foreach ($op->getSubBlocks() as $blockName) {
         $sub = $op->{$blockName};
         if (is_null($sub)) {
             continue;
         }
         if (!is_array($sub)) {
             $sub = [$sub];
         }
         foreach ($sub as $subBlock) {
             if (!$subBlock) {
                 continue;
             }
             $this->enqueueBlock($subBlock);
             $childBlocks[] = ["block" => $subBlock, "name" => $blockName];
         }
     }
     return ["op" => $op, "label" => $result, "childBlocks" => $childBlocks];
 }
コード例 #6
0
ファイル: Simplifier.php プロジェクト: RustJason/php-cfg
 private function replaceOpVariable(Operand $from, Operand $to, Op $op)
 {
     foreach ($op->getVariableNames() as $name) {
         if (is_null($op->{$name})) {
             continue;
         }
         if (is_array($op->{$name})) {
             // SIGH, PHP won't let me do this directly (parses as $op->($name[$key]))
             $result = $op->{$name};
             $new = [];
             foreach ($result as $key => $value) {
                 if ($value === $from) {
                     $new[$key] = $to;
                     if ($op->isWriteVariable($name)) {
                         $to->addWriteOp($op);
                     } else {
                         $to->addUsage($op);
                     }
                 } else {
                     $new[$key] = $value;
                 }
             }
             $op->{$name} = $new;
         } elseif ($op->{$name} === $from) {
             $op->{$name} = $to;
             if ($op->isWriteVariable($name)) {
                 $to->addWriteOp($op);
             } else {
                 $to->addUsage($op);
             }
         }
     }
 }