Hello,
I was able to setup and execute the sample provided on http://clang.llvm.org/docs/RAVFrontendAction.html
The sample tool can be executed using the code as a string argument.
Wanted to know if there is a way we can provide the C-source code files as an argument to this main function (in FindClassDecls.cpp).
Disclaimer: I have just started on Clang.
Regards,
Sunny. R. Billava
Sr. TechLead - AESBU | Powertrain Practice
Phone: +91-20-6652 5000 Ext. 2813 | Cell: +91-9561 125 413 | E-mail: sunny.billava@kpit.com
Hi Sunny,
you can do as follows:
static cl::OptionCategory MySampleCategory(“clang-tool options”);
int main(int argc, const char *argv[])
{
CommonOptionsParser OptionsParser(argc, argv, MySampleCategory);
ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList());
return Tool.run(newFrontendActionFactory().get());
}
Take a look at Matchers as well. It might be more handy for you:
http://clang.llvm.org/docs/LibASTMatchersTutorial.html#intermezzo-learn-ast-matcher-basics
Of course, you could also just read the specified files into a string variable and pass it to runToolOnCode:
std::string FileContent;
// fill it from the files specified in argv
runToolOnCode(new FindNamedClassAction, FileContent);