P4C
The P4 Compiler
Loading...
Searching...
No Matches
attach.h
1#ifndef BACKENDS_P4FMT_ATTACH_H_
2#define BACKENDS_P4FMT_ATTACH_H_
3
4#include "ir/visitor.h"
5#include "lib/source_file.h"
6
7namespace P4::P4Fmt {
8
9class Attach : public Inspector {
10 public:
11 using NodeId = int;
12 struct Comments {
13 std::vector<const Util::Comment *> prefix;
14 std::vector<const Util::Comment *> suffix;
15 };
16 using CommentsMap = std::unordered_map<NodeId, Comments>;
17 enum class TraversalType { Preorder, Postorder };
18
19 explicit Attach(std::unordered_map<const Util::Comment *, bool> &processedComments)
20 : processedComments(processedComments){};
21
22 void attachCommentsToNode(const IR::Node *, TraversalType);
23
24 bool preorder(const IR::Node *node) override;
25 void postorder(const IR::Node *node) override;
26
27 void addPrefixComments(NodeId, const Util::Comment *);
28 void addSuffixComments(NodeId, const Util::Comment *);
29 const CommentsMap &getCommentsMap() const;
30
31 private:
34 std::unordered_map<const Util::Comment *, bool> &processedComments;
35
36 CommentsMap commentsMap;
37};
38
39} // namespace P4::P4Fmt
40
41#endif /* BACKENDS_P4FMT_ATTACH_H_ */
Definition node.h:94
Definition visitor.h:400
Definition attach.h:9
Definition attach.h:12
Definition source_file.h:256