gccrs: Add expansion pass for the Rust front-end
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 23 Aug 2022 15:15:22 +0000 (16:15 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 13 Dec 2022 13:00:04 +0000 (14:00 +0100)
commit1841081a8a306c1a220694a5ddb3a927cb4b2db3
tree5ed5a29b6188aa40af30a4ab469306e9a8b1bfc0
parent32c8fb0eeafb1ec47f75242cb28171fcbdbf6e8e
gccrs: Add expansion pass for the Rust front-end

The expansion pass is responsible for two actions on our AST:

1. Expanding macro calls
2. Performing conditional compilation

Calls to macros should be checked and expanded into an AST fragment based on
the context they've been called in. This is similar to token substitution, with
a lot of intricacies and checks being performed. A single invocation can result
in an AST fragment containing multiple statements or multiple expressions,
which need to be handled as well. Furthermore, Rust macros can contain
repetitions relying on Kleine operators, similar to regular expression
patterns, that also need to be expanded properly.

Finally, Rust code can be hidden behind `cfg` directives, which allow the user
to perform conditional compilation. If a `cfg` predicate is not met, the
expression or statement it refers to should be marked for strip and removed
from the AST.

gcc/rust/
* expand/rust-attribute-visitor.cc: New.
* expand/rust-attribute-visitor.h: New.
* expand/rust-macro-builtins.cc: New.
* expand/rust-macro-builtins.h: New.
* expand/rust-macro-expand.cc: New.
* expand/rust-macro-expand.h: New.
* expand/rust-macro-invoc-lexer.cc: New.
* expand/rust-macro-invoc-lexer.h: New.
* expand/rust-macro-substitute-ctx.cc: New.
* expand/rust-macro-substitute-ctx.h: New.

Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Joel Phillips <simplytheother@gmail.com>
Signed-off-by: Joel Phillips <simplytheother@gmail.com>
gcc/rust/expand/rust-attribute-visitor.cc [new file with mode: 0644]
gcc/rust/expand/rust-attribute-visitor.h [new file with mode: 0644]
gcc/rust/expand/rust-macro-builtins.cc [new file with mode: 0644]
gcc/rust/expand/rust-macro-builtins.h [new file with mode: 0644]
gcc/rust/expand/rust-macro-expand.cc [new file with mode: 0644]
gcc/rust/expand/rust-macro-expand.h [new file with mode: 0644]
gcc/rust/expand/rust-macro-invoc-lexer.cc [new file with mode: 0644]
gcc/rust/expand/rust-macro-invoc-lexer.h [new file with mode: 0644]
gcc/rust/expand/rust-macro-substitute-ctx.cc [new file with mode: 0644]
gcc/rust/expand/rust-macro-substitute-ctx.h [new file with mode: 0644]