public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Matthias Maennich <maennich@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, gprocida@google.com, kernel-team@android.com,
	 maennich@google.com
Subject: [PATCH 1/5] XML writer: use consistent type pointers for type ids and emission tracking
Date: Fri,  3 Dec 2021 11:46:19 +0000	[thread overview]
Message-ID: <20211203114622.2944173-2-maennich@google.com> (raw)
In-Reply-To: <20211203114622.2944173-1-maennich@google.com>

Insertion resolves the canonical type, if available, but look-up did
not. Given that type id insertion and look-up also resolve canonical
types, it makes sense to adjust the remaining code accordingly.

Neither decl_only_type_is_emitted nor record_decl_only_type_as_emitted
do the check, but very few types end up being recorded this way.

The functions write_class_decl and write_union_decl (but not
write_class_decl_opening_tag and write_union_decl_opening_tag which
can be called in other contexts) resolve declaration-only types to a
definition where possible.

To ensure type ids consistently refer to the same resolved type we
should resolve canonical types and definitions-of-declarations more
consistently.

This change introduces get_preferred_type to return the exemplar type
that should be used for type id and emitted checks.

However, it does not also change all the write functions to write out
the exemplar types.

	* src/abg-writer.cc (get_preferred_type): new function.
	(type_has_existing_id): use get_preferred_type for resolution.
	(get_id_for_type): Likewise.
	(record_type_as_emitted): Likewise.
	(type_is_emitted): Likewise.

Reviewed-by: Giuliano Procida <gprocida@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-writer.cc | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 21b79e888f31..9c3ae6f8d5b4 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -390,14 +390,25 @@ public:
   type_has_existing_id(type_base_sptr type) const
   {return type_has_existing_id(type.get());}
 
+  type_base*
+  get_preferred_type(const type_base* type) const
+  {
+    // declaration -> definition -> canonical is possible
+    if (decl_base* decl = look_through_decl_only(is_decl(type)))
+      {
+	type = is_type(decl);
+	ABG_ASSERT(type);
+      }
+    type_base* canonical = type->get_naked_canonical_type();
+    return canonical ? canonical : const_cast<type_base*>(type);
+  }
+
   /// @return true iff type has already been assigned an ID.
   bool
   type_has_existing_id(type_base* type) const
   {
-    type_base *c = type->get_naked_canonical_type();
-    if (c == 0)
-      c = const_cast<type_base*>(type);
-    return (m_type_id_map.find(c) != m_type_id_map.end());
+    type = get_preferred_type(type);
+    return m_type_id_map.find(type) != m_type_id_map.end();
   }
 
   /// Associate a unique id to a given type.  For that, put the type
@@ -413,11 +424,9 @@ public:
   /// associated to it, create a new one and return it.  Otherwise,
   /// return the existing id for that type.
   interned_string
-  get_id_for_type(const type_base* t) const
+  get_id_for_type(type_base* type) const
   {
-    type_base *c = t->get_naked_canonical_type();
-    if (c == 0)
-      c = const_cast<type_base*>(t);
+    type_base* c = get_preferred_type(type);
 
     type_ptr_map::const_iterator it = m_type_id_map.find(c);
     if (it != m_type_id_map.end())
@@ -715,11 +724,9 @@ public:
   ///
   /// @param t the type to flag.
   void
-  record_type_as_emitted(const type_base *t)
+  record_type_as_emitted(const type_base* t)
   {
-    type_base *c = t->get_naked_canonical_type();
-    if (c == 0)
-      c = const_cast<type_base*>(t);
+    type_base* c = get_preferred_type(t);
     m_emitted_type_set.insert(c);
   }
 
@@ -730,9 +737,10 @@ public:
   /// @return true if the type has already been emitted, false
   /// otherwise.
   bool
-  type_is_emitted(const type_base *t) const
+  type_is_emitted(const type_base* t) const
   {
-    return m_emitted_type_set.find(t) != m_emitted_type_set.end();
+    type_base* c = get_preferred_type(t);
+    return m_emitted_type_set.find(c) != m_emitted_type_set.end();
   }
 
   /// Test if a given type has been written out to the XML output.
-- 
2.34.1.400.ga245620fadb-goog


  reply	other threads:[~2021-12-03 12:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03 11:46 [PATCH 0/5] Improvements for the XML Writer Matthias Maennich
2021-12-03 11:46 ` Matthias Maennich [this message]
2021-12-09 17:57   ` [PATCH 1/5] XML writer: use consistent type pointers for type ids and emission tracking Dodji Seketeli
2021-12-03 11:46 ` [PATCH 2/5] XML writer: use exemplar types for tracking referenced types Matthias Maennich
2021-12-10 10:42   ` Dodji Seketeli
2021-12-03 11:46 ` [PATCH 3/5] XML writer: track emitted types by bare pointer Matthias Maennich
2021-12-10 10:50   ` Dodji Seketeli
2021-12-16 16:07     ` Matthias Maennich
2022-01-10 17:00       ` Dodji Seketeli
2022-01-17 18:03         ` Matthias Maennich
2022-01-18 17:15   ` Dodji Seketeli
2021-12-03 11:46 ` [PATCH 4/5] XML writer: map type ids " Matthias Maennich
2022-01-19 10:12   ` Dodji Seketeli
2021-12-03 11:46 ` [PATCH 5/5] XML writer: resolve declaration-only enum definitions Matthias Maennich
2022-01-19 10:38   ` Dodji Seketeli

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=20211203114622.2944173-2-maennich@google.com \
    --to=maennich@google.com \
    --cc=dodji@seketeli.org \
    --cc=gprocida@google.com \
    --cc=kernel-team@android.com \
    --cc=libabigail@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).