From patchwork Wed Dec 4 16:56:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 36519 Received: (qmail 81832 invoked by alias); 4 Dec 2019 16:56:34 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 81823 invoked by uid 89); 4 Dec 2019 16:56:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:5459 X-HELO: mail-wr1-f50.google.com Received: from mail-wr1-f50.google.com (HELO mail-wr1-f50.google.com) (209.85.221.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Dec 2019 16:56:32 +0000 Received: by mail-wr1-f50.google.com with SMTP id a15so21021wrf.9 for ; Wed, 04 Dec 2019 08:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id; bh=O8qFlthycokzkh7Ar4CyErTrVdFodp+DEFcE8qqZjT8=; b=fA6Y1+pbQFMlbm8oVeKdp/saph0jee3Fifme9jvpyEcy9QIdGllimx7XQFbkzSuSmz lUO9C40Rga4Wy6n1qOSV0m23v+aL5zJrzIcJVK99iBpDmVltivTJQ7cehxwLjD0dcm5G YcAYIXruSTqYJb8ZmfmrD0TZHIBAOeSem4nQPHIKd3LAgu6YozPM7QMSmlKwyR4NpnGo AMsHTy7vfr+lHQPIvqqI8gZ/fiLEbz6Df2qSLMblF6GWnHdcKmISH9pCzBxGIURf0tGa KbwIyvvYy3eCLpp09oBqA3pQu9/1nPupwFmcydIZfxgCM0mIzwAYQbsTJlIxujyYDlAj 9XmQ== Return-Path: Received: from localhost (host109-151-46-117.range109-151.btcentralplus.com. [109.151.46.117]) by smtp.gmail.com with ESMTPSA id v8sm6887349wrw.2.2019.12.04.08.56.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Dec 2019 08:56:29 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Richard.Bunt@arm.com, Andrew Burgess Subject: [PATCH] gdb/fortran: Support for single/double type modifiers Date: Wed, 4 Dec 2019 16:56:27 +0000 Message-Id: <20191204165627.27786-1-andrew.burgess@embecosm.com> X-IsSubscribed: yes Extend the Fortran parser to support 'single precision' and 'double precision' types as well 'single complex' and 'double complex' types. gdb/ChangeLog: * f-exp.y (COMPLEX_KEYWORD, SINGLE, DOUBLE, PRECISION): New tokens. (typebase): New patterns for complex, single/double precision, and single/double complex. (f77_keywords): Change token for complex keyword, and add single, double, and precision keywords. gdb/testsuite/ChangeLog: * gdb.fortran/type-kinds.exp (test_cast_1_to_type_kind): Handle casting to type with no kind specified. (test_basic_parsing_of_type_kinds): Additional tests for types with no kind specified, and add tests for single/double precision/complex types. Change-Id: I9c82f4d392c58607747bd08862c1ee330723a1ba --- gdb/ChangeLog | 10 ++++++++++ gdb/f-exp.y | 17 ++++++++++++++++- gdb/testsuite/ChangeLog | 8 ++++++++ gdb/testsuite/gdb.fortran/type-kinds.exp | 20 ++++++++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 9784ad57d82..a9c9583f9a8 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -167,8 +167,10 @@ static int parse_number (struct parser_state *, const char *, int, %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD %token LOGICAL_S8_KEYWORD %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD +%token COMPLEX_KEYWORD %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD %token BOOL_AND BOOL_OR BOOL_NOT +%token SINGLE DOUBLE PRECISION %token CHARACTER %token DOLLAR_VARIABLE @@ -617,12 +619,22 @@ typebase /* Implements (approximately): (type-qualifier)* type-specifier */ { $$ = parse_f_type (pstate)->builtin_real_s8; } | REAL_S16_KEYWORD { $$ = parse_f_type (pstate)->builtin_real_s16; } + | COMPLEX_KEYWORD + { $$ = parse_f_type (pstate)->builtin_complex_s8; } | COMPLEX_S8_KEYWORD { $$ = parse_f_type (pstate)->builtin_complex_s8; } | COMPLEX_S16_KEYWORD { $$ = parse_f_type (pstate)->builtin_complex_s16; } | COMPLEX_S32_KEYWORD { $$ = parse_f_type (pstate)->builtin_complex_s32; } + | SINGLE PRECISION + { $$ = parse_f_type (pstate)->builtin_real;} + | DOUBLE PRECISION + { $$ = parse_f_type (pstate)->builtin_real_s8;} + | SINGLE COMPLEX_KEYWORD + { $$ = parse_f_type (pstate)->builtin_complex_s8;} + | DOUBLE COMPLEX_KEYWORD + { $$ = parse_f_type (pstate)->builtin_complex_s16;} ; nonempty_typelist @@ -956,10 +968,13 @@ static const struct token f77_keywords[] = { "integer", INT_KEYWORD, BINOP_END, true }, { "logical", LOGICAL_KEYWORD, BINOP_END, true }, { "real_16", REAL_S16_KEYWORD, BINOP_END, true }, - { "complex", COMPLEX_S8_KEYWORD, BINOP_END, true }, + { "complex", COMPLEX_KEYWORD, BINOP_END, true }, { "sizeof", SIZEOF, BINOP_END, true }, { "real_8", REAL_S8_KEYWORD, BINOP_END, true }, { "real", REAL_KEYWORD, BINOP_END, true }, + { "single", SINGLE, BINOP_END, true }, + { "double", DOUBLE, BINOP_END, true }, + { "precision", PRECISION, BINOP_END, true }, /* The following correspond to actual functions in Fortran and are case insensitive. */ { "kind", KIND, BINOP_END, false }, diff --git a/gdb/testsuite/gdb.fortran/type-kinds.exp b/gdb/testsuite/gdb.fortran/type-kinds.exp index 9d19a9ceb39..725c3f0cecf 100644 --- a/gdb/testsuite/gdb.fortran/type-kinds.exp +++ b/gdb/testsuite/gdb.fortran/type-kinds.exp @@ -23,9 +23,15 @@ 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. +# value returned by the cast should be SIZE_RESULT. If TYPE_KIND is +# the empty string then the cast is done to just 'BASE_TYPE'. proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} { - set type_string "$base_type (kind=$type_kind)" + if { $type_kind != "" } { + set kind_string " (kind=$type_kind)" + } else { + set kind_string "" + } + set type_string "${base_type}${kind_string}" gdb_test "p (($type_string) 1)" " = $cast_result" gdb_test "p sizeof (($type_string) 1)" " = $size_result" } @@ -34,21 +40,31 @@ proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} { proc test_basic_parsing_of_type_kinds {} { test_cast_1_to_type_kind "character" "1" "1 '\\\\001'" "1" + test_cast_1_to_type_kind "complex" "" "\\(1,0\\)" "8" 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" "" "1" "4" 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" "" "\\.TRUE\\." "4" 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" "" "1" "4" test_cast_1_to_type_kind "integer" "2" "1" "2" test_cast_1_to_type_kind "integer" "4" "1" "4" test_cast_1_to_type_kind "integer" "8" "1" "8" + + test_cast_1_to_type_kind "double precision" "" "1" "8" + test_cast_1_to_type_kind "single precision" "" "1" "4" + + test_cast_1_to_type_kind "double complex" "" "\\(1,0\\)" "16" + test_cast_1_to_type_kind "single complex" "" "\\(1,0\\)" "8" } proc test_parsing_invalid_type_kinds {} {