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
@@ -184,7 +190,7 @@ struct ChecksVariant {
184190};
185191
186192template <> void yamlize (IO &IO, ChecksVariant &Val, bool , EmptyContext &Ctx) {
187- if (! IO.outputting () ) {
193+ if (IO.getKind () == IOKind::Inputting ) {
188194 // Special case for reading from YAML
189195 // Must support reading from both a string or a list
190196 auto &I = reinterpret_cast <Input &>(IO);
@@ -197,6 +203,9 @@ template <> void yamlize(IO &IO, ChecksVariant &Val, bool, EmptyContext &Ctx) {
197203 } else {
198204 IO.setError (" expected string or sequence" );
199205 }
206+ } else if (IO.getKind () == IOKind::GeneratingSchema) {
207+ Val.AsVector = std::vector<std::string>();
208+ yamlize (IO, *Val.AsVector , true , Ctx);
200209 }
201210}
202211
@@ -543,6 +552,12 @@ parseConfiguration(llvm::MemoryBufferRef Config) {
543552 return Options;
544553}
545554
555+ void dumpConfigurationYAMLSchema (llvm::raw_fd_ostream &Stream) {
556+ ClangTidyOptions Options;
557+ llvm::yaml::GenerateSchema GS (Stream);
558+ GS << Options;
559+ }
560+
546561static void diagHandlerImpl (const llvm::SMDiagnostic &Diag, void *Ctx) {
547562 (*reinterpret_cast <DiagCallback *>(Ctx))(Diag);
548563}
0 commit comments