[PATCH] D49890: Clang-Tidy Export Problem
Ahmad Nouralizadeh via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 27 06:03:01 PDT 2018
TheAhmad updated this revision to Diff 157676.
TheAhmad marked 4 inline comments as done.
TheAhmad added a comment.
Used make_pair instead of constructor call.
Used unique_ptr.
Used named cast.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D49890
Files:
ClangTidy.cpp
Index: ClangTidy.cpp
===================================================================
--- ClangTidy.cpp
+++ ClangTidy.cpp
@@ -608,8 +608,56 @@
raw_ostream &OS) {
TranslationUnitDiagnostics TUD;
TUD.MainSourceFile = MainFilePath;
+
+ std::unique_ptr<FileManager> Files =
+ make_unique<FileManager>(FileSystemOptions());
+ vfs::FileSystem &FileSystem = *Files->getVirtualFileSystem();
+ auto InitialWorkingDir = FileSystem.getCurrentWorkingDirectory();
+ if (!InitialWorkingDir)
+ llvm::report_fatal_error("Cannot get current working path.");
+
+ llvm::StringMap<Replacements> FileReplacements;
+ llvm::StringMap<ClangTidyError> SingleErrors;
for (const auto &Error : Errors) {
- tooling::Diagnostic Diag = Error;
+ if (!Error.BuildDirectory.empty())
+ FileSystem.setCurrentWorkingDirectory(Error.BuildDirectory);
+
+ SmallString<128> ErrorAbsoluteFilePath =
+ static_cast<StringRef>(Error.Message.FilePath);
+ Files->makeAbsolutePath(ErrorAbsoluteFilePath);
+ if (SingleErrors.find(ErrorAbsoluteFilePath) == SingleErrors.end()) {
+ ClangTidyError AbsoluteError = Error;
+ AbsoluteError.Message.FilePath = ErrorAbsoluteFilePath.str();
+ AbsoluteError.Fix.clear();
+ SingleErrors.insert(std::make_pair(ErrorAbsoluteFilePath, AbsoluteError));
+ }
+
+ for (const auto &FileAndReplacements : Error.Fix) {
+ for (const auto &Repl : FileAndReplacements.second) {
+ SmallString<128> FixAbsoluteFilePath = Repl.getFilePath();
+ Files->makeAbsolutePath(FixAbsoluteFilePath);
+
+ tooling::Replacement R(FixAbsoluteFilePath, Repl.getOffset(),
+ Repl.getLength(), Repl.getReplacementText());
+
+ FileReplacements[R.getFilePath()].add(R);
+ }
+ }
+
+ FileSystem.setCurrentWorkingDirectory(InitialWorkingDir.get());
+ }
+
+ for (const auto &FileAndReplacements : FileReplacements) {
+ StringRef File = FileAndReplacements.first();
+ Replacements Repls = FileAndReplacements.second;
+
+ ClangTidyError AbsoluteError = SingleErrors.find(File)->second;
+ if (SingleErrors.find(File) == SingleErrors.end())
+ llvm::report_fatal_error("Cannot find the containing ClangTidyError.");
+
+ AbsoluteError.Fix.insert(std::make_pair(File, Repls));
+
+ tooling::Diagnostic Diag = AbsoluteError;
TUD.Diagnostics.insert(TUD.Diagnostics.end(), Diag);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49890.157676.patch
Type: text/x-patch
Size: 2434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180727/82c46ddc/attachment.bin>
More information about the cfe-commits
mailing list