<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 7, 2014 at 7:49 PM, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: klimek<br>
Date: Tue Oct  7 10:49:36 2014<br>
New Revision: 219212<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=219212&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=219212&view=rev</a><br>
Log:<br>
Make clang-tidy's runCheckOnCode actually use the DiagnosticConsumer.<br>
<br>
A precondition of that was to run both the preprocessor checks and AST<br>
checks from the same FrontendAction, otherwise we'd have needed to<br>
duplicate all involved objects in order to not have any references to a<br>
deleted source manager.<br>
<br>
Modified:<br>
    clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h<br>
    clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp<br>
<br>
Modified: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h?rev=219212&r1=219211&r2=219212&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h?rev=219212&r1=219211&r2=219212&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h (original)<br>
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h Tue Oct  7 10:49:36 2014<br>
@@ -22,21 +22,23 @@ namespace clang {<br>
 namespace tidy {<br>
 namespace test {<br>
<br>
-class TestPPAction : public PreprocessOnlyAction {<br>
+class TestClangTidyAction : public ASTFrontendAction {<br>
 public:<br>
-  TestPPAction(ClangTidyCheck &Check, ClangTidyContext *Context)<br>
-      : Check(Check), Context(Context) {}<br>
+  TestClangTidyAction(ClangTidyCheck &Check, ast_matchers::MatchFinder &Finder,<br>
+                      ClangTidyContext &Context)<br>
+      : Check(Check), Finder(Finder), Context(Context) {}<br>
<br>
 private:<br>
-  bool BeginSourceFileAction(CompilerInstance &Compiler,<br>
-                             llvm::StringRef file_name) override {<br>
-    Context->setSourceManager(&Compiler.getSourceManager());<br>
+  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,<br>
+                                                 StringRef File) override {<br>
+    Context.setSourceManager(&Compiler.getSourceManager());<br>
     Check.registerPPCallbacks(Compiler);<br>
-    return true;<br>
+    return Finder.newASTConsumer();<br>
   }<br>
<br>
   ClangTidyCheck &Check;<br>
-  ClangTidyContext *Context;<br>
+  ast_matchers::MatchFinder &Finder;<br>
+  ClangTidyContext &Context;<br>
 };<br>
<br>
 template <typename T><br>
@@ -50,19 +52,25 @@ std::string runCheckOnCode(StringRef Cod<br>
       ClangTidyGlobalOptions(), Options));<br>
   ClangTidyDiagnosticConsumer DiagConsumer(Context);<br>
   T Check("test-check", &Context);<br>
-  std::vector<std::string> ArgCXX11(1, "-std=c++11");<br>
-  ArgCXX11.insert(ArgCXX11.end(), ExtraArgs.begin(), ExtraArgs.end());<br>
-<br>
-  if (!tooling::runToolOnCodeWithArgs(new TestPPAction(Check, &Context), Code,<br>
-                                      ArgCXX11, Filename))<br>
-    return "";<br>
   ast_matchers::MatchFinder Finder;<br>
   Check.registerMatchers(&Finder);<br>
-  std::unique_ptr<tooling::FrontendActionFactory> Factory(<br>
-      tooling::newFrontendActionFactory(&Finder));<br>
-  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, ArgCXX11,<br>
-                                      Filename))<br>
+<br>
+  std::vector<std::string> ArgCXX11(1, "clang-tidy");<br>
+  ArgCXX11.push_back("-fsyntax-only");<br>
+  ArgCXX11.push_back("-std=c++11");<br>
+  ArgCXX11.insert(ArgCXX11.end(), ExtraArgs.begin(), ExtraArgs.end());<br>
+  ArgCXX11.push_back(Filename.str());<br>
+  llvm::IntrusiveRefCntPtr<FileManager> files(<br></blockquote><div><br></div><div>Please capitalize "files". Also, why do we use llvm::IntrusiveRefCntPtr rather than std::unique_ptr? (I guess there's a reason, but I don't see it.)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+      new FileManager(FileSystemOptions()));<br>
+  tooling::ToolInvocation Invocation(<br>
+      ArgCXX11, new TestClangTidyAction(Check, Finder, Context), files.get());<br>
+  SmallString<16> FileNameStorage;<br>
+  StringRef FileNameRef = Filename.toNullTerminatedStringRef(FileNameStorage); </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  Invocation.mapVirtualFile(FileNameRef, Code);<br></blockquote><div><br></div><div>Maybe Invocation.mapVirtualFile(Filename.str(), Code)?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  Invocation.setDiagnosticConsumer(&DiagConsumer);<br>
+  if (!Invocation.run())<br>
     return "";<br>
+<br>
   DiagConsumer.finish();<br>
   tooling::Replacements Fixes;<br>
   for (const ClangTidyError &Error : Context.getErrors())<br>
<br>
Modified: clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp?rev=219212&r1=219211&r2=219212&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp?rev=219212&r1=219211&r2=219212&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp (original)<br>
+++ clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp Tue Oct  7 10:49:36 2014<br>
@@ -114,7 +114,7 @@ TEST(LLVMHeaderGuardCheckTest, FixHeader<br>
                                          "LLVM_ADT_FOO_H\n#endif \\ \n// "<br>
                                          "LLVM_ADT_FOO_H\n",<br>
                                          "include/llvm/ADT/foo.h",<br>
-                                         /*ExpectedWarnings=*/0));<br>
+                                         /*ExpectedWarnings=*/1));<br></blockquote><div><br></div><div>What kind of warning started appearing here? About unknown escape sequence?</div><div><br></div><div>"ExpectedWarnings" doesn't help much =\ I'll change this to actual warning messages some day.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
   EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif  /* "<br>
             "LLVM_ADT_FOO_H\\ \n FOO */",<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br><br>
</div></div>