17#ifndef COMMON_RESOLVEREFERENCES_REFERENCEMAP_H_
18#define COMMON_RESOLVEREFERENCES_REFERENCEMAP_H_
20#include "absl/container/flat_hash_map.h"
21#include "absl/container/flat_hash_set.h"
22#include "frontends/common/programMap.h"
24#include "ir/visitor.h"
25#include "lib/cstring.h"
31 virtual cstring newName(std::string_view base) = 0;
39 absl::flat_hash_map<cstring, int, Util::Hash> usedNames;
40 void postorder(
const IR::Path *p)
override { usedName(p->name.name); }
41 void postorder(
const IR::Type_Declaration *t)
override { usedName(t->name.name); }
42 void postorder(
const IR::Declaration *d)
override { usedName(d->name.name); }
46 void usedName(
cstring name) { usedNames.emplace(name, 0); }
60 bool notNull =
false)
const = 0;
62 bool notNull =
false)
const = 0;
72 absl::flat_hash_map<const IR::Path *, const IR::IDeclaration *, Util::Hash> pathToDeclaration;
75 absl::flat_hash_set<const IR::IDeclaration *, Util::Hash> used;
78 absl::flat_hash_map<const IR::This *, const IR::IDeclaration *, Util::Hash> thisToDeclaration;
82 absl::flat_hash_map<cstring, int, Util::Hash> usedNames;
89 bool notNull =
false)
const override;
97 bool notNull =
false)
const override;
102 void dbprint(std::ostream &cout)
const override;
105 void setIsV1(
bool isv1) { this->isv1 = isv1; }
106 void setAnyOrder(
bool anyOrder) { this->isv1 = anyOrder; }
109 cstring
newName(std::string_view base)
override;
115 bool isV1()
const {
return isv1; }
Definition referenceMap.h:57
The Declaration interface, representing objects with names.
Definition declaration.h:26
Definition referenceMap.h:36
cstring newName(std::string_view base) override
Generate a name from base that does not appear in usedNames.
Definition referenceMap.cpp:118
Definition referenceMap.h:29
Definition programMap.h:28
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
const IR::IDeclaration * getDeclaration(const IR::Path *path, bool notNull=false) const override
Definition referenceMap.cpp:78
void setDeclaration(const IR::Path *path, const IR::IDeclaration *decl)
Sets declaration for path to decl.
Definition referenceMap.cpp:42
void clear()
Clear the reference map.
Definition referenceMap.cpp:31
void usedName(cstring name)
Indicate that name is used in the program.
Definition referenceMap.h:121
cstring newName(std::string_view base) override
Generate a name from base that fresh for the program.
Definition referenceMap.cpp:96
void setIsV1(bool isv1)
Set boolean indicating whether map is for a P4_14 program to isV1.
Definition referenceMap.h:105
bool isUsed(const IR::IDeclaration *decl) const
Definition referenceMap.h:118
bool isV1() const
Definition referenceMap.h:115
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24