Alex
Alex

Reputation: 1

Keep my Clang Based tool from analyzing header files in source code?

I'm writing a stand alone tool based on LibTooling with a RecursiveASTVistor, and I don't want to have to go through the contents of header files stored in source code. Do I need to change the compilation database? I've been using this little hack to keep my tool from crashing, but I don't want my tool to analyze any header files at all included in the source code I'm dealing with.

bool VisitDecl(Decl *D) {

    FullSourceLoc FullLocation = Context->getFullLoc(D->getLocStart());
    const auto &SourceManager = Context->getSourceManager();

    if (FullLocation.isValid() && !SourceManager.isInSystemHeader(FullLocation) && Context->getSourceManager().isInMainFile(D->getLocation()))
}

Upvotes: 0

Views: 417

Answers (1)

Hemant
Hemant

Reputation: 867

What you are doing is the way to skip the system header files. But if you want to skip all the included headers then you can specify your include directory with --isystem=<custom include dirs> instead of just plain -I <custom include dirs> command line option. With that change, all the custom include headers will be considered as system headers and will be skipped.

Upvotes: 1

Related Questions