Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tim Wiederhake <tim.wiederhake@intel.com>
To: gdb-patches@sourceware.org
Cc: Christoph Weinmann <christoph.t.weinmann@intel.com>
Subject: [PATCH 4/5] Fortran: Change subrange enum to bit field.
Date: Mon, 11 Sep 2017 12:58:00 -0000	[thread overview]
Message-ID: <1505134663-29374-5-git-send-email-tim.wiederhake@intel.com> (raw)
In-Reply-To: <1505134663-29374-1-git-send-email-tim.wiederhake@intel.com>

From: Christoph Weinmann <christoph.t.weinmann@intel.com>

Change Fortran subrange enum for subrange expressions to represent a bitfield
for easier manipulation.  Consequently also change occurences and evaluation
of said enum.  The behaviour of GDB is unchanged.

xxxx-yy-zz  Christoph Weinmann  <christoph.t.weinmann@intel.com>
            Tim Wiederhake  <tim.wiederhake@intel.com>

	* expprint.c (print_subexp_standard): Use bitfield instead of enum.
	(dump_subexp_body_standard): Same.
	* f-exp.y (subrange): Same.
	* f-lang.c (f90_value_subarray): Same.
	* parse.c (operator_length_standard): Same.
	* rust-exp.y: Same.
	* rust-lang.c (rust_range, rust_compute_range, rust_subscript): Same.
	* expression.h (enum range_type): Turn into a bitfield.


---
 gdb/expprint.c   | 20 ++++++++------------
 gdb/expression.h | 15 ++++++---------
 gdb/f-exp.y      | 11 ++++++-----
 gdb/f-lang.c     |  8 ++++----
 gdb/parse.c      | 21 ++++++++-------------
 gdb/rust-exp.y   | 12 +++---------
 gdb/rust-lang.c  | 17 ++++++++---------
 7 files changed, 43 insertions(+), 61 deletions(-)

diff --git a/gdb/expprint.c b/gdb/expprint.c
index 9e04f24..19d1c88 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -581,12 +581,10 @@ print_subexp_standard (struct expression *exp, int *pos,
 	*pos += 2;
 
 	fputs_filtered ("RANGE(", stream);
-	if (range_type == HIGH_BOUND_DEFAULT
-	    || range_type == NONE_BOUND_DEFAULT)
+	if ((range_type & SUBARRAY_LOW_BOUND) != 0)
 	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
 	fputs_filtered ("..", stream);
-	if (range_type == LOW_BOUND_DEFAULT
-	    || range_type == NONE_BOUND_DEFAULT)
+	if ((range_type & SUBARRAY_HIGH_BOUND) != 0)
 	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
 	fputs_filtered (")", stream);
 	return;
@@ -1093,16 +1091,16 @@ dump_subexp_body_standard (struct expression *exp,
 
 	switch (range_type)
 	  {
-	  case BOTH_BOUND_DEFAULT:
+	  case SUBARRAY_NO_BOUND:
 	    fputs_filtered ("Range '..'", stream);
 	    break;
-	  case LOW_BOUND_DEFAULT:
+	  case SUBARRAY_HIGH_BOUND:
 	    fputs_filtered ("Range '..EXP'", stream);
 	    break;
-	  case HIGH_BOUND_DEFAULT:
+	  case SUBARRAY_LOW_BOUND:
 	    fputs_filtered ("Range 'EXP..'", stream);
 	    break;
-	  case NONE_BOUND_DEFAULT:
+	  case (SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND):
 	    fputs_filtered ("Range 'EXP..EXP'", stream);
 	    break;
 	  default:
@@ -1110,11 +1108,9 @@ dump_subexp_body_standard (struct expression *exp,
 	    break;
 	  }
 
-	if (range_type == HIGH_BOUND_DEFAULT
-	    || range_type == NONE_BOUND_DEFAULT)
+	if ((range_type & SUBARRAY_LOW_BOUND) != 0)
 	  elt = dump_subexp (exp, stream, elt);
-	if (range_type == LOW_BOUND_DEFAULT
-	    || range_type == NONE_BOUND_DEFAULT)
+	if ((range_type & SUBARRAY_HIGH_BOUND) != 0)
 	  elt = dump_subexp (exp, stream, elt);
       }
       break;
diff --git a/gdb/expression.h b/gdb/expression.h
index 9e4ddf5..c794198 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -155,17 +155,14 @@ extern void dump_raw_expression (struct expression *,
 				 struct ui_file *, const char *);
 extern void dump_prefix_expression (struct expression *, struct ui_file *);
 
-/* In an OP_RANGE expression, either bound could be empty, indicating
-   that its value is by default that of the corresponding bound of the
-   array or string.  So we have four sorts of subrange.  This
-   enumeration type is to identify this.  */
-   
+/* Flags to indicate which boundarys are set in an OP_RANGE expression.  Values
+   can be or'ed together.  */
+
 enum range_type
   {
-    BOTH_BOUND_DEFAULT,		/* "(:)"  */
-    LOW_BOUND_DEFAULT,		/* "(:high)"  */
-    HIGH_BOUND_DEFAULT,		/* "(low:)"  */
-    NONE_BOUND_DEFAULT		/* "(low:high)"  */
+    SUBARRAY_NO_BOUND = 0x0,		/* "( : )"  */
+    SUBARRAY_LOW_BOUND = 0x1,		/* "(low:)"  */
+    SUBARRAY_HIGH_BOUND = 0x2		/* "(:high)"  */
   };
 
 #endif /* !defined (EXPRESSION_H) */
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index bfa9d09..96b9b05 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -261,26 +261,27 @@ arglist	:	arglist ',' exp   %prec ABOVE_COMMA
 /* There are four sorts of subrange types in F90.  */
 
 subrange:	exp ':' exp	%prec ABOVE_COMMA
-			{ write_exp_elt_opcode (pstate, OP_RANGE); 
-			  write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
+			{ write_exp_elt_opcode (pstate, OP_RANGE);
+			  write_exp_elt_longcst (pstate,
+						 SUBARRAY_LOW_BOUND | SUBARRAY_HIGH_BOUND);
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
 	;
 
 subrange:	exp ':'	%prec ABOVE_COMMA
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
-			  write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
+			  write_exp_elt_longcst (pstate, SUBARRAY_LOW_BOUND);
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
 	;
 
 subrange:	':' exp	%prec ABOVE_COMMA
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
-			  write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
+			  write_exp_elt_longcst (pstate, SUBARRAY_HIGH_BOUND);
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
 	;
 
 subrange:	':'	%prec ABOVE_COMMA
 			{ write_exp_elt_opcode (pstate, OP_RANGE);
-			  write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
+			  write_exp_elt_longcst (pstate, SUBARRAY_NO_BOUND);
 			  write_exp_elt_opcode (pstate, OP_RANGE); }
 	;
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 25bb758..832a3e7 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -503,9 +503,9 @@ f90_value_subarray (struct value *array, struct expression *exp, int *pos,
 
 	  *pos += 3;
 
-	  if (type == HIGH_BOUND_DEFAULT || type == NONE_BOUND_DEFAULT)
+	  if ((type & SUBARRAY_LOW_BOUND) != 0)
 	    lo = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
-	  if (type == LOW_BOUND_DEFAULT || type == NONE_BOUND_DEFAULT)
+	  if ((type & SUBARRAY_HIGH_BOUND) != 0)
 	    hi = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
 
 	  subscript_array.emplace_back (type, lo, hi);
@@ -533,9 +533,9 @@ f90_value_subarray (struct value *array, struct expression *exp, int *pos,
 
       if (it->kind == subscript::SUBSCRIPT_RANGE)
 	{
-	  if (it->type == LOW_BOUND_DEFAULT || it->type == BOTH_BOUND_DEFAULT)
+	  if ((it->type & SUBARRAY_LOW_BOUND) == 0)
 	    it->low = lo;
-	  if (it->type == HIGH_BOUND_DEFAULT || it->type == BOTH_BOUND_DEFAULT)
+	  if ((it->type & SUBARRAY_HIGH_BOUND) == 0)
 	    it->high = hi;
 
 	  if (it->low < lo || it->low > hi || it->high < lo || it->high > hi)
diff --git a/gdb/parse.c b/gdb/parse.c
index fb0dff2..dcf1b31 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1001,22 +1001,17 @@ operator_length_standard (const struct expression *expr, int endpos,
 
     case OP_RANGE:
       oplen = 3;
+      args = 0;
       range_type = (enum range_type)
 	longest_to_int (expr->elts[endpos - 2].longconst);
 
-      switch (range_type)
-	{
-	case LOW_BOUND_DEFAULT:
-	case HIGH_BOUND_DEFAULT:
-	  args = 1;
-	  break;
-	case BOTH_BOUND_DEFAULT:
-	  args = 0;
-	  break;
-	case NONE_BOUND_DEFAULT:
-	  args = 2;
-	  break;
-	}
+      /* Increment the argument counter for each argument
+	 provided by the user.  */
+      if ((range_type & SUBARRAY_LOW_BOUND) != 0)
+	args++;
+
+      if ((range_type & SUBARRAY_HIGH_BOUND) != 0)
+	args++;
 
       break;
 
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 4cb3aa2..9adcae5 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2460,23 +2460,17 @@ convert_ast_to_expression (struct parser_state *state,
 
     case OP_RANGE:
       {
-	enum range_type kind = BOTH_BOUND_DEFAULT;
+	enum range_type kind = SUBARRAY_NO_BOUND;
 
 	if (operation->left.op != NULL)
 	  {
 	    convert_ast_to_expression (state, operation->left.op, top);
-	    kind = HIGH_BOUND_DEFAULT;
+	    kind = (range_type) (kind | SUBARRAY_LOW_BOUND);
 	  }
 	if (operation->right.op != NULL)
 	  {
 	    convert_ast_to_expression (state, operation->right.op, top);
-	    if (kind == BOTH_BOUND_DEFAULT)
-	      kind = LOW_BOUND_DEFAULT;
-	    else
-	      {
-		gdb_assert (kind == HIGH_BOUND_DEFAULT);
-		kind = NONE_BOUND_DEFAULT;
-	      }
+	    kind = (range_type) (kind | SUBARRAY_HIGH_BOUND);
 	  }
 	write_exp_elt_opcode (state, OP_RANGE);
 	write_exp_elt_longcst (state, kind);
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index c5764bf..45005fd5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1311,9 +1311,9 @@ rust_range (struct expression *exp, int *pos, enum noside noside)
   kind = (enum range_type) longest_to_int (exp->elts[*pos + 1].longconst);
   *pos += 3;
 
-  if (kind == HIGH_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
+  if ((kind & SUBARRAY_LOW_BOUND) != 0)
     low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
-  if (kind == LOW_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
+  if ((kind & SUBARRAY_HIGH_BOUND) != 0)
     high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
 
   if (noside == EVAL_SKIP)
@@ -1402,7 +1402,7 @@ rust_compute_range (struct type *type, struct value *range,
 
   *low = 0;
   *high = 0;
-  *kind = BOTH_BOUND_DEFAULT;
+  *kind = SUBARRAY_NO_BOUND;
 
   if (TYPE_NFIELDS (type) == 0)
     return;
@@ -1410,15 +1410,14 @@ rust_compute_range (struct type *type, struct value *range,
   i = 0;
   if (strcmp (TYPE_FIELD_NAME (type, 0), "start") == 0)
     {
-      *kind = HIGH_BOUND_DEFAULT;
+      *kind = SUBARRAY_LOW_BOUND;
       *low = value_as_long (value_field (range, 0));
       ++i;
     }
   if (TYPE_NFIELDS (type) > i
       && strcmp (TYPE_FIELD_NAME (type, i), "end") == 0)
     {
-      *kind = (*kind == BOTH_BOUND_DEFAULT
-	       ? LOW_BOUND_DEFAULT : NONE_BOUND_DEFAULT);
+      *kind = (range_type) (*kind | SUBARRAY_HIGH_BOUND);
       *high = value_as_long (value_field (range, i));
     }
 }
@@ -1433,7 +1432,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
   struct type *rhstype;
   LONGEST low, high_bound;
   /* Initialized to appease the compiler.  */
-  enum range_type kind = BOTH_BOUND_DEFAULT;
+  enum range_type kind = SUBARRAY_NO_BOUND;
   LONGEST high = 0;
   int want_slice = 0;
 
@@ -1495,7 +1494,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
 	error (_("Cannot subscript non-array type"));
 
       if (want_slice
-	  && (kind == BOTH_BOUND_DEFAULT || kind == LOW_BOUND_DEFAULT))
+	  && ((kind & SUBARRAY_LOW_BOUND) == 0))
 	low = low_bound;
       if (low < 0)
 	error (_("Index less than zero"));
@@ -1513,7 +1512,7 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside,
 	  CORE_ADDR addr;
 	  struct value *addrval, *tem;
 
-	  if (kind == BOTH_BOUND_DEFAULT || kind == HIGH_BOUND_DEFAULT)
+	  if ((kind & SUBARRAY_HIGH_BOUND) == 0)
 	    high = high_bound;
 	  if (high < 0)
 	    error (_("High index less than zero"));
-- 
2.7.4


  reply	other threads:[~2017-09-11 12:58 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 ` Tim Wiederhake [this message]
2017-09-15 22:29   ` [PATCH 4/5] Fortran: Change subrange enum to bit field 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
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 2/5] Fortran: Move value_f90_subarray Tim Wiederhake
2017-09-15 20:27   ` Simon Marchi
2017-09-11 12:58 ` [PATCH 3/5] Fortran: Allow multi-dimensional subarrays Tim Wiederhake
2017-09-15 22:08   ` 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=1505134663-29374-5-git-send-email-tim.wiederhake@intel.com \
    --to=tim.wiederhake@intel.com \
    --cc=christoph.t.weinmann@intel.com \
    --cc=gdb-patches@sourceware.org \
    /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