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>
23#include "frontends/common/programMap.h"
25#include "ir/visitor.h"
26#include "lib/cstring.h"
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.insert({name, 0}); }
59 virtual const IR::IDeclaration *getDeclaration(
const IR::Path *,
60 bool notNull =
false)
const = 0;
61 virtual const IR::IDeclaration *getDeclaration(
const IR::This *,
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;
92 void setDeclaration(
const IR::Path *path,
const IR::IDeclaration *decl);
97 bool notNull =
false)
const override;
100 void setDeclaration(
const IR::This *pointer,
const IR::IDeclaration *decl);
102 void dbprint(std::ostream &cout)
const override;
105 void setIsV1(
bool isv1) { this->isv1 = isv1; }
106 void setAnyOrder(
bool anyOrder) { this->isv1 = anyOrder; }
115 bool isV1()
const {
return isv1; }
118 bool isUsed(
const IR::IDeclaration *decl)
const {
return used.count(decl) > 0; }
Definition referenceMap.h:57
Definition referenceMap.h:36
cstring newName(cstring base) override
Generate a name from base that does not appear in usedNames.
Definition referenceMap.cpp:115
Definition referenceMap.h:30
Definition programMap.h:28
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
cstring newName(cstring base) override
Generate a name from base that fresh for the program.
Definition referenceMap.cpp:96
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
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
Definition applyOptionsPragmas.cpp:24