diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-08-04 14:26:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-04 14:26:10 +0000 |
commit | 15635e68bb65d5ce6963ce0c820719a06ca794cd (patch) | |
tree | a1b2dfdc3aa8c82367b4a71ae5cb3c633bd35292 /gcc/rust/parse | |
parent | 7bdd8599b99a80b5930945bb87d1abffba8ee157 (diff) | |
parent | c4077cc2a8c9ade9bd9b61804d756fcfc2cc9931 (diff) | |
download | gcc-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/parse')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index acc9d06..596a682 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2121,10 +2121,10 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility vis, case SEMICOLON: lexer.skip_token (); - return std::unique_ptr<AST::ModuleNoBody> ( - new AST::ModuleNoBody (std::move (name), std::move (vis), - std::move (outer_attrs), - locus)); // module name? + return std::unique_ptr<AST::Module> ( + new AST::Module (std::move (name), std::move (vis), + std::move (outer_attrs), + locus)); // module name? case LEFT_CURLY: { lexer.skip_token (); @@ -2157,10 +2157,10 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility vis, return nullptr; } - return std::unique_ptr<AST::ModuleBodied> ( - new AST::ModuleBodied (std::move (name), locus, std::move (items), - std::move (vis), std::move (inner_attrs), - std::move (outer_attrs))); // module name? + return std::unique_ptr<AST::Module> ( + new AST::Module (std::move (name), locus, std::move (items), + std::move (vis), std::move (inner_attrs), + std::move (outer_attrs))); // module name? } default: add_error ( |