Skip to content

Commit

Permalink
Corrections to code for determining source fragments of assignments s…
Browse files Browse the repository at this point in the history
…tatements (#607)
  • Loading branch information
jafingerhut authored and ChrisDodd committed May 12, 2017
1 parent a20ee9b commit d58f789
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions ir/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,28 @@ cstring IR::dbp(const IR::INode* node) {

Util::JsonObject* IR::Node::sourceInfoJsonObj() const {
unsigned lineNumber, columnNumber;
const IR::Expression *lhs, *rhs;
cstring fName = srcInfo.toSourcePositionData(&lineNumber,
&columnNumber);

Util::SourceInfo si = srcInfo;
if (!si.isValid()) {
return nullptr;
}
if (is<IR::AssignmentStatement>()) {
auto assign = to<IR::AssignmentStatement>();
si = (assign->left->srcInfo + si) + assign->right->srcInfo;
}
cstring fName = si.toSourcePositionData(&lineNumber, &columnNumber);
if (fName == nullptr) {
// Do not add anything to the bmv2 JSON file for this, as this
// is likely a statement synthesized by the compiler, and
// either not easy, or it is impossible, to correlate it
// directly with anything in the user's P4 source code.
return nullptr;
}
bool isAssignment = is<IR::AssignmentStatement>();
if (isAssignment) {
auto assign = to<IR::AssignmentStatement>();
lhs = assign->left;
rhs = assign->right;
if (lhs->srcInfo.isValid())
lhs->srcInfo.toSourcePositionData(&lineNumber, &columnNumber);
}
auto json = new Util::JsonObject();
cstring sourceFrag = srcInfo.toBriefSourceFragment();
json->emplace("filename", fName);
json->emplace("line", lineNumber);
json->emplace("column", columnNumber);
cstring fullSourceFrag;
if (isAssignment) {
cstring lhsFrag = lhs->srcInfo.toBriefSourceFragment();
cstring rhsFrag = rhs->srcInfo.toBriefSourceFragment();
fullSourceFrag = lhsFrag + " " + sourceFrag + " " + rhsFrag;
} else {
fullSourceFrag = sourceFrag;
}
json->emplace("source_fragment", fullSourceFrag);
json->emplace("source_fragment", si.toBriefSourceFragment());
return json;
}

Expand Down

0 comments on commit d58f789

Please sign in to comment.