summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@redhat.com>2022-03-07 17:29:13 +0100
committerDodji Seketeli <dodji@redhat.com>2022-03-07 18:12:10 +0100
commit591a0f9e3e3a7e24023f3f6015cbaeb0b94f102e (patch)
tree85a059efc51a553d424d1c02ae03ac628e23ca9e
parentcomparison: Describe the "generic view" of a diff node (diff)
downloadlibabigail-591a0f9e3e3a7e24023f3f6015cbaeb0b94f102e.tar.gz
libabigail-591a0f9e3e3a7e24023f3f6015cbaeb0b94f102e.tar.bz2
libabigail-591a0f9e3e3a7e24023f3f6015cbaeb0b94f102e.tar.xz
comparison: Factorize the code that inserts diff nodes to the graph
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>
-rw-r--r--include/abg-comparison.h51
-rw-r--r--src/abg-comparison.cc170
2 files changed, 4 insertions, 217 deletions
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:
1163 type_or_decl_base_sptr second, 1163 type_or_decl_base_sptr second,
1164 diff_context_sptr ctxt = diff_context_sptr()); 1164 diff_context_sptr ctxt = diff_context_sptr());
1165 1165
1166 virtual void
1167 finish_diff_type();
1168
1169public: 1166public:
1170 1167
1171 const type_or_decl_base_sptr 1168 const type_or_decl_base_sptr
@@ -1219,9 +1216,6 @@ protected:
1219 diff_sptr type_diff, 1216 diff_sptr type_diff,
1220 diff_context_sptr ctxt = diff_context_sptr()); 1217 diff_context_sptr ctxt = diff_context_sptr());
1221 1218
1222 virtual void
1223 finish_diff_type();
1224
1225public: 1219public:
1226 var_decl_sptr 1220 var_decl_sptr
1227 first_var() const; 1221 first_var() const;
@@ -1273,9 +1267,6 @@ protected:
1273 diff_sptr underlying_type_diff, 1267 diff_sptr underlying_type_diff,
1274 diff_context_sptr ctxt = diff_context_sptr()); 1268 diff_context_sptr ctxt = diff_context_sptr());
1275 1269
1276 virtual void
1277 finish_diff_type();
1278
1279public: 1270public:
1280 const pointer_type_def_sptr 1271 const pointer_type_def_sptr
1281 first_pointer() const; 1272 first_pointer() const;
@@ -1333,9 +1324,6 @@ protected:
1333 diff_sptr underlying, 1324 diff_sptr underlying,
1334 diff_context_sptr ctxt = diff_context_sptr()); 1325 diff_context_sptr ctxt = diff_context_sptr());
1335 1326
1336 virtual void
1337 finish_diff_type();
1338
1339public: 1327public:
1340 reference_type_def_sptr 1328 reference_type_def_sptr
1341 first_reference() const; 1329 first_reference() const;
@@ -1393,9 +1381,6 @@ protected:
1393 diff_sptr element_type_diff, 1381 diff_sptr element_type_diff,
1394 diff_context_sptr ctxt = diff_context_sptr()); 1382 diff_context_sptr ctxt = diff_context_sptr());
1395 1383
1396 virtual void
1397 finish_diff_type();
1398
1399public: 1384public:
1400 const array_type_def_sptr 1385 const array_type_def_sptr
1401 first_array() const; 1386 first_array() const;
@@ -1450,9 +1435,6 @@ protected:
1450 diff_sptr underling, 1435 diff_sptr underling,
1451 diff_context_sptr ctxt = diff_context_sptr()); 1436 diff_context_sptr ctxt = diff_context_sptr());
1452 1437
1453 virtual void
1454 finish_diff_type();
1455
1456public: 1438public:
1457 const qualified_type_def_sptr 1439 const qualified_type_def_sptr
1458 first_qualified_type() const; 1440 first_qualified_type() const;
@@ -1519,9 +1501,6 @@ protected:
1519 const diff_sptr, 1501 const diff_sptr,
1520 diff_context_sptr ctxt = diff_context_sptr()); 1502 diff_context_sptr ctxt = diff_context_sptr());
1521 1503
1522 virtual void
1523 finish_diff_type();
1524
1525public: 1504public:
1526 const enum_type_decl_sptr 1505 const enum_type_decl_sptr
1527 first_enum() const; 1506 first_enum() const;
@@ -1592,9 +1571,6 @@ protected:
1592 class_or_union_sptr second_scope, 1571 class_or_union_sptr second_scope,
1593 diff_context_sptr ctxt = diff_context_sptr()); 1572 diff_context_sptr ctxt = diff_context_sptr());
1594 1573
1595 virtual void
1596 finish_diff_type();
1597
1598public: 1574public:
1599 1575
1600 const class_or_union_diff::priv_ptr& 1576 const class_or_union_diff::priv_ptr&
@@ -1714,9 +1690,6 @@ protected:
1714 class_decl_sptr second_scope, 1690 class_decl_sptr second_scope,
1715 diff_context_sptr ctxt = diff_context_sptr()); 1691 diff_context_sptr ctxt = diff_context_sptr());
1716 1692
1717 virtual void
1718 finish_diff_type();
1719
1720public: 1693public:
1721 //TODO: add change of the name of the type. 1694 //TODO: add change of the name of the type.
1722 1695
@@ -1793,9 +1766,6 @@ protected:
1793 union_decl_sptr second_union, 1766 union_decl_sptr second_union,
1794 diff_context_sptr ctxt = diff_context_sptr()); 1767 diff_context_sptr ctxt = diff_context_sptr());
1795 1768
1796 virtual void
1797 finish_diff_type();
1798
1799public: 1769public:
1800 1770
1801 virtual ~union_diff(); 1771 virtual ~union_diff();
@@ -1835,9 +1805,6 @@ protected:
1835 class_diff_sptr underlying, 1805 class_diff_sptr underlying,
1836 diff_context_sptr ctxt = diff_context_sptr()); 1806 diff_context_sptr ctxt = diff_context_sptr());
1837 1807
1838 virtual void
1839 finish_diff_type();
1840
1841public: 1808public:
1842 class_decl::base_spec_sptr 1809 class_decl::base_spec_sptr
1843 first_base() const; 1810 first_base() const;
@@ -1902,9 +1869,6 @@ protected:
1902 scope_decl_sptr second_scope, 1869 scope_decl_sptr second_scope,
1903 diff_context_sptr ctxt = diff_context_sptr()); 1870 diff_context_sptr ctxt = diff_context_sptr());
1904 1871
1905 virtual void
1906 finish_diff_type();
1907
1908public: 1872public:
1909 1873
1910 friend scope_diff_sptr 1874 friend scope_diff_sptr
@@ -1996,9 +1960,6 @@ class fn_parm_diff : public decl_diff_base
1996 struct priv; 1960 struct priv;
1997 std::unique_ptr<priv> priv_; 1961 std::unique_ptr<priv> priv_;
1998 1962
1999 virtual void
2000 finish_diff_type();
2001
2002 fn_parm_diff(const function_decl::parameter_sptr first, 1963 fn_parm_diff(const function_decl::parameter_sptr first,
2003 const function_decl::parameter_sptr second, 1964 const function_decl::parameter_sptr second,
2004 diff_context_sptr ctxt); 1965 diff_context_sptr ctxt);
@@ -2065,9 +2026,6 @@ protected:
2065 const function_type_sptr second, 2026 const function_type_sptr second,
2066 diff_context_sptr ctxt); 2027 diff_context_sptr ctxt);
2067 2028
2068 virtual void
2069 finish_diff_type();
2070
2071public: 2029public:
2072 friend function_type_diff_sptr 2030 friend function_type_diff_sptr
2073 compute_diff(const function_type_sptr first, 2031 compute_diff(const function_type_sptr first,
@@ -2137,9 +2095,6 @@ protected:
2137 const function_decl_sptr second, 2095 const function_decl_sptr second,
2138 diff_context_sptr ctxt); 2096 diff_context_sptr ctxt);
2139 2097
2140 virtual void
2141 finish_diff_type();
2142
2143public: 2098public:
2144 2099
2145friend function_decl_diff_sptr 2100friend function_decl_diff_sptr
@@ -2192,9 +2147,6 @@ protected:
2192 const type_decl_sptr second, 2147 const type_decl_sptr second,
2193 diff_context_sptr ctxt = diff_context_sptr()); 2148 diff_context_sptr ctxt = diff_context_sptr());
2194 2149
2195 virtual void
2196 finish_diff_type();
2197
2198public: 2150public:
2199 friend type_decl_diff_sptr 2151 friend type_decl_diff_sptr
2200 compute_diff(const type_decl_sptr first, 2152 compute_diff(const type_decl_sptr first,
@@ -2244,9 +2196,6 @@ protected:
2244 const diff_sptr underlying_type_diff, 2196 const diff_sptr underlying_type_diff,
2245 diff_context_sptr ctxt = diff_context_sptr()); 2197 diff_context_sptr ctxt = diff_context_sptr());
2246 2198
2247 virtual void
2248 finish_diff_type();
2249
2250public: 2199public:
2251 friend typedef_diff_sptr 2200 friend typedef_diff_sptr
2252 compute_diff(const typedef_decl_sptr first, 2201 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()
1930void 1930void
1931diff::finish_diff_type() 1931diff::finish_diff_type()
1932{ 1932{
1933 if (diff::priv_->finished_)
1934 return;
1935 chain_into_hierarchy();
1936 diff::priv_->finished_ = true;
1933} 1937}
1934 1938
1935/// Getter of the first subject of the diff. 1939/// Getter of the first subject of the diff.
@@ -2544,17 +2548,6 @@ distinct_diff::distinct_diff(type_or_decl_base_sptr first,
2544 priv_(new priv) 2548 priv_(new priv)
2545{ABG_ASSERT(entities_are_of_distinct_kinds(first, second));} 2549{ABG_ASSERT(entities_are_of_distinct_kinds(first, second));}
2546 2550
2547/// Finish building the current instance of @ref distinct_diff.
2548void
2549distinct_diff::finish_diff_type()
2550{
2551 if (diff::priv_->finished_)
2552 return;
2553
2554 chain_into_hierarchy();
2555 diff::priv_->finished_ = true;
2556}
2557
2558/// Getter for the first subject of the diff. 2551/// Getter for the first subject of the diff.
2559/// 2552///
2560/// @return the first subject of the diff. 2553/// @return the first subject of the diff.
@@ -3247,16 +3240,6 @@ var_diff::var_diff(var_decl_sptr first,
3247 priv_(new priv) 3240 priv_(new priv)
3248{priv_->type_diff_ = type_diff;} 3241{priv_->type_diff_ = type_diff;}
3249 3242
3250/// Finish building the current instance of @ref var_diff.
3251void
3252var_diff::finish_diff_type()
3253{
3254 if (diff::priv_->finished_)
3255 return;
3256 chain_into_hierarchy();
3257 diff::priv_->finished_ = true;
3258}
3259
3260/// Getter for the first @ref var_decl of the diff. 3243/// Getter for the first @ref var_decl of the diff.
3261/// 3244///
3262/// @return the first @ref var_decl of the diff. 3245/// @return the first @ref var_decl of the diff.
@@ -3376,16 +3359,6 @@ pointer_diff::pointer_diff(pointer_type_def_sptr first,
3376 priv_(new priv(underlying)) 3359 priv_(new priv(underlying))
3377{} 3360{}
3378 3361
3379/// Finish building the current instance of @ref pointer_diff.
3380void
3381pointer_diff::finish_diff_type()
3382{
3383 if (diff::priv_->finished_)
3384 return;
3385 chain_into_hierarchy();
3386 diff::priv_->finished_ = true;
3387}
3388
3389/// Getter for the first subject of a pointer diff 3362/// Getter for the first subject of a pointer diff
3390/// 3363///
3391/// @return the first pointer considered in this pointer diff. 3364/// @return the first pointer considered in this pointer diff.
@@ -3526,16 +3499,6 @@ array_diff::array_diff(const array_type_def_sptr first,
3526 priv_(new priv(element_type_diff)) 3499 priv_(new priv(element_type_diff))
3527{} 3500{}
3528 3501
3529/// Finish building the current instance of @ref array_diff.
3530void
3531array_diff::finish_diff_type()
3532{
3533 if (diff::priv_->finished_)
3534 return;
3535 chain_into_hierarchy();
3536 diff::priv_->finished_ = true;
3537}
3538
3539/// Getter for the first array of the diff. 3502/// Getter for the first array of the diff.
3540/// 3503///
3541/// @return the first array of the diff. 3504/// @return the first array of the diff.
@@ -3687,16 +3650,6 @@ reference_diff::reference_diff(const reference_type_def_sptr first,
3687 priv_(new priv(underlying)) 3650 priv_(new priv(underlying))
3688{} 3651{}
3689 3652
3690/// Finish building the current instance of @ref reference_diff.
3691void
3692reference_diff::finish_diff_type()
3693{
3694 if (diff::priv_->finished_)
3695 return;
3696 chain_into_hierarchy();
3697 diff::priv_->finished_ = true;
3698}
3699
3700/// Getter for the first reference of the diff. 3653/// Getter for the first reference of the diff.
3701/// 3654///
3702/// @return the first reference of the diff. 3655/// @return the first reference of the diff.
@@ -3832,16 +3785,6 @@ qualified_type_diff::qualified_type_diff(qualified_type_def_sptr first,
3832 priv_(new priv(under)) 3785 priv_(new priv(under))
3833{} 3786{}
3834 3787
3835/// Finish building the current instance of @ref qualified_type_diff.
3836void
3837qualified_type_diff::finish_diff_type()
3838{
3839 if (diff::priv_->finished_)
3840 return;
3841 chain_into_hierarchy();
3842 diff::priv_->finished_ = true;
3843}
3844
3845/// Getter for the first qualified type of the diff. 3788/// Getter for the first qualified type of the diff.
3846/// 3789///
3847/// @return the first qualified type of the diff. 3790/// @return the first qualified type of the diff.
@@ -4075,16 +4018,6 @@ enum_diff::enum_diff(const enum_type_decl_sptr first,
4075 priv_(new priv(underlying_type_diff)) 4018 priv_(new priv(underlying_type_diff))
4076{} 4019{}
4077 4020
4078/// Finish building the current instance of @ref enum_diff.
4079void
4080enum_diff::finish_diff_type()
4081{
4082 if (diff::priv_->finished_)
4083 return;
4084 chain_into_hierarchy();
4085 diff::priv_->finished_ = true;
4086}
4087
4088/// @return the first enum of the diff. 4021/// @return the first enum of the diff.
4089const enum_type_decl_sptr 4022const enum_type_decl_sptr
4090enum_diff::first_enum() const 4023enum_diff::first_enum() const
@@ -4937,16 +4870,6 @@ class_or_union_diff::class_or_union_diff(class_or_union_sptr first_scope,
4937 //priv_(new priv) 4870 //priv_(new priv)
4938{} 4871{}
4939 4872
4940/// Finish building the current instance of @ref class_or_union_diff.
4941void
4942class_or_union_diff::finish_diff_type()
4943{
4944 if (diff::priv_->finished_)
4945 return;
4946 chain_into_hierarchy();
4947 diff::priv_->finished_ = true;
4948}
4949
4950/// Getter of the private data of the @ref class_or_union_diff type. 4873/// Getter of the private data of the @ref class_or_union_diff type.
4951/// 4874///
4952/// Note that due to an optimization, the private data of @ref 4875/// Note that due to an optimization, the private data of @ref
@@ -5552,16 +5475,6 @@ class_diff::get_priv() const
5552 return canonical->priv_; 5475 return canonical->priv_;
5553} 5476}
5554 5477
5555/// Finish building the current instance of @ref class_diff.
5556void
5557class_diff::finish_diff_type()
5558{
5559 if (diff::priv_->finished_)
5560 return;
5561 chain_into_hierarchy();
5562 diff::priv_->finished_ = true;
5563}
5564
5565/// @return the pretty representation of the current instance of @ref 5478/// @return the pretty representation of the current instance of @ref
5566/// class_diff. 5479/// class_diff.
5567const string& 5480const string&
@@ -5800,17 +5713,6 @@ base_diff::base_diff(class_decl::base_spec_sptr first,
5800 priv_(new priv(underlying)) 5713 priv_(new priv(underlying))
5801{} 5714{}
5802 5715
5803/// Finish building the current instance of @ref base_diff.
5804void
5805base_diff::finish_diff_type()
5806{
5807 if (diff::priv_->finished_)
5808 return;
5809
5810 chain_into_hierarchy();
5811 diff::priv_->finished_ = true;
5812}
5813
5814/// Getter for the first base spec of the diff object. 5716/// Getter for the first base spec of the diff object.
5815/// 5717///
5816/// @return the first base specifier for the diff object. 5718/// @return the first base specifier for the diff object.
@@ -5975,11 +5877,6 @@ union_diff::union_diff(union_decl_sptr first_union,
5975 : class_or_union_diff(first_union, second_union, ctxt) 5877 : class_or_union_diff(first_union, second_union, ctxt)
5976{} 5878{}
5977 5879
5978/// Finish building the current instance of @ref union_diff.
5979void
5980union_diff::finish_diff_type()
5981{class_or_union_diff::finish_diff_type();}
5982
5983/// Destructor of the union_diff node. 5880/// Destructor of the union_diff node.
5984union_diff::~union_diff() 5881union_diff::~union_diff()
5985{} 5882{}
@@ -6319,16 +6216,6 @@ scope_diff::scope_diff(scope_decl_sptr first_scope,
6319 priv_(new priv) 6216 priv_(new priv)
6320{} 6217{}
6321 6218
6322/// Finish building the current instance of @ref scope_diff.
6323void
6324scope_diff::finish_diff_type()
6325{
6326 if (diff::priv_->finished_)
6327 return;
6328 chain_into_hierarchy();
6329 diff::priv_->finished_ = true;
6330}
6331
6332/// Getter for the first scope of the diff. 6219/// Getter for the first scope of the diff.
6333/// 6220///
6334/// @return the first scope of the diff. 6221/// @return the first scope of the diff.
@@ -6622,16 +6509,6 @@ fn_parm_diff::fn_parm_diff(const function_decl::parameter_sptr first,
6622 ABG_ASSERT(priv_->type_diff); 6509 ABG_ASSERT(priv_->type_diff);
6623} 6510}
6624 6511
6625/// Finish the building of the current instance of @ref fn_parm_diff.
6626void
6627fn_parm_diff::finish_diff_type()
6628{
6629 if (diff::priv_->finished_)
6630 return;
6631 chain_into_hierarchy();
6632 diff::priv_->finished_ = true;
6633}
6634
6635/// Getter for the first subject of this diff node. 6512/// Getter for the first subject of this diff node.
6636/// 6513///
6637/// @return the first function_decl::parameter_sptr subject of this 6514/// @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,
6893 priv_(new priv) 6770 priv_(new priv)
6894{} 6771{}
6895 6772
6896/// Finish building the current instance of @ref function_type_diff
6897void
6898function_type_diff::finish_diff_type()
6899{
6900 if (diff::priv_->finished_)
6901 return;
6902 chain_into_hierarchy();
6903 diff::priv_->finished_ = true;
6904}
6905
6906/// Getter for the first subject of the diff. 6773/// Getter for the first subject of the diff.
6907/// 6774///
6908/// @return the first function type involved in the diff. 6775/// @return the first function type involved in the diff.
@@ -7109,16 +6976,6 @@ function_decl_diff::function_decl_diff(const function_decl_sptr first,
7109{ 6976{
7110} 6977}
7111 6978
7112/// Finish building the current instance of @ref function_decl_diff.
7113void
7114function_decl_diff::finish_diff_type()
7115{
7116 if (diff::priv_->finished_)
7117 return;
7118 chain_into_hierarchy();
7119 diff::priv_->finished_ = true;
7120}
7121
7122/// @return the first function considered by the diff. 6979/// @return the first function considered by the diff.
7123const function_decl_sptr 6980const function_decl_sptr
7124function_decl_diff::first_function_decl() const 6981function_decl_diff::first_function_decl() const
@@ -7242,15 +7099,6 @@ type_decl_diff::type_decl_diff(const type_decl_sptr first,
7242 : type_diff_base(first, second, ctxt) 7099 : type_diff_base(first, second, ctxt)
7243{} 7100{}
7244 7101
7245/// Finish building the current instance of @ref type_decl_diff.
7246void
7247type_decl_diff::finish_diff_type()
7248{
7249 if (diff::priv_->finished_)
7250 return;
7251 diff::priv_->finished_ = true;
7252}
7253
7254/// Getter for the first subject of the type_decl_diff. 7102/// Getter for the first subject of the type_decl_diff.
7255/// 7103///
7256/// @return the first type_decl involved in the diff. 7104/// @return the first type_decl involved in the diff.
@@ -7390,16 +7238,6 @@ typedef_diff::typedef_diff(const typedef_decl_sptr first,
7390 priv_(new priv(underlying)) 7238 priv_(new priv(underlying))
7391{} 7239{}
7392 7240
7393/// Finish building the current instance of @ref typedef_diff.
7394void
7395typedef_diff::finish_diff_type()
7396{
7397 if (diff::priv_->finished_)
7398 return;
7399 chain_into_hierarchy();
7400 diff::priv_->finished_ = true;
7401}
7402
7403/// Getter for the firt typedef_decl involved in the diff. 7241/// Getter for the firt typedef_decl involved in the diff.
7404/// 7242///
7405/// @return the first subject of the diff. 7243/// @return the first subject of the diff.