2020-08-30 16:58:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Phabel\Plugin;
|
|
|
|
|
|
|
|
use Phabel\Plugin;
|
|
|
|
use PhpParser\Node;
|
|
|
|
use PhpParser\Node\FunctionLike;
|
|
|
|
use SplQueue;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal regenerator traversor.
|
2020-09-05 22:35:30 +02:00
|
|
|
*
|
|
|
|
* @author Daniil Gentili <daniil@daniil.it>
|
|
|
|
* @license MIT
|
2020-08-30 16:58:59 +02:00
|
|
|
*/
|
|
|
|
class ReGeneratorInternal extends Plugin
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* List of nodes for each case.
|
|
|
|
*
|
|
|
|
* @var SplQueue<SplQueue<Node>>
|
|
|
|
*/
|
|
|
|
private SplQueue $states;
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->states = new SplQueue;
|
|
|
|
$this->states->enqueue(new SplQueue);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Push node to current case.
|
|
|
|
*
|
|
|
|
* @param Node $node Node
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function pushNode(Node $node): void
|
|
|
|
{
|
|
|
|
$this->states->top()->enqueue($node);
|
|
|
|
}
|
|
|
|
private function pushState(): int
|
|
|
|
{
|
|
|
|
$this->states->enqueue(new SplQueue);
|
|
|
|
return $this->states->count()-1;
|
|
|
|
}
|
|
|
|
public function enterRoot(FunctionLike $func)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|