I’m looking to make a tool based on clang and I’m having a little trouble understanding which interface / extensibility approach to use.
I’d like to scan the AST of a program and look for incorrect usage of a specific object/API. An oversimplified example is looking for local variables of a specific type, looking to see which methods on that object are called, and issuing a warning when certain patterns are noticed.
The only other requirement is that it must run on Windows.
In an ideal world I’d be able to hook this up to run automatically during any build, issue custom errors, and perform automatic fix-up, but those are all optional.
From what I can tell there are multiple approaches I could take:
- LibClang
- Clang Plugin
- LibTooling
- clang-check
- clang-format
- clang-tidy
LibClang is the only one I’ve used before. In this case, I know the abstracted view of the AST in LibClang is missing information I need. I could add the missing information to LibClang, but it’s an unknown amount of work and I don’t want to require a custom version of clang while merging changes upstream or force us onto a newer clang version. So I can rule out LibClang.
I assume clang-format does support the level of extensibility required here.
That still leaves 4 options. Which should I be using for this type of thing?