public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Nils-Christian Kempke <nils-christian.kempke@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types
Date: Wed,  9 Mar 2022 11:39:17 +0100	[thread overview]
Message-ID: <20220309103922.3257803-7-nils-christian.kempke@intel.com> (raw)
In-Reply-To: <20220309103922.3257803-1-nils-christian.kempke@intel.com>

The currently implemented intrinsic type handling for Fortran missed some
tokens and their parsing.  While still not all Fortran type kinds are
implemented this patch at least makes the currently handled types
consistent.  As an example for what this patch does, consider the
intrinsic type INTEGER.  GDB implemented the handling of the
keywords "integer" and "integer_2" but missed "integer_4" and "integer_8"
even though their corresponding internal types were already available as
the Fortran builtin types builtin_integer and builtin_integer_s8.
Similar problems applied to LOGICAL, REAL, and COMPLEX.  This patch adds
all missing tokens and their parsing.  Whenever a section containing the
type handling was touched, it also was reordered to be in a more easy to
grasp order.  All INTEGER/REAL/LOGICAL/COMPLEX types were grouped
together and ordered ascending in their size making a missing one more
easy to spot.

Before this change GDB would print the following when tyring to use the
INTEGER keywords:

   (gdb) set language fortran
   (gdb) ptype integer*1
   unsupported kind 1 for type integer
   (gdb) ptype integer_1
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer
   (gdb) ptype integer_4
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   No symbol table is loaded.  Use the "file" command.
   (gdb) ptype integer
   type = integer

With this patch all keywords are available and the GDB prints:

   (gdb) set language fortran
   (gdb) ptype integer*1
   type = integer*1
   (gdb) ptype integer_1
   type = integer*1
   (gdb) ptype integer*2
   type = integer*2
   (gdb) ptype integer_2
   type = integer*2
   (gdb) ptype integer*4
   type = integer*4
   (gdb) ptype integer_4
   type = integer*4
   (gdb) ptype integer*8
   type = integer*8
   (gdb) ptype integer_8
   type = integer*8
   (gdb) ptype integer
   type = integer

The described changes have been applied to INTEGER, REAL, COMPLEX,
and LOGICAL. Existing testcases have been adapted to reflect the
new behavior.  Tests for formerly missing types have been added.

gdb/ChangeLog:
2022-02-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* f-exp.y (tokens): Add missing INTEGER, REAL, COMPLEX, and
	LOGICAL tokens and reorder them.
	(typebase): Add parsing rules for new tokens and reorder the
	rules.
	(f77_keywords): Add missing keywords and reorder them.
	* f-lang.c (build_fortran_types): Reorder types.
	* f-lang.h (builtin_f_type): Reorder types.

gdb/testsuite/ChangeLog:
2022-02-22  Nils-Christian Kempke  <nils-christian.kempke@intel.com>

	* types.exp: Add tests for default types.  Add tests for all
	Fortran type keywords.

Signed-off-by: Nils-Christian Kempke <nils-christian.kempke@intel.com>
---
 gdb/f-exp.y                         | 50 +++++++++++++++++++----------
 gdb/f-lang.c                        | 24 +++++++-------
 gdb/f-lang.h                        |  4 +--
 gdb/testsuite/gdb.fortran/types.exp | 31 +++++++++++++++---
 4 files changed, 74 insertions(+), 35 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index f939efb5c4..e07af7322a 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -167,11 +167,12 @@ static int parse_number (struct parser_state *, const char *, int,
 
 /* Special type cases, put in to allow the parser to distinguish different
    legal basetypes.  */
-%token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD 
+%token INT_S1_KEYWORD INT_S2_KEYWORD INT_KEYWORD INT_S4_KEYWORD INT_S8_KEYWORD
+%token LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD LOGICAL_KEYWORD LOGICAL_S4_KEYWORD
 %token LOGICAL_S8_KEYWORD
-%token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD 
-%token COMPLEX_KEYWORD
-%token COMPLEX_S4_KEYWORD COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD
+%token REAL_KEYWORD REAL_S4_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
+%token COMPLEX_KEYWORD COMPLEX_S4_KEYWORD COMPLEX_S8_KEYWORD
+%token COMPLEX_S16_KEYWORD
 %token BOOL_AND BOOL_OR BOOL_NOT   
 %token SINGLE DOUBLE PRECISION
 %token <lval> CHARACTER 
@@ -757,22 +758,32 @@ func_mod:	'(' ')'
 typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 	:	TYPENAME
 			{ $$ = $1.type; }
+	|	INT_S1_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer_s1; }
+	|	INT_S2_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer_s2; }
 	|	INT_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_integer; }
-	|	INT_S2_KEYWORD 
-			{ $$ = parse_f_type (pstate)->builtin_integer_s2; }
+	|	INT_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer; }
+	|	INT_S8_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_integer_s8; }
 	|	CHARACTER 
 			{ $$ = parse_f_type (pstate)->builtin_character; }
-	|	LOGICAL_S8_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_logical_s8; }
-	|	LOGICAL_KEYWORD 
-			{ $$ = parse_f_type (pstate)->builtin_logical; }
-	|	LOGICAL_S2_KEYWORD
-			{ $$ = parse_f_type (pstate)->builtin_logical_s2; }
 	|	LOGICAL_S1_KEYWORD 
 			{ $$ = parse_f_type (pstate)->builtin_logical_s1; }
+	|	LOGICAL_S2_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical_s2; }
+	|	LOGICAL_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical; }
+	|	LOGICAL_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical; }
+	|	LOGICAL_S8_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_logical_s8; }
 	|	REAL_KEYWORD 
 			{ $$ = parse_f_type (pstate)->builtin_real; }
+	|	REAL_S4_KEYWORD
+			{ $$ = parse_f_type (pstate)->builtin_real; }
 	|       REAL_S8_KEYWORD
 			{ $$ = parse_f_type (pstate)->builtin_real_s8; }
 	|	REAL_S16_KEYWORD
@@ -1127,21 +1138,26 @@ static const struct f77_boolean_val boolean_values[]  =
 static const struct token f77_keywords[] =
 {
   /* Historically these have always been lowercase only in GDB.  */
+  { "character", CHARACTER, OP_NULL, true },
   { "complex", COMPLEX_KEYWORD, OP_NULL, true },
   { "complex_4", COMPLEX_S4_KEYWORD, OP_NULL, true },
   { "complex_8", COMPLEX_S8_KEYWORD, OP_NULL, true },
   { "complex_16", COMPLEX_S16_KEYWORD, OP_NULL, true },
-  { "character", CHARACTER, OP_NULL, true },
+  { "integer_1", INT_S1_KEYWORD, OP_NULL, true },
   { "integer_2", INT_S2_KEYWORD, OP_NULL, true },
+  { "integer_4", INT_S4_KEYWORD, OP_NULL, true },
+  { "integer", INT_KEYWORD, OP_NULL, true },
+  { "integer_8", INT_S8_KEYWORD, OP_NULL, true },
   { "logical_1", LOGICAL_S1_KEYWORD, OP_NULL, true },
   { "logical_2", LOGICAL_S2_KEYWORD, OP_NULL, true },
-  { "logical_8", LOGICAL_S8_KEYWORD, OP_NULL, true },
-  { "integer", INT_KEYWORD, OP_NULL, true },
   { "logical", LOGICAL_KEYWORD, OP_NULL, true },
+  { "logical_4", LOGICAL_S4_KEYWORD, OP_NULL, true },
+  { "logical_8", LOGICAL_S8_KEYWORD, OP_NULL, true },
+  { "real", REAL_KEYWORD, OP_NULL, true },
+  { "real_4", REAL_S4_KEYWORD, OP_NULL, true },
+  { "real_8", REAL_S8_KEYWORD, OP_NULL, true },
   { "real_16", REAL_S16_KEYWORD, OP_NULL, true },
   { "sizeof", SIZEOF, OP_NULL, true },
-  { "real_8", REAL_S8_KEYWORD, OP_NULL, true },
-  { "real", REAL_KEYWORD, OP_NULL, true },
   { "single", SINGLE, OP_NULL, true },
   { "double", DOUBLE, OP_NULL, true },
   { "precision", PRECISION, OP_NULL, true },
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 8e9af7661c..5a97beada2 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1619,28 +1619,28 @@ build_fortran_types (struct gdbarch *gdbarch)
   builtin_f_type->builtin_logical_s1
     = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "logical*1");
 
-  builtin_f_type->builtin_integer_s1
-    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "integer*1");
-
-  builtin_f_type->builtin_integer_s2
-    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
-
-  builtin_f_type->builtin_integer_s8
-    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
-			 "integer*8");
-
   builtin_f_type->builtin_logical_s2
     = arch_boolean_type (gdbarch, gdbarch_short_bit (gdbarch), 1, "logical*2");
 
+  builtin_f_type->builtin_logical
+    = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "logical*4");
+
   builtin_f_type->builtin_logical_s8
     = arch_boolean_type (gdbarch, gdbarch_long_long_bit (gdbarch), 1,
 			 "logical*8");
 
+  builtin_f_type->builtin_integer_s1
+    = arch_integer_type (gdbarch, TARGET_CHAR_BIT, 0, "integer*1");
+
+  builtin_f_type->builtin_integer_s2
+    = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), 0, "integer*2");
+
   builtin_f_type->builtin_integer
     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), 0, "integer");
 
-  builtin_f_type->builtin_logical
-    = arch_boolean_type (gdbarch, gdbarch_int_bit (gdbarch), 1, "logical*4");
+  builtin_f_type->builtin_integer_s8
+    = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), 0,
+			 "integer*8");
 
   builtin_f_type->builtin_real
     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index e22b167c38..d8fad03e87 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -307,13 +307,13 @@ extern int calc_f77_array_dims (struct type *);
 struct builtin_f_type
 {
   struct type *builtin_character;
-  struct type *builtin_integer;
   struct type *builtin_integer_s1;
   struct type *builtin_integer_s2;
+  struct type *builtin_integer;
   struct type *builtin_integer_s8;
-  struct type *builtin_logical;
   struct type *builtin_logical_s1;
   struct type *builtin_logical_s2;
+  struct type *builtin_logical;
   struct type *builtin_logical_s8;
   struct type *builtin_real;
   struct type *builtin_real_s8;
diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp
index 8122cbcca3..5ab44b10a3 100644
--- a/gdb/testsuite/gdb.fortran/types.exp
+++ b/gdb/testsuite/gdb.fortran/types.exp
@@ -71,13 +71,35 @@ proc test_float_literal_types_accepted {} {
     gdb_test "pt 10e20" "type = real\\*\[0-9\]+"
 }
 
+# Test the default primitive Fortran types.
+proc test_default_types {} {
+    gdb_test "ptype integer*4" "type = integer"
+    gdb_test "ptype integer_4" "type = integer"
+
+    gdb_test "ptype logical" "type = logical*4"
+
+    gdb_test "ptype real*4" "type = real"
+    gdb_test "ptype real_4" "type = real"
+
+    gdb_test "ptype complex" "type = complex*4"
+}
+
 # Test the the primitive Fortran types, those that GDB should always
 # know, even if the program does not define them, are in fact, known.
 proc test_primitive_types_known {} {
-    foreach type {void character logical*1 integer*1 integer*2 integer*8 \
-		      logical*2 logical*8 integer logical*4 real \
-		      real*8 real*16 complex*4 complex*8 complex*16} {
-	gdb_test "ptype $type" [string_to_regexp "type = $type"]
+    foreach type {void character \
+		     integer*1 integer*2 integer integer*8 \
+		     integer_1 integer_2 integer_8 \
+		     logical*1 logical*2 logical*4 logical*8 \
+		     logical_1 logical_2 logical_4 logical_8 \
+		     real real*8 real*16 real_8 real_16 \
+		     complex*4 complex*8 complex*16 \
+		     complex_4 complex_8 complex_16} {
+
+	# While TYPE_KIND is allowed as input, GDB will always return the
+	# Fortran notation TYPE*KIND
+	regsub -all "_" $type "\*" type_res
+	gdb_test "ptype $type" [string_to_regexp "type = $type_res"]
     }
 }
 
@@ -91,6 +113,7 @@ gdb_test "set print sevenbit-strings" ""
 
 if [set_lang_fortran] then {
     test_primitive_types_known
+    test_default_types
     test_integer_literal_types_accepted
     test_integer_literal_types_rejected
     test_logical_literal_types_accepted
-- 
2.25.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2022-03-09 10:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09 10:39 [PATCH 00/11] Improve Fortran intrinsic types and procedures Nils-Christian Kempke
2022-03-09 10:39 ` [PATCH 01/11] gdb/f-lang: add Integer*1 to Fortran builtin types Nils-Christian Kempke
2022-04-07 14:28   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 02/11] gdb/f-lang: remove hidden ^L characters Nils-Christian Kempke
2022-04-07 14:28   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 03/11] gdb/fortran: fix complex type in Fortran builtin types Nils-Christian Kempke
2022-04-07 14:30   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 04/11] gdb/fortran: reformat build_fortran_types in f-lang.c Nils-Christian Kempke
2022-04-07 14:30   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 05/11] gdb/fortran: change default logical type to builtin_logical Nils-Christian Kempke
2022-04-07 14:32   ` Tom Tromey
2022-03-09 10:39 ` Nils-Christian Kempke [this message]
2022-04-07 14:33   ` [PATCH 06/11] gdb/fortran: clean-up Fortran intrinsic types Tom Tromey
2022-03-09 10:39 ` [PATCH 07/11] gdb/fortran: Change GDB print for fortran default types Nils-Christian Kempke
2022-04-07 14:37   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 08/11] gdb/fortran: rename f77_keywords to f_keywords Nils-Christian Kempke
2022-04-07 14:37   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 09/11] gdb/fortran: rewrite intrinsic handling and add some missing overloads Nils-Christian Kempke
2022-04-07 14:49   ` Tom Tromey
2022-04-08 12:49     ` Kempke, Nils-Christian
2022-04-13  5:14   ` Tom de Vries
2022-04-20 16:10     ` Kempke, Nils-Christian
2022-03-09 10:39 ` [PATCH 10/11] gdb/fortran/testsuite: add complex from integers test Nils-Christian Kempke
2022-04-07 14:49   ` Tom Tromey
2022-04-07 14:50   ` Tom Tromey
2022-03-09 10:39 ` [PATCH 11/11] gdb/doc: add section about fortran intrinsic functions and types Nils-Christian Kempke
2022-03-09 12:49   ` Eli Zaretskii
2022-03-09 17:01     ` Kempke, Nils-Christian

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=20220309103922.3257803-7-nils-christian.kempke@intel.com \
    --to=nils-christian.kempke@intel.com \
    --cc=gdb-patches@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).