P4C
The P4 Compiler
Loading...
Searching...
No Matches
duplicateActionControlPlaneNameCheck.h
1/*
2Copyright 2024 Cisco Systems, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_
18#define FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_
19
20#include <vector>
21
22#include "ir/ir.h"
23#include "ir/visitor.h"
24
25namespace P4 {
26
43class DuplicateActionControlPlaneNameCheck : public Transform {
44 std::vector<cstring> stack;
46 absl::flat_hash_map<cstring, const IR::Node *> actions;
47
48 public:
49 cstring getName(const IR::IDeclaration *decl);
50
51 DuplicateActionControlPlaneNameCheck() {
52 setName("DuplicateActionControlPlaneNameCheck");
53 visitDagOnce = false;
54 }
55 const IR::Node *preorder(IR::P4Parser *parser) override {
56 // There cannot be any action definitions inside a parser, so
57 // do not traverse through its nodes.
58 prune();
59 return parser;
60 }
61
62 const IR::Node *preorder(IR::P4Control *control) override {
63 stack.push_back(getName(control));
64 return control;
65 }
66 const IR::Node *postorder(IR::P4Control *control) override {
67 stack.pop_back();
68 return control;
69 }
70
71 const IR::Node *preorder(IR::P4Table *table) override {
72 // There cannot be any action definitions inside a table, so
73 // do not traverse through its nodes.
74 prune();
75 return table;
76 }
77
78 void checkForDuplicateName(cstring name, const IR::Node *node);
79
80 const IR::Node *postorder(IR::P4Action *action) override;
81};
82
83} // namespace P4
84
85#endif /* FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition node.h:94
Definition visitor.h:437
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24