Playing with llvm/clang libclangTooling: initial impression

For a task at work, I’ve been writing an application that uses clang’s libclangTooling to parse source code and do a few relatively simple things from preprocessing and AST traversal. I’ll be writing more about this at a later date, but at the moment I can say that I’m impressed with what’s possible. There are many glitches/inconsistencies in the interfaces that are likely due to different contributors, and the documentation remains largely absent, but neither of these issues make it unusable.

The task at hand at the moment is producing unit testing skeletons from existing source code. Obviously there are other means of doing this, including commercial tools. But if writing your own tool, being able to do it with API calls to pieces of clang’s front end avoids a lot of nitty-gritty lexing and parsing details while having complete control over the output. And you get preprocessing for free. And my tool will accept most of clang’s command-line options, which means my tool can be fairly flexible; I can pass -D and -I options for preprocessor defines and include paths, for example. Those are passed to clang’s front end without any work on my part.

Leave a Reply