From ad1f51084946125ceb33a0086d42fac0f42460be Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Fri, 28 Jul 2023 17:26:50 +0200 Subject: [PATCH] gccrs: Make is_builtin a member function This function will be used in the multiple other places, therefore we should make it easily usable from there. gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::is_derive): Add member function. * ast/rust-ast.h: Likewise. * expand/rust-expand-visitor.cc (is_derive): Remove old function. (ExpandVisitor::expand_inner_stmts): Update function call. (ExpandVisitor::visit_inner_using_attrs): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast.cc | 9 +++++++++ gcc/rust/ast/rust-ast.h | 2 ++ gcc/rust/expand/rust-expand-visitor.cc | 16 +++------------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index eb133aaec244..434c2768bc57 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -81,6 +81,15 @@ Attribute::as_string () const return path_str + attr_input->as_string (); } +bool +Attribute::is_derive () const +{ + return has_attr_input () + && get_attr_input ().get_attr_input_type () + == AST::AttrInput::TOKEN_TREE + && get_path () == "derive"; +} + // Copy constructor must deep copy attr_input as unique pointer Attribute::Attribute (Attribute const &other) : path (other.path), locus (other.locus) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 7c2e1224a236..08b511f4019a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -517,6 +517,8 @@ public: inner_attribute (inner_attribute) {} + bool is_derive () const; + // default destructor ~Attribute () = default; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 8cbf73dcb086..77dfdcb6d6a1 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -25,16 +25,6 @@ namespace Rust { -bool -is_derive (AST::Attribute &attr) -{ - auto path = attr.get_path (); - return attr.has_attr_input () - && attr.get_attr_input ().get_attr_input_type () - == AST::AttrInput::TOKEN_TREE - && path == "derive"; -} - bool is_builtin (AST::Attribute &attr) { @@ -258,7 +248,7 @@ ExpandVisitor::expand_inner_items ( { auto current = *attr_it; - if (is_derive (current)) + if (current.is_derive ()) { current.parse_attr_to_meta_item (); attr_it = attrs.erase (attr_it); @@ -345,7 +335,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr) { auto current = *attr_it; - if (is_derive (current)) + if (current.is_derive ()) { attr_it = attrs.erase (attr_it); // Get traits to derive in the current attribute @@ -1683,7 +1673,7 @@ ExpandVisitor::visit_inner_using_attrs (T &item, { auto current = *it; - if (!is_builtin (current) && !is_derive (current)) + if (!is_builtin (current) && !current.is_derive ()) { it = attrs.erase (it); expand_inner_attribute (item, current.get_path ()); -- 2.47.2