aboutsummaryrefslogtreecommitdiff
path: root/gdb/expop.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:29 -0700
commita00b7254fb614af557de7ae7cc0eb39a0ce0e408 (patch)
tree8a3d68f79a485f7c2d45ab3b0f3c1074ea793d34 /gdb/expop.h
parent1c02eb30358a1d31918830b800cf1ff7c817439a (diff)
downloadgdb-a00b7254fb614af557de7ae7cc0eb39a0ce0e408.zip
gdb-a00b7254fb614af557de7ae7cc0eb39a0ce0e408.tar.gz
gdb-a00b7254fb614af557de7ae7cc0eb39a0ce0e408.tar.bz2
Implement function call operations
This implement function call operations. The current function call code relies on some very lengthy code (evaluate_funcall is 398 lines...) to distinguish between the different opcodes that might appear in the callee position. Rather than try to replicate this, and have a function that tried to dissect many different kinds of operation subclass, this patch instead puts the work into the callee. A new operation::evaluate_funcall method is added, and then this is overridden in the classes that require special treatment. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expression.h (class operation) <evaluate_funcall>: New methods. * expop.h (class scope_operation) <evaluate_funcall>: New method. (class var_value_operation) <evaluate_funcall>: New method. (class structop_base_operation) <evaluate_funcall>: New method. (class var_msym_value_operation) <evaluate_funcall>: New method. (class structop_member_base): New class. (class structop_member_operation): Derive from structop_member_base. (class structop_mptr_operation): Derive from structop_member_base. (class funcall_operation): New class. * eval.c (operation::evaluate_funcall) (var_value_operation::evaluate_funcall) (scope_operation::evaluate_funcall) (structop_member_base::evaluate_funcall) (structop_base_operation::evaluate_funcall): New methods.
Diffstat (limited to 'gdb/expop.h')
-rw-r--r--gdb/expop.h64
1 files changed, 61 insertions, 3 deletions
diff --git a/gdb/expop.h b/gdb/expop.h
index 9b5c4ea..8ac7947 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -597,6 +597,11 @@ public:
value *evaluate_for_address (struct expression *exp,
enum noside noside) override;
+ value *evaluate_funcall (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ const std::vector<operation_up> &args) override;
+
enum exp_opcode opcode () const override
{ return OP_SCOPE; }
@@ -634,6 +639,11 @@ public:
value *evaluate_for_address (struct expression *exp, enum noside noside)
override;
+ value *evaluate_funcall (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ const std::vector<operation_up> &args) override;
+
enum exp_opcode opcode () const override
{ return OP_VAR_VALUE; }
@@ -702,6 +712,15 @@ public:
struct expression *exp,
enum noside noside) override;
+ value *evaluate_funcall (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ const std::vector<operation_up> &args) override
+ {
+ const char *name = std::get<0> (m_storage)->print_name ();
+ return operation::evaluate_funcall (expect_type, exp, noside, name, args);
+ }
+
enum exp_opcode opcode () const override
{ return OP_VAR_MSYM_VALUE; }
@@ -974,6 +993,11 @@ public:
EVAL_AVOID_SIDE_EFFECTS);
}
+ value *evaluate_funcall (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ const std::vector<operation_up> &args) override;
+
protected:
using tuple_holding_operation::tuple_holding_operation;
@@ -1047,13 +1071,26 @@ protected:
}
};
-class structop_member_operation
+class structop_member_base
: public tuple_holding_operation<operation_up, operation_up>
{
public:
using tuple_holding_operation::tuple_holding_operation;
+ value *evaluate_funcall (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside,
+ const std::vector<operation_up> &args) override;
+};
+
+class structop_member_operation
+ : public structop_member_base
+{
+public:
+
+ using structop_member_base::structop_member_base;
+
value *evaluate (struct type *expect_type,
struct expression *exp,
enum noside noside) override
@@ -1070,11 +1107,11 @@ public:
};
class structop_mptr_operation
- : public tuple_holding_operation<operation_up, operation_up>
+ : public structop_member_base
{
public:
- using tuple_holding_operation::tuple_holding_operation;
+ using structop_member_base::structop_member_base;
value *evaluate (struct type *expect_type,
struct expression *exp,
@@ -2071,6 +2108,27 @@ private:
enum noside noside, int nargs);
};
+/* A function call. This holds the callee operation and the
+ arguments. */
+class funcall_operation
+ : public tuple_holding_operation<operation_up, 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
+ {
+ return std::get<0> (m_storage)->evaluate_funcall (expect_type, exp, noside,
+ std::get<1> (m_storage));
+ }
+
+ enum exp_opcode opcode () const override
+ { return OP_FUNCALL; }
+};
+
} /* namespace expr */
#endif /* EXPOP_H */