17#ifndef COMMON_RESOLVEREFERENCES_RESOLVEREFERENCES_H_ 
   18#define COMMON_RESOLVEREFERENCES_RESOLVEREFERENCES_H_ 
   20#include "absl/container/flat_hash_map.h" 
   22#include "lib/cstring.h" 
   23#include "lib/iterator_range.h" 
   24#include "referenceMap.h" 
   36    const std::vector<const IR::IDeclaration *> &memoizeDeclarations(
 
   37        const IR::INamespace *ns) 
const;
 
   41    std::unordered_multimap<cstring, const IR::IDeclaration *> &memoizeDeclsByName(
 
   42        const IR::INamespace *ns) 
const;
 
   44    mutable absl::flat_hash_map<const IR::INamespace *, std::vector<const IR::IDeclaration *>,
 
   47    mutable absl::flat_hash_map<
const IR::INamespace *,
 
   48                                std::unordered_multimap<cstring, const IR::IDeclaration *>,
 
   55    std::vector<const IR::IDeclaration *> lookup(
const IR::INamespace *ns, 
const IR::ID &name,
 
   61    std::vector<const IR::IDeclaration *> lookupMatchKind(
const IR::ID &name) 
const;
 
   67    bool anyOrder = 
false;
 
   81                                          const IR::INamespace * = 
nullptr) 
const;
 
   88    const IR::Type *
resolveType(
const IR::Type *type) 
const;
 
   90    const IR::IDeclaration *getDeclaration(
const IR::Path *path, 
bool notNull = 
false) 
const;
 
   91    const IR::IDeclaration *getDeclaration(
const IR::This *, 
bool notNull = 
false) 
const;
 
   95        auto nsIt = namespaceDecls.find(ns);
 
   96        const auto &decls = nsIt != namespaceDecls.end() ? nsIt->second : memoizeDeclarations(ns);
 
 
  102        auto nsIt = namespaceDeclNames.find(ns);
 
  104            nsIt != namespaceDeclNames.end() ? nsIt->second : memoizeDeclsByName(ns);
 
  106        auto decls = Values(namesToDecls.equal_range(name));
 
 
 
  128    const IR::IDeclaration *resolvePath(
const IR::Path *path, 
bool isType) 
const override;
 
  134    void end_apply(
const IR::Node *node) 
override;
 
  136    bool preorder(
const IR::Type_Name *type) 
override;
 
  137    bool preorder(
const IR::PathExpression *path) 
override;
 
  138    bool preorder(
const IR::KeyElement *path) 
override;
 
  139    bool preorder(
const IR::This *pointer) 
override;
 
  140    bool preorder(
const IR::Declaration_Instance *decl) 
override;
 
  142    bool preorder(
const IR::P4Program *t) 
override;
 
  143    void postorder(
const IR::P4Program *t) 
override;
 
  144    bool preorder(
const IR::P4Control *t) 
override;
 
  145    bool preorder(
const IR::P4Parser *t) 
override;
 
  146    bool preorder(
const IR::P4Action *t) 
override;
 
  147    bool preorder(
const IR::Function *t) 
override;
 
  148    bool preorder(
const IR::TableProperties *t) 
override;
 
  149    bool preorder(
const IR::Type_Method *t) 
override;
 
  150    bool preorder(
const IR::ParserState *t) 
override;
 
  151    bool preorder(
const IR::Type_Extern *t) 
override;
 
  152    bool preorder(
const IR::Type_ArchBlock *t) 
override;
 
  153    void postorder(
const IR::Type_ArchBlock *t) 
override;
 
  154    bool preorder(
const IR::Type_StructLike *t) 
override;
 
  155    bool preorder(
const IR::BlockStatement *t) 
override;
 
  157    bool preorder(
const IR::P4Table *table) 
override;
 
  158    bool preorder(
const IR::Declaration *d)
 override {
 
  159        refMap->
usedName(d->getName().name);
 
  162    bool preorder(
const IR::Type_Declaration *d)
 override {
 
  163        refMap->
usedName(d->getName().name);
 
  167    void checkShadowing(
const IR::INamespace *ns) 
const;
 
 
The Declaration interface, representing objects with names.
Definition declaration.h:26
 
Definition referenceMap.h:57
 
Class used to encode maps from paths to declarations.
Definition referenceMap.h:66
 
void usedName(cstring name)
Indicate that name is used in the program.
Definition referenceMap.h:121
 
Visitor mixin for looking up names in enclosing scopes from the Visitor::Context.
Definition resolveReferences.h:32
 
std::vector< const IR::IDeclaration * > resolve(const IR::ID &name, ResolutionType type) const
Resolve references for name, restricted to type declarations.
Definition resolveReferences.cpp:48
 
auto getDeclsByName(const IR::INamespace *ns, cstring name) const
Returns the set of decls with the given name that exist in the given namespace.
Definition resolveReferences.h:101
 
auto getDeclarations(const IR::INamespace *ns) const
Returns the set of decls that exist in the given namespace.
Definition resolveReferences.h:94
 
virtual const IR::IDeclaration * resolvePath(const IR::Path *path, bool isType) const
Definition resolveReferences.cpp:310
 
const IR::Vector< IR::Argument > * methodArguments(cstring name) const
We are resolving a method call. Find the arguments from the context.
Definition resolveReferences.cpp:183
 
const IR::Type * resolveType(const IR::Type *type) const
Resolve a refrence to a type type.
Definition resolveReferences.cpp:297
 
const IR::IDeclaration * resolveUnique(const IR::ID &name, ResolutionType type, const IR::INamespace *=nullptr) const
Resolve reference for name, restricted to type declarations, and expect one result.
Definition resolveReferences.cpp:223
 
Definition resolveReferences.h:118
 
Definition iterator_range.h:44
 
Definition applyOptionsPragmas.cpp:24
 
ResolutionType
Helper class to indicate types of nodes that may be returned during resolution.
Definition resolveReferences.h:29