|
8 | 8 |
|
9 | 9 | #include "ClangTidyOptions.h" |
10 | 10 | #include "ClangTidyModuleRegistry.h" |
| 11 | +#include "clang/Basic/DiagnosticIDs.h" |
11 | 12 | #include "clang/Basic/LLVM.h" |
12 | 13 | #include "llvm/ADT/SmallString.h" |
| 14 | +#include "llvm/ADT/StringExtras.h" |
13 | 15 | #include "llvm/Support/Debug.h" |
14 | | -#include "llvm/Support/Errc.h" |
15 | 16 | #include "llvm/Support/ErrorOr.h" |
16 | | -#include "llvm/Support/FileSystem.h" |
17 | 17 | #include "llvm/Support/MemoryBufferRef.h" |
18 | 18 | #include "llvm/Support/Path.h" |
19 | 19 | #include "llvm/Support/YAMLTraits.h" |
@@ -72,7 +72,8 @@ struct NOptionMap { |
72 | 72 | NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) { |
73 | 73 | Options.reserve(OptionMap.size()); |
74 | 74 | for (const auto &KeyValue : OptionMap) |
75 | | - Options.emplace_back(std::string(KeyValue.getKey()), KeyValue.getValue().Value); |
| 75 | + Options.emplace_back(std::string(KeyValue.getKey()), |
| 76 | + KeyValue.getValue().Value); |
76 | 77 | } |
77 | 78 | ClangTidyOptions::OptionMap denormalize(IO &) { |
78 | 79 | ClangTidyOptions::OptionMap Map; |
@@ -126,6 +127,52 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool, |
126 | 127 | } |
127 | 128 | } |
128 | 129 |
|
| 130 | +namespace { |
| 131 | +struct MultiLineString { |
| 132 | + std::string &S; |
| 133 | +}; |
| 134 | +} // namespace |
| 135 | + |
| 136 | +template <> struct BlockScalarTraits<MultiLineString> { |
| 137 | + static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS) { |
| 138 | + OS << S.S; |
| 139 | + } |
| 140 | + static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S) { |
| 141 | + S.S = Str; |
| 142 | + return ""; |
| 143 | + } |
| 144 | +}; |
| 145 | + |
| 146 | +template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> { |
| 147 | + static void enumeration(IO &IO, clang::DiagnosticIDs::Level &Level) { |
| 148 | + IO.enumCase(Level, "Error", clang::DiagnosticIDs::Level::Error); |
| 149 | + IO.enumCase(Level, "Warning", clang::DiagnosticIDs::Level::Warning); |
| 150 | + IO.enumCase(Level, "Note", clang::DiagnosticIDs::Level::Note); |
| 151 | + } |
| 152 | +}; |
| 153 | +template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> { |
| 154 | + static const bool flow = false; |
| 155 | +}; |
| 156 | +template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> { |
| 157 | + static void mapping(IO &IO, ClangTidyOptions::CustomCheckDiag &D) { |
| 158 | + IO.mapRequired("BindName", D.BindName); |
| 159 | + MultiLineString MLS{D.Message}; |
| 160 | + IO.mapRequired("Message", MLS); |
| 161 | + IO.mapOptional("Level", D.Level); |
| 162 | + } |
| 163 | +}; |
| 164 | +template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> { |
| 165 | + static const bool flow = false; |
| 166 | +}; |
| 167 | +template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> { |
| 168 | + static void mapping(IO &IO, ClangTidyOptions::CustomCheckValue &V) { |
| 169 | + IO.mapRequired("Name", V.Name); |
| 170 | + MultiLineString MLS{V.Query}; |
| 171 | + IO.mapRequired("Query", MLS); |
| 172 | + IO.mapRequired("Diagnostic", V.Diags); |
| 173 | + } |
| 174 | +}; |
| 175 | + |
129 | 176 | struct ChecksVariant { |
130 | 177 | std::optional<std::string> AsString; |
131 | 178 | std::optional<std::vector<std::string>> AsVector; |
@@ -181,6 +228,7 @@ template <> struct MappingTraits<ClangTidyOptions> { |
181 | 228 | IO.mapOptional("InheritParentConfig", Options.InheritParentConfig); |
182 | 229 | IO.mapOptional("UseColor", Options.UseColor); |
183 | 230 | IO.mapOptional("SystemHeaders", Options.SystemHeaders); |
| 231 | + IO.mapOptional("CustomChecks", Options.CustomChecks); |
184 | 232 | } |
185 | 233 | }; |
186 | 234 |
|
@@ -242,7 +290,8 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const ClangTidyOptions &Other, |
242 | 290 | overrideValue(UseColor, Other.UseColor); |
243 | 291 | mergeVectors(ExtraArgs, Other.ExtraArgs); |
244 | 292 | mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore); |
245 | | - |
| 293 | + // FIXME: how to handle duplicate names check? |
| 294 | + mergeVectors(CustomChecks, Other.CustomChecks); |
246 | 295 | for (const auto &KeyValue : Other.CheckOptions) { |
247 | 296 | CheckOptions.insert_or_assign( |
248 | 297 | KeyValue.getKey(), |
|
0 commit comments