Sfoglia il codice sorgente

base: implement UNUSED() macro and put it here and there.

legacy
Sam Hocevar sam 12 anni fa
parent
commit
b25222af18
9 ha cambiato i file con 71 aggiunte e 43 eliminazioni
  1. +55
    -17
      src/lol/base/assert.h
  2. +2
    -5
      src/platform/android/androidapp.cpp
  3. +2
    -0
      test/benchsuite.cpp
  4. +2
    -0
      test/math/pi.cpp
  5. +2
    -14
      test/math/poly.cpp
  6. +2
    -0
      test/math/remez.cpp
  7. +2
    -7
      test/sandbox/sample.cpp
  8. +2
    -0
      test/testsuite.cpp
  9. +2
    -0
      test/xolotl/xolotl.cpp

+ 55
- 17
src/lol/base/assert.h Vedi File

@@ -29,21 +29,29 @@ static inline void Abort()
#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))
#define LOL_GET_63RD(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_COUNT_TO_3(...) \
LOL_EVAL(LOL_GET_63RD(__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_FEW_ARGUMENTS))
#define LOL_COUNT_TO_8(...) \
LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
8, 8, 8, 8, 8, 7, 6, 5, 4, 3, \
2, 1, TOO_FEW_ARGUMENTS))

/* Three levels of dispatch are needed because of Visual Studio's bizarre
* handling of __VA_ARGS__ inside macro calls */
@@ -51,6 +59,35 @@ static inline void Abort()
#define LOL_CAT2(a, b) LOL_CAT3(a,b)
#define LOL_CAT(a, b) LOL_CAT2(a,b)

/*
* UNUSED(): declare one or several variables as unused
*/

#define LOL_UNUSED_1(a01) \
sizeof(a01)
#define LOL_UNUSED_2(a01, a02) \
sizeof(a01) + LOL_UNUSED_1(a02)
#define LOL_UNUSED_3(a01, a02, a03) \
sizeof(a01) + LOL_UNUSED_2(a02, a03)
#define LOL_UNUSED_4(a01, a02, a03, a04) \
sizeof(a01) + LOL_UNUSED_3(a02, a03, a04)
#define LOL_UNUSED_5(a01, a02, a03, a04, a05) \
sizeof(a01) + LOL_UNUSED_4(a02, a03, a04, a05)
#define LOL_UNUSED_6(a01, a02, a03, a04, a05, a06) \
sizeof(a01) + LOL_UNUSED_5(a02, a03, a04, a05, a06)
#define LOL_UNUSED_7(a01, a02, a03, a04, a05, a06, a07) \
sizeof(a01) + LOL_UNUSED_6(a02, a03, a04, a05, a06, a07)
#define LOL_UNUSED_8(a01, a02, a03, a04, a05, a06, a07, a08) \
sizeof(a01) + LOL_UNUSED_7(a02, a03, a04, a05, a06, a07, a08)

#define UNUSED(...) (void)sizeof((void)( \
LOL_CALL(LOL_CAT(LOL_UNUSED_, LOL_CALL(LOL_COUNT_TO_8, (__VA_ARGS__))), \
(__VA_ARGS__))), 0) \

/*
* ASSERT(): test and enforce conditions at runtime
*/

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

@@ -61,12 +98,13 @@ static inline void Abort()
Log::Error("assertion failure: " s "\n", __VA_ARGS__)

#if FINAL_RELEASE
# define ASSERT(...) (void)sizeof(LOL_CALL(LOL_1ST, (__VA_ARGS__)))
# define ASSERT(...) UNUSED(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__))), \
LOL_CALL(LOL_CAT(LOL_ERROR_, LOL_CALL(LOL_COUNT_TO_3, \
(__VA_ARGS__))), \
(__VA_ARGS__)); \
Abort(); \
}


+ 2
- 5
src/platform/android/androidapp.cpp Vedi File

@@ -173,14 +173,11 @@ Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env)
void lol_android_main(void) {}
void lol_android_main(int argc, char **argv)
{
(void)argc;
(void)argv;
UNUSED(argc, argv);
}
void lol_android_main(int argc, char **argv, char **envp)
{
(void)argc;
(void)argv;
(void)envp;
UNUSED(argc, argv, envp);
}

#endif /* __ANDROID__ */


+ 2
- 0
test/benchsuite.cpp Vedi File

@@ -26,6 +26,8 @@ void bench_half(int mode);

int main(int argc, char **argv)
{
UNUSED(argc, argv);

Log::Info("-----------------------\n");
Log::Info(" High precision floats\n");
Log::Info("-----------------------\n");


+ 2
- 0
test/math/pi.cpp Vedi File

@@ -23,6 +23,8 @@ using lol::real;

int main(int argc, char **argv)
{
UNUSED(argc, argv);

printf("Pi: "); real::R_PI().print();
printf("e: "); real::R_E().print();
printf("ln(2): "); real::R_LN2().print();


+ 2
- 14
test/math/poly.cpp Vedi File

@@ -97,6 +97,8 @@ static float floatsin(float f)

int main(int argc, char **argv)
{
UNUSED(argc, argv);

typedef union { float f; uint32_t x; } flint;

int error[5] = { 0 };
@@ -108,17 +110,6 @@ int main(int argc, char **argv)
inspect(a4);
inspect(a5);

//flint v = { 1.433971524239 };
flint v = { 1.555388212204 };
inspect(v.f);
printf("sinf: ");
flint w = { sinf(adjustf(v.f, 0)) };
inspect(w.f);
printf("lols: ");
flint z = { lol_sin(adjustf(v.f, 0)) };
inspect(z.f);

printf("-- START --\n");
for (flint u = { (float)real::R_PI_2() }; u.f > 1e-30; u.x -= 1)
{
union { float f; uint32_t x; } s1 = { sinf(adjustf(u.f, 0)) };
@@ -129,9 +120,6 @@ printf("-- START --\n");
case 3:
case 2:
case 1:
inspect(u.f);
printf("sinf: ");
inspect(sinf(u.f));
if (lol::abs((double)s1.f - (double)s2.f) > 1e-10 * lol::abs(s1.f))
printf("%15.13g %08x: %15.13g %15.13g %08x %08x\n", u.f, u.x, s1.f, s2.f, s1.x, s2.x);
case 0:


+ 2
- 0
test/math/remez.cpp Vedi File

@@ -26,6 +26,8 @@ real g(real const &x) { return exp(x); }

int main(int argc, char **argv)
{
UNUSED(argc, argv);

RemezSolver<4, real> solver;
solver.Run(-1, 1, f, g, 40);
return 0;


+ 2
- 7
test/sandbox/sample.cpp Vedi File

@@ -14,18 +14,13 @@

#include "core.h"

class Moo
{
Moo() {}

virtual int SetState(int state) { return state; }
};

using namespace std;
using namespace lol;

int main(int argc, char **argv)
{
UNUSED(argc, argv);

/* Insert any test code here */
return EXIT_SUCCESS;
}


+ 2
- 0
test/testsuite.cpp Vedi File

@@ -21,6 +21,8 @@

int main(int argc, char **argv)
{
UNUSED(argc, argv);

lol::TextTestRunner runner;
bool success = runner.Run();
return success ? EXIT_SUCCESS : EXIT_FAILURE;


+ 2
- 0
test/xolotl/xolotl.cpp Vedi File

@@ -56,6 +56,8 @@ private:

int main(int argc, char **argv)
{
System::Init(argc, argv);

Application app("Xolotl", ivec2(640, 480), 60.0f);

/* Register some debug stuff */


Caricamento…
Annulla
Salva