Euphoria
assert.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5
8#define BREAK_IN_DEBUG() \
9 do \
10 { \
11 } while(false)
12
13
14#ifdef RELEASE
15
16// todo(Gustav): implement assert for windows...
17
18#define ASSERT(x)
19#define ASSERTX(x, ...)
20#define DIE(message)
21
22#else
23
24#if !defined(__PRETTY_FUNCTION__) && !defined(__GNUC__)
25 #define __PRETTY_FUNCTION__ __FUNCSIG__
26#endif
27
30#define IMPLEMENT_ASSERT_LIB
31
32// todo(Gustav): stb libraries and rapidjson aren't using our assert
36#define ASSERT(x) \
37 do \
38 { \
39 if(x) \
40 { \
41 } \
42 else \
43 { \
44 if(::eu::assertlib::is_throwing() == false) { BREAK_IN_DEBUG(); } \
45 ::eu::assertlib::on_assert( \
46 #x, \
47 __LINE__, \
48 __FILE__, \
49 "", \
50 {}, \
51 __PRETTY_FUNCTION__); \
52 } \
53 } while(false)
54
59#define ASSERTX(x, ...) \
60 do \
61 { \
62 if(x) \
63 { \
64 } \
65 else \
66 { \
67 if(::eu::assertlib::is_throwing() == false) { BREAK_IN_DEBUG(); } \
68 ::eu::assertlib::on_assert( \
69 #x, \
70 __LINE__, \
71 __FILE__, \
72 #__VA_ARGS__, \
73 {__VA_ARGS__}, \
74 __PRETTY_FUNCTION__); \
75 } \
76 } while(false)
77
81#define DIE(message) \
82 ::eu::assertlib::on_assert( \
83 message, \
84 __LINE__, \
85 __FILE__, \
86 "", \
87 {}, \
88 __PRETTY_FUNCTION__)
89
94#define DIEX(message, ...) \
95 ::eu::assertlib::on_assert( \
96 message, \
97 __LINE__, \
98 __FILE__, \
99 #__VA_ARGS__, \
100 {__VA_ARGS__}, \
101 __PRETTY_FUNCTION__)
102
103#endif // _MSC_VER
104
105#ifdef IMPLEMENT_ASSERT_LIB
106
109{
111 struct AssertArgumentValue
112 {
113 std::string value;
114
115 template <typename T>
116 AssertArgumentValue(const T& t)
117 : value(fmt::to_string(t))
118 {}
119 };
120
122 void
123 begin_throwing();
124
126 bool
127 is_throwing();
128
130 void
131 on_assert
132 (
133 const char* expression,
134 int line,
135 const char* file,
136 const char* argstr,
137 const std::vector<AssertArgumentValue>& arguments,
138 const char* function
139 );
140}
141#endif // IMPLEMENT_ASSERT_LIB
142