[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. Ping Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. This shouldn't affect diagnostics without fixes. If there is no fix, there won't be anything to export, and the diagnostic just behaves normally. Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. In https://reviews.llvm.org/D26137#602602, @malcolm.parsons wrote: > In https://reviews.llvm.org/D26137#602591, @Alpha wrote: > > > This shouldn't affect diagnostics without fixes. If there is no fix, there > > won't be anything to export, and the diagnostic just behaves normally. > > > That's a shame; I need a machine readable report of all diagnostics. This is not the aim of this change-set. The objective here is only to associate a replacement to the diagnostic from which it was emitted. But having a parse-able output for all clang-tidy's diagnostics can indeed be a nice feature to add in a different patch. Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha created this revision. Alpha added reviewers: alexfh, klimek, djasper. Alpha added a subscriber: cfe-commits. Herald added subscribers: fhahn, mgorny. Add a field indicating the associated check for every replacement to the YAML report generated with the '-export-fixes' option. Update clang-apply-replacements to handle the new format. Follow-up to https://reviews.llvm.org/D16183 https://reviews.llvm.org/D26137 Files: llvm/tools/clang/include/clang/Tooling/Core/Diagnostic.h llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt llvm/tools/clang/lib/Tooling/Core/Diagnostic.cpp llvm/tools/clang/tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h llvm/tools/clang/tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp llvm/tools/clang/tools/extra/clang-tidy/ClangTidy.cpp llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp llvm/tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h Index: llvm/tools/clang/lib/Tooling/Core/Diagnostic.cpp === --- llvm/tools/clang/lib/Tooling/Core/Diagnostic.cpp +++ llvm/tools/clang/lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,43 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics 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 diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, Diagnostic::Level DiagLevel) +: CheckName(CheckName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, DiagnosticMessage &Message, + llvm::StringMap &Fix, + SmallVector &Notes, + Level DiagLevel) +: CheckName(CheckName), Message(Message), Fix(Fix), Notes(Notes), + DiagLevel(DiagLevel) {} + +} // end namespace tooling +} // end namespace clang Index: llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt === --- llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt +++ llvm/tools/clang/lib/Tooling/Core/CMakeLists.txt @@ -4,7 +4,8 @@ Lookup.cpp Replacement.cpp QualTypeNames.cpp + Diagnostic.cpp LINK_LIBS clangAST clangBasic Index: llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h === --- llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h +++ llvm/tools/clang/include/clang/Tooling/DiagnosticsYaml.h @@ -0,0 +1,81 @@ +//===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- 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 +/// diagnostics. +/// +//===--===// + +#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H +#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "llvm/Support/YAMLTraits.h" +#include + +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic) + +namespace llvm { +namespace yaml { + +/// \brief Specialized MappingTraits to describe how a Diagnostic is +/// (de)serialized. +template <> struct MappingTraits { + /// \brief Helper to (de)serialize a Diagnostic since we don't have direct + /// access to its data members. + class NormalizedDiagnostic { + public: +NormalizedDiagnostic(const IO &) +: CheckName(""), Message(), Fix(), Notes(), DiagLevel() {} + +NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D) +: CheckName(D.CheckName), Message(Message), Fix(D.Fix), Notes(D.Notes), + DiagLevel(D.DiagLevel) {}
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha removed rL LLVM as the repository for this revision. Alpha updated this revision to Diff 76849. Alpha added a comment. Fix diagnostic deserialization bug for clang-apply-replacement. https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/DiagnosticsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,43 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics 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 diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, Diagnostic::Level DiagLevel) +: CheckName(CheckName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, DiagnosticMessage &Message, + llvm::StringMap &Fix, + SmallVector &Notes, + Level DiagLevel) +: CheckName(CheckName), Message(Message), Fix(Fix), Notes(Notes), + DiagLevel(DiagLevel) {} + +} // end namespace tooling +} // end namespace clang Index: lib/Tooling/Core/CMakeLists.txt === --- lib/Tooling/Core/CMakeLists.txt +++ lib/Tooling/Core/CMakeLists.txt @@ -4,6 +4,7 @@ Lookup.cpp Replacement.cpp QualTypeNames.cpp + Diagnostic.cpp LINK_LIBS clangAST Index: include/clang/Tooling/DiagnosticsYaml.h === --- include/clang/Tooling/DiagnosticsYaml.h +++ include/clang/Tooling/DiagnosticsYaml.h @@ -0,0 +1,77 @@ +//===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- 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 +/// diagnostics. +/// +//===--===// + +#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H +#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "llvm/Support/YAMLTraits.h" +#include + +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic) + +namespace llvm { +namespace yaml { + +template <> struct MappingTraits { + /// \brief Helper to (de)serialize a Diagnostic since we don't have direct + /// access to its data members. + class NormalizedDiagnostic { + public: +NormalizedDiagnostic(const IO &) +: CheckName(""), Message(), Fix(), Notes(), DiagLevel() {} + +NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D) +: CheckName(D.CheckName), Message(Message), Fix(D.Fix), Notes(D.Notes), + DiagLevel(D.DiagLevel) {} + +clang::tooling::Diagnostic denormalize(const IO &) { + return clang::tooling::Diagnostic(CheckName, Message, Fix, Notes, +DiagLevel); +} + +std::string CheckName; +clang::tooling::DiagnosticMessage Message; +llvm::StringMap Fix; +SmallVector Notes; +clang::tooling::Diagnostic::Level DiagLevel; + }; + + static void mapping(IO &Io, clang::tooling::Diagnostic &D) { +MappingNormalization Keys( +Io, D); +Io.mapRequired("CheckName", Keys->CheckN
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 76850. Alpha added a comment. Remove debug symbols. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/DiagnosticsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,43 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics 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 diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, Diagnostic::Level DiagLevel) +: CheckName(CheckName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, DiagnosticMessage &Message, + llvm::StringMap &Fix, + SmallVector &Notes, + Level DiagLevel) +: CheckName(CheckName), Message(Message), Fix(Fix), Notes(Notes), + DiagLevel(DiagLevel) {} + +} // end namespace tooling +} // end namespace clang Index: lib/Tooling/Core/CMakeLists.txt === --- lib/Tooling/Core/CMakeLists.txt +++ lib/Tooling/Core/CMakeLists.txt @@ -4,6 +4,7 @@ Lookup.cpp Replacement.cpp QualTypeNames.cpp + Diagnostic.cpp LINK_LIBS clangAST Index: include/clang/Tooling/DiagnosticsYaml.h === --- include/clang/Tooling/DiagnosticsYaml.h +++ include/clang/Tooling/DiagnosticsYaml.h @@ -0,0 +1,77 @@ +//===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- 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 +/// diagnostics. +/// +//===--===// + +#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H +#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "llvm/Support/YAMLTraits.h" +#include + +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic) + +namespace llvm { +namespace yaml { + +template <> struct MappingTraits { + /// \brief Helper to (de)serialize a Diagnostic since we don't have direct + /// access to its data members. + class NormalizedDiagnostic { + public: +NormalizedDiagnostic(const IO &) +: CheckName(""), Message(), Fix(), Notes(), DiagLevel() {} + +NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D) +: CheckName(D.CheckName), Message(Message), Fix(D.Fix), Notes(D.Notes), + DiagLevel(D.DiagLevel) {} + +clang::tooling::Diagnostic denormalize(const IO &) { + return clang::tooling::Diagnostic(CheckName, Message, Fix, Notes, +DiagLevel); +} + +std::string CheckName; +clang::tooling::DiagnosticMessage Message; +llvm::StringMap Fix; +SmallVector Notes; +clang::tooling::Diagnostic::Level DiagLevel; + }; + + static void mapping(IO &Io, clang::tooling::Diagnostic &D) { +MappingNormalization Keys( +Io, D); +Io.mapRequired("CheckName", Keys->CheckName); +std::vector Fixes; +Io.mapRequired("Replacements", Fixes); +
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. Ping Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 77029. Alpha added a comment. Ignore export of empty fixes. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/DiagnosticsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,43 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics 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 diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, Diagnostic::Level DiagLevel) +: CheckName(CheckName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef CheckName, DiagnosticMessage &Message, + llvm::StringMap &Fix, + SmallVector &Notes, + Level DiagLevel) +: CheckName(CheckName), Message(Message), Fix(Fix), Notes(Notes), + DiagLevel(DiagLevel) {} + +} // end namespace tooling +} // end namespace clang Index: lib/Tooling/Core/CMakeLists.txt === --- lib/Tooling/Core/CMakeLists.txt +++ lib/Tooling/Core/CMakeLists.txt @@ -4,6 +4,7 @@ Lookup.cpp Replacement.cpp QualTypeNames.cpp + Diagnostic.cpp LINK_LIBS clangAST Index: include/clang/Tooling/DiagnosticsYaml.h === --- include/clang/Tooling/DiagnosticsYaml.h +++ include/clang/Tooling/DiagnosticsYaml.h @@ -0,0 +1,90 @@ +//===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- 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 +/// diagnostics. +/// +//===--===// + +#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H +#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "llvm/Support/YAMLTraits.h" +#include + +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic) + +namespace llvm { +namespace yaml { + +template <> struct MappingTraits { + /// \brief Helper to (de)serialize a Diagnostic since we don't have direct + /// access to its data members. + class NormalizedDiagnostic { + public: +NormalizedDiagnostic(const IO &) +: CheckName(""), Message(), Fix(), Notes(), DiagLevel() {} + +NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D) +: CheckName(D.CheckName), Message(Message), Fix(D.Fix), Notes(D.Notes), + DiagLevel(D.DiagLevel) {} + +clang::tooling::Diagnostic denormalize(const IO &) { + return clang::tooling::Diagnostic(CheckName, Message, Fix, Notes, +DiagLevel); +} + +std::string CheckName; +clang::tooling::DiagnosticMessage Message; +llvm::StringMap Fix; +SmallVector Notes; +clang::tooling::Diagnostic::Level DiagLevel; + }; + + static void mapping(IO &Io, clang::tooling::Diagnostic &D) { +MappingNormalization Keys( +Io, D); +Io.mapRequired("CheckName", Keys->CheckName); +std::vector Fixes; +for (auto & Replacements : Keys->Fi
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added inline comments. Comment at: include/clang/Tooling/Core/Diagnostic.h:35 + DiagnosticMessage(llvm::StringRef Message, const SourceManager &Sources, +SourceLocation Loc); + std::string Message; alexfh wrote: > What are the constraints on the location? Should it be a file location or > macro locations are fine too? Please add a (doxygen-style) comment. Indeed, this should be a file location. Comment at: include/clang/Tooling/Core/Diagnostic.h:68-71 + /// A freeform chunk of text to describe the context of the replacements. + /// Will be printed, for example, when detecting conflicts during replacement + /// deduplication. + std::string Context; alexfh wrote: > That's too vague. Are you intending to use it only for reporting problems > with replacement deduplication? Should it be in this structure at all? This was actually left to keep compatibility with `TranslationUnitReplacements` which was used for the export. But it seems that even for that structure, there is in all likelihood no reference to any use of the `Context` field, except in test cases and in the Yaml IO mapping, where it is marked as an optional entry. Should it be discarded instead (here, and thus also in `TranslationUnitReplacements`)? Comment at: tools/extra/clang-tidy/ClangTidy.cpp:578 raw_ostream &OS) { - TranslationUnitReplacements TUR; - for (const ClangTidyError &Error : Errors) { -for (const auto &FileAndFixes : Error.Fix) - TUR.Replacements.insert(TUR.Replacements.end(), - FileAndFixes.second.begin(), - FileAndFixes.second.end()); - } - + TranslationUnitDiagnostics TUD; + TUD.Diagnostics.insert(TUD.Diagnostics.end(), Errors.begin(), Errors.end()); alexfh wrote: > This function neither fills `TUD.MainSourceFile` nor `TUD.Context` (which I'm > not sure even belongs to this structure). Done for `MainSourceFile` which was surprisingly never exported with the fixes. For `Context`, see above comment about the 'TranslationUnitDiagnostics' structure. Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha updated this revision to Diff 77196. Alpha added a comment. Export effectively MainSourceFile. Change CheckName field. Add doxygen-style comments. Repository: rL LLVM https://reviews.llvm.org/D26137 Files: include/clang/Tooling/Core/Diagnostic.h include/clang/Tooling/DiagnosticsYaml.h lib/Tooling/Core/CMakeLists.txt lib/Tooling/Core/Diagnostic.cpp tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h tools/extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp tools/extra/clang-tidy/ClangTidy.cpp tools/extra/clang-tidy/ClangTidy.h tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.h tools/extra/clang-tidy/tool/ClangTidyMain.cpp Index: lib/Tooling/Core/Diagnostic.cpp === --- lib/Tooling/Core/Diagnostic.cpp +++ lib/Tooling/Core/Diagnostic.cpp @@ -0,0 +1,45 @@ +//===--- Diagnostic.cpp - Framework for clang diagnostics 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 diagnostics refactoring. +// +//===--===// + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceManager.h" + +namespace clang { +namespace tooling { + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message) +: Message(Message), FileOffset(0) {} + +DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, + const SourceManager &Sources, + SourceLocation Loc) +: Message(Message) { + assert(Loc.isValid() && Loc.isFileID()); + FilePath = Sources.getFilename(Loc); + FileOffset = Sources.getFileOffset(Loc); +} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + Diagnostic::Level DiagLevel) +: DiagnosticName(DiagnosticName), DiagLevel(DiagLevel) {} + +Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, + DiagnosticMessage &Message, + llvm::StringMap &Fix, + SmallVector &Notes, + Level DiagLevel) +: DiagnosticName(DiagnosticName), Message(Message), Fix(Fix), Notes(Notes), + DiagLevel(DiagLevel) {} + +} // end namespace tooling +} // end namespace clang Index: lib/Tooling/Core/CMakeLists.txt === --- lib/Tooling/Core/CMakeLists.txt +++ lib/Tooling/Core/CMakeLists.txt @@ -4,6 +4,7 @@ Lookup.cpp Replacement.cpp QualTypeNames.cpp + Diagnostic.cpp LINK_LIBS clangAST Index: include/clang/Tooling/DiagnosticsYaml.h === --- include/clang/Tooling/DiagnosticsYaml.h +++ include/clang/Tooling/DiagnosticsYaml.h @@ -0,0 +1,90 @@ +//===-- DiagnosticsYaml.h -- Serialiazation for Diagnosticss ---*- 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 +/// diagnostics. +/// +//===--===// + +#ifndef LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H +#define LLVM_CLANG_TOOLING_DIAGNOSTICSYAML_H + +#include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Tooling/ReplacementsYaml.h" +#include "llvm/Support/YAMLTraits.h" +#include + +LLVM_YAML_IS_SEQUENCE_VECTOR(clang::tooling::Diagnostic) + +namespace llvm { +namespace yaml { + +template <> struct MappingTraits { + /// \brief Helper to (de)serialize a Diagnostic since we don't have direct + /// access to its data members. + class NormalizedDiagnostic { + public: +NormalizedDiagnostic(const IO &) +: DiagnosticName(""), Message(), Fix(), Notes(), DiagLevel() {} + +NormalizedDiagnostic(const IO &, const clang::tooling::Diagnostic &D) +: DiagnosticName(D.DiagnosticName), Message(Message), Fix(D.Fix), + Notes(D.Notes), DiagLevel(D.DiagLevel) {} + +clang::tooling::Diagnostic denormalize(const IO &) { + return clang::tooling::Diagnostic(DiagnosticName, Message, Fix, Notes, +DiagLevel); +} + +std::string DiagnosticName; +clang::tooling::DiagnosticMessage Message; +llvm::StringMap Fix; +SmallVector Notes; +clang::tooling::Diagnostic::Level Di
[PATCH] D26137: [clang-tidy] Add check name to YAML export
Alpha added a comment. Ping Repository: rL LLVM https://reviews.llvm.org/D26137 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits