]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/fortran: add symbol base comparison operators
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 11 Jan 2021 14:14:02 +0000 (14:14 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 12 Jan 2021 09:40:55 +0000 (09:40 +0000)
Fortran supports symbol based comparison operators as well as the
classic text based comparison operators, so we have:

   Text     | Symbol
   Operator | Operator
   ---------|---------
   .eq.     | ==
   .ne.     | /=
   .le.     | <=
   .ge.     | >=
   .gt.     | >
   .lt.     | <

This commit adds the symbol based operators as well as some tests.

gdb/ChangeLog:

* f-exp.y (dot_ops): Rename to...
(fortran_operators): ...this.  Add a header comment.  Add symbol
based operators.
(yylex): Update to use fortran_operators not dot_ops.  Remove
special handling for '**', this is now included in
fortran_operators.

gdb/testsuite/ChangeLog:

* gdb.fortran/dot-ops.exp: Add new tests.

gdb/ChangeLog
gdb/f-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/dot-ops.exp

index c33b1d4563bf93615c0ea5cb274daf56f36246e1..720d3b230b2088a7f78843a9fee5afc0d1655a03 100644 (file)
@@ -1,3 +1,12 @@
+2021-01-12  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * f-exp.y (dot_ops): Rename to...
+       (fortran_operators): ...this.  Add a header comment.  Add symbol
+       based operators.
+       (yylex): Update to use fortran_operators not dot_ops.  Remove
+       special handling for '**', this is now included in
+       fortran_operators.
+
 2021-01-11  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * arch/aarch64-insn.h (aarch64_debug_printf): New.
index e0f1b1ffe1573db7d15038c3f9eec11ee6863e37..3b0f23d5d730d55c6b6e8dc2c397679aea95835d 100644 (file)
@@ -979,7 +979,9 @@ struct token
   bool case_sensitive;
 };
 
-static const struct token dot_ops[] =
+/* List of Fortran operators.  */
+
+static const struct token fortran_operators[] =
 {
   { ".and.", BOOL_AND, BINOP_END, false },
   { ".or.", BOOL_OR, BINOP_END, false },
@@ -987,11 +989,18 @@ static const struct token dot_ops[] =
   { ".eq.", EQUAL, BINOP_END, false },
   { ".eqv.", EQUAL, BINOP_END, false },
   { ".neqv.", NOTEQUAL, BINOP_END, false },
+  { "==", EQUAL, BINOP_END, false },
   { ".ne.", NOTEQUAL, BINOP_END, false },
+  { "/=", NOTEQUAL, BINOP_END, false },
   { ".le.", LEQ, BINOP_END, false },
+  { "<=", LEQ, BINOP_END, false },
   { ".ge.", GEQ, BINOP_END, false },
+  { ">=", GEQ, BINOP_END, false },
   { ".gt.", GREATERTHAN, BINOP_END, false },
+  { ">", GREATERTHAN, BINOP_END, false },
   { ".lt.", LESSTHAN, BINOP_END, false },
+  { "<", LESSTHAN, BINOP_END, false },
+  { "**", STARSTAR, BINOP_EXP, false },
 };
 
 /* Holds the Fortran representation of a boolean, and the integer value we
@@ -1163,26 +1172,17 @@ yylex (void)
        }
     }
 
-  /* See if it is a special .foo. operator.  */
-  for (int i = 0; i < ARRAY_SIZE (dot_ops); i++)
-    if (strncasecmp (tokstart, dot_ops[i].oper,
-                    strlen (dot_ops[i].oper)) == 0)
+  /* See if it is a Fortran operator.  */
+  for (int i = 0; i < ARRAY_SIZE (fortran_operators); i++)
+    if (strncasecmp (tokstart, fortran_operators[i].oper,
+                    strlen (fortran_operators[i].oper)) == 0)
       {
-       gdb_assert (!dot_ops[i].case_sensitive);
-       pstate->lexptr += strlen (dot_ops[i].oper);
-       yylval.opcode = dot_ops[i].opcode;
-       return dot_ops[i].token;
+       gdb_assert (!fortran_operators[i].case_sensitive);
+       pstate->lexptr += strlen (fortran_operators[i].oper);
+       yylval.opcode = fortran_operators[i].opcode;
+       return fortran_operators[i].token;
       }
 
-  /* See if it is an exponentiation operator.  */
-
-  if (strncmp (tokstart, "**", 2) == 0)
-    {
-      pstate->lexptr += 2;
-      yylval.opcode = BINOP_EXP;
-      return STARSTAR;
-    }
-
   switch (c = *tokstart)
     {
     case 0:
index 65bbebfb598b751718618b8b573147c7fab3e595..e31b712f01c5d24811d8f2f8cd82dab520a4fc9a 100644 (file)
@@ -1,3 +1,7 @@
+2021-01-12  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.fortran/dot-ops.exp: Add new tests.
+
 2021-01-11  Tom de Vries  <tdevries@suse.de>
 
        PR testsuite/26968
index 8454f7e298c509192f334618a95106c59830e538..cc9adf37aa4f0fa04d665c8225d40c083c3723f0 100644 (file)
@@ -109,6 +109,36 @@ proc test_dot_operations {} {
        gdb_test "p 4 $gt 4" " = .FALSE."
        gdb_test "p 3 $gt 4" " = .FALSE."
     }
+
+    # Now test the symbol based comparison operators.
+
+    # Arithmetic EQ
+    gdb_test "p 5 == 4" " = .FALSE."
+    gdb_test "p 4 == 4" " = .TRUE."
+
+    # Arithmetic NE
+    gdb_test "p 5 /= 4" " = .TRUE."
+    gdb_test "p 4 /= 4" " = .FALSE."
+
+    # Arithmetic LE
+    gdb_test "p 5 <= 4" " = .FALSE."
+    gdb_test "p 4 <= 4" " = .TRUE."
+    gdb_test "p 3 <= 4" " = .TRUE."
+
+    # Arithmetic LT
+    gdb_test "p 5 < 4" " = .FALSE."
+    gdb_test "p 4 < 4" " = .FALSE."
+    gdb_test "p 3 < 4" " = .TRUE."
+
+    # Arithmetic GE
+    gdb_test "p 5 >= 4" " = .TRUE."
+    gdb_test "p 4 >= 4" " = .TRUE."
+    gdb_test "p 3 >= 4" " = .FALSE."
+
+    # Arithmetic GT
+    gdb_test "p 5 > 4" " = .TRUE."
+    gdb_test "p 4 > 4" " = .FALSE."
+    gdb_test "p 3 > 4" " = .FALSE."
 }
 
 # Start of test script.