]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add call to globbing visitor
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 15 Jan 2024 12:41:01 +0000 (13:41 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 14:52:26 +0000 (16:52 +0200)
Globbing visitor did not visit subitems.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add a check
for missing item.
* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go):
Add a new function in the visitor to dispatch the visitor to items in
the given module.
(TopLevel::handle_use_glob): Change call to visitor to use the pointer.
* resolve/rust-toplevel-name-resolver-2.0.h: Add prototype for new
member function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/resolve/rust-late-name-resolver-2.0.cc
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h

index 68eb88a1e4c978ebbc95355c177213819b6fbbe3..d8bd9ac524f3ed41d607497b5e5dac2dc0e7408b 100644 (file)
@@ -197,6 +197,8 @@ Late::visit (AST::PathInExpression &expr)
   // do we emit it in `get<Namespace::Labels>`?
 
   auto value = ctx.values.resolve_path (expr.get_segments ());
+  if (!value.has_value ())
+    rust_unreachable (); // Should have been resolved earlier
 
   ctx.map_usage (Usage (expr.get_node_id ()), Definition (*value));
 }
index 3122d41412f7ce1d90855f7a9543efad1b0a6e92..501204174f2207a49ecfaa410f90027ba475f625 100644 (file)
 namespace Rust {
 namespace Resolver2_0 {
 
+void
+GlobbingVisitor::go (AST::Module *module)
+{
+  for (auto &i : module->get_items ())
+    visit (i);
+}
+
 void
 GlobbingVisitor::visit (AST::Module &module)
 {
@@ -399,7 +406,7 @@ TopLevel::handle_use_glob (AST::SimplePath glob)
     return false;
 
   GlobbingVisitor gvisitor (ctx);
-  gvisitor.visit (*result.value ());
+  gvisitor.go (result.value ());
 
   return true;
 }
index 31535a9b22e0f57d5ccb8a497b6b1a7cb05de2e0..f5e224fa04996178d89a52c6dd32618357cbf381 100644 (file)
@@ -33,6 +33,7 @@ class GlobbingVisitor : public AST::DefaultASTVisitor
 public:
   GlobbingVisitor (NameResolutionContext &ctx) : ctx (ctx) {}
 
+  void go (AST::Module *module);
   void visit (AST::Module &module) override;
   void visit (AST::MacroRulesDefinition &macro) override;
   void visit (AST::Function &function) override;