Introduce and use operation::type_p

There's currently code in gdb that checks if an expression evaluates
to a type.  In some spots this is done by comparing the opcode against
OP_TYPE, but other spots more correctly also compare with OP_TYPEOF
and OP_DECLTYPE.

This patch cleans up this area, replacing opcode-checking with a new
method on 'operation'.

Generally, checking the opcode should be considered deprecated,
although it's unfortunately difficult to get rid of opcodes entirely.

I also took advantage of this change to turn eval_op_type into a
method, removing a bit of indirection.

Reviewed-by: Keith Seitz <keiths@redhat.com>
This commit is contained in:
Tom Tromey
2024-09-18 10:25:13 -06:00
parent c5c8598743
commit 1ce2312391
7 changed files with 32 additions and 20 deletions

View File

@@ -147,6 +147,11 @@ public:
virtual bool uses_objfile (struct objfile *objfile) const
{ return false; }
/* Some expression nodes represent a type, not a value. This method
should be overridden to return 'true' in these situations. */
virtual bool type_p () const
{ return false; }
/* Generate agent expression bytecodes for this operation. */
void generate_ax (struct expression *exp, struct agent_expr *ax,
struct axs_value *value,
@@ -215,6 +220,11 @@ struct expression
op->dump (stream, 0);
}
/* Call the type_p method on the outermost sub-expression of this
expression, and return the result. */
bool type_p () const
{ return op->type_p (); }
/* Return true if this expression uses OBJFILE (and will become
dangling when OBJFILE is unloaded), otherwise return false.
OBJFILE must not be a separate debug info file. */