I’m writing a program that uses ClangTool to parrse C++ code; per the tutorials, the main module looks as below.
It works for a single file, but more complex inputs require the usual commandline options to set include path, Microsoft compatibility mode et cetera, and by default you only get a few options like -help and -version.
How do you get the usual set of commandline options that clang has?
// Apply a custom category to all command-line options so that they are the
// only ones displayed.
static cl::OptionCategory MyToolCategory(“my-tool options”);
// CommonOptionsParser declares HelpMessage with a description of the common
// command-line options related to the compilation database and input files.
// It’s nice to have this help message in all tools.
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
int main(int argc, const char **argv) {
std::set_new_handler( {
errs() << "new: " << strerror(errno) << ‘\n’;
exit(1);
});
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
#ifdef _WIN32
// Stack overflow
AddVectoredExceptionHandler(0, handler);
#endif
CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
ClangTool Tool(OptionsParser.getCompilations(),
OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory().get());
}