From: Pierre-Emmanuel Patry Date: Thu, 13 Jul 2023 10:48:18 +0000 (+0200) Subject: gccrs: resolve: Remove ProcMacroInvocable interface X-Git-Tag: basepoints/gcc-15~2316 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=865efbdc2f195b7a9c9cfcb1d3c248c315eafeea;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 8ec707f3afe9..f46925a2f22a 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 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 54075e1fa48c..8cbf73dcb086 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> +static std::vector get_traits_to_derive (AST::Attribute &attr) { - std::vector> result; + std::vector 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 (meta_item); - result.push_back (Rust::make_unique ( - 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 (current.get ()); - result.push_back ( - make_unique (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> -derive_item (AST::Item &item, ProcMacroInvocable &to_derive, +derive_item (AST::Item &item, AST::SimplePath &to_derive, MacroExpander &expander) { std::vector> result; @@ -157,7 +155,7 @@ derive_item (AST::Item &item, ProcMacroInvocable &to_derive, } static std::vector> -expand_item_attribute (AST::Item &item, ProcMacroInvocable &name, +expand_item_attribute (AST::Item &item, AST::SimplePath &name, MacroExpander &expander) { std::vector> 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 f83de953cb08..d52d0707f973 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 - 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 - 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 aeb813a0416d..4c70fe045b09 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 293a6d129b63..5bd9cad7d3ae 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 b45e0139a967..000000000000 --- 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*/