Introduce class adl_func_operation
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:29 +0000 (07:28 -0700)
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-03-08  Tom Tromey  <tom@tromey.com>

* expop.h (class adl_func_operation): New.
* eval.c (adl_func_operation::evaluate): New method.

gdb/ChangeLog
gdb/eval.c
gdb/expop.h

index 1969ec57004f4759bc90845df6aaab0b8ca467d6..627969aea63a84434636712285fbdf83653541e6 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class adl_func_operation): New.
+       * eval.c (adl_func_operation::evaluate): New method.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * ada-lang.c (ada_unop_in_range): No longer static.
index 44384130f6c12eb0e6f28706d47e45389e1140e1..972e63035b383e8a50f6efa958d410d9341d56cf 100644 (file)
@@ -2549,6 +2549,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 *
index 7850c457adbae987bf9b70bc09f59ea2358ad76d..0785df939e4798c1695b06089afabc76aaf27384 100644 (file)
@@ -2030,6 +2030,25 @@ protected:
     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 */
This page took 0.028756 seconds and 4 git commands to generate.