diff mbox series

[3/7] Better suppression section parsing delegation.

Message ID 20200817093819.172380-4-gprocida@google.com
State New
Headers show
Series Suppression parsing - preparatory work | expand

Commit Message

Giuliano Procida Aug. 17, 2020, 9:38 a.m. UTC
The function read_suppressions hands the same ini config section to
each of four parsing functions, until one succeeds. Each of those in
turn has an early exit if the name of the section doesn't correspond.
This can be simplified.

This patch moves the name checking into read_suppressions so that
exactly one parsing function is called per section.

	* src/abg-suppression.cc (read_suppressions): Call appropriate
	read_foo_suppression function based on section name.
	(read_type_suppression): Remove section name check.
	(read_function_suppression): Ditto.
	(read_variable_suppression): Ditto.
	(read_file_suppression): Ditto.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-suppression.cc | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index ae7cc95ce..682bb8742 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -372,17 +372,25 @@  static void
 read_suppressions(const ini::config& config,
 		  suppressions_type& suppressions)
 {
-  suppression_sptr s;
   for (ini::config::sections_type::const_iterator i =
 	 config.get_sections().begin();
        i != config.get_sections().end();
        ++i)
-    if ((s = read_type_suppression(**i))
-	|| (s = read_function_suppression(**i))
-	|| (s = read_variable_suppression(**i))
-	|| (s = read_file_suppression(**i)))
-      suppressions.push_back(s);
-
+    {
+      const ini::config::section_sptr& section = *i;
+      const std::string& name = section->get_name();
+      suppression_sptr s;
+      if (name == "suppress_type")
+	s = read_type_suppression(*section);
+      else if (name == "suppress_function")
+	s = read_function_suppression(*section);
+      else if (name == "suppress_variable")
+	s = read_variable_suppression(*section);
+      else if (name == "suppress_file")
+	s = read_file_suppression(*section);
+      if (s)
+	suppressions.push_back(s);
+    }
 }
 
 /// Read suppressions specifications from an input stream.
@@ -1564,9 +1572,6 @@  read_type_suppression(const ini::config::section& section)
 {
   type_suppression_sptr result;
 
-  if (section.get_name() != "suppress_type")
-    return result;
-
   static const char *const sufficient_props[] = {
     "file_name_regexp",
     "file_name_not_regexp",
@@ -3153,9 +3158,6 @@  read_function_suppression(const ini::config::section& section)
 {
   function_suppression_sptr result;
 
-  if (section.get_name() != "suppress_function")
-    return result;
-
   static const char *const sufficient_props[] = {
     "label",
     "file_name_regexp",
@@ -4033,9 +4035,6 @@  read_variable_suppression(const ini::config::section& section)
 {
   variable_suppression_sptr result;
 
-  if (section.get_name() != "suppress_variable")
-    return result;
-
   static const char *const sufficient_props[] = {
     "label",
     "file_name_regexp",
@@ -4298,9 +4297,6 @@  read_file_suppression(const ini::config::section& section)
 {
   file_suppression_sptr result;
 
-  if (section.get_name() != "suppress_file")
-    return result;
-
   static const char *const sufficient_props[] = {
     "file_name_regexp",
     "file_name_not_regexp",