Skip to content

Commit 6fa8f7e

Browse files
committed
impl option
1 parent 421b26b commit 6fa8f7e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
#include "ClangTidyModuleRegistry.h"
1111
#include "clang/Basic/LLVM.h"
1212
#include "llvm/ADT/SmallString.h"
13+
#include "llvm/ADT/StringExtras.h"
1314
#include "llvm/Support/Debug.h"
14-
#include "llvm/Support/Errc.h"
1515
#include "llvm/Support/ErrorOr.h"
16-
#include "llvm/Support/FileSystem.h"
1716
#include "llvm/Support/MemoryBufferRef.h"
1817
#include "llvm/Support/Path.h"
1918
#include "llvm/Support/YAMLTraits.h"
@@ -126,6 +125,34 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
126125
}
127126
}
128127

128+
namespace {
129+
struct MultiLineString {
130+
std::string &S;
131+
};
132+
} // namespace
133+
134+
template <> struct BlockScalarTraits<MultiLineString> {
135+
static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS) {
136+
OS << S.S;
137+
}
138+
139+
static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S) {
140+
S.S = Str;
141+
return "";
142+
}
143+
};
144+
145+
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
146+
static const bool flow = false;
147+
};
148+
template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
149+
static void mapping(IO &IO, ClangTidyOptions::CustomCheckValue &V) {
150+
IO.mapRequired("Name", V.Name);
151+
MultiLineString MLS{V.Query};
152+
IO.mapRequired("Query", MLS);
153+
}
154+
};
155+
129156
struct ChecksVariant {
130157
std::optional<std::string> AsString;
131158
std::optional<std::vector<std::string>> AsVector;
@@ -181,6 +208,7 @@ template <> struct MappingTraits<ClangTidyOptions> {
181208
IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
182209
IO.mapOptional("UseColor", Options.UseColor);
183210
IO.mapOptional("SystemHeaders", Options.SystemHeaders);
211+
IO.mapOptional("CustomeChecks", Options.CustomChecks);
184212
}
185213
};
186214

@@ -249,6 +277,8 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other,
249277
ClangTidyValue(KeyValue.getValue().Value,
250278
KeyValue.getValue().Priority + Order));
251279
}
280+
mergeVectors(CustomChecks, Other.CustomChecks);
281+
252282
return *this;
253283
}
254284

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ struct ClangTidyOptions {
129129
/// Key-value mapping used to store check-specific options.
130130
OptionMap CheckOptions;
131131

132+
struct CustomCheckValue {
133+
std::string Name;
134+
std::string Query;
135+
// FIXME: extend more features here (e.g. isLanguageVersionSupported, Level)
136+
};
137+
using CustomCheckValueList = llvm::SmallVector<CustomCheckValue>;
138+
std::optional<CustomCheckValueList> CustomChecks;
139+
132140
using ArgList = std::vector<std::string>;
133141

134142
/// Add extra compilation arguments to the end of the list.

0 commit comments

Comments
 (0)