public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PUSHED 07/11] gdb/fortran: Expand the set of types that support (kind=N)
Date: Wed, 06 Mar 2019 18:16:00 -0000	[thread overview]
Message-ID: <ce31929986e31440b7b3d8fb97c26a79aebf43ef.1551895528.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1551895528.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1551895528.git.andrew.burgess@embecosm.com>

Expand the number of types that can be adjusted with a (kind=N) type
extension.

gdb/ChangeLog:

	* f-exp.y (convert_to_kind_type): Handle more type kinds.

gdb/testsuite/ChangeLog:

	* gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): New
	function.
	(test_basic_parsing_of_type_kinds): Expand types tested.
	(test_parsing_invalid_type_kinds): New function.
---
 gdb/ChangeLog                            |  4 ++++
 gdb/f-exp.y                              | 36 ++++++++++++++++++++++++++++
 gdb/testsuite/ChangeLog                  |  7 ++++++
 gdb/testsuite/gdb.fortran/type-kinds.exp | 41 +++++++++++++++++++++++++++++++-
 4 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 327f13736bd..980ee4b4adb 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -830,6 +830,42 @@ convert_to_kind_type (struct type *basetype, int kind)
       if (kind == 1)
 	return parse_f_type (pstate)->builtin_character;
     }
+  else if (basetype == parse_f_type (pstate)->builtin_complex_s8)
+    {
+      if (kind == 4)
+	return parse_f_type (pstate)->builtin_complex_s8;
+      else if (kind == 8)
+	return parse_f_type (pstate)->builtin_complex_s16;
+      else if (kind == 16)
+	return parse_f_type (pstate)->builtin_complex_s32;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_real)
+    {
+      if (kind == 4)
+	return parse_f_type (pstate)->builtin_real;
+      else if (kind == 8)
+	return parse_f_type (pstate)->builtin_real_s8;
+      else if (kind == 16)
+	return parse_f_type (pstate)->builtin_real_s16;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_logical)
+    {
+      if (kind == 1)
+	return parse_f_type (pstate)->builtin_logical_s1;
+      else if (kind == 2)
+	return parse_f_type (pstate)->builtin_logical_s2;
+      else if (kind == 4)
+	return parse_f_type (pstate)->builtin_logical;
+      else if (kind == 8)
+	return parse_f_type (pstate)->builtin_logical_s8;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_integer)
+    {
+      if (kind == 2)
+	return parse_f_type (pstate)->builtin_integer_s2;
+      else if (kind == 4)
+	return parse_f_type (pstate)->builtin_integer;
+    }
 
   error (_("unsupported kind %d for type %s"),
 	 kind, TYPE_SAFE_NAME (basetype));
diff --git a/gdb/testsuite/gdb.fortran/type-kinds.exp b/gdb/testsuite/gdb.fortran/type-kinds.exp
index b60b8044110..c679bc504f9 100644
--- a/gdb/testsuite/gdb.fortran/type-kinds.exp
+++ b/gdb/testsuite/gdb.fortran/type-kinds.exp
@@ -21,15 +21,54 @@ load_lib "fortran.exp"
 
 if { [skip_fortran_tests] } { continue }
 
+# Cast the value 1 to the type 'BASE_TYPE (kind=TYPE_KIND)'.  The
+# expected result of the cast is CAST_RESULT, and the size of the
+# value returned by the cast should be SIZE_RESULT.
+proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} {
+    set type_string "$base_type (kind=$type_kind)"
+    gdb_test "p (($type_string) 1)" " = $cast_result"
+
+    if {($base_type == "real" || $base_type == "complex")
+	&& $type_kind == 16} {
+	setup_kfail gdb/18644 "*-*-*"
+    }
+
+    gdb_test "p sizeof (($type_string) 1)" " = $size_result"
+}
+
 # Test parsing of `(kind=N)` type modifiers.
 proc test_basic_parsing_of_type_kinds {} {
-    gdb_test "p ((character (kind=1)) 1)" " = 1"
+    test_cast_1_to_type_kind "character" "1" "1" "1"
+
+    test_cast_1_to_type_kind "complex" "4" "\\(1,0\\)" "8"
+    test_cast_1_to_type_kind "complex" "8" "\\(1,0\\)" "16"
+    test_cast_1_to_type_kind "complex" "16" "\\(1,0\\)" "32"
+
+    test_cast_1_to_type_kind "real" "4" "1" "4"
+    test_cast_1_to_type_kind "real" "8" "1" "8"
+    test_cast_1_to_type_kind "real" "16" "1" "16"
+
+    test_cast_1_to_type_kind "logical" "1" "\\.TRUE\\." "1"
+    test_cast_1_to_type_kind "logical" "4" "\\.TRUE\\." "4"
+    test_cast_1_to_type_kind "logical" "8" "\\.TRUE\\." "8"
+
+    test_cast_1_to_type_kind "integer" "2" "1" "2"
+    test_cast_1_to_type_kind "integer" "4" "1" "4"
+}
+
+proc test_parsing_invalid_type_kinds {} {
+    foreach typename {complex real logical integer} {
+	foreach typesize {3 5 7 9} {
+	    gdb_test "p (($typename (kind=$typesize)) 1)" "unsupported kind $typesize for type $typename.*"
+	}
+    }
 }
 
 clean_restart
 
 if [set_lang_fortran] then {
     test_basic_parsing_of_type_kinds
+    test_parsing_invalid_type_kinds
 } else {
     warning "$test_name tests suppressed." 0
 }
-- 
2.14.5

  parent reply	other threads:[~2019-03-06 18:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 16:11 [PATCH 00/11] Fortran Parser Cleanup, KIND Support, and Intrinsic Functions Andrew Burgess
2019-02-12 16:11 ` [PATCH 02/11] gdb/fortran: Cleanup code for parsing logical constants Andrew Burgess
2019-02-12 16:11 ` [PATCH 08/11] gdb/fortran: Add builtin 8-byte integer type with (kind=8) support Andrew Burgess
2019-02-12 16:11 ` [PATCH 10/11] gdb/fortran: Add support for the ABS intrinsic function Andrew Burgess
2019-02-12 16:11 ` [PATCH 03/11] gdb/fortran: Simplify handling of Fortran dot operations and keywords Andrew Burgess
2019-02-12 16:11 ` [PATCH 06/11] gdb/fortran: Add Fortran 'kind' intrinsic and keyword Andrew Burgess
2019-02-12 16:11 ` [PATCH 01/11] gdb/fortran: Remove some duplicate tests Andrew Burgess
2019-02-12 16:11 ` [PATCH 09/11] gdb/fortran: Use TYPE_CODE_CHAR for character types Andrew Burgess
2019-02-12 16:11 ` [PATCH 05/11] gdb/fortran: Enable debugging of the Fortran parser Andrew Burgess
2019-02-12 16:11 ` [PATCH 04/11] gdb/fortran: Add new function to evaluate Fortran expressions Andrew Burgess
2019-02-12 16:11 ` [PATCH 07/11] gdb/fortran: Expand the set of types that support (kind=N) Andrew Burgess
2019-02-12 16:11 ` [PATCH 11/11] gdb/fortran: Handle older TYPE*SIZE typenames Andrew Burgess
2019-03-06 18:15 ` [PUSHED 00/11] Fortran Parser Cleanup, KIND Support, and Intrinsic Functions Andrew Burgess
2019-03-06 18:15 ` [PUSHED 01/11] gdb/fortran: Remove some duplicate tests Andrew Burgess
2019-03-06 18:15 ` [PUSHED 04/11] gdb/fortran: Add new function to evaluate Fortran expressions Andrew Burgess
2019-03-06 18:15 ` [PUSHED 02/11] gdb/fortran: Cleanup code for parsing logical constants Andrew Burgess
2019-03-06 18:16 ` [PUSHED 09/11] gdb/fortran: Use TYPE_CODE_CHAR for character types Andrew Burgess
2019-03-06 18:16 ` Andrew Burgess [this message]
2019-03-06 18:16 ` [PUSHED 05/11] gdb/fortran: Enable debugging of the Fortran parser Andrew Burgess
2019-03-06 18:16 ` [PUSHED 03/11] gdb/fortran: Simplify handling of Fortran dot operations and keywords Andrew Burgess
2019-03-06 18:16 ` [PUSHED 08/11] gdb/fortran: Add builtin 8-byte integer type with (kind=8) support Andrew Burgess
2019-03-06 18:16 ` [PUSHED 10/11] gdb/fortran: Add support for the ABS intrinsic function Andrew Burgess
2019-03-06 19:11   ` Tom Tromey
2019-03-07 15:23     ` [PATCH] gdb: Move value_from_host_double into value.c and make more use of it Andrew Burgess
2019-03-07 15:49       ` Tom Tromey
2019-03-06 18:16 ` [PUSHED 06/11] gdb/fortran: Add Fortran 'kind' intrinsic and keyword Andrew Burgess
2019-03-06 18:16 ` [PUSHED 11/11] gdb/fortran: Handle older TYPE*SIZE typenames Andrew Burgess

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=ce31929986e31440b7b3d8fb97c26a79aebf43ef.1551895528.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.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).