Index: tools/clang/include/clang/Tooling/Core/Replacement.h =================================================================== --- tools/clang/include/clang/Tooling/Core/Replacement.h +++ tools/clang/include/clang/Tooling/Core/Replacement.h @@ -79,7 +79,7 @@ /// \param Offset The byte offset of the start of the range in the file. /// \param Length The length of the range in bytes. Replacement(StringRef FilePath, unsigned Offset, unsigned Length, - StringRef ReplacementText); + StringRef ReplacementText, StringRef CheckName = ""); /// \brief Creates a Replacement of the range [Start, Start+Length) with /// ReplacementText. @@ -89,7 +89,9 @@ /// \brief Creates a Replacement of the given range with ReplacementText. Replacement(const SourceManager &Sources, const CharSourceRange &Range, StringRef ReplacementText, - const LangOptions &LangOpts = LangOptions()); + const LangOptions &LangOpts = LangOptions(), + StringRef CheckName = "" + ); /// \brief Creates a Replacement of the node with ReplacementText. template @@ -108,6 +110,7 @@ unsigned getOffset() const { return ReplacementRange.getOffset(); } unsigned getLength() const { return ReplacementRange.getLength(); } StringRef getReplacementText() const { return ReplacementText; } + StringRef getCheckName() const {return CheckName; } /// @} /// \brief Applies the replacement on the Rewriter. @@ -119,15 +122,17 @@ private: void setFromSourceLocation(const SourceManager &Sources, SourceLocation Start, unsigned Length, - StringRef ReplacementText); + StringRef ReplacementText, StringRef CheckName = ""); void setFromSourceRange(const SourceManager &Sources, const CharSourceRange &Range, StringRef ReplacementText, - const LangOptions &LangOpts); + const LangOptions &LangOpts, + StringRef CheckName = ""); std::string FilePath; Range ReplacementRange; std::string ReplacementText; + std::string CheckName; }; /// \brief Less-than operator between two Replacements. Index: tools/clang/include/clang/Tooling/ReplacementsYaml.h =================================================================== --- tools/clang/include/clang/Tooling/ReplacementsYaml.h +++ tools/clang/include/clang/Tooling/ReplacementsYaml.h @@ -33,21 +33,22 @@ /// access to its data members. struct NormalizedReplacement { NormalizedReplacement(const IO &) - : FilePath(""), Offset(0), Length(0), ReplacementText("") {} + : FilePath(""), Offset(0), Length(0), ReplacementText(""), CheckName("") {} NormalizedReplacement(const IO &, const clang::tooling::Replacement &R) - : FilePath(R.getFilePath()), Offset(R.getOffset()), - Length(R.getLength()), ReplacementText(R.getReplacementText()) {} + : FilePath(R.getFilePath()), Offset(R.getOffset()), Length(R.getLength()), + ReplacementText(R.getReplacementText()), CheckName(R.getCheckName()) {} clang::tooling::Replacement denormalize(const IO &) { return clang::tooling::Replacement(FilePath, Offset, Length, - ReplacementText); + ReplacementText, CheckName); } std::string FilePath; unsigned int Offset; unsigned int Length; std::string ReplacementText; + std::string CheckName; }; static void mapping(IO &Io, clang::tooling::Replacement &R) { @@ -57,6 +58,7 @@ Io.mapRequired("Offset", Keys->Offset); Io.mapRequired("Length", Keys->Length); Io.mapRequired("ReplacementText", Keys->ReplacementText); + Io.mapRequired("CheckName", Keys->CheckName); } }; Index: tools/clang/lib/Tooling/Core/Replacement.cpp =================================================================== --- tools/clang/lib/Tooling/Core/Replacement.cpp +++ tools/clang/lib/Tooling/Core/Replacement.cpp @@ -32,9 +32,9 @@ : FilePath(InvalidLocation) {} Replacement::Replacement(StringRef FilePath, unsigned Offset, unsigned Length, - StringRef ReplacementText) + StringRef ReplacementText, StringRef CheckName) : FilePath(FilePath), ReplacementRange(Offset, Length), - ReplacementText(ReplacementText) {} + ReplacementText(ReplacementText), CheckName(CheckName) {} Replacement::Replacement(const SourceManager &Sources, SourceLocation Start, unsigned Length, StringRef ReplacementText) { @@ -44,8 +44,9 @@ Replacement::Replacement(const SourceManager &Sources, const CharSourceRange &Range, StringRef ReplacementText, - const LangOptions &LangOpts) { - setFromSourceRange(Sources, Range, ReplacementText, LangOpts); + const LangOptions &LangOpts, + StringRef CheckName) { + setFromSourceRange(Sources, Range, ReplacementText, LangOpts, CheckName); } bool Replacement::isApplicable() const { @@ -109,13 +110,14 @@ void Replacement::setFromSourceLocation(const SourceManager &Sources, SourceLocation Start, unsigned Length, - StringRef ReplacementText) { + StringRef ReplacementText, StringRef CheckName) { const std::pair DecomposedLocation = Sources.getDecomposedLoc(Start); const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); this->FilePath = Entry ? Entry->getName() : InvalidLocation; this->ReplacementRange = Range(DecomposedLocation.second, Length); this->ReplacementText = ReplacementText; + this->CheckName = CheckName; } // FIXME: This should go into the Lexer, but we need to figure out how @@ -137,10 +139,11 @@ void Replacement::setFromSourceRange(const SourceManager &Sources, const CharSourceRange &Range, StringRef ReplacementText, - const LangOptions &LangOpts) { + const LangOptions &LangOpts, + StringRef CheckName) { setFromSourceLocation(Sources, Sources.getSpellingLoc(Range.getBegin()), getRangeSize(Sources, Range, LangOpts), - ReplacementText); + ReplacementText, CheckName); } template Index: tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp =================================================================== --- tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -77,7 +77,7 @@ assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() && "Only file locations supported in fix-it hints."); - Error.Fix.insert(tooling::Replacement(SM, Range, FixIt.CodeToInsert)); + Error.Fix.insert(tooling::Replacement(SM, Range, FixIt.CodeToInsert, LangOptions(), StringRef(Error.CheckName))); } }