Jan Kratochvil 7306e88
RE: [ping] [PATCH v2 0/6] fortran: multi-dimensional subarrays with strides
Jan Kratochvil 7306e88
https://sourceware.org/ml/gdb-patches/2016-07/msg00009.html
Jan Kratochvil fdbd5e3
Jan Kratochvil 7306e88
From 338e4c860ad205896b4a95c79f54470c79eeb348 Mon Sep 17 00:00:00 2001
Jan Kratochvil 046f33b
From: Christoph Weinmann <christoph.t.weinmann@intel.com>
Jan Kratochvil 7306e88
Date: Wed, 1 Jun 2016 15:11:24 +0200
Jan Kratochvil 7306e88
Subject: [PATCH 4/6] fortran: enable parsing of stride parameter for subranges
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Allow the user to provide a stride parameter for Fortran
Jan Kratochvil 046f33b
subarrays.  The stride parameter can be any integer except
Jan Kratochvil 046f33b
'0'.  The default stride value is '1'.
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
2013-11-27  Christoph Weinmann  <christoph.t.weinmann@intel.com>
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
	* eval.c (value_f90_subarray): Add expression evaluation
Jan Kratochvil 046f33b
	for a stride parameter in a Fortran range expression.
Jan Kratochvil 7306e88
	* expression.h (range_type): Add field to enum to show when
Jan Kratochvil 7306e88
	a stride value was provided by the user.
Jan Kratochvil 046f33b
	* f-exp.y: Add yacc rules for writing info on the elt stack
Jan Kratochvil 046f33b
	when the user provided a stride argument.
Jan Kratochvil 046f33b
	* parse.c (operator_length_standard): Check if a stride
Jan Kratochvil 046f33b
	value was provided, and increment argument counter
Jan Kratochvil 046f33b
	accordingly.
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Signed-off-by: Christoph Weinmann <christoph.t.weinmann@intel.com>
Jan Kratochvil 046f33b
---
Jan Kratochvil 7306e88
 gdb/eval.c       | 11 ++++++++++-
Jan Kratochvil 7306e88
 gdb/expression.h |  7 +++++--
Jan Kratochvil 7306e88
 gdb/f-exp.y      | 31 ++++++++++++++++++++++++++++++-
Jan Kratochvil 7306e88
 gdb/parse.c      |  3 +++
Jan Kratochvil 7306e88
 gdb/valops.c     |  4 ++--
Jan Kratochvil 7306e88
 5 files changed, 50 insertions(+), 6 deletions(-)
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
diff --git a/gdb/eval.c b/gdb/eval.c
Jan Kratochvil 7306e88
index 44e8600..b5aaf1c 100644
Jan Kratochvil 046f33b
--- a/gdb/eval.c
Jan Kratochvil 046f33b
+++ b/gdb/eval.c
Jan Kratochvil 7306e88
@@ -419,7 +419,7 @@ value_f90_subarray (struct value *array, struct expression *exp,
Jan Kratochvil 7306e88
   typedef struct subscript_range
Jan Kratochvil 7306e88
   {
Jan Kratochvil 7306e88
     enum range_type f90_range_type;
Jan Kratochvil 7306e88
-    LONGEST low, high;
Jan Kratochvil 7306e88
+    LONGEST low, high, stride;
Jan Kratochvil 7306e88
   } subscript_range;
Jan Kratochvil 7306e88
 
Jan Kratochvil 7306e88
   typedef enum subscript_kind
Jan Kratochvil 7306e88
@@ -490,6 +490,15 @@ value_f90_subarray (struct value *array, struct expression *exp,
Jan Kratochvil 046f33b
 	      == SUBARRAY_HIGH_BOUND)
Jan Kratochvil 046f33b
 	    range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
Jan Kratochvil 046f33b
 							  pos, noside));
Jan Kratochvil 046f33b
+
Jan Kratochvil 046f33b
+	  /* Assign the user's stride value if provided.  */
Jan Kratochvil 046f33b
+	  if ((range->f90_range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
Jan Kratochvil 046f33b
+	    range->stride = value_as_long (evaluate_subexp (NULL_TYPE, exp,
Jan Kratochvil 7306e88
+							     pos, noside));
Jan Kratochvil 7306e88
+
Jan Kratochvil 046f33b
+	  /* Assign the default stride value '1'.  */
Jan Kratochvil 046f33b
+	  else
Jan Kratochvil 046f33b
+	    range->stride = 1;
Jan Kratochvil 046f33b
 	}
Jan Kratochvil 046f33b
       /* User input is an index.  E.g.: "p arry(5)".  */
Jan Kratochvil 046f33b
       else
Jan Kratochvil 7306e88
diff --git a/gdb/expression.h b/gdb/expression.h
Jan Kratochvil 7306e88
index 5a6b720..34ca54b 100644
Jan Kratochvil 7306e88
--- a/gdb/expression.h
Jan Kratochvil 7306e88
+++ b/gdb/expression.h
Jan Kratochvil 7306e88
@@ -153,13 +153,16 @@ extern void dump_raw_expression (struct expression *,
Jan Kratochvil 7306e88
 extern void dump_prefix_expression (struct expression *, struct ui_file *);
Jan Kratochvil 7306e88
 
Jan Kratochvil 7306e88
 /* In an OP_RANGE expression, either bound can be provided by the user, or not.
Jan Kratochvil 7306e88
-   This enumeration type is to identify this.  */
Jan Kratochvil 7306e88
+   In addition to this, the user can also specify a stride value to indicated
Jan Kratochvil 7306e88
+   only certain elements of the array.  This enumeration type is to identify
Jan Kratochvil 7306e88
+   this.  */
Jan Kratochvil 7306e88
 
Jan Kratochvil 7306e88
 enum range_type
Jan Kratochvil 7306e88
   {
Jan Kratochvil 7306e88
     SUBARRAY_NONE_BOUND = 0x0,		/* "( : )"  */
Jan Kratochvil 7306e88
     SUBARRAY_LOW_BOUND = 0x1,		/* "(low:)"  */
Jan Kratochvil 7306e88
-    SUBARRAY_HIGH_BOUND = 0x2		/* "(:high)"  */
Jan Kratochvil 7306e88
+    SUBARRAY_HIGH_BOUND = 0x2,		/* "(:high)"  */
Jan Kratochvil 7306e88
+    SUBARRAY_STRIDE = 0x4		/* "(::stride)"  */
Jan Kratochvil 7306e88
   };
Jan Kratochvil 7306e88
 
Jan Kratochvil 7306e88
 #endif /* !defined (EXPRESSION_H) */
Jan Kratochvil 046f33b
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
Jan Kratochvil 7306e88
index e2c54b6..71f1823 100644
Jan Kratochvil 046f33b
--- a/gdb/f-exp.y
Jan Kratochvil 046f33b
+++ b/gdb/f-exp.y
Jan Kratochvil 7306e88
@@ -280,7 +280,36 @@ subrange:	':' exp	%prec ABOVE_COMMA
Jan Kratochvil 046f33b
 
Jan Kratochvil 7306e88
 subrange:	':'	%prec ABOVE_COMMA
Jan Kratochvil 7306e88
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
Jan Kratochvil 7306e88
-			  write_exp_elt_longcst (pstate, 0);
Jan Kratochvil 7306e88
+			  write_exp_elt_longcst (pstate, SUBARRAY_NONE_BOUND);
Jan Kratochvil 7306e88
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
Jan Kratochvil 7306e88
+	;
Jan Kratochvil 7306e88
+
Jan Kratochvil 046f33b
+/* Each subrange type can have a stride argument.  */
Jan Kratochvil 046f33b
+subrange:	exp ':' exp ':' exp %prec ABOVE_COMMA
Jan Kratochvil 7306e88
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
Jan Kratochvil 046f33b
+						 | SUBARRAY_HIGH_BOUND
Jan Kratochvil 046f33b
+						 | SUBARRAY_STRIDE);
Jan Kratochvil 7306e88
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
Jan Kratochvil 046f33b
+	;
Jan Kratochvil 046f33b
+
Jan Kratochvil 046f33b
+subrange:	exp ':' ':' exp %prec ABOVE_COMMA
Jan Kratochvil 7306e88
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND
Jan Kratochvil 046f33b
+						 | SUBARRAY_STRIDE);
Jan Kratochvil 7306e88
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
Jan Kratochvil 046f33b
+	;
Jan Kratochvil 046f33b
+
Jan Kratochvil 046f33b
+subrange:	':' exp ':' exp %prec ABOVE_COMMA
Jan Kratochvil 7306e88
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND
Jan Kratochvil 046f33b
+						 | SUBARRAY_STRIDE);
Jan Kratochvil 7306e88
+			  write_exp_elt_opcode (pstate, OP_RANGE); }
Jan Kratochvil 046f33b
+	;
Jan Kratochvil 046f33b
+
Jan Kratochvil 046f33b
+subrange:	':' ':' exp %prec ABOVE_COMMA
Jan Kratochvil 7306e88
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, SUBARRAY_STRIDE);
Jan Kratochvil 7306e88
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
Jan Kratochvil 7306e88
 	;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
diff --git a/gdb/parse.c b/gdb/parse.c
Jan Kratochvil 7306e88
index 6d54a77..992af87 100644
Jan Kratochvil 046f33b
--- a/gdb/parse.c
Jan Kratochvil 046f33b
+++ b/gdb/parse.c
Jan Kratochvil 046f33b
@@ -1018,6 +1018,9 @@ operator_length_standard (const struct expression *expr, int endpos,
Jan Kratochvil 046f33b
       if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
Jan Kratochvil 046f33b
 	args++;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
+      if ((range_type & SUBARRAY_STRIDE) == SUBARRAY_STRIDE)
Jan Kratochvil 046f33b
+	args++;
Jan Kratochvil 046f33b
+
Jan Kratochvil 046f33b
       break;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
     default:
Jan Kratochvil 7306e88
diff --git a/gdb/valops.c b/gdb/valops.c
Jan Kratochvil 7306e88
index 817a4cf..fbc7dcb 100644
Jan Kratochvil 7306e88
--- a/gdb/valops.c
Jan Kratochvil 7306e88
+++ b/gdb/valops.c
Jan Kratochvil 7306e88
@@ -3834,7 +3834,7 @@ value_slice_1 (struct value *array, int lowbound, int length, int call_count)
Jan Kratochvil 7306e88
   if (call_count == 1)
Jan Kratochvil 7306e88
     {
Jan Kratochvil 7306e88
       range_type = TYPE_INDEX_TYPE (array_type);
Jan Kratochvil 7306e88
-      slice_range_size = elem_count;
Jan Kratochvil 7306e88
+      slice_range_size = ary_low_bound + elem_count - 1;
Jan Kratochvil 7306e88
 
Jan Kratochvil 7306e88
       /* Check if the array bounds are valid.  */
Jan Kratochvil 7306e88
       if (get_discrete_bounds (range_type, &ary_low_bound, &ary_high_bound) < 0)
Jan Kratochvil 7306e88
@@ -3846,7 +3846,7 @@ value_slice_1 (struct value *array, int lowbound, int length, int call_count)
Jan Kratochvil 7306e88
   else
Jan Kratochvil 7306e88
     {
Jan Kratochvil 7306e88
       range_type = TYPE_INDEX_TYPE (TYPE_TARGET_TYPE (array_type));
Jan Kratochvil 7306e88
-      slice_range_size = (ary_low_bound + row_count - 1) * (elem_count);
Jan Kratochvil 7306e88
+      slice_range_size = ary_low_bound + (row_count * elem_count) - 1;
Jan Kratochvil 7306e88
       ary_low_bound = TYPE_LOW_BOUND (range_type);
Jan Kratochvil 7306e88
     }
Jan Kratochvil 7306e88
 
Jan Kratochvil 046f33b
-- 
Jan Kratochvil 7306e88
2.5.5
Jan Kratochvil fdbd5e3