[030/203] Split out eval_op_alignof

Message ID 20210101214723.1784144-31-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:44 p.m.
This splits UNOP_ALIGNOF into a new function for future use.

gdb/ChangeLog
2021-01-01  Tom Tromey  <tom@tromey.com>

	* eval.c (eval_op_alignof): New function.
	(evaluate_subexp_standard): Use it.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 28 ++++++++++++++++++----------
 2 files changed, 23 insertions(+), 10 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 3626c8c9be2..5d29274b383 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1853,6 +1853,22 @@  eval_op_ind (struct type *expect_type, struct expression *exp,
   return value_ind (arg1);
 }
 
+/* A helper function for UNOP_ALIGNOF.  */
+
+static struct value *
+eval_op_alignof (struct type *expect_type, struct expression *exp,
+		 enum noside noside,
+		 struct value *arg1)
+{
+  struct type *type = value_type (arg1);
+  /* FIXME: This should be size_t.  */
+  struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
+  ULONGEST align = type_align (type);
+  if (align == 0)
+    error (_("could not determine alignment of type"));
+  return value_from_longest (size_type, align);
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
 			  struct expression *exp, int *pos,
@@ -2744,16 +2760,8 @@  evaluate_subexp_standard (struct type *expect_type,
       return evaluate_subexp_for_sizeof (exp, pos, noside);
 
     case UNOP_ALIGNOF:
-      {
-	type = value_type (
-	  evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS));
-	/* FIXME: This should be size_t.  */
-	struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
-	ULONGEST align = type_align (type);
-	if (align == 0)
-	  error (_("could not determine alignment of type"));
-	return value_from_longest (size_type, align);
-      }
+      arg1 = evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
+      return eval_op_alignof (expect_type, exp, noside, arg1);
 
     case UNOP_CAST:
       (*pos) += 2;