Skip to content

Commit

Permalink
refactor: rename variables, remove unused headers
Browse files Browse the repository at this point in the history
Signed-off-by: Nitish <snapdgnn@proton.me>
  • Loading branch information
snapdgn committed Aug 26, 2024
1 parent e9f53dc commit b87606d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions backends/p4fmt/attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const IR::Node *Attach::attachCommentsToNode(IR::Node *node, TraversalType ttype

const auto nodeStart = node->srcInfo.getStart();

for (auto &[comment, isVisited] : processedComments) {
for (auto &[comment, isAttached] : processedComments) {
// Skip if already attached
if (isVisited) {
if (isAttached) {
continue;
}

Expand All @@ -47,14 +47,14 @@ const IR::Node *Attach::attachCommentsToNode(IR::Node *node, TraversalType ttype
case TraversalType::Preorder:
if (commentEnd.getLineNumber() == nodeStart.getLineNumber() - 1) {
addPrefixComments(node->id, comment);
isVisited = true; // Mark the comment as attached
isAttached = true; // Mark the comment as attached
}
break;

case TraversalType::Postorder:
if (commentEnd.getLineNumber() == nodeStart.getLineNumber()) {
addSuffixComments(node->id, comment);
isVisited = true;
isAttached = true;
}
break;

Expand Down
10 changes: 6 additions & 4 deletions backends/p4fmt/attach.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#ifndef BACKENDS_P4FMT_ATTACH_H_
#define BACKENDS_P4FMT_ATTACH_H_

#include <filesystem>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "backends/p4fmt/p4fmt.h"
#include "ir/ir.h"
#include "ir/visitor.h"
#include "lib/source_file.h"

Expand All @@ -22,7 +20,7 @@ class Attach : public Transform {
using CommentsMap = std::unordered_map<NodeId, Comments>;
enum class TraversalType { Preorder, Postorder };

explicit Attach(const std::unordered_map <const Util::Comment *, bool> &processedComments)
explicit Attach(const std::unordered_map<const Util::Comment *, bool> &processedComments)
: processedComments(processedComments){};
~Attach() override;

Expand All @@ -41,7 +39,11 @@ class Attach : public Transform {
const CommentsMap &getCommentsMap() const;

private:
// This map associates each comment with a boolean value that tracks whether the comment
// has been processed for attachment to IR nodes. Initially, all comments are set to 'false',
// indicating that they have not yet been processed.
std::unordered_map<const Util::Comment *, bool> processedComments;

CommentsMap commentsMap;
};

Expand Down
6 changes: 2 additions & 4 deletions backends/p4fmt/p4fmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ std::stringstream getFormattedOutput(std::filesystem::path inputFile) {
std::unordered_map<const Util::Comment *, bool> globalCommentsMap;

// Initialize the global comments map from the list of comments in the program.
// The map associates each comment with a boolean value that tracks whether the comment
// has been processed for attachment to IR nodes. Initially, all comments are set to 'false',
// indicating that they have not yet been processed.
if (!program->objects.empty()) {
const auto *firstNode = program->objects.front();
if (firstNode->srcInfo.isValid()) {
for (const auto *comment : firstNode->srcInfo.getAllFileComments()) {
globalCommentsMap[comment] = false; // Initialize all comments as not visited
globalCommentsMap[comment] =
false; // Initialize all comments as not yet attached to nodes
}
}
}
Expand Down

0 comments on commit b87606d

Please sign in to comment.