Browse Source

core: implement a cool ASSERT() macro.

legacy
Sam Hocevar sam 12 years ago
parent
commit
8613d04c03
8 changed files with 95 additions and 54 deletions
  1. +6
    -6
      src/Makefile.am
  2. +0
    -0
      src/base/log.cpp
  3. +2
    -3
      src/core.h
  4. +78
    -0
      src/lol/base/assert.h
  5. +3
    -3
      src/lol/base/log.h
  6. +0
    -36
      src/lol/debug.h
  7. +3
    -3
      src/lolcore.vcxproj
  8. +3
    -3
      src/lolcore.vcxproj.filters

+ 6
- 6
src/Makefile.am View File

@@ -15,13 +15,13 @@ liblol_a_SOURCES = \
worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \ worldentity.cpp worldentity.h gradient.cpp gradient.h gradient.lolfx \
platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \ platform.cpp platform.h sprite.cpp sprite.h camera.cpp camera.h \
\ \
lol/base/types.h lol/base/array.h lol/base/string.h lol/base/hash.h \
lol/base/map.h \
lol/base/log.h lol/base/array.h lol/base/types.h lol/base/array.h \
lol/base/string.h lol/base/hash.h lol/base/map.h \
lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \
lol/math/math.h lol/math/geometry.h \ lol/math/math.h lol/math/geometry.h \
lol/sys/init.h lol/sys/log.h lol/sys/thread.h lol/sys/timer.h \
lol/sys/init.h lol/sys/thread.h lol/sys/timer.h \
lol/image/color.h \ lol/image/color.h \
lol/unit.h lol/debug.h \
lol/unit.h \
\ \
generated/location.hh generated/position.hh generated/stack.hh \ generated/location.hh generated/position.hh generated/stack.hh \
\ \
@@ -42,7 +42,7 @@ liblol_a_SOURCES = \
$(d3d9_sources) \ $(d3d9_sources) \
$(android_sources) \ $(android_sources) \
\ \
base/hash.cpp base/string.cpp \
base/hash.cpp base/log.cpp base/string.cpp \
\ \
math/vector.cpp math/real.cpp math/half.cpp math/trig.cpp \ math/vector.cpp math/real.cpp math/half.cpp math/trig.cpp \
math/geometry.cpp \ math/geometry.cpp \
@@ -69,7 +69,7 @@ liblol_a_SOURCES = \
\ \
mesh/mesh.cpp mesh/mesh.h \ mesh/mesh.cpp mesh/mesh.h \
\ \
sys/init.cpp sys/log.cpp sys/timer.cpp \
sys/init.cpp sys/timer.cpp \
sys/threadbase.h \ sys/threadbase.h \
\ \
image/image.cpp image/image.h image/image-private.h \ image/image.cpp image/image.h image/image-private.h \


src/sys/log.cpp → src/base/log.cpp View File


+ 2
- 3
src/core.h View File

@@ -74,9 +74,9 @@ static inline int isnan(float f)
#endif #endif


// Base types // Base types
#include <lol/debug.h>

#include <lol/base/types.h> #include <lol/base/types.h>
#include <lol/base/log.h>
#include <lol/base/assert.h>
#include <lol/base/array.h> #include <lol/base/array.h>
#include <lol/base/string.h> #include <lol/base/string.h>
#include <lol/base/hash.h> #include <lol/base/hash.h>
@@ -89,7 +89,6 @@ static inline int isnan(float f)
#include <lol/math/geometry.h> #include <lol/math/geometry.h>


#include <lol/sys/init.h> #include <lol/sys/init.h>
#include <lol/sys/log.h>
#include <lol/sys/thread.h> #include <lol/sys/thread.h>
#include <lol/sys/timer.h> #include <lol/sys/timer.h>




+ 78
- 0
src/lol/base/assert.h View File

@@ -0,0 +1,78 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if !defined __LOL_BASE_ASSERT_H__
#define __LOL_BASE_ASSERT_H__

#include <cstdlib>

namespace lol
{

static inline void Abort()
{
#if defined __CELLOS_LV2__
*(uint32_t *)NULL = 0xdead;
#else
std::abort();
#endif
}

#define LOL_CALL(macro, args) macro args
#define LOL_EVAL(a) a
#define LOL_1ST(a, ...) a

#define LOL_NUM2(a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, \
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \
a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \
a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \
a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \
a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, \
a61, a62, a63, ...) a63
#define LOL_NUM(...) \
LOL_EVAL(LOL_NUM2(__VA_ARGS__, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
2, 1, TOO_MANY_ARGUMENTS))

/* Three levels of dispatch are needed because of Visual Studio's bizarre
* handling of __VA_ARGS__ inside macro calls */
#define LOL_CAT3(a, b) a##b
#define LOL_CAT2(a, b) LOL_CAT3(a,b)
#define LOL_CAT(a, b) LOL_CAT2(a,b)

#define LOL_ERROR_1(t) \
Log::Error("assertion failure: " #t "\n")

#define LOL_ERROR_2(t, s) \
Log::Error("assertion failure: %s\n", s)

#define LOL_ERROR_3(t, s, ...) \
Log::Error("assertion failure: " s "\n", __VA_ARGS__)

#if FINAL_RELEASE
# define ASSERT(...) (void)sizeof(LOL_CALL(LOL_1ST, (__VA_ARGS__)))
#else
# define ASSERT(...) \
if (!(LOL_CALL(LOL_1ST, (__VA_ARGS__)))) \
{ \
LOL_CALL(LOL_CAT(LOL_ERROR_, LOL_CALL(LOL_NUM, (__VA_ARGS__))), \
(__VA_ARGS__)); \
Abort(); \
}
#endif

} /* namespace lol */

#endif // __LOL_BASE_ASSERT_H__


src/lol/sys/log.h → src/lol/base/log.h View File

@@ -14,8 +14,8 @@
// The central logging system. // The central logging system.
// //


#if !defined __LOL_SYS_LOG_H__
#define __LOL_SYS_LOG_H__
#if !defined __LOL_BASE_LOG_H__
#define __LOL_BASE_LOG_H__


#include <stdint.h> #include <stdint.h>
#include <cstdarg> #include <cstdarg>
@@ -51,5 +51,5 @@ private:


} /* namespace lol */ } /* namespace lol */


#endif // __LOL_SYS_LOG_H__
#endif // __LOL_BASE_LOG_H__



+ 0
- 36
src/lol/debug.h View File

@@ -1,36 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

//
// Debug utilities
// ---------------
//

#if !defined __LOL_DEBUG_H__
#define __LOL_DEBUG_H__

#include <cstdlib>

namespace lol
{

static inline void Abort()
{
#if defined __CELLOS_LV2__
*(uint32_t *)NULL = 0;
#else
std::abort();
#endif
}

} /* namespace lol */

#endif // __LOL_DEBUG_H__


+ 3
- 3
src/lolcore.vcxproj View File

@@ -235,6 +235,7 @@
<ClCompile Include="bullet\LinearMath\btSerializer.cpp" /> <ClCompile Include="bullet\LinearMath\btSerializer.cpp" />
<ClCompile Include="camera.cpp" /> <ClCompile Include="camera.cpp" />
<ClCompile Include="base\hash.cpp" /> <ClCompile Include="base\hash.cpp" />
<ClCompile Include="base\log.cpp" />
<ClCompile Include="base\string.cpp" /> <ClCompile Include="base\string.cpp" />
<ClCompile Include="debug\fps.cpp" /> <ClCompile Include="debug\fps.cpp" />
<ClCompile Include="debug\record.cpp" /> <ClCompile Include="debug\record.cpp" />
@@ -293,7 +294,6 @@
<ClCompile Include="scene.cpp" /> <ClCompile Include="scene.cpp" />
<ClCompile Include="sprite.cpp" /> <ClCompile Include="sprite.cpp" />
<ClCompile Include="sys\init.cpp" /> <ClCompile Include="sys\init.cpp" />
<ClCompile Include="sys\log.cpp" />
<ClCompile Include="sys\timer.cpp" /> <ClCompile Include="sys\timer.cpp" />
<ClCompile Include="text.cpp" /> <ClCompile Include="text.cpp" />
<ClCompile Include="ticker.cpp" /> <ClCompile Include="ticker.cpp" />
@@ -586,11 +586,12 @@
<ClInclude Include="loldebug.h" /> <ClInclude Include="loldebug.h" />
<ClInclude Include="lolgl.h" /> <ClInclude Include="lolgl.h" />
<ClInclude Include="lol\base\array.h" /> <ClInclude Include="lol\base\array.h" />
<ClInclude Include="lol\base\assert.h" />
<ClInclude Include="lol\base\hash.h" /> <ClInclude Include="lol\base\hash.h" />
<ClInclude Include="lol\base\log.h" />
<ClInclude Include="lol\base\map.h" /> <ClInclude Include="lol\base\map.h" />
<ClInclude Include="lol\base\string.h" /> <ClInclude Include="lol\base\string.h" />
<ClInclude Include="lol\base\types.h" /> <ClInclude Include="lol\base\types.h" />
<ClInclude Include="lol\debug.h" />
<ClInclude Include="lol\image\color.h" /> <ClInclude Include="lol\image\color.h" />
<ClInclude Include="lol\math\geometry.h" /> <ClInclude Include="lol\math\geometry.h" />
<ClInclude Include="lol\math\half.h" /> <ClInclude Include="lol\math\half.h" />
@@ -599,7 +600,6 @@
<ClInclude Include="lol\math\remez.h" /> <ClInclude Include="lol\math\remez.h" />
<ClInclude Include="lol\math\vector.h" /> <ClInclude Include="lol\math\vector.h" />
<ClInclude Include="lol\sys\init.h" /> <ClInclude Include="lol\sys\init.h" />
<ClInclude Include="lol\sys\log.h" />
<ClInclude Include="lol\sys\thread.h" /> <ClInclude Include="lol\sys\thread.h" />
<ClInclude Include="lol\sys\timer.h" /> <ClInclude Include="lol\sys\timer.h" />
<ClInclude Include="lol\unit.h" /> <ClInclude Include="lol\unit.h" />


+ 3
- 3
src/lolcore.vcxproj.filters View File

@@ -731,9 +731,6 @@
<ClInclude Include="gpu\indexbuffer.h"> <ClInclude Include="gpu\indexbuffer.h">
<Filter>gpu</Filter> <Filter>gpu</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="lol\debug.h">
<Filter>lol</Filter>
</ClInclude>
<ClInclude Include="input\input.h"> <ClInclude Include="input\input.h">
<Filter>input</Filter> <Filter>input</Filter>
</ClInclude> </ClInclude>
@@ -1613,6 +1610,9 @@
<ClInclude Include="lol\base\array.h"> <ClInclude Include="lol\base\array.h">
<Filter>lol\base</Filter> <Filter>lol\base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="lol\base\assert.h">
<Filter>lol\base</Filter>
</ClInclude>
<ClInclude Include="lol\base\hash.h"> <ClInclude Include="lol\base\hash.h">
<Filter>lol\base</Filter> <Filter>lol\base</Filter>
</ClInclude> </ClInclude>


Loading…
Cancel
Save