daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // debug.h: Debugging utilities. |
| 8 | |
| 9 | #ifndef COMMON_DEBUG_H_ |
| 10 | #define COMMON_DEBUG_H_ |
| 11 | |
| 12 | #ifndef WIN32_LEAN_AND_MEAN |
| 13 | #define WIN32_LEAN_AND_MEAN |
| 14 | #endif |
| 15 | #include <windows.h> |
| 16 | #include <stdio.h> |
| 17 | #include <assert.h> |
| 18 | |
| 19 | namespace gl |
| 20 | { |
| 21 | // Outputs text to the debugging log |
| 22 | void trace(const char *format, ...); |
| 23 | } |
| 24 | |
| 25 | // A macro to output a trace of a function call and its arguments to the debugging log |
| 26 | #ifndef NDEBUG |
| 27 | #define TRACE(arguments, ...) gl::trace("trace: %s("arguments")\n", __FUNCTION__, __VA_ARGS__) |
| 28 | #else |
| 29 | #define TRACE(...) ((void)0) |
| 30 | #endif |
| 31 | |
| 32 | // A macro to output a function call and its arguments to the debugging log, to denote an item in need of fixing. Will occur even in release mode. |
| 33 | #define FIXME(arguments, ...) gl::trace("fixme: %s("arguments")\n", __FUNCTION__, __VA_ARGS__) |
| 34 | |
| 35 | // A macro to output a function call and its arguments to the debugging log, in case of error. Will occur even in release mode. |
| 36 | #define ERR(arguments, ...) gl::trace("err: %s("arguments")\n", __FUNCTION__, __VA_ARGS__) |
| 37 | |
| 38 | // A macro asserting a condition and outputting failures to the debug log |
| 39 | #define ASSERT(expression) do { \ |
| 40 | if(!(expression)) \ |
| 41 | ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ |
| 42 | assert(expression); \ |
| 43 | } while(0) |
| 44 | |
| 45 | |
| 46 | // A macro to indicate unimplemented functionality |
| 47 | #ifndef NDEBUG |
| 48 | #define UNIMPLEMENTED() do { \ |
| 49 | FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \ |
| 50 | assert(false); \ |
| 51 | } while(0) |
| 52 | #else |
| 53 | #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__) |
| 54 | #endif |
| 55 | |
| 56 | // A macro for code which is not expected to be reached under valid assumptions |
| 57 | #ifndef NDEBUG |
| 58 | #define UNREACHABLE() do { \ |
| 59 | ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \ |
| 60 | assert(false); \ |
| 61 | } while(0) |
| 62 | #else |
| 63 | #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__) |
| 64 | #endif |
| 65 | |
| 66 | // A macro functioning as a compile-time assert to validate constant conditions |
| 67 | #define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition)?1:-1] |
| 68 | |
| 69 | #endif // COMMON_DEBUG_H_ |