diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-10-28 00:24:26 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2017-10-28 00:24:26 +0000 |
commit | 8e07bd488771eaacaa5281ddcd8e6c734c81c3a6 (patch) | |
tree | b85c5440627bfff3a1d62a408ac96bb6bfe00c94 | |
parent | f405b11224a1514bb921487cd8f1be19ff649aa4 (diff) | |
download | bcm5719-llvm-8e07bd488771eaacaa5281ddcd8e6c734c81c3a6.tar.gz bcm5719-llvm-8e07bd488771eaacaa5281ddcd8e6c734c81c3a6.zip |
[ADT] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 316818
-rw-r--r-- | llvm/include/llvm/ADT/FoldingSet.h | 44 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/PointerIntPair.h | 31 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/PointerSumType.h | 50 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/PointerUnion.h | 79 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/STLExtras.h | 122 | ||||
-rw-r--r-- | llvm/include/llvm/ADT/Twine.h | 54 |
6 files changed, 195 insertions, 185 deletions
diff --git a/llvm/include/llvm/ADT/FoldingSet.h b/llvm/include/llvm/ADT/FoldingSet.h index c5987a947e1..e363e69d032 100644 --- a/llvm/include/llvm/ADT/FoldingSet.h +++ b/llvm/include/llvm/ADT/FoldingSet.h @@ -1,4 +1,4 @@ -//===-- llvm/ADT/FoldingSet.h - Uniquing Hash Set ---------------*- C++ -*-===// +//===- llvm/ADT/FoldingSet.h - Uniquing Hash Set ----------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -115,11 +115,9 @@ class FoldingSetBase { protected: /// Buckets - Array of bucket chains. - /// void **Buckets; /// NumBuckets - Length of the Buckets array. Always a power of 2. - /// unsigned NumBuckets; /// NumNodes - Number of nodes in the folding set. Growth occurs when NumNodes @@ -135,14 +133,13 @@ public: //===--------------------------------------------------------------------===// /// Node - This class is used to maintain the singly linked bucket list in /// a folding set. - /// class Node { private: // NextInFoldingSetBucket - next link in the bucket list. - void *NextInFoldingSetBucket; + void *NextInFoldingSetBucket = nullptr; public: - Node() : NextInFoldingSetBucket(nullptr) {} + Node() = default; // Accessors void *getNextInBucket() const { return NextInFoldingSetBucket; } @@ -221,7 +218,6 @@ protected: /// DefaultFoldingSetTrait - This class provides default implementations /// for FoldingSetTrait implementations. -/// template<typename T> struct DefaultFoldingSetTrait { static void Profile(const T &X, FoldingSetNodeID &ID) { X.Profile(ID); @@ -307,7 +303,6 @@ public: /// FoldingSetNodeID - This class is used to gather all the unique data bits of /// a node. When all the bits are gathered this class is used to produce a /// hash value for the node. -/// class FoldingSetNodeID { /// Bits - Vector of all the data bits that make the node unique. /// Use a SmallVector to avoid a heap allocation in the common case. @@ -320,7 +315,6 @@ public: : Bits(Ref.getData(), Ref.getData() + Ref.getSize()) {} /// Add* - Add various data types to Bit data. - /// void AddPointer(const void *Ptr); void AddInteger(signed I); void AddInteger(unsigned I); @@ -344,7 +338,6 @@ public: unsigned ComputeHash() const; /// operator== - Used to compare two nodes to each other. - /// bool operator==(const FoldingSetNodeID &RHS) const; bool operator==(const FoldingSetNodeIDRef RHS) const; @@ -363,7 +356,7 @@ public: }; // Convenience type to hide the implementation of the folding set. -typedef FoldingSetBase::Node FoldingSetNode; +using FoldingSetNode = FoldingSetBase::Node; template<class T> class FoldingSetIterator; template<class T> class FoldingSetBucketIterator; @@ -415,15 +408,17 @@ protected: ~FoldingSetImpl() = default; public: - typedef FoldingSetIterator<T> iterator; + using iterator = FoldingSetIterator<T>; + iterator begin() { return iterator(Buckets); } iterator end() { return iterator(Buckets+NumBuckets); } - typedef FoldingSetIterator<const T> const_iterator; + using const_iterator = FoldingSetIterator<const T>; + const_iterator begin() const { return const_iterator(Buckets); } const_iterator end() const { return const_iterator(Buckets+NumBuckets); } - typedef FoldingSetBucketIterator<T> bucket_iterator; + using bucket_iterator = FoldingSetBucketIterator<T>; bucket_iterator bucket_begin(unsigned hash) { return bucket_iterator(Buckets + (hash & (NumBuckets-1))); @@ -503,9 +498,7 @@ template <class T> class FoldingSet final : public FoldingSetImpl<T> { } public: - explicit FoldingSet(unsigned Log2InitSize = 6) - : Super(Log2InitSize) {} - + explicit FoldingSet(unsigned Log2InitSize = 6) : Super(Log2InitSize) {} FoldingSet(FoldingSet &&Arg) = default; FoldingSet &operator=(FoldingSet &&RHS) = default; }; @@ -552,8 +545,7 @@ class ContextualFoldingSet final : public FoldingSetImpl<T> { public: explicit ContextualFoldingSet(Ctx Context, unsigned Log2InitSize = 6) - : Super(Log2InitSize), Context(Context) - {} + : Super(Log2InitSize), Context(Context) {} Ctx getContext() const { return Context; } }; @@ -569,15 +561,15 @@ class FoldingSetVector { VectorT Vector; public: - explicit FoldingSetVector(unsigned Log2InitSize = 6) - : Set(Log2InitSize) { - } + explicit FoldingSetVector(unsigned Log2InitSize = 6) : Set(Log2InitSize) {} + + using iterator = pointee_iterator<typename VectorT::iterator>; - typedef pointee_iterator<typename VectorT::iterator> iterator; iterator begin() { return Vector.begin(); } iterator end() { return Vector.end(); } - typedef pointee_iterator<typename VectorT::const_iterator> const_iterator; + using const_iterator = pointee_iterator<typename VectorT::const_iterator>; + const_iterator begin() const { return Vector.begin(); } const_iterator end() const { return Vector.end(); } @@ -667,15 +659,13 @@ public: /// FoldingSetBucketIteratorImpl - This is the common bucket iterator support /// shared by all folding sets, which knows how to walk a particular bucket /// of a folding set hash table. - class FoldingSetBucketIteratorImpl { protected: void *Ptr; explicit FoldingSetBucketIteratorImpl(void **Bucket); - FoldingSetBucketIteratorImpl(void **Bucket, bool) - : Ptr(Bucket) {} + FoldingSetBucketIteratorImpl(void **Bucket, bool) : Ptr(Bucket) {} void advance() { void *Probe = static_cast<FoldingSetNode*>(Ptr)->getNextInBucket(); diff --git a/llvm/include/llvm/ADT/PointerIntPair.h b/llvm/include/llvm/ADT/PointerIntPair.h index eb5a3369900..884d05155bf 100644 --- a/llvm/include/llvm/ADT/PointerIntPair.h +++ b/llvm/include/llvm/ADT/PointerIntPair.h @@ -14,15 +14,14 @@ #ifndef LLVM_ADT_POINTERINTPAIR_H #define LLVM_ADT_POINTERINTPAIR_H -#include "llvm/Support/Compiler.h" #include "llvm/Support/PointerLikeTypeTraits.h" #include <cassert> +#include <cstdint> #include <limits> namespace llvm { template <typename T> struct DenseMapInfo; - template <typename PointerT, unsigned IntBits, typename PtrTraits> struct PointerIntPairInfo; @@ -39,25 +38,24 @@ struct PointerIntPairInfo; /// for something else. For example, this allows: /// PointerIntPair<PointerIntPair<void*, 1, bool>, 1, bool> /// ... and the two bools will land in different bits. -/// template <typename PointerTy, unsigned IntBits, typename IntType = unsigned, typename PtrTraits = PointerLikeTypeTraits<PointerTy>, typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>> class PointerIntPair { - intptr_t Value; + intptr_t Value = 0; public: - constexpr PointerIntPair() : Value(0) {} + constexpr PointerIntPair() = default; + PointerIntPair(PointerTy PtrVal, IntType IntVal) { setPointerAndInt(PtrVal, IntVal); } + explicit PointerIntPair(PointerTy PtrVal) { initWithPointer(PtrVal); } PointerTy getPointer() const { return Info::getPointer(Value); } - IntType getInt() const { - return (IntType)Info::getInt(Value); - } + IntType getInt() const { return (IntType)Info::getInt(Value); } void setPointer(PointerTy PtrVal) { Value = Info::updatePointer(Value, PtrVal); @@ -88,6 +86,7 @@ public: } void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); } + void setFromOpaqueValue(void *Val) { Value = reinterpret_cast<intptr_t>(Val); } @@ -108,14 +107,18 @@ public: bool operator==(const PointerIntPair &RHS) const { return Value == RHS.Value; } + bool operator!=(const PointerIntPair &RHS) const { return Value != RHS.Value; } + bool operator<(const PointerIntPair &RHS) const { return Value < RHS.Value; } bool operator>(const PointerIntPair &RHS) const { return Value > RHS.Value; } + bool operator<=(const PointerIntPair &RHS) const { return Value <= RHS.Value; } + bool operator>=(const PointerIntPair &RHS) const { return Value >= RHS.Value; } @@ -180,21 +183,25 @@ struct isPodLike<PointerIntPair<PointerTy, IntBits, IntType>> { // Provide specialization of DenseMapInfo for PointerIntPair. template <typename PointerTy, unsigned IntBits, typename IntType> struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType>> { - typedef PointerIntPair<PointerTy, IntBits, IntType> Ty; + using Ty = PointerIntPair<PointerTy, IntBits, IntType>; + static Ty getEmptyKey() { uintptr_t Val = static_cast<uintptr_t>(-1); Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable; return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val)); } + static Ty getTombstoneKey() { uintptr_t Val = static_cast<uintptr_t>(-2); Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable; return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val)); } + static unsigned getHashValue(Ty V) { uintptr_t IV = reinterpret_cast<uintptr_t>(V.getOpaqueValue()); return unsigned(IV) ^ unsigned(IV >> 9); } + static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; } }; @@ -207,16 +214,20 @@ struct PointerLikeTypeTraits< getAsVoidPointer(const PointerIntPair<PointerTy, IntBits, IntType> &P) { return P.getOpaqueValue(); } + static inline PointerIntPair<PointerTy, IntBits, IntType> getFromVoidPointer(void *P) { return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); } + static inline PointerIntPair<PointerTy, IntBits, IntType> getFromVoidPointer(const void *P) { return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); } + enum { NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits }; }; } // end namespace llvm -#endif + +#endif // LLVM_ADT_POINTERINTPAIR_H diff --git a/llvm/include/llvm/ADT/PointerSumType.h b/llvm/include/llvm/ADT/PointerSumType.h index 1a49e062dc2..e37957160d9 100644 --- a/llvm/include/llvm/ADT/PointerSumType.h +++ b/llvm/include/llvm/ADT/PointerSumType.h @@ -11,8 +11,10 @@ #define LLVM_ADT_POINTERSUMTYPE_H #include "llvm/ADT/DenseMapInfo.h" -#include "llvm/Support/Compiler.h" #include "llvm/Support/PointerLikeTypeTraits.h" +#include <cassert> +#include <cstdint> +#include <type_traits> namespace llvm { @@ -24,16 +26,15 @@ template <uintptr_t N, typename PointerArgT, typename TraitsArgT = PointerLikeTypeTraits<PointerArgT>> struct PointerSumTypeMember { enum { Tag = N }; - typedef PointerArgT PointerT; - typedef TraitsArgT TraitsT; + using PointerT = PointerArgT; + using TraitsT = TraitsArgT; }; namespace detail { -template <typename TagT, typename... MemberTs> -struct PointerSumTypeHelper; +template <typename TagT, typename... MemberTs> struct PointerSumTypeHelper; -} +} // end namespace detail /// A sum type over pointer-like types. /// @@ -60,12 +61,12 @@ struct PointerSumTypeHelper; /// There is no support for constructing or accessing with a dynamic tag as /// that would fundamentally violate the type safety provided by the sum type. template <typename TagT, typename... MemberTs> class PointerSumType { - uintptr_t Value; + uintptr_t Value = 0; - typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT; + using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>; public: - constexpr PointerSumType() : Value(0) {} + constexpr PointerSumType() = default; /// A typed constructor for a specific tagged member of the sum type. template <TagT N> @@ -128,14 +129,14 @@ struct PointerSumTypeHelper : MemberTs... { template <TagT N> static void LookupOverload(...); template <TagT N> struct Lookup { // Compute a particular member type by resolving the lookup helper ovorload. - typedef decltype(LookupOverload<N>( - static_cast<PointerSumTypeHelper *>(nullptr))) MemberT; + using MemberT = decltype( + LookupOverload<N>(static_cast<PointerSumTypeHelper *>(nullptr))); /// The Nth member's pointer type. - typedef typename MemberT::PointerT PointerT; + using PointerT = typename MemberT::PointerT; /// The Nth member's traits type. - typedef typename MemberT::TraitsT TraitsT; + using TraitsT = typename MemberT::TraitsT; }; // Next we need to compute the number of bits available for the discriminant @@ -171,35 +172,36 @@ struct PointerSumTypeHelper : MemberTs... { "Each member must pass the checker."); }; -} +} // end namespace detail // Teach DenseMap how to use PointerSumTypes as keys. template <typename TagT, typename... MemberTs> struct DenseMapInfo<PointerSumType<TagT, MemberTs...>> { - typedef PointerSumType<TagT, MemberTs...> SumType; - - typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT; + using SumType = PointerSumType<TagT, MemberTs...>; + using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>; enum { SomeTag = HelperT::MinTag }; - typedef typename HelperT::template Lookup<HelperT::MinTag>::PointerT - SomePointerT; - typedef DenseMapInfo<SomePointerT> SomePointerInfo; + using SomePointerT = + typename HelperT::template Lookup<HelperT::MinTag>::PointerT; + using SomePointerInfo = DenseMapInfo<SomePointerT>; static inline SumType getEmptyKey() { return SumType::create<SomeTag>(SomePointerInfo::getEmptyKey()); } + static inline SumType getTombstoneKey() { - return SumType::create<SomeTag>( - SomePointerInfo::getTombstoneKey()); + return SumType::create<SomeTag>(SomePointerInfo::getTombstoneKey()); } + static unsigned getHashValue(const SumType &Arg) { uintptr_t OpaqueValue = Arg.getOpaqueValue(); return DenseMapInfo<uintptr_t>::getHashValue(OpaqueValue); } + static bool isEqual(const SumType &LHS, const SumType &RHS) { return LHS == RHS; } }; -} +} // end namespace llvm -#endif +#endif // LLVM_ADT_POINTERSUMTYPE_H diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h index d019edb57e5..4276859e925 100644 --- a/llvm/include/llvm/ADT/PointerUnion.h +++ b/llvm/include/llvm/ADT/PointerUnion.h @@ -25,7 +25,7 @@ namespace llvm { template <typename T> struct PointerUnionTypeSelectorReturn { - typedef T Return; + using Return = T; }; /// Get a type based on whether two types are the same or not. @@ -33,25 +33,25 @@ template <typename T> struct PointerUnionTypeSelectorReturn { /// For: /// /// \code -/// typedef typename PointerUnionTypeSelector<T1, T2, EQ, NE>::Return Ret; +/// using Ret = typename PointerUnionTypeSelector<T1, T2, EQ, NE>::Return; /// \endcode /// /// Ret will be EQ type if T1 is same as T2 or NE type otherwise. template <typename T1, typename T2, typename RET_EQ, typename RET_NE> struct PointerUnionTypeSelector { - typedef typename PointerUnionTypeSelectorReturn<RET_NE>::Return Return; + using Return = typename PointerUnionTypeSelectorReturn<RET_NE>::Return; }; template <typename T, typename RET_EQ, typename RET_NE> struct PointerUnionTypeSelector<T, T, RET_EQ, RET_NE> { - typedef typename PointerUnionTypeSelectorReturn<RET_EQ>::Return Return; + using Return = typename PointerUnionTypeSelectorReturn<RET_EQ>::Return; }; template <typename T1, typename T2, typename RET_EQ, typename RET_NE> struct PointerUnionTypeSelectorReturn< PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>> { - typedef - typename PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>::Return Return; + using Return = + typename PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>::Return; }; /// Provide PointerLikeTypeTraits for void* that is used by PointerUnion @@ -86,8 +86,8 @@ public: /// X = P.get<int*>(); // runtime assertion failure. template <typename PT1, typename PT2> class PointerUnion { public: - typedef PointerIntPair<void *, 1, bool, PointerUnionUIntTraits<PT1, PT2>> - ValTy; + using ValTy = + PointerIntPair<void *, 1, bool, PointerUnionUIntTraits<PT1, PT2>>; private: ValTy Val; @@ -102,7 +102,6 @@ private: public: PointerUnion() = default; - PointerUnion(PT1 V) : Val(const_cast<void *>( PointerLikeTypeTraits<PT1>::getAsVoidPointer(V))) {} @@ -117,14 +116,15 @@ public: // we recursively strip off low bits if we have a nested PointerUnion. return !PointerLikeTypeTraits<PT1>::getFromVoidPointer(Val.getPointer()); } + explicit operator bool() const { return !isNull(); } /// Test if the Union currently holds the type matching T. template <typename T> int is() const { - typedef typename ::llvm::PointerUnionTypeSelector< - PT1, T, IsPT1, ::llvm::PointerUnionTypeSelector< - PT2, T, IsPT2, UNION_DOESNT_CONTAIN_TYPE<T>>>::Return - Ty; + using Ty = typename ::llvm::PointerUnionTypeSelector< + PT1, T, IsPT1, + ::llvm::PointerUnionTypeSelector<PT2, T, IsPT2, + UNION_DOESNT_CONTAIN_TYPE<T>>>::Return; int TyNo = Ty::Num; return static_cast<int>(Val.getInt()) == TyNo; } @@ -158,7 +158,8 @@ public: assert( get<PT1>() == Val.getPointer() && "Can't get the address because PointerLikeTypeTraits changes the ptr"); - return const_cast<PT1 *>(reinterpret_cast<const PT1 *>(Val.getAddrOfPointer())); + return const_cast<PT1 *>( + reinterpret_cast<const PT1 *>(Val.getAddrOfPointer())); } /// Assignment from nullptr which just clears the union. @@ -227,19 +228,22 @@ struct PointerLikeTypeTraits<PointerUnion<PT1, PT2>> { /// for usage. template <typename PT1, typename PT2, typename PT3> class PointerUnion3 { public: - typedef PointerUnion<PT1, PT2> InnerUnion; - typedef PointerUnion<InnerUnion, PT3> ValTy; + using InnerUnion = PointerUnion<PT1, PT2>; + using ValTy = PointerUnion<InnerUnion, PT3>; private: ValTy Val; struct IsInnerUnion { ValTy Val; + IsInnerUnion(ValTy val) : Val(val) {} + template <typename T> int is() const { return Val.template is<InnerUnion>() && Val.template get<InnerUnion>().template is<T>(); } + template <typename T> T get() const { return Val.template get<InnerUnion>().template get<T>(); } @@ -247,14 +251,15 @@ private: struct IsPT3 { ValTy Val; + IsPT3(ValTy val) : Val(val) {} + template <typename T> int is() const { return Val.template is<T>(); } template <typename T> T get() const { return Val.template get<T>(); } }; public: PointerUnion3() = default; - PointerUnion3(PT1 V) { Val = InnerUnion(V); } PointerUnion3(PT2 V) { Val = InnerUnion(V); } PointerUnion3(PT3 V) { Val = V; } @@ -267,10 +272,9 @@ public: /// Test if the Union currently holds the type matching T. template <typename T> int is() const { // If T is PT1/PT2 choose IsInnerUnion otherwise choose IsPT3. - typedef typename ::llvm::PointerUnionTypeSelector< + using Ty = typename ::llvm::PointerUnionTypeSelector< PT1, T, IsInnerUnion, - ::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return - Ty; + ::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return; return Ty(Val).template is<T>(); } @@ -280,10 +284,9 @@ public: template <typename T> T get() const { assert(is<T>() && "Invalid accessor called"); // If T is PT1/PT2 choose IsInnerUnion otherwise choose IsPT3. - typedef typename ::llvm::PointerUnionTypeSelector< + using Ty = typename ::llvm::PointerUnionTypeSelector< PT1, T, IsInnerUnion, - ::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return - Ty; + ::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return; return Ty(Val).template get<T>(); } @@ -348,16 +351,15 @@ struct PointerLikeTypeTraits<PointerUnion3<PT1, PT2, PT3>> { template <typename PT1, typename PT2, typename PT3, typename PT4> class PointerUnion4 { public: - typedef PointerUnion<PT1, PT2> InnerUnion1; - typedef PointerUnion<PT3, PT4> InnerUnion2; - typedef PointerUnion<InnerUnion1, InnerUnion2> ValTy; + using InnerUnion1 = PointerUnion<PT1, PT2>; + using InnerUnion2 = PointerUnion<PT3, PT4>; + using ValTy = PointerUnion<InnerUnion1, InnerUnion2>; private: ValTy Val; public: PointerUnion4() = default; - PointerUnion4(PT1 V) { Val = InnerUnion1(V); } PointerUnion4(PT2 V) { Val = InnerUnion1(V); } PointerUnion4(PT3 V) { Val = InnerUnion2(V); } @@ -371,9 +373,10 @@ public: /// Test if the Union currently holds the type matching T. template <typename T> int is() const { // If T is PT1/PT2 choose InnerUnion1 otherwise choose InnerUnion2. - typedef typename ::llvm::PointerUnionTypeSelector< - PT1, T, InnerUnion1, ::llvm::PointerUnionTypeSelector< - PT2, T, InnerUnion1, InnerUnion2>>::Return Ty; + using Ty = typename ::llvm::PointerUnionTypeSelector< + PT1, T, InnerUnion1, + ::llvm::PointerUnionTypeSelector<PT2, T, InnerUnion1, + InnerUnion2>>::Return; return Val.template is<Ty>() && Val.template get<Ty>().template is<T>(); } @@ -383,9 +386,10 @@ public: template <typename T> T get() const { assert(is<T>() && "Invalid accessor called"); // If T is PT1/PT2 choose InnerUnion1 otherwise choose InnerUnion2. - typedef typename ::llvm::PointerUnionTypeSelector< - PT1, T, InnerUnion1, ::llvm::PointerUnionTypeSelector< - PT2, T, InnerUnion1, InnerUnion2>>::Return Ty; + using Ty = typename ::llvm::PointerUnionTypeSelector< + PT1, T, InnerUnion1, + ::llvm::PointerUnionTypeSelector<PT2, T, InnerUnion1, + InnerUnion2>>::Return; return Val.template get<Ty>().template get<T>(); } @@ -452,18 +456,21 @@ struct PointerLikeTypeTraits<PointerUnion4<PT1, PT2, PT3, PT4>> { // Teach DenseMap how to use PointerUnions as keys. template <typename T, typename U> struct DenseMapInfo<PointerUnion<T, U>> { - typedef PointerUnion<T, U> Pair; - typedef DenseMapInfo<T> FirstInfo; - typedef DenseMapInfo<U> SecondInfo; + using Pair = PointerUnion<T, U>; + using FirstInfo = DenseMapInfo<T>; + using SecondInfo = DenseMapInfo<U>; static inline Pair getEmptyKey() { return Pair(FirstInfo::getEmptyKey()); } + static inline Pair getTombstoneKey() { return Pair(FirstInfo::getTombstoneKey()); } + static unsigned getHashValue(const Pair &PairVal) { intptr_t key = (intptr_t)PairVal.getOpaqueValue(); return DenseMapInfo<intptr_t>::getHashValue(key); } + static bool isEqual(const Pair &LHS, const Pair &RHS) { return LHS.template is<T>() == RHS.template is<T>() && (LHS.template is<T>() ? FirstInfo::isEqual(LHS.template get<T>(), diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 1d1eb601a33..3ec9dfe5de0 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -17,23 +17,24 @@ #ifndef LLVM_ADT_STLEXTRAS_H #define LLVM_ADT_STLEXTRAS_H -#include <algorithm> // for std::all_of +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/iterator.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/Support/ErrorHandling.h" +#include <algorithm> #include <cassert> -#include <cstddef> // for std::size_t -#include <cstdlib> // for qsort +#include <cstddef> +#include <cstdint> +#include <cstdlib> #include <functional> +#include <initializer_list> #include <iterator> #include <limits> #include <memory> #include <tuple> -#include <utility> // for std::pair - -#include "llvm/ADT/Optional.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/iterator.h" -#include "llvm/ADT/iterator_range.h" -#include "llvm/Support/Compiler.h" -#include "llvm/Support/ErrorHandling.h" +#include <type_traits> +#include <utility> namespace llvm { @@ -50,7 +51,7 @@ template <typename RangeT> using ValueOfRange = typename std::remove_reference<decltype( *std::begin(std::declval<RangeT &>()))>::type; -} // End detail namespace +} // end namespace detail //===----------------------------------------------------------------------===// // Extra additions to <functional> @@ -58,6 +59,7 @@ using ValueOfRange = typename std::remove_reference<decltype( template <class Ty> struct identity { using argument_type = Ty; + Ty &operator()(Ty &self) const { return self; } @@ -88,7 +90,7 @@ template<typename Fn> class function_ref; template<typename Ret, typename ...Params> class function_ref<Ret(Params...)> { - Ret (*callback)(intptr_t callable, Params ...params); + Ret (*callback)(intptr_t callable, Params ...params) = nullptr; intptr_t callable; template<typename Callable> @@ -98,7 +100,7 @@ class function_ref<Ret(Params...)> { } public: - function_ref() : callback(nullptr) {} + function_ref() = default; template <typename Callable> function_ref(Callable &&callable, @@ -107,6 +109,7 @@ public: function_ref>::value>::type * = nullptr) : callback(callback_fn<typename std::remove_reference<Callable>::type>), callable(reinterpret_cast<intptr_t>(&callable)) {} + Ret operator()(Params ...params) const { return callback(callable, std::forward<Params>(params)...); } @@ -118,41 +121,34 @@ public: // delete on something. It is used like this: // // for_each(V.begin(), B.end(), deleter<Interval>); -// template <class T> inline void deleter(T *Ptr) { delete Ptr; } - - //===----------------------------------------------------------------------===// // Extra additions to <iterator> //===----------------------------------------------------------------------===// // mapped_iterator - This is a simple iterator adapter that causes a function to // be applied whenever operator* is invoked on the iterator. -// template <class RootIt, class UnaryFunc> class mapped_iterator { RootIt current; UnaryFunc Fn; -public: - typedef typename std::iterator_traits<RootIt>::iterator_category - iterator_category; - typedef typename std::iterator_traits<RootIt>::difference_type - difference_type; - typedef decltype(std::declval<UnaryFunc>()(*std::declval<RootIt>())) - value_type; - typedef void pointer; - //typedef typename UnaryFunc::result_type *pointer; - typedef void reference; // Can't modify value returned by fn +public: + using iterator_category = + typename std::iterator_traits<RootIt>::iterator_category; + using difference_type = + typename std::iterator_traits<RootIt>::difference_type; + using value_type = + decltype(std::declval<UnaryFunc>()(*std::declval<RootIt>())); - typedef RootIt iterator_type; + using pointer = void; + using reference = void; // Can't modify value returned by fn - inline const RootIt &getCurrent() const { return current; } - inline const UnaryFunc &getFunc() const { return Fn; } + using iterator_type = RootIt; inline explicit mapped_iterator(const RootIt &I, UnaryFunc F) : current(I), Fn(F) {} @@ -204,6 +200,9 @@ public: difference_type operator-(const mapped_iterator &X) const { return current - X.current; } + + inline const RootIt &getCurrent() const { return current; } + inline const UnaryFunc &getFunc() const { return Fn; } }; template <class Iterator, class Func> @@ -213,10 +212,8 @@ operator+(typename mapped_iterator<Iterator, Func>::difference_type N, return mapped_iterator<Iterator, Func>(X.getCurrent() - N, X.getFunc()); } - // map_iterator - Provide a convenient way to create mapped_iterators, just like // make_pair is useful for creating pairs... -// template <class ItTy, class FuncTy> inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) { return mapped_iterator<ItTy, FuncTy>(I, F); @@ -224,8 +221,8 @@ inline mapped_iterator<ItTy, FuncTy> map_iterator(const ItTy &I, FuncTy F) { /// Helper to determine if type T has a member called rbegin(). template <typename Ty> class has_rbegin_impl { - typedef char yes[1]; - typedef char no[2]; + using yes = char[1]; + using no = char[2]; template <typename Inner> static yes& test(Inner *I, decltype(I->rbegin()) * = nullptr); @@ -363,12 +360,13 @@ template <size_t... I> struct index_sequence; template <class... Ts> struct index_sequence_for; namespace detail { + using std::declval; // We have to alias this since inlining the actual type at the usage site // in the parameter list of iterator_facade_base<> below ICEs MSVC 2017. template<typename... Iters> struct ZipTupleType { - typedef std::tuple<decltype(*declval<Iters>())...> type; + using type = std::tuple<decltype(*declval<Iters>())...>; }; template <typename ZipType, typename... Iters> @@ -454,11 +452,11 @@ class zip_shortest : public zip_common<zip_shortest<Iters...>, Iters...> { public: using Base = zip_common<zip_shortest<Iters...>, Iters...>; + zip_shortest(Iters &&... ts) : Base(std::forward<Iters>(ts)...) {} + bool operator==(const zip_shortest<Iters...> &other) const { return !test(other, index_sequence_for<Iters...>{}); } - - zip_shortest(Iters &&... ts) : Base(std::forward<Iters>(ts)...) {} }; template <template <typename...> class ItType, typename... Args> class zippy { @@ -481,11 +479,13 @@ private: } public: + zippy(Args &&... ts_) : ts(std::forward<Args>(ts_)...) {} + iterator begin() const { return begin_impl(index_sequence_for<Args...>{}); } iterator end() const { return end_impl(index_sequence_for<Args...>{}); } - zippy(Args &&... ts_) : ts(std::forward<Args>(ts_)...) {} }; -} // End detail namespace + +} // end namespace detail /// zip iterator for two or more iteratable types. template <typename T, typename U, typename... Args> @@ -518,7 +518,7 @@ template <typename ValueT, typename... IterTs> class concat_iterator : public iterator_facade_base<concat_iterator<ValueT, IterTs...>, std::forward_iterator_tag, ValueT> { - typedef typename concat_iterator::iterator_facade_base BaseT; + using BaseT = typename concat_iterator::iterator_facade_base; /// We store both the current and end iterators for each concatenated /// sequence in a tuple of pairs. @@ -595,6 +595,7 @@ public: : IterPairs({std::begin(Ranges), std::end(Ranges)}...) {} using BaseT::operator++; + concat_iterator &operator++() { increment(index_sequence_for<IterTs...>()); return *this; @@ -608,6 +609,7 @@ public: }; namespace detail { + /// Helper to store a sequence of ranges being concatenated and access them. /// /// This is designed to facilitate providing actual storage when temporaries @@ -615,9 +617,9 @@ namespace detail { /// based for loops. template <typename ValueT, typename... RangeTs> class concat_range { public: - typedef concat_iterator<ValueT, - decltype(std::begin(std::declval<RangeTs &>()))...> - iterator; + using iterator = + concat_iterator<ValueT, + decltype(std::begin(std::declval<RangeTs &>()))...>; private: std::tuple<RangeTs...> Ranges; @@ -631,12 +633,14 @@ private: } public: - iterator begin() { return begin_impl(index_sequence_for<RangeTs...>{}); } - iterator end() { return end_impl(index_sequence_for<RangeTs...>{}); } concat_range(RangeTs &&... Ranges) : Ranges(std::forward<RangeTs>(Ranges)...) {} + + iterator begin() { return begin_impl(index_sequence_for<RangeTs...>{}); } + iterator end() { return end_impl(index_sequence_for<RangeTs...>{}); } }; -} + +} // end namespace detail /// Concatenated range across two or more ranges. /// @@ -673,7 +677,7 @@ struct less_second { /// \brief Represents a compile-time sequence of integers. template <class T, T... I> struct integer_sequence { - typedef T value_type; + using value_type = T; static constexpr size_t size() { return sizeof...(I); } }; @@ -750,7 +754,6 @@ inline int (*get_array_pod_sort_comparator(const T &)) return array_pod_sort_comparator<T>; } - /// array_pod_sort - This sorts an array with the specified start and end /// extent. This is just like std::sort, except that it calls qsort instead of /// using an inlined template. qsort is slightly slower than std::sort, but @@ -1000,6 +1003,7 @@ struct equal { /// operands. template <typename T> struct deref { T func; + // Could be further improved to cope with non-derivable functors and // non-binary functors (should be a variadic template member function // operator()). @@ -1012,12 +1016,13 @@ template <typename T> struct deref { }; namespace detail { + template <typename R> class enumerator_iter; template <typename R> struct result_pair { friend class enumerator_iter<R>; - result_pair() : Index(-1) {} + result_pair() = default; result_pair(std::size_t Index, IterOfRange<R> Iter) : Index(Index), Iter(Iter) {} @@ -1032,7 +1037,7 @@ template <typename R> struct result_pair { ValueOfRange<R> &value() { return *Iter; } private: - std::size_t Index; + std::size_t Index = std::numeric_limits<std::size_t>::max(); IterOfRange<R> Iter; }; @@ -1047,7 +1052,7 @@ class enumerator_iter public: explicit enumerator_iter(IterOfRange<R> EndIter) - : Result(std::numeric_limits<size_t>::max(), EndIter) { } + : Result(std::numeric_limits<size_t>::max(), EndIter) {} enumerator_iter(std::size_t Index, IterOfRange<R> Iter) : Result(Index, Iter) {} @@ -1085,6 +1090,7 @@ public: enumerator_iter<R> begin() { return enumerator_iter<R>(0, std::begin(TheRange)); } + enumerator_iter<R> end() { return enumerator_iter<R>(std::end(TheRange)); } @@ -1092,7 +1098,8 @@ public: private: R TheRange; }; -} + +} // end namespace detail /// Given an input range, returns a new range whose values are are pair (A,B) /// such that A is the 0-based index of the item in the sequence, and B is @@ -1114,12 +1121,14 @@ template <typename R> detail::enumerator<R> enumerate(R &&TheRange) { } namespace detail { + template <typename F, typename Tuple, std::size_t... I> auto apply_tuple_impl(F &&f, Tuple &&t, index_sequence<I...>) -> decltype(std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...)) { return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...); } -} + +} // end namespace detail /// Given an input tuple (a1, a2, ..., an), pass the arguments of the /// tuple variadically to f as if by calling f(a1, a2, ..., an) and @@ -1135,6 +1144,7 @@ auto apply_tuple(F &&f, Tuple &&t) -> decltype(detail::apply_tuple_impl( return detail::apply_tuple_impl(std::forward<F>(f), std::forward<Tuple>(t), Indices{}); } -} // End llvm namespace -#endif +} // end namespace llvm + +#endif // LLVM_ADT_STLEXTRAS_H diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h index f5f00dcfafe..b60fd098139 100644 --- a/llvm/include/llvm/ADT/Twine.h +++ b/llvm/include/llvm/ADT/Twine.h @@ -1,4 +1,4 @@ -//===-- Twine.h - Fast Temporary String Concatenation -----------*- C++ -*-===// +//===- Twine.h - Fast Temporary String Concatenation ------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -155,17 +155,19 @@ namespace llvm { /// LHS - The prefix in the concatenation, which may be uninitialized for /// Null or Empty kinds. Child LHS; + /// RHS - The suffix in the concatenation, which may be uninitialized for /// Null or Empty kinds. Child RHS; + /// LHSKind - The NodeKind of the left hand side, \see getLHSKind(). - NodeKind LHSKind; + NodeKind LHSKind = EmptyKind; + /// RHSKind - The NodeKind of the right hand side, \see getRHSKind(). - NodeKind RHSKind; + NodeKind RHSKind = EmptyKind; /// Construct a nullary twine; the kind must be NullKind or EmptyKind. - explicit Twine(NodeKind Kind) - : LHSKind(Kind), RHSKind(EmptyKind) { + explicit Twine(NodeKind Kind) : LHSKind(Kind) { assert(isNullary() && "Invalid kind!"); } @@ -252,7 +254,7 @@ namespace llvm { /// @{ /// Construct from an empty string. - /*implicit*/ Twine() : LHSKind(EmptyKind), RHSKind(EmptyKind) { + /*implicit*/ Twine() { assert(isValid() && "Invalid twine!"); } @@ -263,8 +265,7 @@ namespace llvm { /// We take care here to optimize "" into the empty twine -- this will be /// optimized out for string constants. This allows Twine arguments have /// default "" values, without introducing unnecessary string constants. - /*implicit*/ Twine(const char *Str) - : RHSKind(EmptyKind) { + /*implicit*/ Twine(const char *Str) { if (Str[0] != '\0') { LHS.cString = Str; LHSKind = CStringKind; @@ -275,84 +276,73 @@ namespace llvm { } /// Construct from an std::string. - /*implicit*/ Twine(const std::string &Str) - : LHSKind(StdStringKind), RHSKind(EmptyKind) { + /*implicit*/ Twine(const std::string &Str) : LHSKind(StdStringKind) { LHS.stdString = &Str; assert(isValid() && "Invalid twine!"); } /// Construct from a StringRef. - /*implicit*/ Twine(const StringRef &Str) - : LHSKind(StringRefKind), RHSKind(EmptyKind) { + /*implicit*/ Twine(const StringRef &Str) : LHSKind(StringRefKind) { LHS.stringRef = &Str; assert(isValid() && "Invalid twine!"); } /// Construct from a SmallString. /*implicit*/ Twine(const SmallVectorImpl<char> &Str) - : LHSKind(SmallStringKind), RHSKind(EmptyKind) { + : LHSKind(SmallStringKind) { LHS.smallString = &Str; assert(isValid() && "Invalid twine!"); } /// Construct from a formatv_object_base. /*implicit*/ Twine(const formatv_object_base &Fmt) - : LHSKind(FormatvObjectKind), RHSKind(EmptyKind) { + : LHSKind(FormatvObjectKind) { LHS.formatvObject = &Fmt; assert(isValid() && "Invalid twine!"); } /// Construct from a char. - explicit Twine(char Val) - : LHSKind(CharKind), RHSKind(EmptyKind) { + explicit Twine(char Val) : LHSKind(CharKind) { LHS.character = Val; } /// Construct from a signed char. - explicit Twine(signed char Val) - : LHSKind(CharKind), RHSKind(EmptyKind) { + explicit Twine(signed char Val) : LHSKind(CharKind) { LHS.character = static_cast<char>(Val); } /// Construct from an unsigned char. - explicit Twine(unsigned char Val) - : LHSKind(CharKind), RHSKind(EmptyKind) { + explicit Twine(unsigned char Val) : LHSKind(CharKind) { LHS.character = static_cast<char>(Val); } /// Construct a twine to print \p Val as an unsigned decimal integer. - explicit Twine(unsigned Val) - : LHSKind(DecUIKind), RHSKind(EmptyKind) { + explicit Twine(unsigned Val) : LHSKind(DecUIKind) { LHS.decUI = Val; } /// Construct a twine to print \p Val as a signed decimal integer. - explicit Twine(int Val) - : LHSKind(DecIKind), RHSKind(EmptyKind) { + explicit Twine(int Val) : LHSKind(DecIKind) { LHS.decI = Val; } /// Construct a twine to print \p Val as an unsigned decimal integer. - explicit Twine(const unsigned long &Val) - : LHSKind(DecULKind), RHSKind(EmptyKind) { + explicit Twine(const unsigned long &Val) : LHSKind(DecULKind) { LHS.decUL = &Val; } /// Construct a twine to print \p Val as a signed decimal integer. - explicit Twine(const long &Val) - : LHSKind(DecLKind), RHSKind(EmptyKind) { + explicit Twine(const long &Val) : LHSKind(DecLKind) { LHS.decL = &Val; } /// Construct a twine to print \p Val as an unsigned decimal integer. - explicit Twine(const unsigned long long &Val) - : LHSKind(DecULLKind), RHSKind(EmptyKind) { + explicit Twine(const unsigned long long &Val) : LHSKind(DecULLKind) { LHS.decULL = &Val; } /// Construct a twine to print \p Val as a signed decimal integer. - explicit Twine(const long long &Val) - : LHSKind(DecLLKind), RHSKind(EmptyKind) { + explicit Twine(const long long &Val) : LHSKind(DecLLKind) { LHS.decLL = &Val; } |