8#ifndef FRONTENDS_COMMON_RESOLVEREFERENCES_REFERENCEMAP_H_
9#define FRONTENDS_COMMON_RESOLVEREFERENCES_REFERENCEMAP_H_
11#include "absl/container/flat_hash_map.h"
12#include "absl/container/flat_hash_set.h"
13#include "frontends/common/programMap.h"
15#include "ir/visitor.h"
16#include "lib/cstring.h"
22 virtual cstring newName(std::string_view base) = 0;
30 absl::flat_hash_map<cstring, int, Util::Hash> usedNames;
31 void postorder(
const IR::Path *p)
override { usedName(p->name.name); }
32 void postorder(
const IR::Type_Declaration *t)
override { usedName(t->name.name); }
33 void postorder(
const IR::Declaration *d)
override { usedName(d->name.name); }
36 MinimalNameGenerator();
37 void usedName(
cstring name) { usedNames.emplace(name, 0); }
38 explicit MinimalNameGenerator(
const IR::Node *root) : MinimalNameGenerator() {
52 bool notNull =
false)
const = 0;
54 bool notNull =
false)
const = 0;
64 absl::flat_hash_map<const IR::Path *, const IR::IDeclaration *, Util::Hash> pathToDeclaration;
67 absl::flat_hash_set<const IR::IDeclaration *, Util::Hash> used;
70 absl::flat_hash_map<const IR::This *, const IR::IDeclaration *, Util::Hash> thisToDeclaration;
74 absl::flat_hash_map<cstring, int, Util::Hash> usedNames;
81 bool notNull =
false)
const override;
89 bool notNull =
false)
const override;
94 void dbprint(std::ostream &cout)
const override;
97 void setIsV1(
bool isv1) { this->isv1 = isv1; }
98 void setAnyOrder(
bool anyOrder) { this->isv1 = anyOrder; }
101 cstring
newName(std::string_view base)
override;
107 bool isV1()
const {
return isv1; }
Definition referenceMap.h:48
The Declaration interface, representing objects with names.
Definition declaration.h:17
cstring newName(std::string_view base) override
Generate a name from base that does not appear in usedNames.
Definition referenceMap.cpp:107
Definition referenceMap.h:20
const IR::IDeclaration * getDeclaration(const IR::Path *path, bool notNull=false) const override
Definition referenceMap.cpp:67
void setDeclaration(const IR::Path *path, const IR::IDeclaration *decl)
Sets declaration for path to decl.
Definition referenceMap.cpp:31
void clear()
Clear the reference map.
Definition referenceMap.cpp:20
void usedName(cstring name)
Indicate that name is used in the program.
Definition referenceMap.h:113
cstring newName(std::string_view base) override
Generate a name from base that fresh for the program.
Definition referenceMap.cpp:85
void setIsV1(bool isv1)
Set boolean indicating whether map is for a P4_14 program to isV1.
Definition referenceMap.h:97
bool isUsed(const IR::IDeclaration *decl) const
Definition referenceMap.h:110
bool isV1() const
Definition referenceMap.h:107
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13