Remove per-language op_name functions

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.
This commit is contained in:
Tom Tromey
2020-11-30 01:37:10 -07:00
parent 1cd49c43f3
commit 88b91969e1
12 changed files with 27 additions and 92 deletions

View 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.

View 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
};

View 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);
}
}

View 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
};

View 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);

View 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);

View 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
};

View 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
};

View 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
};

View 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
};

View 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);
@ -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). */

View 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
};