Author: aaronballman
Date: Wed Sep  2 11:04:15 2015
New Revision: 246660

URL: http://llvm.org/viewvc/llvm-project?rev=246660&view=rev
Log:
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.

Modified:
    clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h

Modified: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h?rev=246660&r1=246659&r2=246660&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h Wed Sep  2 
11:04:15 2015
@@ -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::vect
       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::vect
   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(


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to