return;
}
- ctx.map_usage (expr.get_node_id (), *resolved);
+ ctx.map_usage (Usage (expr.get_node_id ()), Definition (*resolved));
// in the old resolver, resolutions are kept in the resolver, not the mappings
// :/ how do we deal with that?
auto resolved = ctx.types.get (type.get_segments ().back ()->as_string ());
- ctx.map_usage (type.get_node_id (), *resolved);
+ ctx.map_usage (Usage (type.get_node_id ()), Definition (*resolved));
}
} // namespace Resolver2_0
}
void
-NameResolutionContext::map_usage (NodeId usage, NodeId definition)
+NameResolutionContext::map_usage (Usage usage, Definition definition)
{
auto inserted = resolved_nodes.emplace (usage, definition).second;
tl::optional<NodeId>
NameResolutionContext::lookup (NodeId usage)
{
- auto it = resolved_nodes.find (usage);
+ auto it = resolved_nodes.find (Usage (usage));
if (it == resolved_nodes.end ())
return tl::nullopt;
- return it->second;
+ return it->second.id;
}
void
correct
*/
+// FIXME: Documentation
+class Usage
+{
+public:
+ explicit Usage (NodeId id) : id (id) {}
+
+ // TODO: move to name-resolution-ctx.cc
+ // storing it as a key in a map
+ bool operator< (const Usage other) const { return other.id < id; }
+
+ NodeId id;
+};
+
+// FIXME: Documentation
+class Definition
+{
+public:
+ explicit Definition (NodeId id) : id (id) {}
+
+ NodeId id;
+};
+
// Now our resolver, which keeps track of all the `ForeverStack`s we could want
class NameResolutionContext
{
// TODO: Rename
// TODO: Use newtype pattern for Usage and Definition
- void map_usage (NodeId usage, NodeId definition);
+ void map_usage (Usage usage, Definition definition);
+
tl::optional<NodeId> lookup (NodeId usage);
private:
/* Map of "usage" nodes which have been resolved to a "definition" node */
- std::map<NodeId, NodeId> resolved_nodes;
+ std::map<Usage, Definition> resolved_nodes;
};
} // namespace Resolver2_0