aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/util')
-rw-r--r--gcc/rust/util/rust-hir-map.cc106
-rw-r--r--gcc/rust/util/rust-hir-map.h53
-rw-r--r--gcc/rust/util/rust-proc-macro-invocation.h21
3 files changed, 134 insertions, 46 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 0faea56..76e4c70 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -1007,40 +1007,39 @@ Mappings::lookup_attribute_proc_macros (
}
void
-Mappings::insert_derive_proc_macro (
- std::pair<std::string, std::string> hierarchy, ProcMacro::CustomDerive macro)
+Mappings::insert_derive_proc_macro_def (NodeId id,
+ ProcMacro::CustomDerive macro)
{
- auto it = procmacroDeriveMappings.find (hierarchy);
+ auto it = procmacroDeriveMappings.find (id);
rust_assert (it == procmacroDeriveMappings.end ());
- procmacroDeriveMappings[hierarchy] = macro;
+ procmacroDeriveMappings[id] = macro;
}
void
-Mappings::insert_bang_proc_macro (std::pair<std::string, std::string> hierarchy,
- ProcMacro::Bang macro)
+Mappings::insert_bang_proc_macro_def (NodeId id, ProcMacro::Bang macro)
{
- auto it = procmacroBangMappings.find (hierarchy);
+ auto it = procmacroBangMappings.find (id);
rust_assert (it == procmacroBangMappings.end ());
- procmacroBangMappings[hierarchy] = macro;
+ procmacroBangMappings[id] = macro;
}
void
-Mappings::insert_attribute_proc_macro (
- std::pair<std::string, std::string> hierarchy, ProcMacro::Attribute macro)
+Mappings::insert_attribute_proc_macro_def (NodeId id,
+ ProcMacro::Attribute macro)
{
- auto it = procmacroAttributeMappings.find (hierarchy);
+ auto it = procmacroAttributeMappings.find (id);
rust_assert (it == procmacroAttributeMappings.end ());
- procmacroAttributeMappings[hierarchy] = macro;
+ procmacroAttributeMappings[id] = macro;
}
bool
-Mappings::lookup_derive_proc_macro (
- std::pair<std::string, std::string> hierarchy, ProcMacro::CustomDerive &macro)
+Mappings::lookup_derive_proc_macro_def (NodeId id,
+ ProcMacro::CustomDerive &macro)
{
- auto it = procmacroDeriveMappings.find (hierarchy);
+ auto it = procmacroDeriveMappings.find (id);
if (it == procmacroDeriveMappings.end ())
return false;
@@ -1049,10 +1048,9 @@ Mappings::lookup_derive_proc_macro (
}
bool
-Mappings::lookup_bang_proc_macro (std::pair<std::string, std::string> hierarchy,
- ProcMacro::Bang &macro)
+Mappings::lookup_bang_proc_macro_def (NodeId id, ProcMacro::Bang &macro)
{
- auto it = procmacroBangMappings.find (hierarchy);
+ auto it = procmacroBangMappings.find (id);
if (it == procmacroBangMappings.end ())
return false;
@@ -1061,10 +1059,10 @@ Mappings::lookup_bang_proc_macro (std::pair<std::string, std::string> hierarchy,
}
bool
-Mappings::lookup_attribute_proc_macro (
- std::pair<std::string, std::string> hierarchy, ProcMacro::Attribute &macro)
+Mappings::lookup_attribute_proc_macro_def (NodeId id,
+ ProcMacro::Attribute &macro)
{
- auto it = procmacroAttributeMappings.find (hierarchy);
+ auto it = procmacroAttributeMappings.find (id);
if (it == procmacroAttributeMappings.end ())
return false;
@@ -1073,6 +1071,72 @@ Mappings::lookup_attribute_proc_macro (
}
void
+Mappings::insert_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
+ ProcMacro::CustomDerive def)
+{
+ auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
+ rust_assert (it == procmacroDeriveInvocations.end ());
+
+ procmacroDeriveInvocations[invoc.get_node_id ()] = def;
+}
+
+bool
+Mappings::lookup_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
+ ProcMacro::CustomDerive &def)
+{
+ auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
+ if (it == procmacroDeriveInvocations.end ())
+ return false;
+
+ def = it->second;
+ return true;
+}
+
+void
+Mappings::insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
+ ProcMacro::Bang def)
+{
+ auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ());
+ rust_assert (it == procmacroBangInvocations.end ());
+
+ procmacroBangInvocations[invoc.get_macro_node_id ()] = def;
+}
+
+bool
+Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
+ ProcMacro::Bang &def)
+{
+ auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ());
+ if (it == procmacroBangInvocations.end ())
+ return false;
+
+ def = it->second;
+ return true;
+}
+
+void
+Mappings::insert_attribute_proc_macro_invocation (
+ Rust::ProcMacroInvocable &invoc, ProcMacro::Attribute def)
+{
+ auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
+ rust_assert (it == procmacroAttributeInvocations.end ());
+
+ procmacroAttributeInvocations[invoc.get_node_id ()] = def;
+}
+
+bool
+Mappings::lookup_attribute_proc_macro_invocation (
+ Rust::ProcMacroInvocable &invoc, ProcMacro::Attribute &def)
+{
+ auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
+ if (it == procmacroAttributeInvocations.end ())
+ return false;
+
+ def = 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 d1fbe59..3360e2c 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> &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 &macro);
- bool lookup_bang_proc_macro (std::pair<std::string, std::string> hierachy,
- ProcMacro::Bang &macro);
- bool
- lookup_attribute_proc_macro (std::pair<std::string, std::string> hierachy,
- ProcMacro::Attribute &macro);
+ 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 &macro);
+ bool lookup_bang_proc_macro_def (NodeId id, ProcMacro::Bang &macro);
+ bool lookup_attribute_proc_macro_def (NodeId id, ProcMacro::Attribute &macro);
+
+ 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;
diff --git a/gcc/rust/util/rust-proc-macro-invocation.h b/gcc/rust/util/rust-proc-macro-invocation.h
new file mode 100644
index 0000000..b45e013
--- /dev/null
+++ b/gcc/rust/util/rust-proc-macro-invocation.h
@@ -0,0 +1,21 @@
+#ifndef RUST_PROC_MACRO_INVOCATION_H
+#define RUST_PROC_MACRO_INVOCATION_H
+
+#include "rust-mapping-common.h"
+#include "rust-location.h"
+
+namespace Rust {
+
+class ProcMacroInvocable
+{
+public:
+ virtual NodeId get_node_id () const = 0;
+ virtual const std::string as_string () const = 0;
+ virtual Location get_locus () const = 0;
+
+ virtual ~ProcMacroInvocable () {}
+};
+
+} // namespace Rust
+
+#endif /* ! RUST_PROC_MACRO_INVOCATION_H*/