[PATCH] D69921: [clang-format] refactor the use of the SMDiagnostics in replacement warnings
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 6 13:38:02 PST 2019
MyDeveloperDay updated this revision to Diff 228133.
MyDeveloperDay added a comment.
Remove unused `Ranges`
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69921/new/
https://reviews.llvm.org/D69921
Files:
clang/tools/clang-format/ClangFormat.cpp
Index: clang/tools/clang-format/ClangFormat.cpp
===================================================================
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -292,56 +292,26 @@
static bool
emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName,
const std::unique_ptr<llvm::MemoryBuffer> &Code) {
- if (Replaces.empty()) {
+ if (Replaces.empty())
return false;
- }
-
- IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
- DiagOpts->ShowColors = (ShowColors && !NoShowColors);
-
- IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
- IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
- new DiagnosticsEngine(DiagID, &*DiagOpts));
-
- IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
- new llvm::vfs::InMemoryFileSystem);
- FileManager Files(FileSystemOptions(), InMemoryFileSystem);
- SourceManager Sources(*Diags, Files);
- FileID FileID = createInMemoryFile(AssumedFileName, Code.get(), Sources,
- Files, InMemoryFileSystem.get());
-
- FileManager &FileMgr = Sources.getFileManager();
- llvm::ErrorOr<const FileEntry *> FileEntryPtr =
- FileMgr.getFile(AssumedFileName);
unsigned Errors = 0;
if (WarnFormat && !NoWarnFormat) {
llvm::SourceMgr Mgr;
for (const auto &R : Replaces) {
- PresumedLoc PLoc = Sources.getPresumedLoc(
- Sources.getLocForStartOfFile(FileID).getLocWithOffset(R.getOffset()));
-
- SourceLocation LineBegin =
- Sources.translateFileLineCol(FileEntryPtr.get(), PLoc.getLine(), 1);
- SourceLocation NextLineBegin = Sources.translateFileLineCol(
- FileEntryPtr.get(), PLoc.getLine() + 1, 1);
-
- const char *StartBuf = Sources.getCharacterData(LineBegin);
- const char *EndBuf = Sources.getCharacterData(NextLineBegin);
+ const char *StartBuf = Code->getBufferStart();
- StringRef Line(StartBuf, (EndBuf - StartBuf) - 1);
+ Mgr.AddNewSourceBuffer(
+ MemoryBuffer::getMemBuffer(StartBuf, AssumedFileName), SMLoc());
- SMDiagnostic Diag(
- Mgr, SMLoc::getFromPointer(StartBuf), AssumedFileName,
- PLoc.getLine(), PLoc.getColumn(),
+ SMDiagnostic Diag = Mgr.GetMessage(
+ SMLoc::getFromPointer(StartBuf + R.getOffset()),
WarningsAsErrors ? SourceMgr::DiagKind::DK_Error
: SourceMgr::DiagKind::DK_Warning,
- "code should be clang-formatted [-Wclang-format-violations]", Line,
- ArrayRef<std::pair<unsigned, unsigned>>());
+ "code should be clang-formatted [-Wclang-format-violations]");
Diag.print(nullptr, llvm::errs(), (ShowColors && !NoShowColors));
- Errors++;
- if (ErrorLimit && Errors >= ErrorLimit)
+ if (ErrorLimit && ++Errors >= ErrorLimit)
break;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69921.228133.patch
Type: text/x-patch
Size: 2941 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191106/687ea6a6/attachment.bin>
More information about the cfe-commits
mailing list