[llvm] 8b61376 - YAMLParser: llvm::Optional => std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 01:34:39 PST 2022
Author: Fangrui Song
Date: 2022-12-15T09:34:31Z
New Revision: 8b61376dfa1d67ef2776bcb4a5f92095132ce2fa
URL: https://github.com/llvm/llvm-project/commit/8b61376dfa1d67ef2776bcb4a5f92095132ce2fa
DIFF: https://github.com/llvm/llvm-project/commit/8b61376dfa1d67ef2776bcb4a5f92095132ce2fa.diff
LOG: YAMLParser: llvm::Optional => std::optional
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
llvm/include/llvm/Support/YAMLParser.h
llvm/lib/Support/YAMLParser.cpp
llvm/lib/Support/YAMLTraits.cpp
llvm/unittests/Support/YAMLParserTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 6bb0b2ac32513..fedf3aa27169c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -92,7 +92,7 @@ ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
static Optional<bool> getAsBool(StringRef Value,
const llvm::Twine &LookupName) {
- if (llvm::Optional<bool> Parsed = llvm::yaml::parseBool(Value))
+ if (std::optional<bool> Parsed = llvm::yaml::parseBool(Value))
return *Parsed;
// To maintain backwards compatability, we support parsing numbers as
// booleans, even though its not supported in YAML.
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 2cd40ed774a8a..524cd90105278 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -424,8 +424,7 @@ bool IdentifierNamingCheck::HungarianNotation::isOptionEnabled(
if (Iter == StrMap.end())
return false;
- llvm::Optional<bool> Parsed = llvm::yaml::parseBool(Iter->getValue());
- return *Parsed;
+ return *llvm::yaml::parseBool(Iter->getValue());
}
void IdentifierNamingCheck::HungarianNotation::loadFileConfig(
diff --git a/llvm/include/llvm/Support/YAMLParser.h b/llvm/include/llvm/Support/YAMLParser.h
index 231cc1d28c9a0..8c5561e905502 100644
--- a/llvm/include/llvm/Support/YAMLParser.h
+++ b/llvm/include/llvm/Support/YAMLParser.h
@@ -45,6 +45,7 @@
#include <iterator>
#include <map>
#include <memory>
+#include <optional>
#include <string>
#include <system_error>
@@ -78,7 +79,7 @@ bool scanTokens(StringRef Input);
std::string escape(StringRef Input, bool EscapePrintable = true);
/// Parse \p S as a bool according to https://yaml.org/type/bool.html.
-llvm::Optional<bool> parseBool(StringRef S);
+std::optional<bool> parseBool(StringRef S);
/// This class represents a YAML stream potentially containing multiple
/// documents.
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 7dbb16fe88f74..b85b1eb83ef89 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -760,7 +760,7 @@ std::string yaml::escape(StringRef Input, bool EscapePrintable) {
return EscapedInput;
}
-llvm::Optional<bool> yaml::parseBool(StringRef S) {
+std::optional<bool> yaml::parseBool(StringRef S) {
switch (S.size()) {
case 1:
switch (S.front()) {
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 8cdd03149bcfa..4eb0b3afd5630 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -886,7 +886,7 @@ void ScalarTraits<bool>::output(const bool &Val, void *, raw_ostream &Out) {
}
StringRef ScalarTraits<bool>::input(StringRef Scalar, void *, bool &Val) {
- if (llvm::Optional<bool> Parsed = parseBool(Scalar)) {
+ if (std::optional<bool> Parsed = parseBool(Scalar)) {
Val = *Parsed;
return StringRef();
}
diff --git a/llvm/unittests/Support/YAMLParserTest.cpp b/llvm/unittests/Support/YAMLParserTest.cpp
index 14def9c528875..b52a3850c02b7 100644
--- a/llvm/unittests/Support/YAMLParserTest.cpp
+++ b/llvm/unittests/Support/YAMLParserTest.cpp
@@ -343,7 +343,7 @@ TEST(YAMLParser, FlowSequenceTokensOutsideFlowSequence) {
}
static void expectCanParseBool(StringRef S, bool Expected) {
- llvm::Optional<bool> Parsed = yaml::parseBool(S);
+ std::optional<bool> Parsed = yaml::parseBool(S);
EXPECT_TRUE(Parsed.has_value());
EXPECT_EQ(*Parsed, Expected);
}
More information about the llvm-commits
mailing list