summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuliano Procida <gprocida@google.com>2022-01-21 17:30:04 +0000
committerDodji Seketeli <dodji@redhat.com>2022-02-24 18:26:36 +0100
commit628dbfebd6acaa7d617a6c952fc61c372138092d (patch)
tree6d185abfee4fd2ecfc97208e1353b70039d72877
parentXML writer: drop write_elf_symbols_table variable emitted_syms (diff)
downloadlibabigail-628dbfebd6acaa7d617a6c952fc61c372138092d.tar.gz
libabigail-628dbfebd6acaa7d617a6c952fc61c372138092d.tar.bz2
libabigail-628dbfebd6acaa7d617a6c952fc61c372138092d.tar.xz
XML writer: improve slightly emission of top-level declarations
In the loop that emits declarations, the iterator already points to a decl_base_sptr, there is no need to do another dynamic_cast. It is also possible to simplify the loop and its conditionals. There is no change to tests or behaviour. * src/abg-writer.cc (decl_is_emitted): Make decl_base_sptr argument a const reference. (write_translation_unit): Eliminate a typedef and just use a range-for loop without the extra dynamic cast for the non-type case. Use else instead of continue to make it clear there are only two possibilities. Reviewed-by: Matthias Maennich <maennich@google.com> Signed-off-by: Giuliano Procida <gprocida@google.com>
-rw-r--r--src/abg-writer.cc20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index c6869282..496f36a6 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -733,7 +733,7 @@ public:
733 /// @return true if the decl has already been emitted, false 733 /// @return true if the decl has already been emitted, false
734 /// otherwise. 734 /// otherwise.
735 bool 735 bool
736 decl_is_emitted(decl_base_sptr& decl) const 736 decl_is_emitted(const decl_base_sptr& decl) const
737 { 737 {
738 ABG_ASSERT(!is_type(decl)); 738 ABG_ASSERT(!is_type(decl));
739 string repr = get_pretty_representation(decl, true); 739 string repr = get_pretty_representation(decl, true);
@@ -2440,12 +2440,11 @@ write_translation_unit(write_context& ctxt,
2440 ctxt, indent + c.get_xml_element_indent()); 2440 ctxt, indent + c.get_xml_element_indent());
2441 2441
2442 typedef scope_decl::declarations declarations; 2442 typedef scope_decl::declarations declarations;
2443 typedef declarations::const_iterator const_iterator; 2443 const declarations& decls = tu.get_global_scope()->get_sorted_member_decls();
2444 const declarations& d = tu.get_global_scope()->get_sorted_member_decls();
2445 2444
2446 for (const_iterator i = d.begin(); i != d.end(); ++i) 2445 for (const decl_base_sptr& decl : decls)
2447 { 2446 {
2448 if (type_base_sptr t = is_type(*i)) 2447 if (type_base_sptr t = is_type(decl))
2449 { 2448 {
2450 // Emit declaration-only classes that are needed. Some of 2449 // Emit declaration-only classes that are needed. Some of
2451 // these classes can be empty. Those beasts can be classes 2450 // these classes can be empty. Those beasts can be classes
@@ -2456,13 +2455,12 @@ write_translation_unit(write_context& ctxt,
2456 && !ctxt.type_is_emitted(class_type)) 2455 && !ctxt.type_is_emitted(class_type))
2457 write_type(class_type, ctxt, 2456 write_type(class_type, ctxt,
2458 indent + c.get_xml_element_indent()); 2457 indent + c.get_xml_element_indent());
2459 continue;
2460 } 2458 }
2461 2459 else
2462 if (decl_base_sptr d = is_decl(*i)) 2460 {
2463 if (ctxt.decl_is_emitted(d)) 2461 if (!ctxt.decl_is_emitted(decl))
2464 continue; 2462 write_decl(decl, ctxt, indent + c.get_xml_element_indent());
2465 write_decl(*i, ctxt, indent + c.get_xml_element_indent()); 2463 }
2466 } 2464 }
2467 2465
2468 write_referenced_types(ctxt, tu, indent, is_last); 2466 write_referenced_types(ctxt, tu, indent, is_last);