Jan Kratochvil 046f33b
From: Christoph Weinmann <christoph.t.weinmann@intel.com>
Jan Kratochvil 046f33b
[PATCH 3/6] fortran: change subrange enum to bit field
Jan Kratochvil 046f33b
https://sourceware.org/ml/gdb-patches/2015-12/msg00006.html
Jan Kratochvil 046f33b
Message-Id: <1448976075-11456-4-git-send-email-christoph.t.weinmann@intel.com>
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Change Fortran subrange enum for subrange expressions to
Jan Kratochvil 046f33b
represent a bitfield for easier manipulation.  Consequently
Jan Kratochvil 046f33b
also change occurences and evaluation of said enum.  The
Jan Kratochvil 046f33b
behaviour of GDB is unchanged.
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): Change evaluation of the
Jan Kratochvil 046f33b
	subarray boundaries.  Set boundaries to be either user
Jan Kratochvil 046f33b
	provided (bit in f90_range_type was set) or take the
Jan Kratochvil 046f33b
	default value if the boundary was not provided by the user.
Jan Kratochvil 046f33b
	* f-exp.y (subrange): Change rules for subrange expressions
Jan Kratochvil 046f33b
	to write the relevant bit sequence onto the elt stack.
Jan Kratochvil 046f33b
	* f-lang.h (f90_range_type): Change the enum to use bit
Jan Kratochvil 046f33b
	values for each boundary, if set by the user.
Jan Kratochvil 046f33b
	* parse.c (operator_length_standard): In case of
Jan Kratochvil 046f33b
	OP_F90_RANGE change the calculation of the number of
Jan Kratochvil 046f33b
	arguments on the elt stack, depending on the number of
Jan Kratochvil 046f33b
	boundaries provided by the user.
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
Signed-off-by: Christoph Weinmann <christoph.t.weinmann@intel.com>
Jan Kratochvil 046f33b
---
Jan Kratochvil 046f33b
 gdb/eval.c   |   14 ++++++--------
Jan Kratochvil 046f33b
 gdb/f-exp.y  |   11 ++++++-----
Jan Kratochvil 046f33b
 gdb/f-lang.h |    6 ++----
Jan Kratochvil 046f33b
 gdb/parse.c  |   21 ++++++++-------------
Jan Kratochvil 046f33b
 4 files changed, 22 insertions(+), 30 deletions(-)
Jan Kratochvil 046f33b
Jan Kratochvil 046f33b
diff --git a/gdb/eval.c b/gdb/eval.c
Jan Kratochvil 046f33b
index 0c1b607..47ba602 100644
Jan Kratochvil 046f33b
--- a/gdb/eval.c
Jan Kratochvil 046f33b
+++ b/gdb/eval.c
Jan Kratochvil 046f33b
@@ -480,12 +480,12 @@ value_f90_subarray (struct value *array, struct expression *exp,
Jan Kratochvil 046f33b
 	  /* If a lower bound was provided by the user, the bit has been
Jan Kratochvil 046f33b
 	     set and we can assign the value from the elt stack.  Same for
Jan Kratochvil 046f33b
 	     upper bound.  */
Jan Kratochvil 046f33b
-	  if ((range->f90_range_type == HIGH_BOUND_DEFAULT)
Jan Kratochvil 046f33b
-	      || range->f90_range_type == NONE_BOUND_DEFAULT)
Jan Kratochvil 046f33b
+	  if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
Jan Kratochvil 046f33b
+	      == SUBARRAY_LOW_BOUND)
Jan Kratochvil 046f33b
 	    range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
Jan Kratochvil 046f33b
 							 pos, noside));
Jan Kratochvil 046f33b
-	  if ((range->f90_range_type == LOW_BOUND_DEFAULT)
Jan Kratochvil 046f33b
-	      || range->f90_range_type == NONE_BOUND_DEFAULT)
Jan Kratochvil 046f33b
+	  if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
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
@@ -526,12 +526,10 @@ value_f90_subarray (struct value *array, struct expression *exp,
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 	    /* If no lower bound was provided by the user, we take the
Jan Kratochvil 046f33b
 	       default boundary.  Same for the high bound.  */
Jan Kratochvil 046f33b
-	    if ((range->f90_range_type == LOW_BOUND_DEFAULT)
Jan Kratochvil 046f33b
-		|| (range->f90_range_type == BOTH_BOUND_DEFAULT))
Jan Kratochvil 046f33b
+	    if ((range->f90_range_type & SUBARRAY_LOW_BOUND) == 0)
Jan Kratochvil 046f33b
 	      range->low = TYPE_LOW_BOUND (index_type);
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
-	    if ((range->f90_range_type == HIGH_BOUND_DEFAULT)
Jan Kratochvil 046f33b
-		|| (range->f90_range_type == BOTH_BOUND_DEFAULT))
Jan Kratochvil 046f33b
+	    if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
Jan Kratochvil 046f33b
 	      range->high = TYPE_HIGH_BOUND (index_type);
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 	    /* Both user provided low and high bound have to be inside the
Jan Kratochvil 046f33b
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
Jan Kratochvil 046f33b
index ab23df0..1ff768c 100644
Jan Kratochvil 046f33b
--- a/gdb/f-exp.y
Jan Kratochvil 046f33b
+++ b/gdb/f-exp.y
Jan Kratochvil 046f33b
@@ -315,26 +315,27 @@ arglist	:	arglist ',' exp   %prec ABOVE_COMMA
Jan Kratochvil 046f33b
 /* There are four sorts of subrange types in F90.  */
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 subrange:	exp ':' exp	%prec ABOVE_COMMA
Jan Kratochvil 046f33b
-			{ write_exp_elt_opcode (pstate, OP_F90_RANGE); 
Jan Kratochvil 046f33b
-			  write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
Jan Kratochvil 046f33b
+			{ write_exp_elt_opcode (pstate, OP_F90_RANGE);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate,
Jan Kratochvil 046f33b
+						 SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND);
Jan Kratochvil 046f33b
 			  write_exp_elt_opcode (pstate, OP_F90_RANGE); }
Jan Kratochvil 046f33b
 	;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 subrange:	exp ':'	%prec ABOVE_COMMA
Jan Kratochvil 046f33b
 			{ write_exp_elt_opcode (pstate, OP_F90_RANGE);
Jan Kratochvil 046f33b
-			  write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND);
Jan Kratochvil 046f33b
 			  write_exp_elt_opcode (pstate, OP_F90_RANGE); }
Jan Kratochvil 046f33b
 	;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 subrange:	':' exp	%prec ABOVE_COMMA
Jan Kratochvil 046f33b
 			{ write_exp_elt_opcode (pstate, OP_F90_RANGE);
Jan Kratochvil 046f33b
-			  write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND);
Jan Kratochvil 046f33b
 			  write_exp_elt_opcode (pstate, OP_F90_RANGE); }
Jan Kratochvil 046f33b
 	;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 subrange:	':'	%prec ABOVE_COMMA
Jan Kratochvil 046f33b
 			{ write_exp_elt_opcode (pstate, OP_F90_RANGE);
Jan Kratochvil 046f33b
-			  write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
Jan Kratochvil 046f33b
+			  write_exp_elt_longcst (pstate, 0);
Jan Kratochvil 046f33b
 			  write_exp_elt_opcode (pstate, OP_F90_RANGE); }
Jan Kratochvil 046f33b
 	;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
Jan Kratochvil 046f33b
index f7a14d7..20cf5bd 100644
Jan Kratochvil 046f33b
--- a/gdb/f-lang.h
Jan Kratochvil 046f33b
+++ b/gdb/f-lang.h
Jan Kratochvil 046f33b
@@ -44,10 +44,8 @@ extern void f_val_print (struct type *, const gdb_byte *, int, CORE_ADDR,
Jan Kratochvil 046f33b
    
Jan Kratochvil 046f33b
 enum f90_range_type
Jan Kratochvil 046f33b
   {
Jan Kratochvil 046f33b
-    BOTH_BOUND_DEFAULT,		/* "(:)"  */
Jan Kratochvil 046f33b
-    LOW_BOUND_DEFAULT,		/* "(:high)"  */
Jan Kratochvil 046f33b
-    HIGH_BOUND_DEFAULT,		/* "(low:)"  */
Jan Kratochvil 046f33b
-    NONE_BOUND_DEFAULT		/* "(low:high)"  */
Jan Kratochvil 046f33b
+    SUBARRAY_LOW_BOUND = 0x1,		/* "(low:)"  */
Jan Kratochvil 046f33b
+    SUBARRAY_HIGH_BOUND = 0x2		/* "(:high)"  */
Jan Kratochvil 046f33b
   };
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
 /* A common block.  */
Jan Kratochvil 046f33b
diff --git a/gdb/parse.c b/gdb/parse.c
Jan Kratochvil 046f33b
index a24c52a..7e45c05 100644
Jan Kratochvil 046f33b
--- a/gdb/parse.c
Jan Kratochvil 046f33b
+++ b/gdb/parse.c
Jan Kratochvil 046f33b
@@ -1006,22 +1006,17 @@ operator_length_standard (const struct expression *expr, int endpos,
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
     case OP_F90_RANGE:
Jan Kratochvil 046f33b
       oplen = 3;
Jan Kratochvil 046f33b
+      args = 0;
Jan Kratochvil 046f33b
       range_type = (enum f90_range_type)
Jan Kratochvil 046f33b
 	longest_to_int (expr->elts[endpos - 2].longconst);
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
-      switch (range_type)
Jan Kratochvil 046f33b
-	{
Jan Kratochvil 046f33b
-	case LOW_BOUND_DEFAULT:
Jan Kratochvil 046f33b
-	case HIGH_BOUND_DEFAULT:
Jan Kratochvil 046f33b
-	  args = 1;
Jan Kratochvil 046f33b
-	  break;
Jan Kratochvil 046f33b
-	case BOTH_BOUND_DEFAULT:
Jan Kratochvil 046f33b
-	  args = 0;
Jan Kratochvil 046f33b
-	  break;
Jan Kratochvil 046f33b
-	case NONE_BOUND_DEFAULT:
Jan Kratochvil 046f33b
-	  args = 2;
Jan Kratochvil 046f33b
-	  break;
Jan Kratochvil 046f33b
-	}
Jan Kratochvil 046f33b
+      /* Increment the argument counter for each argument
Jan Kratochvil 046f33b
+	 provided by the user.  */
Jan Kratochvil 046f33b
+      if ((range_type & SUBARRAY_LOW_BOUND) == SUBARRAY_LOW_BOUND)
Jan Kratochvil 046f33b
+	args++;
Jan Kratochvil 046f33b
+
Jan Kratochvil 046f33b
+      if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
Jan Kratochvil 046f33b
+	args++;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
       break;
Jan Kratochvil 046f33b
 
Jan Kratochvil 046f33b
-- 
Jan Kratochvil 046f33b
1.7.0.7