Creating your own clang-based tool
The static analyzer is an impressive example of what you can do with the clang infrastructure. It is also possible to extend clang with plugins so that you can add your own functionality to clang. The technique is very similar to adding a pass plugin to LLVM.
Let’s explore the functionality with a simple plugin. The LLVM coding standard requires function names to begin with a lowercase letter. However, the coding standard has evolved, and there are many instances in which a function begins with an uppercase letter. A plugin that warns about a violation of the naming rule can help fix this issue, so let’s give it a try.
Because you want to run a user-defined action over the AST, you need to define a subclass of the PluginASTAction
class. If you write your own tool using the clang libraries, then you can define subclasses of the ASTFrontendAction
class for your actions. The PluginASTAction
class is a subclass of the ASTFrontendAction...