diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-01-09 13:51:35 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-08-01 16:52:26 +0200 |
commit | 8c331e24575c0584be372a78bb0bbcca914d567c (patch) | |
tree | 18151cba46c42235bbb52555a6948c8d54d6e349 /gcc/rust/util/rust-hir-map.cc | |
parent | 06ce1b34fc0f1098ed45f25d52c05a6d8586c2c7 (diff) | |
download | gcc-8c331e24575c0584be372a78bb0bbcca914d567c.zip gcc-8c331e24575c0584be372a78bb0bbcca914d567c.tar.gz gcc-8c331e24575c0584be372a78bb0bbcca914d567c.tar.bz2 |
gccrs: Add name resolution for on globbing use decl
This is the first part of the code required to enable globbing on use
declarations.
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit):
Insert names into their namespace.
(TopLevel::visit): Insert ast module.
(TopLevel::handle_use_dec): Resolve use declaration.
(TopLevel::handle_use_glob): Use globbing visitor.
(flatten_list): Use globbing path vector.
(flatten_glob): Likewise.
(flatten): Likewise.
(prefix_subpaths): Add a function to prefix subpath.
* resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor):
Add globbing visitor.
* util/rust-hir-map.cc (Mappings::insert_ast_module): Add function to
insert module in module hashmap.
(Mappings::lookup_ast_module): Add function to retrieve ast module.
* util/rust-hir-map.h: Add module map and getter/setter prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/util/rust-hir-map.cc')
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index c62c111..05b26d6 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -17,9 +17,11 @@ // <http://www.gnu.org/licenses/>. #include "rust-hir-map.h" +#include "optional.h" #include "rust-ast-full.h" #include "rust-diagnostics.h" #include "rust-hir-full.h" +#include "rust-item.h" #include "rust-macro-builtins.h" #include "rust-mapping-common.h" #include "rust-attribute-values.h" @@ -1159,6 +1161,23 @@ Mappings::lookup_module_children (NodeId module) } void +Mappings::insert_ast_module (AST::Module *module) +{ + rust_assert (modules.find (module->get_node_id ()) == modules.end ()); + modules[module->get_node_id ()] = module; +} + +tl::optional<AST::Module *> +Mappings::lookup_ast_module (NodeId id) +{ + auto it = modules.find (id); + if (it == modules.end ()) + return tl::nullopt; + + return {it->second}; +} + +void Mappings::insert_module_child_item (NodeId module, Resolver::CanonicalPath child) { |