-//===-- llvm/ADT/FoldingSet.h - Uniquing Hash Set ---------------*- C++ -*-===//
+//===- llvm/ADT/FoldingSet.h - Uniquing Hash Set ----------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
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
//===--------------------------------------------------------------------===//
/// 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; }
/// 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);
/// 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.
: 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);
unsigned ComputeHash() const;
/// operator== - Used to compare two nodes to each other.
- ///
bool operator==(const FoldingSetNodeID &RHS) const;
bool operator==(const FoldingSetNodeIDRef RHS) const;
};
// 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;
~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)));
}
public:
- explicit FoldingSet(unsigned Log2InitSize = 6)
- : Super(Log2InitSize) {}
-
+ explicit FoldingSet(unsigned Log2InitSize = 6) : Super(Log2InitSize) {}
FoldingSet(FoldingSet &&Arg) = default;
FoldingSet &operator=(FoldingSet &&RHS) = default;
};
public:
explicit ContextualFoldingSet(Ctx Context, unsigned Log2InitSize = 6)
- : Super(Log2InitSize), Context(Context)
- {}
+ : Super(Log2InitSize), Context(Context) {}
Ctx getContext() const { return Context; }
};
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(); }
/// 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();
#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;
/// 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);
}
void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); }
+
void setFromOpaqueValue(void *Val) {
Value = reinterpret_cast<intptr_t>(Val);
}
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;
}
// 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; }
};
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
#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 {
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.
///
/// 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>
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
"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
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.
/// 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
/// 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;
public:
PointerUnion() = default;
-
PointerUnion(PT1 V)
: Val(const_cast<void *>(
PointerLikeTypeTraits<PT1>::getAsVoidPointer(V))) {}
// 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;
}
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.
/// 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>();
}
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; }
/// 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>();
}
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>();
}
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); }
/// 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>();
}
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>();
}
// 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>(),
#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 {
using ValueOfRange = typename std::remove_reference<decltype(
*std::begin(std::declval<RangeT &>()))>::type;
-} // End detail namespace
+} // end namespace detail
//===----------------------------------------------------------------------===//
// Extra additions to <functional>
template <class Ty> struct identity {
using argument_type = Ty;
+
Ty &operator()(Ty &self) const {
return self;
}
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>
}
public:
- function_ref() : callback(nullptr) {}
+ function_ref() = default;
template <typename Callable>
function_ref(Callable &&callable,
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)...);
}
// 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) {}
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>
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);
/// 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);
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>
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 {
}
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>
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.
: IterPairs({std::begin(Ranges), std::end(Ranges)}...) {}
using BaseT::operator++;
+
concat_iterator &operator++() {
increment(index_sequence_for<IterTs...>());
return *this;
};
namespace detail {
+
/// Helper to store a sequence of ranges being concatenated and access them.
///
/// This is designed to facilitate providing actual storage when temporaries
/// 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;
}
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.
///
/// \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); }
};
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
/// 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()).
};
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) {}
ValueOfRange<R> &value() { return *Iter; }
private:
- std::size_t Index;
+ std::size_t Index = std::numeric_limits<std::size_t>::max();
IterOfRange<R> 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) {}
enumerator_iter<R> begin() {
return enumerator_iter<R>(0, std::begin(TheRange));
}
+
enumerator_iter<R> end() {
return enumerator_iter<R>(std::end(TheRange));
}
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
}
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
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
-//===-- Twine.h - Fast Temporary String Concatenation -----------*- C++ -*-===//
+//===- Twine.h - Fast Temporary String Concatenation ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
/// 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!");
}
/// @{
/// Construct from an empty string.
- /*implicit*/ Twine() : LHSKind(EmptyKind), RHSKind(EmptyKind) {
+ /*implicit*/ Twine() {
assert(isValid() && "Invalid twine!");
}
/// 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;
}
/// 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;
}