From: Matthias Maennich Date: Tue, 21 May 2019 04:39:19 +0000 (+0100) Subject: abidw: Consolidate setting options X-Git-Tag: libabigail-1.7~93 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=344138e6b4d218f7ef09caa97648a6ead58ccf9d;p=libabigail.git abidw: Consolidate setting options When setting options meant to be used for the write_context, it is easy to forget to change all relavant locations. In order to consolidate that, introduce a set_opts function that sets various known options. We benefit from earlier refactoring as now the write_context is passed around to carry options for writers. Hence we can be sure, that if we set up the context correctly (and do not use deprecated functionality), the respective write_* function will see the options set in the context. * include/abg-writer.h (set_common_option): Declare new function. * tools/abidw.cc (load_corpus_and_write_abixml) (load_kernel_corpus_group_and_write_abixml): Use the newly introduced set_common_option. Signed-off-by: Matthias Maennich Signed-off-by: Dodji Seketeli --- diff --git a/include/abg-writer.h b/include/abg-writer.h index dddb5541..200b5f7e 100644 --- a/include/abg-writer.h +++ b/include/abg-writer.h @@ -53,6 +53,24 @@ set_show_locs(write_context& ctxt, bool flag); void set_annotate(write_context& ctxt, bool flag); + +/// A convenience generic function to set common options (usually used +/// by Libabigail tools) from a generic options carrying-object, into +/// a given @ref write_context. +/// +/// @param ctxt the @ref the write_context to consider. +/// +/// @param opts the option-carrying object to set the options from. +/// It must contain data members named: annotate, and show_locs, at +/// very least. +template +void +set_common_options(write_context& ctxt, const OPTS& opts) +{ + set_annotate(ctxt, opts.annotate); + set_show_locs(ctxt, opts.show_locs); +} + void set_ostream(write_context& ctxt, ostream& os); diff --git a/tools/abidw.cc b/tools/abidw.cc index 2ff6cf3d..33b7c76b 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -444,8 +444,7 @@ load_corpus_and_write_abixml(char* argv[], { const write_context_sptr& write_ctxt = create_write_context(corp->get_environment(), cout); - set_annotate(*write_ctxt, opts.annotate); - set_show_locs(*write_ctxt, opts.show_locs); + set_common_options(*write_ctxt, opts); if (opts.abidiff) { @@ -558,7 +557,7 @@ load_kernel_corpus_group_and_write_abixml(char* argv[], { const xml_writer::write_context_sptr& ctxt = xml_writer::create_write_context(group->get_environment(), cout); - set_annotate(*ctxt, opts.annotate); + set_common_options(*ctxt, opts); if (!opts.out_file_path.empty()) {