[v3,151/206] Introduce opencl_structop_operation

Message ID 20210220201609.838264-152-tom@tromey.com
State New
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Feb. 20, 2021, 8:15 p.m.
This adds class opencl_structop_operation, which implements
STRUCTOP_STRUCT for OpenCL.

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

	* opencl-lang.c (opencl_structop_operation::evaluate): New
	method.
	* c-exp.h (class opencl_structop_operation): New.
---
 gdb/ChangeLog     |  6 ++++++
 gdb/c-exp.h       | 16 ++++++++++++++++
 gdb/opencl-lang.c | 28 ++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/c-exp.h b/gdb/c-exp.h
index 1afe2d2fbee..58a16d5c0c8 100644
--- a/gdb/c-exp.h
+++ b/gdb/c-exp.h
@@ -170,6 +170,22 @@  using opencl_leq_operation = opencl_binop_operation<BINOP_LEQ,
 using opencl_not_operation = unop_operation<UNOP_LOGICAL_NOT,
 					    opencl_logical_not>;
 
+/* STRUCTOP_STRUCT implementation for OpenCL.  */
+class opencl_structop_operation
+  : public structop_base_operation
+{
+public:
+
+  using structop_base_operation::structop_base_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override;
+
+  enum exp_opcode opcode () const override
+  { return STRUCTOP_STRUCT; }
+};
+
 }/* namespace expr */
 
 #endif /* C_EXP_H */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 8ddcd76c589..317163966cd 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -958,6 +958,34 @@  Cannot perform conditional operation on vectors with different sizes"));
   return evaluate_subexp_c (expect_type, exp, pos, noside);
 }
 
+namespace expr
+{
+
+value *
+opencl_structop_operation::evaluate (struct type *expect_type,
+				     struct expression *exp,
+				     enum noside noside)
+{
+  value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+  struct type *type1 = check_typedef (value_type (arg1));
+
+  if (type1->code () == TYPE_CODE_ARRAY && type1->is_vector ())
+    return opencl_component_ref (exp, arg1, std::get<1> (m_storage).c_str (),
+				 noside);
+  else
+    {
+      struct value *v = value_struct_elt (&arg1, NULL,
+					  std::get<1> (m_storage).c_str (),
+					  NULL, "structure");
+
+      if (noside == EVAL_AVOID_SIDE_EFFECTS)
+	v = value_zero (value_type (v), VALUE_LVAL (v));
+      return v;
+    }
+}
+
+} /* namespace expr */
+
 const struct exp_descriptor exp_descriptor_opencl =
 {
   print_subexp_standard,