abg-writer: Refactor write_corpus_group API
authorMatthias Maennich <maennich@google.com>
Tue, 21 May 2019 04:39:17 +0000 (05:39 +0100)
committerDodji Seketeli <dodji@redhat.com>
Wed, 22 May 2019 12:33:45 +0000 (14:33 +0200)
Introduce a new call overload for write_corpus_group that follows the
parameter order context, object (i.e. corpus_group), 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_group): Introduce new
overload write_corpus_group(ctxt, corpus_group, indent) and
deprecate all others.
* src/abg-writer.cc (write_corpus_group): Likewise for the
definitions and adjust.
* tools/abidw.cc (load_kernel_corpus_group_and_write_abixml):
Migrate to new API of write_corpus_group()

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

index d93cc69..45303e4 100644 (file)
@@ -102,21 +102,26 @@ write_corpus(const corpus_sptr corpus,
             const bool        annotate = false);
 
 bool
-write_corpus_group(const corpus_group_sptr&    group,
-                  unsigned                     indent,
-                  write_context&               ctxt);
+write_corpus_group(write_context&          ctx,
+                  const corpus_group_sptr& group,
+                  unsigned                 indent);
 
-bool
-write_corpus_group(const corpus_group_sptr&    group,
-                  unsigned                     indent,
-                  std::ostream&                out,
-                  const bool                   annotate = false);
+bool ABG_DEPRECATED
+write_corpus_group(const corpus_group_sptr& group,
+                  unsigned                 indent,
+                  write_context&           ctxt);
 
-bool
-write_corpus_group(const corpus_group_sptr&    group,
-                  unsigned                     indent,
-                  const string&                path,
-                  const bool                   annotate = false);
+bool ABG_DEPRECATED
+write_corpus_group(const corpus_group_sptr& group,
+                  unsigned                 indent,
+                  std::ostream&            out,
+                  const bool               annotate = false);
+
+bool ABG_DEPRECATED
+write_corpus_group(const corpus_group_sptr& group,
+                  unsigned                 indent,
+                  const string&            path,
+                  const bool               annotate = false);
 
 }// end namespace xml_writer
 }// end namespace abigail
index 85f3aeb..8280e23 100644 (file)
@@ -4204,17 +4204,17 @@ write_corpus(const corpus_sptr corpus,
 /// Serialize an ABI corpus group to a single native xml document.
 /// The root note of the resulting XML document is 'abi-corpus-group'.
 ///
+/// @param ctxt the write context to use.
+///
 /// @param group the corpus group 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_group(const corpus_group_sptr&    group,
-                  unsigned                     indent,
-                  write_context&               ctxt)
+write_corpus_group(write_context&          ctxt,
+                  const corpus_group_sptr& group,
+                  unsigned                 indent)
 
 {
   if (!group)
@@ -4260,16 +4260,39 @@ std::ostream& out = ctxt.get_ostream();
 ///
 /// @param indent the number of white space indentation to use.
 ///
+/// @param ctxt the write context to use.
+///
+/// @deprecated use write_corpus_group(ctxt, corpus_group, indent)
+///
+/// @return true upon successful completion, false otherwise.
+bool ABG_DEPRECATED
+write_corpus_group(const corpus_group_sptr& group,
+                  unsigned                 indent,
+                  write_context&           ctxt)
+
+{
+  return write_corpus_group(ctxt, group, indent);
+}
+
+/// Serialize an ABI corpus group to a single native xml document.
+/// The root note of the resulting XML document is 'abi-corpus-group'.
+///
+/// @param group the corpus group to serialize.
+///
+/// @param indent the number of white space indentation to use.
+///
 /// @param out the output stream to serialize the ABI corpus to.
 ///
 /// @param annotate whether ABIXML output should be annotated.
 ///
+/// @deprecated use write_corpus_group(ctxt, corpus_group, indent)
+///
 /// @return true upon successful completion, false otherwise.
-bool
-write_corpus_group(const corpus_group_sptr&    group,
-                  unsigned                     indent,
-                  std::ostream&                out,
-                  const bool                   annotate)
+bool ABG_DEPRECATED
+write_corpus_group(const corpus_group_sptr& group,
+                  unsigned                 indent,
+                  std::ostream&            out,
+                  const bool               annotate)
 
 {
   if (!group)
@@ -4278,7 +4301,7 @@ write_corpus_group(const corpus_group_sptr&       group,
   write_context ctxt(group->get_environment(), out);
   set_annotate(ctxt, annotate);
 
-  return write_corpus_group(group, indent, ctxt);
+  return write_corpus_group(ctxt, group, indent);
 }
 
 /// Serialize an ABI corpus to a single native xml document.  The root
index 45c0b86..d470886 100644 (file)
@@ -570,12 +570,18 @@ load_kernel_corpus_group_and_write_abixml(char* argv[],
                << opts.out_file_path << "'\n";
              return 1;
            }
-         exit_code = !xml_writer::write_corpus_group(group, 0, of,
-                                                     opts.annotate);
+         const write_context_sptr& ctxt
+             = create_write_context(group->get_environment(), of);
+         set_annotate(*ctxt, opts.annotate);
+         exit_code = !write_corpus_group(*ctxt, group, 0);
        }
       else
-       exit_code = !xml_writer::write_corpus_group(group, 0, cout,
-                                                   opts.annotate);
+       {
+         const write_context_sptr& ctxt
+             = create_write_context(group->get_environment(), cout);
+         set_annotate(*ctxt, opts.annotate);
+         exit_code = !write_corpus_group(*ctxt, group, 0);
+       }
     }
 
   return exit_code;