[committed,017/103] gccrs: mappings: Add MacroInvocation -> MacroRulesDef mappings

Message ID 20230221120230.596966-18-arthur.cohen@embecosm.com
State Unresolved
Headers
Series [committed,001/103] gccrs: Fix missing dead code analysis ICE on local enum definition |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Arthur Cohen Feb. 21, 2023, 12:01 p.m. UTC
  From: Arthur Cohen <arthur.cohen@embecosm.com>

gcc/rust/ChangeLog:

	* util/rust-hir-map.h: Add new mappings.
	* util/rust-hir-map.cc (Mappings::insert_macro_invocation): Add insertion
	function into mappings.
	(Mappings::lookup_macro_invocation): Add lookup function for mappings.
---
 gcc/rust/util/rust-hir-map.cc | 22 ++++++++++++++++++++++
 gcc/rust/util/rust-hir-map.h  |  6 ++++++
 2 files changed, 28 insertions(+)
  

Patch

diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 80434489fcd..7ea782ed4c4 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -866,6 +866,28 @@  Mappings::lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def)
   return true;
 }
 
+void
+Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
+				   AST::MacroRulesDefinition *def)
+{
+  auto it = macroInvocations.find (invoc.get_macro_node_id ());
+  rust_assert (it == macroInvocations.end ());
+
+  macroInvocations[invoc.get_macro_node_id ()] = def;
+}
+
+bool
+Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc,
+				   AST::MacroRulesDefinition **def)
+{
+  auto it = macroInvocations.find (invoc.get_macro_node_id ());
+  if (it == macroInvocations.end ())
+    return false;
+
+  *def = it->second;
+  return true;
+}
+
 void
 Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility)
 {
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 474bd5fa229..addd9efc3b0 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -269,6 +269,11 @@  public:
 
   bool lookup_macro_def (NodeId id, AST::MacroRulesDefinition **def);
 
+  void insert_macro_invocation (AST::MacroInvocation &invoc,
+				AST::MacroRulesDefinition *def);
+  bool lookup_macro_invocation (AST::MacroInvocation &invoc,
+				AST::MacroRulesDefinition **def);
+
   void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility);
   bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def);
 
@@ -334,6 +339,7 @@  private:
 
   // macros
   std::map<NodeId, AST::MacroRulesDefinition *> macroMappings;
+  std::map<NodeId, AST::MacroRulesDefinition *> macroInvocations;
 
   // crate names
   std::map<CrateNum, std::string> crate_names;