aboutsummaryrefslogtreecommitdiff
path: root/gdb/expop.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:22 -0700
commit0af8829eb1aea4fa72f1a0a2c7c749c411c8ed41 (patch)
tree2876e6a11f15bbd8343769a414930d65632ede21 /gdb/expop.h
parent4efc574cb9e721c1e29425146d6f51424a730729 (diff)
downloadgdb-0af8829eb1aea4fa72f1a0a2c7c749c411c8ed41.zip
gdb-0af8829eb1aea4fa72f1a0a2c7c749c411c8ed41.tar.gz
gdb-0af8829eb1aea4fa72f1a0a2c7c749c411c8ed41.tar.bz2
Introduce decltype_operation
This adds class decltype_operation, which implements OP_DECLTYPE. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (class decltype_operation): New.
Diffstat (limited to 'gdb/expop.h')
-rw-r--r--gdb/expop.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/gdb/expop.h b/gdb/expop.h
index da74359..1831378 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -1470,6 +1470,53 @@ public:
{ return OP_TYPEOF; }
};
+/* Implement 'decltype'. */
+class decltype_operation
+ : public maybe_constant_operation<operation_up>
+{
+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)
+ {
+ value *result
+ = std::get<0> (m_storage)->evaluate (nullptr, exp,
+ EVAL_AVOID_SIDE_EFFECTS);
+ enum exp_opcode sub_op = std::get<0> (m_storage)->opcode ();
+ if (sub_op == BINOP_SUBSCRIPT
+ || sub_op == STRUCTOP_MEMBER
+ || sub_op == STRUCTOP_MPTR
+ || sub_op == UNOP_IND
+ || sub_op == STRUCTOP_STRUCT
+ || sub_op == STRUCTOP_PTR
+ || sub_op == OP_SCOPE)
+ {
+ struct type *type = value_type (result);
+
+ if (!TYPE_IS_REFERENCE (type))
+ {
+ type = lookup_lvalue_reference_type (type);
+ result = allocate_value (type);
+ }
+ }
+
+ return result;
+ }
+ else
+ error (_("Attempt to use a type as an expression"));
+ }
+
+ enum exp_opcode opcode () const override
+ { return OP_DECLTYPE; }
+};
+
} /* namespace expr */
#endif /* EXPOP_H */