[PATCH] Set up clang-tidy diagnostic consumer to print types etc.

Alexander Kornienko alexfh at google.com
Mon Jul 14 06:56:47 PDT 2014


Hi bkramer,

http://reviews.llvm.org/D4494

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h

Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -209,7 +209,7 @@
   // FIXME: Move this to a separate method, so that CreateASTConsumer doesn't
   // modify Compiler.
   Context.setSourceManager(&Compiler.getSourceManager());
-  Context.setCurrentFile(File);
+  Context.setCurrentFile(File, &Compiler.getASTContext());
 
   std::vector<std::unique_ptr<ClangTidyCheck>> Checks;
   ChecksFilter &Filter = Context.getChecksFilter();
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -18,6 +18,7 @@
 
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyOptions.h"
+#include "clang/AST/ASTDiagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 #include "llvm/ADT/SmallString.h"
@@ -163,7 +164,7 @@
     : DiagEngine(nullptr), OptionsProvider(OptionsProvider) {
   // Before the first translation unit we can get errors related to command-line
   // parsing, use empty string for the file name in this case.
-  setCurrentFile("");
+  setCurrentFile("", nullptr);
 }
 
 DiagnosticBuilder ClangTidyContext::diag(
@@ -199,9 +200,21 @@
   DiagEngine->setSourceManager(SourceMgr);
 }
 
-void ClangTidyContext::setCurrentFile(StringRef File) {
+static void DummyArgToStringFn(DiagnosticsEngine::ArgumentKind, intptr_t,
+                               StringRef, StringRef,
+                               ArrayRef<DiagnosticsEngine::ArgumentValue>,
+                               SmallVectorImpl<char> &Output, void *,
+                               ArrayRef<intptr_t>) {
+  StringRef Str = "<can't format argument>";
+  Output.append(Str.begin(), Str.end());
+}
+
+void ClangTidyContext::setCurrentFile(StringRef File, ASTContext *Context) {
   CurrentFile = File;
   CheckFilter.reset(new ChecksFilter(getOptions().Checks));
+  DiagEngine->SetArgToStringFn(Context ? &FormatASTNodeDiagnosticArgument
+                                       : &DummyArgToStringFn,
+                               Context);
 }
 
 const ClangTidyGlobalOptions &ClangTidyContext::getGlobalOptions() const {
Index: clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -19,6 +19,7 @@
 
 namespace clang {
 
+class ASTContext;
 class CompilerInstance;
 namespace ast_matchers {
 class MatchFinder;
@@ -134,7 +135,7 @@
   void setSourceManager(SourceManager *SourceMgr);
 
   /// \brief Should be called when starting to process new translation unit.
-  void setCurrentFile(StringRef File);
+  void setCurrentFile(StringRef File, ASTContext *Context);
 
   /// \brief Returns the name of the clang-tidy check which produced this
   /// diagnostic ID.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4494.11376.patch
Type: text/x-patch
Size: 3007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140714/22fcd6ad/attachment.bin>


More information about the cfe-commits mailing list