[PATCH] D69782: Summary: Instead of dropping all the ranges associated with a Diagnostic when converting them to a ClangTidy error, instead attach them to the ClangTidyError, so they can be consumed by other APIs.

Joe Turner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 3 21:43:27 PST 2019


compositeprimes created this revision.
compositeprimes added reviewers: gribozavr, alexfh.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D69782

Files:
  include/clang/Tooling/Core/Diagnostic.h
  include/clang/Tooling/DiagnosticsYaml.h
  lib/Tooling/Core/Diagnostic.cpp


Index: lib/Tooling/Core/Diagnostic.cpp
===================================================================
--- lib/Tooling/Core/Diagnostic.cpp
+++ lib/Tooling/Core/Diagnostic.cpp
@@ -42,9 +42,10 @@
 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
                        const DiagnosticMessage &Message,
                        const SmallVector<DiagnosticMessage, 1> &Notes,
-                       Level DiagLevel, llvm::StringRef BuildDirectory)
+                       Level DiagLevel, llvm::StringRef BuildDirectory,
+                       ArrayRef<CharSourceRange> Ranges)
     : DiagnosticName(DiagnosticName), Message(Message), Notes(Notes),
-      DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
+      DiagLevel(DiagLevel), BuildDirectory(BuildDirectory), Ranges(Ranges) {}
 
 const llvm::StringMap<Replacements> *selectFirstFix(const Diagnostic& D) {
    if (!D.Message.Fix.empty())
Index: include/clang/Tooling/DiagnosticsYaml.h
===================================================================
--- include/clang/Tooling/DiagnosticsYaml.h
+++ include/clang/Tooling/DiagnosticsYaml.h
@@ -58,11 +58,12 @@
 
     NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D)
         : DiagnosticName(D.DiagnosticName), Message(D.Message), Notes(D.Notes),
-          DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory) {}
+          DiagLevel(D.DiagLevel), BuildDirectory(D.BuildDirectory),
+          Ranges(D.Ranges) {}
 
     clang::tooling::Diagnostic denormalize(const IO &) {
       return clang::tooling::Diagnostic(DiagnosticName, Message, Notes,
-                                        DiagLevel, BuildDirectory);
+                                        DiagLevel, BuildDirectory, Ranges);
     }
 
     std::string DiagnosticName;
@@ -71,6 +72,7 @@
     SmallVector<clang::tooling::DiagnosticMessage, 1> Notes;
     clang::tooling::Diagnostic::Level DiagLevel;
     std::string BuildDirectory;
+    ArrayRef<CharSourceRange> Ranges;
   };
 
   static void mapping(IO &Io, clang::tooling::Diagnostic &D) {
Index: include/clang/Tooling/Core/Diagnostic.h
===================================================================
--- include/clang/Tooling/Core/Diagnostic.h
+++ include/clang/Tooling/Core/Diagnostic.h
@@ -62,7 +62,7 @@
 
   Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message,
              const SmallVector<DiagnosticMessage, 1> &Notes, Level DiagLevel,
-             llvm::StringRef BuildDirectory);
+             llvm::StringRef BuildDirectory, ArrayRef<CharSourceRange> Ranges);
 
   /// Name identifying the Diagnostic.
   std::string DiagnosticName;
@@ -84,6 +84,10 @@
   ///
   /// Note: it is empty in unittest.
   std::string BuildDirectory;
+
+  /// Extra source ranges associated with the diagnostic (in addition to the
+  /// location of the Message above).
+  ArrayRef<CharSourceRange> Ranges;
 };
 
 /// Collection of Diagnostics generated from a single translation unit.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69782.227644.patch
Type: text/x-patch
Size: 2971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191104/ec27f42f/attachment-0001.bin>


More information about the cfe-commits mailing list