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,8 @@ /// \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 +109,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. @@ -116,18 +118,20 @@ /// \brief Returns a human readable string representation. std::string toString() const; - private: - void setFromSourceLocation(const SourceManager &Sources, - SourceLocation Start, unsigned Length, - StringRef ReplacementText); - void setFromSourceRange(const SourceManager &Sources, - const CharSourceRange &Range, - StringRef ReplacementText, - const LangOptions &LangOpts); +private: + void setFromSourceLocation(const SourceManager &Sources, SourceLocation Start, + unsigned Length, StringRef ReplacementText, + StringRef CheckName = ""); + void setFromSourceRange(const SourceManager &Sources, + const CharSourceRange &Range, + StringRef ReplacementText, + 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,30 +33,34 @@ /// 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()) {} + 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) { MappingNormalization - Keys(Io, R); + Keys(Io, R); Io.mapRequired("FilePath", Keys->FilePath); 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) { @@ -43,9 +43,9 @@ Replacement::Replacement(const SourceManager &Sources, const CharSourceRange &Range, - StringRef ReplacementText, - const LangOptions &LangOpts) { - setFromSourceRange(Sources, Range, ReplacementText, LangOpts); + StringRef ReplacementText, const LangOptions &LangOpts, + StringRef CheckName) { + setFromSourceRange(Sources, Range, ReplacementText, LangOpts, CheckName); } bool Replacement::isApplicable() const { @@ -109,13 +109,15 @@ 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); + getRangeSize(Sources, Range, LangOpts), ReplacementText, + CheckName); } template @@ -314,7 +317,7 @@ // Merges the next element 'R' into this merged element. As we always merge // from 'First' into 'Second' or vice versa, the MergedReplacement knows what - // set the next element is coming from. + // set the next element is coming from. void merge(const Replacement &R) { if (MergeSecond) { unsigned REnd = R.getOffset() + Delta + R.getLength(); @@ -416,4 +419,3 @@ } // end namespace tooling } // end namespace clang - 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,8 @@ 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(), Error.CheckName)); } }