P4C
The P4 Compiler
Loading...
Searching...
No Matches
duplicateActionControlPlaneNameCheck.h
1/*
2 * Copyright 2024 Cisco Systems, Inc.
3 * SPDX-FileCopyrightText: 2024 Cisco Systems, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_
9#define FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_
10
11#include <vector>
12
13#include "ir/ir.h"
14#include "ir/visitor.h"
15
16namespace P4 {
17
34class DuplicateActionControlPlaneNameCheck : public Transform {
35 std::vector<cstring> stack;
37 absl::flat_hash_map<cstring, const IR::Node *> actions;
38
39 public:
40 cstring getName(const IR::IDeclaration *decl);
41
42 DuplicateActionControlPlaneNameCheck() {
43 setName("DuplicateActionControlPlaneNameCheck");
44 visitDagOnce = false;
45 }
46 const IR::Node *preorder(IR::P4Parser *parser) override {
47 // There cannot be any action definitions inside a parser, so
48 // do not traverse through its nodes.
49 prune();
50 return parser;
51 }
52
53 const IR::Node *preorder(IR::P4Control *control) override {
54 stack.push_back(getName(control));
55 return control;
56 }
57 const IR::Node *postorder(IR::P4Control *control) override {
58 stack.pop_back();
59 return control;
60 }
61
62 const IR::Node *preorder(IR::P4Table *table) override {
63 // There cannot be any action definitions inside a table, so
64 // do not traverse through its nodes.
65 prune();
66 return table;
67 }
68
69 void checkForDuplicateName(cstring name, const IR::Node *node);
70
71 const IR::Node *postorder(IR::P4Action *action) override;
72};
73
74} // namespace P4
75
76#endif /* FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:17
Definition node.h:44
Definition visitor.h:433
Definition cstring.h:76
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13