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:13 -0700
commite2803273a078950d0895de245cdc5375f362a8c5 (patch)
tree5831732b28dc39d8afa6d009089f501fe6b0c57c /gdb/eval.c
parente18c58f290609dcfe8d7df450bb88b1adf44337a (diff)
downloadgdb-e2803273a078950d0895de245cdc5375f362a8c5.zip
gdb-e2803273a078950d0895de245cdc5375f362a8c5.tar.gz
gdb-e2803273a078950d0895de245cdc5375f362a8c5.tar.bz2
Introduce class operation
This patch introduces class operation, the new base class for all expression operations. In the new approach, an operation is simply a class that presents a certain interface. Operations own their operands, and management is done via unique_ptr. The operation interface is largely ad hoc, based on the evolution of expression handling in GDB. Parts (for example, evaluate_with_coercion) are probably redundant; however I took this approach to try to avoid mixing different kinds of refactorings. In some specific situations, rather than add a generic method across the entire operation class hierarchy, I chose instead to use dynamic_cast and specialized methods on certain concrete subclasses. This will appear in some subsequent patches. One goal of this work is to avoid the kinds of easy-to-make errors that affected the old implementation. To this end, some helper subclasses are also added here. These helpers automate the implementation of the 'dump', 'uses_objfile', and 'constant_p' methods. Nearly every concrete operation that is subsequently added will use these facilities. (Note that the 'dump' implementation is only outlined here, the body appears in the next patch.) gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expression.h (expr::operation): New class. (expr::make_operation): New function. (expr::operation_up): New typedef. * expop.h: New file. * eval.c (operation::evaluate_for_cast) (operation::evaluate_for_address, operation::evaluate_for_sizeof): New methods. * ax-gdb.c (operation::generate_ax): New method.
Diffstat (limited to 'gdb/eval.c')
-rw-r--r--gdb/eval.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 8636bcf..8adbcef 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -40,6 +40,7 @@
#include "objfiles.h"
#include "typeprint.h"
#include <ctype.h>
+#include "expop.h"
/* Prototypes for local functions. */
@@ -3267,6 +3268,29 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
}
}
+namespace expr
+{
+
+value *
+operation::evaluate_for_cast (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ value *val = evaluate (expect_type, exp, noside);
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+ return value_cast (expect_type, val);
+}
+
+value *
+operation::evaluate_for_address (struct expression *exp, enum noside noside)
+{
+ value *val = evaluate (nullptr, exp, noside);
+ return evaluate_subexp_for_address_base (exp, noside, val);
+}
+
+}
+
/* Evaluate like `evaluate_subexp' except coercing arrays to pointers.
When used in contexts where arrays will be coerced anyway, this is
equivalent to `evaluate_subexp' but much faster because it avoids
@@ -3455,6 +3479,18 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
return evaluate_subexp_for_sizeof_base (exp, type);
}
+namespace expr
+{
+
+value *
+operation::evaluate_for_sizeof (struct expression *exp, enum noside noside)
+{
+ value *val = evaluate (nullptr, exp, EVAL_AVOID_SIDE_EFFECTS);
+ return evaluate_subexp_for_sizeof_base (exp, value_type (val));
+}
+
+}
+
/* Evaluate a subexpression of EXP, at index *POS, and return a value
for that subexpression cast to TO_TYPE. Advance *POS over the
subexpression. */