diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-07-04 16:56:46 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-07-08 12:46:30 +0100 |
commit | fb27d1452b31d5485b1fce692f14279472cf0baf (patch) | |
tree | 362332a85d7d4e27ed53f91a2f8293817fafc856 /gcc/rust/resolve/rust-name-resolver.cc | |
parent | 31887c00fbdc7d607cf79b1042cb84d2c6db17e2 (diff) | |
download | gcc-fb27d1452b31d5485b1fce692f14279472cf0baf.zip gcc-fb27d1452b31d5485b1fce692f14279472cf0baf.tar.gz gcc-fb27d1452b31d5485b1fce692f14279472cf0baf.tar.bz2 |
Refactor mappings class and HIR lowering to be consistent
In order to support loading extern crates and use statements we needed to
clarify the usage of NodeId and HirId within gccrs. Each of these id's were
nested behind the CrateNum but the type resolution, linting and code-gen
passes do not support that level of nesting.
In order to get metadata exports and imports working lets focus on gccrs
supporting compilation of a single crate at a time. This means the crate
prefix only matters for imports and limits the complexity here. Down the
line there might be a way to leverage DefId's for all Path resolution
which could solve this problem but significant refactoring would be
required here to do this properly and its not nessecary for a basic working
rust compiler.
Diffstat (limited to 'gcc/rust/resolve/rust-name-resolver.cc')
-rw-r--r-- | gcc/rust/resolve/rust-name-resolver.cc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/gcc/rust/resolve/rust-name-resolver.cc b/gcc/rust/resolve/rust-name-resolver.cc index a788914..fb70874 100644 --- a/gcc/rust/resolve/rust-name-resolver.cc +++ b/gcc/rust/resolve/rust-name-resolver.cc @@ -34,11 +34,10 @@ _R.push_back (builtin_type); \ tyctx->insert_builtin (_TY->get_ref (), builtin_type->get_node_id (), \ _TY); \ - mappings->insert_node_to_hir (mappings->get_current_crate (), \ - builtin_type->get_node_id (), \ + mappings->insert_node_to_hir (builtin_type->get_node_id (), \ _TY->get_ref ()); \ mappings->insert_canonical_path ( \ - mappings->get_current_crate (), builtin_type->get_node_id (), \ + builtin_type->get_node_id (), \ CanonicalPath::new_seg (builtin_type->get_node_id (), _X)); \ } \ while (0) @@ -129,6 +128,24 @@ Rib::decl_was_declared_here (NodeId def) const return false; } +void +Rib::debug () const +{ + fprintf (stderr, "%s\n", debug_str ().c_str ()); +} + +std::string +Rib::debug_str () const +{ + std::string buffer; + for (const auto &it : path_mappings) + { + buffer += it.first.get () + "=" + std::to_string (it.second); + buffer += ","; + } + return "{" + buffer + "}"; +} + Scope::Scope (CrateNum crate_num) : crate_num (crate_num) {} void |