From patchwork Wed Mar 6 18:14:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 31744 Received: (qmail 35679 invoked by alias); 6 Mar 2019 18:15:55 -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 34631 invoked by uid 89); 6 Mar 2019 18:15:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=BAYES_00, DNS_FROM_AHBL_RHSBL, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.1 spammy=vicinity X-HELO: mail-wr1-f44.google.com Received: from mail-wr1-f44.google.com (HELO mail-wr1-f44.google.com) (209.85.221.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Mar 2019 18:15:27 +0000 Received: by mail-wr1-f44.google.com with SMTP id i12so14500965wrw.0 for ; Wed, 06 Mar 2019 10:15:13 -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=Aq+zy3ez2z/M4EPcyogSAh6N9nagVItaMZh0QmRup9e/CL1TedpEecKe0QKYKPJknk oiJmt65k7bjDhKlMbshm2wTjCCNTd4gPx3bKDNN2v5qc3XSDzPlgmXLeBQYiXYkJOqNO 9Z5KEb5FjtR+6lv0yb/c7ffFgOR+XPbwGsHfq7XQ+F1HKc2svYLRMK9SKKH47PDr5WXl MJnatnG0E8ad+4tyWFOraRH5HlpRwgjh42zt18XsSnJmVaaeVZgsCLbiEqRwnGBZfoB6 AtdEgLGBvt+dwaNEpevEY3T2HH2UglpBmYJ/V2NIR28U8DgBamS+oOi0aeApE23SzLsq njiw== Return-Path: Received: from localhost (host86-142-70-198.range86-142.btcentralplus.com. [86.142.70.198]) by smtp.gmail.com with ESMTPSA id e7sm4625027wrw.35.2019.03.06.10.15.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Mar 2019 10:15:10 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PUSHED 02/11] gdb/fortran: Cleanup code for parsing logical constants Date: Wed, 6 Mar 2019 18:14:55 +0000 Message-Id: <185eedfd87dc1fa11c5c7e0d719b911fda03044b.1551895528.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 {} {