Add a debug option to Makefile, and use KAK_DEBUG define to remove debug code

This commit is contained in:
Maxime Coste 2013-02-27 19:02:01 +01:00
parent 6f48407f55
commit cd8c36fc50
7 changed files with 28 additions and 8 deletions

View File

@ -5,6 +5,17 @@ deps := $(addprefix ., $(sources:.cc=.d))
CXXFLAGS += -std=c++0x -g -Wall -Wno-reorder -Wno-sign-compare
LDFLAGS += -lmenu -lncursesw -lboost_regex
debug ?= yes
ifeq ($(debug),yes)
CXXFLAGS += -DKAK_DEBUG
else
ifeq ($(debug),no)
CXXFLAGS += -O3
else
$(error debug should be either yes or no)
endif
endif
kak : $(objects)
$(CXX) $(LDFLAGS) $(CXXFLAGS) $(objects) -o $@

View File

@ -16,8 +16,14 @@ void on_assert_failed(const char* message);
#undef assert
#endif
#define assert(condition) \
#ifdef KAK_DEBUG
#define assert(condition) \
if (not (condition)) \
on_assert_failed("assert failed \"" #condition "\" at " __FILE__ ":" TOSTRING(__LINE__))
on_assert_failed("assert failed \"" #condition \
"\" at " __FILE__ ":" TOSTRING(__LINE__))
#else
#define assert(condition)
#endif
#endif // assert_hh_INCLUDED

View File

@ -225,6 +225,7 @@ bool Buffer::redo()
void Buffer::check_invariant() const
{
#ifdef KAK_DEBUG
ByteCount start = 0;
assert(not m_lines.empty());
for (auto& line : m_lines)
@ -234,6 +235,7 @@ void Buffer::check_invariant() const
assert(line.content.back() == '\n');
start += line.length();
}
#endif
}
void Buffer::do_insert(const BufferIterator& pos, const String& content)

View File

@ -27,11 +27,6 @@
namespace Kakoune
{
using namespace std::placeholders;
// berk
extern bool quit_requested;
namespace
{

View File

@ -376,6 +376,7 @@ bool Editor::redo()
void Editor::check_invariant() const
{
#ifdef KAK_DEBUG
assert(not m_selections.empty());
m_selections.check_invariant();
@ -383,6 +384,7 @@ void Editor::check_invariant() const
compare_selections);
assert(std::is_sorted(m_selections.begin(), it, compare_selections));
assert(std::is_sorted(it, m_selections.end(), compare_selections));
#endif
}
void Editor::begin_edition()

View File

@ -48,9 +48,11 @@ bool ParametersParser::has_option(const String& name) const
const String& ParametersParser::option_value(const String& name) const
{
#ifdef KAK_DEBUG
auto it = m_options.find(name);
assert(it != m_options.end());
assert(it->second == true);
#endif
for (size_t i = 0; i < m_params.size(); ++i)
{

View File

@ -26,10 +26,12 @@ BufferIterator Range::end() const
void Range::check_invariant() const
{
#ifdef KAK_DEBUG
assert(m_first.is_valid());
assert(m_last.is_valid());
assert(utf8::is_character_start(m_first));
assert(utf8::is_character_start(m_last));
#endif
}
static void avoid_eol(BufferIterator& it)