-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ast: Check if the #[derive]
attribute is used on a compatible item
#2904
base: master
Are you sure you want to change the base?
ast: Check if the #[derive]
attribute is used on a compatible item
#2904
Conversation
#[derive]
attribute is used on a compatible item
b5d02ac
to
21079c3
Compare
gcc/rust/ChangeLog: * ast/rust-ast.h: Create new `Item::Kind` enum and new `Item::get_item_kind` method * ast/rust-item.h: Implement `Item::get_item_kind` method * ast/rust-macro.h: Implement `Item::get_item_kind` method * expand/rust-derive.cc (DeriveVisitor::derive): Check that `#[derive]` is applied on compatible item * expand/rust-expand-visitor.cc: Check if returned item is null before putting it into the item list gcc/testsuite/ChangeLog: * rust/compile/derive_macro9.rs: New test.
21079c3
to
b1d0557
Compare
So, seems like I'm stuck: I think the attribute visitor is overloading the methods wrongly, making them not go through the code recursively. If so, the simplest way would be for the original ASTVisitor to have two sets of methods:
Again, maybe I'm completely misunderstanding how it works and sorry for the noise. |
Not entirely sure I understand what you mean. Right now we use
don't worry, I'm glad we've got people challenging the implementation |
Let me try to explain a bit more: currently, if we want to recurse through the whole AST, we need to call the right methods in every implementations of the The second set of methods will be in charge of going through the AST whereas the first one will only be used when you're interested into a particular item. Now about stopping the recursion, we can make the overloadable methods return a class ASTVisitor
{
public:
virtual void walk (AST::Crate &crate);
protected:
virtual void walk (AST::StructStruct &struct_item) final {
if visit (struct_item) {
visit_outer_attrs (struct_item);
visit (struct_item.get_visibility ());
for (auto &generic : struct_item.get_generic_params ())
visit (generic);
if (struct_item.has_where_clause ())
visit (struct_item.get_where_clause ());
for (auto &field : struct_item.get_fields ())
visit (field);
}
}
virtual bool visit (AST::StructStruct &struct_item) override; No need to worry about overloading incorrectly |
Ok, It's clearer. Usually we call I recognize having two different functions instead of overly relying on overloading would be clearer though. |
If it sounds good to you, I can implement it. |
Fixes #2154.
Second commit is a small typo I encountered in the function I was working on.