Update clang-format

This commit is contained in:
Jonathan Müller 2018-09-20 19:57:03 +02:00
commit 9f18b7f4d8
89 changed files with 11377 additions and 11546 deletions

View file

@ -8,31 +8,29 @@
#include <debug_assert.hpp>
#ifdef CPPAST_ENABLE_ASSERTIONS
#define CPPAST_ASSERTION_LEVEL 1
# define CPPAST_ASSERTION_LEVEL 1
#else
#define CPPAST_ASSERTION_LEVEL 0
# define CPPAST_ASSERTION_LEVEL 0
#endif
#ifdef CPPAST_ENABLE_PRECONDITION_CHECKS
#define CPPAST_PRECONDITION_LEVEL 1
# define CPPAST_PRECONDITION_LEVEL 1
#else
#define CPPAST_PRECONDITION_LEVEL 0
# define CPPAST_PRECONDITION_LEVEL 0
#endif
namespace cppast
{
namespace detail
{
struct assert_handler : debug_assert::set_level<CPPAST_ASSERTION_LEVEL>,
debug_assert::default_handler
{
};
namespace detail
{
struct assert_handler : debug_assert::set_level<CPPAST_ASSERTION_LEVEL>,
debug_assert::default_handler
{};
struct precondition_error_handler : debug_assert::set_level<CPPAST_PRECONDITION_LEVEL>,
debug_assert::default_handler
{
};
}
} // namespace cppast::detail
struct precondition_error_handler : debug_assert::set_level<CPPAST_PRECONDITION_LEVEL>,
debug_assert::default_handler
{};
} // namespace detail
} // namespace cppast
#endif // CPPAST_ASSERT_HPP_INCLUDED

View file

@ -5,8 +5,8 @@
#ifndef CPPAST_INTRUSIVE_LIST_HPP_INCLUDED
#define CPPAST_INTRUSIVE_LIST_HPP_INCLUDED
#include <memory>
#include <iterator>
#include <memory>
#include <type_safe/optional_ref.hpp>
@ -14,228 +14,226 @@
namespace cppast
{
class cpp_file;
class cpp_file;
namespace detail
namespace detail
{
template <typename T>
class intrusive_list_node
{
template <typename T>
class intrusive_list_node
std::unique_ptr<T> next_;
void do_on_insert(const T& parent) noexcept
{
std::unique_ptr<T> next_;
static_cast<T&>(*this).on_insert(parent);
}
void do_on_insert(const T& parent) noexcept
{
static_cast<T&>(*this).on_insert(parent);
}
template <typename U>
friend struct intrusive_list_access;
};
template <typename U>
friend struct intrusive_list_access;
};
template <typename T>
struct intrusive_list_access
template <typename T>
struct intrusive_list_access
{
template <typename U>
static T* get_next(const U& obj)
{
template <typename U>
static T* get_next(const U& obj)
{
static_assert(std::is_base_of<U, T>::value, "must be a base");
return static_cast<T*>(obj.next_.get());
}
static_assert(std::is_base_of<U, T>::value, "must be a base");
return static_cast<T*>(obj.next_.get());
}
template <typename U>
static T* set_next(U& obj, std::unique_ptr<T> node)
{
static_assert(std::is_base_of<U, T>::value, "must be a base");
obj.next_ = std::move(node);
return static_cast<T*>(obj.next_.get());
}
template <typename U, typename V>
static void on_insert(U& obj, const V& parent)
{
obj.do_on_insert(parent);
}
};
template <typename T>
class intrusive_list_iterator
template <typename U>
static T* set_next(U& obj, std::unique_ptr<T> node)
{
public:
using value_type = T;
using reference = T&;
using pointer = T*;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
static_assert(std::is_base_of<U, T>::value, "must be a base");
obj.next_ = std::move(node);
return static_cast<T*>(obj.next_.get());
}
intrusive_list_iterator() noexcept : cur_(nullptr) {}
reference operator*() const noexcept
{
return *cur_;
}
pointer operator->() const noexcept
{
return cur_;
}
intrusive_list_iterator& operator++() noexcept
{
cur_ = intrusive_list_access<T>::get_next(*cur_);
return *this;
}
intrusive_list_iterator operator++(int)noexcept
{
auto tmp = *this;
++(*this);
return tmp;
}
friend bool operator==(const intrusive_list_iterator& a,
const intrusive_list_iterator& b) noexcept
{
return a.cur_ == b.cur_;
}
friend bool operator!=(const intrusive_list_iterator& a,
const intrusive_list_iterator& b) noexcept
{
return !(a == b);
}
private:
intrusive_list_iterator(T* ptr) : cur_(ptr) {}
T* cur_;
template <typename U>
friend class intrusive_list;
};
template <typename T>
class intrusive_list
template <typename U, typename V>
static void on_insert(U& obj, const V& parent)
{
public:
intrusive_list() = default;
obj.do_on_insert(parent);
}
};
//=== modifiers ===//
template <typename Dummy = T, typename = typename std::enable_if<
std::is_same<Dummy, cpp_file>::value>::type>
void push_back(std::unique_ptr<T> obj) noexcept
{
push_back_impl(std::move(obj));
}
template <typename T>
class intrusive_list_iterator
{
public:
using value_type = T;
using reference = T&;
using pointer = T*;
using difference_type = std::ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
template <typename U, typename = typename std::enable_if<
!std::is_same<T, cpp_file>::value, U>::type>
void push_back(const U& parent, std::unique_ptr<T> obj) noexcept
{
push_back_impl(std::move(obj));
intrusive_list_access<T>::on_insert(last_.value(), parent);
}
intrusive_list_iterator() noexcept : cur_(nullptr) {}
//=== accesors ===//
bool empty() const noexcept
{
return first_ == nullptr;
}
type_safe::optional_ref<T> front() noexcept
{
return type_safe::opt_ref(first_.get());
}
type_safe::optional_ref<const T> front() const noexcept
{
return type_safe::opt_cref(first_.get());
}
type_safe::optional_ref<T> back() noexcept
{
return last_;
}
type_safe::optional_ref<const T> back() const noexcept
{
return last_;
}
//=== iterators ===//
using iterator = intrusive_list_iterator<T>;
using const_iterator = intrusive_list_iterator<const T>;
iterator begin() noexcept
{
return iterator(first_.get());
}
iterator end() noexcept
{
return {};
}
const_iterator begin() const noexcept
{
return const_iterator(first_.get());
}
const_iterator end() const noexcept
{
return {};
}
private:
void push_back_impl(std::unique_ptr<T> obj)
{
DEBUG_ASSERT(obj != nullptr, detail::assert_handler{});
if (last_)
{
auto ptr = intrusive_list_access<T>::set_next(last_.value(), std::move(obj));
last_ = type_safe::ref(*ptr);
}
else
{
first_ = std::move(obj);
last_ = type_safe::opt_ref(first_.get());
}
}
std::unique_ptr<T> first_;
type_safe::optional_ref<T> last_;
};
template <typename T>
class iteratable_intrusive_list
reference operator*() const noexcept
{
public:
iteratable_intrusive_list(type_safe::object_ref<const intrusive_list<T>> list)
: list_(list)
return *cur_;
}
pointer operator->() const noexcept
{
return cur_;
}
intrusive_list_iterator& operator++() noexcept
{
cur_ = intrusive_list_access<T>::get_next(*cur_);
return *this;
}
intrusive_list_iterator operator++(int) noexcept
{
auto tmp = *this;
++(*this);
return tmp;
}
friend bool operator==(const intrusive_list_iterator& a,
const intrusive_list_iterator& b) noexcept
{
return a.cur_ == b.cur_;
}
friend bool operator!=(const intrusive_list_iterator& a,
const intrusive_list_iterator& b) noexcept
{
return !(a == b);
}
private:
intrusive_list_iterator(T* ptr) : cur_(ptr) {}
T* cur_;
template <typename U>
friend class intrusive_list;
};
template <typename T>
class intrusive_list
{
public:
intrusive_list() = default;
//=== modifiers ===//
template <typename Dummy = T,
typename = typename std::enable_if<std::is_same<Dummy, cpp_file>::value>::type>
void push_back(std::unique_ptr<T> obj) noexcept
{
push_back_impl(std::move(obj));
}
template <typename U,
typename = typename std::enable_if<!std::is_same<T, cpp_file>::value, U>::type>
void push_back(const U& parent, std::unique_ptr<T> obj) noexcept
{
push_back_impl(std::move(obj));
intrusive_list_access<T>::on_insert(last_.value(), parent);
}
//=== accesors ===//
bool empty() const noexcept
{
return first_ == nullptr;
}
type_safe::optional_ref<T> front() noexcept
{
return type_safe::opt_ref(first_.get());
}
type_safe::optional_ref<const T> front() const noexcept
{
return type_safe::opt_cref(first_.get());
}
type_safe::optional_ref<T> back() noexcept
{
return last_;
}
type_safe::optional_ref<const T> back() const noexcept
{
return last_;
}
//=== iterators ===//
using iterator = intrusive_list_iterator<T>;
using const_iterator = intrusive_list_iterator<const T>;
iterator begin() noexcept
{
return iterator(first_.get());
}
iterator end() noexcept
{
return {};
}
const_iterator begin() const noexcept
{
return const_iterator(first_.get());
}
const_iterator end() const noexcept
{
return {};
}
private:
void push_back_impl(std::unique_ptr<T> obj)
{
DEBUG_ASSERT(obj != nullptr, detail::assert_handler{});
if (last_)
{
auto ptr = intrusive_list_access<T>::set_next(last_.value(), std::move(obj));
last_ = type_safe::ref(*ptr);
}
bool empty() const noexcept
else
{
return list_->empty();
first_ = std::move(obj);
last_ = type_safe::opt_ref(first_.get());
}
}
using iterator = typename intrusive_list<T>::const_iterator;
std::unique_ptr<T> first_;
type_safe::optional_ref<T> last_;
};
iterator begin() const noexcept
{
return list_->begin();
}
template <typename T>
class iteratable_intrusive_list
{
public:
iteratable_intrusive_list(type_safe::object_ref<const intrusive_list<T>> list) : list_(list)
{}
iterator end() const noexcept
{
return list_->end();
}
bool empty() const noexcept
{
return list_->empty();
}
private:
type_safe::object_ref<const intrusive_list<T>> list_;
};
}
} // namespace cppast::detail
using iterator = typename intrusive_list<T>::const_iterator;
iterator begin() const noexcept
{
return list_->begin();
}
iterator end() const noexcept
{
return list_->end();
}
private:
type_safe::object_ref<const intrusive_list<T>> list_;
};
} // namespace detail
} // namespace cppast
#endif // CPPAST_INTRUSIVE_LIST_HPP_INCLUDED