diff options
Diffstat (limited to 'gcc/rust/resolve/rust-early-name-resolver-2.0.cc')
-rw-r--r-- | gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 91 |
1 files changed, 12 insertions, 79 deletions
diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc index 41d0a07..ba73a54 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -83,7 +83,8 @@ Early::resolve_glob_import (TopLevel::ImportKind &&glob) // here, we insert the module's NodeId into the import_mappings and will look // up the module proper in `FinalizeImports` - import_mappings.insert ({std::move (glob), resolved->get_node_id ()}); + // The namespace does not matter here since we are dealing with a glob + import_mappings.insert ({std::move (glob), ImportData::Glob (*resolved)}); return true; } @@ -91,89 +92,21 @@ Early::resolve_glob_import (TopLevel::ImportKind &&glob) bool Early::resolve_simple_import (TopLevel::ImportKind &&import) { - // TODO: Fix documentation - the function has changed slightly - - const auto &path = import.to_resolve; - // auto locus = path.get_final_segment ().get_locus (); - // auto declared_name = path.get_final_segment ().as_string (); - - // In that function, we only need to declare a new definition - the use path. - // the resolution needs to happpen in the EarlyNameResolver. So the - // definitions we'll add will be the path's NodeId - that makes sense, as we - // need one definition per path declared in a Use tree. so all good. - // alright, now in what namespace do we declare them? all of them? do we only - // declare them in the EarlyNameResolver? this is dodgy - - // in what namespace do we perform path resolution? All of them? see which one - // matches? Error out on ambiguities? - // so, apparently, for each one that matches, add it to the proper namespace - // :( - - return ctx.values.resolve_path (path.get_segments ()) - .or_else ([&] () { return ctx.types.resolve_path (path.get_segments ()); }) - .or_else ([&] () { return ctx.macros.resolve_path (path.get_segments ()); }) - .map ([&] (Rib::Definition def) { - import_mappings.insert ({std::move (import), def.get_node_id ()}); + return ctx.resolve_path (import.to_resolve) + .map ([&] (std::pair<Rib::Definition, Namespace> def_ns) { + import_mappings.insert ( + {std::move (import), ImportData::Simple (def_ns)}); }) .has_value (); - - // switch (ns) - // { - // case Namespace::Values: - // resolved = ctx.values.resolve_path (path.get_segments ()); - // break; - // case Namespace::Types: - // resolved = ctx.types.resolve_path (path.get_segments ()); - // break; - // case Namespace::Macros: - // resolved = ctx.macros.resolve_path (path.get_segments ()); - // break; - // case Namespace::Labels: - // // TODO: Is that okay? - // rust_unreachable (); - // } - - // FIXME: Ugly - // (void) resolved.map ([this, &found, path, import] (Rib::Definition - // def) { - // found = true; - - // import_mappings.insert ({std::move (import), def.get_node_id - // ()}); - - // // what do we do with the id? - // // insert_or_error_out (declared_name, locus, def.get_node_id (), - // // ns); auto result = node_forwarding.find (def.get_node_id ()); - // if - // // (result != node_forwarding.cend () - // // && result->second != path.get_node_id ()) - // // rust_error_at (path.get_locus (), "%qs defined multiple - // times", - // // declared_name.c_str ()); - // // else // No previous thing has inserted this into our scope - // // node_forwarding.insert ({def.get_node_id (), - // path.get_node_id - // // ()}); - - // return def.get_node_id (); - // }); - // }; - - // resolve_and_insert (path); - - // return found; } bool Early::resolve_rebind_import (TopLevel::ImportKind &&rebind_import) { - auto &path = rebind_import.to_resolve; - - return ctx.values.resolve_path (path.get_segments ()) - .or_else ([&] () { return ctx.types.resolve_path (path.get_segments ()); }) - .or_else ([&] () { return ctx.macros.resolve_path (path.get_segments ()); }) - .map ([&] (Rib::Definition def) { - import_mappings.insert ({std::move (rebind_import), def.get_node_id ()}); + return ctx.resolve_path (rebind_import.to_resolve) + .map ([&] (std::pair<Rib::Definition, Namespace> def_ns) { + import_mappings.insert ( + {std::move (rebind_import), ImportData::Rebind (def_ns)}); }) .has_value (); } @@ -183,8 +116,8 @@ Early::build_import_mapping (TopLevel::ImportKind &&import) { auto found = false; - // We create a copy of the path in case of errors, since the `import` will be - // moved into the newly created import mappings + // We create a copy of the path in case of errors, since the `import` will + // be moved into the newly created import mappings auto path = import.to_resolve; switch (import.kind) |