From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Introduce typeof_operation X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4efc574cb9e721c1e29425146d6f51424a730729;p=binutils-gdb.git Introduce typeof_operation This adds class typeof_operation, which implements OP_TYPEOF. gdb/ChangeLog 2021-03-08 Tom Tromey * expop.h (class typeof_operation): New. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6496f982e5a..89d3e6f9a74 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2021-03-08 Tom Tromey + + * expop.h (class typeof_operation): New. + 2021-03-08 Tom Tromey * expop.h (class type_operation): New. diff --git a/gdb/expop.h b/gdb/expop.h index 8b7bfbe3af6..da7435918e2 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -1445,6 +1445,31 @@ public: { return true; } }; +/* Implement the "typeof" operation. */ +class typeof_operation + : public maybe_constant_operation +{ +public: + + using maybe_constant_operation::maybe_constant_operation; + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + if (noside == EVAL_SKIP) + return eval_skip_value (exp); + else if (noside == EVAL_AVOID_SIDE_EFFECTS) + return std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + else + error (_("Attempt to use a type as an expression")); + } + + enum exp_opcode opcode () const override + { return OP_TYPEOF; } +}; + } /* namespace expr */ #endif /* EXPOP_H */