public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7823] gccrs: resolve: Remove ProcMacroInvocable interface
@ 2024-01-16 18:01 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:01 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:865efbdc2f195b7a9c9cfcb1d3c248c315eafeea
commit r14-7823-g865efbdc2f195b7a9c9cfcb1d3c248c315eafeea
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Jul 13 12:48:18 2023 +0200
gccrs: resolve: Remove ProcMacroInvocable interface
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>
Diff:
---
gcc/rust/ast/rust-ast.h | 13 ++++++-------
gcc/rust/expand/rust-expand-visitor.cc | 22 ++++++++++------------
gcc/rust/expand/rust-macro-expand.h | 4 ++--
gcc/rust/util/rust-hir-map.cc | 12 ++++++------
gcc/rust/util/rust-hir-map.h | 9 ++++-----
gcc/rust/util/rust-proc-macro-invocation.h | 21 ---------------------
6 files changed, 28 insertions(+), 53 deletions(-)
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 8ec707f3afe..f46925a2f22 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -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
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 54075e1fa48..8cbf73dcb08 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -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));
}
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h
index f83de953cb0..d52d0707f97 100644
--- a/gcc/rust/expand/rust-macro-expand.h
+++ b/gcc/rust/expand/rust-macro-expand.h
@@ -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))
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index aeb813a0416..4c70fe045b0 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -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 ())
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 293a6d129b6..5bd9cad7d3a 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -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 ¯o);
bool lookup_attribute_proc_macro_def (NodeId id, ProcMacro::Attribute ¯o);
- 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
index b45e0139a96..00000000000
--- a/gcc/rust/util/rust-proc-macro-invocation.h
+++ /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*/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 18:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:01 [gcc r14-7823] gccrs: resolve: Remove ProcMacroInvocable interface Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).