<div dir="ltr">That works, thanks!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 13, 2015 at 11:44 AM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class=""><div dir="ltr">On Sun, Dec 13, 2015 at 5:03 AM Russell Wallace via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm writing a program that uses ClangTool to parrse C++ code; per the tutorials, the main module looks as below.<br><br>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.<br></div></blockquote><div><br></div></span><div>a) you use a compilation database (<a href="http://clang.llvm.org/docs/JSONCompilationDatabase.html" target="_blank">http://clang.llvm.org/docs/JSONCompilationDatabase.html</a>), which is made to work well for multiple files with different sets of arguments</div><div>b) you call your tool with</div><div>./bin/my-tool path/to/file.cc -- <compiler args></div><div><br><div class="gmail_quote"></div></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr"><br>How do you get the usual set of commandline options that clang has?<br><br>// Apply a custom category to all command-line options so that they are the<br>// only ones displayed.<br>static cl::OptionCategory MyToolCategory("my-tool options");<br><br>// CommonOptionsParser declares HelpMessage with a description of the common<br>// command-line options related to the compilation database and input files.<br>// It's nice to have this help message in all tools.<br>static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);<br><br>int main(int argc, const char **argv) {<br>  std::set_new_handler([]() {<br>    errs() << "new: " << strerror(errno) << '\n';<br>    exit(1);<br>  });<br><br>  sys::PrintStackTraceOnErrorSignal();<br>  PrettyStackTraceProgram X(argc, argv);<br><br>#ifdef _WIN32<br>  // Stack overflow<br>  AddVectoredExceptionHandler(0, handler);<br>#endif<br><br>  CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);<br>  ClangTool Tool(OptionsParser.getCompilations(),<br>                 OptionsParser.getSourcePathList());<br>  return Tool.run(newFrontendActionFactory<MainAction>().get());<br>}<br><br></div></span>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>
</blockquote></div><br></div>