[cfe-dev] clang based diff tool

Marshall Clow mclow.lists at gmail.com
Mon Oct 6 08:40:19 PDT 2014


On Oct 4, 2014, at 2:37 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:
> On 3 Oct 2014, at 17:32, Maurizio Vitale <mrz.vtl at gmail.com> wrote:
> 
>> G'day everybody,
>>  I vaguely remember that there was some tought/work on having a semantics-based diff tool on top of clang. Did I dream of this? any pointers to the discussion?
>> 
>> Maurizio
> 
> One of my students worked on a project to do this using libclang and the Python bindings last year.  His goal was to identify common refactorings and present them in a human-readable form (including things like 'Variable x was renamed y in every use except those in foo.c').  His code probably isn't in a very good state to be reusable, but I'm sure he'd be happy to share his experiences with you.

I’d love to see someone pursue this.
There’s lots of things that one could build upon a smart diff tool.

Finding similar chunks of code.
Detecting botched refactoring.
Etc. Etc.


Rambling to follow …

A long time ago, I worked on a horrible code base; the result of years of copy/paste development.
We had a tool called (I think) Pattern Insight that found these two chunks of code (actual duplicated code was about 60 lines long)

blah blah global1 blah blah
blah blah blah blah blah
blah blah blah blah global1
blah global1 blah global1 blah blah
global1 blah blah blah blah
blah blah global1 blah blah

— and —

blah blah global2 blah blah
blah blah blah blah blah
blah blah blah blah global2
blah global1 blah global2 blah blah
global2 blah blah blah blah
blah blah global2 blah blah

And said (paraphrased) “Did you really mean ‘global1’ on line 4 of that second chunk?”


— Marshall





More information about the cfe-dev mailing list