2013-07-16 01:43:32 +00:00
|
|
|
/*
|
2013-07-19 17:29:33 +00:00
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
2013-07-16 01:43:32 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
2013-07-19 17:29:33 +00:00
|
|
|
Author: Leonardo de Moura
|
2013-07-16 01:43:32 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef __has_builtin
|
|
|
|
#define __has_builtin(x) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LEAN_DEBUG
|
|
|
|
#define DEBUG_CODE(CODE) CODE
|
|
|
|
#else
|
2013-07-19 17:29:33 +00:00
|
|
|
#define DEBUG_CODE(CODE)
|
2013-07-16 01:43:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define lean_assert(COND) DEBUG_CODE({if (!(COND)) { lean::notify_assertion_violation(__FILE__, __LINE__, #COND); lean::invoke_debugger(); }})
|
|
|
|
#define lean_cond_assert(TAG, COND) DEBUG_CODE({if (lean::is_debug_enabled(TAG) && !(COND)) { lean::notify_assertion_violation(__FILE__, __LINE__, #COND); lean::invoke_debugger(); }})
|
|
|
|
|
|
|
|
#if __has_builtin(__builtin_unreachable)
|
|
|
|
#define lean_unreachable() __builtin_unreachable()
|
|
|
|
#else
|
|
|
|
#define lean_unreachable() DEBUG_CODE({lean::notify_assertion_violation(__FILE__, __LINE__, "UNREACHABLE CODE WAS REACHED."); lean::invoke_debugger();})
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LEAN_DEBUG
|
|
|
|
#define lean_verify(COND) if (!(COND)) { lean::notify_assertion_violation(__FILE__, __LINE__, #COND); lean::invoke_debugger(); }
|
|
|
|
#else
|
|
|
|
#define lean_verify(COND) (COND)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace lean {
|
2013-07-18 16:12:07 +00:00
|
|
|
|
2013-07-16 01:43:32 +00:00
|
|
|
void notify_assertion_violation(char const * file_name, int line, char const * condition);
|
|
|
|
void enable_debug(char const * tag);
|
|
|
|
void disable_debug(char const * tag);
|
|
|
|
bool is_debug_enabled(char const * tag);
|
|
|
|
void invoke_debugger();
|
2013-07-18 18:10:15 +00:00
|
|
|
// support for testing
|
2013-07-19 17:29:33 +00:00
|
|
|
void continue_on_violation(bool flag);
|
2013-07-18 18:10:15 +00:00
|
|
|
bool has_violations();
|
2013-07-16 01:43:32 +00:00
|
|
|
|
|
|
|
}
|