Llvm 避免遍历包含的系统库

Llvm 避免遍历包含的系统库,llvm,clang,Llvm,Clang,我现在正在与LLVM合作。我使用ASTUnit构建树,并使用RecursiveASTVisitor遍历树 clang::ASTUnit* AST; clang::DiagnosticOptions diagOpts; llvm::IntrusiveRefCntPtr<clang::Diagnostic> diags = clang::CompilerInstance::createDiagnostics(diagOpts, 0, 0); const

我现在正在与LLVM合作。我使用ASTUnit构建树,并使用RecursiveASTVisitor遍历树

    clang::ASTUnit* AST;
    clang::DiagnosticOptions diagOpts;
    llvm::IntrusiveRefCntPtr<clang::Diagnostic> diags = clang::CompilerInstance::createDiagnostics(diagOpts, 0, 0);

    const char** ptr = new const char*[1];
    ptr[0] = argv[1];

    clang::CompilerInvocation *ci = new clang::CompilerInvocation();
    clang::CompilerInvocation::CreateFromArgs(*ci, ptr, ptr+1, *diags);
    ci->setLangDefaults(clang::IK_CXX, clang::LangStandard::lang_cxx98);
    ci->getPreprocessorOutputOpts().ShowComments = 1;
    ci->getPreprocessorOutputOpts().ShowLineMarkers = 1;

    AST = clang::ASTUnit::LoadFromCompilerInvocation(ci, diags);

    ...
    ...

    MyRecursiveASTVisitor myvis(AST->getASTContext());
    myvis.TraverseDecl(AST->getASTContext().getTranslationUnitDecl());
clang::ASTUnit*AST;
叮当声:诊断选项诊断选项;
llvm::IntrusiveRefCntPtr diags=clang::CompilerInstance::createDiagnostics(diagOpts,0,0);
常量字符**ptr=新常量字符*[1];
ptr[0]=argv[1];
clang::CompilerInvocation*ci=新clang::CompilerInvocation();
编译器职业::CreateFromArgs(*ci,ptr,ptr+1,*诊断);
ci->setLangDefaults(clang::IK_CXX,clang::LangStandard::lang_cxx98);
ci->getPreprocessorOutputOpts().ShowComments=1;
ci->getPreprocessorOutputOpts().ShowLineMarkers=1;
AST=clang::ASTUnit::LoadFromCompilerInvocation(ci,diags);
...
...
MyRecursiveASTVisitor myvis(AST->getASTContext());
myvis.TraverseDecl(AST->getASTContext().getTranslationUnitDecl());

我希望避免访问包含的系统库。有可能吗?

我想我找到了某种解决方案,但不是最终的解决方案

在继承的ASTVisitor类中:

class MyRecursiveASTVisitor : public clang::RecursiveASTVisitor<MyRecursiveASTVisitor>
类MyRecursiveASTVisitor:public clang::RecursiveASTVisitor 您可以重写函数TraverseDecl。在这个函数中,您可以遍历声明。如果不调用此函数recursive,则当声明不是来自主文件时,可以避免遍历来自其他文件的声明

bool TraverseDecl ( clang::Decl *D )
{
    bool rval;

    if (!D) return true;

    if (sm.isFromMainFile(D->getLocation()) || std::string(D->getDeclKindName()) == "TranslationUnit")
    {
        bool rval = clang::RecursiveASTVisitor<MyRecursiveASTVisitor>::TraverseDecl(D);
    }
    else
        rval = true;

    return rval;
}
bool transversedecl(铿锵::Decl*D)
{
布尔瓦尔;
如果(!D)返回true;
if(sm.isFromMainFile(D->getLocation())| | std::string(D->getDeclKindName())=“TranslationUnit”)
{
bool rval=clang::RecursiveASTVisitor::TraverseDecl(D);
}
其他的
rval=真;
返回rval;
}
在此上下文中,sm是MyRecursiveASTVisitor类的clang::SourceManager。同样,在重写的TraverseStmt函数中,可以避免遍历其他文件中的语句

现在我只想知道语句或声明是来自系统库还是来自用户定义库