Skip to content

Commit

Permalink
Ensure line numbers in emitted output match
Browse files Browse the repository at this point in the history
We really need https://wiki.php.net/rfc/sourcemaps or something
like https://wiki.php.net/rfc/linecontrol, but for the time
being, this methods is OK, too
  • Loading branch information
thekid committed Oct 18, 2017
1 parent f034ccf commit 4a3e013
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/php/lang/ast/Emitter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class Emitter {
const METHOD = 1;

protected $out;
protected $line= 1;
protected $meta= [];

/**
Expand Down Expand Up @@ -635,11 +636,19 @@ protected function emitFrom($node) {

public function emit($arg) {
if ($arg instanceof Node) {
while ($arg->line > $this->line) {
$this->out->write("\n");
$this->line++;
}
$this->{'emit'.$arg->arity}($arg);
} else {
foreach ($arg as $node) {
while ($node->line > $this->line) {
$this->out->write("\n");
$this->line++;
}
$this->{'emit'.$node->arity}($node);
isset($node->symbol->std) || $this->out->write(";\n");
isset($node->symbol->std) || $this->out->write(';');
}
}
}
Expand Down

0 comments on commit 4a3e013

Please sign in to comment.