aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-rib.h
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-08-28 16:40:12 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2024-08-01 16:52:25 +0200
commitc47cae71d32fa580572a5284e677590ed7cd9509 (patch)
tree3ff564f59c6148fe433cc49a324f57c53d129c37 /gcc/rust/resolve/rust-rib.h
parent53c74beb3a15a477f4fef770fe6abccbdb124fb7 (diff)
downloadgcc-c47cae71d32fa580572a5284e677590ed7cd9509.zip
gcc-c47cae71d32fa580572a5284e677590ed7cd9509.tar.gz
gcc-c47cae71d32fa580572a5284e677590ed7cd9509.tar.bz2
gccrs: late: Setup builtin types properly, change Rib API
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Start using Rib::Definition for shadowable information. * resolve/rust-late-name-resolver-2.0.cc (next_node_id): New. (next_hir_id): New. (Late::setup_builtin_types): Improve builtin type setup. * resolve/rust-rib.cc (Rib::Definition::Definition): New constructor. (Rib::Definition::Shadowable): Likewise. (Rib::Definition::NonShadowable): Likewise. (Rib::Rib): Fix general constructor. (Rib::insert): Use Definition class. (Rib::get): Likewise. * resolve/rust-rib.h: New Definition class, new prototypes.
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