Skip to content

Commit

Permalink
Don't use an invalid srcInfo to construct json source info.
Browse files Browse the repository at this point in the history
- Also fix off-by-one error tracking stdin line number
  • Loading branch information
Chris Dodd committed May 9, 2017
1 parent 8f355cd commit 67700f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ir/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Util::JsonObject* IR::Node::sourceInfoJsonObj() const {
auto assign = to<IR::AssignmentStatement>();
lhs = assign->left;
rhs = assign->right;
lhs->srcInfo.toSourcePositionData(&lineNumber, &columnNumber);
if (lhs->srcInfo.isValid())
lhs->srcInfo.toSourcePositionData(&lineNumber, &columnNumber);
}
auto json = new Util::JsonObject();
cstring sourceFrag = srcInfo.toBriefSourceFragment();
Expand Down
3 changes: 2 additions & 1 deletion lib/source_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ InputSources* InputSources::instance = new InputSources();

InputSources::InputSources() :
sealed(false) {
mapLine(nullptr, 0);
mapLine(nullptr, 1); // the first line read will be line 1 of stdin
contents.push_back("");
}

Expand Down Expand Up @@ -169,6 +169,7 @@ SourceFileLine InputSources::getSourceLine(unsigned line) const {
// The first line indicates that line 2 is the first line in x.p4
// line=2, it->first=1, it->second.sourceLine=1
// So we have to subtract one to get the real line number
BUG_CHECK(line - it->first + it->second.sourceLine > 0, "invalid source line");
return SourceFileLine(it->second.fileName, line - it->first + it->second.sourceLine - 1);
}

Expand Down

0 comments on commit 67700f3

Please sign in to comment.