@@ -136,29 +136,106 @@ namespace ngraph
136
136
// TODO(amprocte): refactor NGRAPH_CHECK_HELPER so we don't have to introduce a locally-scoped
137
137
// variable (ss___) and risk shadowing.
138
138
//
139
- #define NGRAPH_CHECK_HELPER (exc_class, ctx, check, ...) \
139
+ #define NGRAPH_CHECK_HELPER2 (exc_class, ctx, check, ...) \
140
140
do \
141
141
{ \
142
142
if (!(check)) \
143
143
{ \
144
144
::std::stringstream ss___; \
145
- ::ngraph::write_all_to_stream (ss___, ## __VA_ARGS__); \
145
+ ::ngraph::write_all_to_stream (ss___, __VA_ARGS__); \
146
146
throw exc_class ( \
147
147
(::ngraph::CheckLocInfo{__FILE__, __LINE__, #check}), (ctx), ss___.str ()); \
148
148
} \
149
149
} while (0 )
150
150
151
+ #define NGRAPH_CHECK_HELPER1 (exc_class, ctx, check ) \
152
+ do \
153
+ { \
154
+ if (!(check)) \
155
+ { \
156
+ throw exc_class ((::ngraph::CheckLocInfo{__FILE__, __LINE__, #check}), (ctx), " " ); \
157
+ } \
158
+ } while (0 )
159
+
151
160
// / \brief Macro to check whether a boolean condition holds.
152
161
// / \param cond Condition to check
153
162
// / \param ... Additional error message info to be added to the error message via the `<<`
154
163
// / stream-insertion operator. Note that the expressions here will be evaluated lazily,
155
164
// / i.e., only if the `cond` evalutes to `false`.
156
165
// / \throws ::ngraph::CheckFailure if `cond` is false.
157
- #define NGRAPH_CHECK (cond, ...) \
158
- NGRAPH_CHECK_HELPER (::ngraph::CheckFailure, " " , (cond), ##__VA_ARGS__)
166
+ #define NGRAPH_CHECK (...) NGRAPH_CHECK_HELPER(::ngraph::CheckFailure, " " , __VA_ARGS__)
159
167
160
168
// / \brief Macro to signal a code path that is unreachable in a successful execution. It's
161
169
// / implemented with NGRAPH_CHECK macro.
162
170
// / \param ... Additional error message that should describe why that execution path is unreachable.
163
171
// / \throws ::ngraph::CheckFailure if the macro is executed.
164
- #define NGRAPH_UNREACHABLE (...) NGRAPH_CHECK(false , " Unreachable: " , ##__VA_ARGS__)
172
+ #define NGRAPH_UNREACHABLE (...) NGRAPH_CHECK(false , " Unreachable: " , __VA_ARGS__)
173
+ #define NGRAPH_CHECK_HELPER (exc_class, ctx, ...) \
174
+ CALL_OVERLOAD (NGRAPH_CHECK_HELPER, exc_class, ctx, __VA_ARGS__)
175
+
176
+ #define GLUE (x, y ) x y
177
+
178
+ #define RETURN_ARG_COUNT (_1_, \
179
+ _2_, \
180
+ _3_, \
181
+ _4_, \
182
+ _5_, \
183
+ _6, \
184
+ _7, \
185
+ _8, \
186
+ _9, \
187
+ _10, \
188
+ _11, \
189
+ _12, \
190
+ _13, \
191
+ _14, \
192
+ _15, \
193
+ _16, \
194
+ _17, \
195
+ _18, \
196
+ _19, \
197
+ _20, \
198
+ _21, \
199
+ _22, \
200
+ _23, \
201
+ _24, \
202
+ _25, \
203
+ count, \
204
+ ...) \
205
+ count
206
+ #define EXPAND_ARGS (args ) RETURN_ARG_COUNT args
207
+ #define COUNT_ARGS_MAXN (...) \
208
+ EXPAND_ARGS ((__VA_ARGS__, \
209
+ 2 , \
210
+ 2 , \
211
+ 2 , \
212
+ 2 , \
213
+ 2 , \
214
+ 2 , \
215
+ 2 , \
216
+ 2 , \
217
+ 2 , \
218
+ 2 , \
219
+ 2 , \
220
+ 2 , \
221
+ 2 , \
222
+ 2 , \
223
+ 2 , \
224
+ 2 , \
225
+ 2 , \
226
+ 2 , \
227
+ 2 , \
228
+ 2 , \
229
+ 2 , \
230
+ 2 , \
231
+ 2 , \
232
+ 2 , \
233
+ 1 , \
234
+ 0 ))
235
+
236
+ #define OVERLOAD_MACRO2 (name, count ) name##count
237
+ #define OVERLOAD_MACRO1 (name, count ) OVERLOAD_MACRO2(name, count)
238
+ #define OVERLOAD_MACRO (name, count ) OVERLOAD_MACRO1(name, count)
239
+
240
+ #define CALL_OVERLOAD (name, exc_class, ctx, ...) \
241
+ GLUE (OVERLOAD_MACRO(name, COUNT_ARGS_MAXN(__VA_ARGS__)), (exc_class, ctx, __VA_ARGS__))
0 commit comments