aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-expand.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-08-04 14:26:10 +0000
committerGitHub <noreply@github.com>2021-08-04 14:26:10 +0000
commit15635e68bb65d5ce6963ce0c820719a06ca794cd (patch)
treea1b2dfdc3aa8c82367b4a71ae5cb3c633bd35292 /gcc/rust/expand/rust-macro-expand.cc
parent7bdd8599b99a80b5930945bb87d1abffba8ee157 (diff)
parentc4077cc2a8c9ade9bd9b61804d756fcfc2cc9931 (diff)
downloadgcc-15635e68bb65d5ce6963ce0c820719a06ca794cd.zip
gcc-15635e68bb65d5ce6963ce0c820719a06ca794cd.tar.gz
gcc-15635e68bb65d5ce6963ce0c820719a06ca794cd.tar.bz2
Merge #605
605: Merge both module classes in one r=philberty a=CohenArthur This PR merges both kinds of Modules (formerly `ModuleBodied` and `ModuleNoBody`) as one class with an enum. This is the [behavior used by rustc](https://github.com/rust-lang/rust/blob/2939249f294dd54a9ce78a8ee1f2922a44e7fb7c/compiler/rustc_ast/src/ast.rs#L2274), where both variants are kept in an enum with one holding a vector of items. This change is important for multiple file parsing: An external mod (`mod foo; // defined in foo.rs or foo/mod.rs`) will see its items expanded during expansion, which occurs after parsing. This means that the previous directive will be "replaced" by `mod foo { <items> }` at the AST level. In order to achieve this, we need to be able to modify a previously parsed instance of an AST element. In rustc, this is done [here](https://github.com/rust-lang/rust/blob/2939249f294dd54a9ce78a8ee1f2922a44e7fb7c/compiler/rustc_expand/src/expand.rs#L1427), where `mod_kind` was previously `ModKind::Unloaded` and becomes `ModKind::Loaded(parsed_items, ...)`. Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.cc')
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc26
1 files changed, 10 insertions, 16 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 28d14ba..0a25471 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -2015,7 +2015,7 @@ public:
"cannot strip block expression in this position - outer "
"attributes not allowed");
}
- void visit (AST::ModuleBodied &module) override
+ void visit (AST::Module &module) override
{
// strip test based on outer attrs
expander.expand_cfg_attrs (module.get_outer_attrs ());
@@ -2025,27 +2025,21 @@ public:
return;
}
- // strip test based on inner attrs
- expander.expand_cfg_attrs (module.get_inner_attrs ());
- if (expander.fails_cfg_with_expand (module.get_inner_attrs ()))
+ // A loaded module might have inner attributes
+ if (module.get_kind () == AST::Module::ModuleKind::LOADED)
{
- module.mark_for_strip ();
- return;
+ // strip test based on inner attrs
+ expander.expand_cfg_attrs (module.get_inner_attrs ());
+ if (expander.fails_cfg_with_expand (module.get_inner_attrs ()))
+ {
+ module.mark_for_strip ();
+ return;
+ }
}
// strip items if required
expand_pointer_allow_strip (module.get_items ());
}
- void visit (AST::ModuleNoBody &module) override
- {
- // strip test based on outer attrs
- expander.expand_cfg_attrs (module.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (module.get_outer_attrs ()))
- {
- module.mark_for_strip ();
- return;
- }
- }
void visit (AST::ExternCrate &crate) override
{
// strip test based on outer attrs