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 Inspector {
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 bool preorder(const IR::P4Parser *) override {
47 // There cannot be any action definitions inside a parser, so
48 // do not traverse through its nodes.
49 return false;
50 }
51
52 bool preorder(const IR::P4Control *control) override {
53 stack.push_back(getName(control));
54 return true;
55 }
56 void postorder(const IR::P4Control *) override { stack.pop_back(); }
57
58 bool preorder(const IR::P4Table *) override {
59 // There cannot be any action definitions inside a table, so
60 // do not traverse through its nodes.
61 return false;
62 }
63
64 void checkForDuplicateName(cstring name, const IR::Node *node);
65
66 void postorder(const IR::P4Action *action) override;
67};
68
69} // namespace P4
70
71#endif /* FRONTENDS_P4_DUPLICATEACTIONCONTROLPLANENAMECHECK_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:17
Definition node.h:53
Definition visitor.h:418
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13