From 4ac118445077fca5153730740d7233b055821746 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Sun, 21 May 2023 18:13:34 +0200 Subject: gccrs: expand: Add derive proc macro draft Add a first draft for derive proc macros based on the attribute expander code. Convert the result back to a parsable entity and parse it. The procedural macro expander was beginning to require almost all functionalities already provided by the macro expander, hence the merge. gcc/rust/ChangeLog: * ast/rust-ast-collector.h: Update enum name to match definition. * expand/rust-expand-visitor.cc (ExpandVisitor::expand_derive): Add call to expander. (ExpandVisitor::expand_outer_attribute): Change call to macro expander. (ExpandVisitor::expand_inner_attribute): Likewise. * expand/rust-expand-visitor.h: Remove const attribute to match visitor declaration. Attach result to the AST. Add condition for item erasure. * expand/rust-proc-macro.h: Add token collector and expansion call. Add lexers and parsers for each proc macro type and uses them to parse macro output. * expand/rust-macro-expand.h (struct MacroExpander): Add functions. * expand/rust-proc-macro.cc (ProcMacroExpander::import_proc_macros): Moved from here... * expand/rust-macro-expand.cc (MacroExpander::import_proc_macros): ... to here. Unify procedural macro parsing under one function. Add a flag to determine whether it originate from a derive macro. (MacroExpander::parse_procmacro_output): Parse macro output to statements. Store an error on parsing failure. * Make-lang.in: Add const_TokenPtr specific lexer. * expand/rust-proc-macro-invoc-lexer.cc: New file. * expand/rust-proc-macro-invoc-lexer.h: New file. * rust-session-manager.cc (Session::expansion): Remove ProcMacroExpander declaration. * ast/rust-ast-fragment.cc (Fragment::Fragment): Add overwrite flag. (Fragment::should_overwrite): Add a getter to determine whether the fragment shall overwrite it's parent or be appended after. * ast/rust-ast-fragment.h: Add flag to declaration. Signed-off-by: Pierre-Emmanuel Patry --- 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 2f18079..939fa64 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -93,6 +93,7 @@ GRS_OBJS = \ rust/rust-derive-copy.o \ rust/rust-proc-macro.o \ rust/rust-macro-invoc-lexer.o \ + rust/rust-proc-macro-invoc-lexer.o \ rust/rust-macro-substitute-ctx.o \ rust/rust-macro-builtins.o \ rust/rust-hir.o \ -- cgit v1.1