diff mbox series

[12/21] Reduce direct access to suppression priv_ members.

Message ID 20200423154441.170531-13-gprocida@google.com
State Superseded
Headers show
Series Simplify regex and suppression parsing. | expand

Commit Message

Giuliano Procida April 23, 2020, 3:44 p.m. UTC
Most suppression type functionality is available on the types
themselves via methods, particularly now that there are getters
for all the regex members.

This patch eliminates lots of accesses via priv_ members.

There are no behavioural changes.

	* src/abg-suppression.cc (sonames_of_binaries_match): Use
	suppression_matches_soname helper function.
	(suppression_matches_type_name): Use type_suppression regex getters.
	(suppression_matches_type_location): Use type_suppression
	regex getters.
	(function::suppression::suppresses_function): Use own regex
	getters.
	(function::suppression::suppresses_function_symbol): Use own
	regex getters.
	(suppression_matches_function_name): Use function_suppression
	regex and name getters.
	(suppression_matches_function_sym_name): Use function_suppression
	regex and symbol name getters.
	(suppression_matches_variable_name): Use variable__suppression
	regex and name getters.
	(suppression_matches_variable_sym_name): Use variable_suppression
	regex and symbol name getters.
	(suppression_matches_type): Use type_suppression
	regex getter.
	(variable_suppression::suppresses_variable): Use own regex
	getters.
	(variable_suppression::suppresses_variable_symbol): Use own
	regex getters.
	(type_suppression::suppresses_file): Use own regex getters.
	(suppression_matches_soname_or_filename): Indentation fix, en
	passant.

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

Patch

diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc
index 5082536d..f6710b71 100644
--- a/src/abg-suppression.cc
+++ b/src/abg-suppression.cc
@@ -279,8 +279,8 @@  sonames_of_binaries_match(const suppression_base& suppr,
   if (!suppr.has_soname_related_property())
     return false;
 
-  if (!suppr.priv_->matches_soname(first_soname)
-      && !suppr.priv_->matches_soname(second_soname))
+  if (!suppression_matches_soname(first_soname, suppr)
+      && !suppression_matches_soname(second_soname, suppr))
     return false;
 
   return true;
@@ -973,8 +973,8 @@  suppression_matches_type_name(const type_suppression&	s,
 			      const string&		type_name)
 {
   if (!s.get_type_name().empty()
-      || s.priv_->get_type_name_regex()
-      || s.priv_->get_type_name_not_regex())
+      || s.get_type_name_regex()
+      || s.get_type_name_not_regex())
     {
       // Check if there is an exact type name match.
       if (!s.get_type_name().empty())
@@ -990,14 +990,14 @@  suppression_matches_type_name(const type_suppression&	s,
 	  // the regular expression of the type name, then this
 	  // suppression doesn't apply.
 	  if (const regex_t_sptr& type_name_regex =
-	      s.priv_->get_type_name_regex())
+	      s.get_type_name_regex())
 	    {
 	      if (!regex::match(type_name_regex, type_name))
 		return false;
 	    }
 
 	  if (const regex_t_sptr type_name_not_regex =
-	      s.priv_->get_type_name_not_regex())
+	      s.get_type_name_not_regex())
 	    {
 	      if (regex::match(type_name_not_regex, type_name))
 		return false;
@@ -1045,7 +1045,7 @@  suppression_matches_type_location(const type_suppression&	s,
       unsigned loc_line = 0, loc_column = 0;
       loc.expand(loc_path, loc_line, loc_column);
 
-      if (regex_t_sptr regexp = s.priv_->get_source_location_to_keep_regex())
+      if (regex_t_sptr regexp = s.get_source_location_to_keep_regex())
 	if (regex::match(regexp, loc_path))
 	  return false;
 
@@ -1060,7 +1060,7 @@  suppression_matches_type_location(const type_suppression&	s,
   else
     {
       if (!s.get_source_locations_to_keep().empty()
-	  || s.priv_->get_source_location_to_keep_regex())
+	  || s.get_source_location_to_keep_regex())
 	// The user provided a "source_location_not_regexp" or
 	// a "source_location_not_in" property that was not
 	// triggered.  This means the current type suppression
@@ -1111,7 +1111,7 @@  suppression_matches_type_location(const type_suppression&	s,
 	    }
 	}
       if (!s.get_source_locations_to_keep().empty()
-	  || s.priv_->get_source_location_to_keep_regex())
+	  || s.get_source_location_to_keep_regex())
 	// The user provided a "source_location_not_regexp" or
 	// a "source_location_not_in" property that was not
 	// triggered.  This means the current type suppression
@@ -2485,7 +2485,7 @@  function_suppression::suppresses_function(const function_decl* fn,
     }
 
   // check if the "name_regexp" property matches.
-  const regex_t_sptr name_regex = priv_->get_name_regex();
+  const regex_t_sptr name_regex = get_name_regex();
   if (name_regex)
     {
       if (!regex::match(name_regex, fname))
@@ -2516,7 +2516,7 @@  function_suppression::suppresses_function(const function_decl* fn,
     }
 
   // check if the "name_not_regexp" property matches.
-  const regex_t_sptr name_not_regex = priv_->get_name_not_regex();
+  const regex_t_sptr name_not_regex = get_name_not_regex();
   if (name_not_regex)
     {
       if (regex::match(name_not_regex, fname))
@@ -2562,7 +2562,7 @@  function_suppression::suppresses_function(const function_decl* fn,
     }
   else
     {
-      const regex_t_sptr return_type_regex = priv_->get_return_type_regex();
+      const regex_t_sptr return_type_regex = get_return_type_regex();
       if (return_type_regex
 	  && !regex::match(return_type_regex, fn_return_type_name))
 	return false;
@@ -2600,12 +2600,11 @@  function_suppression::suppresses_function(const function_decl* fn,
     }
   else if (sym)
     {
-      const regex_t_sptr symbol_name_regex = priv_->get_symbol_name_regex();
+      const regex_t_sptr symbol_name_regex = get_symbol_name_regex();
       if (symbol_name_regex && !regex::match(symbol_name_regex, fn_sym_name))
 	return false;
 
-      const regex_t_sptr symbol_name_not_regex =
-	priv_->get_symbol_name_not_regex();
+      const regex_t_sptr symbol_name_not_regex = get_symbol_name_not_regex();
       if (symbol_name_not_regex
 	  && regex::match(symbol_name_not_regex, fn_sym_name))
 	return false;
@@ -2642,8 +2641,7 @@  function_suppression::suppresses_function(const function_decl* fn,
     }
   else if (sym)
     {
-      const regex_t_sptr symbol_version_regex =
-	priv_->get_symbol_version_regex();
+      const regex_t_sptr symbol_version_regex = get_symbol_version_regex();
       if (symbol_version_regex
 	  && !regex::match(symbol_version_regex, fn_sym_version))
 	return false;
@@ -2683,7 +2681,7 @@  function_suppression::suppresses_function(const function_decl* fn,
 	  else
 	    {
 	      const regex_t_sptr parm_type_name_regex =
-		(*p)->priv_->get_type_name_regex();
+		(*p)->get_parameter_type_name_regex();
 	      if (parm_type_name_regex)
 		{
 		  if (!regex::match(parm_type_name_regex,
@@ -2774,7 +2772,7 @@  function_suppression::suppresses_function_symbol(const elf_symbol* sym,
     }
   else if (get_symbol_name_regex())
     {
-      const regex_t_sptr symbol_name_regex = priv_->get_symbol_name_regex();
+      const regex_t_sptr symbol_name_regex = get_symbol_name_regex();
       if (symbol_name_regex && !regex::match(symbol_name_regex, sym_name))
 	return false;
     }
@@ -2789,8 +2787,7 @@  function_suppression::suppresses_function_symbol(const elf_symbol* sym,
     }
   else if (get_symbol_version_regex())
     {
-      const regex_t_sptr symbol_version_regex =
-	priv_->get_symbol_version_regex();
+      const regex_t_sptr symbol_version_regex = get_symbol_version_regex();
       if (symbol_version_regex
 	  && !regex::match(symbol_version_regex, sym_version))
 	return false;
@@ -2882,21 +2879,21 @@  bool
 suppression_matches_function_name(const suppr::function_suppression& s,
 				  const string& fn_name)
 {
-  if (regex_t_sptr regexp = s.priv_->get_name_regex())
+  if (regex_t_sptr regexp = s.get_name_regex())
     {
       if (!regex::match(regexp, fn_name))
 	return false;
     }
-  else if (regex_t_sptr regexp = s.priv_->get_name_not_regex())
+  else if (regex_t_sptr regexp = s.get_name_not_regex())
     {
       if (regex::match(regexp, fn_name))
 	return false;
     }
-  else if (s.priv_->name_.empty())
+  else if (s.get_name().empty())
     return false;
-  else // if (!s.priv_->name_.empty())
+  else // if (!s.get_name().empty())
     {
-      if (s.priv_->name_ != fn_name)
+      if (s.get_name() != fn_name)
 	return false;
     }
 
@@ -2918,21 +2915,21 @@  bool
 suppression_matches_function_sym_name(const suppr::function_suppression& s,
 				      const string& fn_linkage_name)
 {
-  if (regex_t_sptr regexp = s.priv_->get_symbol_name_regex())
+  if (regex_t_sptr regexp = s.get_symbol_name_regex())
     {
       if (!regex::match(regexp, fn_linkage_name))
 	return false;
     }
-  else if (regex_t_sptr regexp = s.priv_->get_symbol_name_not_regex())
+  else if (regex_t_sptr regexp = s.get_symbol_name_not_regex())
     {
       if (regex::match(regexp, fn_linkage_name))
 	return false;
     }
-  else if (s.priv_->symbol_name_.empty())
+  else if (s.get_symbol_name().empty())
     return false;
-  else // if (!s.priv_->symbol_name_.empty())
+  else // if (!s.get_symbol_name().empty())
     {
-      if (s.priv_->symbol_name_ != fn_linkage_name)
+      if (s.get_symbol_name() != fn_linkage_name)
 	return false;
     }
 
@@ -2951,21 +2948,21 @@  bool
 suppression_matches_variable_name(const suppr::variable_suppression& s,
 				  const string& var_name)
 {
-  if (regex_t_sptr regexp = s.priv_->get_name_regex())
+  if (regex_t_sptr regexp = s.get_name_regex())
     {
       if (!regex::match(regexp, var_name))
 	return false;
     }
-  else if (regex_t_sptr regexp = s.priv_->get_name_not_regex())
+  else if (regex_t_sptr regexp = s.get_name_not_regex())
     {
       if (regex::match(regexp, var_name))
 	return false;
     }
-  else if (s.priv_->name_.empty())
+  else if (s.get_name().empty())
     return false;
-  else // if (!s.priv_->name_.empty())
+  else // if (!s.get_name().empty())
     {
-      if (s.priv_->name_ != var_name)
+      if (s.get_name() != var_name)
 	return false;
     }
 
@@ -2985,22 +2982,21 @@  bool
 suppression_matches_variable_sym_name(const suppr::variable_suppression& s,
 				      const string& var_linkage_name)
 {
-  if (regex_t_sptr regexp = s.priv_->get_symbol_name_regex())
+  if (regex_t_sptr regexp = s.get_symbol_name_regex())
     {
       if (!regex::match(regexp, var_linkage_name))
 	return false;
     }
-  else if (regex_t_sptr regexp =
-	   s.priv_->get_symbol_name_not_regex())
+  else if (regex_t_sptr regexp = s.get_symbol_name_not_regex())
     {
       if (regex::match(regexp, var_linkage_name))
 	return false;
     }
-  else if (s.priv_->symbol_name_.empty())
+  else if (s.get_symbol_name().empty())
     return false;
-  else // if (!s.priv_->symbol_name_.empty())
+  else // if (!s.get_symbol_name().empty())
     {
-      if (s.priv_->symbol_name_ != var_linkage_name)
+      if (s.get_symbol_name() != var_linkage_name)
 	return false;
     }
 
@@ -3020,7 +3016,7 @@  bool
 suppression_matches_type(const suppr::type_suppression& s,
 			 const string& type_name)
 {
-  if (regex_t_sptr regexp = s.priv_->get_type_name_regex())
+  if (regex_t_sptr regexp = s.get_type_name_regex())
     {
       if (!regex::match(regexp, type_name))
 	return false;
@@ -3729,11 +3725,11 @@  variable_suppression::suppresses_variable(const var_decl* var,
       // "name_regex" and "name_not_regex" properties match
       if (get_name().empty())
 	{
-	  const regex_t_sptr name_regex = priv_->get_name_regex();
+	  const regex_t_sptr name_regex = get_name_regex();
 	  if (name_regex && !regex::match(name_regex, var_name))
 	    return false;
 
-	  const regex_t_sptr name_not_regex = priv_->get_name_not_regex();
+	  const regex_t_sptr name_not_regex = get_name_not_regex();
 	  if (name_not_regex && regex::match(name_not_regex, var_name))
 	    return false;
 	}
@@ -3749,12 +3745,11 @@  variable_suppression::suppresses_variable(const var_decl* var,
     }
   else
     {
-      const regex_t_sptr sym_name_regex = priv_->get_symbol_name_regex();
+      const regex_t_sptr sym_name_regex = get_symbol_name_regex();
       if (sym_name_regex && !regex::match(sym_name_regex, var_sym_name))
 	return false;
 
-      const regex_t_sptr sym_name_not_regex =
-	priv_->get_symbol_name_not_regex();
+      const regex_t_sptr sym_name_not_regex = get_symbol_name_not_regex();
       if (sym_name_not_regex && regex::match(sym_name_not_regex, var_sym_name))
 	return false;
     }
@@ -3769,8 +3764,7 @@  variable_suppression::suppresses_variable(const var_decl* var,
     }
   else
     {
-      const regex_t_sptr symbol_version_regex =
-	priv_->get_symbol_version_regex();
+      const regex_t_sptr symbol_version_regex = get_symbol_version_regex();
       if (symbol_version_regex
 	  && !regex::match(symbol_version_regex, var_sym_version))
 	return false;
@@ -3789,7 +3783,7 @@  variable_suppression::suppresses_variable(const var_decl* var,
     {
       if (get_type_name().empty())
 	{
-	  const regex_t_sptr type_name_regex = priv_->get_type_name_regex();
+	  const regex_t_sptr type_name_regex = get_type_name_regex();
 	  if (type_name_regex && !regex::match(type_name_regex, var_type_name))
 	    return false;
 	}
@@ -3880,7 +3874,7 @@  variable_suppression::suppresses_variable_symbol(const elf_symbol* sym,
     }
   else if (get_symbol_name_regex())
     {
-      const regex_t_sptr sym_name_regex = priv_->get_symbol_name_regex();
+      const regex_t_sptr sym_name_regex = get_symbol_name_regex();
       if (sym_name_regex && !regex::match(sym_name_regex, sym_name))
 	return false;
     }
@@ -3896,8 +3890,7 @@  variable_suppression::suppresses_variable_symbol(const elf_symbol* sym,
     }
   else if (get_symbol_version_regex())
     {
-      const regex_t_sptr symbol_version_regex =
-	priv_->get_symbol_version_regex();
+      const regex_t_sptr symbol_version_regex = get_symbol_version_regex();
       if (symbol_version_regex
 	  && !regex::match(symbol_version_regex, sym_version))
 	return false;
@@ -4200,14 +4193,14 @@  file_suppression::suppresses_file(const string& file_path)
 
   bool has_regexp = false;
 
-  if (regex_t_sptr regexp = suppression_base::priv_->get_file_name_regex())
+  if (regex_t_sptr regexp = get_file_name_regex())
     {
       has_regexp = true;
       if (!regex::match(regexp, fname))
 	return false;
     }
 
-  if (regex_t_sptr regexp = suppression_base::priv_->get_file_name_not_regex())
+  if (regex_t_sptr regexp = get_file_name_not_regex())
     {
       has_regexp = true;
       if (regex::match(regexp, fname))
@@ -4361,7 +4354,7 @@  suppression_matches_soname_or_filename(const string& soname,
 				       const suppression_base& suppr)
 {
   return (suppression_matches_soname(soname, suppr)
-	 || suppr.priv_->matches_binary_name(filename));
+	  || suppr.priv_->matches_binary_name(filename));
 }
 
 /// @return the name of the artificial private type suppression