0

I'd like a diff-like tool which, on files determined or forced to be treated as C sources, respects function boundaries. That is, does not try to have the lines of a single function match lines from different functions in the other file.

Requirements:

  • Runs on Linux

Desirable:

  • Gratis
  • Libre
  • Has an interactive GUI (like meld, kdiff3 etc.)
  • plugs into diff-related tools
  • Seems you mean "function-name" aware, and you only want it to compare functions with the same name? – Ira Baxter Aug 12 '17 at 9:05
  • @IraBaxter: Yeah, that's right. – einpoklum - reinstate Monica Aug 12 '17 at 9:10
  • No answers in 60 days. Interested in a tool that compares source file according to language structures (rather than text lines) [that doesn't specifically match functions]? – Ira Baxter Oct 9 '17 at 7:39
  • @IraBaxter: Sure, that's close enough to be interesting. – einpoklum - reinstate Monica Oct 9 '17 at 8:40
1

You might consider Semantic Designs (my company) family of Smart Differencers.

The Smart Differencer parses source text for two files to be compared using a language (and even dialect, e.g, VisualStudio 2010) accurate parser, builds a tree, and then finds a minimal distance tree edit to explain how they are different, in terms of the grammar. This means reporting deltas such as "changed expression", "moved statement", "renamed variable" using precise line and column information. Because it uses a parser, it ignores changes in whitespace (although you can ask it to consider comments as non-white-space as an option).

It runs natively under Windows, seamlessly on Linux under Wine using provided sh scripts. It is commercial. The output is diff-like because it is a diff tool, rather than having a GUI.

Smart Differencer works with many languages. For the C version, it has some difficulties parsing C source with awkwardly placed macros and/or preprocessor conditionals; note that it is trying to parse source files without the context of the complete compilation unit you normally feed a compiler. System header files tend to be be pretty bad here but rarely does one want to compare these. You can ameliorate these by providing it with some hints about things that are macros; if you are willing to modify your source code a little bit, once, by moving awkward conditionals you can pretty much solve this problem.

Not exactly what OP wants, but the core of it seems to match.

  • ... and can you limit the possible operations? e.g. "don't move statements in or out of functions"? – einpoklum - reinstate Monica Oct 9 '17 at 12:25
  • The Smart Differencers know about the grammar but not about function boundaries. Thats kind of an interesting feature request :-} – Ira Baxter Oct 9 '17 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.