aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/rust-session-manager.cc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2023-03-20 04:17:04 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:28:38 +0100
commitd85089ea28c99eabbee89fd434bea748d1623427 (patch)
treea7f1831df6209fa97509abd8ac30309ce527e39d /gcc/rust/rust-session-manager.cc
parenta7382ca757ed535e7bc74782038104ef5ac59694 (diff)
downloadgcc-d85089ea28c99eabbee89fd434bea748d1623427.zip
gcc-d85089ea28c99eabbee89fd434bea748d1623427.tar.gz
gcc-d85089ea28c99eabbee89fd434bea748d1623427.tar.bz2
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.
Diffstat (limited to 'gcc/rust/rust-session-manager.cc')
-rw-r--r--gcc/rust/rust-session-manager.cc7
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc
index 639b45a..2388964 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 ();