<div dir="ltr">I'm trying to parse C++ code to an abstract syntax tree and do something with the result. (Basically I'm trying to create a DSL that has the syntax and denotational semantics of a subset of C++, but different operational semantics.)<br><br>To parse C++ with default compiler options and the ability to add more on the command line and/or use a compilation database, I'm going by <a href="http://clang.llvm.org/docs/LibASTMatchersTutorial.html">http://clang.llvm.org/docs/LibASTMatchersTutorial.html</a> which gets as far as<br><br>int main(int argc, const char **argv) {<br>  CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);<br>  ClangTool Tool(OptionsParser.getCompilations(),<br>                 OptionsParser.getSourcePathList());<br><br>  LoopPrinter Printer;<br>  MatchFinder Finder;<br>  Finder.addMatcher(LoopMatcher, &Printer);<br><br>  return Tool.run(newFrontendActionFactory(&Finder).get());<br>}<br><br>The only thing not applicable here is that the tutorial is about using the pattern matching facility to match fragments of code wherever they might occur in the AST, whereas I'm looking to recur over the entire AST. The ideal would be if I could just say 'parse, give me the AST and I'll take it from there'. Is there an easy way to do that?<br><br>An alternative possibility would be to use an AST visitor to match function and other declarations at the top level and go from there. <a href="http://clang.llvm.org/docs/RAVFrontendAction.html">http://clang.llvm.org/docs/RAVFrontendAction.html</a> discusses this, getting as far as<br><br>int main(int argc, char **argv) {<br>  if (argc > 1) {<br>    clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);<br>  }<br>}<br><br>However, this only parses code fragments passed as literal text. Is there a way to combine these and get the features of CommonOptionsParser and ClangTool but run over the entire AST rather than using local pattern matching?<br></div>