diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-02-16 17:55:27 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-02-17 13:28:25 +0000 |
commit | 2c03f34027234cbd0e235de84ac04871ecf7b8f0 (patch) | |
tree | 6aa94ea90238e053c7d4861b68b26e6f31a9b70e /gcc/rust/resolve/rust-ast-resolve-expr.h | |
parent | ef626302f776b91db4848d8ca6e0e905e3b694a2 (diff) | |
download | gcc-2c03f34027234cbd0e235de84ac04871ecf7b8f0.zip gcc-2c03f34027234cbd0e235de84ac04871ecf7b8f0.tar.gz gcc-2c03f34027234cbd0e235de84ac04871ecf7b8f0.tar.bz2 |
Add initial support for macro expansion
This is the first pass at implementing macros more testcases are needed.
This does not support repetition matchers but it supports simple
declarative macros and transcribes them. The approach taken here is that
we reuse our existing parser to call the apropriate functions as specified
as part of the MacroFragmentType enum if the parser does not have errors
parsing that item then it must be a match.
Then once we match a rule we have a map of the token begin/end offsets
for each fragment match, this is then used to adjust and create a new token
stream for the macro rule definition so that when we feed it to the parser
the tokens are already substituted. The resulting expression or item is
then attached to the respective macro invocation and this is then name
resolved and used for hir lowering.
Fixes #17 #22
Addresses #573
Diffstat (limited to 'gcc/rust/resolve/rust-ast-resolve-expr.h')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-expr.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h index b7b8646..4ccb72b 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.h +++ b/gcc/rust/resolve/rust-ast-resolve-expr.h @@ -70,6 +70,16 @@ public: expr->accept_vis (resolver); }; + void visit (AST::MacroInvocation &expr) override + { + AST::ASTFragment &fragment = expr.get_fragment (); + + // FIXME + // this assertion might go away, maybe on failure's to expand a macro? + rust_assert (!fragment.get_nodes ().empty ()); + fragment.get_nodes ().at (0).accept_vis (*this); + } + void visit (AST::TupleIndexExpr &expr) override { resolve_expr (expr.get_tuple_expr ().get (), expr.get_node_id ()); |