public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom Tromey <tromey@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] Remove null sentinel from 'attributes'
Date: Mon,  4 Apr 2022 18:50:20 +0000 (GMT)	[thread overview]
Message-ID: <20220404185020.840D73858D37@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c3f2a3738a3603f51e3621504d8207767526add9

commit c3f2a3738a3603f51e3621504d8207767526add9
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Feb 22 11:05:41 2022 -0700

    Remove null sentinel from 'attributes'
    
    In a subsequent patch, it's handy if the 'attributes' array in
    ada-lex.l does not have a NULL sentinel at the end.  In C++, this is
    easy to avoid.

Diff:
---
 gdb/ada-lex.l | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 27470a75653..a0c9816e568 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -655,7 +655,6 @@ attributes[] = {
   { "size", TICK_SIZE },
   { "tag", TICK_TAG },
   { "val", TICK_VAL },
-  { NULL, -1 }
 };
 
 /* Return the syntactic code corresponding to the attribute name or
@@ -664,24 +663,23 @@ attributes[] = {
 static int
 processAttribute (const char *str)
 {
-  int i, k;
+  for (const auto &item : attributes)
+    if (strcasecmp (str, item.name) == 0)
+      return item.code;
 
-  for (i = 0; attributes[i].code != -1; i += 1)
-    if (strcasecmp (str, attributes[i].name) == 0)
-      return attributes[i].code;
-
-  for (i = 0, k = -1; attributes[i].code != -1; i += 1)
-    if (subseqMatch (str, attributes[i].name))
+  gdb::optional<int> found;
+  for (const auto &item : attributes)
+    if (subseqMatch (str, item.name))
       {
-	if (k == -1)
-	  k = i;
+	if (!found.has_value ())
+	  found = item.code;
 	else
 	  error (_("ambiguous attribute name: `%s'"), str);
       }
-  if (k == -1)
+  if (!found.has_value ())
     error (_("unrecognized attribute: `%s'"), str);
 
-  return attributes[k].code;
+  return *found;
 }
 
 /* Back up lexptr by yyleng and then to the rightmost occurrence of


                 reply	other threads:[~2022-04-04 18:50 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=20220404185020.840D73858D37@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=gdb-cvs@sourceware.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: link
Be 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).