public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Giuliano Procida <gprocida@google.com>
To: libabigail@sourceware.org
Cc: dodji@seketeli.org, kernel-team@android.com, gprocida@google.com,
	 maennich@google.com
Subject: [PATCH 2/4] abg-writer: refactor recording of unemitted types
Date: Fri, 10 Sep 2021 12:23:23 +0100	[thread overview]
Message-ID: <20210910112325.806676-3-gprocida@google.com> (raw)
In-Reply-To: <20210910112325.806676-1-gprocida@google.com>

The code fragment

if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
  referenced_types_to_emit.insert(*i);

appears 5 times. This commit inlines the insertion into the helper
function which is also renamed.

	* src/abg-writer.cc (referenced_type_should_be_emitted):
	Replaced by record_unemitted_type.
	(record_unemitted_type): Replacement function that also takes
	care of inserting the type into the set.
	(write_translation_unit): Replace calls to
	referenced_type_should_be_emitted and inserts with calls to
	record_unemitted_type.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-writer.cc | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index d23f4fd6..795ca685 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -2248,10 +2248,12 @@ write_canonical_types_of_scope(const scope_decl	&scope,
 }
 
 /// Test if a type referenced in a given translation unit should be
-/// emitted or not.
+/// emitted and record it if so.
 ///
 /// This is a subroutine of @ref write_translation_unit.
 ///
+/// @param types the set of types to update.
+///
 /// @param t the type to consider.
 ///
 /// @param ctxt the write context to consider.
@@ -2260,20 +2262,18 @@ write_canonical_types_of_scope(const scope_decl	&scope,
 ///
 /// @param tu_is_last true if @p tu is the last translation unit being
 /// emitted.
-///
-/// @return true iff @p t is to be emitted.
-static bool
-referenced_type_should_be_emitted(const type_base *t,
-				  const write_context& ctxt,
-				  const translation_unit& tu,
-				  bool tu_is_last)
+static void
+record_unemitted_type(type_ptr_set_type& types,
+		      const type_base *t,
+		      const write_context& ctxt,
+		      const translation_unit& tu,
+		      bool tu_is_last)
 {
   if ((tu_is_last || t->get_translation_unit()->get_absolute_path()
        == tu.get_absolute_path())
       && !ctxt.type_is_emitted(t)
       && !ctxt.decl_only_type_is_emitted(t))
-    return true;
-  return false;
+    types.insert(t);
 }
 
 /// Serialize a translation unit to an output stream.
@@ -2389,22 +2389,19 @@ write_translation_unit(write_context&		ctxt,
 	 ctxt.get_referenced_types().begin();
        i != ctxt.get_referenced_types().end();
        ++i)
-    if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-      referenced_types_to_emit.insert(*i);
+    record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
   for (fn_type_ptr_set_type::const_iterator i =
 	 ctxt.get_referenced_function_types().begin();
        i != ctxt.get_referenced_function_types().end();
        ++i)
-    if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-      referenced_types_to_emit.insert(*i);
+    record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
   for (type_ptr_set_type::const_iterator i =
 	 ctxt.get_referenced_non_canonical_types().begin();
        i != ctxt.get_referenced_non_canonical_types().end();
        ++i)
-    if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-      referenced_types_to_emit.insert(*i);
+    record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
   // Ok, now let's emit the referenced type for good.
   while (!referenced_types_to_emit.empty())
@@ -2459,15 +2456,13 @@ write_translation_unit(write_context&		ctxt,
 	     ctxt.get_referenced_types().begin();
 	   i != ctxt.get_referenced_types().end();
 	   ++i)
-	if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-	  referenced_types_to_emit.insert(*i);
+        record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
 
       for (type_ptr_set_type::const_iterator i =
 	     ctxt.get_referenced_non_canonical_types().begin();
 	   i != ctxt.get_referenced_non_canonical_types().end();
 	   ++i)
-	if (referenced_type_should_be_emitted(*i, ctxt, tu, is_last))
-	  referenced_types_to_emit.insert(*i);
+        record_unemitted_type(referenced_types_to_emit, *i, ctxt, tu, is_last);
     }
 
   // Now handle all function types that were not only referenced by
-- 
2.33.0.309.g3052b89438-goog


  parent reply	other threads:[~2021-09-10 11:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 11:23 [PATCH 0/4] Looking at equality and hashing Giuliano Procida
2021-09-10 11:23 ` [PATCH 1/4] abg-writer: get_id_for_type: refactor insertion and look-up Giuliano Procida
2021-09-10 11:23 ` Giuliano Procida [this message]
2021-09-10 11:23 ` [PATCH 3/4] abg-writer: allow debugging of equality / hash issues Giuliano Procida
2021-09-10 11:23 ` [PATCH 4/4] RFC: abg-writer: add a missing check for emitted declarations Giuliano Procida

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