Edit

kc3-lang/angle/src/common/debug.h

Branch :

  • Show log

    Commit

  • Author : alokp@chromium.org
    Date : 2010-05-07 14:33:36
    Hash : 7664e55a
    Message : Making glsl-translator cross-platform. Removed unnecessary inclusion of windows.h. Review URL: http://codereview.appspot.com/1136042 git-svn-id: https://angleproject.googlecode.com/svn/trunk@249 736b8ea6-26fd-11df-bfd4-992fa37f6226

  • src/common/debug.h
  • //
    // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    // debug.h: Debugging utilities.
    
    #ifndef COMMON_DEBUG_H_
    #define COMMON_DEBUG_H_
    
    #include <stdio.h>
    #include <assert.h>
    
    namespace gl
    {
        // Outputs text to the debugging log
        void trace(const char *format, ...);
    }
    
    // A macro to output a trace of a function call and its arguments to the debugging log
    #ifndef NDEBUG
        #define TRACE(message, ...) gl::trace("trace: %s"message"\n", __FUNCTION__, __VA_ARGS__)
    #else
        #define TRACE(...) ((void)0)
    #endif
    
    // 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.
    #define FIXME(message, ...) gl::trace("fixme: %s"message"\n", __FUNCTION__, __VA_ARGS__)
    
    // A macro to output a function call and its arguments to the debugging log, in case of error. Will occur even in release mode.
    #define ERR(message, ...) gl::trace("err: %s"message"\n", __FUNCTION__, __VA_ARGS__)
    
    // A macro asserting a condition and outputting failures to the debug log
    #define ASSERT(expression) do { \
        if(!(expression)) \
            ERR("\t! Assert failed in %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
        assert(expression); \
        } while(0)
    
    
    // A macro to indicate unimplemented functionality
    #ifndef NDEBUG
        #define UNIMPLEMENTED() do { \
            FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
            assert(false); \
            } while(0)
    #else
        #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
    #endif
    
    // A macro for code which is not expected to be reached under valid assumptions
    #ifndef NDEBUG
        #define UNREACHABLE() do { \
            ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__); \
            assert(false); \
            } while(0)
    #else
        #define UNREACHABLE() ERR("\t! Unreachable reached: %s(%d)\n", __FUNCTION__, __LINE__)
    #endif
    
    // A macro functioning as a compile-time assert to validate constant conditions
    #define META_ASSERT(condition) typedef int COMPILE_TIME_ASSERT_##__LINE__[static_cast<bool>(condition)?1:-1]
    
    #endif   // COMMON_DEBUG_H_