Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
[CFG] While: create new block for cond, if it's rly needed
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Feb 26, 2019
1 parent 8f24616 commit c3478ec
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/ControlFlow/ControlFlowGraph.php
Expand Up @@ -90,7 +90,7 @@ protected function passNodes(array $nodes, Block $block)
$block = $this->passIf($stmt, $block);
break;
case \PhpParser\Node\Stmt\While_::class:
$block = $this->passWhile($stmt, $block);
$block = $this->passWhile($stmt, $this->createNewBlockIfNeeded($block));
break;
case \PhpParser\Node\Stmt\Do_::class:
$block = $this->passDo($stmt, $block);
Expand Down Expand Up @@ -264,16 +264,11 @@ protected function passDo(\PhpParser\Node\Stmt\Do_ $do, Block $block)

/**
* @param \PhpParser\Node\Stmt\While_ $while
* @param Block $block
* @param Block $cond
* @return Block
*/
protected function passWhile(\PhpParser\Node\Stmt\While_ $while, Block $block)
protected function passWhile(\PhpParser\Node\Stmt\While_ $while, Block $cond)
{
$cond = new Block($this->lastBlockId++);
$block->setExit(
$cond
);

$loop = new Block($this->lastBlockId++);

$jumpIf = new Node\JumpIfNode($this->passExpr($while->cond), $loop);
Expand Down

0 comments on commit c3478ec

Please sign in to comment.