[140/203] Introduce class adl_func_operation

Message ID 20210101214723.1784144-141-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 adl_func_operation, which implements
argument-dependent lookup function calls.

Other function calls will be handled in a different way.  However,
because ADL calls were created in a single spot in the C++ parser, and
because they had different semantics from the other cases, it was
convenient to treat them specially.

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

	* expop.h (class adl_func_operation): New.
	* eval.c (adl_func_operation::evaluate): New method.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 23 +++++++++++++++++++++++
 gdb/expop.h   | 19 +++++++++++++++++++
 3 files changed, 47 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 495cd4b26a3..62b3f219ca4 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2524,6 +2524,29 @@  logical_or_operation::evaluate (struct type *expect_type,
     }
 }
 
+value *
+adl_func_operation::evaluate (struct type *expect_type,
+			      struct expression *exp,
+			      enum noside noside)
+{
+  std::vector<operation_up> &arg_ops = std::get<2> (m_storage);
+  std::vector<value *> args (arg_ops.size ());
+  for (int i = 0; i < arg_ops.size (); ++i)
+    args[i] = arg_ops[i]->evaluate_with_coercion (exp, noside);
+
+  struct symbol *symp;
+  find_overload_match (args, std::get<0> (m_storage).c_str (),
+		       NON_METHOD,
+		       nullptr, nullptr,
+		       nullptr, &symp, nullptr, 0, noside);
+  if (SYMBOL_TYPE (symp)->code () == TYPE_CODE_ERROR)
+    error_unknown_type (symp->print_name ());
+  value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
+  return evaluate_subexp_do_call (exp, noside, callee, args,
+				  nullptr, expect_type);
+
+}
+
 }
 
 struct value *
diff --git a/gdb/expop.h b/gdb/expop.h
index f858f591baf..a8aa0f43acc 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -2027,6 +2027,25 @@  class logical_or_operation
     override;
 };
 
+/* This class implements ADL (aka Koenig) function calls for C++.  It
+   holds the name of the function to call, the block in which the
+   lookup should be done, and a vector of arguments.  */
+class adl_func_operation
+  : public tuple_holding_operation<std::string, const block *,
+				   std::vector<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 opcode () const override
+  { return OP_ADL_FUNC; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */