diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 13 | ||||
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.cc | 22 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 4 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 12 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 9 | ||||
-rw-r--r-- | 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 8ec707f..f46925a 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 54075e1..8cbf73d 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 f83de95..d52d070 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 aeb813a..4c70fe0 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 293a6d1..5bd9cad 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 b45e013..0000000 --- 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*/ |