From e2803273a078950d0895de245cdc5375f362a8c5 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 8 Mar 2021 07:27:57 -0700 Subject: 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 * 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. --- gdb/ax-gdb.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gdb/ax-gdb.c') diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index e18e968..728b21d 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -2270,6 +2270,32 @@ gen_expr (struct expression *exp, union exp_element **pc, } } +namespace expr +{ + +void +operation::generate_ax (struct expression *exp, + struct agent_expr *ax, + struct axs_value *value, + struct type *cast_type) +{ + if (constant_p ()) + { + struct value *v = evaluate (nullptr, exp, EVAL_AVOID_SIDE_EFFECTS); + ax_const_l (ax, value_as_long (v)); + value->kind = axs_rvalue; + value->type = check_typedef (value_type (v)); + } + else + { + do_generate_ax (exp, ax, value, cast_type); + if (cast_type != nullptr) + gen_cast (ax, value, cast_type); + } +} + +} + /* This handles the middle-to-right-side of code generation for binary expressions, which is shared between regular binary operations and assign-modify (+= and friends) expressions. */ -- cgit v1.1