diff options
Diffstat (limited to 'gcc/rust/util')
-rw-r--r-- | gcc/rust/util/rust-attributes.cc | 1 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 66 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 29 |
3 files changed, 95 insertions, 1 deletions
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 0656b27..3403f48 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -43,6 +43,7 @@ static const BuiltinAttrDefinition __definitions[] {"rustc_builtin_macro", EXPANSION}, {"path", EXPANSION}, {"macro_use", NAME_RESOLUTION}, + {"macro_export", NAME_RESOLUTION}, // FIXME: This is not implemented yet, see // https://github.com/Rust-GCC/gccrs/issues/1475 {"target_feature", CODE_GENERATION}, diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 3edbc20..706a29c 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -942,6 +942,72 @@ Mappings::get_exported_macros () } void +Mappings::insert_derive_proc_macro ( + std::pair<std::string, std::string> hierarchy, ProcMacro::CustomDerive macro) +{ + auto it = procmacroDeriveMappings.find (hierarchy); + rust_assert (it == procmacroDeriveMappings.end ()); + + procmacroDeriveMappings[hierarchy] = macro; +} + +void +Mappings::insert_bang_proc_macro (std::pair<std::string, std::string> hierarchy, + ProcMacro::Bang macro) +{ + auto it = procmacroBangMappings.find (hierarchy); + rust_assert (it == procmacroBangMappings.end ()); + + procmacroBangMappings[hierarchy] = macro; +} + +void +Mappings::insert_attribute_proc_macro ( + std::pair<std::string, std::string> hierarchy, ProcMacro::Attribute macro) +{ + auto it = procmacroAttributeMappings.find (hierarchy); + rust_assert (it == procmacroAttributeMappings.end ()); + + procmacroAttributeMappings[hierarchy] = macro; +} + +bool +Mappings::lookup_derive_proc_macro ( + std::pair<std::string, std::string> hierarchy, ProcMacro::CustomDerive ¯o) +{ + auto it = procmacroDeriveMappings.find (hierarchy); + if (it == procmacroDeriveMappings.end ()) + return false; + + macro = it->second; + return true; +} + +bool +Mappings::lookup_bang_proc_macro (std::pair<std::string, std::string> hierarchy, + ProcMacro::Bang ¯o) +{ + auto it = procmacroBangMappings.find (hierarchy); + if (it == procmacroBangMappings.end ()) + return false; + + macro = it->second; + return true; +} + +bool +Mappings::lookup_attribute_proc_macro ( + std::pair<std::string, std::string> hierarchy, ProcMacro::Attribute ¯o) +{ + auto it = procmacroAttributeMappings.find (hierarchy); + if (it == procmacroAttributeMappings.end ()) + return false; + + macro = it->second; + return true; +} + +void Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility) { visibility_map.insert ({id, visibility}); 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; |