Skip to content

Commit 4a3e013

Browse files
committed
Ensure line numbers in emitted output match
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
1 parent f034ccf commit 4a3e013

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/php/lang/ast/Emitter.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract class Emitter {
1010
const METHOD = 1;
1111

1212
protected $out;
13+
protected $line= 1;
1314
protected $meta= [];
1415

1516
/**
@@ -635,11 +636,19 @@ protected function emitFrom($node) {
635636

636637
public function emit($arg) {
637638
if ($arg instanceof Node) {
639+
while ($arg->line > $this->line) {
640+
$this->out->write("\n");
641+
$this->line++;
642+
}
638643
$this->{'emit'.$arg->arity}($arg);
639644
} else {
640645
foreach ($arg as $node) {
646+
while ($node->line > $this->line) {
647+
$this->out->write("\n");
648+
$this->line++;
649+
}
641650
$this->{'emit'.$node->arity}($node);
642-
isset($node->symbol->std) || $this->out->write(";\n");
651+
isset($node->symbol->std) || $this->out->write(';');
643652
}
644653
}
645654
}

0 commit comments

Comments
 (0)