]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Change lookup_hir_smt's return type with optional
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 3 May 2024 18:17:16 +0000 (20:17 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:25 +0000 (16:35 +0100)
Wrap the function's return type within an optional in order to
differentiate missing values from null pointers.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::insert_hir_stmt): Change call site
to accomodate new return type.
(Mappings::lookup_hir_stmt): Change the function's return type.
(Mappings::resolve_nodeid_to_stmt): Adapt call site to new return type.
* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h

index ae11e67a57b161e78ca7bc2b48705106bc2bbec0..025b3121b2737acf9aca53c951de15319293c965 100644 (file)
@@ -612,18 +612,18 @@ void
 Mappings::insert_hir_stmt (HIR::Stmt *stmt)
 {
   auto id = stmt->get_mappings ().get_hirid ();
-  rust_assert (lookup_hir_stmt (id) == nullptr);
+  rust_assert (!lookup_hir_stmt (id));
 
   hirStmtMappings[id] = stmt;
   insert_node_to_hir (stmt->get_mappings ().get_nodeid (), id);
 }
 
-HIR::Stmt *
+tl::optional<HIR::Stmt *>
 Mappings::lookup_hir_stmt (HirId id)
 {
   auto it = hirStmtMappings.find (id);
   if (it == hirStmtMappings.end ())
-    return nullptr;
+    return tl::nullopt;
 
   return it->second;
 }
@@ -796,7 +796,7 @@ Mappings::resolve_nodeid_to_stmt (NodeId id)
     return tl::nullopt;
 
   HirId resolved = it->second;
-  return {lookup_hir_stmt (resolved)};
+  return lookup_hir_stmt (resolved);
 }
 
 void
index e4f47852ed98ee62e0c0c6cd064a78f1351d615f..f6db83d6e117e3c46c0c234c376fe52b00929844 100644 (file)
@@ -158,7 +158,7 @@ public:
   tl::optional<HIR::Type *> lookup_hir_type (HirId id);
 
   void insert_hir_stmt (HIR::Stmt *stmt);
-  HIR::Stmt *lookup_hir_stmt (HirId id);
+  tl::optional<HIR::Stmt *> lookup_hir_stmt (HirId id);
 
   void insert_hir_param (HIR::FunctionParam *type);
   HIR::FunctionParam *lookup_hir_param (HirId id);