aboutsummaryrefslogtreecommitdiff
path: root/gdb/eval.c
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:28 -0700
commit5019124b1ddc3839bd8ccba08819b11c0151e8a9 (patch)
treee83820e9ee3c77bdff1892dfbc7b2664c26d0df6 /gdb/eval.c
parent2bc9b40ce16a109a22320589d2cfb9fced5fb769 (diff)
downloadgdb-5019124b1ddc3839bd8ccba08819b11c0151e8a9.zip
gdb-5019124b1ddc3839bd8ccba08819b11c0151e8a9.tar.gz
gdb-5019124b1ddc3839bd8ccba08819b11c0151e8a9.tar.bz2
Implement the "&&" and "||" operators
This implements the "&&" and "||" operators. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (class logical_and_operation) (class logical_or_operation): New. * eval.c (logical_and_operation::evaluate) (logical_or_operation::evaluate): New methods. * ax-gdb.c (logical_and_operation::do_generate_ax) (logical_or_operation::do_generate_ax): New methods.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r--gdb/eval.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 655e4ef..4438413 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2486,6 +2486,69 @@ multi_subscript_operation::evaluate (struct type *expect_type,
gdb::make_array_view (argvec, values.size ()));
}
+value *
+logical_and_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+
+ value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp,
+ EVAL_AVOID_SIDE_EFFECTS);
+
+ if (binop_user_defined_p (BINOP_LOGICAL_AND, arg1, arg2))
+ {
+ arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ return value_x_binop (arg1, arg2, BINOP_LOGICAL_AND, OP_NULL, noside);
+ }
+ else
+ {
+ int tem = value_logical_not (arg1);
+ if (!tem)
+ {
+ arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ tem = value_logical_not (arg2);
+ }
+ struct type *type = language_bool_type (exp->language_defn,
+ exp->gdbarch);
+ return value_from_longest (type, !tem);
+ }
+}
+
+value *
+logical_or_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+
+ value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp,
+ EVAL_AVOID_SIDE_EFFECTS);
+
+ if (binop_user_defined_p (BINOP_LOGICAL_OR, arg1, arg2))
+ {
+ arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ return value_x_binop (arg1, arg2, BINOP_LOGICAL_OR, OP_NULL, noside);
+ }
+ else
+ {
+ int tem = value_logical_not (arg1);
+ if (tem)
+ {
+ arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+ tem = value_logical_not (arg2);
+ }
+
+ struct type *type = language_bool_type (exp->language_defn,
+ exp->gdbarch);
+ return value_from_longest (type, !tem);
+ }
+}
+
}
struct value *