1616#include " llvm/Support/ErrorOr.h"
1717#include " llvm/Support/MemoryBufferRef.h"
1818#include " llvm/Support/Path.h"
19+ #include " llvm/Support/YAMLGenerateSchema.h"
1920#include " llvm/Support/YAMLTraits.h"
2021#include < algorithm>
2122#include < optional>
@@ -87,7 +88,7 @@ struct NOptionMap {
8788template <>
8889void yamlize (IO &IO, ClangTidyOptions::OptionMap &Val, bool ,
8990 EmptyContext &Ctx) {
90- if (IO.outputting () ) {
91+ if (IO.getKind () == IOKind::Outputting ) {
9192 // Ensure check options are sorted
9293 std::vector<std::pair<StringRef, StringRef>> SortedOptions;
9394 SortedOptions.reserve (Val.size ());
@@ -108,7 +109,7 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
108109 IO.postflightKey (SaveInfo);
109110 }
110111 IO.endMapping ();
111- } else {
112+ } else if (IO. getKind () == IOKind::Inputting) {
112113 // We need custom logic here to support the old method of specifying check
113114 // options using a list of maps containing key and value keys.
114115 auto &I = reinterpret_cast <Input &>(IO);
@@ -128,6 +129,11 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
128129 } else {
129130 IO.setError (" expected a sequence or map" );
130131 }
132+ } else {
133+ MappingNormalization<NOptionMap, ClangTidyOptions::OptionMap> NOpts (IO,
134+ Val);
135+ EmptyContext Ctx;
136+ yamlize (IO, NOpts->Options , true , Ctx);
131137 }
132138}
133139
@@ -182,7 +188,7 @@ struct ChecksVariant {
182188};
183189
184190template <> void yamlize (IO &IO, ChecksVariant &Val, bool , EmptyContext &Ctx) {
185- if (! IO.outputting () ) {
191+ if (IO.getKind () == IOKind::Inputting ) {
186192 // Special case for reading from YAML
187193 // Must support reading from both a string or a list
188194 auto &I = reinterpret_cast <Input &>(IO);
@@ -195,6 +201,9 @@ template <> void yamlize(IO &IO, ChecksVariant &Val, bool, EmptyContext &Ctx) {
195201 } else {
196202 IO.setError (" expected string or sequence" );
197203 }
204+ } else if (IO.getKind () == IOKind::GeneratingSchema) {
205+ Val.AsVector = std::vector<std::string>();
206+ yamlize (IO, *Val.AsVector , true , Ctx);
198207 }
199208}
200209
@@ -541,6 +550,12 @@ parseConfiguration(llvm::MemoryBufferRef Config) {
541550 return Options;
542551}
543552
553+ void dumpConfigurationYAMLSchema (llvm::raw_fd_ostream &Stream) {
554+ ClangTidyOptions Options;
555+ llvm::yaml::GenerateSchema GS (Stream);
556+ GS << Options;
557+ }
558+
544559static void diagHandlerImpl (const llvm::SMDiagnostic &Diag, void *Ctx) {
545560 (*reinterpret_cast <DiagCallback *>(Ctx))(Diag);
546561}
0 commit comments