public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/3] Remove evaluate_type
Date: Fri, 28 Apr 2023 10:02:53 -0600	[thread overview]
Message-ID: <20230428-minor-expr-cleanuups-v1-3-0a634e8d5c25@adacore.com> (raw)
In-Reply-To: <20230428-minor-expr-cleanuups-v1-0-0a634e8d5c25@adacore.com>

Like evaluate_expression, evaluate_type is also just a simple wrapper.
Removing it makes the code a little nicer.
---
 gdb/dtrace-probe.c | 2 +-
 gdb/eval.c         | 9 ---------
 gdb/expression.h   | 5 +++++
 gdb/gnu-v3-abi.c   | 2 +-
 gdb/mi/mi-main.c   | 2 +-
 gdb/typeprint.c    | 4 ++--
 gdb/value.h        | 2 --
 gdb/varobj.c       | 2 +-
 8 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index dad15df5b99..a742c3c25e3 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -494,7 +494,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	    }
 
 	  if (expr != NULL && expr->first_opcode () == OP_TYPE)
-	    type = evaluate_type (expr.get ())->type ();
+	    type = expr->evaluate_type ()->type ();
 
 	  args.emplace_back (type, std::move (type_str), std::move (expr));
 	}
diff --git a/gdb/eval.c b/gdb/eval.c
index a8d5c78e09e..a75bddcadfd 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -116,15 +116,6 @@ expression::evaluate (struct type *expect_type, enum noside noside)
   return retval;
 }
 
-/* Evaluate an expression, avoiding all memory references
-   and getting a value whose type alone is correct.  */
-
-struct value *
-evaluate_type (struct expression *exp)
-{
-  return exp->evaluate (nullptr, EVAL_AVOID_SIDE_EFFECTS);
-}
-
 /* Find the current value of a watchpoint on EXP.  Return the value in
    *VALP and *RESULTP and the chain of intermediate and final values
    in *VAL_CHAIN.  RESULTP and VAL_CHAIN may be NULL if the caller does
diff --git a/gdb/expression.h b/gdb/expression.h
index 5bfb051a393..e6e4bec2e80 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -225,6 +225,11 @@ struct expression
   struct value *evaluate (struct type *expect_type = nullptr,
 			  enum noside noside = EVAL_NORMAL);
 
+  /* Evaluate an expression, avoiding all memory references
+     and getting a value whose type alone is correct.  */
+  struct value *evaluate_type ()
+  { return evaluate (nullptr, EVAL_AVOID_SIDE_EFFECTS); }
+
   /* Language it was entered in.  */
   const struct language_defn *language_defn;
   /* Architecture it was parsed in.  */
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 12bc5b09a93..687bf7e89bd 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1211,7 +1211,7 @@ gnuv3_get_type_from_type_info (struct value *type_info_ptr)
      internal form to reconstruct the type somehow.  */
   std::string type_name = gnuv3_get_typename_from_type_info (type_info_ptr);
   expression_up expr (parse_expression (type_name.c_str ()));
-  struct value *type_val = evaluate_type (expr.get ());
+  struct value *type_val = expr->evaluate_type ();
   return type_val->type ();
 }
 
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 683d36d93d5..19cdf47a283 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2466,7 +2466,7 @@ print_variable_or_computed (const char *expression, enum print_values values)
   expression_up expr = parse_expression (expression);
 
   if (values == PRINT_SIMPLE_VALUES)
-    val = evaluate_type (expr.get ());
+    val = expr->evaluate_type ();
   else
     val = expr->evaluate ();
 
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 06ecd2c4776..6dbd44eb4cd 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -511,7 +511,7 @@ whatis_exp (const char *exp, int show)
 	 "whatis" prints the type of the expression without stripping
 	 any typedef level.  "ptype" always strips all levels of
 	 typedefs.  */
-      val = evaluate_type (expr.get ());
+      val = expr->evaluate_type ();
       type = val->type ();
 
       if (show == -1 && expr->first_opcode () == OP_TYPE)
@@ -708,7 +708,7 @@ maintenance_print_type (const char *type_name, int from_tty)
   if (type_name != NULL)
     {
       expression_up expr = parse_expression (type_name);
-      struct value *val = evaluate_type (expr.get ());
+      struct value *val = expr->evaluate_type ();
       struct type *type = val->type ();
 
       if (type != nullptr)
diff --git a/gdb/value.h b/gdb/value.h
index f6092aba5a4..d042d816409 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1299,8 +1299,6 @@ extern int using_struct_return (struct gdbarch *gdbarch,
 				struct value *function,
 				struct type *value_type);
 
-extern struct value *evaluate_type (struct expression *exp);
-
 extern value *evaluate_var_value (enum noside noside, const block *blk,
 				  symbol *var);
 
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 75b4d44b109..dd39784a21c 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -375,7 +375,7 @@ varobj_create (const char *objname,
 	{
 	  /* Error getting the value.  Try to at least get the
 	     right type.  */
-	  struct value *type_only_value = evaluate_type (var->root->exp.get ());
+	  struct value *type_only_value = var->root->exp->evaluate_type ();
 
 	  var->type = type_only_value->type ();
 	}

-- 
2.39.1


  parent reply	other threads:[~2023-04-28 16:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 16:02 [PATCH 0/3] Minor expression cleanups Tom Tromey
2023-04-28 16:02 ` [PATCH 1/3] Remove op_name Tom Tromey
2023-04-28 16:02 ` [PATCH 2/3] Remove evaluate_expression Tom Tromey
2023-04-28 16:02 ` Tom Tromey [this message]
2023-04-28 16:14 ` [PATCH 0/3] Minor expression cleanups Keith Seitz
2023-05-01 17:04   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230428-minor-expr-cleanuups-v1-3-0a634e8d5c25@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).