diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-28 17:26:50 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:04:32 +0100 |
commit | ad1f51084946125ceb33a0086d42fac0f42460be (patch) | |
tree | f55a270e862aae2bae23ff28c5e7e20d53800096 | |
parent | 3afb921cdaeea68ae11096844fefaf743f64db4b (diff) | |
download | gcc-ad1f51084946125ceb33a0086d42fac0f42460be.zip gcc-ad1f51084946125ceb33a0086d42fac0f42460be.tar.gz gcc-ad1f51084946125ceb33a0086d42fac0f42460be.tar.bz2 |
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 <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/ast/rust-ast.cc | 9 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 2 | ||||
-rw-r--r-- | 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 eb133aa..434c276 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 7c2e122..08b511f 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 8cbf73d..77dfdcb 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -26,16 +26,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) { auto &segments = attr.get_path ().get_segments (); @@ -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 ()); |