summaryrefslogtreecommitdiff
path: root/gdb/ada-lex.l
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-02-22 11:05:41 -0700
committerTom Tromey <tromey@adacore.com>2022-04-04 12:46:08 -0600
commitc3f2a3738a3603f51e3621504d8207767526add9 (patch)
tree4d437a53ecfabcf87a5b8d18fc55f7237ed97d37 /gdb/ada-lex.l
parent81eaa5061095f972d48e8160a4f677bd3e6ace51 (diff)
downloadbinutils-gdb-c3f2a3738a3603f51e3621504d8207767526add9.tar.gz
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.
Diffstat (limited to 'gdb/ada-lex.l')
-rw-r--r--gdb/ada-lex.l22
1 files 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