]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: expand: Add stub function for attribute expansion
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 30 Mar 2023 18:40:07 +0000 (20:40 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:45 +0000 (18:28 +0100)
Add a stub function and utility functions that should be called on some
nodes to expand attribute procedural macros.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::expand_outer_attribute):
Stub for a single attribute expansion.
(ExpandVisitor::visit_outer_attrs): Visit the attributes to
expand on a given item.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-expand-visitor.h

index b2d1cf3e0c3d7bfc013b060792c7fa396d1ed901..f93accdeb4060f28e1a1dd580726e9832d2533b7 100644 (file)
@@ -1349,6 +1349,33 @@ ExpandVisitor::visit (AST::BareFunctionType &type)
     visit (type.get_return_type ());
 }
 
+template <typename T>
+void
+ExpandVisitor::expand_outer_attribute (T &item, AST::SimplePath &path)
+{
+  // FIXME: Implement outer attribute expansion
+}
+
+template <typename T>
+void
+ExpandVisitor::visit_outer_attrs (T &item, std::vector<AST::Attribute> &attrs)
+{
+  for (auto it = attrs.begin (); it != attrs.end (); /* erase => No increment*/)
+    {
+      auto current = *it;
+
+      it = attrs.erase (it);
+      expand_outer_attribute (item, current.get_path ());
+    }
+}
+
+template <typename T>
+void
+ExpandVisitor::visit_outer_attrs (T &item)
+{
+  visit_outer_attrs (item, item.get_outer_attrs ());
+}
+
 template <typename T>
 void
 ExpandVisitor::expand_inner_attribute (T &item, AST::SimplePath &path)
index 66dc1870628c4cefa9788756425fe0df6239052e..e0ff37cf1750d0d4675e14c65e702431379d3c69 100644 (file)
@@ -313,6 +313,14 @@ public:
   void visit (AST::InferredType &) override;
   void visit (AST::BareFunctionType &type) override;
 
+  template <typename T>
+  void expand_outer_attribute (T &item, AST::SimplePath &path);
+
+  template <typename T>
+  void visit_outer_attrs (T &item, std::vector<AST::Attribute> &attrs);
+
+  template <typename T> void visit_outer_attrs (T &item);
+
   template <typename T>
   void expand_inner_attribute (T &item, AST::SimplePath &Path);