Author: Krzysztof Parzyszek Date: 2022-12-09T10:27:48-06:00 New Revision: e52b9bf64f0487f6ec5a6a7b24f95f31ab83fb8b
URL: https://github.com/llvm/llvm-project/commit/e52b9bf64f0487f6ec5a6a7b24f95f31ab83fb8b DIFF: https://github.com/llvm/llvm-project/commit/e52b9bf64f0487f6ec5a6a7b24f95f31ab83fb8b.diff LOG: [STLExtras] Convert deref_or_none and zip_longest to std::optional Added: Modified: clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTStructuralEquivalence.cpp clang/lib/Sema/SemaOverload.cpp llvm/include/llvm/ADT/STLExtras.h llvm/include/llvm/Support/Format.h llvm/unittests/ADT/IteratorTest.cpp llvm/unittests/Support/raw_ostream_test.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index e6f360fe79533..dd7e0bfecdaeb 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -94,6 +94,7 @@ #include <cstdlib> #include <map> #include <memory> +#include <optional> #include <string> #include <tuple> #include <utility> @@ -6493,8 +6494,8 @@ static bool hasSameOverloadableAttrs(const FunctionDecl *A, auto BEnableIfAttrs = B->specific_attrs<EnableIfAttr>(); for (auto Pair : zip_longest(AEnableIfAttrs, BEnableIfAttrs)) { - Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); - Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); + std::optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); + std::optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); // Return false if the number of enable_if attributes is diff erent. if (!Cand1A || !Cand2A) diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 66846dde85f58..e383170079b1e 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -91,6 +91,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> +#include <optional> #include <utility> using namespace clang; @@ -238,8 +239,8 @@ class StmtComparer { const GenericSelectionExpr *E2) { for (auto Pair : zip_longest(E1->getAssocTypeSourceInfos(), E2->getAssocTypeSourceInfos())) { - Optional<TypeSourceInfo *> Child1 = std::get<0>(Pair); - Optional<TypeSourceInfo *> Child2 = std::get<1>(Pair); + std::optional<TypeSourceInfo *> Child1 = std::get<0>(Pair); + std::optional<TypeSourceInfo *> Child2 = std::get<1>(Pair); // Skip this case if there are a diff erent number of associated types. if (!Child1 || !Child2) return false; @@ -310,8 +311,8 @@ class StmtComparer { return false; for (auto Pair : zip_longest(E1->getArgs(), E2->getArgs())) { - Optional<TypeSourceInfo *> Child1 = std::get<0>(Pair); - Optional<TypeSourceInfo *> Child2 = std::get<1>(Pair); + std::optional<TypeSourceInfo *> Child1 = std::get<0>(Pair); + std::optional<TypeSourceInfo *> Child2 = std::get<1>(Pair); // Different number of args. if (!Child1 || !Child2) return false; @@ -400,8 +401,8 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, // Iterate over the children of both statements and also compare them. for (auto Pair : zip_longest(S1->children(), S2->children())) { - Optional<const Stmt *> Child1 = std::get<0>(Pair); - Optional<const Stmt *> Child2 = std::get<1>(Pair); + std::optional<const Stmt *> Child1 = std::get<0>(Pair); + std::optional<const Stmt *> Child2 = std::get<1>(Pair); // One of the statements has a diff erent amount of children than the other, // so the statements can't be equivalent. if (!Child1 || !Child2) diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 31298c6cd5175..7f3d400fc67ee 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -40,6 +40,7 @@ #include "llvm/Support/Casting.h" #include <algorithm> #include <cstdlib> +#include <optional> using namespace clang; using namespace sema; @@ -9654,8 +9655,8 @@ static Comparison compareEnableIfAttrs(const Sema &S, const FunctionDecl *Cand1, llvm::FoldingSetNodeID Cand1ID, Cand2ID; for (auto Pair : zip_longest(Cand1Attrs, Cand2Attrs)) { - Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); - Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); + std::optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); + std::optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); // It's impossible for Cand1 to be better than (or equal to) Cand2 if Cand1 // has fewer enable_if attributes than Cand2, and vice versa. diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 28c13a8390e62..1354268bc2822 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -18,7 +18,6 @@ #define LLVM_ADT_STLEXTRAS_H #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLForwardCompat.h" #include "llvm/ADT/STLFunctionalExtras.h" #include "llvm/ADT/identity.h" @@ -921,7 +920,7 @@ Iter next_or_end(const Iter &I, const Iter &End) { } template <typename Iter> -auto deref_or_none(const Iter &I, const Iter &End) -> llvm::Optional< +auto deref_or_none(const Iter &I, const Iter &End) -> std::optional< std::remove_const_t<std::remove_reference_t<decltype(*I)>>> { if (I == End) return std::nullopt; @@ -929,7 +928,7 @@ auto deref_or_none(const Iter &I, const Iter &End) -> llvm::Optional< } template <typename Iter> struct ZipLongestItemType { - using type = llvm::Optional<std::remove_const_t< + using type = std::optional<std::remove_const_t< std::remove_reference_t<decltype(*std::declval<Iter>())>>>; }; @@ -1030,7 +1029,7 @@ template <typename... Args> class zip_longest_range { } // namespace detail /// Iterate over two or more iterators at the same time. Iteration continues -/// until all iterators reach the end. The llvm::Optional only contains a value +/// until all iterators reach the end. The std::optional only contains a value /// if the iterator has not reached the end. template <typename T, typename U, typename... Args> detail::zip_longest_range<T, U, Args...> zip_longest(T &&t, U &&u, diff --git a/llvm/include/llvm/Support/Format.h b/llvm/include/llvm/Support/Format.h index d6308a88c1894..c22c941ae06ef 100644 --- a/llvm/include/llvm/Support/Format.h +++ b/llvm/include/llvm/Support/Format.h @@ -216,7 +216,7 @@ class FormattedBytes { ArrayRef<uint8_t> Bytes; // If not None, display offsets for each line relative to starting value. - Optional<uint64_t> FirstByteOffset; + std::optional<uint64_t> FirstByteOffset; uint32_t IndentLevel; // Number of characters to indent each line. uint32_t NumPerLine; // Number of bytes to show per line. uint8_t ByteGroupSize; // How many hex bytes are grouped without spaces @@ -225,7 +225,7 @@ class FormattedBytes { friend class raw_ostream; public: - FormattedBytes(ArrayRef<uint8_t> B, uint32_t IL, Optional<uint64_t> O, + FormattedBytes(ArrayRef<uint8_t> B, uint32_t IL, std::optional<uint64_t> O, uint32_t NPL, uint8_t BGS, bool U, bool A) : Bytes(B), FirstByteOffset(O), IndentLevel(IL), NumPerLine(NPL), ByteGroupSize(BGS), Upper(U), ASCII(A) { @@ -237,7 +237,7 @@ class FormattedBytes { inline FormattedBytes format_bytes(ArrayRef<uint8_t> Bytes, - Optional<uint64_t> FirstByteOffset = std::nullopt, + std::optional<uint64_t> FirstByteOffset = std::nullopt, uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4, uint32_t IndentLevel = 0, bool Upper = false) { return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine, @@ -246,7 +246,7 @@ format_bytes(ArrayRef<uint8_t> Bytes, inline FormattedBytes format_bytes_with_ascii(ArrayRef<uint8_t> Bytes, - Optional<uint64_t> FirstByteOffset = std::nullopt, + std::optional<uint64_t> FirstByteOffset = std::nullopt, uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4, uint32_t IndentLevel = 0, bool Upper = false) { return FormattedBytes(Bytes, IndentLevel, FirstByteOffset, NumPerLine, diff --git a/llvm/unittests/ADT/IteratorTest.cpp b/llvm/unittests/ADT/IteratorTest.cpp index 69cfadb6aa178..641ff4fcc7f54 100644 --- a/llvm/unittests/ADT/IteratorTest.cpp +++ b/llvm/unittests/ADT/IteratorTest.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "gtest/gtest.h" +#include <optional> using namespace llvm; @@ -478,7 +479,7 @@ TEST(ZipIteratorTest, ZipLongestBasic) { { // Check left range longer than right. - const vector<tuple<Optional<unsigned>, Optional<StringRef>>> expected{ + const vector<tuple<optional<unsigned>, optional<StringRef>>> expected{ make_tuple(3, StringRef("2")), make_tuple(1, StringRef("7")), make_tuple(4, StringRef("1")), make_tuple(1, StringRef("8")), make_tuple(5, std::nullopt), make_tuple(9, std::nullopt)}; @@ -492,7 +493,7 @@ TEST(ZipIteratorTest, ZipLongestBasic) { { // Check right range longer than left. - const vector<tuple<Optional<StringRef>, Optional<unsigned>>> expected{ + const vector<tuple<optional<StringRef>, optional<unsigned>>> expected{ make_tuple(StringRef("2"), 3), make_tuple(StringRef("7"), 1), make_tuple(StringRef("1"), 4), make_tuple(StringRef("8"), 1), make_tuple(std::nullopt, 5), make_tuple(std::nullopt, 9)}; diff --git a/llvm/unittests/Support/raw_ostream_test.cpp b/llvm/unittests/Support/raw_ostream_test.cpp index 84006cb0b3151..4a8c58716fa93 100644 --- a/llvm/unittests/Support/raw_ostream_test.cpp +++ b/llvm/unittests/Support/raw_ostream_test.cpp @@ -15,6 +15,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" +#include <optional> using namespace llvm; @@ -206,7 +207,7 @@ TEST(raw_ostreamTest, FormatDecimal) { static std::string formatted_bytes_str(ArrayRef<uint8_t> Bytes, - llvm::Optional<uint64_t> Offset = std::nullopt, + std::optional<uint64_t> Offset = std::nullopt, uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4) { std::string S; raw_string_ostream Str(S); @@ -216,7 +217,7 @@ formatted_bytes_str(ArrayRef<uint8_t> Bytes, } static std::string format_bytes_with_ascii_str( - ArrayRef<uint8_t> Bytes, Optional<uint64_t> Offset = std::nullopt, + ArrayRef<uint8_t> Bytes, std::optional<uint64_t> Offset = std::nullopt, uint32_t NumPerLine = 16, uint8_t ByteGroupSize = 4) { std::string S; raw_string_ostream Str(S); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits