[cfe-dev] Tooling: disable standard compile-run

Manuel Klimek klimek at google.com
Tue Feb 25 04:35:33 PST 2014


On Sun, Feb 23, 2014 at 11:50 AM, Robert Zimmermann <tsett at gmx.net> wrote:

> Hello,
> I wrote a small program for Windows using LibTooling to implement
> additional syntax-checking.
> For this I use a MatchFinder with several matchers and later I start
> ClangTool.run()
> Here a code example:
>
> ClangTool Tool(...);
> MatchFinder Finder;
> for (vector<BaseChecker*>::iterator iter = checkers->begin(); iter !=
> checkers->end(); iter++)
> {
>   BaseChecker* checker = *iter;
>   Finder.addMatcher(*checker->getMatcher(),
> static_cast<MatchFinder::MatchCallback*>(checker));
> }
> ret = Tool.run(newFrontendActionFactory(&Finder));
>
> If I run my tool on c++-code I got the problem that it do not find all
> the standard c++-header, but the rest of my matchers is working.
> I know that I could add the path to the FrontEnd.h, but then it will
> only work on systems with the same path.
>
> I also tried to add them via the -I switch, but I got a lot of errors in
> these files.
>
> The question is: Can I disable the standard compile-run (with a switch
> or in my code) and just create the AST and run the MatchFinder?
>

Compilation is already disabled when you use ClangTool. The problem is that
in C++ you need to know all available types at any point in the program to
even construct an AST (as such, the AST is more a "semantic" tree than a
syntactic one). Thus, you (unfortunately) need all headers.

The solution we have for this is to use a CompilationDatabase. As you're on
Windows, and I've never looked into how well the CMake generated ones work
there, I'd suggest to start with a FixedCompilationDatabase [1], and add
the full set of -I flag the compiler would also see there.

[1]
http://clang.llvm.org/doxygen/classclang_1_1tooling_1_1FixedCompilationDatabase.html

Hope that helps!
/Manuel



>
> Best,
> Robert
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140225/066d4836/attachment.html>


More information about the cfe-dev mailing list