]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
fortran: change subrange enum to bit field
authorChristoph Weinmann <christoph.t.weinmann@intel.com>
Mon, 23 Nov 2015 09:31:44 +0000 (10:31 +0100)
committerBernhard Heckel <bernhard.heckel@intel.com>
Wed, 7 Sep 2016 10:08:45 +0000 (12:08 +0200)
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.

2013-11-27  Christoph Weinmann  <christoph.t.weinmann@intel.com>

* eval.c (value_f90_subarray): Change evaluation of the
subarray boundaries.  Set boundaries to be either user
provided (bit in range_type was set), or take the default
value if the boundary was not provided by the user.
* expprint.c (print_subexp_standard): Alter boundary com-
putations to use updated range_type enum.
* expprint.h (dump_subexp_body_standard): Dito.
* expression.h (range_type): Change the enum to use bit
values for each boundary, if set by the user.
* f-exp.y (subrange): Change rules for subrange expressions
to write the relevant bit sequence onto the elt stack.
* parse.c (operator_length_standard): In case of OP_RANGE
change the calculation of the number of arguments on the
elt stack, depending on the number of boundaries provided
by the user.
* rust-exp.y (convert_ast_to_expression): Modify calcula-
tion of subscript elements to use altered range_type.
* rust-lang.c (rust_range): Dito.
* rust-lang.c (rust_subscript): Dito.

Signed-off-by: Christoph Weinmann <christoph.t.weinmann@intel.com>
gdb/eval.c
gdb/expprint.c
gdb/expression.h
gdb/f-exp.y
gdb/parse.c
gdb/rust-exp.y
gdb/rust-lang.c

index a6b729d60c80058ecfbc43099417772732c3d813..2d9eb31b53d9f6f1788c424c9ad614528ffba398 100644 (file)
@@ -482,12 +482,12 @@ value_f90_subarray (struct value *array, struct expression *exp,
          /* If a lower bound was provided by the user, the bit has been
             set and we can assign the value from the elt stack.  Same for
             upper bound.  */
-         if ((range->f90_range_type == HIGH_BOUND_DEFAULT)
-             || range->f90_range_type == NONE_BOUND_DEFAULT)
+         if ((range->f90_range_type & SUBARRAY_LOW_BOUND)
+             == SUBARRAY_LOW_BOUND)
            range->low = value_as_long (evaluate_subexp (NULL_TYPE, exp,
                                                         pos, noside));
-         if ((range->f90_range_type == LOW_BOUND_DEFAULT)
-             || range->f90_range_type == NONE_BOUND_DEFAULT)
+         if ((range->f90_range_type & SUBARRAY_HIGH_BOUND)
+             == SUBARRAY_HIGH_BOUND)
            range->high = value_as_long (evaluate_subexp (NULL_TYPE, exp,
                                                          pos, noside));
        }
@@ -528,12 +528,10 @@ value_f90_subarray (struct value *array, struct expression *exp,
 
            /* If no lower bound was provided by the user, we take the
               default boundary.  Same for the high bound.  */
-           if ((range->f90_range_type == LOW_BOUND_DEFAULT)
-               || (range->f90_range_type == BOTH_BOUND_DEFAULT))
+           if ((range->f90_range_type & SUBARRAY_LOW_BOUND) == 0)
              range->low = TYPE_LOW_BOUND (index_type);
 
-           if ((range->f90_range_type == HIGH_BOUND_DEFAULT)
-               || (range->f90_range_type == BOTH_BOUND_DEFAULT))
+           if ((range->f90_range_type & SUBARRAY_HIGH_BOUND) == 0)
              range->high = TYPE_HIGH_BOUND (index_type);
 
            /* Both user provided low and high bound have to be inside the
index c37ecb06164a7d0f20f03934781cc45f42970ab6..214d58eebd23b6d817a60df896c56314d3f4e7ed 100644 (file)
@@ -568,12 +568,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) == SUBARRAY_LOW_BOUND)
          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) == SUBARRAY_HIGH_BOUND)
          print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
        fputs_filtered (")", stream);
        return;
@@ -1055,16 +1053,16 @@ dump_subexp_body_standard (struct expression *exp,
 
        switch (range_type)
          {
-         case BOTH_BOUND_DEFAULT:
+         case SUBARRAY_NONE_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:
@@ -1072,11 +1070,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) == SUBARRAY_LOW_BOUND)
          elt = dump_subexp (exp, stream, elt);
-       if (range_type == LOW_BOUND_DEFAULT
-           || range_type == NONE_BOUND_DEFAULT)
+       if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
          elt = dump_subexp (exp, stream, elt);
       }
       break;
index 4952d8457e90c8ab6446e77aabebb89a164531e5..5a6b72093a50f0b32722fe6f96c9babe88201b7c 100644 (file)
@@ -152,17 +152,14 @@ extern void dump_raw_expression (struct expression *,
                                 struct ui_file *, 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.  */
-   
+/* In an OP_RANGE expression, either bound can be provided by the user, or not.
+   This enumeration type is to identify this.  */
+
 enum range_type
   {
-    BOTH_BOUND_DEFAULT,                /* "(:)"  */
-    LOW_BOUND_DEFAULT,         /* "(:high)"  */
-    HIGH_BOUND_DEFAULT,                /* "(low:)"  */
-    NONE_BOUND_DEFAULT         /* "(low:high)"  */
+    SUBARRAY_NONE_BOUND = 0x0,         /* "( : )"  */
+    SUBARRAY_LOW_BOUND = 0x1,          /* "(low:)"  */
+    SUBARRAY_HIGH_BOUND = 0x2          /* "(:high)"  */
   };
 
 #endif /* !defined (EXPRESSION_H) */
index dc131c17a9cfe0cc77189a7e3cd93721b42c994e..e2c54b608bc978b62b1782213aeb4a3b704a78af 100644 (file)
@@ -260,26 +260,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, 0);
                          write_exp_elt_opcode (pstate, OP_RANGE); }
        ;
 
index 2b00708f1b83994158957ced4a3f936e0bfa05f1..6d54a77092a45987a32c7c760801e240dfffa8bc 100644 (file)
@@ -1006,22 +1006,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) == SUBARRAY_LOW_BOUND)
+       args++;
+
+      if ((range_type & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
+       args++;
 
       break;
 
index aeb605887aa6e844a7f4cad3c99ba41f7da34dfc..b1b9633809414c26772474da6ad954c04c7c4dba 100644 (file)
@@ -2429,23 +2429,17 @@ convert_ast_to_expression (struct parser_state *state,
 
     case OP_RANGE:
       {
-       enum range_type kind = BOTH_BOUND_DEFAULT;
+       enum range_type kind = SUBARRAY_NONE_BOUND;
 
        if (operation->left.op != NULL)
          {
            convert_ast_to_expression (state, operation->left.op, top);
-           kind = HIGH_BOUND_DEFAULT;
+           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);
index 17b20c66aabca2cb02e2636bca8596f00aeda2a2..295002fc0727afa5db4fbdb984cb263260f9cdd3 100644 (file)
@@ -1241,9 +1241,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) == SUBARRAY_LOW_BOUND)
     low = evaluate_subexp (NULL_TYPE, exp, pos, noside);
-  if (kind == LOW_BOUND_DEFAULT || kind == NONE_BOUND_DEFAULT)
+  if ((kind & SUBARRAY_HIGH_BOUND) == SUBARRAY_HIGH_BOUND)
     high = evaluate_subexp (NULL_TYPE, exp, pos, noside);
 
   if (noside == EVAL_SKIP)
@@ -1332,7 +1332,7 @@ rust_compute_range (struct type *type, struct value *range,
 
   *low = 0;
   *high = 0;
-  *kind = BOTH_BOUND_DEFAULT;
+  *kind = SUBARRAY_NONE_BOUND;
 
   if (TYPE_NFIELDS (type) == 0)
     return;
@@ -1340,15 +1340,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));
     }
 }
@@ -1363,7 +1362,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_NONE_BOUND;
   LONGEST high = 0;
   int want_slice = 0;
 
@@ -1425,7 +1424,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) != SUBARRAY_LOW_BOUND))
        low = low_bound;
       if (low < 0)
        error (_("Index less than zero"));
@@ -1443,7 +1442,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) != SUBARRAY_HIGH_BOUND)
            high = high_bound;
          if (high < 0)
            error (_("High index less than zero"));