diff options
author | Tom Tromey <tom@tromey.com> | 2021-12-03 14:45:37 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-12-08 13:20:30 -0700 |
commit | 696d6f4d5c1bc9b36d0402c2393efe62e49392d9 (patch) | |
tree | e0a5c7edfce36b065afc1f443a15906936c44660 /gdb/c-exp.y | |
parent | 621f8c42d3df079ca5781cdb0925c5ec3498f59c (diff) | |
download | gdb-696d6f4d5c1bc9b36d0402c2393efe62e49392d9.zip gdb-696d6f4d5c1bc9b36d0402c2393efe62e49392d9.tar.gz gdb-696d6f4d5c1bc9b36d0402c2393efe62e49392d9.tar.bz2 |
Use for-each more in gdb
There are some loops in gdb that use ARRAY_SIZE (or a wordier
equivalent) to loop over a static array. This patch changes some of
these to use foreach instead.
Regression tested on x86-64 Fedora 34.
Diffstat (limited to 'gdb/c-exp.y')
-rw-r--r-- | gdb/c-exp.y | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 9b4b88a..22cd50a 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -2644,7 +2644,6 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) { int c; int namelen; - unsigned int i; const char *tokstart; bool saw_structop = last_was_structop; @@ -2667,33 +2666,33 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) tokstart = pstate->lexptr; /* See if it is a special token of length 3. */ - for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++) - if (strncmp (tokstart, tokentab3[i].oper, 3) == 0) + for (const auto &token : tokentab3) + if (strncmp (tokstart, token.oper, 3) == 0) { - if ((tokentab3[i].flags & FLAG_CXX) != 0 + if ((token.flags & FLAG_CXX) != 0 && par_state->language ()->la_language != language_cplus) break; - gdb_assert ((tokentab3[i].flags & FLAG_C) == 0); + gdb_assert ((token.flags & FLAG_C) == 0); pstate->lexptr += 3; - yylval.opcode = tokentab3[i].opcode; - return tokentab3[i].token; + yylval.opcode = token.opcode; + return token.token; } /* See if it is a special token of length 2. */ - for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++) - if (strncmp (tokstart, tokentab2[i].oper, 2) == 0) + for (const auto &token : tokentab2) + if (strncmp (tokstart, token.oper, 2) == 0) { - if ((tokentab2[i].flags & FLAG_CXX) != 0 + if ((token.flags & FLAG_CXX) != 0 && par_state->language ()->la_language != language_cplus) break; - gdb_assert ((tokentab2[i].flags & FLAG_C) == 0); + gdb_assert ((token.flags & FLAG_C) == 0); pstate->lexptr += 2; - yylval.opcode = tokentab2[i].opcode; - if (tokentab2[i].token == ARROW) + yylval.opcode = token.opcode; + if (token.token == ARROW) last_was_structop = 1; - return tokentab2[i].token; + return token.token; } switch (c = *tokstart) @@ -2979,18 +2978,18 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) /* Catch specific keywords. */ std::string copy = copy_name (yylval.sval); - for (i = 0; i < sizeof ident_tokens / sizeof ident_tokens[0]; i++) - if (copy == ident_tokens[i].oper) + for (const auto &token : ident_tokens) + if (copy == token.oper) { - if ((ident_tokens[i].flags & FLAG_CXX) != 0 + if ((token.flags & FLAG_CXX) != 0 && par_state->language ()->la_language != language_cplus) break; - if ((ident_tokens[i].flags & FLAG_C) != 0 + if ((token.flags & FLAG_C) != 0 && par_state->language ()->la_language != language_c && par_state->language ()->la_language != language_objc) break; - if ((ident_tokens[i].flags & FLAG_SHADOW) != 0) + if ((token.flags & FLAG_SHADOW) != 0) { struct field_of_this_result is_a_field_of_this; @@ -3009,8 +3008,8 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) /* It is ok to always set this, even though we don't always strictly need to. */ - yylval.opcode = ident_tokens[i].opcode; - return ident_tokens[i].token; + yylval.opcode = token.opcode; + return token.token; } if (*tokstart == '$') |