diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-08 13:28:46 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-08 13:33:19 +0100 |
commit | d2a6a5eef46296a8b5b2f4c39059a7d55ff22941 (patch) | |
tree | 076c5327a3ab63898edec891d2b8fab9c1cffd8a /gcc | |
parent | 865b6090a8f8981cdfc050ea2ee44abbe92de141 (diff) | |
download | gcc-d2a6a5eef46296a8b5b2f4c39059a7d55ff22941.zip gcc-d2a6a5eef46296a8b5b2f4c39059a7d55ff22941.tar.gz gcc-d2a6a5eef46296a8b5b2f4c39059a7d55ff22941.tar.bz2 |
macros: Allow any delimiters for invocation
It is not necessary for macro invocations to match the delimiters used
in the matcher. A matcher using parentheses can be invoked with curlies
or brackets, as well as any other combination(curlies matcher can be
invoked with parentheses or brackets)
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 22 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/macro10.rs | 11 |
2 files changed, 25 insertions, 8 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index b15e783..84a526c 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -3493,26 +3493,30 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser, return false; } + auto delimiter = parser.peek_current_token (); + // this is used so we can check that we delimit the stream correctly. - switch (matcher.get_delim_type ()) + switch (delimiter->get_id ()) { - case AST::DelimType::PARENS: { + case LEFT_PAREN: { if (!parser.skip_token (LEFT_PAREN)) return false; } break; - case AST::DelimType::SQUARE: { + case LEFT_SQUARE: { if (!parser.skip_token (LEFT_SQUARE)) return false; } break; - case AST::DelimType::CURLY: { + case LEFT_CURLY: { if (!parser.skip_token (LEFT_CURLY)) return false; } break; + default: + gcc_unreachable (); } const MacroInvocLexer &source = parser.get_token_source (); @@ -3566,25 +3570,27 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser, } } - switch (matcher.get_delim_type ()) + switch (delimiter->get_id ()) { - case AST::DelimType::PARENS: { + case LEFT_PAREN: { if (!parser.skip_token (RIGHT_PAREN)) return false; } break; - case AST::DelimType::SQUARE: { + case LEFT_SQUARE: { if (!parser.skip_token (RIGHT_SQUARE)) return false; } break; - case AST::DelimType::CURLY: { + case LEFT_CURLY: { if (!parser.skip_token (RIGHT_CURLY)) return false; } break; + default: + gcc_unreachable (); } return true; diff --git a/gcc/testsuite/rust/compile/macro10.rs b/gcc/testsuite/rust/compile/macro10.rs new file mode 100644 index 0000000..3f1453e --- /dev/null +++ b/gcc/testsuite/rust/compile/macro10.rs @@ -0,0 +1,11 @@ +// { dg-additional-options "-w" } +macro_rules! foo { + {} => { + 15 + }; +} + +fn main() { + let a = foo!(); + let b = foo![]; +} |