diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-05-18 14:05:25 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-06-08 14:32:35 +0200 |
commit | 12131c106fdffe25c40fa4a309d8ead03b99a685 (patch) | |
tree | c01ec34eb87fe38d5d2c8993d0cb55891378265d /gcc/rust/util/rust-hir-map.h | |
parent | 562a0860f15ec5da89cd3605bcab5da18421ce15 (diff) | |
download | gcc-12131c106fdffe25c40fa4a309d8ead03b99a685.zip gcc-12131c106fdffe25c40fa4a309d8ead03b99a685.tar.gz gcc-12131c106fdffe25c40fa4a309d8ead03b99a685.tar.bz2 |
expand: Add prc macro expander and registration
Add containers and functions to the hir-map in order to register and
lookup all three kind of procedural macros.
Add a first draft for attribute procedural macro expansion. This
expander still lack proper error handling as well as polishing.
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::insert_bang_proc_macro):
Add a function to insert a new bang proc macro.
(Mappings::lookup_bang_proc_macro): Add a function to lookup a
bang procedural macro.
(Mappings::insert_derive_proc_macro): Add a function to insert a
derive procedural macro.
(Mappings::lookup_derive_proc_macro): Add a function to lookup a
derive procedural macro.
(Mappings::insert_attribute_proc_macro): Add a function to
insert an attribute procedural macro.
(Mappings::lookup_attribute_proc_macro): Add a function to
lookup an attribute procedural macro.
* util/rust-hir-map.h: Add function prototypes.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_outer_attribute):
Implement expansion of outer attributes.
(ExpandVisitor::expand_inner_attribute):
Add call for inner attribute expansion.
* expand/rust-expand-visitor.h:
Add new procedural macro expander attribute.
* expand/rust-proc-macro.cc (load_macros_array): Add a function
to load the proc macro array from a given shared object.
(load_macros): Add a function to retrieve procedural macro
vector from a given shared object.
(ProcMacroExpander::import_proc_macros): Add a function to load
procedural macros from a given extern crate name.
* expand/rust-proc-macro.h (RUST_PROC_MACRO_H): Add new
proc-macro file.
(class ProcMacroExpander): Add new ProcMacroExpander class.
* rust-session-manager.cc (Session::expansion): Create new macro
expander and feed it to the expand visitor.
* util/rust-attributes.cc: Add macro_export builtin attribute.
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 | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 9f333f4..6e6a1c8 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 "libproc_macro/proc_macro.h" namespace Rust { namespace Analysis { @@ -282,6 +283,22 @@ public: void insert_exported_macro (AST::MacroRulesDefinition &def); std::vector<NodeId> &get_exported_macros (); + 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_visibility (NodeId id, Privacy::ModuleVisibility visibility); bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def); @@ -350,11 +367,21 @@ private: // all hirid nodes std::map<CrateNum, std::set<HirId>> hirNodesWithinCrate; - // macros + // MBE macros std::map<NodeId, AST::MacroRulesDefinition *> macroMappings; std::map<NodeId, AST::MacroRulesDefinition *> macroInvocations; std::vector<NodeId> exportedMacros; + // Procedural macros + 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; + // crate names std::map<CrateNum, std::string> crate_names; |