Tooling: disable standard compile-run

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?

Best,
Robert

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

In article <CAOsfVv=JZx+QY-YTe+Eg7yiFwUE8cU4O7zUeYYcTM-dUT+UCKQ@mail.gmail.com>,
    Manuel Klimek <klimek@google.com> writes:

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.

CMake on Windows doesn't generate compilation databases at all.

You have to hack one up manually yourself, but it's not hard.

See the section titles "The Compilation Database" here:
<https://github.com/LegalizeAdulthood/remove-void-args>

Thanks for the answers.
I will look through the stuff and write my experience then.

Best,
Robert

In article <530CEE52.90407@gmx.net>,
    Robert Zimmermann <tsett@gmx.net> writes:

Thanks for the answers.
I will look through the stuff and write my experience then.

Obviously the "hack yourself one together" in an editor approach
doesn't scale.

For more than one file (i.e. compiling an entire code base), you can
do a clean build with VS and then write a script to generate the
compilation database from the VS log file, which includes the full
compilation command for every source file.

In article <530CEE52.90407@gmx.net>,
    Robert Zimmermann <tsett@gmx.net> writes:

> Thanks for the answers.
> I will look through the stuff and write my experience then.

Obviously the "hack yourself one together" in an editor approach
doesn't scale.

For more than one file (i.e. compiling an entire code base), you can
do a clean build with VS and then write a script to generate the
compilation database from the VS log file, which includes the full
compilation command for every source file.

I think it's probably easier to change CMake to output them for Windows
(and would benefit everybody :wink: than to re-parse the output. If somebody
wants hints, just drop me a mail and I'm happy to point you in the right
direction.

Hello again,
I looked into this stuff with the CompilationDatabase.
I think my problem is a little bit another.

The tool is called like for a single file like that:
check-tool –
Thus, I should already have a Database.

When the tool is called for a C+±File it gives an error like: missing
When I add all the directories where these files should be located (e.g. -I$(MINGWPATH)\lib\gcc\mingw32\4.8.1\include\c++) to the compiler-flags and I got strange compiler errors.

Best,
Robert

In article <CAOsfVv=8kzT9FYXQbWxOB9qHnvgAAOX=673jd61sni5mHzJswQ@mail.gmail.com>,
    Manuel Klimek <klimek@google.com> writes:

I think it's probably easier to change CMake to output them for Windows
(and would benefit everybody :wink: than to re-parse the output.

Easier? I have no idea.

Better? Most definitely as you end up creating a solution that
everyone can use.

Hello again,
I looked into this stuff with the CompilationDatabase.
I think my problem is a little bit another.

The tool is called like for a single file like that:
check-tool <tool-flags> <file> -- <compiler-flags>
Thus, I should already have a Database.

When the tool is called for a C++-File it gives an error like: missing
<map>
When I add all the directories where these files should be located (e.g.
-I$(MINGWPATH)\lib\gcc\mingw32\4.8.1\include\c++) to the compiler-flags
and I got strange compiler errors.

Seeing those compile errors would be interesting... :wink:

Hi,

The tool is called like for a single file like that:
check-tool <tool-flags> <file> -- <compiler-flags>

Have you tried
check-tool <tool-flags <file> -- clang++ <compiler-flags>
On my system this adds the default compiler options for C++.

Best,
Marcel