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/go-exp.y | |
parent | 621f8c42d3df079ca5781cdb0925c5ec3498f59c (diff) | |
download | fsf-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/go-exp.y')
-rw-r--r-- | gdb/go-exp.y | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/gdb/go-exp.y b/gdb/go-exp.y index aaa6517..209e0a7 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1018,7 +1018,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; @@ -1030,23 +1029,23 @@ lex_one_token (struct parser_state *par_state) tokstart = par_state->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) { par_state->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) { par_state->lexptr += 2; - yylval.opcode = tokentab2[i].opcode; + yylval.opcode = token.opcode; /* NOTE: -> doesn't exist in Go, so we don't need to watch for setting last_was_structop here. */ - return tokentab2[i].token; + return token.token; } switch (c = *tokstart) @@ -1270,13 +1269,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 == '$') |