Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 1/4] gdb: make get_dyn_prop a method of struct type
Date: Thu, 30 Apr 2020 14:17:50 -0400	[thread overview]
Message-ID: <20200430181753.1093-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20200430181753.1093-1-simon.marchi@efficios.com>

Move get_dyn_prop, currently a free function, to be a method on struct
type.

gdb/ChangeLog:

        * gdbtypes.h (struct type) <get_dyn_prop>: New method.
	(get_dyn_prop): Remove.  Update all users to use
	type::get_dyn_prop.
	* gdbtypes.c (get_dyn_prop): Rename to...
	(type::get_dyn_prop): ... this.
---
 gdb/ada-lang.c      |  4 ++--
 gdb/ada-typeprint.c |  4 ++--
 gdb/gdbtypes.c      | 16 ++++++++--------
 gdb/gdbtypes.h      | 23 +++++++++++------------
 gdb/rust-lang.c     |  3 +--
 5 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index bfbc69084ec..6932a544ec6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2812,7 +2812,7 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
     = create_static_range_type (NULL, base_index_type, low, high);
   struct type *slice_type = create_array_type_with_stride
 			      (NULL, TYPE_TARGET_TYPE (type0), index_type,
-			       get_dyn_prop (DYN_PROP_BYTE_STRIDE, type0),
+			       type0->get_dyn_prop (DYN_PROP_BYTE_STRIDE),
 			       TYPE_FIELD_BITSIZE (type0, 0));
   int base_low =  ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type0));
   LONGEST base_low_pos, low_pos;
@@ -2842,7 +2842,7 @@ ada_value_slice (struct value *array, int low, int high)
     = create_static_range_type (NULL, TYPE_INDEX_TYPE (type), low, high);
   struct type *slice_type = create_array_type_with_stride
 			      (NULL, TYPE_TARGET_TYPE (type), index_type,
-			       get_dyn_prop (DYN_PROP_BYTE_STRIDE, type),
+			       type->get_dyn_prop (DYN_PROP_BYTE_STRIDE),
 			       TYPE_FIELD_BITSIZE (type, 0));
   LONGEST low_pos, high_pos;
 
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 83972fe125d..9071eeace13 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -776,13 +776,13 @@ print_record_field_types (struct type *type, struct type *outer_type,
 			  struct ui_file *stream, int show, int level,
 			  const struct type_print_options *flags)
 {
-  struct dynamic_prop *prop = get_dyn_prop (DYN_PROP_VARIANT_PARTS, type);
+  struct dynamic_prop *prop = type->get_dyn_prop (DYN_PROP_VARIANT_PARTS);
   if (prop != nullptr)
     {
       if (prop->kind == PROP_TYPE)
 	{
 	  type = prop->data.original_type;
-	  prop = get_dyn_prop (DYN_PROP_VARIANT_PARTS, type);
+	  prop = type->get_dyn_prop (DYN_PROP_VARIANT_PARTS);
 	}
       gdb_assert (prop->kind == PROP_VARIANT_PARTS);
       print_record_field_types_dynamic (*prop->data.variant_parts,
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6648dc4d678..9efcfea1ef9 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1938,7 +1938,7 @@ stub_noname_complaint (void)
 static int
 array_type_has_dynamic_stride (struct type *type)
 {
-  struct dynamic_prop *prop = get_dyn_prop (DYN_PROP_BYTE_STRIDE, type);
+  struct dynamic_prop *prop = type->get_dyn_prop (DYN_PROP_BYTE_STRIDE);
 
   return (prop != NULL && prop->kind != PROP_CONST);
 }
@@ -1971,7 +1971,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
   if (TYPE_ALLOCATED_PROP (type))
     return 1;
 
-  struct dynamic_prop *prop = get_dyn_prop (DYN_PROP_VARIANT_PARTS, type);
+  struct dynamic_prop *prop = type->get_dyn_prop (DYN_PROP_VARIANT_PARTS);
   if (prop != nullptr && prop->kind != PROP_TYPE)
     return 1;
 
@@ -2180,7 +2180,7 @@ resolve_dynamic_array_or_string (struct type *type,
   else
     elt_type = TYPE_TARGET_TYPE (type);
 
-  prop = get_dyn_prop (DYN_PROP_BYTE_STRIDE, type);
+  prop = type->get_dyn_prop (DYN_PROP_BYTE_STRIDE);
   if (prop != NULL)
     {
       if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
@@ -2417,8 +2417,8 @@ resolve_dynamic_struct (struct type *type,
 
   resolved_type = copy_type (type);
 
-  struct dynamic_prop *variant_prop = get_dyn_prop (DYN_PROP_VARIANT_PARTS,
-						    resolved_type);
+  dynamic_prop *variant_prop
+    = resolved_type->get_dyn_prop (DYN_PROP_VARIANT_PARTS);
   if (variant_prop != nullptr && variant_prop->kind == PROP_VARIANT_PARTS)
     {
       compute_variant_fields (type, resolved_type, addr_stack,
@@ -2633,10 +2633,10 @@ resolve_dynamic_type (struct type *type,
 
 /* See gdbtypes.h  */
 
-struct dynamic_prop *
-get_dyn_prop (enum dynamic_prop_node_kind prop_kind, const struct type *type)
+dynamic_prop *
+type::get_dyn_prop (dynamic_prop_node_kind prop_kind) const
 {
-  struct dynamic_prop_list *node = TYPE_DYN_PROP_LIST (type);
+  dynamic_prop_list *node = TYPE_DYN_PROP_LIST (this);
 
   while (node != NULL)
     {
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 87b1bca3a22..a56570726fe 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -349,15 +349,15 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
 
 /* * True if this type is allocatable.  */
 #define TYPE_IS_ALLOCATABLE(t) \
-  (get_dyn_prop (DYN_PROP_ALLOCATED, t) != NULL)
+  ((t)->get_dyn_prop (DYN_PROP_ALLOCATED) != NULL)
 
 /* * True if this type has variant parts.  */
 #define TYPE_HAS_VARIANT_PARTS(t) \
-  (get_dyn_prop (DYN_PROP_VARIANT_PARTS, t) != nullptr)
+  ((t)->get_dyn_prop (DYN_PROP_VARIANT_PARTS) != nullptr)
 
 /* * True if this type has a dynamic length.  */
 #define TYPE_HAS_DYNAMIC_LENGTH(t) \
-  (get_dyn_prop (DYN_PROP_BYTE_SIZE, t) != nullptr)
+  ((t)->get_dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr)
 
 /* * Instruction-space delimited type.  This is for Harvard architectures
    which have separate instruction and data address spaces (and perhaps
@@ -886,6 +886,10 @@ struct main_type
 
 struct type
 {
+  /* * Return the dynamic property of the requested KIND from this type's
+     list of dynamic properties.  */
+  dynamic_prop *get_dyn_prop (dynamic_prop_node_kind kind) const;
+
   /* * Type that is a pointer to this type.
      NULL if no such pointer-to type is known yet.
      The debugger may add the address of such a type
@@ -1445,7 +1449,7 @@ extern bool set_type_align (struct type *, ULONGEST);
 
 /* Property accessors for the type data location.  */
 #define TYPE_DATA_LOCATION(thistype) \
-  get_dyn_prop (DYN_PROP_DATA_LOCATION, thistype)
+  ((thistype)->get_dyn_prop (DYN_PROP_DATA_LOCATION))
 #define TYPE_DATA_LOCATION_BATON(thistype) \
   TYPE_DATA_LOCATION (thistype)->data.baton
 #define TYPE_DATA_LOCATION_ADDR(thistype) \
@@ -1453,13 +1457,13 @@ extern bool set_type_align (struct type *, ULONGEST);
 #define TYPE_DATA_LOCATION_KIND(thistype) \
   TYPE_DATA_LOCATION (thistype)->kind
 #define TYPE_DYNAMIC_LENGTH(thistype) \
-  get_dyn_prop (DYN_PROP_BYTE_SIZE, thistype)
+  ((thistype)->get_dyn_prop (DYN_PROP_BYTE_SIZE))
 
 /* Property accessors for the type allocated/associated.  */
 #define TYPE_ALLOCATED_PROP(thistype) \
-  get_dyn_prop (DYN_PROP_ALLOCATED, thistype)
+  ((thistype)->get_dyn_prop (DYN_PROP_ALLOCATED))
 #define TYPE_ASSOCIATED_PROP(thistype) \
-  get_dyn_prop (DYN_PROP_ASSOCIATED, thistype)
+  ((thistype)->get_dyn_prop (DYN_PROP_ASSOCIATED))
 
 /* Attribute accessors for dynamic properties.  */
 #define TYPE_DYN_PROP_LIST(thistype) \
@@ -2105,11 +2109,6 @@ extern struct type *resolve_dynamic_type
 /* * Predicate if the type has dynamic values, which are not resolved yet.  */
 extern int is_dynamic_type (struct type *type);
 
-/* * Return the dynamic property of the requested KIND from TYPE's
-   list of dynamic properties.  */
-extern struct dynamic_prop *get_dyn_prop
-  (enum dynamic_prop_node_kind kind, const struct type *type);
-
 /* * Given a dynamic property PROP of a given KIND, add this dynamic
    property to the given TYPE.
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 20661e48d96..4233834dff3 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -708,8 +708,7 @@ rust_print_struct_def (struct type *type, const char *varstring,
       if (is_enum)
 	{
 	  fputs_filtered ("enum ", stream);
-	  struct dynamic_prop *prop = get_dyn_prop (DYN_PROP_VARIANT_PARTS,
-						    type);
+	  dynamic_prop *prop = type->get_dyn_prop (DYN_PROP_VARIANT_PARTS);
 	  if (prop != nullptr && prop->kind == PROP_TYPE)
 	    type = prop->data.original_type;
 	}
-- 
2.26.2



  reply	other threads:[~2020-04-30 18:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 18:17 [PATCH 0/4] Move dyn prop functions to be methods " Simon Marchi
2020-04-30 18:17 ` Simon Marchi [this message]
2020-04-30 18:17 ` [PATCH 2/4] gdb: make add_dyn_prop a method " Simon Marchi
2020-04-30 18:17 ` [PATCH 3/4] gdb: make remove_dyn_prop " Simon Marchi
2020-04-30 18:17 ` [PATCH 4/4] gdb: remove TYPE_DYN_PROP_LIST macro Simon Marchi
2020-05-07 13:58   ` Tom Tromey
2020-05-07 14:15     ` Simon Marchi
2020-05-07 13:59 ` [PATCH 0/4] Move dyn prop functions to be methods of struct type Tom Tromey
2020-05-07 14:07   ` Simon Marchi
2020-05-07 15:34     ` Simon Marchi

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=20200430181753.1093-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.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