From f54db47233000079cf93edba9e033085e40ea24c Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:12:09 +0100 Subject: [PATCH 01/10] Rename differences map data member --- src/goto-diff/unified_diff.cpp | 10 +++++----- src/goto-diff/unified_diff.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index 75924bfca5d..ccdfb2d8dc4 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -33,8 +33,8 @@ void unified_difft::get_diff( dest.clear(); differences_mapt::const_iterator entry= - differences_map.find(function); - if(entry==differences_map.end()) + differences_map_.find(function); + if(entry==differences_map_.end()) return; goto_functionst::function_mapt::const_iterator old_fit= @@ -304,7 +304,7 @@ void unified_difft::unified_diff( const goto_programt &old_goto_program, const goto_programt &new_goto_program) { - differencest &differences=differences_map[identifier]; + differencest &differences=differences_map_[identifier]; differences.clear(); if(old_goto_program.instructions.empty() || @@ -363,14 +363,14 @@ bool unified_difft::operator()() for( ; ito!=old_funcs.end(); ++ito) unified_diff(ito->first, ito->second->second.body, empty); - return !differences_map.empty(); + return !differences_map_.empty(); } void unified_difft::output(std::ostream &os) const { goto_programt empty; - for(const std::pair &p : differences_map) + for(const std::pair &p : differences_map_) { const irep_idt &function=p.first; diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index 2ba9f09ae1c..d551bf10c59 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -62,7 +62,7 @@ class unified_difft typedef std::vector differencest; typedef std::map differences_mapt; - differences_mapt differences_map; + differences_mapt differences_map_; void unified_diff( const irep_idt &identifier, From 8c35211ca250a95001462a87147f85a8dbb5c144 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:13:22 +0100 Subject: [PATCH 02/10] Make data member private --- src/goto-diff/unified_diff.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index d551bf10c59..a24ce91c7e6 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -53,7 +53,6 @@ class unified_difft const irep_idt &function, goto_program_difft &dest) const; -protected: const goto_functionst &old_goto_functions; const namespacet ns_old; const goto_functionst &new_goto_functions; @@ -62,8 +61,6 @@ class unified_difft typedef std::vector differencest; typedef std::map differences_mapt; - differences_mapt differences_map_; - void unified_diff( const irep_idt &identifier, const goto_programt &old_goto_program, @@ -105,6 +102,9 @@ class unified_difft *ins2.get_target(), false)); } + +private: + differences_mapt differences_map_; }; #endif // CPROVER_GOTO_DIFF_UNIFIED_DIFF_H From 11c9acc515b9b541b4a5b3bc8ef8118fa5f7bd4b Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:14:27 +0100 Subject: [PATCH 03/10] Add getter for data member --- src/goto-diff/unified_diff.cpp | 5 +++++ src/goto-diff/unified_diff.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index ccdfb2d8dc4..3b3ea8260de 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -396,3 +396,8 @@ void unified_difft::output(std::ostream &os) const os); } } + +const unified_difft::differences_mapt &unified_difft::differences_map() const +{ + return differences_map_; +} diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index a24ce91c7e6..75759a28b9d 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -103,6 +103,8 @@ class unified_difft false)); } + const differences_mapt &differences_map() const; + private: differences_mapt differences_map_; }; From f815cc0074408abb9a5dff7431b2e88925baea3b Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:16:17 +0100 Subject: [PATCH 04/10] Move instructions_equal definition --- src/goto-diff/unified_diff.cpp | 19 +++++++++++++++++++ src/goto-diff/unified_diff.h | 15 +-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index 3b3ea8260de..0e9c7cb35d5 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -397,6 +397,25 @@ void unified_difft::output(std::ostream &os) const } } + +bool unified_difft::instructions_equal( + const goto_programt::instructiont &ins1, + const goto_programt::instructiont &ins2, + bool recurse) const +{ + return + ins1.code==ins2.code && + ins1.function==ins2.function && + ins1.type==ins2.type && + ins1.guard==ins2.guard && + ins1.targets.size()==ins2.targets.size() && + (ins1.targets.empty() || + instructions_equal( + *ins1.get_target(), + *ins2.get_target(), + false)); +} + const unified_difft::differences_mapt &unified_difft::differences_map() const { return differences_map_; diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index 75759a28b9d..78dfbf7bf69 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -88,20 +88,7 @@ class unified_difft bool instructions_equal( const goto_programt::instructiont &ins1, const goto_programt::instructiont &ins2, - bool recurse=true) const - { - return - ins1.code==ins2.code && - ins1.function==ins2.function && - ins1.type==ins2.type && - ins1.guard==ins2.guard && - ins1.targets.size()==ins2.targets.size() && - (ins1.targets.empty() || - instructions_equal( - *ins1.get_target(), - *ins2.get_target(), - false)); - } + bool recurse=true) const; const differences_mapt &differences_map() const; From e32c6c5433a1df7abaeeaece303610ee2b8f60ff Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:16:52 +0100 Subject: [PATCH 05/10] Make instructions_equal static --- src/goto-diff/unified_diff.cpp | 2 +- src/goto-diff/unified_diff.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index 0e9c7cb35d5..5cb584b49fc 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -401,7 +401,7 @@ void unified_difft::output(std::ostream &os) const bool unified_difft::instructions_equal( const goto_programt::instructiont &ins1, const goto_programt::instructiont &ins2, - bool recurse) const + bool recurse) { return ins1.code==ins2.code && diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index 78dfbf7bf69..39e01a97538 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -85,10 +85,10 @@ class unified_difft const differencest &differences, std::ostream &os) const; - bool instructions_equal( + static bool instructions_equal( const goto_programt::instructiont &ins1, const goto_programt::instructiont &ins2, - bool recurse=true) const; + bool recurse=true); const differences_mapt &differences_map() const; From 4555d9f0b18fffe69adb331be58c02afa353bb83 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:17:20 +0100 Subject: [PATCH 06/10] Remove unused parameter --- src/goto-diff/unified_diff.cpp | 6 ++---- src/goto-diff/unified_diff.h | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index 5cb584b49fc..ffc07405b9e 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -400,8 +400,7 @@ void unified_difft::output(std::ostream &os) const bool unified_difft::instructions_equal( const goto_programt::instructiont &ins1, - const goto_programt::instructiont &ins2, - bool recurse) + const goto_programt::instructiont &ins2) { return ins1.code==ins2.code && @@ -412,8 +411,7 @@ bool unified_difft::instructions_equal( (ins1.targets.empty() || instructions_equal( *ins1.get_target(), - *ins2.get_target(), - false)); + *ins2.get_target())); } const unified_difft::differences_mapt &unified_difft::differences_map() const diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index 39e01a97538..2aed152ff87 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -87,8 +87,7 @@ class unified_difft static bool instructions_equal( const goto_programt::instructiont &ins1, - const goto_programt::instructiont &ins2, - bool recurse=true); + const goto_programt::instructiont &ins2); const differences_mapt &differences_map() const; From 6833af641ade5fce9def6bf9639ff6dcc3f0ef80 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 25 Oct 2017 16:18:20 +0100 Subject: [PATCH 07/10] Fix formatting --- src/goto-diff/unified_diff.cpp | 276 +++++++++++++++------------------ src/goto-diff/unified_diff.h | 11 +- 2 files changed, 125 insertions(+), 162 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index ffc07405b9e..3974c8acef1 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -17,47 +17,40 @@ Date: April 2016 #include -unified_difft::unified_difft(const goto_modelt &model_old, - const goto_modelt &model_new): - old_goto_functions(model_old.goto_functions), - ns_old(model_old.symbol_table), - new_goto_functions(model_new.goto_functions), - ns_new(model_new.symbol_table) +unified_difft::unified_difft( + const goto_modelt &model_old, + const goto_modelt &model_new) + : old_goto_functions(model_old.goto_functions), + ns_old(model_old.symbol_table), + new_goto_functions(model_new.goto_functions), + ns_new(model_new.symbol_table) { } -void unified_difft::get_diff( - const irep_idt &function, - goto_program_difft &dest) const +void unified_difft::get_diff(const irep_idt &function, goto_program_difft &dest) + const { dest.clear(); - differences_mapt::const_iterator entry= - differences_map_.find(function); - if(entry==differences_map_.end()) + differences_mapt::const_iterator entry = differences_map_.find(function); + if(entry == differences_map_.end()) return; - goto_functionst::function_mapt::const_iterator old_fit= + goto_functionst::function_mapt::const_iterator old_fit = old_goto_functions.function_map.find(function); - goto_functionst::function_mapt::const_iterator new_fit= + goto_functionst::function_mapt::const_iterator new_fit = new_goto_functions.function_map.find(function); goto_programt empty; - const goto_programt &old_goto_program= - old_fit==old_goto_functions.function_map.end() ? - empty : - old_fit->second.body; - const goto_programt &new_goto_program= - new_fit==new_goto_functions.function_map.end() ? - empty : - new_fit->second.body; - - get_diff( - old_goto_program, - new_goto_program, - entry->second, - dest); + const goto_programt &old_goto_program = + old_fit == old_goto_functions.function_map.end() ? empty + : old_fit->second.body; + const goto_programt &new_goto_program = + new_fit == new_goto_functions.function_map.end() ? empty + : new_fit->second.body; + + get_diff(old_goto_program, new_goto_program, entry->second, dest); } void unified_difft::get_diff( @@ -66,34 +59,34 @@ void unified_difft::get_diff( const differencest &differences, goto_program_difft &dest) const { - goto_programt::instructionst::const_iterator old_it= + goto_programt::instructionst::const_iterator old_it = old_goto_program.instructions.begin(); - goto_programt::instructionst::const_iterator new_it= + goto_programt::instructionst::const_iterator new_it = new_goto_program.instructions.begin(); - for(differencest::const_reverse_iterator rit=differences.rbegin(); - rit!=differences.rend(); + for(differencest::const_reverse_iterator rit = differences.rbegin(); + rit != differences.rend(); ++rit) { switch(*rit) { - case differencet::SAME: - dest.push_back(std::make_pair(new_it, differencet::SAME)); - assert(old_it!=old_goto_program.instructions.end()); - ++old_it; - assert(new_it!=new_goto_program.instructions.end()); - ++new_it; - break; - case differencet::DELETED: - dest.push_back(std::make_pair(old_it, differencet::DELETED)); - assert(old_it!=old_goto_program.instructions.end()); - ++old_it; - break; - case differencet::NEW: - dest.push_back(std::make_pair(new_it, differencet::NEW)); - assert(new_it!=new_goto_program.instructions.end()); - ++new_it; - break; + case differencet::SAME: + dest.push_back(std::make_pair(new_it, differencet::SAME)); + assert(old_it != old_goto_program.instructions.end()); + ++old_it; + assert(new_it != new_goto_program.instructions.end()); + ++new_it; + break; + case differencet::DELETED: + dest.push_back(std::make_pair(old_it, differencet::DELETED)); + assert(old_it != old_goto_program.instructions.end()); + ++old_it; + break; + case differencet::NEW: + dest.push_back(std::make_pair(new_it, differencet::NEW)); + assert(new_it != new_goto_program.instructions.end()); + ++new_it; + break; } } } @@ -106,18 +99,14 @@ void unified_difft::output_diff( std::ostream &os) const { goto_program_difft diff; - get_diff( - old_goto_program, - new_goto_program, - differences, - diff); + get_diff(old_goto_program, new_goto_program, differences, diff); - bool has_diff=false; + bool has_diff = false; for(const auto &d : diff) { - if(d.second!=differencet::SAME) + if(d.second != differencet::SAME) { - has_diff=true; + has_diff = true; break; } } @@ -130,18 +119,18 @@ void unified_difft::output_diff( { switch(d.second) { - case differencet::SAME: - os << ' '; - new_goto_program.output_instruction(ns_new, identifier, os, *d.first); - break; - case differencet::DELETED: - os << '-'; - old_goto_program.output_instruction(ns_old, identifier, os, *d.first); - break; - case differencet::NEW: - os << '+'; - new_goto_program.output_instruction(ns_new, identifier, os, *d.first); - break; + case differencet::SAME: + os << ' '; + new_goto_program.output_instruction(ns_new, identifier, os, *d.first); + break; + case differencet::DELETED: + os << '-'; + old_goto_program.output_instruction(ns_old, identifier, os, *d.first); + break; + case differencet::NEW: + os << '+'; + new_goto_program.output_instruction(ns_new, identifier, os, *d.first); + break; } } } @@ -152,21 +141,20 @@ void unified_difft::lcss( const goto_programt &new_goto_program, differencest &differences) const { - std::size_t old_count=old_goto_program.instructions.size(); - std::size_t new_count=new_goto_program.instructions.size(); + std::size_t old_count = old_goto_program.instructions.size(); + std::size_t new_count = new_goto_program.instructions.size(); - differences.reserve(old_count+new_count); + differences.reserve(old_count + new_count); // skip common prefix - goto_programt::instructionst::const_iterator old_it= + goto_programt::instructionst::const_iterator old_it = old_goto_program.instructions.begin(); - goto_programt::instructionst::const_iterator new_it= + goto_programt::instructionst::const_iterator new_it = new_goto_program.instructions.begin(); - for( ; - old_it!=old_goto_program.instructions.end() && - new_it!=new_goto_program.instructions.end(); - ++old_it, ++new_it) + for(; old_it != old_goto_program.instructions.end() && + new_it != new_goto_program.instructions.end(); + ++old_it, ++new_it) { if(!instructions_equal(*old_it, *new_it)) break; @@ -178,12 +166,12 @@ void unified_difft::lcss( // differ // skip common suffix - goto_programt::instructionst::const_iterator old_rit= + goto_programt::instructionst::const_iterator old_rit = old_goto_program.instructions.end(); - goto_programt::instructionst::const_iterator new_rit= + goto_programt::instructionst::const_iterator new_rit = new_goto_program.instructions.end(); - while(old_rit!=old_it && new_rit!=new_it) + while(old_rit != old_it && new_rit != new_it) { --old_rit; --new_rit; @@ -202,38 +190,37 @@ void unified_difft::lcss( // old_rit, new_rit are now iterators to the first instructions of // the common tail - if(old_count==0 && new_count==0) + if(old_count == 0 && new_count == 0) return; // apply longest common subsequence (LCSS) - typedef std::vector > lcss_matrixt; + typedef std::vector> lcss_matrixt; lcss_matrixt lcss_matrix( - old_count+1, - std::vector(new_count+1, 0)); + old_count + 1, std::vector(new_count + 1, 0)); // fill the matrix - std::size_t i=1, j=1; - for(goto_programt::instructionst::const_iterator old_it2=old_it; - old_it2!=old_rit; + std::size_t i = 1, j = 1; + for(goto_programt::instructionst::const_iterator old_it2 = old_it; + old_it2 != old_rit; ++old_it2) { - j=1; - for(goto_programt::instructionst::const_iterator new_it2=new_it; - new_it2!=new_rit; + j = 1; + for(goto_programt::instructionst::const_iterator new_it2 = new_it; + new_it2 != new_rit; ++new_it2) { if(instructions_equal(*old_it2, *new_it2)) - lcss_matrix[i][j]+=lcss_matrix[i-1][j-1]+1; + lcss_matrix[i][j] += lcss_matrix[i - 1][j - 1] + 1; else - lcss_matrix[i][j]= - std::max(lcss_matrix[i][j-1], lcss_matrix[i-1][j]); + lcss_matrix[i][j] = + std::max(lcss_matrix[i][j - 1], lcss_matrix[i - 1][j]); ++j; } ++i; } - #if 0 +#if 0 std::cerr << "old_count=" << old_count << '\n'; std::cerr << "new_count=" << new_count << '\n'; for(i=0; i<=old_count; ++i) @@ -247,26 +234,26 @@ void unified_difft::lcss( } std::cerr << '\n'; } - #endif +#endif // backtracking // note that the order in case of multiple possible matches of // the if-clauses is important to provide a convenient ordering // of - and + lines (- goes before +) - i=old_count; - j=new_count; + i = old_count; + j = new_count; --old_rit; --new_rit; - while(i>0 || j>0) + while(i > 0 || j > 0) { - if(i==0) + if(i == 0) { differences.push_back(differencet::NEW); --j; --new_rit; } - else if(j==0) + else if(j == 0) { differences.push_back(differencet::DELETED); --i; @@ -280,7 +267,7 @@ void unified_difft::lcss( --j; --new_rit; } - else if(lcss_matrix[i][j-1] - function_mapt; + typedef std::map + function_mapt; function_mapt old_funcs, new_funcs; @@ -338,29 +323,25 @@ bool unified_difft::operator()() goto_programt empty; - function_mapt::const_iterator ito=old_funcs.begin(); - for(function_mapt::const_iterator itn=new_funcs.begin(); - itn!=new_funcs.end(); + function_mapt::const_iterator ito = old_funcs.begin(); + for(function_mapt::const_iterator itn = new_funcs.begin(); + itn != new_funcs.end(); ++itn) { - for( ; - ito!=old_funcs.end() && ito->firstfirst; - ++ito) + for(; ito != old_funcs.end() && ito->first < itn->first; ++ito) unified_diff(ito->first, ito->second->second.body, empty); - if(ito==old_funcs.end() || itn->firstfirst) + if(ito == old_funcs.end() || itn->first < ito->first) unified_diff(itn->first, empty, itn->second->second.body); else { - assert(ito->first==itn->first); + assert(ito->first == itn->first); unified_diff( - itn->first, - ito->second->second.body, - itn->second->second.body); + itn->first, ito->second->second.body, itn->second->second.body); ++ito; } } - for( ; ito!=old_funcs.end(); ++ito) + for(; ito != old_funcs.end(); ++ito) unified_diff(ito->first, ito->second->second.body, empty); return !differences_map_.empty(); @@ -372,46 +353,33 @@ void unified_difft::output(std::ostream &os) const for(const std::pair &p : differences_map_) { - const irep_idt &function=p.first; + const irep_idt &function = p.first; - goto_functionst::function_mapt::const_iterator old_fit= + goto_functionst::function_mapt::const_iterator old_fit = old_goto_functions.function_map.find(function); - goto_functionst::function_mapt::const_iterator new_fit= + goto_functionst::function_mapt::const_iterator new_fit = new_goto_functions.function_map.find(function); - const goto_programt &old_goto_program= - old_fit==old_goto_functions.function_map.end() ? - empty : - old_fit->second.body; - const goto_programt &new_goto_program= - new_fit==new_goto_functions.function_map.end() ? - empty : - new_fit->second.body; - - output_diff( - function, - old_goto_program, - new_goto_program, - p.second, - os); + const goto_programt &old_goto_program = + old_fit == old_goto_functions.function_map.end() ? empty + : old_fit->second.body; + const goto_programt &new_goto_program = + new_fit == new_goto_functions.function_map.end() ? empty + : new_fit->second.body; + + output_diff(function, old_goto_program, new_goto_program, p.second, os); } } - bool unified_difft::instructions_equal( const goto_programt::instructiont &ins1, const goto_programt::instructiont &ins2) { - return - ins1.code==ins2.code && - ins1.function==ins2.function && - ins1.type==ins2.type && - ins1.guard==ins2.guard && - ins1.targets.size()==ins2.targets.size() && - (ins1.targets.empty() || - instructions_equal( - *ins1.get_target(), - *ins2.get_target())); + return ins1.code == ins2.code && ins1.function == ins2.function && + ins1.type == ins2.type && ins1.guard == ins2.guard && + ins1.targets.size() == ins2.targets.size() && + (ins1.targets.empty() || + instructions_equal(*ins1.get_target(), *ins2.get_target())); } const unified_difft::differences_mapt &unified_difft::differences_map() const diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index 2aed152ff87..428328591a0 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -30,9 +30,7 @@ class goto_programt; class unified_difft { public: - unified_difft( - const goto_modelt &model_old, - const goto_modelt &model_new); + unified_difft(const goto_modelt &model_old, const goto_modelt &model_new); bool operator()(); @@ -45,13 +43,10 @@ class unified_difft NEW }; - typedef std::list > + typedef std::list> goto_program_difft; - void get_diff( - const irep_idt &function, - goto_program_difft &dest) const; + void get_diff(const irep_idt &function, goto_program_difft &dest) const; const goto_functionst &old_goto_functions; const namespacet ns_old; From a7afc6ccde2db7dea73ffafad01d373ec1fc4b2d Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 26 Oct 2017 14:13:28 +0100 Subject: [PATCH 08/10] Return from get_diff by value --- src/goto-diff/change_impact.cpp | 3 +-- src/goto-diff/unified_diff.cpp | 23 ++++++++++++----------- src/goto-diff/unified_diff.h | 7 +++---- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/goto-diff/change_impact.cpp b/src/goto-diff/change_impact.cpp index 67bcc2535b0..32ce14e28fc 100644 --- a/src/goto-diff/change_impact.cpp +++ b/src/goto-diff/change_impact.cpp @@ -315,8 +315,7 @@ change_impactt::change_impactt( void change_impactt::change_impact(const irep_idt &function) { - unified_difft::goto_program_difft diff; - unified_diff.get_diff(function, diff); + unified_difft::goto_program_difft diff = unified_diff.get_diff(function); if(diff.empty()) return; diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index 3974c8acef1..e5468a2b1f2 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -27,14 +27,12 @@ unified_difft::unified_difft( { } -void unified_difft::get_diff(const irep_idt &function, goto_program_difft &dest) - const +unified_difft::goto_program_difft +unified_difft::get_diff(const irep_idt &function) const { - dest.clear(); - differences_mapt::const_iterator entry = differences_map_.find(function); if(entry == differences_map_.end()) - return; + return {}; goto_functionst::function_mapt::const_iterator old_fit = old_goto_functions.function_map.find(function); @@ -50,20 +48,21 @@ void unified_difft::get_diff(const irep_idt &function, goto_program_difft &dest) new_fit == new_goto_functions.function_map.end() ? empty : new_fit->second.body; - get_diff(old_goto_program, new_goto_program, entry->second, dest); + return get_diff(old_goto_program, new_goto_program, entry->second); } -void unified_difft::get_diff( +unified_difft::goto_program_difft unified_difft::get_diff( const goto_programt &old_goto_program, const goto_programt &new_goto_program, - const differencest &differences, - goto_program_difft &dest) const + const differencest &differences) const { goto_programt::instructionst::const_iterator old_it = old_goto_program.instructions.begin(); goto_programt::instructionst::const_iterator new_it = new_goto_program.instructions.begin(); + goto_program_difft dest; + for(differencest::const_reverse_iterator rit = differences.rbegin(); rit != differences.rend(); ++rit) @@ -89,6 +88,8 @@ void unified_difft::get_diff( break; } } + + return dest; } void unified_difft::output_diff( @@ -98,8 +99,8 @@ void unified_difft::output_diff( const differencest &differences, std::ostream &os) const { - goto_program_difft diff; - get_diff(old_goto_program, new_goto_program, differences, diff); + goto_program_difft diff = + get_diff(old_goto_program, new_goto_program, differences); bool has_diff = false; for(const auto &d : diff) diff --git a/src/goto-diff/unified_diff.h b/src/goto-diff/unified_diff.h index 428328591a0..e8a6e227e46 100644 --- a/src/goto-diff/unified_diff.h +++ b/src/goto-diff/unified_diff.h @@ -46,7 +46,7 @@ class unified_difft typedef std::list> goto_program_difft; - void get_diff(const irep_idt &function, goto_program_difft &dest) const; + goto_program_difft get_diff(const irep_idt &function) const; const goto_functionst &old_goto_functions; const namespacet ns_old; @@ -67,11 +67,10 @@ class unified_difft const goto_programt &new_goto_program, differencest &differences) const; - void get_diff( + goto_program_difft get_diff( const goto_programt &old_goto_program, const goto_programt &new_goto_program, - const differencest &differences, - goto_program_difft &dest) const; + const differencest &differences) const; void output_diff( const irep_idt &identifier, From 8d0b23bc049596fba7a25295a0c4262f4e07ebb5 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 1 Nov 2017 13:37:31 +0000 Subject: [PATCH 09/10] Change asserts to invariants --- src/goto-diff/unified_diff.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index e5468a2b1f2..8929616abb2 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -71,19 +71,27 @@ unified_difft::goto_program_difft unified_difft::get_diff( { case differencet::SAME: dest.push_back(std::make_pair(new_it, differencet::SAME)); - assert(old_it != old_goto_program.instructions.end()); + INVARIANT( + old_it != old_goto_program.instructions.end(), + "Old iterator reached the final goto instruction"); ++old_it; - assert(new_it != new_goto_program.instructions.end()); + INVARIANT( + new_it != new_goto_program.instructions.end(), + "New iterator reached the final goto instruction"); ++new_it; break; case differencet::DELETED: dest.push_back(std::make_pair(old_it, differencet::DELETED)); - assert(old_it != old_goto_program.instructions.end()); + INVARIANT( + old_it != old_goto_program.instructions.end(), + "Old iterator reached the final goto instruction"); ++old_it; break; case differencet::NEW: dest.push_back(std::make_pair(new_it, differencet::NEW)); - assert(new_it != new_goto_program.instructions.end()); + INVARIANT( + new_it != new_goto_program.instructions.end(), + "New iterator reached the final goto instruction"); ++new_it; break; } @@ -336,7 +344,8 @@ bool unified_difft::operator()() unified_diff(itn->first, empty, itn->second->second.body); else { - assert(ito->first == itn->first); + INVARIANT( + ito->first == itn->first, "Old and new function names do not match"); unified_diff( itn->first, ito->second->second.body, itn->second->second.body); ++ito; From 05dc65c6fdafd330e409270ff817bc2bd0e40421 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Wed, 1 Nov 2017 14:31:22 +0000 Subject: [PATCH 10/10] Use lower-case characters to start error messages --- src/goto-diff/unified_diff.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/goto-diff/unified_diff.cpp b/src/goto-diff/unified_diff.cpp index 8929616abb2..aefcdc4c91c 100644 --- a/src/goto-diff/unified_diff.cpp +++ b/src/goto-diff/unified_diff.cpp @@ -73,25 +73,25 @@ unified_difft::goto_program_difft unified_difft::get_diff( dest.push_back(std::make_pair(new_it, differencet::SAME)); INVARIANT( old_it != old_goto_program.instructions.end(), - "Old iterator reached the final goto instruction"); + "old iterator reached the final goto instruction"); ++old_it; INVARIANT( new_it != new_goto_program.instructions.end(), - "New iterator reached the final goto instruction"); + "new iterator reached the final goto instruction"); ++new_it; break; case differencet::DELETED: dest.push_back(std::make_pair(old_it, differencet::DELETED)); INVARIANT( old_it != old_goto_program.instructions.end(), - "Old iterator reached the final goto instruction"); + "old iterator reached the final goto instruction"); ++old_it; break; case differencet::NEW: dest.push_back(std::make_pair(new_it, differencet::NEW)); INVARIANT( new_it != new_goto_program.instructions.end(), - "New iterator reached the final goto instruction"); + "new iterator reached the final goto instruction"); ++new_it; break; } @@ -345,7 +345,7 @@ bool unified_difft::operator()() else { INVARIANT( - ito->first == itn->first, "Old and new function names do not match"); + ito->first == itn->first, "old and new function names do not match"); unified_diff( itn->first, ito->second->second.body, itn->second->second.body); ++ito;