[PATCH 110/203] Introduce typeid_operation

Tom Tromey
2021-01-01T21:48:45Z

This adds class typeid_operation, which implements OP_TYPEID.

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

* expop.h (class typeid_operation): New.
---
gdb/ChangeLog | 4 ++++
gdb/expop.h | 29 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)

diff --git a/gdb/expop.h b/gdb/expop.h
index ba107f10ba0..9f23b8afd7c 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1506,6 +1506,35 @@ class decltype_operation
{ return OP_DECLTYPE; }
};

+/* Implement 'typeid'. */
+class typeid_operation
+ : public tuple_holding_operation<operation_up>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
+ enum noside sub_noside
+ = ((sub_op == OP_TYPE || sub_op == OP_DECLTYPE || sub_op == OP_TYPEOF)
+ ? EVAL_AVOID_SIDE_EFFECTS
+ : noside);
+
+ value *result = std::get<0> (m_storage)->evaluate (nullptr, exp,
+ sub_noside);
+ if (noside != EVAL_NORMAL)
+ return allocate_value (cplus_typeid_type (exp->gdbarch));
+ return cplus_typeid (result);
+ }
+
+ enum exp_opcode opcode () const override
+ { return OP_TYPEID; }
+};
+
} /* namespace expr */

#endif /* EXPOP_H */
--
2.26.2