我现在正在使用LLVM + Clang。我使用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());
我想避免访问包含的系统库。可能吗?