aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-rib.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/resolve/rust-rib.h')
-rw-r--r--gcc/rust/resolve/rust-rib.h30
1 files changed, 24 insertions, 6 deletions
diff --git a/gcc/rust/resolve/rust-rib.h b/gcc/rust/resolve/rust-rib.h
index da777bb..732ad76 100644
--- a/gcc/rust/resolve/rust-rib.h
+++ b/gcc/rust/resolve/rust-rib.h
@@ -103,6 +103,24 @@ struct DuplicateNameError
class Rib
{
public:
+ // TODO: Rename the class? to what? Binding? Declaration?
+ // This is useful for items which are in namespaces where shadowing is not
+ // allowed, but which are still shadowable! for example, when you do a glob
+ // import, if a later import has the same name as an item imported in the glob
+ // import, that glob imported item will need to get shadowed
+ class Definition
+ {
+ public:
+ static Definition NonShadowable (NodeId id);
+ static Definition Shadowable (NodeId id);
+
+ NodeId id;
+ bool shadowable;
+
+ private:
+ Definition (NodeId id, bool shadowable);
+ };
+
enum class Kind
{
Normal,
@@ -131,15 +149,14 @@ public:
* Insert a new node in the rib
*
* @param name The name associated with the AST node
- * @param id Its NodeId
- * @param can_shadow If the newly inserted value can shadow an existing one
+ * @param def The `Definition` to insert
*
* @return `DuplicateNameError` if the node is already present in the rib. The
* `DuplicateNameError` class contains the NodeId of the existing
* node. Returns the new NodeId on success.
*/
- tl::expected<NodeId, DuplicateNameError> insert (std::string name, NodeId id,
- bool can_shadow = false);
+ tl::expected<NodeId, DuplicateNameError> insert (std::string name,
+ Definition def);
/**
* Access an inserted NodeId.
@@ -149,10 +166,11 @@ public:
tl::optional<NodeId> get (const std::string &name);
/* View all the values stored in the rib */
- const std::unordered_map<std::string, NodeId> &get_values () const;
+ const std::unordered_map<std::string, Definition> &get_values () const;
private:
- std::unordered_map<std::string, NodeId> values;
+ // TODO: Switch this to (NodeId, shadowable = false);
+ std::unordered_map<std::string, Definition> values;
};
} // namespace Resolver2_0