protected function parseStmt_Switch(Stmt\Switch_ $node)
{
if ($this->switchCanUseJumptable($node)) {
$this->compileJumptableSwitch($node);
return;
}
// Desugar switch into compare-and-jump sequence
$cond = $this->parseExprNode($node->cond);
$endBlock = new Block();
$defaultBlock = $endBlock;
/** @var Block|null $prevBlock */
$prevBlock = null;
foreach ($node->cases as $case) {
$ifBlock = new Block();
if ($prevBlock && !$prevBlock->dead) {
$prevBlock->children[] = new Jump($ifBlock);
$ifBlock->addParent($prevBlock);
}
if ($case->cond) {
$caseExpr = $this->parseExprNode($case->cond);
$this->block->children[] = $cmp = new Op\Expr\BinaryOp\Equal($this->readVariable($cond), $this->readVariable($caseExpr), $this->mapAttributes($case));
$elseBlock = new Block();
$this->block->children[] = new JumpIf($cmp->result, $ifBlock, $elseBlock);
$ifBlock->addParent($this->block);
$elseBlock->addParent($this->block);
$this->block = $elseBlock;
} else {
$defaultBlock = $ifBlock;
}
$prevBlock = $this->parseNodes($case->stmts, $ifBlock);
}
if ($prevBlock && !$prevBlock->dead) {
$prevBlock->children[] = new Jump($endBlock);
$endBlock->addParent($prevBlock);
}
$this->block->children[] = new Jump($defaultBlock);
$defaultBlock->addParent($this->block);
$this->block = $endBlock;
}