public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Lewis Hyatt <lhyatt@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1399] c++: Minor cleanup in parser.cc Date: Fri, 1 Jul 2022 21:33:51 +0000 (GMT) [thread overview] Message-ID: <20220701213351.2DD5B3858C51@sourceware.org> (raw) https://gcc.gnu.org/g:ff64a8c951995cb1214b4d2864a4bd553b60f249 commit r13-1399-gff64a8c951995cb1214b4d2864a4bd553b60f249 Author: Lewis Hyatt <lhyatt@gmail.com> Date: Fri Jul 1 13:53:34 2022 -0400 c++: Minor cleanup in parser.cc The code to determine whether a given token starts a module directive is currently repeated in 4 places in parser.cc. 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.cc (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: --- gcc/cp/parser.cc | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 212ed1445d5..6b3763bca53 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -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. */ @@ -3833,9 +3843,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 */ @@ -3936,9 +3944,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 */ @@ -4025,9 +4031,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 */ @@ -14958,9 +14962,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;
reply other threads:[~2022-07-01 21:33 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220701213351.2DD5B3858C51@sourceware.org \ --to=lhyatt@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).