Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 07/10] Make tdesc_feature::types an std::vector
Date: Tue, 31 Oct 2017 01:42:00 -0000	[thread overview]
Message-ID: <1509414120-14659-8-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1509414120-14659-1-git-send-email-simon.marchi@ericsson.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

This patch makes tdesc_feature::types an std::vector of unique_ptr of
tdesc_type.  This way, we don't need to manually free the objects and
the vector in ~tdesc_feature.

gdb/ChangeLog:

	* target-descriptions.c (tdesc_type_p): Remove typedef.
	(DEF_VEC_P (tdesc_type_p)): Remove.
	(struct tdesc_feature) <types>: Change type to std::vector.
	<~tdesc_feature>: Replace with default implementation.
	<accept>: Adjust.
	(tdesc_named_type): Adjust.
	(tdesc_create_vector): Adjust.
	(tdesc_create_struct): Adjust.
	(tdesc_create_union): Adjust.
	(tdesc_create_flags): Adjust.
	(tdesc_create_enum): Adjust.
---
 gdb/target-descriptions.c | 60 ++++++++++++++++-------------------------------
 1 file changed, 20 insertions(+), 40 deletions(-)

diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 647d42d..13d6884 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -192,7 +192,7 @@ enum tdesc_type_kind
   TDESC_TYPE_ENUM
 };
 
-typedef struct tdesc_type : tdesc_element
+struct tdesc_type : tdesc_element
 {
   tdesc_type (const char *name_, enum tdesc_type_kind kind_)
     : name (xstrdup (name_)), kind (kind_)
@@ -269,8 +269,9 @@ typedef struct tdesc_type : tdesc_element
   {
     return !(*this == other);
   }
-} *tdesc_type_p;
-DEF_VEC_P(tdesc_type_p);
+};
+
+typedef std::unique_ptr<tdesc_type> tdesc_type_up;
 
 /* A feature from a target description.  Each feature is a collection
    of other elements, e.g. registers and types.  */
@@ -281,15 +282,7 @@ struct tdesc_feature : tdesc_element
     : name (name_)
   {}
 
-  virtual ~tdesc_feature ()
-  {
-    struct tdesc_type *type;
-    int ix;
-
-    for (ix = 0; VEC_iterate (tdesc_type_p, types, ix, type); ix++)
-      delete type;
-    VEC_free (tdesc_type_p, types);
-  }
+  virtual ~tdesc_feature () = default;
 
   DISABLE_COPY_AND_ASSIGN (tdesc_feature);
 
@@ -301,17 +294,13 @@ struct tdesc_feature : tdesc_element
   std::vector<std::unique_ptr<tdesc_reg>> registers;
 
   /* The types associated with this feature.  */
-  VEC(tdesc_type_p) *types = NULL;
+  std::vector<tdesc_type_up> types;
 
   void accept (tdesc_element_visitor &v) const override
   {
     v.visit_pre (this);
 
-    struct tdesc_type *type;
-
-    for (int ix = 0;
-	 VEC_iterate (tdesc_type_p, types, ix, type);
-	 ix++)
+    for (const tdesc_type_up &type : types)
       type->accept (v);
 
     for (const tdesc_reg_up &reg : registers)
@@ -337,20 +326,15 @@ struct tdesc_feature : tdesc_element
 	  return false;
       }
 
-    if (VEC_length (tdesc_type_p, types)
-	!= VEC_length (tdesc_type_p, other.types))
+    if (types.size () != other.types.size ())
       return false;
 
-    tdesc_type *type;
-
-    for (int ix = 0;
-	 VEC_iterate (tdesc_type_p, types, ix, type);
-	 ix++)
+    for (int ix = 0; ix < types.size (); ix++)
       {
-	tdesc_type *type2
-	  = VEC_index (tdesc_type_p, other.types, ix);
+	const tdesc_type_up &type1 = types[ix];
+	const tdesc_type_up &type2 = other.types[ix];
 
-	if (type != type2 && *type != *type2)
+	if (type1 != type2 && *type1 != *type2)
 	  return false;
       }
 
@@ -361,7 +345,6 @@ struct tdesc_feature : tdesc_element
   {
     return !(*this == other);
   }
-
 };
 
 typedef std::unique_ptr<tdesc_feature> tdesc_feature_up;
@@ -776,16 +759,13 @@ tdesc_predefined_type (enum tdesc_type_kind kind)
 struct tdesc_type *
 tdesc_named_type (const struct tdesc_feature *feature, const char *id)
 {
-  int ix;
-  struct tdesc_type *type;
-
   /* First try target-defined types.  */
-  for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
+  for (const tdesc_type_up &type : feature->types)
     if (strcmp (type->name, id) == 0)
-      return type;
+      return type.get ();
 
   /* Next try the predefined types.  */
-  for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
+  for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
     if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
       return &tdesc_predefined_types[ix];
 
@@ -1499,7 +1479,7 @@ tdesc_create_vector (struct tdesc_feature *feature, const char *name,
   type->u.v.type = field_type;
   type->u.v.count = count;
 
-  VEC_safe_push (tdesc_type_p, feature->types, type);
+  feature->types.emplace_back (type);
   return type;
 }
 
@@ -1510,7 +1490,7 @@ tdesc_create_struct (struct tdesc_feature *feature, const char *name)
 {
   struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_STRUCT);
 
-  VEC_safe_push (tdesc_type_p, feature->types, type);
+  feature->types.emplace_back (type);
   return type;
 }
 
@@ -1531,7 +1511,7 @@ tdesc_create_union (struct tdesc_feature *feature, const char *name)
 {
   struct tdesc_type *type = new tdesc_type (name, TDESC_TYPE_UNION);
 
-  VEC_safe_push (tdesc_type_p, feature->types, type);
+  feature->types.emplace_back (type);
   return type;
 }
 
@@ -1547,7 +1527,7 @@ tdesc_create_flags (struct tdesc_feature *feature, const char *name,
 
   type->u.u.size = size;
 
-  VEC_safe_push (tdesc_type_p, feature->types, type);
+  feature->types.emplace_back (type);
   return type;
 }
 
@@ -1561,7 +1541,7 @@ tdesc_create_enum (struct tdesc_feature *feature, const char *name,
 
   type->u.u.size = size;
 
-  VEC_safe_push (tdesc_type_p, feature->types, type);
+  feature->types.emplace_back (type);
   return type;
 }
 
-- 
2.7.4


  parent reply	other threads:[~2017-10-31  1:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31  1:42 [PATCH 00/10] Use std::vector and std::string throughout target-descriptions.c Simon Marchi
2017-10-31  1:42 ` [PATCH 08/10] Make tdesc_type::name an std::string Simon Marchi
2017-10-31  1:42 ` [PATCH 05/10] Make tdesc_feature::registers an std::vector Simon Marchi
2017-11-02  9:32   ` Yao Qi
2017-11-02 13:22     ` Simon Marchi
2017-10-31  1:42 ` [PATCH 04/10] Make tdesc_feature::name an std::string Simon Marchi
2017-10-31  1:42 ` Simon Marchi [this message]
2017-10-31  1:42 ` [PATCH 01/10] Make target_desc::properties an std::vector Simon Marchi
2017-10-31  1:42 ` [PATCH 03/10] Make target_desc::features " Simon Marchi
2017-11-02  9:29   ` Yao Qi
2017-11-02 13:20     ` Simon Marchi
2017-10-31  1:42 ` [PATCH 06/10] Make tdesc_reg string fields std::string Simon Marchi
2017-11-02  9:43   ` Yao Qi
2017-11-02 13:24     ` Simon Marchi
2017-10-31  1:42 ` [PATCH 10/10] Make tdesc_arch_data::arch_regs an std::vector Simon Marchi
2017-10-31  1:42 ` [PATCH 09/10] Make tdesc_type::u::u::fields " Simon Marchi
2017-11-02 10:02   ` Yao Qi
2017-11-02 13:27     ` Simon Marchi
2017-12-03 16:04       ` [PATCH 11/10] Split tdesc_type into multiple classes Simon Marchi
2017-12-05 16:46         ` Yao Qi
2017-12-05 21:42           ` Simon Marchi
2017-10-31  1:43 ` [PATCH 02/10] Make target_desc::compatible an std::vector Simon Marchi
2017-11-02 10:16 ` [PATCH 00/10] Use std::vector and std::string throughout target-descriptions.c Yao Qi

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=1509414120-14659-8-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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