diff mbox series

[2/4] Add no-parameter-names to drop function parameter names.

Message ID 20200421122821.13769-3-mark@klomp.org
State Committed
Headers show
Series [1/4] Add named-types-ids to use name ids after the type name instead of numbers. | expand

Commit Message

Mark Wielaard April 21, 2020, 12:28 p.m. UTC
From: Mark Wielaard <mark@klomp.org>

The function parameter names are not relevant for the (exported)
ABI. So provide an option to simply drop them from the corpus.

	* doc/manuals/abidw.rst: Add documentation for --no-parameter-names.
	* include/abg-writer.h (set_write_parameter_names): New function.
	(set_write_parameter_names): Call it.
	* src/abg-writer.cc (write_context): Add m_write_parameter_names
	bool, get_write_parameter_names and set_write_parameter_names
	functions.
	(write_context::write_function_decl): Check write_parameter_names.
	* tools/abidw.cc (options): Add write_parameter_names.
	(display_usage): Describe --no-parameter-names.
	(parse_command_line): Parse --no-parameter-names.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 doc/manuals/abidw.rst |  5 +++++
 include/abg-writer.h  |  4 ++++
 src/abg-writer.cc     | 30 +++++++++++++++++++++++++++++-
 tools/abidw.cc        |  5 +++++
 4 files changed, 43 insertions(+), 1 deletion(-)

Comments

Dodji Seketeli April 24, 2020, 1:35 p.m. UTC | #1
"Mark J. Wielaard" <mark@klomp.org> a ?crit:

> From: Mark Wielaard <mark@klomp.org>
>
> The function parameter names are not relevant for the (exported)
> ABI. So provide an option to simply drop them from the corpus.
>
> 	* doc/manuals/abidw.rst: Add documentation for --no-parameter-names.
> 	* include/abg-writer.h (set_write_parameter_names): New function.
> 	(set_write_parameter_names): Call it.
> 	* src/abg-writer.cc (write_context): Add m_write_parameter_names
> 	bool, get_write_parameter_names and set_write_parameter_names
> 	functions.
> 	(write_context::write_function_decl): Check write_parameter_names.
> 	* tools/abidw.cc (options): Add write_parameter_names.
> 	(display_usage): Describe --no-parameter-names.
> 	(parse_command_line): Parse --no-parameter-names.

Applied to master, thanks!
diff mbox series

Patch

diff --git a/doc/manuals/abidw.rst b/doc/manuals/abidw.rst
index 1e427d32..dd72d149 100644
--- a/doc/manuals/abidw.rst
+++ b/doc/manuals/abidw.rst
@@ -178,6 +178,11 @@  Options
    In the emitted ABI representation, do not show file, line or column
    where ABI artifacts are defined.
 
+  * ``--no-parameter-names``
+
+    In the emitted ABI representation, do not show names of function
+    parameters, just the types.
+
   * ``--named-type-ids``
 
     Without this option ids used to reference types in the XML file
diff --git a/include/abg-writer.h b/include/abg-writer.h
index f1598a15..71b7efe6 100644
--- a/include/abg-writer.h
+++ b/include/abg-writer.h
@@ -68,6 +68,9 @@  set_short_locs(write_context& ctxt, bool flag);
 void
 set_named_type_ids(write_context& ctxt, bool flag);
 
+void
+set_write_parameter_names(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.
@@ -86,6 +89,7 @@  set_common_options(write_context& ctxt, const OPTS& opts)
   set_write_architecture(ctxt, opts.write_architecture);
   set_write_corpus_path(ctxt, opts.write_corpus_path);
   set_write_comp_dir(ctxt, opts.write_comp_dir);
+  set_write_parameter_names(ctxt, opts.write_parameter_names);
   set_short_locs(ctxt, opts.short_locs);
   set_named_type_ids(ctxt, opts.named_type_ids);
 }
diff --git a/src/abg-writer.cc b/src/abg-writer.cc
index c240443c..6c57166f 100644
--- a/src/abg-writer.cc
+++ b/src/abg-writer.cc
@@ -221,6 +221,7 @@  class write_context
   bool					m_write_architecture;
   bool					m_write_corpus_path;
   bool					m_write_comp_dir;
+  bool					m_write_parameter_names;
   bool					m_short_locs;
   bool					m_named_type_ids;
   mutable type_ptr_map			m_type_id_map;
@@ -257,6 +258,7 @@  public:
       m_write_architecture(true),
       m_write_corpus_path(true),
       m_write_comp_dir(true),
+      m_write_parameter_names(true),
       m_short_locs(false),
       m_named_type_ids(false)
   {}
@@ -370,6 +372,20 @@  public:
   set_named_type_ids(bool f)
   {m_named_type_ids = f;}
 
+  /// Getter of the parameter-names option.
+  ///
+  /// @return true iff parameter names shall be emitted
+  bool
+  get_write_parameter_names() const
+  {return m_write_parameter_names;}
+
+  /// Setter of the parameter-names option
+  ///
+  /// @param f the new value of the flag.
+  void
+  set_write_parameter_names(bool f)
+  {m_write_parameter_names = f;}
+
   /// Getter of the "show-locs" option.
   ///
   /// When this option is true then the XML writer emits location
@@ -2112,6 +2128,18 @@  void
 set_named_type_ids(write_context& ctxt, bool flag)
 {ctxt.set_named_type_ids(flag);}
 
+/// Set the 'parameter-names' flag.
+///
+/// When this flag is set then the XML writer will emit the names of
+/// function parameters.
+///
+/// @param ctxt the context to set this flag on to.
+///
+/// @param flag the new value of the 'parameter-names' flag.
+void
+set_write_parameter_names(write_context& ctxt, bool flag)
+{ctxt.set_write_parameter_names(flag);}
+
 /// Serialize the canonical types of a given scope.
 ///
 /// @param scope the scope to consider.
@@ -3225,7 +3253,7 @@  write_function_decl(const function_decl_sptr& decl, write_context& ctxt,
 	    << "'";
 	  ctxt.record_type_as_referenced(parm_type);
 
-	  if (!(*pi)->get_name().empty())
+	  if (ctxt.get_write_parameter_names() && !(*pi)->get_name().empty())
 	    o << " name='" << (*pi)->get_name() << "'";
 	}
       write_is_artificial(*pi, o);
diff --git a/tools/abidw.cc b/tools/abidw.cc
index 7251c98d..510a0707 100644
--- a/tools/abidw.cc
+++ b/tools/abidw.cc
@@ -99,6 +99,7 @@  struct options
   bool			write_architecture;
   bool			write_corpus_path;
   bool			write_comp_dir;
+  bool			write_parameter_names;
   bool			short_locs;
   bool			load_all_types;
   bool			linux_kernel_mode;
@@ -120,6 +121,7 @@  struct options
       write_architecture(true),
       write_corpus_path(true),
       write_comp_dir(true),
+      write_parameter_names(true),
       short_locs(false),
       load_all_types(),
       linux_kernel_mode(true),
@@ -168,6 +170,7 @@  display_usage(const string& prog_name, ostream& out)
     << "  --drop-undefined-syms  drop undefined symbols from representation\n"
     << "  --named_type-ids  use id attributes based on type names in XML file\n"
     << "  --no-comp-dir-path  do not show compilation path information\n"
+    << "  --no-parameter-names  do not show names of function parameters\n"
     << "  --check-alternate-debug-info <elf-path>  check alternate debug info "
     "of <elf-path>\n"
     << "  --check-alternate-debug-info-base-name <elf-path>  check alternate "
@@ -288,6 +291,8 @@  parse_command_line(int argc, char* argv[], options& opts)
 	opts.short_locs = true;
       else if (!strcmp(argv[i], "--no-comp-dir-path"))
 	opts.write_comp_dir = false;
+      else if (!strcmp(argv[i], "--no-parameter-names"))
+	opts.write_parameter_names = false;
       else if (!strcmp(argv[i], "--check-alternate-debug-info")
 	       || !strcmp(argv[i], "--check-alternate-debug-info-base-name"))
 	{