Header and dependency cleanup

This commit is contained in:
Maxime Coste 2019-01-24 21:02:07 +11:00
parent 4b72cfe530
commit 346c78f5e0
21 changed files with 41 additions and 48 deletions

View File

@ -1,7 +1,6 @@
#ifndef array_view_hh_INCLUDED #ifndef array_view_hh_INCLUDED
#define array_view_hh_INCLUDED #define array_view_hh_INCLUDED
#include <vector>
#include <initializer_list> #include <initializer_list>
#include <iterator> #include <iterator>
@ -31,10 +30,10 @@ public:
template<size_t N> template<size_t N>
constexpr ArrayView(T(&array)[N]) : m_pointer(array), m_size(N) {} constexpr ArrayView(T(&array)[N]) : m_pointer(array), m_size(N) {}
template<typename Alloc, typename U, template<typename Container,
typename = std::enable_if_t<sizeof(U) == sizeof(T)>> typename = std::enable_if_t<sizeof(decltype(*std::declval<Container>().data())) == sizeof(T)>>
constexpr ArrayView(const std::vector<U, Alloc>& v) constexpr ArrayView(const Container& c)
: m_pointer(v.data()), m_size(v.size()) {} : m_pointer(c.data()), m_size(c.size()) {}
constexpr ArrayView(const std::initializer_list<T>& v) constexpr ArrayView(const std::initializer_list<T>& v)
: m_pointer(v.begin()), m_size(v.size()) {} : m_pointer(v.begin()), m_size(v.size()) {}

View File

@ -29,7 +29,6 @@
#include "user_interface.hh" #include "user_interface.hh"
#include "window.hh" #include "window.hh"
#include <cstring>
#include <functional> #include <functional>
#include <utility> #include <utility>
@ -1851,7 +1850,7 @@ const CommandDesc prompt_cmd = {
const String& command = parser[1]; const String& command = parser[1];
auto initstr = parser.get_switch("init").value_or(StringView{}); auto initstr = parser.get_switch("init").value_or(StringView{});
Completer completer; PromptCompleter completer;
if (parser.get_switch("file-completion")) if (parser.get_switch("file-completion"))
completer = [](const Context& context, CompletionFlags, completer = [](const Context& context, CompletionFlags,
StringView prefix, ByteCount cursor_pos) -> Completions { StringView prefix, ByteCount cursor_pos) -> Completions {
@ -1896,7 +1895,7 @@ const CommandDesc prompt_cmd = {
auto& text = sc.env_vars["text"_sv] = str.str(); auto& text = sc.env_vars["text"_sv] = str.str();
auto clear_password = on_scope_end([&] { auto clear_password = on_scope_end([&] {
if (flags & PromptFlags::Password) if (flags & PromptFlags::Password)
memset(text.data(), 0, (int)text.length()); std::fill(text.begin(), text.end(), '\0');
}); });
ScopedSetBool disable_history{context.history_disabled()}; ScopedSetBool disable_history{context.history_disabled()};

View File

@ -42,9 +42,6 @@ enum class CompletionFlags
constexpr bool with_bit_ops(Meta::Type<CompletionFlags>) { return true; } constexpr bool with_bit_ops(Meta::Type<CompletionFlags>) { return true; }
using Completer = std::function<Completions (const Context&, CompletionFlags,
StringView, ByteCount)>;
inline Completions complete_nothing(const Context&, CompletionFlags, inline Completions complete_nothing(const Context&, CompletionFlags,
StringView, ByteCount cursor_pos) StringView, ByteCount cursor_pos)
{ {

View File

@ -5,6 +5,8 @@
#include "optional.hh" #include "optional.hh"
#include "utils.hh" #include "utils.hh"
#include <functional>
namespace Kakoune namespace Kakoune
{ {

View File

@ -2,7 +2,7 @@
#define hash_hh_INCLUDED #define hash_hh_INCLUDED
#include <type_traits> #include <type_traits>
#include <functional> #include <utility>
#include <cstddef> #include <cstddef>
@ -11,13 +11,6 @@ namespace Kakoune
size_t hash_data(const char* data, size_t len); size_t hash_data(const char* data, size_t len);
template<typename... Type>
constexpr size_t hash_value(const Type&... val)
{
static_assert(sizeof...(Type) == 1, "");
return std::hash<Type...>()(val...);
}
template<typename Type> template<typename Type>
std::enable_if_t<std::is_integral<Type>::value, size_t> std::enable_if_t<std::is_integral<Type>::value, size_t>
constexpr hash_value(const Type& val) constexpr hash_value(const Type& val)

View File

@ -11,7 +11,7 @@
#include "string.hh" #include "string.hh"
#include "utils.hh" #include "utils.hh"
#include <functional> #include <memory>
namespace Kakoune namespace Kakoune
{ {
@ -84,7 +84,7 @@ private:
}; };
using HighlighterParameters = ConstArrayView<String>; using HighlighterParameters = ConstArrayView<String>;
using HighlighterFactory = std::function<std::unique_ptr<Highlighter> (HighlighterParameters params, Highlighter* parent)>; using HighlighterFactory = std::unique_ptr<Highlighter> (*)(HighlighterParameters params, Highlighter* parent);
struct HighlighterFactoryAndDocstring struct HighlighterFactoryAndDocstring
{ {

View File

@ -9,21 +9,16 @@
#include "face_registry.hh" #include "face_registry.hh"
#include "highlighter_group.hh" #include "highlighter_group.hh"
#include "line_modification.hh" #include "line_modification.hh"
#include "option.hh"
#include "option_types.hh" #include "option_types.hh"
#include "parameters_parser.hh" #include "parameters_parser.hh"
#include "ranges.hh" #include "ranges.hh"
#include "regex.hh" #include "regex.hh"
#include "register_manager.hh" #include "register_manager.hh"
#include "string.hh" #include "string.hh"
#include "unit_tests.hh"
#include "utf8.hh" #include "utf8.hh"
#include "utf8_iterator.hh" #include "utf8_iterator.hh"
#include "window.hh" #include "window.hh"
#include <locale>
#include <cstdio>
namespace Kakoune namespace Kakoune
{ {

View File

@ -7,6 +7,8 @@
#include "meta.hh" #include "meta.hh"
#include "enum.hh" #include "enum.hh"
#include <memory>
namespace Kakoune namespace Kakoune
{ {

View File

@ -751,7 +751,7 @@ class Prompt : public InputMode
public: public:
Prompt(InputHandler& input_handler, StringView prompt, Prompt(InputHandler& input_handler, StringView prompt,
String initstr, String emptystr, Face face, PromptFlags flags, String initstr, String emptystr, Face face, PromptFlags flags,
Completer completer, PromptCallback callback) PromptCompleter completer, PromptCallback callback)
: InputMode(input_handler), m_prompt(prompt.str()), m_prompt_face(face), : InputMode(input_handler), m_prompt(prompt.str()), m_prompt_face(face),
m_empty_text{std::move(emptystr)}, m_empty_text{std::move(emptystr)},
m_flags(flags), m_completer(std::move(completer)), m_callback(std::move(callback)), m_flags(flags), m_completer(std::move(completer)), m_callback(std::move(callback)),
@ -1064,8 +1064,8 @@ private:
context().client().menu_hide(); context().client().menu_hide();
} }
PromptCallback m_callback; PromptCallback m_callback;
Completer m_completer; PromptCompleter m_completer;
const String m_prompt; const String m_prompt;
Face m_prompt_face; Face m_prompt_face;
Completions m_completions; Completions m_completions;
@ -1578,7 +1578,7 @@ void InputHandler::repeat_last_insert()
void InputHandler::prompt(StringView prompt, String initstr, String emptystr, void InputHandler::prompt(StringView prompt, String initstr, String emptystr,
Face prompt_face, PromptFlags flags, Face prompt_face, PromptFlags flags,
Completer completer, PromptCallback callback) PromptCompleter completer, PromptCallback callback)
{ {
push_mode(new InputModes::Prompt(*this, prompt, std::move(initstr), std::move(emptystr), push_mode(new InputModes::Prompt(*this, prompt, std::move(initstr), std::move(emptystr),
prompt_face, flags, std::move(completer), std::move(callback))); prompt_face, flags, std::move(completer), std::move(callback)));

View File

@ -47,6 +47,10 @@ enum class InsertMode : unsigned;
enum class KeymapMode : char; enum class KeymapMode : char;
enum class CursorMode; enum class CursorMode;
using PromptCompleter = std::function<Completions (const Context&, CompletionFlags,
StringView, ByteCount)>;
class InputHandler : public SafeCountable class InputHandler : public SafeCountable
{ {
public: public:
@ -66,7 +70,7 @@ public:
// not change the mode itself // not change the mode itself
void prompt(StringView prompt, String initstr, String emptystr, void prompt(StringView prompt, String initstr, String emptystr,
Face prompt_face, PromptFlags flags, Face prompt_face, PromptFlags flags,
Completer completer, PromptCallback callback); PromptCompleter completer, PromptCallback callback);
void set_prompt_face(Face prompt_face); void set_prompt_face(Face prompt_face);
// enter menu mode, callback is called on each selection change, // enter menu mode, callback is called on each selection change,

View File

@ -90,8 +90,8 @@ Vector<LineModification> compute_line_modifications(const Buffer& buffer, size_t
bool operator==(const LineModification& lhs, const LineModification& rhs) bool operator==(const LineModification& lhs, const LineModification& rhs)
{ {
return std::tie(lhs.old_line, lhs.new_line, lhs.num_removed, lhs.num_added) == return lhs.old_line == rhs.old_line and lhs.new_line == rhs.new_line and
std::tie(rhs.old_line, rhs.new_line, rhs.num_removed, rhs.num_added); lhs.num_removed == rhs.num_removed and lhs.num_added == rhs.num_added;
} }
void LineRangeSet::update(ConstArrayView<LineModification> modifs) void LineRangeSet::update(ConstArrayView<LineModification> modifs)

View File

@ -7,6 +7,8 @@
#include "range.hh" #include "range.hh"
#include "vector.hh" #include "vector.hh"
#include <functional>
namespace Kakoune namespace Kakoune
{ {

View File

@ -29,7 +29,6 @@
#include "clock.hh" #include "clock.hh"
#include <fcntl.h> #include <fcntl.h>
#include <locale>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>

View File

@ -1,7 +1,6 @@
#ifndef normal_hh_INCLUDED #ifndef normal_hh_INCLUDED
#define normal_hh_INCLUDED #define normal_hh_INCLUDED
#include "context.hh"
#include "optional.hh" #include "optional.hh"
#include "keys.hh" #include "keys.hh"
#include "keymap_manager.hh" #include "keymap_manager.hh"

View File

@ -11,7 +11,7 @@
#include "string_utils.hh" #include "string_utils.hh"
#include <memory> #include <memory>
#include <type_traits> #include <utility>
namespace Kakoune namespace Kakoune
{ {

View File

@ -6,9 +6,6 @@
#include "assert.hh" #include "assert.hh"
#include "ref_ptr.hh" #include "ref_ptr.hh"
#include <type_traits>
#include <utility>
#ifdef SAFE_PTR_TRACK_CALLSTACKS #ifdef SAFE_PTR_TRACK_CALLSTACKS
#include "backtrace.hh" #include "backtrace.hh"
#include "vector.hh" #include "vector.hh"

View File

@ -3,7 +3,6 @@
#include <cwctype> #include <cwctype>
#include <cwchar> #include <cwchar>
#include <locale>
#include "array_view.hh" #include "array_view.hh"
#include "ranges.hh" #include "ranges.hh"

View File

@ -18,11 +18,15 @@ template<typename BaseIt,
typename CodepointType = Codepoint, typename CodepointType = Codepoint,
typename DifferenceType = CharCount, typename DifferenceType = CharCount,
typename InvalidPolicy = utf8::InvalidPolicy::Pass> typename InvalidPolicy = utf8::InvalidPolicy::Pass>
class iterator : public std::iterator<std::bidirectional_iterator_tag, class iterator
CodepointType, DifferenceType,
CodepointType*, CodepointType>
{ {
public: public:
using value_type = CodepointType;
using difference_type = DifferenceType;
using pointer = CodepointType*;
using reference = CodepointType&;
using iterator_category = std::bidirectional_iterator_tag;
iterator() = default; iterator() = default;
constexpr static bool noexcept_policy = noexcept(InvalidPolicy{}(0)); constexpr static bool noexcept_policy = noexcept(InvalidPolicy{}(0));

View File

@ -12,7 +12,6 @@
#include "option_types.hh" #include "option_types.hh"
#include <algorithm> #include <algorithm>
#include <sstream>
namespace Kakoune namespace Kakoune
{ {

View File

@ -1,10 +1,11 @@
#include "word_db.hh" #include "word_db.hh"
#include "utils.hh" #include "buffer.hh"
#include "line_modification.hh" #include "line_modification.hh"
#include "option_types.hh" #include "option_types.hh"
#include "utf8_iterator.hh"
#include "unit_tests.hh" #include "unit_tests.hh"
#include "utils.hh"
#include "value.hh"
namespace Kakoune namespace Kakoune
{ {
@ -20,7 +21,7 @@ WordDB& get_word_db(const Buffer& buffer)
struct WordSplitter struct WordSplitter
{ {
struct Iterator : std::iterator<std::forward_iterator_tag, StringView> struct Iterator
{ {
Iterator(const char* begin, const WordSplitter& splitter) Iterator(const char* begin, const WordSplitter& splitter)
: m_word_begin{begin}, m_word_end{begin}, m_splitter{&splitter} : m_word_begin{begin}, m_word_end{begin}, m_splitter{&splitter}

View File

@ -1,16 +1,18 @@
#ifndef word_db_hh_INCLUDED #ifndef word_db_hh_INCLUDED
#define word_db_hh_INCLUDED #define word_db_hh_INCLUDED
#include "buffer.hh"
#include "shared_string.hh" #include "shared_string.hh"
#include "hash_map.hh" #include "hash_map.hh"
#include "vector.hh" #include "vector.hh"
#include "ranked_match.hh" #include "ranked_match.hh"
#include "option_manager.hh"
#include "safe_ptr.hh"
namespace Kakoune namespace Kakoune
{ {
using RankedMatchList = Vector<RankedMatch>; using RankedMatchList = Vector<RankedMatch>;
class Buffer;
// maintain a database of words available in a buffer // maintain a database of words available in a buffer
class WordDB : public OptionManagerWatcher class WordDB : public OptionManagerWatcher