[PATCH] [clang-tidy] Add support for boolean check options.

Manuel Klimek klimek at google.com
Mon Oct 20 11:50:18 PDT 2014


================
Comment at: clang-tidy/ClangTidyOptions.h:79-97
@@ -77,3 +78,21 @@
 
-  typedef std::pair<std::string, std::string> StringPair;
-  typedef std::map<std::string, std::string> OptionMap;
+  struct Option {
+    template <typename T>
+    typename std::enable_if<llvm::yaml::has_ScalarTraits<T>::value, T>::type
+    get(const T &Default) const {
+      T Result = Default;
+      llvm::yaml::ScalarTraits<T>::input(Value, nullptr, Result);
+      return Result;
+    }
+
+    template <typename T>
+    typename std::enable_if<llvm::yaml::has_ScalarTraits<T>::value, void>::type
+    store(const T &TypedValue) {
+      llvm::raw_string_ostream OS(Value);
+      llvm::yaml::ScalarTraits<T>::output(TypedValue, nullptr, OS);
+    }
+
+    std::string Value;
+    std::function<llvm::StringRef(llvm::StringRef)> Validate;
+  };
+
----------------
So, if we want to roll with having the scalar transformations on the class, I'd just make Value private and overload get() and store() for string types - that would also make the outer code symmetrical.

Second, I'm slightly confused about storing the Validate function with the option - it seems to be completely unrelated (it's about the option type, not about the option value).

http://reviews.llvm.org/D5602






More information about the cfe-commits mailing list