From a3e7bde5b0ab530b10483818d52504f7942ecdd5 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Wed, 15 Mar 2023 17:30:25 +0100 Subject: mappings: Keep exported macro IDs gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add new visitor for AST::MacroRulesDefinition. * hir/rust-ast-lower-item.h: Declare above mentioned visitor. * metadata/rust-export-metadata.cc (ExportContext::emit_macro): New function. * metadata/rust-export-metadata.h: Declare it. (PublicInterface::gather_export_data): Go through each exported macro. * util/rust-hir-map.cc (Mappings::insert_exported_macro): New function. (Mappings::get_exported_macros): New function. * util/rust-hir-map.h: Add new mappings for exported macros. --- gcc/rust/hir/rust-ast-lower-item.cc | 8 ++++++++ gcc/rust/hir/rust-ast-lower-item.h | 1 + 2 files changed, 9 insertions(+) (limited to 'gcc/rust/hir') diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index a166b91..9e580a6 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -705,6 +705,14 @@ ASTLoweringItem::visit (AST::ExternBlock &extern_block) translated = lower_extern_block (extern_block); } +void +ASTLoweringItem::visit (AST::MacroRulesDefinition &def) +{ + for (const auto &attr : def.get_outer_attrs ()) + if (attr.get_path ().as_string () == "macro_export") + mappings->insert_exported_macro (def); +} + HIR::SimplePath ASTLoweringSimplePath::translate (const AST::SimplePath &path) { diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index 3680ed4..c0ecff4 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -44,6 +44,7 @@ public: void visit (AST::Trait &trait) override; void visit (AST::TraitImpl &impl_block) override; void visit (AST::ExternBlock &extern_block) override; + void visit (AST::MacroRulesDefinition &rules_def) override; private: ASTLoweringItem () : translated (nullptr) {} -- cgit v1.1