[PATCH 076/203] Introduce float_const_operation

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

This adds class float_const_operation, an operation holding a
floating-point constant. Unlike most other new operations, this one
requires a custom 'dump' method.

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

* expprint.c (float_const_operation::dump): New method.
* expop.h (float_data): New typedef.
(class float_const_operation): New.
---
gdb/ChangeLog | 6 ++++++
gdb/expop.h | 42 ++++++++++++++++++++++++++++++++++++++++++
gdb/expprint.c | 8 ++++++++
3 files changed, 56 insertions(+)

diff --git a/gdb/expop.h b/gdb/expop.h
index 2e7191cf59c..6af6504332e 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -371,6 +371,48 @@ class maybe_constant_operation
}
};

+/* A floating-point constant. The constant is encoded in the target
+ format. */
+
+typedef std::array<gdb_byte, 16> float_data;
+
+/* An operation that holds a floating-point constant of a given
+ type.
+
+ This does not need the facilities provided by
+ tuple_holding_operation, so it does not use it. */
+class float_const_operation
+ : public operation
+{
+public:
+
+ float_const_operation (struct type *type, float_data data)
+ : m_type (type),
+ m_data (data)
+ {
+ }
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override
+ {
+ return value_from_contents (m_type, m_data.data ());
+ }
+
+ enum exp_opcode opcode () const override
+ { return OP_FLOAT; }
+
+ bool constant_p () const override
+ { return true; }
+
+ void dump (struct ui_file *stream, int depth) const override;
+
+private:
+
+ struct type *m_type;
+ float_data m_data;
+};
+
} /* namespace expr */

#endif /* EXPOP_H */
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 3c84a65bfda..0f4c8602f1c 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -1276,4 +1276,12 @@ dump_for_expression (struct ui_file *stream, int depth,
fprintf_filtered (stream, "\n");
}

+void
+float_const_operation::dump (struct ui_file *stream, int depth) const
+{
+ fprintf_filtered (stream, _("%*sFloat: "), depth, "");
+ print_floating (m_data.data (), m_type, stream);
+ fprintf_filtered (stream, "\n");
+}
+
} /* namespace expr */
--
2.26.2