public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] expand: Add inner attribute expansion stubs
@ 2023-04-06 21:37 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-04-06 21:37 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:fe11b51bd316141618b41292e74b4439b02860ac
commit fe11b51bd316141618b41292e74b4439b02860ac
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Mar 30 16:35:53 2023 +0200
expand: Add inner attribute expansion stubs
Add function stubs for inner attribute proc macros expansion.
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to inner attribute stub.
(ExpandVisitor::expand_inner_attribute): Expand one single
attribute.
(ExpandVisitor::visit_inner_using_attrs): Expand a given item
using a vector of attributes.
(ExpandVisitor::visit_inner_attrs): Visit inner attributes of a
given item.
* expand/rust-expand-visitor.h: Add function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/expand/rust-expand-visitor.cc | 41 ++++++++++++++++++++++++++++++++--
gcc/rust/expand/rust-expand-visitor.h | 8 +++++++
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 96619482467..b2d1cf3e0c3 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -762,8 +762,11 @@ void
ExpandVisitor::visit (AST::Module &module)
{
if (module.get_kind () == AST::Module::ModuleKind::LOADED)
- for (auto &item : module.get_items ())
- visit (item);
+ {
+ visit_inner_attrs (module);
+ for (auto &item : module.get_items ())
+ visit (item);
+ }
}
void
@@ -789,6 +792,8 @@ ExpandVisitor::visit (AST::UseDeclaration &use_decl)
void
ExpandVisitor::visit (AST::Function &function)
{
+ visit_inner_using_attrs (function,
+ function.get_definition ()->get_inner_attrs ());
for (auto ¶m : function.get_generic_params ())
visit (param);
@@ -954,6 +959,7 @@ ExpandVisitor::visit (AST::Trait &trait)
void
ExpandVisitor::visit (AST::InherentImpl &impl)
{
+ visit_inner_attrs (impl);
// just expand sub-stuff - can't actually strip generic params themselves
for (auto &generic : impl.get_generic_params ())
visit (generic);
@@ -978,6 +984,7 @@ ExpandVisitor::visit (AST::InherentImpl &impl)
void
ExpandVisitor::visit (AST::TraitImpl &impl)
{
+ visit_inner_attrs (impl);
// just expand sub-stuff - can't actually strip generic params themselves
for (auto ¶m : impl.get_generic_params ())
visit (param);
@@ -1035,6 +1042,7 @@ ExpandVisitor::visit (AST::ExternalFunctionItem &item)
void
ExpandVisitor::visit (AST::ExternBlock &block)
{
+ visit_inner_attrs (block);
std::function<std::unique_ptr<AST::ExternalItem> (AST::SingleASTNode)>
extractor
= [] (AST::SingleASTNode node) { return node.take_external_item (); };
@@ -1341,6 +1349,35 @@ ExpandVisitor::visit (AST::BareFunctionType &type)
visit (type.get_return_type ());
}
+template <typename T>
+void
+ExpandVisitor::expand_inner_attribute (T &item, AST::SimplePath &path)
+{
+ // TODO: Warn about instability ?
+ // FIXME: Implement expansion for that particular path
+}
+
+template <typename T>
+void
+ExpandVisitor::visit_inner_using_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_inner_attribute (item, current.get_path ());
+ }
+}
+
+template <typename T>
+void
+ExpandVisitor::visit_inner_attrs (T &item)
+{
+ visit_inner_using_attrs (item, item.get_inner_attrs ());
+}
+
template <typename T>
void
ExpandVisitor::expand_derive (const T &item,
diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h
index 613251dfbbe..66dc1870628 100644
--- a/gcc/rust/expand/rust-expand-visitor.h
+++ b/gcc/rust/expand/rust-expand-visitor.h
@@ -313,6 +313,14 @@ public:
void visit (AST::InferredType &) override;
void visit (AST::BareFunctionType &type) override;
+ template <typename T>
+ void expand_inner_attribute (T &item, AST::SimplePath &Path);
+
+ template <typename T>
+ void visit_inner_using_attrs (T &item, std::vector<AST::Attribute> &attrs);
+
+ template <typename T> void visit_inner_attrs (T &item);
+
bool is_derive (AST::Attribute &attr);
template <typename T>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-06 21:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-06 21:37 [gcc/devel/rust/master] expand: Add inner attribute expansion stubs Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).