Skip to content

Commit

Permalink
remove attachment of prefix/suffix comments to SourceInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Nitish <snapdgnn@proton.me>
  • Loading branch information
snapdgn committed Aug 20, 2024
1 parent ff972fc commit da4b314
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion backends/p4fmt/attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const IR::Node *Attach::preorder(IR::P4Program *program) {
if (!program->objects.empty()) {
const auto *firstNode = program->objects.front();
if (firstNode->srcInfo.isValid()) {
for (const auto *comment : firstNode->srcInfo.getAllComments()) {
for (const auto *comment : firstNode->srcInfo.getAllFileComments()) {
globalCommentsList.insert(comment);
}
}
Expand Down
10 changes: 1 addition & 9 deletions lib/source_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,7 @@ std::ostream &operator<<(std::ostream &os, const SourceInfo &info) {
return os;
}

void SourceInfo::addCommentsBefore(Util::Comment *comment) { before.push_back(comment); }

void SourceInfo::addCommentsAfter(Util::Comment *comment) { after.push_back(comment); }

const std::vector<Util::Comment *> &SourceInfo::getCommentsBefore() const { return this->before; }

const std::vector<Util::Comment *> &SourceInfo::getCommentsAfter() const { return this->after; }

const std::vector<Comment *> &SourceInfo::getAllComments() const {
const std::vector<Comment *> &SourceInfo::getAllFileComments() const {
if (sources == nullptr) {
static std::vector<Comment *> EMPTY;
return EMPTY;
Expand Down
17 changes: 4 additions & 13 deletions lib/source_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ class SourceInfo final {
int line = -1;
int column = -1;
cstring srcBrief = ""_cs;

void addCommentsBefore(Util::Comment *comment);
void addCommentsAfter(Util::Comment *comment);

[[nodiscard]] const std::vector<Util::Comment *> &getCommentsBefore() const;
[[nodiscard]] const std::vector<Util::Comment *> &getCommentsAfter() const;

SourceInfo(cstring filename, int line, int column, cstring srcBrief) {
this->filename = filename;
this->line = line;
Expand Down Expand Up @@ -196,7 +189,7 @@ class SourceInfo final {

const SourcePosition &getEnd() const { return this->end; }

[[nodiscard]] const std::vector<Comment *> &getAllComments() const;
[[nodiscard]] const std::vector<Comment *> &getAllFileComments() const;

/**
True if this comes 'before' this source position.
Expand All @@ -218,8 +211,6 @@ class SourceInfo final {
const InputSources *sources = nullptr;
SourcePosition start = SourcePosition();
SourcePosition end = SourcePosition();
std::vector<Util::Comment *> before;
std::vector<Util::Comment *> after;
};

class IHasSourceInfo {
Expand Down Expand Up @@ -258,7 +249,7 @@ class Comment final : IHasDbPrint {
cstring body;

public:
Comment(const SourceInfo &srcInfo, bool singleLine, cstring body)
Comment(SourceInfo srcInfo, bool singleLine, cstring body)
: srcInfo(srcInfo), singleLine(singleLine), body(body) {}
cstring toString() const {
std::stringstream str;
Expand All @@ -275,8 +266,8 @@ class Comment final : IHasDbPrint {
}

// Retrieve the source position associated with this comment.
const SourcePosition &getStartPosition() const { return srcInfo.getStart(); }
const SourcePosition &getEndPosition() const { return srcInfo.getEnd(); }
[[nodiscard]] const SourcePosition &getStartPosition() const { return srcInfo.getStart(); }
[[nodiscard]] const SourcePosition &getEndPosition() const { return srcInfo.getEnd(); }
};

/**
Expand Down

0 comments on commit da4b314

Please sign in to comment.