Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P4fmt]: attaching comments to IR Nodes #4845

Merged
merged 15 commits into from
Oct 24, 2024
Prev Previous commit
Next Next commit
expose IHasSourceInfo for the Comment class
Signed-off-by: Nitish <snapdgnn@proton.me>
  • Loading branch information
snapdgn committed Oct 24, 2024
commit ef82f5157625172e28d3d71c800f147ca737da8d
2 changes: 1 addition & 1 deletion backends/p4fmt/attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const IR::Node *Attach::attachCommentsToNode(IR::Node *node, TraversalType ttype
continue;
}

const auto &commentEnd = comment->getEndPosition();
const auto &commentEnd = comment->getSourceInfo().getEnd();

switch (ttype) {
case TraversalType::Preorder:
snapdgn marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 3 additions & 5 deletions lib/source_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ struct SourceFileLine {
cstring toString() const;
};

class Comment final : IHasDbPrint {
class Comment final : IHasDbPrint, IHasSourceInfo {
private:
SourceInfo srcInfo;
bool singleLine;
Expand All @@ -274,10 +274,8 @@ class Comment final : IHasDbPrint {
if (!singleLine) out << "*/";
}

/// Retrieve the beginning of the source position associated with this comment.
[[nodiscard]] const SourcePosition &getStartPosition() const { return srcInfo.getStart(); }
/// Retrieve the end of the source position associated with this comment.
[[nodiscard]] const SourcePosition &getEndPosition() const { return srcInfo.getEnd(); }
/// Retrieve the Source position associated with this Comment.
snapdgn marked this conversation as resolved.
Show resolved Hide resolved
[[nodiscard]] SourceInfo getSourceInfo() const override { return srcInfo; }
};

/**
Expand Down