Changeset 2297 for trunk


Ignore:
Timestamp:
Jan 29, 2013, 4:59:02 PM (7 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/base/assert.h

    r2265 r2297  
    3030#define LOL_1ST(a, ...) a
    3131
    32 #define LOL_NUM2(a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, \
    33                  a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \
    34                  a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \
    35                  a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \
    36                  a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \
    37                  a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, \
    38                  a61, a62, a63, ...) a63
    39 #define LOL_NUM(...) \
    40     LOL_EVAL(LOL_NUM2(__VA_ARGS__, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    41                                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    42                                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    43                                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    44                                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    45                                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
    46                                    2, 1, TOO_MANY_ARGUMENTS))
     32#define LOL_GET_63RD(a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, \
     33                     a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \
     34                     a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \
     35                     a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \
     36                     a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \
     37                     a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, \
     38                     a61, a62, a63, ...) a63
     39#define LOL_COUNT_TO_3(...) \
     40    LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
     41                                       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
     42                                       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
     43                                       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
     44                                       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
     45                                       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \
     46                                       2, 1, TOO_FEW_ARGUMENTS))
     47#define LOL_COUNT_TO_8(...) \
     48    LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
     49                                       8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
     50                                       8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
     51                                       8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
     52                                       8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \
     53                                       8, 8, 8, 8, 8, 7, 6, 5, 4, 3, \
     54                                       2, 1, TOO_FEW_ARGUMENTS))
    4755
    4856/* Three levels of dispatch are needed because of Visual Studio's bizarre
     
    5159#define LOL_CAT2(a, b) LOL_CAT3(a,b)
    5260#define LOL_CAT(a, b) LOL_CAT2(a,b)
     61
     62/*
     63 * UNUSED(): declare one or several variables as unused
     64 */
     65
     66#define LOL_UNUSED_1(a01) \
     67    sizeof(a01)
     68#define LOL_UNUSED_2(a01, a02) \
     69    sizeof(a01) + LOL_UNUSED_1(a02)
     70#define LOL_UNUSED_3(a01, a02, a03) \
     71    sizeof(a01) + LOL_UNUSED_2(a02, a03)
     72#define LOL_UNUSED_4(a01, a02, a03, a04) \
     73    sizeof(a01) + LOL_UNUSED_3(a02, a03, a04)
     74#define LOL_UNUSED_5(a01, a02, a03, a04, a05) \
     75    sizeof(a01) + LOL_UNUSED_4(a02, a03, a04, a05)
     76#define LOL_UNUSED_6(a01, a02, a03, a04, a05, a06) \
     77    sizeof(a01) + LOL_UNUSED_5(a02, a03, a04, a05, a06)
     78#define LOL_UNUSED_7(a01, a02, a03, a04, a05, a06, a07) \
     79    sizeof(a01) + LOL_UNUSED_6(a02, a03, a04, a05, a06, a07)
     80#define LOL_UNUSED_8(a01, a02, a03, a04, a05, a06, a07, a08) \
     81    sizeof(a01) + LOL_UNUSED_7(a02, a03, a04, a05, a06, a07, a08)
     82
     83#define UNUSED(...) (void)sizeof((void)( \
     84    LOL_CALL(LOL_CAT(LOL_UNUSED_, LOL_CALL(LOL_COUNT_TO_8, (__VA_ARGS__))), \
     85             (__VA_ARGS__))), 0) \
     86
     87/*
     88 * ASSERT(): test and enforce conditions at runtime
     89 */
    5390
    5491#define LOL_ERROR_1(t) \
     
    6299
    63100#if FINAL_RELEASE
    64 #   define ASSERT(...) (void)sizeof(LOL_CALL(LOL_1ST, (__VA_ARGS__)))
     101#   define ASSERT(...) UNUSED(LOL_CALL(LOL_1ST, (__VA_ARGS__)))
    65102#else
    66103#   define ASSERT(...) \
    67104        if (!(LOL_CALL(LOL_1ST, (__VA_ARGS__)))) \
    68105        { \
    69             LOL_CALL(LOL_CAT(LOL_ERROR_, LOL_CALL(LOL_NUM, (__VA_ARGS__))), \
     106            LOL_CALL(LOL_CAT(LOL_ERROR_, LOL_CALL(LOL_COUNT_TO_3, \
     107                                                  (__VA_ARGS__))), \
    70108                     (__VA_ARGS__)); \
    71109            Abort(); \
  • trunk/src/platform/android/androidapp.cpp

    r2222 r2297  
    174174void lol_android_main(int argc, char **argv)
    175175{
    176     (void)argc;
    177     (void)argv;
     176    UNUSED(argc, argv);
    178177}
    179178void lol_android_main(int argc, char **argv, char **envp)
    180179{
    181     (void)argc;
    182     (void)argv;
    183     (void)envp;
     180    UNUSED(argc, argv, envp);
    184181}
    185182
  • trunk/test/benchsuite.cpp

    r2183 r2297  
    2727int main(int argc, char **argv)
    2828{
     29    UNUSED(argc, argv);
     30
    2931    Log::Info("-----------------------\n");
    3032    Log::Info(" High precision floats\n");
  • trunk/test/math/pi.cpp

    r2183 r2297  
    2424int main(int argc, char **argv)
    2525{
     26    UNUSED(argc, argv);
     27
    2628    printf("Pi: "); real::R_PI().print();
    2729    printf("e: "); real::R_E().print();
  • trunk/test/math/poly.cpp

    r2183 r2297  
    9898int main(int argc, char **argv)
    9999{
     100    UNUSED(argc, argv);
     101
    100102    typedef union { float f; uint32_t x; } flint;
    101103
     
    109111    inspect(a5);
    110112
    111 //flint v = { 1.433971524239 };
    112 flint v = { 1.555388212204 };
    113 inspect(v.f);
    114 printf("sinf: ");
    115 flint w = { sinf(adjustf(v.f, 0)) };
    116 inspect(w.f);
    117 printf("lols: ");
    118 flint z = { lol_sin(adjustf(v.f, 0)) };
    119 inspect(z.f);
    120 
    121 printf("-- START --\n");
    122113    for (flint u = { (float)real::R_PI_2() }; u.f > 1e-30; u.x -= 1)
    123114    {
     
    130121        case 2:
    131122        case 1:
    132 inspect(u.f);
    133 printf("sinf: ");
    134 inspect(sinf(u.f));
    135123            if (lol::abs((double)s1.f - (double)s2.f) > 1e-10 * lol::abs(s1.f))
    136124                printf("%15.13g %08x: %15.13g %15.13g %08x %08x\n", u.f, u.x, s1.f, s2.f, s1.x, s2.x);
  • trunk/test/math/remez.cpp

    r2183 r2297  
    2727int main(int argc, char **argv)
    2828{
     29    UNUSED(argc, argv);
     30
    2931    RemezSolver<4, real> solver;
    3032    solver.Run(-1, 1, f, g, 40);
  • trunk/test/sandbox/sample.cpp

    r2183 r2297  
    1515#include "core.h"
    1616
    17 class Moo
    18 {
    19     Moo() {}
    20 
    21     virtual int SetState(int state) { return state; }
    22 };
    23 
    2417using namespace std;
    2518using namespace lol;
     
    2720int main(int argc, char **argv)
    2821{
     22    UNUSED(argc, argv);
     23
    2924    /* Insert any test code here */
    3025    return EXIT_SUCCESS;
  • trunk/test/testsuite.cpp

    r2276 r2297  
    2222int main(int argc, char **argv)
    2323{
     24    UNUSED(argc, argv);
     25
    2426    lol::TextTestRunner runner;
    2527    bool success = runner.Run();
  • trunk/test/xolotl/xolotl.cpp

    r2183 r2297  
    5757int main(int argc, char **argv)
    5858{
     59    System::Init(argc, argv);
     60
    5961    Application app("Xolotl", ivec2(640, 480), 60.0f);
    6062
Note: See TracChangeset for help on using the changeset viewer.