P4C
The P4 Compiler
Loading...
Searching...
No Matches
namespace_context.h
1#ifndef BACKENDS_P4TOOLS_COMMON_LIB_NAMESPACE_CONTEXT_H_
2#define BACKENDS_P4TOOLS_COMMON_LIB_NAMESPACE_CONTEXT_H_
3
4#include <optional>
5#include <set>
6
7#include "ir/declaration.h"
8#include "ir/ir.h"
9#include "lib/cstring.h"
10
11namespace P4::P4Tools {
12
15 private:
16 const IR::INamespace *curNamespace;
17 const NamespaceContext *outer;
18
20 mutable std::optional<std::set<cstring>> usedNames;
21
22 NamespaceContext(const IR::INamespace *ns, const NamespaceContext *outer)
23 : curNamespace(ns), outer(outer) {}
24
28 const IR::IDeclaration *findNestedDecl(const IR::INestedNamespace *nestedNameSpace,
29 const IR::Path *path) const;
30
31 public:
33 static const NamespaceContext *Empty;
34
37 const NamespaceContext *push(const IR::INamespace *ns) const;
38
40 const NamespaceContext *pop() const;
41
43 const IR::IDeclaration *findDecl(const IR::Path *path) const;
44
46 const std::set<cstring> &getUsedNames() const;
47
50 cstring genName(cstring name, char sep) const;
51};
52
53} // namespace P4::P4Tools
54
55#endif /* BACKENDS_P4TOOLS_COMMON_LIB_NAMESPACE_CONTEXT_H_ */
The Declaration interface, representing objects with names.
Definition declaration.h:26
Represents a stack of namespaces.
Definition namespace_context.h:14
const IR::IDeclaration * findDecl(const IR::Path *path) const
Looks up a declaration in this context. A BUG occurs if the declaration cannot be found.
Definition namespace_context.cpp:58
const NamespaceContext * push(const IR::INamespace *ns) const
Definition namespace_context.cpp:14
const NamespaceContext * pop() const
Definition namespace_context.cpp:18
const std::set< cstring > & getUsedNames() const
Definition namespace_context.cpp:94
static const NamespaceContext * Empty
Represents the empty namespace context.
Definition namespace_context.h:33
Definition cstring.h:85
Definition common/compiler/compiler_result.cpp:3