Elijah_Th updated this revision to Diff 47302.
Elijah_Th added a comment.

Fixed YAML format (was not correct in the last patch).
Grouped replacements in YAML by Diagnostics. It will help to apply replacements 
for one fix at once.


http://reviews.llvm.org/D16183

Files:
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/Core/Diagnostics.h
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/Diagnostics.cpp
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  
/media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h

Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h
@@ -0,0 +1,55 @@
+//===-- ReplacementsYaml.h -- Serialiazation for Replacements ---*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file defines the structure of a YAML document for serializing
+/// ClangTidy errors.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
+#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H
+
+#include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Core/Diagnostics.h"
+#include "llvm/Support/YAMLTraits.h"
+#include <string>
+#include <vector>
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostics)
+
+namespace llvm {
+namespace yaml {
+    
+template <> struct MappingTraits<clang::tooling::Diagnostics> {
+  static void mapping(IO &Io,
+                      clang::tooling::Diagnostics &D) {
+    std::vector<clang::tooling::Replacement> fixes(D.Fix.begin(), D.Fix.end());
+    Io.mapRequired("CheckName", D.CheckName);
+    Io.mapRequired("Replacements", fixes);
+  }
+};
+
+template <> struct MappingTraits<clang::tooling::TranslationUnitDiagnostics> {
+  static void mapping(IO &Io,
+                      clang::tooling::TranslationUnitDiagnostics &TUD) {
+    Io.mapRequired("MainSourceFile", TUD.MainSourceFile);
+    Io.mapOptional("Context", TUD.Context, std::string());
+    for (clang::tooling::Diagnostics diag : TUD.Diags) {
+        if (diag.Fix.size() > 0) {
+            Io.mapRequired("Diagnostics", diag);
+        }
+    }
+  }
+};
+} // end namespace yaml
+} // end namespace llvm
+
+#endif /* LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H */
+
Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/Core/Diagnostics.h
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/Core/Diagnostics.h
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/include/clang/Tooling/Core/Diagnostics.h
@@ -0,0 +1,70 @@
+//===--- Replacement.h - Framework for clang refactoring tools --*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Classes supporting refactorings that span multiple translation units.
+//  While single translation unit refactorings are supported via the Rewriter,
+//  when refactoring multiple translation units changes must be stored in a
+//  SourceManager independent form, duplicate changes need to be removed, and
+//  all changes must be applied at once at the end of the refactoring so that
+//  the code is always parseable.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLING_CORE_DIAGNOSTICS_H
+#define LLVM_CLANG_TOOLING_CORE_DIAGNOSTICS_H
+
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallVector.h"
+#include "Replacement.h"
+#include <string>
+
+namespace clang {
+    namespace tooling {
+
+        struct DiagnosticsMessage {
+            DiagnosticsMessage(StringRef Message = "");
+            DiagnosticsMessage(StringRef Message, const SourceManager &Sources,
+                    SourceLocation Loc);
+            std::string Message;
+            std::string FilePath;
+            unsigned FileOffset;
+        };
+
+        struct Diagnostics {
+
+            enum Level {
+                Ignored = DiagnosticsEngine::Ignored,
+                Warning = DiagnosticsEngine::Warning,
+                Error = DiagnosticsEngine::Error
+            };
+            
+            Diagnostics();
+
+            Diagnostics(StringRef CheckName, Level DiagLevel);
+
+            std::string CheckName;
+            DiagnosticsMessage Message;
+            tooling::Replacements Fix;
+            SmallVector<DiagnosticsMessage, 1> Notes;
+
+            Level DiagLevel;
+        };
+        
+        struct TranslationUnitDiagnostics {
+          std::string MainSourceFile;
+
+          std::string Context;
+
+          std::vector<Diagnostics> Diags;
+};
+
+    }
+}
+
+#endif
Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/Diagnostics.cpp
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/Diagnostics.cpp
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/Diagnostics.cpp
@@ -0,0 +1,40 @@
+//===--- Replacement.cpp - Framework for clang refactoring tools ----------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Implements classes to support/store refactorings.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Tooling/Core/Diagnostics.h"
+#include "clang/Basic/SourceManager.h"
+
+namespace clang {
+    namespace tooling {
+
+        DiagnosticsMessage::DiagnosticsMessage(StringRef Message)
+        : Message(Message), FileOffset(0) {
+        }
+
+        DiagnosticsMessage::DiagnosticsMessage(StringRef Message,
+                const SourceManager &Sources,
+                SourceLocation Loc)
+        : Message(Message) {
+            assert(Loc.isValid() && Loc.isFileID());
+            FilePath = Sources.getFilename(Loc);
+            FileOffset = Sources.getFileOffset(Loc);
+        }
+        
+        Diagnostics::Diagnostics() : DiagLevel(Ignored) {}
+
+        Diagnostics::Diagnostics(StringRef CheckName,
+                Diagnostics::Level DiagLevel)
+        : CheckName(CheckName), DiagLevel(DiagLevel) {
+        }   
+    }
+}
Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt
@@ -3,6 +3,7 @@
 add_clang_library(clangToolingCore
   Lookup.cpp
   Replacement.cpp
+  Diagnostics.cpp
 
   LINK_LIBS
   clangAST
Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Core/Diagnostics.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Regex.h"
@@ -32,40 +33,8 @@
 
 namespace tidy {
 
-/// \brief A message from a clang-tidy check.
-///
-/// Note that this is independent of a \c SourceManager.
-struct ClangTidyMessage {
-  ClangTidyMessage(StringRef Message = "");
-  ClangTidyMessage(StringRef Message, const SourceManager &Sources,
-                   SourceLocation Loc);
-  std::string Message;
-  std::string FilePath;
-  unsigned FileOffset;
-};
-
-/// \brief A detected error complete with information to display diagnostic and
-/// automatic fix.
-///
-/// This is used as an intermediate format to transport Diagnostics without a
-/// dependency on a SourceManager.
-///
-/// FIXME: Make Diagnostics flexible enough to support this directly.
-struct ClangTidyError {
-  enum Level {
-    Warning = DiagnosticsEngine::Warning,
-    Error = DiagnosticsEngine::Error
-  };
-
-  ClangTidyError(StringRef CheckName, Level DiagLevel);
-
-  std::string CheckName;
-  ClangTidyMessage Message;
-  tooling::Replacements Fix;
-  SmallVector<ClangTidyMessage, 1> Notes;
-
-  Level DiagLevel;
-};
+typedef clang::tooling::DiagnosticsMessage ClangTidyMessage;
+typedef clang::tooling::Diagnostics ClangTidyError;
 
 /// \brief Read-only set of strings represented as a list of positive and
 /// negative globs. Positive globs add all matched strings to the set, negative
Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -102,22 +102,6 @@
 };
 } // end anonymous namespace
 
-ClangTidyMessage::ClangTidyMessage(StringRef Message)
-    : Message(Message), FileOffset(0) {}
-
-ClangTidyMessage::ClangTidyMessage(StringRef Message,
-                                   const SourceManager &Sources,
-                                   SourceLocation Loc)
-    : Message(Message) {
-  assert(Loc.isValid() && Loc.isFileID());
-  FilePath = Sources.getFilename(Loc);
-  FileOffset = Sources.getFileOffset(Loc);
-}
-
-ClangTidyError::ClangTidyError(StringRef CheckName,
-                               ClangTidyError::Level DiagLevel)
-    : CheckName(CheckName), DiagLevel(DiagLevel) {}
-
 // Returns true if GlobList starts with the negative indicator ('-'), removes it
 // from the GlobList.
 static bool ConsumeNegativeIndicator(StringRef &GlobList) {
Index: /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp
===================================================================
--- /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp
+++ /media/SSD_/code/LLVM-code/LLVM-trunk_256412/llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp
@@ -35,6 +35,7 @@
 #include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/ReplacementsYaml.h"
+#include "clang/Tooling/DiagnosticsYaml.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -430,13 +431,10 @@
 
 void exportReplacements(const std::vector<ClangTidyError> &Errors,
                         raw_ostream &OS) {
-  tooling::TranslationUnitReplacements TUR;
-  for (const ClangTidyError &Error : Errors)
-    TUR.Replacements.insert(TUR.Replacements.end(), Error.Fix.begin(),
-                            Error.Fix.end());
-
   yaml::Output YAML(OS);
-  YAML << TUR;
+  TranslationUnitDiagnostics TUD;
+  TUD.Diags.insert(TUD.Diags.end(), Errors.begin(), Errors.end());
+  YAML << TUD;
 }
 
 } // namespace tidy
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to