diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-29 12:51:33 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-01-31 14:16:49 +0100 |
commit | 1fed030c16519c0ebedb4cf0c6cebaa9ffa32e66 (patch) | |
tree | eb4c5bd6a99ad154f0d395260a59292acfafb157 /gcc/rust | |
parent | f7014b28b81f43f62086d75222a9cfe7ca562b27 (diff) | |
download | gcc-1fed030c16519c0ebedb4cf0c6cebaa9ffa32e66.zip gcc-1fed030c16519c0ebedb4cf0c6cebaa9ffa32e66.tar.gz gcc-1fed030c16519c0ebedb4cf0c6cebaa9ffa32e66.tar.bz2 |
gccrs: macros: Handle matchers properly in repetitions
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::match_matcher): Handle
fragments differently based on whether or not we are currently trying
to match a matcher in a repetition context.
(MacroExpander::match_n_matches): Use new `in_repetition` argument
properly when calling `match_matcher`.
* expand/rust-macro-expand.h (MacroExpander::match_matcher): Allow
passing extra `in_repetition` bool argument
gcc/testsuite/ChangeLog:
* rust/compile/macro43.rs: New test.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 14 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index a214ca9..df258bd 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -435,7 +435,7 @@ MacroExpander::match_fragment (Parser<MacroInvocLexer> &parser, bool MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser, - AST::MacroMatcher &matcher) + AST::MacroMatcher &matcher, bool in_repetition) { if (depth_exceeds_recursion_limit ()) { @@ -485,8 +485,12 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser, // matched fragment get the offset in the token stream size_t offs_end = source.get_offs (); - sub_stack.insert_metavar ( - MatchedFragment (fragment->get_ident (), offs_begin, offs_end)); + if (in_repetition) + sub_stack.append_fragment ( + MatchedFragment (fragment->get_ident (), offs_begin, offs_end)); + else + sub_stack.insert_metavar ( + MatchedFragment (fragment->get_ident (), offs_begin, offs_end)); } break; @@ -509,7 +513,7 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser, AST::MacroMatcher *m = static_cast<AST::MacroMatcher *> (match.get ()); expansion_depth++; - if (!match_matcher (parser, *m)) + if (!match_matcher (parser, *m, in_repetition)) { expansion_depth--; return false; @@ -619,7 +623,7 @@ MacroExpander::match_n_matches (Parser<MacroInvocLexer> &parser, case AST::MacroMatch::MacroMatchType::Matcher: { AST::MacroMatcher *m = static_cast<AST::MacroMatcher *> (match.get ()); - valid_current_match = match_matcher (parser, *m); + valid_current_match = match_matcher (parser, *m, true); } break; } diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index 97a0269..bef1402 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -273,7 +273,7 @@ struct MacroExpander AST::MacroMatchRepetition &rep); bool match_matcher (Parser<MacroInvocLexer> &parser, - AST::MacroMatcher &matcher); + AST::MacroMatcher &matcher, bool in_repetition = false); /** * Match any amount of matches |