diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-11-25 15:05:32 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:33:10 +0100 |
commit | e0315c138337ddfac4dc41d1e26d0c8dd7564e0b (patch) | |
tree | b89827956a946595575b0e017dcab8aba63b6860 /gcc | |
parent | 3fa779425cc550afb6e18671c45dba0e21d1d273 (diff) | |
download | gcc-e0315c138337ddfac4dc41d1e26d0c8dd7564e0b.zip gcc-e0315c138337ddfac4dc41d1e26d0c8dd7564e0b.tar.gz gcc-e0315c138337ddfac4dc41d1e26d0c8dd7564e0b.tar.bz2 |
gccrs: lang-items: Store NodeId mappings for lang items
gcc/rust/ChangeLog:
* util/rust-hir-map.h: Keep a NodeId mappings for lang items.
* util/rust-hir-map.cc (Mappings::insert_lang_item_node): New function.
(Mappings::lookup_lang_item_node): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 22 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 8 |
2 files changed, 30 insertions, 0 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 5f77f570..f11a779 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1241,6 +1241,9 @@ Mappings::lookup_builtin_marker () return builtinMarker; } +// FIXME: Before merging: Should we remove the `locus` parameter here? since +// lang items are looked up mostly for code generation, it doesn't make sense to +// error out on the locus of the node trying to access an inexistant lang item DefId Mappings::get_lang_item (LangItem::Kind item_type, location_t locus) { @@ -1277,5 +1280,24 @@ Mappings::lookup_lang_item (LangItem::Kind item_type) return it->second; } +void +Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id) +{ + auto it = lang_item_nodes.find (item_type); + rust_assert (it == lang_item_nodes.end ()); + + lang_item_nodes.insert ({item_type, node_id}); +} + +tl::optional<NodeId &> +Mappings::lookup_lang_item_node (LangItem::Kind item_type) +{ + auto it = lang_item_nodes.find (item_type); + if (it == lang_item_nodes.end ()) + return tl::nullopt; + + return it->second; +} + } // namespace Analysis } // namespace Rust diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 14a0514..aba51be 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -259,6 +259,9 @@ public: void insert_lang_item (LangItem::Kind item_type, DefId id); tl::optional<DefId &> lookup_lang_item (LangItem::Kind item_type); + void insert_lang_item_node (LangItem::Kind item_type, NodeId node_id); + tl::optional<NodeId &> lookup_lang_item_node (LangItem::Kind item_type); + // This will fatal_error when this lang item does not exist DefId get_lang_item (LangItem::Kind item_type, location_t locus); @@ -375,7 +378,12 @@ private: std::map<HirId, HIR::GenericParam *> hirGenericParamMappings; std::map<HirId, HIR::Trait *> hirTraitItemsToTraitMappings; std::map<HirId, HIR::Pattern *> hirPatternMappings; + + // We need to have two maps here, as lang-items need to be used for both AST + // passes and HIR passes. Thus those two maps are created at different times. std::map<LangItem::Kind, DefId> lang_item_mappings; + std::map<LangItem::Kind, NodeId> lang_item_nodes; + std::map<NodeId, Resolver::CanonicalPath> paths; std::map<NodeId, location_t> locations; std::map<NodeId, HirId> nodeIdToHirMappings; |