From d85089ea28c99eabbee89fd434bea748d1623427 Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Mon, 20 Mar 2023 04:17:04 +0100 Subject: 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 | 1 + 1 file changed, 1 insertion(+) (limited to 'gcc/rust/Make-lang.in') diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 8f48390..083a44e 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -82,6 +82,7 @@ GRS_OBJS = \ rust/rust-compile-resolve-path.o \ rust/rust-macro-expand.o \ rust/rust-attribute-visitor.o \ + rust/rust-expand-visitor.o \ rust/rust-macro-invoc-lexer.o \ rust/rust-macro-substitute-ctx.o \ rust/rust-macro-builtins.o \ -- cgit v1.1