]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/fortran: Cleanup code for parsing logical constants
authorAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 16 Jan 2019 13:36:46 +0000 (13:36 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 6 Mar 2019 18:11:30 +0000 (18:11 +0000)
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.

gdb/ChangeLog
gdb/f-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/types.exp

index ac61e65efb0c449b5b7109c744087709629904f2..25a22802c4818ca83848dec8c5445f3dc2eb4445 100644 (file)
@@ -1,3 +1,11 @@
+2019-03-06  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * 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.
+
 2019-03-06  Tom Tromey  <tromey@adacore.com>
 
        * remote-sim.c (gdbsim_target_open): Use result of
index d70c66474c0eff698ea83a6c17d563afc2c80b4c..704585e63ae3bd38fffe46860608d0a8e47d9bbd 100644 (file)
@@ -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;
            }
        }
index 1a6b440be3671a00bca3b2a9a3b23fb7661553f5..e2e74a8bffd79da5c3995763f9817cf1a55ed709 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-06  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.fortran/types.exp (test_logical_literal_types_accepted):
+       Check upper and lower case logical literals.
+
 2019-03-06  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.fortran/types.exp (test_float_literal_types_accepted):
index f786bd30eb048dc86da5fb32c1e2a44ae724d4b3..0e28691d90ead554a76bbdab72f5c30844c4cc10 100644 (file)
@@ -45,10 +45,13 @@ proc test_integer_literal_types_rejected {} {
 proc test_logical_literal_types_accepted {} {
     global gdb_prompt
 
-    # Test the only possible values for a logical, TRUE and FALSE.
+    # Test the only possible values for a logical, TRUE and FALSE (and
+    # also true and false).
 
     gdb_test "pt .TRUE." "type = logical\\*2"
     gdb_test "pt .FALSE." "type = logical\\*2"
+    gdb_test "pt .true." "type = logical\\*2"
+    gdb_test "pt .false." "type = logical\\*2"
 }
 
 proc test_float_literal_types_accepted {} {