Hello- I would like please to follow up on this patch submitted for PR53431 here: https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586191.html
However, it was suggested on the PR that part of it could be split into a separate simpler patch. I have now done that, and also made a few tweaks to the first version at the same time, so may I please request that you review this version 2 instead? This email contains the first smaller cleanup patch, and the next email contains the main part of it. Thanks very much. bootstrap and regtest were performed on x86-64 Linux, all tests look the same before + after, plus the new passing testcases. FAIL 112 112 PASS 528007 528042 UNSUPPORTED 14888 14888 UNTESTED 132 132 XFAIL 3238 3238 XPASS 17 17 -Lewis
From: Lewis Hyatt <lhy...@gmail.com> Date: Thu, 23 Dec 2021 17:03:04 -0500 Subject: [PATCH] c++: Minor cleanup in parser.c The code to determine whether a given token starts a module directive is currently repeated in 4 places in parser.c. I am about to submit a patch that needs to add it in a 5th place, so since the code is not completely trivial (needing to check for 3 different token types), it seems worthwhile to factor this logic into its own function. gcc/cp/ChangeLog: * parser.c (cp_token_is_module_directive): New function refactoring common code. (cp_parser_skip_to_closing_parenthesis_1): Use the new function. (cp_parser_skip_to_end_of_statement): Likewise. (cp_parser_skip_to_end_of_block_or_statement): Likewise. (cp_parser_declaration): Likewise. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 33fb40a5b59..9b7446655be 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -629,6 +629,16 @@ cp_lexer_alloc (void) return lexer; } +/* Return TRUE if token is the start of a module declaration that will be + terminated by a CPP_PRAGMA_EOL token. */ +static inline bool +cp_token_is_module_directive (cp_token *token) +{ + return token->keyword == RID__EXPORT + || token->keyword == RID__MODULE + || token->keyword == RID__IMPORT; +} + /* Create a new main C++ lexer, the lexer that gets tokens from the preprocessor. */ @@ -3805,9 +3815,7 @@ cp_parser_skip_to_closing_parenthesis_1 (cp_parser *parser, break; case CPP_KEYWORD: - if (token->keyword != RID__EXPORT - && token->keyword != RID__MODULE - && token->keyword != RID__IMPORT) + if (!cp_token_is_module_directive (token)) break; /* FALLTHROUGH */ @@ -3908,9 +3916,7 @@ cp_parser_skip_to_end_of_statement (cp_parser* parser) break; case CPP_KEYWORD: - if (token->keyword != RID__EXPORT - && token->keyword != RID__MODULE - && token->keyword != RID__IMPORT) + if (!cp_token_is_module_directive (token)) break; /* FALLTHROUGH */ @@ -3997,9 +4003,7 @@ cp_parser_skip_to_end_of_block_or_statement (cp_parser* parser) break; case CPP_KEYWORD: - if (token->keyword != RID__EXPORT - && token->keyword != RID__MODULE - && token->keyword != RID__IMPORT) + if (!cp_token_is_module_directive (token)) break; /* FALLTHROUGH */ @@ -14860,9 +14864,7 @@ cp_parser_declaration (cp_parser* parser, tree prefix_attrs) else cp_parser_module_export (parser); } - else if (token1->keyword == RID__EXPORT - || token1->keyword == RID__IMPORT - || token1->keyword == RID__MODULE) + else if (cp_token_is_module_directive (token1)) { bool exporting = token1->keyword == RID__EXPORT; cp_token *next = exporting ? token2 : token1;