Class Kitab\Compiler\Compiler

class Compiler
{
    pub fn __construct();
    pub fn compile(Finder $finder, Target $target);
    pub fn getParser(): Parser;
    pro fn link(File $file, array &$symbols);
}

A compiler that orchestrates the whole compilation process.

This compiler, as explained previously, is a stream compiler. It receives a finder that is an iterator where each item is a PHP file to analyse. Each file is parsed by the parser, transformed into a Intermediate Representation, that is compiled by the target into partial objects. The target ends the whole process by assembling all the objects.

Attributes

pro static $_parser = null;

The parsed used to parse PHP files.

The parser is allocated once, hence the static declaration.

Methods

pub fn __construct()

When constructing the compiler, a new instance of the Kitab\Compiler\Parser parser is created and stored statically.

pub fn compile(Finder $finder, Target $target)

Compile all files provided by the finder into the specified target. See the workflow description for more details.

Examples

$finder = new Kitab\Finder();
$finder->in($path);

$target = new Kitab\Compiler\Target\Html\Html();

$compiler = new Kitab\Compiler\Compiler();
$compiler->compile($finder, $target);
pub fn getParser(): Parser

Return the parser stored in the cache.

Examples

$compiler = new Kitab\Compiler\Compiler();

assert($compiler->getParser() instanceof Kitab\Compiler\Parser);
pro fn link(File $file, array &$symbols)

Extract new symbols from an intermediate representation and update the linker.

The linker is a tree structure.

Exceptions

If the link handles an intermediate representation that is unexpected, a Kitab\Exception\LinkerUnknownIntermediateRepresentation exception will be thrown. This is not likely to happen, except during a development phase.