Move some more functionality into the AST consumer creation factory function, before registering matchers with the MatchFinder object. This allows us to set the language options for the ClangTidyContext object appropriately so that they can be used from registerMatchers(), and more closely models the way the clang-tidy tool works.

llvm-svn: 246660
This commit is contained in:
Aaron Ballman 2015-09-02 16:04:15 +00:00
parent b33cd908d4
commit 01cee3a7bd
1 changed files with 6 additions and 3 deletions

View File

@ -33,6 +33,10 @@ private:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,
StringRef File) override {
Context.setSourceManager(&Compiler.getSourceManager());
Context.setCurrentFile(File);
Context.setASTContext(&Compiler.getASTContext());
Check.registerMatchers(&Finder);
Check.registerPPCallbacks(Compiler);
return Finder.newASTConsumer();
}
@ -56,9 +60,6 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
ClangTidyGlobalOptions(), Options));
ClangTidyDiagnosticConsumer DiagConsumer(Context);
T Check("test-check", &Context);
ast_matchers::MatchFinder Finder;
Check.registerMatchers(&Finder);
Context.setCurrentFile(Filename.str());
std::vector<std::string> ArgCXX11(1, "clang-tidy");
ArgCXX11.push_back("-fsyntax-only");
@ -66,6 +67,8 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
ArgCXX11.push_back("-Iinclude");
ArgCXX11.insert(ArgCXX11.end(), ExtraArgs.begin(), ExtraArgs.end());
ArgCXX11.push_back(Filename.str());
ast_matchers::MatchFinder Finder;
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions()));
tooling::ToolInvocation Invocation(