]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: expand: Add new ExpandVisitor class
authorArthur Cohen <arthur.cohen@embecosm.com>
Mon, 20 Mar 2023 03:17:04 +0000 (04:17 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:28:38 +0000 (18:28 +0100)
commitd85089ea28c99eabbee89fd434bea748d1623427
treea7f1831df6209fa97509abd8ac30309ce527e39d
parenta7382ca757ed535e7bc74782038104ef5ac59694
gccrs: expand: Add new ExpandVisitor class

This class takes care of actually performing the macro expansion by calling
into the MacroExpander for each node of a given AST, leaving the job of
cfg-stripping nodes to the AttrVisitor.

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* expand/rust-attribute-visitor.cc (AttrVisitor::go): Visit all items of a
crate.
(AttrVisitor::expand_struct_fields): Do not perform macro expansion anymore.
(AttrVisitor::expand_function_params): Likewise.
(AttrVisitor::expand_generic_args): Likewise.
(AttrVisitor::expand_qualified_path_type): Likewise.
(AttrVisitor::expand_self_param): Likewise.
(AttrVisitor::expand_trait_function_decl): Likewise.
(AttrVisitor::expand_trait_method_decl): Likewise.
(AttrVisitor::visit): Likewise.
(AttrVisitor::maybe_expand_expr): Remove function.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-attribute-visitor.h: Do not keep MacroExpander inside AttrVisitor
anymore.
* expand/rust-macro-expand.h (struct MacroExpander): Turn ContextType into an
enum class for more type safety.
* expand/rust-macro-expand.cc (MacroExpander::expand_crate): Use new ContextType
API.
* rust-session-manager.cc (Session::expansion): Call into ExpandVisitor.
* expand/rust-expand-visitor.cc: New file.
* expand/rust-expand-visitor.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/macro49.rs: New test.
* rust/compile/macro50.rs: New test.
gcc/rust/Make-lang.in
gcc/rust/expand/rust-attribute-visitor.cc
gcc/rust/expand/rust-attribute-visitor.h
gcc/rust/expand/rust-expand-visitor.cc [new file with mode: 0644]
gcc/rust/expand/rust-expand-visitor.h [new file with mode: 0644]
gcc/rust/expand/rust-macro-expand.cc
gcc/rust/expand/rust-macro-expand.h
gcc/rust/rust-session-manager.cc
gcc/testsuite/rust/compile/macro49.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/macro50.rs [new file with mode: 0644]