]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: resolve: Add mappings for proc macros and resolving
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Mon, 19 Jun 2023 10:51:34 +0000 (12:51 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:58 +0000 (18:55 +0100)
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>
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-macro.h
gcc/rust/ast/rust-path.h
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-macro-expand.cc
gcc/rust/expand/rust-macro-expand.h
gcc/rust/util/rust-hir-map.cc
gcc/rust/util/rust-hir-map.h
gcc/rust/util/rust-proc-macro-invocation.h [new file with mode: 0644]

index 699232c3d6e5453472955ca6b9acd9207d078601..eb133aaec244b2d8b83fb037722fb47f3ebcc48c 100644 (file)
@@ -173,7 +173,7 @@ SimplePathSegment::as_string () const
   return segment_name;
 }
 
-std::string
+const std::string
 SimplePath::as_string () const
 {
   std::string path;
index faf14fe722b7f156db44c6d3d3c1ce7fc57d5acd..5be6932ce609adbf745f761edb5c4026c65e6bf6 100644 (file)
@@ -25,6 +25,7 @@
 #include "rust-token.h"
 #include "rust-location.h"
 #include "rust-diagnostics.h"
+#include "rust-proc-macro-invocation.h"
 
 namespace Rust {
 // TODO: remove typedefs and make actual types for these
@@ -32,7 +33,7 @@ typedef int TupleIndex;
 struct Session;
 struct MacroExpander;
 
-class Identifier
+class Identifier : public ProcMacroInvocable
 {
 public:
   // Create dummy identifier
@@ -59,7 +60,7 @@ public:
 
   NodeId get_node_id () const { return node_id; }
   location_t get_locus () const { return loc; }
-  const std::string &as_string () const { return ident; }
+  const std::string as_string () const { return ident; }
 
   bool empty () const { return ident.empty (); }
 
@@ -409,7 +410,7 @@ public:
 };
 
 // A simple path without generic or type arguments
-class SimplePath
+class SimplePath : public ProcMacroInvocable
 {
   bool opening_scope_resolution;
   std::vector<SimplePathSegment> segments;
@@ -435,15 +436,15 @@ public:
   // Returns whether the SimplePath is empty, i.e. has path segments.
   bool is_empty () const { return segments.empty (); }
 
-  std::string as_string () const;
+  const std::string as_string () const override;
 
   bool has_opening_scope_resolution () const
   {
     return opening_scope_resolution;
   }
 
-  location_t get_locus () const { return locus; }
-  NodeId get_node_id () const { return node_id; }
+  location_t get_locus () const override { return locus; }
+  NodeId get_node_id () const override { return node_id; }
 
   // does this need visitor if not polymorphic? probably not
 
index db8cf1ef5d450b376bfe0d6d4ebc9f50a66c62af..78941f883bea2921000d5b47b13cf2b3f00b29b7 100644 (file)
@@ -838,6 +838,8 @@ public:
     return path;
   }
 
+  SimplePath &get_path () { return path; }
+
   location_t get_locus () const override { return path.get_locus (); }
 
   bool check_cfg_predicate (const Session &session) const override;
@@ -935,7 +937,7 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
-  Identifier get_ident () const { return ident; }
+  Identifier &get_ident () { return ident; }
 
   location_t get_locus () const override { return ident_locus; }
 
index d70789c4c906c2a425767c2a114401edb2e78bb5..12326a3a0ee1b3396c263ef1c846db0ffefe9e55 100644 (file)
@@ -242,7 +242,7 @@ public:
     return type;
   }
 
-  const std::string &get_path () const
+  const std::string get_path () const
   {
     rust_assert (kind == Kind::Either);
 
index c4b3791dfa5f586630e70fb134b52a2de8f3e59c..3fa0b5ffdcbeea819868ac67811d73632c9c991b 100644 (file)
@@ -57,43 +57,66 @@ ExpandVisitor::go (AST::Crate &crate)
  *
  * @param attrs The attributes on the item to derive
  */
-static std::vector<std::string>
+static std::vector<std::unique_ptr<ProcMacroInvocable>>
 get_traits_to_derive (AST::Attribute &attr)
 {
-  std::vector<std::string> to_derive;
-
+  std::vector<std::unique_ptr<ProcMacroInvocable>> result;
   auto &input = attr.get_attr_input ();
   switch (input.get_attr_input_type ())
     {
-      // isn't there a better way to do this?? like parse it or
-      // something idk. some function I'm not thinking of?
-      case AST::AttrInput::TOKEN_TREE: {
-       auto &tokens
-         = static_cast<AST::DelimTokenTree &> (input).get_token_trees ();
-
-       // erase the delimiters
-       rust_assert (tokens.size () >= 2);
-       tokens.erase (tokens.begin ());
-       tokens.pop_back ();
-
-       for (auto &token : tokens)
+      case AST::AttrInput::META_ITEM: {
+       auto meta = static_cast<AST::AttrInputMetaItemContainer &> (input);
+       for (auto &current : meta.get_items ())
          {
-           // skip commas, as they are part of the token stream
-           if (token->as_string () == ",")
-             continue;
-
-           to_derive.emplace_back (token->as_string ());
+           // HACK: Find a better way to achieve the downcast.
+           switch (current->get_kind ())
+             {
+               case AST::MetaItemInner::Kind::MetaItem: {
+                 // Let raw pointer go out of scope without freeing, it doesn't
+                 // own the data anyway
+                 auto meta_item
+                   = static_cast<AST::MetaItem *> (current.get ());
+                 switch (meta_item->get_item_kind ())
+                   {
+                     case AST::MetaItem::ItemKind::Path: {
+                       auto path
+                         = static_cast<AST::MetaItemPath *> (meta_item);
+                       result.push_back (Rust::make_unique<AST::SimplePath> (
+                         path->get_path ()));
+                     }
+                     break;
+                     case AST::MetaItem::ItemKind::Word: {
+                       auto word = static_cast<AST::MetaWord *> (meta_item);
+                       result.push_back (
+                         Rust::make_unique<Identifier> (word->get_ident ()));
+                     }
+                     break;
+                   case AST::MetaItem::ItemKind::ListPaths:
+                   case AST::MetaItem::ItemKind::NameValueStr:
+                   case AST::MetaItem::ItemKind::PathLit:
+                   case AST::MetaItem::ItemKind::Seq:
+                   case AST::MetaItem::ItemKind::ListNameValueStr:
+                   default:
+                     gcc_unreachable ();
+                     break;
+                   }
+               }
+               break;
+             case AST::MetaItemInner::Kind::LitExpr:
+             default:
+               gcc_unreachable ();
+               break;
+             }
          }
-       break;
       }
+      break;
+    case AST::AttrInput::TOKEN_TREE:
     case AST::AttrInput::LITERAL:
-    case AST::AttrInput::META_ITEM:
     case AST::AttrInput::MACRO:
       rust_unreachable ();
       break;
     }
-
-  return to_derive;
+  return result;
 }
 
 static std::unique_ptr<AST::Item>
@@ -104,7 +127,7 @@ builtin_derive_item (AST::Item &item, const AST::Attribute &derive,
 }
 
 static std::vector<std::unique_ptr<AST::Item>>
-derive_item (AST::Item &item, const std::string &to_derive,
+derive_item (AST::Item &item, ProcMacroInvocable &to_derive,
             MacroExpander &expander)
 {
   std::vector<std::unique_ptr<AST::Item>> result;
@@ -127,7 +150,7 @@ derive_item (AST::Item &item, const std::string &to_derive,
 }
 
 static std::vector<std::unique_ptr<AST::Item>>
-expand_item_attribute (AST::Item &item, AST::SimplePath &name,
+expand_item_attribute (AST::Item &item, ProcMacroInvocable &name,
                       MacroExpander &expander)
 {
   std::vector<std::unique_ptr<AST::Item>> result;
@@ -232,13 +255,14 @@ ExpandVisitor::expand_inner_items (
 
              if (is_derive (current))
                {
+                 current.parse_attr_to_meta_item ();
                  attr_it = attrs.erase (attr_it);
                  // Get traits to derive in the current attribute
                  auto traits_to_derive = get_traits_to_derive (current);
                  for (auto &to_derive : traits_to_derive)
                    {
-                     auto maybe_builtin
-                       = MacroBuiltin::builtins.lookup (to_derive);
+                     auto maybe_builtin = MacroBuiltin::builtins.lookup (
+                       to_derive->as_string ());
                      if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin))
                        {
                          auto new_item
@@ -251,7 +275,7 @@ ExpandVisitor::expand_inner_items (
                      else
                        {
                          auto new_items
-                           = derive_item (*item, to_derive, expander);
+                           = derive_item (*item, *to_derive, expander);
                          std::move (new_items.begin (), new_items.end (),
                                     std::inserter (items, it));
                        }
@@ -323,8 +347,8 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr)
                  auto traits_to_derive = get_traits_to_derive (current);
                  for (auto &to_derive : traits_to_derive)
                    {
-                     auto maybe_builtin
-                       = MacroBuiltin::builtins.lookup (to_derive);
+                     auto maybe_builtin = MacroBuiltin::builtins.lookup (
+                       to_derive->as_string ());
                      if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin))
                        {
                          auto new_item
@@ -337,7 +361,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr)
                      else
                        {
                          auto new_items
-                           = derive_item (item, to_derive, expander);
+                           = derive_item (item, *to_derive, expander);
                          std::move (new_items.begin (), new_items.end (),
                                     std::inserter (stmts, it));
                        }
index ac57e83afa8eaf283555357905b3be8d85bd90ec..28868afa2af8f40ee6fd793533ec438c31ae7d3b 100644 (file)
@@ -1093,50 +1093,6 @@ MacroExpander::transcribe_rule (
   return fragment;
 }
 
-// TODO: Move to early name resolver ?
-void
-MacroExpander::import_proc_macros (std::string extern_crate)
-{
-  auto path = session.extern_crates.find (extern_crate);
-  if (path == session.extern_crates.end ())
-    {
-      // Extern crate path is not available.
-      // FIXME: Emit error
-      rust_error_at (UNDEF_LOCATION, "Cannot find requested proc macro crate");
-      rust_unreachable ();
-    }
-  auto macros = load_macros (path->second);
-
-  std::string prefix = extern_crate + "::";
-  for (auto &macro : macros)
-    {
-      switch (macro.tag)
-       {
-       case ProcMacro::CUSTOM_DERIVE:
-         rust_debug ("Found one derive proc macro.");
-         mappings->insert_derive_proc_macro (
-           std::make_pair (extern_crate,
-                           macro.payload.custom_derive.trait_name),
-           macro.payload.custom_derive);
-         break;
-       case ProcMacro::ATTR:
-         rust_debug ("Found one attribute proc macro.");
-         mappings->insert_attribute_proc_macro (
-           std::make_pair (extern_crate, macro.payload.attribute.name),
-           macro.payload.attribute);
-         break;
-       case ProcMacro::BANG:
-         rust_debug ("Found one bang proc macro.");
-         mappings->insert_bang_proc_macro (
-           std::make_pair (extern_crate, macro.payload.bang.name),
-           macro.payload.bang);
-         break;
-       default:
-         rust_unreachable ();
-       }
-    }
-}
-
 AST::Fragment
 MacroExpander::parse_proc_macro_output (ProcMacro::TokenStream ts)
 {
index 30d2970fef5921c3c2b3b6e97790ebde560fe069..f83de953cb086574191e63a625a21f35585e8216 100644 (file)
@@ -407,27 +407,13 @@ struct MacroExpander
   void import_proc_macros (std::string extern_crate);
 
   template <typename T>
-  AST::Fragment expand_derive_proc_macro (T &item,
-                                         const std::string &trait_name)
+  AST::Fragment expand_derive_proc_macro (T &item, ProcMacroInvocable &path)
   {
     ProcMacro::CustomDerive macro;
-
-    // FIXME: Resolve crate name
-    std::string crate = "";
-    std::string name = trait_name;
-
-    if (!mappings->lookup_derive_proc_macro (std::make_pair (crate, name),
-                                            macro))
+    if (!mappings->lookup_derive_proc_macro_invocation (path, macro))
       {
-       // FIXME: Resolve this path segment instead of taking it directly.
-       import_proc_macros (crate);
-       if (!mappings->lookup_derive_proc_macro (std::make_pair (crate, name),
-                                                macro))
-         {
-           rust_error_at (UNDEF_LOCATION, "procedural macro %s not found",
-                          name.c_str ());
-           rust_assert (false);
-         }
+       rust_error_at (path.get_locus (), "Macro not found");
+       return AST::Fragment::create_error ();
       }
 
     AST::TokenCollector collector;
@@ -441,24 +427,14 @@ struct MacroExpander
   }
 
   template <typename T>
-  AST::Fragment expand_bang_proc_macro (T &item, AST::SimplePath &path)
+  AST::Fragment expand_bang_proc_macro (T &item,
+                                       AST::MacroInvocation &invocation)
   {
     ProcMacro::Bang macro;
-
-    std::string crate = path.get_segments ()[0].get_segment_name ();
-    std::string name = path.get_segments ()[1].get_segment_name ();
-    if (!mappings->lookup_bang_proc_macro (std::make_pair (crate, name), macro))
+    if (!mappings->lookup_bang_proc_macro_invocation (invocation, macro))
       {
-       // FIXME: Resolve this path segment instead of taking it directly.
-       import_proc_macros (crate);
-
-       if (!mappings->lookup_bang_proc_macro (std::make_pair (crate, name),
-                                              macro))
-         {
-           rust_error_at (UNDEF_LOCATION, "procedural macro %s not found",
-                          name.c_str ());
-           rust_assert (false);
-         }
+       rust_error_at (invocation.get_locus (), "Macro not found");
+       return AST::Fragment::create_error ();
       }
 
     AST::TokenCollector collector;
@@ -472,25 +448,13 @@ struct MacroExpander
   }
 
   template <typename T>
-  AST::Fragment expand_attribute_proc_macro (T &item, AST::SimplePath &path)
+  AST::Fragment expand_attribute_proc_macro (T &item, ProcMacroInvocable &path)
   {
     ProcMacro::Attribute macro;
-
-    std::string crate = path.get_segments ()[0].get_segment_name ();
-    std::string name = path.get_segments ()[1].get_segment_name ();
-    if (!mappings->lookup_attribute_proc_macro (std::make_pair (crate, name),
-                                               macro))
+    if (!mappings->lookup_attribute_proc_macro_invocation (path, macro))
       {
-       // FIXME: Resolve this path segment instead of taking it directly.
-       import_proc_macros (crate);
-       if (!mappings->lookup_attribute_proc_macro (std::make_pair (crate,
-                                                                   name),
-                                                   macro))
-         {
-           rust_error_at (UNDEF_LOCATION, "procedural macro %s not found",
-                          name.c_str ());
-           rust_assert (false);
-         }
+       rust_error_at (path.get_locus (), "Macro not found");
+       return AST::Fragment::create_error ();
       }
 
     AST::TokenCollector collector;
index caf44a282490d50fcc0dd4e401d9483e50417273..aeb813a0416d6388723a2339c9f4b05d5c7f829f 100644 (file)
@@ -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;
 
@@ -1072,6 +1070,72 @@ Mappings::lookup_attribute_proc_macro (
   return true;
 }
 
+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)
 {
index a47898b84048f8200b1f4508997976ae2da99ca9..293a6d129b6358fd04af900074006ff9f1052bb9 100644 (file)
@@ -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 (file)
index 0000000..b45e013
--- /dev/null
@@ -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*/