[v3,035/206] Split out eval_op_type

Message ID 20210220201609.838264-36-tom@tromey.com
State New
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Feb. 20, 2021, 8:13 p.m.
This splits OP_TYPE into a new function for future use.

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

	* eval.c (eval_op_type): New function.
	(evaluate_subexp_standard): Use it.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    | 21 +++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index 7fdc4b42dc7..46225f4ff1e 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2029,6 +2029,20 @@  eval_op_postdec (struct type *expect_type, struct expression *exp,
     }
 }
 
+/* A helper function for OP_TYPE.  */
+
+static struct value *
+eval_op_type (struct type *expect_type, struct expression *exp,
+	      enum noside noside, struct type *type)
+{
+  if (noside == EVAL_SKIP)
+    return eval_skip_value (exp);
+  else if (noside == EVAL_AVOID_SIDE_EFFECTS)
+    return allocate_value (type);
+  else
+    error (_("Attempt to use a type name as an expression"));
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
 			  struct expression *exp, int *pos,
@@ -2984,12 +2998,7 @@  evaluate_subexp_standard (struct type *expect_type,
       /* The value is not supposed to be used.  This is here to make it
 	 easier to accommodate expressions that contain types.  */
       (*pos) += 2;
-      if (noside == EVAL_SKIP)
-	return eval_skip_value (exp);
-      else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return allocate_value (exp->elts[pc + 1].type);
-      else
-	error (_("Attempt to use a type name as an expression"));
+      return eval_op_type (expect_type, exp, noside, exp->elts[pc + 1].type);
 
     case OP_TYPEOF:
     case OP_DECLTYPE: