[126/203] Introduce ada_string_operation

Message ID 20210101214723.1784144-127-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:46 p.m.
This adds class ada_string_operation, which implements string
constants for Ada.

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

	* ada-lang.c (ada_string_operation::evaluate): New method.
	* ada-exp.h (class ada_string_operation): New.
---
 gdb/ChangeLog  |  5 +++++
 gdb/ada-exp.h  | 13 +++++++++++++
 gdb/ada-lang.c | 13 +++++++++++++
 3 files changed, 31 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h
index 3f780dc9ff4..88ed0c53b46 100644
--- a/gdb/ada-exp.h
+++ b/gdb/ada-exp.h
@@ -42,6 +42,19 @@  class ada_wrapped_operation
   { return std::get<0> (m_storage)->opcode (); }
 };
 
+/* An Ada string constant.  */
+class ada_string_operation
+  : public string_operation
+{
+public:
+
+  using string_operation::string_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override;
+};
+
 } /* namespace expr */
 
 #endif /* ADA_EXP_H */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7855cd32eb3..d74c11f9a36 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10570,6 +10570,19 @@  ada_wrapped_operation::evaluate (struct type *expect_type,
   return result;
 }
 
+value *
+ada_string_operation::evaluate (struct type *expect_type,
+				struct expression *exp,
+				enum noside noside)
+{
+  value *result = string_operation::evaluate (expect_type, exp, noside);
+  /* The result type will have code OP_STRING, bashed there from 
+     OP_ARRAY.  Bash it back.  */
+  if (value_type (result)->code () == TYPE_CODE_STRING)
+    value_type (result)->set_code (TYPE_CODE_ARRAY);
+  return result;
+}
+
 }
 
 /* Implement the evaluate_exp routine in the exp_descriptor structure