From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id B28823953CF3 for ; Sat, 19 Sep 2020 08:53:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B28823953CF3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x329.google.com with SMTP id x23so7382548wmi.3 for ; Sat, 19 Sep 2020 01:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eM5cutKHr8aOxXp0cAsItO+hLL59heAZWDI5IeVWPrE=; b=EC1FVPxkVdURGciOoTIU6KVI4YpdIb99O8an5JNYLZp3Oea/WEqjen6I7j0vqR1oU3 +LMvJv34grUONcAZJdS8h2iA6Y7f+40KIttPUEyo7AB5mLWnde6TpPPTTycAogqkzafF Zfn8SI8H8P3nFfBiebJePOaSu5QAPOsQQO1SVGRqYwntVx7nWqrHAv3LtlXVnvotHiBt AN8HQtofcki5Ep2q+TErAs+nNxgc30wJXsMyQUaNIhSsFTcU7RooqWpupSobfxgDbtRR M6gc/NXuI20EC/qEthoVXob5vC8GJB62CjG1sVBiLSiqXNW1fLJOW9wlk7LgRzEoOU0S TOhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eM5cutKHr8aOxXp0cAsItO+hLL59heAZWDI5IeVWPrE=; b=e8R8dtwrU7zqf+2C0euDOQI+KGaCGH4GEpERln84RN/Sp4KaKg2uXvXThTVuSKCCIS l8IMWFHwJr6ytA45YQNiF4ZNtiCdw0mJ3Dqb2AUs1vfCZ9lUP3LXWKeeF3wvz74HB1Id IfpbPF+fE9wtj4SJYzxL1IfB9pzusn+nTv/qGKP1kHLpbAWXwko4JUfAv21KUlb7CQmw qrJAv7an6q7DTSeRQjuSnC152gGyaEVe6yhZ1QA1M9SeNWRFEuPZE/vzPkXaHSbOalWR KVPZsnbvKiOsswzHJ+w9EWC3wYuCFUuUb9UKUeAQ2a90BfAhkK/DMp7nkyOEU8xCCtmf FRpw== X-Gm-Message-State: AOAM533TgzskyCG049G+V8R3PHKmH7vdq1erkPodbzKYnUsVVopGcYBO ttSeGpWExx8Fzf4sCPyLt5ACXuT6iWaiMg== X-Google-Smtp-Source: ABdhPJznen2s66NZVlI5zye3Q46rl1kzYZgWQ7JURWHm/pEeVx3G359KPOqOxZPbr+xXNNO4p3RStQ== X-Received: by 2002:a1c:2ed0:: with SMTP id u199mr19015287wmu.125.1600505619291; Sat, 19 Sep 2020 01:53:39 -0700 (PDT) Received: from localhost (host31-53-80-104.range31-53.btcentralplus.com. [31.53.80.104]) by smtp.gmail.com with ESMTPSA id v204sm9667083wmg.20.2020.09.19.01.53.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Sep 2020 01:53:38 -0700 (PDT) Date: Sat, 19 Sep 2020 09:53:37 +0100 From: Andrew Burgess To: gdb-patches@sourceware.org Subject: Re: [PATCHv2 05/10] gdb/fortran: Clean up array/string expression evaluation Message-ID: <20200919085337.GD1540618@embecosm.com> References: <21becb1edce3be52c86d7b522a504ace8b1b8913.1598452395.git.andrew.burgess@embecosm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <21becb1edce3be52c86d7b522a504ace8b1b8913.1598452395.git.andrew.burgess@embecosm.com> X-Operating-System: Linux/5.8.9-101.fc31.x86_64 (x86_64) X-Uptime: 09:52:45 up 17:00, 1 user, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Sep 2020 08:53:42 -0000 * Andrew Burgess [2020-08-26 15:49:12 +0100]: > In preparation for adding Fortan array stride expression support, this > is the first phase of some clean up to the expression evaluation for > Fortran arrays and strings. > > The current code is split into two blocks, linked, weirdly, with a > goto. After this commit all the code is moved to its own function, > and arrays and strings are now handled using the same code; this will > be useful later when I want to add array stride support where strings > will want to be treated just like arrays. > > For now the new function is added as a static within eval.c, even > though the function is Fortran only. A following commit will remove > some of the Fortran specific code from eval.c into one of the Fortran > specific files, including this new function. > > There should be no user visible changes after this commit. > > gdb/ChangeLog: > > * eval.c (fortran_value_subarray): New function, content is taken > from... > (evaluate_subexp_standard): ...here, in two places. Now arrays > and strings both call the new function. > (calc_f77_array_dims): Add header comment, handle strings. I went ahead and pushed this patch with a slightly modified commit message. Thanks, Andrew > --- > gdb/ChangeLog | 8 +++ > gdb/eval.c | 136 +++++++++++++++++++++++++------------------------- > 2 files changed, 75 insertions(+), 69 deletions(-) > > diff --git a/gdb/eval.c b/gdb/eval.c > index cd300ddfef6..660edbe34af 100644 > --- a/gdb/eval.c > +++ b/gdb/eval.c > @@ -1260,6 +1260,67 @@ is_integral_or_integral_reference (struct type *type) > && is_integral_type (TYPE_TARGET_TYPE (type))); > } > > +/* Called from evaluate_subexp_standard to perform array indexing, and > + sub-range extraction, for Fortran. As well as arrays this function > + also handles strings as they can be treated like arrays of characters. > + ARRAY is the array or string being accessed. EXP, POS, and NOSIDE are > + as for evaluate_subexp_standard, and NARGS is the number of arguments > + in this access (e.g. 'array (1,2,3)' would be NARGS 3). */ > + > +static struct value * > +fortran_value_subarray (struct value *array, struct expression *exp, > + int *pos, int nargs, enum noside noside) > +{ > + if (exp->elts[*pos].opcode == OP_RANGE) > + return value_f90_subarray (array, exp, pos, noside); > + > + if (noside == EVAL_SKIP) > + { > + skip_undetermined_arglist (nargs, exp, pos, noside); > + /* Return the dummy value with the correct type. */ > + return array; > + } > + > + LONGEST subscript_array[MAX_FORTRAN_DIMS]; > + int ndimensions = 1; > + struct type *type = check_typedef (value_type (array)); > + > + if (nargs > MAX_FORTRAN_DIMS) > + error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS); > + > + ndimensions = calc_f77_array_dims (type); > + > + if (nargs != ndimensions) > + error (_("Wrong number of subscripts")); > + > + gdb_assert (nargs > 0); > + > + /* Now that we know we have a legal array subscript expression let us > + actually find out where this element exists in the array. */ > + > + /* Take array indices left to right. */ > + for (int i = 0; i < nargs; i++) > + { > + /* Evaluate each subscript; it must be a legal integer in F77. */ > + value *arg2 = evaluate_subexp_with_coercion (exp, pos, noside); > + > + /* Fill in the subscript array. */ > + subscript_array[i] = value_as_long (arg2); > + } > + > + /* Internal type of array is arranged right to left. */ > + for (int i = nargs; i > 0; i--) > + { > + struct type *array_type = check_typedef (value_type (array)); > + LONGEST index = subscript_array[i - 1]; > + > + array = value_subscripted_rvalue (array, index, > + f77_get_lowerbound (array_type)); > + } > + > + return array; > +} > + > struct value * > evaluate_subexp_standard (struct type *expect_type, > struct expression *exp, int *pos, > @@ -1954,33 +2015,8 @@ evaluate_subexp_standard (struct type *expect_type, > switch (code) > { > case TYPE_CODE_ARRAY: > - if (exp->elts[*pos].opcode == OP_RANGE) > - return value_f90_subarray (arg1, exp, pos, noside); > - else > - { > - if (noside == EVAL_SKIP) > - { > - skip_undetermined_arglist (nargs, exp, pos, noside); > - /* Return the dummy value with the correct type. */ > - return arg1; > - } > - goto multi_f77_subscript; > - } > - > case TYPE_CODE_STRING: > - if (exp->elts[*pos].opcode == OP_RANGE) > - return value_f90_subarray (arg1, exp, pos, noside); > - else > - { > - if (noside == EVAL_SKIP) > - { > - skip_undetermined_arglist (nargs, exp, pos, noside); > - /* Return the dummy value with the correct type. */ > - return arg1; > - } > - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); > - return value_subscript (arg1, value_as_long (arg2)); > - } > + return fortran_value_subarray (arg1, exp, pos, nargs, noside); > > case TYPE_CODE_PTR: > case TYPE_CODE_FUNC: > @@ -2400,49 +2436,6 @@ evaluate_subexp_standard (struct type *expect_type, > } > return (arg1); > > - multi_f77_subscript: > - { > - LONGEST subscript_array[MAX_FORTRAN_DIMS]; > - int ndimensions = 1, i; > - struct value *array = arg1; > - > - if (nargs > MAX_FORTRAN_DIMS) > - error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS); > - > - ndimensions = calc_f77_array_dims (type); > - > - if (nargs != ndimensions) > - error (_("Wrong number of subscripts")); > - > - gdb_assert (nargs > 0); > - > - /* Now that we know we have a legal array subscript expression > - let us actually find out where this element exists in the array. */ > - > - /* Take array indices left to right. */ > - for (i = 0; i < nargs; i++) > - { > - /* Evaluate each subscript; it must be a legal integer in F77. */ > - arg2 = evaluate_subexp_with_coercion (exp, pos, noside); > - > - /* Fill in the subscript array. */ > - > - subscript_array[i] = value_as_long (arg2); > - } > - > - /* Internal type of array is arranged right to left. */ > - for (i = nargs; i > 0; i--) > - { > - struct type *array_type = check_typedef (value_type (array)); > - LONGEST index = subscript_array[i - 1]; > - > - array = value_subscripted_rvalue (array, index, > - f77_get_lowerbound (array_type)); > - } > - > - return array; > - } > - > case BINOP_LOGICAL_AND: > arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside); > if (noside == EVAL_SKIP) > @@ -3356,12 +3349,17 @@ parse_and_eval_type (char *p, int length) > return expr->elts[1].type; > } > > +/* Return the number of dimensions for a Fortran array or string. */ > + > int > calc_f77_array_dims (struct type *array_type) > { > int ndimen = 1; > struct type *tmp_type; > > + if ((array_type->code () == TYPE_CODE_STRING)) > + return 1; > + > if ((array_type->code () != TYPE_CODE_ARRAY)) > error (_("Can't get dimensions for a non-array type")); > > -- > 2.25.4 >