[cfe-dev] How to Provide C Source Code Files as Input to RecursiveASTVisitor based CLANG Tool

Firat Kasmis via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 8 10:09:32 PST 2016


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<FindNamedClassAction>().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);


2016-11-08 13:51 GMT+01:00 Sunny Billava via cfe-dev <cfe-dev at lists.llvm.org
>:

> 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 at kpit.com
> *——————————————————————————————————*
> *KPIT* | *Web:* www.kpit.com   *Social:* Facebook
> <http://www.kpit.com/facebook> | Twitter <http://www.kpit.com/twitter> |
> Linkedin <http://www.kpit.com/linkedin> | Youtube
> <http://www.kpit.com/youtube>
>
>
> This message contains information that may be privileged or confidential
> and is the property of the KPIT Technologies Ltd. It is intended only for
> the person to whom it is addressed. If you are not the intended recipient,
> you are not authorized to read, print, retain copy, disseminate,
> distribute, or use this message or any part thereof. If you receive this
> message in error, please notify the sender immediately and delete all
> copies of this message. KPIT Technologies Ltd. does not accept any
> liability for virus infected mails.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161108/332b1d80/attachment.html>


More information about the cfe-dev mailing list