]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Make is_builtin a member function
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Fri, 28 Jul 2023 15:26:50 +0000 (17:26 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:04:32 +0000 (19:04 +0100)
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>
gcc/rust/ast/rust-ast.cc
gcc/rust/ast/rust-ast.h
gcc/rust/expand/rust-expand-visitor.cc

index eb133aaec244b2d8b83fb037722fb47f3ebcc48c..434c2768bc57b726927dcf2f8ed614136e861d89 100644 (file)
@@ -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)
index 7c2e1224a236e65d88e8757a83d52c2268b15061..08b511f4019abafe94a1c303e087cfbecb98ecf8 100644 (file)
@@ -517,6 +517,8 @@ public:
       inner_attribute (inner_attribute)
   {}
 
+  bool is_derive () const;
+
   // default destructor
   ~Attribute () = default;
 
index 8cbf73dcb086d283b890c986803de1bb8ea6d8d5..77dfdcb6d6a1404e55130136e8ab8dbb8a819553 100644 (file)
 
 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 ());