Unverified Commit fcf0f75a authored by Nathan James's avatar Nathan James
Browse files

[clang-tidy] OptionsView::store specialized on bool

Following on fcf7cc26 and 672207c3 which granted checks the ability to read boolean configuration arguments as `true` or `false`.
This enables storing the options back to the configuration file using `true` and `false`.
This is in line with how clang-format dumps boolean options in its style config.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D83053
parent d1ca9960
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -155,12 +155,19 @@ void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
  Options[NamePrefix + LocalName.str()] = Value;
}

void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options,
                                           StringRef LocalName,
                                           int64_t Value) const {
  store(Options, LocalName, llvm::itostr(Value));
}

template <>
void ClangTidyCheck::OptionsView::store<bool>(
    ClangTidyOptions::OptionMap &Options, StringRef LocalName,
    bool Value) const {
  store(Options, LocalName, Value ? StringRef("true") : StringRef("false"));
}

llvm::Expected<int64_t>
ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
                                        ArrayRef<NameAndValue> Mapping,
+17 −3
Original line number Diff line number Diff line
@@ -405,9 +405,13 @@ public:
               StringRef Value) const;

    /// Stores an option with the check-local name \p LocalName with
    /// ``int64_t`` value \p Value to \p Options.
    void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
               int64_t Value) const;
    /// integer value \p Value to \p Options.
    template <typename T>
    std::enable_if_t<std::is_integral<T>::value>
    store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
          T Value) const {
      storeInt(Options, LocalName, Value);
    }

    /// Stores an option with the check-local name \p LocalName as the string
    /// representation of the Enum \p Value to \p Options.
@@ -448,6 +452,9 @@ public:
      return Result;
    }

    void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
                  int64_t Value) const;

    static void logErrToStdErr(llvm::Error &&Err);

    std::string NamePrefix;
@@ -509,6 +516,13 @@ template <>
bool ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName,
                                                         bool Default) const;

/// Stores an option with the check-local name \p LocalName with
/// bool value \p Value to \p Options.
template <>
void ClangTidyCheck::OptionsView::store<bool>(
    ClangTidyOptions::OptionMap &Options, StringRef LocalName,
    bool Value) const;

} // namespace tidy
} // namespace clang

+3 −3
Original line number Diff line number Diff line
@@ -18,13 +18,13 @@
// RUN: clang-tidy -dump-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-CHILD4
// CHECK-CHILD4: Checks: {{.*}}modernize-loop-convert,modernize-use-using,llvm-qualified-auto
// CHECK-CHILD4: - key: llvm-qualified-auto.AddConstToQualified
// CHECK-CHILD4-NEXT: value: '1'
// CHECK-CHILD4-NEXT: value: 'true'
// CHECK-CHILD4: - key: modernize-loop-convert.MaxCopySize
// CHECK-CHILD4-NEXT: value: '20'
// CHECK-CHILD4: - key: modernize-loop-convert.MinConfidence
// CHECK-CHILD4-NEXT: value: reasonable
// CHECK-CHILD4: - key: modernize-use-using.IgnoreMacros
// CHECK-CHILD4-NEXT: value: '0'
// CHECK-CHILD4-NEXT: value: 'false'

// RUN: clang-tidy --explain-config %S/Inputs/config-files/4/44/- -- | FileCheck %s -check-prefix=CHECK-EXPLAIN
// CHECK-EXPLAIN: 'llvm-qualified-auto' is enabled in the {{.*}}{{[/\\]}}Inputs{{[/\\]}}config-files{{[/\\]}}4{{[/\\]}}44{{[/\\]}}.clang-tidy.
@@ -42,7 +42,7 @@
// CHECK-CHILD5: - key: modernize-loop-convert.MinConfidence
// CHECK-CHILD5-NEXT: value: reasonable
// CHECK-CHILD5: - key: modernize-use-using.IgnoreMacros
// CHECK-CHILD5-NEXT: value: '0'
// CHECK-CHILD5-NEXT: value: 'false'

// RUN: clang-tidy -dump-config \
// RUN: --config='{InheritParentConfig: false, \