Skip to content

Commit

Permalink
Change lookup_ast_item's return type
Browse files Browse the repository at this point in the history
Wrap the function's return type within an optional.

gcc/rust/ChangeLog:

	* metadata/rust-export-metadata.cc (ExportContext::emit_trait):
	Adapt call site to the new return type.
	(ExportContext::emit_function): Likewise.
	(ExportContext::emit_macro): Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_ast_item): Change the
	function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
  • Loading branch information
P-E-P committed May 17, 2024
1 parent f13cb85 commit 06bc336
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
15 changes: 5 additions & 10 deletions gcc/rust/metadata/rust-export-metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ void
ExportContext::emit_trait (const HIR::Trait &trait)
{
// lookup the AST node for this
AST::Item *item = nullptr;
bool ok
= mappings.lookup_ast_item (trait.get_mappings ().get_nodeid (), &item);
rust_assert (ok);
AST::Item *item
= mappings.lookup_ast_item (trait.get_mappings ().get_nodeid ()).value ();

std::stringstream oss;
AST::Dump dumper (oss);
Expand All @@ -72,9 +70,8 @@ void
ExportContext::emit_function (const HIR::Function &fn)
{
// lookup the AST node for this
AST::Item *item = nullptr;
bool ok = mappings.lookup_ast_item (fn.get_mappings ().get_nodeid (), &item);
rust_assert (ok);
AST::Item *item
= mappings.lookup_ast_item (fn.get_mappings ().get_nodeid ()).value ();

// is this a CFG macro or not
if (item->is_marked_for_strip ())
Expand Down Expand Up @@ -119,9 +116,7 @@ ExportContext::emit_macro (NodeId macro)
std::stringstream oss;
AST::Dump dumper (oss);

AST::Item *item;
auto ok = mappings.lookup_ast_item (macro, &item);
rust_assert (ok);
AST::Item *item = mappings.lookup_ast_item (macro).value ();

dumper.go (*item);

Expand Down
9 changes: 4 additions & 5 deletions gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1225,15 +1225,14 @@ Mappings::insert_ast_item (AST::Item *item)
ast_item_mappings[item->get_node_id ()] = item;
}

bool
Mappings::lookup_ast_item (NodeId id, AST::Item **result)
tl::optional<AST::Item *>
Mappings::lookup_ast_item (NodeId id)
{
auto it = ast_item_mappings.find (id);
if (it == ast_item_mappings.end ())
return false;
return tl::nullopt;

*result = it->second;
return true;
return it->second;
}

HIR::ImplBlock *
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/util/rust-hir-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class Mappings
bool node_is_module (NodeId query);

void insert_ast_item (AST::Item *item);
bool lookup_ast_item (NodeId id, AST::Item **result);
tl::optional<AST::Item *> lookup_ast_item (NodeId id);

HIR::ImplBlock *lookup_builtin_marker ();

Expand Down

0 comments on commit 06bc336

Please sign in to comment.