]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: resolve: Remove ProcMacroInvocable interface
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 13 Jul 2023 10:48:18 +0000 (12:48 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:55:59 +0000 (18:55 +0100)
Since all identifiers in attributes are converted to SimplePath, this
common interface is no longer required.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class Identifier): Remove interface
inheritance.
(class SimplePath): Likewise.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Change
return type.
(derive_item): Update according to get_traits_to_derive return
type.
(expand_item_attribute): Likewise.
(ExpandVisitor::expand_inner_stmts): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
* util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_invocation):
Change input type to SimplePath.
(Mappings::lookup_derive_proc_macro_invocation): Likewise.
(Mappings::insert_attribute_proc_macro_invocation): Likewise.
(Mappings::lookup_attribute_proc_macro_invocation): Likewise.
* util/rust-hir-map.h: Likewise with function prototypes.
* util/rust-proc-macro-invocation.h: Removed.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ast/rust-ast.h
gcc/rust/expand/rust-expand-visitor.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 [deleted file]

index 8ec707f3afe995abc09bb8e121336883630a6f10..f46925a2f22a7b2f2538662cb935f2acec97ef4e 100644 (file)
@@ -25,7 +25,6 @@
 #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
@@ -33,7 +32,7 @@ typedef int TupleIndex;
 struct Session;
 struct MacroExpander;
 
-class Identifier : public ProcMacroInvocable
+class Identifier
 {
 public:
   // Create dummy identifier
@@ -60,7 +59,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 (); }
 
@@ -410,7 +409,7 @@ public:
 };
 
 // A simple path without generic or type arguments
-class SimplePath : public ProcMacroInvocable
+class SimplePath
 {
   bool opening_scope_resolution;
   std::vector<SimplePathSegment> segments;
@@ -443,15 +442,15 @@ public:
   // Returns whether the SimplePath is empty, i.e. has path segments.
   bool is_empty () const { return segments.empty (); }
 
-  const std::string as_string () const override;
+  const std::string as_string () const;
 
   bool has_opening_scope_resolution () const
   {
     return opening_scope_resolution;
   }
 
-  location_t get_locus () const override { return locus; }
-  NodeId get_node_id () const override { return node_id; }
+  location_t get_locus () const { return locus; }
+  NodeId get_node_id () const { return node_id; }
 
   // does this need visitor if not polymorphic? probably not
 
index 54075e1fa48c4b369d5a054bf5fb36afb7b25cd9..8cbf73dcb086d283b890c986803de1bb8ea6d8d5 100644 (file)
@@ -57,10 +57,10 @@ ExpandVisitor::go (AST::Crate &crate)
  *
  * @param attrs The attributes on the item to derive
  */
-static std::vector<std::unique_ptr<ProcMacroInvocable>>
+static std::vector<AST::SimplePath>
 get_traits_to_derive (AST::Attribute &attr)
 {
-  std::vector<std::unique_ptr<ProcMacroInvocable>> result;
+  std::vector<AST::SimplePath> result;
   auto &input = attr.get_attr_input ();
   switch (input.get_attr_input_type ())
     {
@@ -81,8 +81,7 @@ get_traits_to_derive (AST::Attribute &attr)
                      case AST::MetaItem::ItemKind::Path: {
                        auto path
                          = static_cast<AST::MetaItemPath *> (meta_item);
-                       result.push_back (Rust::make_unique<AST::SimplePath> (
-                         path->get_path ()));
+                       result.push_back (path->get_path ());
                      }
                      break;
                      case AST::MetaItem::ItemKind::Word: {
@@ -94,8 +93,7 @@ get_traits_to_derive (AST::Attribute &attr)
                        auto path
                          = static_cast<AST::MetaItemPath *> (current.get ());
 
-                       result.push_back (
-                         make_unique<AST::SimplePath> (path->get_path ()));
+                       result.push_back (path->get_path ());
                      }
                      break;
                    case AST::MetaItem::ItemKind::ListPaths:
@@ -134,7 +132,7 @@ builtin_derive_item (AST::Item &item, const AST::Attribute &derive,
 }
 
 static std::vector<std::unique_ptr<AST::Item>>
-derive_item (AST::Item &item, ProcMacroInvocable &to_derive,
+derive_item (AST::Item &item, AST::SimplePath &to_derive,
             MacroExpander &expander)
 {
   std::vector<std::unique_ptr<AST::Item>> result;
@@ -157,7 +155,7 @@ derive_item (AST::Item &item, ProcMacroInvocable &to_derive,
 }
 
 static std::vector<std::unique_ptr<AST::Item>>
-expand_item_attribute (AST::Item &item, ProcMacroInvocable &name,
+expand_item_attribute (AST::Item &item, AST::SimplePath &name,
                       MacroExpander &expander)
 {
   std::vector<std::unique_ptr<AST::Item>> result;
@@ -269,7 +267,7 @@ ExpandVisitor::expand_inner_items (
                  for (auto &to_derive : traits_to_derive)
                    {
                      auto maybe_builtin = MacroBuiltin::builtins.lookup (
-                       to_derive->as_string ());
+                       to_derive.as_string ());
                      if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin))
                        {
                          auto new_item
@@ -282,7 +280,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));
                        }
@@ -355,7 +353,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr)
                  for (auto &to_derive : traits_to_derive)
                    {
                      auto maybe_builtin = MacroBuiltin::builtins.lookup (
-                       to_derive->as_string ());
+                       to_derive.as_string ());
                      if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin))
                        {
                          auto new_item
@@ -368,7 +366,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 f83de953cb086574191e63a625a21f35585e8216..d52d0707f9733baa564e4fb377e0cb4a220131b4 100644 (file)
@@ -407,7 +407,7 @@ struct MacroExpander
   void import_proc_macros (std::string extern_crate);
 
   template <typename T>
-  AST::Fragment expand_derive_proc_macro (T &item, ProcMacroInvocable &path)
+  AST::Fragment expand_derive_proc_macro (T &item, AST::SimplePath &path)
   {
     ProcMacro::CustomDerive macro;
     if (!mappings->lookup_derive_proc_macro_invocation (path, macro))
@@ -448,7 +448,7 @@ struct MacroExpander
   }
 
   template <typename T>
-  AST::Fragment expand_attribute_proc_macro (T &item, ProcMacroInvocable &path)
+  AST::Fragment expand_attribute_proc_macro (T &item, AST::SimplePath &path)
   {
     ProcMacro::Attribute macro;
     if (!mappings->lookup_attribute_proc_macro_invocation (path, macro))
index aeb813a0416d6388723a2339c9f4b05d5c7f829f..4c70fe045b096f616a795da8e67756635a41bf48 100644 (file)
@@ -1071,7 +1071,7 @@ Mappings::lookup_attribute_proc_macro_def (NodeId id,
 }
 
 void
-Mappings::insert_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
+Mappings::insert_derive_proc_macro_invocation (AST::SimplePath &invoc,
                                               ProcMacro::CustomDerive def)
 {
   auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
@@ -1081,7 +1081,7 @@ Mappings::insert_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
 }
 
 bool
-Mappings::lookup_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
+Mappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc,
                                               ProcMacro::CustomDerive &def)
 {
   auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
@@ -1115,8 +1115,8 @@ Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
 }
 
 void
-Mappings::insert_attribute_proc_macro_invocation (
-  Rust::ProcMacroInvocable &invoc, ProcMacro::Attribute def)
+Mappings::insert_attribute_proc_macro_invocation (AST::SimplePath &invoc,
+                                                 ProcMacro::Attribute def)
 {
   auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
   rust_assert (it == procmacroAttributeInvocations.end ());
@@ -1125,8 +1125,8 @@ Mappings::insert_attribute_proc_macro_invocation (
 }
 
 bool
-Mappings::lookup_attribute_proc_macro_invocation (
-  Rust::ProcMacroInvocable &invoc, ProcMacro::Attribute &def)
+Mappings::lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc,
+                                                 ProcMacro::Attribute &def)
 {
   auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
   if (it == procmacroAttributeInvocations.end ())
index 293a6d129b6358fd04af900074006ff9f1052bb9..5bd9cad7d3ae63b1dff1d76f23d7b137fe227db3 100644 (file)
@@ -28,7 +28,6 @@
 #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 {
@@ -306,18 +305,18 @@ public:
   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,
+  void insert_derive_proc_macro_invocation (AST::SimplePath &invoc,
                                            ProcMacro::CustomDerive def);
 
-  bool lookup_derive_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
+  bool lookup_derive_proc_macro_invocation (AST::SimplePath &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,
+  void insert_attribute_proc_macro_invocation (AST::SimplePath &invoc,
                                               ProcMacro::Attribute def);
-  bool lookup_attribute_proc_macro_invocation (Rust::ProcMacroInvocable &invoc,
+  bool lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc,
                                               ProcMacro::Attribute &def);
 
   void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility);
diff --git a/gcc/rust/util/rust-proc-macro-invocation.h b/gcc/rust/util/rust-proc-macro-invocation.h
deleted file mode 100644 (file)
index b45e013..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#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*/