Fix line number handling in line directive callback.

The line argument passed into the lineCallback function is the
literal value of the first argument of the #line directive.
lastLine in DoPreprocessing() should be updated taking into
consideration the different definitions for #line between specs.

Add a test to reveal the bug.
This commit is contained in:
Lei Zhang 2015-07-03 01:25:47 -04:00
parent 3a194f7ba4
commit 5cbc990a0a
9 changed files with 40 additions and 13 deletions

View file

@ -639,18 +639,25 @@ struct DoPreprocessing {
adjustLine(line);
outputStream << "#extension " << extension << " : " << behavior;
});
parseContext.setLineCallback([&lastLine, &outputStream](
int line, bool hasSource, int sourceNum) {
parseContext.setLineCallback([&lastLine, &outputStream, &parseContext](
int newLineNo, bool hasSource, int sourceNum) {
// SourceNum is the number of the source-string that is being parsed.
if (lastLine != -1) {
outputStream << std::endl;
}
outputStream << "#line " << line;
outputStream << "#line " << newLineNo;
if (hasSource) {
outputStream << " " << sourceNum;
}
if (parseContext.lineDirectiveShouldSetNextLine()) {
// newLineNo is the new line number for the line following the #line
// directive. So the new line number for the current line is
newLineNo -= 1;
}
outputStream << std::endl;
lastLine = std::max(line - 1, 1);
// Line number starts from 1. And we are at the next line of the #line
// directive now. So lastLine (from 0) should be (newLineNo - 1) + 1.
lastLine = newLineNo;
});