Euphoria
assert.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include "fmt/format.h"
7
10#ifdef _WIN32
11 #define BREAK_IN_DEBUG() \
12 do \
13 { \
14 __debugbreak(); \
15 } while(false)
16#else
17#define BREAK_IN_DEBUG() \
18 do \
19 { \
20 } while(false)
21#endif
22
23#ifdef RELEASE
24
25// todo(Gustav): implement assert for windows...
26
27#define ASSERT(x)
28#define ASSERTX(x, ...)
29#define DIE(message)
30
31#else
32
33#if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__)
34 #define __PRETTY_FUNCTION__ __FUNCSIG__
35#endif
36
39#define IMPLEMENT_ASSERT_LIB
40
41// todo(Gustav): stb libraries and rapidjson aren't using our assert
45#define ASSERT(x) \
46 do \
47 { \
48 if(x) \
49 { \
50 } \
51 else \
52 { \
53 if(::eu::assertlib::is_throwing() == false) { BREAK_IN_DEBUG(); } \
54 else ::eu::assertlib::on_assert( \
55 #x, \
56 __LINE__, \
57 __FILE__, \
58 "", \
59 {}, \
60 __PRETTY_FUNCTION__); \
61 } \
62 } while(false)
63
68#define ASSERTX(x, ...) \
69 do \
70 { \
71 if(x) \
72 { \
73 } \
74 else \
75 { \
76 if(::eu::assertlib::is_throwing() == false) { BREAK_IN_DEBUG(); } \
77 ::eu::assertlib::on_assert( \
78 #x, \
79 __LINE__, \
80 __FILE__, \
81 #__VA_ARGS__, \
82 {__VA_ARGS__}, \
83 __PRETTY_FUNCTION__); \
84 } \
85 } while(false)
86
90#define DIE(message) \
91 ::eu::assertlib::on_assert( \
92 message, \
93 __LINE__, \
94 __FILE__, \
95 "", \
96 {}, \
97 __PRETTY_FUNCTION__)
98
103#define DIEX(message, ...) \
104 ::eu::assertlib::on_assert( \
105 message, \
106 __LINE__, \
107 __FILE__, \
108 #__VA_ARGS__, \
109 {__VA_ARGS__}, \
110 __PRETTY_FUNCTION__)
111
112#endif // _MSC_VER
113
114#ifdef IMPLEMENT_ASSERT_LIB
115
118{
120 struct AssertArgumentValue
121 {
122 std::string value;
123
124 template <typename T>
125 AssertArgumentValue(const T& t)
126 : value(fmt::to_string(t))
127 {}
128 };
129
131 void
132 begin_throwing();
133
135 bool
136 is_throwing();
137
139 void
140 on_assert
141 (
142 const char* expression,
143 int line,
144 const char* file,
145 const char* argstr,
146 const std::vector<AssertArgumentValue>& arguments,
147 const char* function
148 );
149}
150#endif // IMPLEMENT_ASSERT_LIB
151