Skip to content

Commit ffb474e

Browse files
committed
[Basic] NFC: Factor out _FILENAME_FOR_ASSERT macro
1 parent 9264125 commit ffb474e

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

include/swift/Basic/Assertions.h

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
#define ASSERT_UNLIKELY(expression) ((expression))
2525
#endif
2626

27+
// Visual Studio doesn't have __FILE_NAME__
28+
#ifdef __FILE_NAME__
29+
#define _FILENAME_FOR_ASSERT __FILE_NAME__
30+
#else
31+
#define _FILENAME_FOR_ASSERT __FILE__
32+
#endif
33+
2734
// ================================ Mandatory Asserts ================================
2835

2936
// `ASSERT(expr)`:
@@ -41,27 +48,13 @@
4148
// that are more expensive than you think. You can switch those to
4249
// `CONDITIONAL_ASSERT` or `DEBUG_ASSERT` as needed.
4350

44-
// Visual Studio doesn't have __FILE_NAME__
45-
#ifdef __FILE_NAME__
46-
47-
#define ASSERT(expr) \
48-
do { \
49-
if (ASSERT_UNLIKELY(!(expr))) { \
50-
ASSERT_failure(#expr, __FILE_NAME__, __LINE__, __func__); \
51-
} \
52-
} while (0)
53-
54-
#else
55-
56-
#define ASSERT(expr) \
57-
do { \
58-
if (ASSERT_UNLIKELY(!(expr))) { \
59-
ASSERT_failure(#expr, __FILE__, __LINE__, __func__); \
60-
} \
51+
#define ASSERT(expr) \
52+
do { \
53+
if (ASSERT_UNLIKELY(!(expr))) { \
54+
ASSERT_failure(#expr, _FILENAME_FOR_ASSERT, __LINE__, __func__); \
55+
} \
6156
} while (0)
6257

63-
#endif
64-
6558
// Function that reports the actual failure when it occurs.
6659
void ASSERT_failure(const char *expr, const char *file, int line, const char *func);
6760

0 commit comments

Comments
 (0)