Is there a working Semantic Diff tool for C++?

Asked
Viewd2667

9

I've found only abandoned projects, theories and feature lists. But I could not find a tool which can compare two C++ source files and show semantic differences.

Of course I would not compare two unrelated files, or changes accumulated during 10 years of development and maintenance. But changes usually discussed at a code review would be understood more easily, if presented together with proper meaning, instead of textual changes at char/word/line level

4 ответов

2

There is one for C used by linux kernel developers. Not for C++ though

http://coccinelle.lip6.fr

  • @Brad: they talk about semantic patches, but it appears that what they mean are “pattern matches” that are insensitive to changes in white spaces, variable names, etc across multiple versions of a file, but it isn’t clear they compare two files to determine that they are similar. Can you point specifically to where they say that?

    Ira Baxter06 сентября 2009, 05:16
  • You have the spdiff tool to infer semantic patches http://www.diku.dk/hjemmesider/ansatte/jespera/doc.html .

    LB4016 сентября 2009, 14:30
3

A true "semantic diff" is impossible. Closer would be a tool that compared two source files to see how one was derived from the other by abstract editing operations (delete, copy, move, rename) on program structures (variables, expressions, statements, methods). See our Smart Differencer for a tool that does this for a few languages, with C++ coming soon.

March 2013: GCC/MS dialects of C++11 supported.

  • March 2010: Its been available for several months, just got back to this particular SO question.

    Ira Baxter02 марта 2010, 05:34
-2

It's not possible, in general. One program cannot even tell whether another will terminate (the famous Halting Problem). For more limited programs (finitely bounded loops, and maybe other constraints) you can do more, but it's heavy-duty stuff, and the language would have to be, not C++ but something less tricky, a limited subset or a simpler language altogether. That's probably why you're finding nothing that's been more than started.

-2

Yes, it is called "writing comments for commits" and "issue tracking". Consider it metadata for semantic analysis.

  • Please, read the question before posting - even git users can do it. “git merge” handles branches, question is about files.

    ima12 августа 2009, 04:41
  • What issue tracking integrated into what merge tool in Git? Git has neither half-decent integration with issue tracking, nor built-in merge tool, so I can only guess it doesn’t have integration of those two.

    ima11 августа 2009, 06:04
  • True. Every version control can show history with comments, but I’ve never seen it integrated into merge tool, on per-change basis. Might become quite a useful feature… on the other, might clash with comments in code.

    ima10 августа 2009, 20:48
  • Idea was - for files diff and merge - to have issues and comments and histories readily available for each individual change.

    ima12 августа 2009, 04:47
  • Интегрированы в инструмент слияния? Нравится Git?

    greyfade11 августа 2009, 00:06
  • But that would be ISO layer 8 processing of information, instead of using a tool

    CsTamas10 августа 2009, 20:33
  • Я, наверное, вас неправильно понял, но git merge обрабатывает слияния так же чисто и просто, как и простые коммиты, с полной историей и коммитами из исходного репозитория. С хорошими комментариями к фиксации (и с рецензентами, использующими –signoff) довольно легко отслеживать историю конкретных проблем. Было бы неплохо интегрировать систему отслеживания проблем / ошибок, но ее несложно добавить с помощью пары скриптов Perl.

    greyfade11 августа 2009, 20:16