[applied] comparison: Factorize the code that inserts diff nodes to the graph

Message ID 87v8wphe64.fsf@redhat.com
State New
Headers
Series [applied] comparison: Factorize the code that inserts diff nodes to the graph |

Commit Message

Dodji Seketeli March 7, 2022, 5:21 p.m. UTC
  Hello,

During the traversal of the graph of diff nodes, diff::traverse does
two things:

    1/ If the generic view of the diff node of is not yet connected to
    the diff graph, then connect it.  Note that the typed view of the
    diff node is always connected to the diff graph.

    2/ Visit the diff node using its generic view and visit its
    children nodes.

Looking at the part 1/, I realized that the code connecting the
generic view of the diff node to the diff graph was duplicated in
every single type of diff node.

This patch put that code into diff::finish_diff_type and makes all the
different kinds diff node use that (virtual) member function,
effectively factorizing that code.

	* include/abg-comparison.h ({distinct, var, pointer, reference,
	array, qualified_type, enum, class_or_union, class, union, base,
	scope, fn_parm, function_type, function_decl, type_decl,
	typedef}_diff::finish_diff_type): Remove these declarations.
	* src/abg-comparison.cc ({distinct, var, pointer, reference,
	array, qualified_type, enum, class_or_union, class, union, base,
	scope, fn_parm, function_type, function_decl, type_decl,
	typedef}_diff::finish_diff_type): Remove these definitions.
	(diff::finish_diff_type): Add the code to connect the children
	nodes to the current node, making the generic view of the diff
	node usable to walk the graph.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 include/abg-comparison.h |  51 ------------
 src/abg-comparison.cc    | 170 +--------------------------------------
 2 files changed, 4 insertions(+), 217 deletions(-)
  

Patch

diff --git a/include/abg-comparison.h b/include/abg-comparison.h
index 595528a5..78e4102e 100644
--- a/include/abg-comparison.h
+++ b/include/abg-comparison.h
@@ -1163,9 +1163,6 @@  protected:
 		type_or_decl_base_sptr second,
 		diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
 
   const type_or_decl_base_sptr
@@ -1219,9 +1216,6 @@  protected:
 	   diff_sptr type_diff,
 	   diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   var_decl_sptr
   first_var() const;
@@ -1273,9 +1267,6 @@  protected:
 	       diff_sptr		underlying_type_diff,
 	       diff_context_sptr	ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   const pointer_type_def_sptr
   first_pointer() const;
@@ -1333,9 +1324,6 @@  protected:
 		 diff_sptr			underlying,
 		 diff_context_sptr		ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   reference_type_def_sptr
   first_reference() const;
@@ -1393,9 +1381,6 @@  protected:
 	     diff_sptr			element_type_diff,
 	     diff_context_sptr		ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   const array_type_def_sptr
   first_array() const;
@@ -1450,9 +1435,6 @@  protected:
 		      diff_sptr		underling,
 		      diff_context_sptr	ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   const qualified_type_def_sptr
   first_qualified_type() const;
@@ -1519,9 +1501,6 @@  protected:
 	    const diff_sptr,
 	    diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   const enum_type_decl_sptr
   first_enum() const;
@@ -1592,9 +1571,6 @@  protected:
 		      class_or_union_sptr second_scope,
 		      diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
 
   const class_or_union_diff::priv_ptr&
@@ -1714,9 +1690,6 @@  protected:
 	     class_decl_sptr second_scope,
 	     diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   //TODO: add change of the name of the type.
 
@@ -1793,9 +1766,6 @@  protected:
 	     union_decl_sptr second_union,
 	     diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
 
   virtual ~union_diff();
@@ -1835,9 +1805,6 @@  protected:
 	    class_diff_sptr		underlying,
 	    diff_context_sptr		ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   class_decl::base_spec_sptr
   first_base() const;
@@ -1902,9 +1869,6 @@  protected:
 	     scope_decl_sptr second_scope,
 	     diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
 
   friend scope_diff_sptr
@@ -1996,9 +1960,6 @@  class fn_parm_diff : public decl_diff_base
   struct priv;
   std::unique_ptr<priv> priv_;
 
-  virtual void
-  finish_diff_type();
-
   fn_parm_diff(const function_decl::parameter_sptr	first,
 	       const function_decl::parameter_sptr	second,
 	       diff_context_sptr			ctxt);
@@ -2065,9 +2026,6 @@  protected:
 		     const function_type_sptr	second,
 		     diff_context_sptr		ctxt);
 
-  virtual void
-  finish_diff_type();
-
 public:
   friend function_type_diff_sptr
   compute_diff(const function_type_sptr	first,
@@ -2137,9 +2095,6 @@  protected:
 		     const function_decl_sptr	second,
 		     diff_context_sptr		ctxt);
 
-  virtual void
-  finish_diff_type();
-
 public:
 
 friend function_decl_diff_sptr
@@ -2192,9 +2147,6 @@  protected:
 		 const type_decl_sptr second,
 		 diff_context_sptr ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   friend type_decl_diff_sptr
   compute_diff(const type_decl_sptr	first,
@@ -2244,9 +2196,6 @@  protected:
 	       const diff_sptr		underlying_type_diff,
 	       diff_context_sptr	ctxt = diff_context_sptr());
 
-  virtual void
-  finish_diff_type();
-
 public:
   friend typedef_diff_sptr
   compute_diff(const typedef_decl_sptr	first,
diff --git a/src/abg-comparison.cc b/src/abg-comparison.cc
index cc5b9f6d..5e61ba50 100644
--- a/src/abg-comparison.cc
+++ b/src/abg-comparison.cc
@@ -1930,6 +1930,10 @@  diff::end_traversing()
 void
 diff::finish_diff_type()
 {
+  if (diff::priv_->finished_)
+    return;
+  chain_into_hierarchy();
+  diff::priv_->finished_ = true;
 }
 
 /// Getter of the first subject of the diff.
@@ -2544,17 +2548,6 @@  distinct_diff::distinct_diff(type_or_decl_base_sptr first,
     priv_(new priv)
 {ABG_ASSERT(entities_are_of_distinct_kinds(first, second));}
 
-/// Finish building the current instance of @ref distinct_diff.
-void
-distinct_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first subject of the diff.
 ///
 /// @return the first subject of the diff.
@@ -3247,16 +3240,6 @@  var_diff::var_diff(var_decl_sptr	first,
     priv_(new priv)
 {priv_->type_diff_ = type_diff;}
 
-/// Finish building the current instance of @ref var_diff.
-void
-var_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first @ref var_decl of the diff.
 ///
 /// @return the first @ref var_decl of the diff.
@@ -3376,16 +3359,6 @@  pointer_diff::pointer_diff(pointer_type_def_sptr	first,
     priv_(new priv(underlying))
 {}
 
-/// Finish building the current instance of @ref pointer_diff.
-void
-pointer_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first subject of a pointer diff
 ///
 /// @return the first pointer considered in this pointer diff.
@@ -3526,16 +3499,6 @@  array_diff::array_diff(const array_type_def_sptr	first,
     priv_(new priv(element_type_diff))
 {}
 
-/// Finish building the current instance of @ref array_diff.
-void
-array_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first array of the diff.
 ///
 /// @return the first array of the diff.
@@ -3687,16 +3650,6 @@  reference_diff::reference_diff(const reference_type_def_sptr	first,
 	priv_(new priv(underlying))
 {}
 
-/// Finish building the current instance of @ref reference_diff.
-void
-reference_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first reference of the diff.
 ///
 /// @return the first reference of the diff.
@@ -3832,16 +3785,6 @@  qualified_type_diff::qualified_type_diff(qualified_type_def_sptr	first,
     priv_(new priv(under))
 {}
 
-/// Finish building the current instance of @ref qualified_type_diff.
-void
-qualified_type_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first qualified type of the diff.
 ///
 /// @return the first qualified type of the diff.
@@ -4075,16 +4018,6 @@  enum_diff::enum_diff(const enum_type_decl_sptr	first,
     priv_(new priv(underlying_type_diff))
 {}
 
-/// Finish building the current instance of @ref enum_diff.
-void
-enum_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// @return the first enum of the diff.
 const enum_type_decl_sptr
 enum_diff::first_enum() const
@@ -4937,16 +4870,6 @@  class_or_union_diff::class_or_union_diff(class_or_union_sptr first_scope,
     //priv_(new priv)
 {}
 
-/// Finish building the current instance of @ref class_or_union_diff.
-void
-class_or_union_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter of the private data of the @ref class_or_union_diff type.
 ///
 /// Note that due to an optimization, the private data of @ref
@@ -5552,16 +5475,6 @@  class_diff::get_priv() const
   return canonical->priv_;
 }
 
-/// Finish building the current instance of @ref class_diff.
-void
-class_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// @return the pretty representation of the current instance of @ref
 /// class_diff.
 const string&
@@ -5800,17 +5713,6 @@  base_diff::base_diff(class_decl::base_spec_sptr first,
     priv_(new priv(underlying))
 {}
 
-/// Finish building the current instance of @ref base_diff.
-void
-base_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first base spec of the diff object.
 ///
 /// @return the first base specifier for the diff object.
@@ -5975,11 +5877,6 @@  union_diff::union_diff(union_decl_sptr first_union,
   : class_or_union_diff(first_union, second_union, ctxt)
 {}
 
-/// Finish building the current instance of @ref union_diff.
-void
-union_diff::finish_diff_type()
-{class_or_union_diff::finish_diff_type();}
-
 /// Destructor of the union_diff node.
 union_diff::~union_diff()
 {}
@@ -6319,16 +6216,6 @@  scope_diff::scope_diff(scope_decl_sptr first_scope,
     priv_(new priv)
 {}
 
-/// Finish building the current instance of @ref scope_diff.
-void
-scope_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first scope of the diff.
 ///
 /// @return the first scope of the diff.
@@ -6622,16 +6509,6 @@  fn_parm_diff::fn_parm_diff(const function_decl::parameter_sptr	first,
   ABG_ASSERT(priv_->type_diff);
 }
 
-/// Finish the building of the current instance of @ref fn_parm_diff.
-void
-fn_parm_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first subject of this diff node.
 ///
 /// @return the first function_decl::parameter_sptr subject of this
@@ -6893,16 +6770,6 @@  function_type_diff::function_type_diff(const function_type_sptr first,
     priv_(new priv)
 {}
 
-/// Finish building the current instance of @ref function_type_diff
-void
-function_type_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first subject of the diff.
 ///
 /// @return the first function type involved in the diff.
@@ -7109,16 +6976,6 @@  function_decl_diff::function_decl_diff(const function_decl_sptr first,
 {
 }
 
-/// Finish building the current instance of @ref function_decl_diff.
-void
-function_decl_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// @return the first function considered by the diff.
 const function_decl_sptr
 function_decl_diff::first_function_decl() const
@@ -7242,15 +7099,6 @@  type_decl_diff::type_decl_diff(const type_decl_sptr first,
   : type_diff_base(first, second, ctxt)
 {}
 
-/// Finish building the current instance of @ref type_decl_diff.
-void
-type_decl_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the first subject of the type_decl_diff.
 ///
 /// @return the first type_decl involved in the diff.
@@ -7390,16 +7238,6 @@  typedef_diff::typedef_diff(const typedef_decl_sptr	first,
     priv_(new priv(underlying))
 {}
 
-/// Finish building the current instance of @ref typedef_diff.
-void
-typedef_diff::finish_diff_type()
-{
-  if (diff::priv_->finished_)
-    return;
-  chain_into_hierarchy();
-  diff::priv_->finished_ = true;
-}
-
 /// Getter for the firt typedef_decl involved in the diff.
 ///
 /// @return the first subject of the diff.