diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-03-20 04:17:04 +0100 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-03-25 08:47:56 +0000 |
commit | 267d80f146da679e44aa377f889d717032102268 (patch) | |
tree | 497a17c92f6cca03a8b6fa330921106ac2733187 /gcc/rust/rust-session-manager.cc | |
parent | e10e882ddf3d0f85f36e6645c4637f9725ee2562 (diff) | |
download | gcc-267d80f146da679e44aa377f889d717032102268.zip gcc-267d80f146da679e44aa377f889d717032102268.tar.gz gcc-267d80f146da679e44aa377f889d717032102268.tar.bz2 |
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.
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r-- | gcc/rust/rust-session-manager.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index ce1fdbb..66863f4 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -40,6 +40,8 @@ #include "rust-extern-crate.h" #include "rust-attributes.h" #include "rust-early-name-resolver.h" +#include "rust-attribute-visitor.h" +#include "rust-expand-visitor.h" #include "diagnostic.h" #include "input.h" @@ -846,10 +848,9 @@ Session::expansion (AST::Crate &crate) while (!fixed_point_reached && iterations < cfg.recursion_limit) { - /* We need to name resolve macros and imports here */ + AttrVisitor ().go (crate); Resolver::EarlyNameResolver ().go (crate); - - expander.expand_crate (); + ExpandVisitor (expander).go (crate); fixed_point_reached = !expander.has_changed (); expander.reset_changed_state (); |