[PATCH] D92920: [clang-tidy] Add a diagnostic callback to parseConfiguration
Nathan James via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 9 03:06:57 PST 2020
njames93 updated this revision to Diff 310476.
njames93 added a comment.
Use MemoryBufferRef instead of StringRef so the Diagnostic can have a meaningful filename.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92920/new/
https://reviews.llvm.org/D92920
Files:
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.h
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.h
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -14,6 +14,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <functional>
#include <string>
@@ -313,6 +314,11 @@
/// error.
llvm::ErrorOr<ClangTidyOptions> parseConfiguration(llvm::StringRef Config);
+using DiagCallback = llvm::function_ref<void(const llvm::SMDiagnostic &)>;
+
+llvm::ErrorOr<ClangTidyOptions>
+parseConfigurationWithDiags(llvm::MemoryBufferRef Config, DiagCallback Handler);
+
/// Serializes configuration to a YAML-encoded string.
std::string configurationAsText(const ClangTidyOptions &Options);
Index: clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -13,6 +13,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
@@ -389,6 +390,22 @@
return Options;
}
+static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
+ (*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
+};
+
+llvm::ErrorOr<ClangTidyOptions>
+parseConfigurationWithDiags(llvm::MemoryBufferRef Config,
+ DiagCallback Handler) {
+ llvm::yaml::Input Input(Config, nullptr, Handler ? diagHandlerImpl : nullptr,
+ &Handler);
+ ClangTidyOptions Options;
+ Input >> Options;
+ if (Input.error())
+ return Input.error();
+ return Options;
+}
+
std::string configurationAsText(const ClangTidyOptions &Options) {
std::string Text;
llvm::raw_string_ostream Stream(Text);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92920.310476.patch
Type: text/x-patch
Size: 2108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201209/a0f27a6c/attachment.bin>
More information about the cfe-commits
mailing list