Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tim Wiederhake <tim.wiederhake@intel.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] Fortran: Move calc_f77_array_dims.
Date: Fri, 15 Sep 2017 20:22:00 -0000	[thread overview]
Message-ID: <d106b38ccd7c5ac949668918bece1fc6@polymtl.ca> (raw)
In-Reply-To: <1505134663-29374-2-git-send-email-tim.wiederhake@intel.com>

Hi Tim,

The patch is ok, with some nits I noted below.

On 2017-09-11 14:57, Tim Wiederhake wrote:
> 2017-09-11  Tim Wiederhake  <tim.wiederhake@intel.com>
> 
> gdb/ChangeLog:
> 	* eval.c (evaluate_subexp_standard): Use new function name.
> 	(calc_f77_array_dims): Move ...
> 	* f-lang.c (f77_get_array_dims): ... here.  Constify argument. Make
> 	NULL check explicit.
> 	* f-lang.h (calc_f77_arra_dims): Rename to...
> 	(f77_get_array_dims): ... this.  Add comment.
> 	* f-valprint.c (f77_print_array): Use new function name.
> 
> ---
>  gdb/eval.c       | 21 +--------------------
>  gdb/f-lang.c     | 16 ++++++++++++++++
>  gdb/f-lang.h     |  4 +++-
>  gdb/f-valprint.c |  2 +-
>  4 files changed, 21 insertions(+), 22 deletions(-)
> 
> diff --git a/gdb/eval.c b/gdb/eval.c
> index 24f32f8..7a808a0 100644
> --- a/gdb/eval.c
> +++ b/gdb/eval.c
> @@ -2336,7 +2336,7 @@ evaluate_subexp_standard (struct type 
> *expect_type,
>  	if (nargs > MAX_FORTRAN_DIMS)
>  	  error (_("Too many subscripts for F77 (%d Max)"), 
> MAX_FORTRAN_DIMS);
> 
> -	ndimensions = calc_f77_array_dims (type);
> +	ndimensions = f77_get_array_dims (type);
> 
>  	if (nargs != ndimensions)
>  	  error (_("Wrong number of subscripts"));
> @@ -3266,22 +3266,3 @@ parse_and_eval_type (char *p, int length)
>      error (_("Internal error in eval_type."));
>    return expr->elts[1].type;
>  }
> -
> -int
> -calc_f77_array_dims (struct type *array_type)
> -{
> -  int ndimen = 1;
> -  struct type *tmp_type;
> -
> -  if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
> -    error (_("Can't get dimensions for a non-array type"));
> -
> -  tmp_type = array_type;
> -
> -  while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
> -    {
> -      if (TYPE_CODE (tmp_type) == TYPE_CODE_ARRAY)
> -	++ndimen;
> -    }
> -  return ndimen;
> -}
> diff --git a/gdb/f-lang.c b/gdb/f-lang.c
> index 903cfd1..77b759b 100644
> --- a/gdb/f-lang.c
> +++ b/gdb/f-lang.c
> @@ -370,3 +370,19 @@ _initialize_f_language (void)
>  {
>    f_type_data = gdbarch_data_register_post_init (build_fortran_types);
>  }
> +
> +/* See f-lang.h.  */
> +
> +int
> +f77_get_array_dims (const struct type *array_type)
> +{
> +  if ((TYPE_CODE (array_type) != TYPE_CODE_ARRAY))
> +    error (_("Can't get dimensions for a non-array type"));
> +
> +  int ndimen = 0;
> +  for (; array_type != NULL; array_type = TYPE_TARGET_TYPE 
> (array_type))
> +    if (TYPE_CODE (array_type) == TYPE_CODE_ARRAY)
> +      ndimen += 1;

ndimen++; ?

Just a question (just showing off my ignorance of fortran): don't you 
want to stop looping when you reach a type that is a non-array?  I don't 
know which types in fortran can have a target, but is it possible to 
have something like this?

array type -> array type -> other type -> array type

The code above would give a dimension of 3, is it what we want?  I would 
have thought that the "top-level" array has a dimension of 2, but its 
elements is of type "other type".

> +
> +  return ndimen;
> +}
> diff --git a/gdb/f-lang.h b/gdb/f-lang.h
> index 5633b41..cfe667b 100644
> --- a/gdb/f-lang.h
> +++ b/gdb/f-lang.h
> @@ -55,7 +55,9 @@ extern int f77_get_lowerbound (struct type *);
> 
>  extern void f77_get_dynamic_array_length (struct type *);
> 
> -extern int calc_f77_array_dims (struct type *);
> +/* Calculate the number of dimensions of an array.  Expects ARRAY_TYPE 
> to be
> + * the type of an array.  */

Nit: remove the star at the beginning of the second line.

I would suggest this wording: Calculate the number of dimensions of an 
array of type ARRAY_TYPE.

> +extern int f77_get_array_dims (const struct type *array_type);
> 
> 
>  /* Fortran (F77) types */
> diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
> index 8fc894a..59d1a2f 100644
> --- a/gdb/f-valprint.c
> +++ b/gdb/f-valprint.c
> @@ -180,7 +180,7 @@ f77_print_array (struct type *type, const gdb_byte 
> *valaddr,
>    int ndimensions;
>    int elts = 0;
> 
> -  ndimensions = calc_f77_array_dims (type);
> +  ndimensions = f77_get_array_dims (type);
> 
>    if (ndimensions > MAX_FORTRAN_DIMS || ndimensions < 0)
>      error (_("\

Thanks,

Simon


  reply	other threads:[~2017-09-15 20:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 12:58 [PATCH 0/5] Fortran: Array strides Tim Wiederhake
2017-09-11 12:58 ` [PATCH 3/5] Fortran: Allow multi-dimensional subarrays Tim Wiederhake
2017-09-15 22:08   ` Simon Marchi
2017-09-11 12:58 ` [PATCH 2/5] Fortran: Move value_f90_subarray Tim Wiederhake
2017-09-15 20:27   ` Simon Marchi
2017-09-11 12:58 ` [PATCH 1/5] Fortran: Move calc_f77_array_dims Tim Wiederhake
2017-09-15 20:22   ` Simon Marchi [this message]
2017-09-15 20:28     ` Simon Marchi
2017-09-11 12:58 ` [PATCH 5/5] Fortran: Enable parsing of stride parameter for subranges Tim Wiederhake
2017-09-11 12:58 ` [PATCH 4/5] Fortran: Change subrange enum to bit field Tim Wiederhake
2017-09-15 22:29   ` Simon Marchi

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=d106b38ccd7c5ac949668918bece1fc6@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tim.wiederhake@intel.com \
    /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