[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 05/11] abg-writer: Refactor write_corpus_group API



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: Introduce write_corpus_group(ctxt,
	corpus_group, indent) and deprecate all other overloads
	* src/abg-writer.cc: Likewise. Also adjust call sites to use new
	overload.
	* tools/abidw.cc: Migrate to new API of write_corpus_group()

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 include/abg-writer.h | 31 +++++++++++++++++-------------
 src/abg-writer.cc    | 45 +++++++++++++++++++++++++++++++++-----------
 tools/abidw.cc       | 14 ++++++++++----
 3 files changed, 62 insertions(+), 28 deletions(-)

diff --git a/include/abg-writer.h b/include/abg-writer.h
index d93cc69a3452..45303e42bb15 100644
--- a/include/abg-writer.h
+++ b/include/abg-writer.h
@@ -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
diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index 85f3aebc155a..8280e2342a56 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -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)
@@ -4253,6 +4253,27 @@ std::ostream& out = ctxt.get_ostream();
   return true;
 }
 
+/// 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 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'.
 ///
@@ -4264,12 +4285,14 @@ std::ostream& out = ctxt.get_ostream();
 ///
 /// @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
diff --git a/tools/abidw.cc b/tools/abidw.cc
index 45c0b862aeec..d47088604603 100644
--- a/tools/abidw.cc
+++ b/tools/abidw.cc
@@ -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;
-- 
2.21.0.1020.gf2820cf01a-goog