]> sourceware.org Git - libabigail.git/commitdiff
abg-writer: Refactor write_corpus API
authorMatthias Maennich <maennich@google.com>
Tue, 21 May 2019 04:39:16 +0000 (05:39 +0100)
committerDodji Seketeli <dodji@redhat.com>
Wed, 22 May 2019 12:33:45 +0000 (14:33 +0200)
Introduce a new overload for write_corpus that follows the parameter
order context, object (i.e. corpus), indent.

Deprecate all other overloads that were part of the API and mostly
forward them to the new overload. That effort is made to ensure
write_context is always provided. write_context allows access to all
options that influence the output format.

* include/abg-writer.h (write_corpus): Introduce new overload
write_corpus(ctxt, corpus, indent) and deprecate all others.
* src/abg-writer.cc (write_corpus): Likewise for the definitions
and adjust.
* tests/test-read-dwarf.cc (test_task::perform): Use the new
write_corpus which requires a write_context.
* tools/abidw.cc (load_corpus_and_write_abixml, ): Likewise.
* tools/abilint.cc (main): Likewise. Also simplify logic around the
locations as they now can be expressed with less code.

Signed-off-by: Matthias Maennich <maennich@google.com>
include/abg-writer.h
src/abg-writer.cc
tests/test-read-dwarf.cc
tools/abidw.cc
tools/abilint.cc

index ee245cf75db6767267c051e2bff96c13e93622d2..d93cc69a3452403d133a26256926f87eec417227 100644 (file)
@@ -84,21 +84,22 @@ write_corpus_to_archive(const corpus_sptr corp,
                        const bool annotate = false);
 
 bool
-write_corpus(const corpus_sptr corpus,
-            unsigned           indent,
-            write_context&     ctxt);
+write_corpus(write_context& ctxt, const corpus_sptr& corpus, unsigned indent);
 
-bool
-write_corpus(const corpus_sptr corpus,
-            unsigned           indent,
-            std::ostream&      out,
-            const bool annotate = false);
+bool ABG_DEPRECATED
+write_corpus(const corpus_sptr& corpus, unsigned indent, write_context& ctxt);
 
-bool
-write_corpus(const corpus_sptr corpus,
-            unsigned           indent,
-            const string&      path,
-            const bool annotate = false);
+bool ABG_DEPRECATED
+write_corpus(const corpus_sptr corpus,
+            unsigned          indent,
+            std::ostream&     out,
+            const bool        annotate = false);
+
+bool ABG_DEPRECATED
+write_corpus(const corpus_sptr corpus,
+            unsigned          indent,
+            const string&     path,
+            const bool        annotate = false);
 
 bool
 write_corpus_group(const corpus_group_sptr&    group,
index 627a44715807916a0b18d068fc55a618bc0416ed..85f3aebc155a21223cbb1d6a37b906b034fa47a4 100644 (file)
@@ -4063,17 +4063,15 @@ write_corpus_to_archive(const corpus_sptr corp, const bool annotate)
 /// Serialize an ABI corpus to a single native xml document.  The root
 /// note of the resulting XML document is 'abi-corpus'.
 ///
+/// @param ctxt the write context to use.
+///
 /// @param corpus the corpus to serialize.
 ///
 /// @param indent the number of white space indentation to use.
 ///
-/// @param ctxt the write context to use.
-///
 /// @return true upon successful completion, false otherwise.
 bool
-write_corpus(const corpus_sptr corpus,
-            unsigned           indent,
-            write_context&     ctxt)
+write_corpus(write_context& ctxt, const corpus_sptr& corpus, unsigned indent)
 {
   if (!corpus)
     return false;
@@ -4157,7 +4155,25 @@ write_corpus(const corpus_sptr   corpus,
 }
 
 /// Serialize an ABI corpus to a single native xml document.  The root
-/// note of the resulting XML document is 'abi-corpus'.
+/// node of the resulting XML document is 'abi-corpus'.
+///
+/// @param corpus the corpus to serialize.
+///
+/// @param indent the number of white space indentation to use.
+///
+/// @param ctxt the write context to use.
+///
+/// @deprecated: use write_corpus(ctxt, corpus, indent)
+///
+/// @return true upon successful completion, false otherwise.
+bool ABG_DEPRECATED
+write_corpus(const corpus_sptr& corpus, unsigned indent, write_context& ctxt)
+{
+  return write_corpus(ctxt, corpus, indent);
+}
+
+/// Serialize an ABI corpus to a single native xml document.  The root
+/// node of the resulting XML document is 'abi-corpus'.
 ///
 /// @param corpus the corpus to serialize.
 ///
@@ -4167,12 +4183,14 @@ write_corpus(const corpus_sptr  corpus,
 ///
 /// @param annotate whether ABIXML output should be annotated.
 ///
+/// @deprecated: use write_corpus(ctxt, corpus, indent)
+///
 /// @return true upon successful completion, false otherwise.
-bool
-write_corpus(const corpus_sptr corpus,
-            unsigned           indent,
-            std::ostream&      out,
-            const bool annotate)
+bool ABG_DEPRECATED
+write_corpus(const corpus_sptr corpus,
+            unsigned          indent,
+            std::ostream&     out,
+            const bool        annotate)
 {
   if (!corpus)
     return false;
@@ -4180,7 +4198,7 @@ write_corpus(const corpus_sptr    corpus,
   write_context ctxt(corpus->get_environment(), out);
   set_annotate(ctxt, annotate);
 
-  return write_corpus(corpus, indent, ctxt);
+  return write_corpus(ctxt, corpus, indent);
 }
 
 /// Serialize an ABI corpus group to a single native xml document.
@@ -4227,7 +4245,7 @@ std::ostream& out = ctxt.get_ostream();
         group->get_corpora().begin();
        c != group->get_corpora().end();
        ++c)
-    write_corpus(*c, get_indent_to_level(ctxt, indent, 1), ctxt);
+    write_corpus(ctxt, *c, get_indent_to_level(ctxt, indent, 1));
 
   do_indent_to_level(ctxt, indent, 0);
   out << "</abi-corpus-group>\n";
@@ -4274,12 +4292,14 @@ write_corpus_group(const corpus_group_sptr&     group,
 ///
 /// @param annotate whether ABIXML output should be annotated.
 ///
+/// @deprecated: use write_corpus(ctxt, corpus, indent)
+///
 /// @return true upon successful completion, false otherwise.
-bool
-write_corpus(const corpus_sptr corpus,
-            unsigned           indent,
-            const string&      path,
-            const bool annotate)
+bool ABG_DEPRECATED
+write_corpus(const corpus_sptr corpus,
+            unsigned          indent,
+            const string&     path,
+            const bool        annotate)
 {
     bool result = true;
 
@@ -4292,7 +4312,10 @@ write_corpus(const corpus_sptr   corpus,
          return false;
        }
 
-      if (!write_corpus(corpus, indent, of, annotate))
+      const write_context_sptr& ctxt
+         = create_write_context(corpus->get_environment(), of);
+      ctxt->set_annotate(annotate);
+      if (!write_corpus(*ctxt, corpus, indent))
        {
          cerr << "failed to access " << path << "\n";
          result = false;
index e743e5b6e960c8ca5e90207bc639677443af3a67..b3be07fec1ec7e4ecbc9d1ea094696c055cbbaa4 100644 (file)
@@ -46,6 +46,9 @@ using abigail::dwarf_reader::read_corpus_from_elf;
 using abigail::dwarf_reader::read_context;
 using abigail::dwarf_reader::read_context_sptr;
 using abigail::dwarf_reader::create_read_context;
+using abigail::xml_writer::create_write_context;
+using abigail::xml_writer::write_context_sptr;
+using abigail::xml_writer::write_corpus;
 
 /// This is an aggregate that specifies where a test shall get its
 /// input from, and where it shall write its ouput to.
@@ -333,8 +336,9 @@ struct test_task : public abigail::workers::task
        is_ok = false;
        return;
       }
-    is_ok =
-      abigail::xml_writer::write_corpus(corp, /*indent=*/0, of);
+    const write_context_sptr write_ctxt
+       = create_write_context(corp->get_environment(), of);
+    is_ok = write_corpus(*write_ctxt, corp, /*indent=*/0);
     of.close();
 
     string abidw = string(get_build_dir()) + "/tools/abidw";
index d86c3607e454345ce34251914c2df084cd54149c..45c0b862aeecc2e2e941fd3f4154d95ab5188cc0 100644 (file)
@@ -69,6 +69,8 @@ using abigail::comparison::corpus_diff_sptr;
 using abigail::comparison::compute_diff;
 using abigail::comparison::diff_context_sptr;
 using abigail::comparison::diff_context;
+using abigail::xml_writer::create_write_context;
+using abigail::xml_writer::write_context_sptr;
 using abigail::xml_writer::write_corpus;
 using abigail::xml_reader::read_corpus_from_native_xml_file;
 using abigail::dwarf_reader::read_context;
@@ -446,7 +448,10 @@ load_corpus_and_write_abixml(char* argv[],
          // it back, and compare the ABI of what we've read back
          // against the ABI of the input ELF file.
          temp_file_sptr tmp_file = temp_file::create();
-         write_corpus(corp, 0, tmp_file->get_stream(), opts.annotate);
+         const write_context_sptr& write_ctxt = create_write_context(
+             corp->get_environment(), tmp_file->get_stream());
+         set_annotate(*write_ctxt, opts.annotate);
+         write_corpus(*write_ctxt, corp, 0);
          tmp_file->get_stream().flush();
          corpus_sptr corp2 =
            read_corpus_from_native_xml_file(tmp_file->get_path(),
@@ -489,23 +494,21 @@ load_corpus_and_write_abixml(char* argv[],
                << opts.out_file_path << "'\n";
              return 1;
            }
-         abigail::xml_writer::write_context_sptr write_ctxt =
-           abigail::xml_writer::create_write_context(corp->get_environment(),
-                                                     of);
-         abigail::xml_writer::set_show_locs(*write_ctxt, opts.show_locs);
-         abigail::xml_writer::set_annotate(*write_ctxt, opts.annotate);
-         abigail::xml_writer::write_corpus(corp, 0, *write_ctxt);
+         const write_context_sptr& write_ctxt
+             = create_write_context(corp->get_environment(), of);
+         set_show_locs(*write_ctxt, opts.show_locs);
+         set_annotate(*write_ctxt, opts.annotate);
+         write_corpus(*write_ctxt, corp, 0);
          of.close();
          return 0;
        }
       else
        {
-         abigail::xml_writer::write_context_sptr write_ctxt =
-           abigail::xml_writer::create_write_context(corp->get_environment(),
-                                                     cout);
-         abigail::xml_writer::set_show_locs(*write_ctxt, opts.show_locs);
-         abigail::xml_writer::set_annotate(*write_ctxt, opts.annotate);
-         exit_code = !abigail::xml_writer::write_corpus(corp, 0, *write_ctxt);
+         write_context_sptr write_ctxt
+             = create_write_context(corp->get_environment(), cout);
+         set_show_locs(*write_ctxt, opts.show_locs);
+         set_annotate(*write_ctxt, opts.annotate);
+         exit_code = !write_corpus(*write_ctxt, corp, 0);
        }
     }
 
index fab2e6331c8bddc7043d4d5202da926e9dc2e9cc..0bdc4962dee00d1499a21a9455ea333f421fb44b 100644 (file)
@@ -305,7 +305,11 @@ main(int argc, char* argv[])
          set_suppressions(*ctxt, opts);
          corpus_sptr corp = abigail::xml_reader::read_corpus_from_input(*ctxt);
          if (!opts.noout)
-           write_corpus(corp, /*indent=*/0, cout);
+           {
+             const write_context_sptr& ctxt
+                 = create_write_context(corp->get_environment(), cout);
+             write_corpus(*ctxt, corp, /*indent=*/0);
+           }
          return 0;
        }
     }
@@ -411,51 +415,35 @@ main(int argc, char* argv[])
          return 1;
        }
 
-      std::iostream& of = tmp_file->get_stream();
-      bool r = true;
+      std::ostream& of = opts.diff ? tmp_file->get_stream() : cout;
+      const abigail::ir::environment* env
+         = tu ? tu->get_environment() : corp->get_environment();
+      const write_context_sptr ctxt = create_write_context(env, of);
+
+      bool is_ok = true;
 
       if (tu)
        {
-         if (opts.diff)
-           {
-             const write_context_sptr& ctxt = create_write_context(
-                 tu->get_environment(), tmp_file->get_stream());
-             r = write_translation_unit(*ctxt, *tu, 0);
-           }
-         if (!opts.noout && !opts.diff)
-           {
-             const write_context_sptr& ctxt
-                 = create_write_context(tu->get_environment(), cout);
-             r &= write_translation_unit(*ctxt, *tu, 0);
-           }
+         if (!opts.noout)
+           is_ok = write_translation_unit(*ctxt, *tu, 0);
        }
       else
        {
-         r = true;
-         if (type == abigail::tools_utils::FILE_TYPE_XML_CORPUS)
+         if (type == abigail::tools_utils::FILE_TYPE_XML_CORPUS
+             || type == abigail::tools_utils::FILE_TYPE_ELF)
            {
-             if (opts.diff)
-               r = write_corpus(corp, /*indent=*/0, of);
-
-             if (!opts.noout && !opts.diff)
-               r &= write_corpus(corp, /*indent=*/0, cout);
+             if (!opts.noout)
+               is_ok = write_corpus(*ctxt, corp, 0);
            }
          else if (type == abigail::tools_utils::FILE_TYPE_ZIP_CORPUS)
            {
 #ifdef WITH_ZIP_ARCHIVE
              if (!opts.noout)
-               r = write_corpus_to_archive(*corp, tmp_file->get_path());
+               is_ok = write_corpus_to_archive(*corp, tmp_file->get_path());
 #endif //WITH_ZIP_ARCHIVE
            }
-         else if (type == abigail::tools_utils::FILE_TYPE_ELF)
-           {
-             if (!opts.noout)
-               r = write_corpus(corp, /*indent=*/0, cout);
-           }
        }
 
-      bool is_ok = r;
-
       if (!is_ok)
        {
          string output =
This page took 0.045898 seconds and 5 git commands to generate.