From patchwork Tue Feb 12 16:10:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31411 Received: (qmail 66811 invoked by alias); 12 Feb 2019 16:11:14 -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 66736 invoked by uid 89); 12 Feb 2019 16:11:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=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.2 spammy=vicinity X-HELO: mail-wm1-f50.google.com Received: from mail-wm1-f50.google.com (HELO mail-wm1-f50.google.com) (209.85.128.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Feb 2019 16:11:11 +0000 Received: by mail-wm1-f50.google.com with SMTP id x10so3586685wmg.2 for ; Tue, 12 Feb 2019 08:11:11 -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:in-reply-to:references :in-reply-to:references; bh=aYA9/CYyK9doIibc6tRJZSmuHVPOfLbY90bLOq2uGUY=; b=fIe2EkQF94u7M5eNH7zF+t3CeRDjHaw/M+4tGwsieIG6DqkVOY2FEsglUzjQX9sYnS o5coLA4H6N5VwZIA8dUBxRGoDf5aZhYyJ713pGhyNNx02QzWZcnPZy8/K63JhrhWHjUJ YEFzpLKi4/2NkwodYad5x2hjlEgZ2TvSUIiFAwW3pZgVqpYr7oHUNf6/fTI0IleLrmE/ hYV6FjVyiWeTUyinJCFgBeW3CJP+B1VNogblx3MEOz99vllL/YcC8TK4qSDHeOllIRrv rKjDoQv30grWBJvJhCqTlSVGyAWgdLQesvNI+BjwrDrxY+KkAiTIFclPVajmQ8cCq4Yc eDsA== Return-Path: Received: from localhost (host81-151-161-9.range81-151.btcentralplus.com. [81.151.161.9]) by smtp.gmail.com with ESMTPSA id y139sm4049316wmd.22.2019.02.12.08.11.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Feb 2019 08:11:08 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Richard Bunt , Andrew Burgess Subject: [PATCH 02/11] gdb/fortran: Cleanup code for parsing logical constants Date: Tue, 12 Feb 2019 16:10:53 +0000 Message-Id: <0c6835d90cb03bd83bf2bc3a60b702e617999fe3.1549986233.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes 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 | 8 ++++++++ gdb/f-exp.y | 35 +++++++++++++++++++---------------- gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.fortran/types.exp | 5 ++++- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/gdb/f-exp.y b/gdb/f-exp.y index d70c66474c0..704585e63ae 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -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; } } diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp index f786bd30eb0..0e28691d90e 100644 --- a/gdb/testsuite/gdb.fortran/types.exp +++ b/gdb/testsuite/gdb.fortran/types.exp @@ -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 {} {