Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Changes for LLDB upstream merge #31

Merged
merged 23 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
30d8981
[ADT] Add the worlds simplest STL extra. Or at least close to it.
chandlerc Aug 19, 2016
16c9aae
Add StringRef::take_front and StringRef::take_back
Aug 30, 2016
5838161
Appease buildbots after r280114.
Aug 30, 2016
9956a48
Rename ArrayRef::keep_front / keep_back to take_front / take_back.
Aug 30, 2016
f086853
[IR] Properly handle escape characters in Attribute::getAsString()
honggyukim Sep 1, 2016
3af3da0
[Support] Add StringRef::withNullAsEmpty()
Sep 19, 2016
cd4d5a7
=delete the StringRef(nullptr_t) constructor.
Sep 21, 2016
8c4f313
[Support] Add StringRef::consumeInteger.
Sep 22, 2016
89eccd7
Speculative fix for build failures due to consumeInteger.
Sep 22, 2016
6442008
Fix build breakage due to typo in cast.
Sep 22, 2016
41760b0
Add some predicated searching functions to StringRef.
Sep 25, 2016
e96242b
Fix signed / unsigned comparison.
Sep 25, 2016
962cff5
Add a comment on StringRef::contains(char)
Sep 25, 2016
be17507
Allow StringRef to be constructed from a null pointer.
Sep 26, 2016
b769d83
Add llvm::join_items to StringExtras.
Sep 27, 2016
9f78d67
Add llvm::enumerate() to STLExtras.
Sep 29, 2016
6a2627b
Revert "Add llvm::enumerate() to STLExtras."
Sep 29, 2016
94e2b94
Resubmit "Add llvm::enumerate() to STLExtras."
Sep 30, 2016
ea906a2
Add llvm::enumerate() range adapter.
Oct 5, 2016
c1b9e51
Fix build due to comparison of std::pairs.
Oct 5, 2016
dac6b09
Fix the build with MSVC 2013, still cannot default move ctors yet
rnk Oct 5, 2016
3e3953a
Remove extra semicolon
rnk Oct 5, 2016
f5d747c
Re-apply "Disallow ArrayRef assignment from temporaries."
jrose-apple Oct 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions include/llvm/ADT/ArrayRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ namespace llvm {
return slice(0, size() - N);
}

/// \brief Return a copy of *this with only the first \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> take_front(size_t N = 1) const {
if (N >= size())
return *this;
return drop_back(size() - N);
}

/// \brief Return a copy of *this with only the last \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
ArrayRef<T> take_back(size_t N = 1) const {
if (N >= size())
return *this;
return drop_front(size() - N);
}

/// @}
/// @name Operator Overloads
/// @{
Expand All @@ -203,6 +219,22 @@ namespace llvm {
return Data[Index];
}

/// Disallow accidental assignment from a temporary.
///
/// The declaration here is extra complicated so that "arrayRef = {}"
/// continues to select the move assignment operator.
template <typename U>
typename std::enable_if<std::is_same<U, T>::value, ArrayRef<T>>::type &
operator=(U &&Temporary) = delete;

/// Disallow accidental assignment from a temporary.
///
/// The declaration here is extra complicated so that "arrayRef = {}"
/// continues to select the move assignment operator.
template <typename U>
typename std::enable_if<std::is_same<U, T>::value, ArrayRef<T>>::type &
operator=(std::initializer_list<U>) = delete;

/// @}
/// @name Expensive Operations
/// @{
Expand Down Expand Up @@ -321,6 +353,22 @@ namespace llvm {
return slice(0, this->size() - N);
}

/// \brief Return a copy of *this with only the first \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> take_front(size_t N = 1) const {
if (N >= this->size())
return *this;
return drop_back(this->size() - N);
}

/// \brief Return a copy of *this with only the last \p N elements.
LLVM_ATTRIBUTE_UNUSED_RESULT
MutableArrayRef<T> take_back(size_t N = 1) const {
if (N >= this->size())
return *this;
return drop_front(this->size() - N);
}

/// @}
/// @name Operator Overloads
/// @{
Expand Down
71 changes: 70 additions & 1 deletion include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace llvm {
namespace detail {

template <typename RangeT>
using IterOfRange = decltype(std::begin(std::declval<RangeT>()));
using IterOfRange = decltype(std::begin(std::declval<RangeT &>()));

} // End detail namespace

Expand Down Expand Up @@ -369,6 +369,11 @@ struct build_index_impl<0, I...> : index_sequence<I...> {};
template <class... Ts>
struct index_sequence_for : build_index_impl<sizeof...(Ts)> {};

/// Utility type to build an inheritance chain that makes it easy to rank
/// overload candidates.
template <int N> struct rank : rank<N - 1> {};
template <> struct rank<0> {};

//===----------------------------------------------------------------------===//
// Extra additions for arrays
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -608,6 +613,70 @@ template <typename T> struct deref {
}
};

namespace detail {
template <typename R> class enumerator_impl {
public:
template <typename X> struct result_pair {
result_pair(std::size_t Index, X Value) : Index(Index), Value(Value) {}

const std::size_t Index;
X Value;
};

class iterator {
typedef
typename std::iterator_traits<IterOfRange<R>>::reference iter_reference;
typedef result_pair<iter_reference> result_type;

public:
iterator(IterOfRange<R> &&Iter, std::size_t Index)
: Iter(Iter), Index(Index) {}

result_type operator*() const { return result_type(Index, *Iter); }

iterator &operator++() {
++Iter;
++Index;
return *this;
}

bool operator!=(const iterator &RHS) const { return Iter != RHS.Iter; }

private:
IterOfRange<R> Iter;
std::size_t Index;
};

public:
explicit enumerator_impl(R &&Range) : Range(std::forward<R>(Range)) {}

iterator begin() { return iterator(std::begin(Range), 0); }
iterator end() { return iterator(std::end(Range), std::size_t(-1)); }

private:
R Range;
};
}

/// 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
/// the value from the original sequence. Example:
///
/// std::vector<char> Items = {'A', 'B', 'C', 'D'};
/// for (auto X : enumerate(Items)) {
/// printf("Item %d - %c\n", X.Item, X.Value);
/// }
///
/// Output:
/// Item 0 - A
/// Item 1 - B
/// Item 2 - C
/// Item 3 - D
///
template <typename R> detail::enumerator_impl<R> enumerate(R &&Range) {
return detail::enumerator_impl<R>(std::forward<R>(Range));
}

} // End llvm namespace

#endif
61 changes: 60 additions & 1 deletion include/llvm/ADT/StringExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iterator>

namespace llvm {
class raw_ostream;
template<typename T> class SmallVectorImpl;

/// hexdigit - Return the hexadecimal character for the
Expand Down Expand Up @@ -150,6 +151,12 @@ static inline StringRef getOrdinalSuffix(unsigned Val) {
}
}

/// PrintEscapedString - Print each character of the specified string, escaping
/// it if it is not printable or if it is an escape char.
void PrintEscapedString(StringRef Name, raw_ostream &Out);

namespace detail {

template <typename IteratorT>
inline std::string join_impl(IteratorT Begin, IteratorT End,
StringRef Separator, std::input_iterator_tag) {
Expand Down Expand Up @@ -184,12 +191,64 @@ inline std::string join_impl(IteratorT Begin, IteratorT End,
return S;
}

template <typename Sep>
inline void join_items_impl(std::string &Result, Sep Separator) {}

template <typename Sep, typename Arg>
inline void join_items_impl(std::string &Result, Sep Separator,
const Arg &Item) {
Result += Item;
}

template <typename Sep, typename Arg1, typename... Args>
inline void join_items_impl(std::string &Result, Sep Separator, const Arg1 &A1,
Args &&... Items) {
Result += A1;
Result += Separator;
join_items_impl(Result, Separator, std::forward<Args>(Items)...);
}

inline size_t join_one_item_size(char C) { return 1; }
inline size_t join_one_item_size(const char *S) { return S ? ::strlen(S) : 0; }

template <typename T> inline size_t join_one_item_size(const T &Str) {
return Str.size();
}

inline size_t join_items_size() { return 0; }

template <typename A1> inline size_t join_items_size(const A1 &A) {
return join_one_item_size(A);
}
template <typename A1, typename... Args>
inline size_t join_items_size(const A1 &A, Args &&... Items) {
return join_one_item_size(A) + join_items_size(std::forward<Args>(Items)...);
}
}

/// Joins the strings in the range [Begin, End), adding Separator between
/// the elements.
template <typename IteratorT>
inline std::string join(IteratorT Begin, IteratorT End, StringRef Separator) {
typedef typename std::iterator_traits<IteratorT>::iterator_category tag;
return join_impl(Begin, End, Separator, tag());
return detail::join_impl(Begin, End, Separator, tag());
}

/// Joins the strings in the parameter pack \p Items, adding \p Separator
/// between the elements. All arguments must be implicitly convertible to
/// std::string, or there should be an overload of std::string::operator+=()
/// that accepts the argument explicitly.
template <typename Sep, typename... Args>
inline std::string join_items(Sep Separator, Args &&... Items) {
std::string Result;
if (sizeof...(Items) == 0)
return Result;

size_t NS = detail::join_one_item_size(Separator);
size_t NI = detail::join_items_size(std::forward<Args>(Items)...);
Result.reserve(NI + (sizeof...(Items) - 1) * NS + 1);
detail::join_items_impl(Result, Separator, std::forward<Args>(Items)...);
return Result;
}

} // End llvm namespace
Expand Down
Loading