P4C
The P4 Compiler
Loading...
Searching...
No Matches
hierarchicalNames.h
1/*
2 * Copyright 2017 VMware, Inc.
3 * SPDX-FileCopyrightText: 2017 VMware, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef FRONTENDS_P4_HIERARCHICALNAMES_H_
9#define FRONTENDS_P4_HIERARCHICALNAMES_H_
10
11#include "ir/ir.h"
12#include "ir/visitor.h"
13
14namespace P4 {
15
49class HierarchicalNames : public Modifier {
50 std::vector<cstring> stack;
51
52 cstring getName(const IR::IDeclaration *decl) const { return decl->getName(); }
53
54 public:
55 HierarchicalNames() {
56 setName("HierarchicalNames");
57 visitDagOnce = false;
58 }
59 bool preorder(IR::P4Parser *parser) override {
60 stack.push_back(getName(parser));
61 return true;
62 }
63 void postorder(IR::P4Parser *) override { stack.pop_back(); }
64
65 bool preorder(IR::P4Control *control) override {
66 stack.push_back(getName(control));
67 return true;
68 }
69 void postorder(IR::P4Control *) override { stack.pop_back(); }
70
71 bool preorder(IR::P4Table *table) override {
72 visit(table->annotations);
73 return false;
74 }
75
76 void postorder(IR::Annotation *annotation) override;
77 // Do not change name annotations on parameters
78 bool preorder(IR::Parameter *) override { return false; }
79};
80
81} // namespace P4
82
83#endif /* FRONTENDS_P4_HIERARCHICALNAMES_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:17
virtual ID getName() const =0
Definition visitor.h:385
Definition cstring.h:85
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13