diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-06-19 12:51:34 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:55:58 +0100 |
commit | ed866110ef0f90f24c60a91a7141565b706ad185 (patch) | |
tree | a3e6c06b4b808e38b4f59ed476b30607397489cd /gcc/rust/util/rust-hir-map.h | |
parent | 00f79c773bc247830b29b6cef02d89337123c167 (diff) | |
download | gcc-ed866110ef0f90f24c60a91a7141565b706ad185.zip gcc-ed866110ef0f90f24c60a91a7141565b706ad185.tar.gz gcc-ed866110ef0f90f24c60a91a7141565b706ad185.tar.bz2 |
gccrs: resolve: Add mappings for proc macros and resolving
Add multiple mappings for procedural macro name resolution.
Procedural macros were not resolved using name resolution and mapping
but rather with some hacky path comparison.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::import_proc_macros):
Remove function.
* expand/rust-macro-expand.h (struct MacroExpander): Remove
import_proc_macro function.
* util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_def):
Add a function to insert a derive proc macro definition.
(Mappings::insert_bang_proc_macro): Remove function.
(Mappings::insert_bang_proc_macro_def): Add function to insert a
bang proc macro definition.
(Mappings::insert_attribute_proc_macro_def): Likewise with
attribute proc macros.
(Mappings::lookup_derive_proc_macro_def): Add a function to
lookup a defined derive proc macro definition.
(Mappings::lookup_bang_proc_macro): Remove function.
(Mappings::lookup_bang_proc_macro_def): Add a function to lookup
a bang proc macro definition.
(Mappings::lookup_attribute_proc_macro_def): Add a function to
lookup an attribute prod macro definition.
(Mappings::insert_derive_proc_macro_invocation): Add a function
to insert a derive proc macro invocation.
(Mappings::lookup_derive_proc_macro_invocation): Add a function
to lookup a derive proc macro invocation.
(Mappings::insert_bang_proc_macro_invocation): Add a function to
insert a bang proc macro invocation.
(Mappings::lookup_bang_proc_macro_invocation): Add a function to
lookup a bang proc macro invocation.
(Mappings::insert_attribute_proc_macro_invocation): Add a
function to insert an attribute proc macro invocation.
(Mappings::lookup_attribute_proc_macro_invocation): Add a
function to lookup an attribute proc macro invocation.
* util/rust-hir-map.h: Add different proc macro mappings
and change function prototypes.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Return a
vector of SimplePath instead.
(derive_item): Accept SimplePath instead of a string.
* ast/rust-ast.h: Add common ProcMacroInvocable interface to
Identifiers and SimplePath nodes.
* ast/rust-ast.cc: Add const modifier.
* ast/rust-macro.h: Change path and identifier getters.
* ast/rust-path.h: Change return type to reference.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/util/rust-hir-map.h')
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index a47898b..293a6d1 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -28,6 +28,7 @@ #include "rust-hir-full-decls.h" #include "rust-lang-item.h" #include "rust-privacy-common.h" +#include "rust-proc-macro-invocation.h" #include "libproc_macro/proc_macro.h" namespace Rust { @@ -297,21 +298,27 @@ public: bool lookup_attribute_proc_macros (CrateNum num, std::vector<ProcMacro::Attribute> ¯os); - void insert_derive_proc_macro (std::pair<std::string, std::string> hierachy, - ProcMacro::CustomDerive macro); - void insert_bang_proc_macro (std::pair<std::string, std::string> hierachy, - ProcMacro::Bang macro); - void - insert_attribute_proc_macro (std::pair<std::string, std::string> hierachy, - ProcMacro::Attribute macro); - - bool lookup_derive_proc_macro (std::pair<std::string, std::string> hierachy, - ProcMacro::CustomDerive ¯o); - bool lookup_bang_proc_macro (std::pair<std::string, std::string> hierachy, - ProcMacro::Bang ¯o); - bool - lookup_attribute_proc_macro (std::pair<std::string, std::string> hierachy, - ProcMacro::Attribute ¯o); + void insert_derive_proc_macro_def (NodeId id, ProcMacro::CustomDerive macro); + void insert_bang_proc_macro_def (NodeId id, ProcMacro::Bang macro); + void insert_attribute_proc_macro_def (NodeId id, ProcMacro::Attribute macro); + + bool lookup_derive_proc_macro_def (NodeId id, ProcMacro::CustomDerive ¯o); + bool lookup_bang_proc_macro_def (NodeId id, ProcMacro::Bang ¯o); + bool lookup_attribute_proc_macro_def (NodeId id, ProcMacro::Attribute ¯o); + + void insert_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc, + ProcMacro::CustomDerive def); + + bool lookup_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc, + ProcMacro::CustomDerive &def); + void insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc, + ProcMacro::Bang def); + bool lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc_id, + ProcMacro::Bang &def); + void insert_attribute_proc_macro_invocation (Rust::ProcMacroInvocable &invoc, + ProcMacro::Attribute def); + bool lookup_attribute_proc_macro_invocation (Rust::ProcMacroInvocable &invoc, + ProcMacro::Attribute &def); void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility); bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def); @@ -392,20 +399,16 @@ private: // Procedural macros std::map<CrateNum, std::vector<ProcMacro::CustomDerive>> procmacrosDeriveMappings; - std::map<CrateNum, std::vector<ProcMacro::Bang>> procmacrosBangMappings; - std::map<CrateNum, std::vector<ProcMacro::Attribute>> procmacrosAttributeMappings; - std::map<std::pair<std::string, std::string>, ProcMacro::CustomDerive> - procmacroDeriveMappings; - - std::map<std::pair<std::string, std::string>, ProcMacro::Bang> - procmacroBangMappings; - - std::map<std::pair<std::string, std::string>, ProcMacro::Attribute> - procmacroAttributeMappings; + std::map<NodeId, ProcMacro::CustomDerive> procmacroDeriveMappings; + std::map<NodeId, ProcMacro::Bang> procmacroBangMappings; + std::map<NodeId, ProcMacro::Attribute> procmacroAttributeMappings; + std::map<NodeId, ProcMacro::CustomDerive> procmacroDeriveInvocations; + std::map<NodeId, ProcMacro::Bang> procmacroBangInvocations; + std::map<NodeId, ProcMacro::Attribute> procmacroAttributeInvocations; // crate names std::map<CrateNum, std::string> crate_names; |