diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-08-30 09:04:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 09:04:11 +0000 |
commit | be5e11036ef4c292397661a3135825acef9dc2df (patch) | |
tree | 63259be4b68b6672001db9731c5408d5ce701c89 /gcc/rust | |
parent | 64c7a90934f03630356c76d7aa9ba6978ee4e9e6 (diff) | |
parent | 32be5443e30189c9236c62a864e6549804860977 (diff) | |
download | gcc-be5e11036ef4c292397661a3135825acef9dc2df.zip gcc-be5e11036ef4c292397661a3135825acef9dc2df.tar.gz gcc-be5e11036ef4c292397661a3135825acef9dc2df.tar.bz2 |
Merge #1513
1513: macros: Handle matchers properly in repetitions r=CohenArthur a=CohenArthur
This fixes an issue encountered when trying to compile libcore 1.29
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
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 1d57e39..a372e81 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 94d6702..c324c0e 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 |