]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove per-language op_name functions
authorTom Tromey <tom@tromey.com>
Mon, 30 Nov 2020 08:37:10 +0000 (01:37 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 30 Nov 2020 08:37:10 +0000 (01:37 -0700)
enum exp_opcode is created from all the .def files, but then each
language is required to implement its own op_name function to turn an
enum value to a string.  This seemed over-complicated to me, and this
patch removes the per-language functions in favor of simply using the
.def names for all languages.  Note that op_name is only used for
dumping expressions, which is a maintainer/debug feature.
Furthermore, I don't think there was any case where the .def name and
the string name differed.

gdb/ChangeLog
2020-11-30  Tom Tromey  <tom@tromey.com>

* rust-lang.c (rust_op_name): Remove.
(exp_descriptor_rust): Update.
* parser-defs.h (op_name_standard): Don't declare.
(struct exp_descriptor) <op_name>: Remove.
* parse.c (exp_descriptor_standard): Update.
* opencl-lang.c (exp_descriptor_opencl): Update.
* m2-lang.c (m2_language::exp_descriptor_modula2): Update.
* f-lang.c (op_name_f): Remove.
(f_language::exp_descriptor_tab): Update.
* expression.h (op_name): Update.
* expprint.c (op_name): Rewrite.
(op_name_standard): Remove.
(dump_raw_expression, dump_subexp): Update.
* c-lang.c (exp_descriptor_c): Update.
* ax-gdb.c (gen_expr): Update.
* ada-lang.c (ada_op_name): Remove.
(ada_exp_descriptor): Update.

12 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/ax-gdb.c
gdb/c-lang.c
gdb/expprint.c
gdb/expression.h
gdb/f-lang.c
gdb/m2-lang.c
gdb/opencl-lang.c
gdb/parse.c
gdb/parser-defs.h
gdb/rust-lang.c

index 813305d0fdc4ff125c7fb3dbfa2673dac8b7c1f5..b6c4862ae9a2bea168ea3d9b6be1687d967928b3 100644 (file)
@@ -1,3 +1,23 @@
+2020-11-30  Tom Tromey  <tom@tromey.com>
+
+       * rust-lang.c (rust_op_name): Remove.
+       (exp_descriptor_rust): Update.
+       * parser-defs.h (op_name_standard): Don't declare.
+       (struct exp_descriptor) <op_name>: Remove.
+       * parse.c (exp_descriptor_standard): Update.
+       * opencl-lang.c (exp_descriptor_opencl): Update.
+       * m2-lang.c (m2_language::exp_descriptor_modula2): Update.
+       * f-lang.c (op_name_f): Remove.
+       (f_language::exp_descriptor_tab): Update.
+       * expression.h (op_name): Update.
+       * expprint.c (op_name): Rewrite.
+       (op_name_standard): Remove.
+       (dump_raw_expression, dump_subexp): Update.
+       * c-lang.c (exp_descriptor_c): Update.
+       * ax-gdb.c (gen_expr): Update.
+       * ada-lang.c (ada_op_name): Remove.
+       (ada_exp_descriptor): Update.
+
 2020-11-30  Tom Tromey  <tom@tromey.com>
 
        * eval.c (init_array_element): Remove.
index 714227d24dd5402cb9efec6172587730cf3b61c8..906671155d03426fd29e4357125e0c35e8301aa5 100644 (file)
@@ -127,8 +127,6 @@ static void replace_operator_with_call (expression_up *, int, int, int,
 
 static int possible_user_operator_p (enum exp_opcode, struct value **);
 
-static const char *ada_op_name (enum exp_opcode);
-
 static const char *ada_decoded_op_name (enum exp_opcode);
 
 static int numeric_type_p (struct type *);
@@ -13289,27 +13287,6 @@ ada_operator_check (struct expression *exp, int pos,
   return 0;
 }
 
-static const char *
-ada_op_name (enum exp_opcode opcode)
-{
-  switch (opcode)
-    {
-    default:
-      return op_name_standard (opcode);
-
-#define OP_DEFN(op, len, args, binop) case op: return #op;
-      ADA_OPERATORS;
-#undef OP_DEFN
-
-    case OP_AGGREGATE:
-      return "OP_AGGREGATE";
-    case OP_CHOICES:
-      return "OP_CHOICES";
-    case OP_NAME:
-      return "OP_NAME";
-    }
-}
-
 /* As for operator_length, but assumes PC is pointing at the first
    element of the operator, and gives meaningful results only for the 
    Ada-specific operators, returning 0 for *OPLENP and *ARGSP otherwise.  */
@@ -13601,7 +13578,6 @@ static const struct exp_descriptor ada_exp_descriptor = {
   ada_print_subexp,
   ada_operator_length,
   ada_operator_check,
-  ada_op_name,
   ada_dump_subexp_body,
   ada_evaluate_subexp
 };
index 601c7522a3bad68ef6f4412fdb5b9b3d6585557f..cea37da5586db6ff19e74b98b558e553b1d247f7 100644 (file)
@@ -2266,7 +2266,7 @@ gen_expr (struct expression *exp, union exp_element **pc,
 
     default:
       error (_("Unsupported operator %s (%d) in expression."),
-            op_name (exp, op), op);
+            op_name (op), op);
     }
 }
 
index 624aea52f774284a1b23f44eb92d562ab65d2cac..2a17e007fd0db71d69e8e8d2e8854aa92a5ba357 100644 (file)
@@ -846,7 +846,6 @@ const struct exp_descriptor exp_descriptor_c =
   print_subexp_standard,
   operator_length_standard,
   operator_check_standard,
-  op_name_standard,
   dump_subexp_body_standard,
   evaluate_subexp_c
 };
index 29e6237ab4d8f8780c79a3175fff1a3bd9bd8096..f1cf62e1c9a23117d1a9773f0ec4f12e8786fd34 100644 (file)
@@ -685,26 +685,11 @@ op_string (enum exp_opcode op)
 
 static int dump_subexp_body (struct expression *exp, struct ui_file *, int);
 
-/* Name for OPCODE, when it appears in expression EXP.  */
-
-const char *
-op_name (struct expression *exp, enum exp_opcode opcode)
-{
-  if (opcode >= OP_UNUSED_LAST)
-    {
-      char *cell = get_print_cell ();
-      xsnprintf (cell, PRINT_CELL_SIZE, "unknown opcode: %u",
-                unsigned (opcode));
-      return cell;
-    }
-  return exp->language_defn->expression_ops ()->op_name (opcode);
-}
-
 /* Default name for the standard operator OPCODE (i.e., one defined in
    the definition of enum exp_opcode).  */
 
 const char *
-op_name_standard (enum exp_opcode opcode)
+op_name (enum exp_opcode opcode)
 {
   switch (opcode)
     {
@@ -719,6 +704,8 @@ op_name_standard (enum exp_opcode opcode)
     case name:         \
       return #name ;
 #include "std-operator.def"
+#include "ada-operator.def"
+#include "fortran-operator.def"
 #undef OP
     }
 }
@@ -747,7 +734,7 @@ dump_raw_expression (struct expression *exp, struct ui_file *stream,
     {
       fprintf_filtered (stream, "\t%5d  ", elt);
 
-      const char *opcode_name = op_name (exp, exp->elts[elt].opcode);
+      const char *opcode_name = op_name (exp->elts[elt].opcode);
       fprintf_filtered (stream, "%20s  ", opcode_name);
 
       print_longest (stream, 'd', 0, exp->elts[elt].longconst);
@@ -782,7 +769,7 @@ dump_subexp (struct expression *exp, struct ui_file *stream, int elt)
     fprintf_filtered (stream, " ");
   indent += 2;
 
-  fprintf_filtered (stream, "%-20s  ", op_name (exp, exp->elts[elt].opcode));
+  fprintf_filtered (stream, "%-20s  ", op_name (exp->elts[elt].opcode));
 
   elt = dump_subexp_body (exp, stream, elt);
 
index 8de712310ecfe72f9f08fdff3c4300f366d6e31b..a8bfac17d8b32d75210e0b1e206a12cfc4dafc41 100644 (file)
@@ -171,7 +171,7 @@ extern struct value *evaluate_subexp_do_call (expression *exp,
 
 extern void print_expression (struct expression *, struct ui_file *);
 
-extern const char *op_name (struct expression *exp, enum exp_opcode opcode);
+extern const char *op_name (enum exp_opcode opcode);
 
 extern const char *op_string (enum exp_opcode);
 
index 4171c96c8a9fa392d10b1d3a3bc36f30700e21ca..6771758bacb2765a53a52a4322b723a7a31eedaf 100644 (file)
@@ -1072,24 +1072,6 @@ print_subexp_f (struct expression *exp, int *pos,
     }
 }
 
-/* Special expression names for Fortran.  */
-
-static const char *
-op_name_f (enum exp_opcode opcode)
-{
-  switch (opcode)
-    {
-    default:
-      return op_name_standard (opcode);
-
-#define OP(name)       \
-    case name:         \
-      return #name ;
-#include "fortran-operator.def"
-#undef OP
-    }
-}
-
 /* Special expression dumping for Fortran.  */
 
 static int
@@ -1159,7 +1141,6 @@ const struct exp_descriptor f_language::exp_descriptor_tab =
   print_subexp_f,
   operator_length_f,
   operator_check_f,
-  op_name_f,
   dump_subexp_body_f,
   evaluate_subexp_f
 };
index 1155469e0a51729ecba25e03825752bd98f1ba67..2576dcafc53de85c142ca0452658b9009efc85a3 100644 (file)
@@ -167,7 +167,6 @@ const struct exp_descriptor m2_language::exp_descriptor_modula2 =
   print_subexp_standard,
   operator_length_standard,
   operator_check_standard,
-  op_name_standard,
   dump_subexp_body_standard,
   evaluate_subexp_modula2
 };
index 830a6acaaabc317043ca02fe8b1fed3ec516f114..ca3a82b1088c8f2c9be191ceecd69bac75498ee8 100644 (file)
@@ -948,7 +948,6 @@ const struct exp_descriptor exp_descriptor_opencl =
   print_subexp_standard,
   operator_length_standard,
   operator_check_standard,
-  op_name_standard,
   dump_subexp_body_standard,
   evaluate_subexp_opencl
 };
index 8b9dfba0fb713cc3ff21981145f323fc8fa60cf8..c34b6085cd09eb9553a5b3855b8237686262a9d5 100644 (file)
@@ -59,7 +59,6 @@ const struct exp_descriptor exp_descriptor_standard =
     print_subexp_standard,
     operator_length_standard,
     operator_check_standard,
-    op_name_standard,
     dump_subexp_body_standard,
     evaluate_subexp_standard
   };
index bc6fc2f9ba37e891bfedcc4fe585bf18eb5cdd89..17216057b18ce6e9388f7a95cf5570535ecf724b 100644 (file)
@@ -355,8 +355,6 @@ extern int operator_check_standard (struct expression *exp, int pos,
                                      (struct objfile *objfile, void *data),
                                    void *data);
 
-extern const char *op_name_standard (enum exp_opcode);
-
 extern bool parse_float (const char *p, int len,
                         const struct type *type, gdb_byte *data);
 \f
@@ -417,12 +415,6 @@ struct exp_descriptor
                                                void *data),
                           void *data);
 
-    /* Name of this operator for dumping purposes.
-       The returned value should never be NULL, even if EXP_OPCODE is
-       an unknown opcode (a string containing an image of the numeric
-       value of the opcode can be returned, for instance).  */
-    const char *(*op_name) (enum exp_opcode);
-
     /* Dump the rest of this (prefix) expression after the operator
        itself has been printed.  See dump_subexp_body_standard in
        (expprint.c).  */
index fb2f2d5e8e43bb1bae17c1594e09e8ea523d7931..b89fd30491ac534190990bec4a8ae7aecdfba24f 100644 (file)
@@ -1680,22 +1680,6 @@ rust_operator_length (const struct expression *exp, int pc, int *oplenp,
   *argsp = args;
 }
 
-/* op_name implementation for Rust.  */
-
-static const char *
-rust_op_name (enum exp_opcode opcode)
-{
-  switch (opcode)
-    {
-    case OP_AGGREGATE:
-      return "OP_AGGREGATE";
-    case OP_OTHERS:
-      return "OP_OTHERS";
-    default:
-      return op_name_standard (opcode);
-    }
-}
-
 /* dump_subexp_body implementation for Rust.  */
 
 static int
@@ -1869,7 +1853,6 @@ static const struct exp_descriptor exp_descriptor_rust =
   rust_print_subexp,
   rust_operator_length,
   rust_operator_check,
-  rust_op_name,
   rust_dump_subexp_body,
   rust_evaluate_subexp
 };