Jan Kratochvil fdbd5e3
http://sourceware.org/ml/gdb-patches/2016-02/msg00845.html
Jan Kratochvil fdbd5e3
Subject: [PATCH v2 3/6] fortran: change subrange enum to bit field
Jan Kratochvil fdbd5e3
Jan Kratochvil 046f33b
From: Christoph Weinmann <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
Signed-off-by: Christoph Weinmann <christoph.t.weinmann@intel.com>
Jan Kratochvil 046f33b
---
Jan Kratochvil fdbd5e3
 gdb/eval.c   | 14 ++++++--------
Jan Kratochvil fdbd5e3
 gdb/f-exp.y  | 11 ++++++-----
Jan Kratochvil fdbd5e3
 gdb/f-lang.h |  6 ++----
Jan Kratochvil fdbd5e3
 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 fdbd5e3
index 164d7ab..9b8b051 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 fdbd5e3
index 9343abb..b1206de 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 fdbd5e3
index eeca107..4d56bf7 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 fdbd5e3
index 4191fc6..d500279 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 fdbd5e3
2.5.0
Jan Kratochvil fdbd5e3