aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-exp.y
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-01-16 13:36:46 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-03-06 18:11:30 +0000
commitdd9f2c763b325227a3721eaf4006db67b37f3b13 (patch)
treef758a098af7793cdcb7be768e8148e94474fbe00 /gdb/f-exp.y
parent84ec972406ec519b509f986780481899115847c2 (diff)
downloadgdb-dd9f2c763b325227a3721eaf4006db67b37f3b13.zip
gdb-dd9f2c763b325227a3721eaf4006db67b37f3b13.tar.gz
gdb-dd9f2c763b325227a3721eaf4006db67b37f3b13.tar.bz2
gdb/fortran: Cleanup code for parsing logical constants
This patch cleans up the code used for parsing the Fortran logical constants '.TRUE.' and '.FALSE.'. Instead of listing both upper and lowercase versions of these strings we now use strncasecmp. I've also switched to use ARRAY_SIZE for the array iteration, and I've cleaned up whitespace in the vicinity of the code I've changed. Finally, I've added a test to ensure that both the upper and lower case versions of the logical constants are understood by GDB, something that was missing previously. There should be no user visible changes after this commit. gdb/ChangeLog: * f-exp.y (struct f77_boolean_val): Add comments. (boolean_values): Remove uppercase versions, and end marker. (yylex): Use ARRAY_SIZE for iterating over boolean_values array, and use strncasecmp to achieve case insensitivity. Additionally, perform whitespace cleanup around this code. gdb/testsuite/ChangeLog: * gdb.fortran/types.exp (test_logical_literal_types_accepted): Check upper and lower case logical literals.
Diffstat (limited to 'gdb/f-exp.y')
-rw-r--r--gdb/f-exp.y35
1 files changed, 19 insertions, 16 deletions
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index d70c664..704585e 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -807,19 +807,22 @@ static const struct token dot_ops[] =
{ NULL, 0, BINOP_END }
};
-struct f77_boolean_val
+/* Holds the Fortran representation of a boolean, and the integer value we
+ substitute in when one of the matching strings is parsed. */
+struct f77_boolean_val
{
+ /* The string representing a Fortran boolean. */
const char *name;
+
+ /* The integer value to replace it with. */
int value;
-};
+};
-static const struct f77_boolean_val boolean_values[] =
+/* The set of Fortran booleans. These are matched case insensitively. */
+static const struct f77_boolean_val boolean_values[] =
{
{ ".true.", 1 },
- { ".TRUE.", 1 },
- { ".false.", 0 },
- { ".FALSE.", 0 },
- { NULL, 0 }
+ { ".false.", 0 }
};
static const struct token f77_keywords[] =
@@ -931,19 +934,19 @@ yylex (void)
prev_lexptr = lexptr;
tokstart = lexptr;
-
- /* First of all, let us make sure we are not dealing with the
+
+ /* First of all, let us make sure we are not dealing with the
special tokens .true. and .false. which evaluate to 1 and 0. */
-
+
if (*lexptr == '.')
- {
- for (int i = 0; boolean_values[i].name != NULL; i++)
+ {
+ for (int i = 0; i < ARRAY_SIZE (boolean_values); i++)
{
- if (strncmp (tokstart, boolean_values[i].name,
- strlen (boolean_values[i].name)) == 0)
+ if (strncasecmp (tokstart, boolean_values[i].name,
+ strlen (boolean_values[i].name)) == 0)
{
- lexptr += strlen (boolean_values[i].name);
- yylval.lval = boolean_values[i].value;
+ lexptr += strlen (boolean_values[i].name);
+ yylval.lval = boolean_values[i].value;
return BOOLEAN_LITERAL;
}
}