diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-07-21 18:22:43 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:00:26 +0100 |
commit | 5a0e099e892d575af167d6a0a7e9ae5f26f439d8 (patch) | |
tree | 50f1657f3f4c71e9c63d769be27bb5df388d9d2f /gcc | |
parent | 7c10950f544f7972317c848bec284af63981943d (diff) | |
download | gcc-5a0e099e892d575af167d6a0a7e9ae5f26f439d8.zip gcc-5a0e099e892d575af167d6a0a7e9ae5f26f439d8.tar.gz gcc-5a0e099e892d575af167d6a0a7e9ae5f26f439d8.tar.bz2 |
gccrs: rib2.0: Add shadowing
gcc/rust/ChangeLog:
* resolve/rust-rib.h: Add shadowing parameter. Make kind field public.
* resolve/rust-rib.cc (Rib::insert): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-rib.cc | 8 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-rib.h | 7 |
2 files changed, 9 insertions, 6 deletions
diff --git a/gcc/rust/resolve/rust-rib.cc b/gcc/rust/resolve/rust-rib.cc index 2cc9f3e..21fbe2c 100644 --- a/gcc/rust/resolve/rust-rib.cc +++ b/gcc/rust/resolve/rust-rib.cc @@ -36,13 +36,15 @@ Rib::Rib (Kind kind, std::unordered_map<std::string, NodeId> values) {} tl::expected<NodeId, DuplicateNameError> -Rib::insert (std::string name, NodeId id) +Rib::insert (std::string name, NodeId id, bool can_shadow) { auto res = values.insert ({name, id}); auto inserted_id = res.first->second; + auto existed = !res.second; - // if we couldn't insert, the element already exists - exit with an error - if (!res.second) + // if we couldn't insert, the element already exists - exit with an error, + // unless shadowing is allowed + if (existed && !can_shadow) return tl::make_unexpected (DuplicateNameError (name, inserted_id)); // return the NodeId diff --git a/gcc/rust/resolve/rust-rib.h b/gcc/rust/resolve/rust-rib.h index ea69cc7..37bd90f 100644 --- a/gcc/rust/resolve/rust-rib.h +++ b/gcc/rust/resolve/rust-rib.h @@ -93,7 +93,7 @@ public: ForwardTypeParamBan, /* Const generic, as in the following example: fn foo<T, const X: T>() {} */ ConstParamType, - }; + } kind; Rib (Kind kind); Rib (Kind kind, std::string identifier, NodeId id); @@ -107,12 +107,14 @@ public: * * @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 * * @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); + tl::expected<NodeId, DuplicateNameError> insert (std::string name, NodeId id, + bool can_shadow = false); /** * Access an inserted NodeId. @@ -125,7 +127,6 @@ public: const std::unordered_map<std::string, NodeId> &get_values () const; private: - Kind kind; std::unordered_map<std::string, NodeId> values; }; |