]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove now-unused C evaluator code
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:41 +0000 (07:28 -0700)
Now that the C parser has switched to the new style, there is no need
for the old C evaluation code.  This affects some other languages that
were relying on the C code.

gdb/ChangeLog
2021-03-08  Tom Tromey  <tom@tromey.com>

* go-lang.c (go_language::expression_ops): Don't declare.
* go-lang.h (class go_language) <expression_ops>: Remove.
* opencl-lang.c (evaluate_subexp_opencl, exp_descriptor_opencl):
Remove.
(class opencl_language) <expression_ops>: Remove.
* d-lang.c (class d_language) <expression_ops>: Remove.
* c-lang.h (evaluate_subexp_c, exp_descriptor_c): Don't declare.
* c-lang.c (evaluate_subexp_c, exp_descriptor_c): Remove.
(class c_language, class cplus_language, class asm_language)
(class minimal_language) <expression_ops>: Remove.

gdb/ChangeLog
gdb/c-lang.c
gdb/c-lang.h
gdb/d-lang.c
gdb/go-lang.c
gdb/go-lang.h
gdb/opencl-lang.c

index 0853471221e9550f52e1af1c3262f78041a1ad7c..630679aaecab6fb17237d1ca89014ffaf2f4e8a4 100644 (file)
@@ -1,3 +1,16 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * go-lang.c (go_language::expression_ops): Don't declare.
+       * go-lang.h (class go_language) <expression_ops>: Remove.
+       * opencl-lang.c (evaluate_subexp_opencl, exp_descriptor_opencl):
+       Remove.
+       (class opencl_language) <expression_ops>: Remove.
+       * d-lang.c (class d_language) <expression_ops>: Remove.
+       * c-lang.h (evaluate_subexp_c, exp_descriptor_c): Don't declare.
+       * c-lang.c (evaluate_subexp_c, exp_descriptor_c): Remove.
+       (class c_language, class cplus_language, class asm_language)
+       (class minimal_language) <expression_ops>: Remove.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * ada-lang.c (resolve_subexp, replace_operator_with_call)
index d191d07a00abb787e2f643e024d77a4fd1c2d6c4..00ab941bbb8fafad399c7d9243d914194bde4550 100644 (file)
@@ -579,157 +579,6 @@ parse_one_string (struct obstack *output, const char *data, int len,
     }
 }
 
-/* Expression evaluator for the C language family.  Most operations
-   are delegated to evaluate_subexp_standard; see that function for a
-   description of the arguments.  */
-
-struct value *
-evaluate_subexp_c (struct type *expect_type, struct expression *exp,
-                  int *pos, enum noside noside)
-{
-  enum exp_opcode op = exp->elts[*pos].opcode;
-
-  switch (op)
-    {
-    case OP_STRING:
-      {
-       int oplen, limit;
-       struct type *type;
-       struct value *result;
-       c_string_type dest_type;
-       const char *dest_charset;
-       int satisfy_expected = 0;
-
-       auto_obstack output;
-
-       ++*pos;
-       oplen = longest_to_int (exp->elts[*pos].longconst);
-
-       ++*pos;
-       limit = *pos + BYTES_TO_EXP_ELEM (oplen + 1);
-       dest_type = ((enum c_string_type_values)
-                    longest_to_int (exp->elts[*pos].longconst));
-       switch (dest_type & ~C_CHAR)
-         {
-         case C_STRING:
-           type = language_string_char_type (exp->language_defn,
-                                             exp->gdbarch);
-           break;
-         case C_WIDE_STRING:
-           type = lookup_typename (exp->language_defn, "wchar_t", NULL, 0);
-           break;
-         case C_STRING_16:
-           type = lookup_typename (exp->language_defn, "char16_t", NULL, 0);
-           break;
-         case C_STRING_32:
-           type = lookup_typename (exp->language_defn, "char32_t", NULL, 0);
-           break;
-         default:
-           internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
-         }
-
-       /* Ensure TYPE_LENGTH is valid for TYPE.  */
-       check_typedef (type);
-
-       /* If the caller expects an array of some integral type,
-          satisfy them.  If something odder is expected, rely on the
-          caller to cast.  */
-       if (expect_type && expect_type->code () == TYPE_CODE_ARRAY)
-         {
-           struct type *element_type
-             = check_typedef (TYPE_TARGET_TYPE (expect_type));
-
-           if (element_type->code () == TYPE_CODE_INT
-               || element_type->code () == TYPE_CODE_CHAR)
-             {
-               type = element_type;
-               satisfy_expected = 1;
-             }
-         }
-
-       dest_charset = charset_for_string_type (dest_type, exp->gdbarch);
-
-       ++*pos;
-       while (*pos < limit)
-         {
-           int len;
-
-           len = longest_to_int (exp->elts[*pos].longconst);
-
-           ++*pos;
-           if (noside != EVAL_SKIP)
-             parse_one_string (&output, &exp->elts[*pos].string, len,
-                               dest_charset, type);
-           *pos += BYTES_TO_EXP_ELEM (len);
-         }
-
-       /* Skip the trailing length and opcode.  */
-       *pos += 2;
-
-       if (noside == EVAL_SKIP)
-         {
-           /* Return a dummy value of the appropriate type.  */
-           if (expect_type != NULL)
-             result = allocate_value (expect_type);
-           else if ((dest_type & C_CHAR) != 0)
-             result = allocate_value (type);
-           else
-             result = value_cstring ("", 0, type);
-           return result;
-         }
-
-       if ((dest_type & C_CHAR) != 0)
-         {
-           LONGEST value;
-
-           if (obstack_object_size (&output) != TYPE_LENGTH (type))
-             error (_("Could not convert character "
-                      "constant to target character set"));
-           value = unpack_long (type, (gdb_byte *) obstack_base (&output));
-           result = value_from_longest (type, value);
-         }
-       else
-         {
-           int i;
-
-           /* Write the terminating character.  */
-           for (i = 0; i < TYPE_LENGTH (type); ++i)
-             obstack_1grow (&output, 0);
-
-           if (satisfy_expected)
-             {
-               LONGEST low_bound, high_bound;
-               int element_size = TYPE_LENGTH (type);
-
-               if (!get_discrete_bounds (expect_type->index_type (),
-                                         &low_bound, &high_bound))
-                 {
-                   low_bound = 0;
-                   high_bound = (TYPE_LENGTH (expect_type) / element_size) - 1;
-                 }
-               if (obstack_object_size (&output) / element_size
-                   > (high_bound - low_bound + 1))
-                 error (_("Too many array elements"));
-
-               result = allocate_value (expect_type);
-               memcpy (value_contents_raw (result), obstack_base (&output),
-                       obstack_object_size (&output));
-             }
-           else
-             result = value_cstring ((const char *) obstack_base (&output),
-                                     obstack_object_size (&output),
-                                     type);
-         }
-       return result;
-      }
-      break;
-
-    default:
-      break;
-    }
-  return evaluate_subexp_standard (expect_type, exp, pos, noside);
-}
-
 namespace expr
 {
 
@@ -969,15 +818,6 @@ c_language_arch_info (struct gdbarch *gdbarch,
   lai->set_bool_type (builtin->builtin_int);
 }
 
-const struct exp_descriptor exp_descriptor_c = 
-{
-  print_subexp_standard,
-  operator_length_standard,
-  operator_check_standard,
-  dump_subexp_body_standard,
-  evaluate_subexp_c
-};
-
 /* Class representing the C language.  */
 
 class c_language : public language_defn
@@ -1049,11 +889,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_c; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return c_op_print_tab; }
 };
@@ -1232,11 +1067,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_c; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return c_op_print_tab; }
 
@@ -1313,11 +1143,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_c; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return c_op_print_tab; }
 };
@@ -1375,11 +1200,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_c; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return c_op_print_tab; }
 };
index a488c04c5695d916a1eeda0f9a1f5c9106bbfee6..543a62632d512b0d08e7bc571a842597f6b26f39 100644 (file)
@@ -90,10 +90,7 @@ extern void c_value_print (struct value *, struct ui_file *,
 
 /* These are in c-lang.c: */
 
-extern struct value *evaluate_subexp_c (struct type *expect_type,
-                                       struct expression *exp,
-                                       int *pos,
-                                       enum noside noside);
+extern void c_printchar (int, struct type *, struct ui_file *);
 
 extern void c_printstr (struct ui_file * stream,
                        struct type *elttype,
@@ -106,8 +103,6 @@ extern void c_printstr (struct ui_file * stream,
 extern void c_language_arch_info (struct gdbarch *gdbarch,
                                  struct language_arch_info *lai);
 
-extern const struct exp_descriptor exp_descriptor_c;
-
 extern void c_emit_char (int c, struct type *type,
                         struct ui_file *stream, int quoter);
 
index 65ee7409c80b04dd5f1226e999904d7553aafc7d..4488c10e6092118f394265a844e2315bd5000210 100644 (file)
@@ -219,11 +219,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_c; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return d_op_print_tab; }
 };
index eafd868baf41accc596d3b88bc6901481a937ac8..3af89b36c2f8c7b0e66229024d359f0fe760c719 100644 (file)
@@ -386,14 +386,6 @@ go_language::demangle_symbol (const char *mangled_name, int options) const
   return result;
 }
 
-/* See language.h.  */
-
-const struct exp_descriptor *
-go_language::expression_ops () const
-{
-  return &exp_descriptor_c;
-}
-
 /* Given a Go symbol, return its package or NULL if unknown.
    Space for the result is malloc'd, caller must free.  */
 
index 71f91803d6fd46adc5e630ed194b88c483c75153..5d45c14fc06dbe6e1f4666c6b21fa535e04a4d9b 100644 (file)
@@ -137,10 +137,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override;
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return op_print_tab; }
 
index c5150953022cab6efc05353cc6e3eda4db40c17a..b283be173c455b6b826910420eef0b66f7a1288c 100644 (file)
@@ -692,272 +692,6 @@ eval_opencl_assign (struct type *expect_type, struct expression *exp,
   return value_assign (arg1, arg2);
 }
 
-/* Expression evaluator for the OpenCL.  Most operations are delegated to
-   evaluate_subexp_standard; see that function for a description of the
-   arguments.  */
-
-static struct value *
-evaluate_subexp_opencl (struct type *expect_type, struct expression *exp,
-                  int *pos, enum noside noside)
-{
-  enum exp_opcode op = exp->elts[*pos].opcode;
-  struct value *arg1 = NULL;
-  struct value *arg2 = NULL;
-  struct type *type1, *type2;
-
-  switch (op)
-    {
-    /* Handle assignment and cast operators to support OpenCL-style
-       scalar-to-vector widening.  */
-    case BINOP_ASSIGN:
-      (*pos)++;
-      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-      type1 = value_type (arg1);
-      arg2 = evaluate_subexp (type1, exp, pos, noside);
-
-      return eval_opencl_assign (expect_type, exp, noside, op, arg1, arg2);
-
-    case UNOP_CAST:
-      type1 = exp->elts[*pos + 1].type;
-      (*pos) += 2;
-      arg1 = evaluate_subexp (type1, exp, pos, noside);
-
-      if (noside == EVAL_SKIP)
-       return value_from_longest (builtin_type (exp->gdbarch)->
-                                  builtin_int, 1);
-
-      return opencl_value_cast (type1, arg1);
-
-    case UNOP_CAST_TYPE:
-      (*pos)++;
-      arg1 = evaluate_subexp (NULL, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
-      type1 = value_type (arg1);
-      arg1 = evaluate_subexp (type1, exp, pos, noside);
-
-      if (noside == EVAL_SKIP)
-       return value_from_longest (builtin_type (exp->gdbarch)->
-                                  builtin_int, 1);
-
-      return opencl_value_cast (type1, arg1);
-
-    /* Handle binary relational and equality operators that are either not
-       or differently defined for GNU vectors.  */
-    case BINOP_EQUAL:
-    case BINOP_NOTEQUAL:
-    case BINOP_LESS:
-    case BINOP_GTR:
-    case BINOP_GEQ:
-    case BINOP_LEQ:
-      (*pos)++;
-      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-      arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
-
-      if (noside == EVAL_SKIP)
-       return value_from_longest (builtin_type (exp->gdbarch)->
-                                  builtin_int, 1);
-
-      return opencl_relop (expect_type, exp, noside, op, arg1, arg2);
-
-    /* Handle the logical unary operator not(!).  */
-    case UNOP_LOGICAL_NOT:
-      (*pos)++;
-      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-
-      if (noside == EVAL_SKIP)
-       return value_from_longest (builtin_type (exp->gdbarch)->
-                                  builtin_int, 1);
-
-      return opencl_logical_not (expect_type, exp, noside, op, arg1);
-
-    /* Handle the logical operator and(&&) and or(||).  */
-    case BINOP_LOGICAL_AND:
-    case BINOP_LOGICAL_OR:
-      (*pos)++;
-      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-
-      if (noside == EVAL_SKIP)
-       {
-         evaluate_subexp (nullptr, exp, pos, noside);
-
-         return value_from_longest (builtin_type (exp->gdbarch)->
-                                    builtin_int, 1);
-       }
-      else
-       {
-         /* For scalar operations we need to avoid evaluating operands
-            unnecessarily.  However, for vector operations we always need to
-            evaluate both operands.  Unfortunately we only know which of the
-            two cases apply after we know the type of the second operand.
-            Therefore we evaluate it once using EVAL_AVOID_SIDE_EFFECTS.  */
-         int oldpos = *pos;
-
-         arg2 = evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
-         *pos = oldpos;
-         type1 = check_typedef (value_type (arg1));
-         type2 = check_typedef (value_type (arg2));
-
-         if ((type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
-             || (type2->code () == TYPE_CODE_ARRAY && type2->is_vector ()))
-           {
-             arg2 = evaluate_subexp (nullptr, exp, pos, noside);
-
-             return opencl_relop (nullptr, exp, noside, op, arg1, arg2);
-           }
-         else
-           {
-             /* For scalar built-in types, only evaluate the right
-                hand operand if the left hand operand compares
-                unequal(&&)/equal(||) to 0.  */
-             int res;
-             int tmp = value_logical_not (arg1);
-
-             if (op == BINOP_LOGICAL_OR)
-               tmp = !tmp;
-
-             arg2
-               = evaluate_subexp (nullptr, exp, pos, tmp ? EVAL_SKIP : noside);
-             type1 = language_bool_type (exp->language_defn, exp->gdbarch);
-
-             if (op == BINOP_LOGICAL_AND)
-               res = !tmp && !value_logical_not (arg2);
-             else /* BINOP_LOGICAL_OR */
-               res = tmp || !value_logical_not (arg2);
-
-             return value_from_longest (type1, res);
-           }
-       }
-
-    /* Handle the ternary selection operator.  */
-    case TERNOP_COND:
-      (*pos)++;
-      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-      type1 = check_typedef (value_type (arg1));
-      if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
-       {
-         struct value *arg3, *tmp, *ret;
-         struct type *eltype2, *type3, *eltype3;
-         int t2_is_vec, t3_is_vec, i;
-         LONGEST lowb1, lowb2, lowb3, highb1, highb2, highb3;
-
-         arg2 = evaluate_subexp (nullptr, exp, pos, noside);
-         arg3 = evaluate_subexp (nullptr, exp, pos, noside);
-         type2 = check_typedef (value_type (arg2));
-         type3 = check_typedef (value_type (arg3));
-         t2_is_vec
-           = type2->code () == TYPE_CODE_ARRAY && type2->is_vector ();
-         t3_is_vec
-           = type3->code () == TYPE_CODE_ARRAY && type3->is_vector ();
-
-         /* Widen the scalar operand to a vector if necessary.  */
-         if (t2_is_vec || !t3_is_vec)
-           {
-             arg3 = opencl_value_cast (type2, arg3);
-             type3 = value_type (arg3);
-           }
-         else if (!t2_is_vec || t3_is_vec)
-           {
-             arg2 = opencl_value_cast (type3, arg2);
-             type2 = value_type (arg2);
-           }
-         else if (!t2_is_vec || !t3_is_vec)
-           {
-             /* Throw an error if arg2 or arg3 aren't vectors.  */
-             error (_("\
-Cannot perform conditional operation on incompatible types"));
-           }
-
-         eltype2 = check_typedef (TYPE_TARGET_TYPE (type2));
-         eltype3 = check_typedef (TYPE_TARGET_TYPE (type3));
-
-         if (!get_array_bounds (type1, &lowb1, &highb1)
-             || !get_array_bounds (type2, &lowb2, &highb2)
-             || !get_array_bounds (type3, &lowb3, &highb3))
-           error (_("Could not determine the vector bounds"));
-
-         /* Throw an error if the types of arg2 or arg3 are incompatible.  */
-         if (eltype2->code () != eltype3->code ()
-             || TYPE_LENGTH (eltype2) != TYPE_LENGTH (eltype3)
-             || eltype2->is_unsigned () != eltype3->is_unsigned ()
-             || lowb2 != lowb3 || highb2 != highb3)
-           error (_("\
-Cannot perform operation on vectors with different types"));
-
-         /* Throw an error if the sizes of arg1 and arg2/arg3 differ.  */
-         if (lowb1 != lowb2 || lowb1 != lowb3
-             || highb1 != highb2 || highb1 != highb3)
-           error (_("\
-Cannot perform conditional operation on vectors with different sizes"));
-
-         ret = allocate_value (type2);
-
-         for (i = 0; i < highb1 - lowb1 + 1; i++)
-           {
-             tmp = value_logical_not (value_subscript (arg1, i)) ?
-                   value_subscript (arg3, i) : value_subscript (arg2, i);
-             memcpy (value_contents_writeable (ret) +
-                     i * TYPE_LENGTH (eltype2), value_contents_all (tmp),
-                     TYPE_LENGTH (eltype2));
-           }
-
-         return ret;
-       }
-      else
-       {
-         if (value_logical_not (arg1))
-           {
-             /* Skip the second operand.  */
-             evaluate_subexp (nullptr, exp, pos, EVAL_SKIP);
-
-             return evaluate_subexp (nullptr, exp, pos, noside);
-           }
-         else
-           {
-             /* Skip the third operand.  */
-             arg2 = evaluate_subexp (nullptr, exp, pos, noside);
-             evaluate_subexp (nullptr, exp, pos, EVAL_SKIP);
-
-             return arg2;
-           }
-       }
-
-    /* Handle STRUCTOP_STRUCT to allow component access on OpenCL vectors.  */
-    case STRUCTOP_STRUCT:
-      {
-       int pc = (*pos)++;
-       int tem = longest_to_int (exp->elts[pc + 1].longconst);
-
-       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
-       arg1 = evaluate_subexp (nullptr, exp, pos, noside);
-       type1 = check_typedef (value_type (arg1));
-
-       if (noside == EVAL_SKIP)
-         {
-           return value_from_longest (builtin_type (exp->gdbarch)->
-                                      builtin_int, 1);
-         }
-       else if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
-         {
-           return opencl_component_ref (exp, arg1, &exp->elts[pc + 2].string,
-                                        noside);
-         }
-       else
-         {
-           struct value *v = value_struct_elt (&arg1, NULL,
-                                               &exp->elts[pc + 2].string, NULL,
-                                               "structure");
-
-           if (noside == EVAL_AVOID_SIDE_EFFECTS)
-             v = value_zero (value_type (v), VALUE_LVAL (v));
-           return v;
-         }
-      }
-    default:
-      break;
-    }
-
-  return evaluate_subexp_c (expect_type, exp, pos, noside);
-}
-
 namespace expr
 {
 
@@ -1119,15 +853,6 @@ Cannot perform conditional operation on vectors with different sizes"));
 
 } /* namespace expr */
 
-const struct exp_descriptor exp_descriptor_opencl =
-{
-  print_subexp_standard,
-  operator_length_standard,
-  operator_check_standard,
-  dump_subexp_body_standard,
-  evaluate_subexp_opencl
-};
-
 /* Class representing the OpenCL language.  */
 
 class opencl_language : public language_defn
@@ -1251,11 +976,6 @@ public:
 
   /* See language.h.  */
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_opencl; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
   { return c_op_print_tab; }
 };