aboutsummaryrefslogtreecommitdiff
path: root/gdb/d-exp.y
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-12-03 14:45:37 -0700
committerTom Tromey <tom@tromey.com>2021-12-08 13:20:30 -0700
commit696d6f4d5c1bc9b36d0402c2393efe62e49392d9 (patch)
treee0a5c7edfce36b065afc1f443a15906936c44660 /gdb/d-exp.y
parent621f8c42d3df079ca5781cdb0925c5ec3498f59c (diff)
downloadfsf-binutils-gdb-696d6f4d5c1bc9b36d0402c2393efe62e49392d9.zip
fsf-binutils-gdb-696d6f4d5c1bc9b36d0402c2393efe62e49392d9.tar.gz
fsf-binutils-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/d-exp.y')
-rw-r--r--gdb/d-exp.y25
1 files changed, 12 insertions, 13 deletions
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 1d11d9f..637bc8c 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -1027,7 +1027,6 @@ lex_one_token (struct parser_state *par_state)
{
int c;
int namelen;
- unsigned int i;
const char *tokstart;
int saw_structop = last_was_structop;
@@ -1039,21 +1038,21 @@ lex_one_token (struct parser_state *par_state)
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)
{
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)
{
pstate->lexptr += 2;
- yylval.opcode = tokentab2[i].opcode;
- return tokentab2[i].token;
+ yylval.opcode = token.opcode;
+ return token.token;
}
switch (c = *tokstart)
@@ -1274,13 +1273,13 @@ lex_one_token (struct parser_state *par_state)
/* 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)
{
/* 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 == '$')