How do I construct a syntax-only match-finder tool?

188 Views Asked by At

I am building an ASTMatcher-based tool that I would like to run over my sources:

int main(int argc, const char** argv) {
    CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
    ClangTool Tool(OptionsParser.getCompilations(),
                   OptionsParser.getSourcePathList());
    MatchFinder Finder;

    // Repeated calls to Finder.addMatcher(...);

    Tool.run(newFrontendActionFactory(&Finder).get());

    // Handle the results of the matching.
}

Running this over a source file that depends on other headers yields the following error:

~$ /path/to/my/tool /path/to/my/file.cpp --
/path/to/my/file.cpp:8:10: fatal error: 'string' file not found
#include <string>
         ^~~~~~~~
1 error generated.
Error while processing /path/to/my/file.cpp.

I do not want to include any other headers in this processing, lest my matchers find content in those headers that I do not want to handle.

I tried passing -fsyntax_only to the tool, but I get the same result as above:

 ~$ /path/to/my/tool /path/to/my/file.cpp -- -fsyntax-only

I noticed in the ASTMatcher tutorial that there is a clang::SyntaxOnlyAction. However, I have been unable to figure out how MatchFinder and SyntaxOnlyAction can be used in conjunction with one another. Likewise, I have been able to do an AST dump from the command line of the same file, no problem, so I know it's possible.

Is it possible to configure a MatchFinder-based tool to honor the syntax-only behavior?

0

There are 0 best solutions below