P4C
The P4 Compiler
Loading...
Searching...
No Matches
hierarchicalNames.h
1/*
2Copyright 2017 VMware, 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_HIERARCHICALNAMES_H_
18#define FRONTENDS_P4_HIERARCHICALNAMES_H_
19
20#include "ir/ir.h"
21#include "ir/visitor.h"
22
23namespace P4 {
24
59 std::vector<cstring> stack;
60
61 public:
62 cstring getName(const IR::IDeclaration *decl);
63
65 setName("HierarchicalNames");
66 visitDagOnce = false;
67 }
68 const IR::Node *preorder(IR::P4Parser *parser) override {
69 stack.push_back(getName(parser));
70 return parser;
71 }
72 const IR::Node *postorder(IR::P4Parser *parser) override {
73 stack.pop_back();
74 return parser;
75 }
76
77 const IR::Node *preorder(IR::P4Control *control) override {
78 stack.push_back(getName(control));
79 return control;
80 }
81 const IR::Node *postorder(IR::P4Control *control) override {
82 stack.pop_back();
83 return control;
84 }
85
86 const IR::Node *preorder(IR::P4Table *table) override {
87 visit(table->annotations);
88 prune();
89 return table;
90 }
91
92 const IR::Node *postorder(IR::Annotation *annotation) override;
93 // Do not change name annotations on parameters
94 const IR::Node *preorder(IR::Parameter *parameter) override {
95 prune();
96 return parameter;
97 }
98};
99
100} // namespace P4
101
102#endif /* FRONTENDS_P4_HIERARCHICALNAMES_H_ */
Definition hierarchicalNames.h:58
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition node.h:95
Definition visitor.h:424
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24