CTR Pia  4.11.3
Game Communication Engine
assert.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: assert.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/platform.h>
18 
19 
20 // @addtogroup pia_common_debug_macro Definitions of Debugging Macros Provided by the Pia Library
21 // @brief Specifies the debugging macros provided by the Pia library.
22 //! @{
23 //! @name Assert
24 //! @{
25 
26 /*!
27  @brief Immediately ends the program if the <tt><var>EXP</var></tt> argument is <tt>false</tt> or <tt>NULL</tt>.
28 
29  @details When you use this macro, all strings that you have output using the <tt>@ref PIA_CACHED_PRINTF</tt> macro are output from the cache.
30 
31  @details This macro is ignored in release builds.
32 
33  @param[in] EXP Specifies to forcibly end the program if this argument is <tt>false</tt> or <tt>NULL</tt>.
34 
35  @see PIA_CACHED_PRINTF
36  */
37 #if NN_PIA_ENABLE_ASSERT
38 #define PIA_ASSERT(EXP) \
39  if (!(EXP)) \
40  { \
41  ::nn::pia::Assert(#EXP, PIA_CODE_POSITION_FILE, PIA_CODE_POSITION_LINE, NULL); \
42  }
43 #else
44 #define PIA_ASSERT(EXP) ((void)0)
45 #endif
46 
47 
48 /*!
49  @brief Immediately ends the program if the <tt><var>EXP</var></tt> argument is <tt>false</tt> or <tt>NULL</tt>.
50 
51  @details When you use this macro, all strings that you have output using the <tt>@ref PIA_CACHED_PRINTF</tt> macro are output from the cache.
52 
53  @details This macro is ignored in release builds.
54 
55  @param[in] EXP Specifies to forcibly end the program if this argument is <tt>false</tt> or <tt>NULL</tt>.
56  @param[in] ... Specifies variable arguments equivalent to those of the <tt>printf</tt> function in the standard library.
57 
58  @see PIA_CACHED_PRINTF
59  */
60 #if NN_PIA_ENABLE_ASSERT
61 #define PIA_ASSERTMSG(EXP, ...) \
62  if (!(EXP)) \
63  { \
64  ::nn::pia::Assert(#EXP, PIA_CODE_POSITION_FILE, PIA_CODE_POSITION_LINE, __VA_ARGS__); \
65  }
66 #else
67 #define PIA_ASSERTMSG(EXP, ...) ((void)0)
68 #endif
69 
70 
71 //! @cond PRIVATE
72 #define PIA_MACRO_CAT(l, r) l##r
73 #define PIA_MACRO_EXPANDING_CAT(l, r) PIA_MACRO_CAT(l, r)
74 //! @endcond
75 
76 /*!
77  @brief Results in a compiler error if <tt><var>EXP</var></tt> is <tt>false</tt> or <tt>NULL</tt>.
78 
79  @details This is a compile-time (static) assertion macro.
80  Specify a constant expression for the <tt><var>EXP</var></tt> argument.
81 
82  @param[in] EXP Specifies a constant expression. A compiler error results if this argument is <tt>false</tt> or <tt>NULL</tt>.
83  */
84 #define PIA_COMPILE_ASSERT(EXP) \
85  typedef ::nn::pia::PIA_COMPILE_ASSERT_INNER< \
86  sizeof(::nn::pia::PIA_COMPILE_ASSERT_FAILURE<static_cast<bool>(EXP)>)> \
87 PIA_MACRO_EXPANDING_CAT(pia_compile_assert_at_, __LINE__)
88 
89 
90 //! @}
91 
92 
93 //! @name Panic
94 //! @{
95 
96 /*!
97  @brief Immediately ends the program.
98 
99  @details When you use this macro, all strings that you have output using the <tt>@ref PIA_CACHED_PRINTF</tt> macro are output from the cache.
100 
101  @param[in] ... Specifies variable arguments equivalent to those of the <tt>printf</tt> function in the standard library.
102 
103  @see PIA_CACHED_PRINTF
104  */
105 #if NN_PIA_ENABLE_ASSERT
106 #define PIA_PANIC(...) ::nn::pia::Panic(PIA_CODE_POSITION_FILE, PIA_CODE_POSITION_LINE, __VA_ARGS__)
107 #else
108 #define PIA_PANIC(...) PIA_BASIC_HALT(__VA_ARGS__)
109 #endif
110 
111 //! @}
112 //! @}
113 
114 
115 namespace nn
116 {
117 namespace pia
118 {
119 
120 /*!
121 @cond PRIVATE
122  @brief Evaluates an assertion.
123 
124  @details This function is meant to be used by macros such as <tt>PIA_ASSERT</tt> or <tt>PIA_ASSERTMSG</tt>.
125 
126  We do not recommend calling this function directly.
127 
128  @param[in] pExp Specifies a conditional expression in text format.
129  @param[in] pPos Specifies a location in code in text format. (<tt>__FILE__</tt>, <tt>__FUNCTION__</tt>, <tt>__MODULE__</tt>, and so on.)
130  @param[in] line Specifies the line number.
131  @param[in] pMsg Specifies an additional message to output on assertion.
132  */
133 void Assert(const char* pExp, const char* pPos, u32 line, const char* pMsg, ...);
134 //! @endcond
135 
136 
137 /*!
138 @cond PRIVATE
139  @brief Triggers an immediate panic of the running kernel.
140 
141  @details This function is meant to be used by macros such as <tt>PIA_PANIC</tt>.
142 
143  We do not recommend calling this function directly.
144 
145  @param[in] pPos Specifies a location in code in text format. (<tt>__FILE__</tt>, <tt>__FUNCTION__</tt>, <tt>__MODULE__</tt>, and so on.)
146  @param[in] line Specifies the line number.
147  @param[in] pMsg Specifies an additional message to output on assertion.
148  */
149 void Panic(const char* pPos, u32 line, const char* pMsg, ...);
150 //! @endcond
151 
152 
153 /*!
154 @cond PRIVATE
155  @brief Represents a template class for compiler assertions.
156 
157  @details These template classes are meant to be used by macros such as <tt>PIA_COMPILE_ASSERT</tt>.
158 
159  We do not recommend using this template class for other purposes.
160  */
161 template <bool b>
162 struct PIA_COMPILE_ASSERT_FAILURE;
163 template <>
164 struct PIA_COMPILE_ASSERT_FAILURE<true>
165 {
166 };
167 template <int x>
168 struct PIA_COMPILE_ASSERT_INNER
169 {
170 };
171 //! @endcond
172 }
173 } // end of namespace nn::pia
Definition: assert.h:115