Skip to content

Commit

Permalink
Rename macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravindu-Hirimuthugoda committed Jul 15, 2023
1 parent 6e062e2 commit a2be3b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions include/nomp-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ int nomp_log_set_verbose(const int verbose);
int nomp_log_(const char *desc, int logno, nomp_log_type type,
const char *fname, unsigned line_no, ...);

#define nomp_num_helper(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
#define nomp_num(...) nomp_num_helper(__VA_ARGS__, 2, 2, 2, 2, 2, 2, 2, 1, 0)
#define NOMP_CASE_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
#define NOMP_CASE(...) NOMP_CASE_IMPL(__VA_ARGS__, 2, 2, 2, 2, 2, 2, 2, 1, 0)

#define nomp_first_helper(first, ...) first
#define nomp_first(...) nomp_first_helper(__VA_ARGS__, throwaway)
#define NOMP_FIRST_IMPL(first, ...) first
#define NOMP_FIRST(...) NOMP_FIRST_IMPL(__VA_ARGS__, throwaway)

#define nomp_rest_helper_2(first, ...) , __VA_ARGS__
#define nomp_rest_helper_1(first)
#define nomp_rest_helper_(num, ...) nomp_rest_helper_##num(__VA_ARGS__)
#define nomp_rest_helper(num, ...) nomp_rest_helper_(num, __VA_ARGS__)
#define nomp_rest(...) nomp_rest_helper(nomp_num(__VA_ARGS__), __VA_ARGS__)
#define NOMP_REST_IMPL_WITH_2(first, ...) , __VA_ARGS__
#define NOMP_REST_IMPL_WITH_1(first)
#define NOMP_REST_IMPL_(num, ...) NOMP_REST_IMPL_WITH_##num(__VA_ARGS__)
#define NOMP_REST_IMPL(num, ...) NOMP_REST_IMPL_(num, __VA_ARGS__)
#define NOMP_REST(...) NOMP_REST_IMPL(NOMP_CASE(__VA_ARGS__), __VA_ARGS__)

#define nomp_log(logno, type, ...) \
nomp_log_(nomp_first(__VA_ARGS__), logno, type, __FILE__, \
__LINE__ nomp_rest(__VA_ARGS__))
nomp_log_(NOMP_FIRST(__VA_ARGS__), logno, type, __FILE__, \
__LINE__ NOMP_REST(__VA_ARGS__))

/**
* @ingroup nomp_log_utils
Expand Down
12 changes: 6 additions & 6 deletions tests/nomp-test.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ inline static int subtest_(int err, const char *test_name) {
printf("\t%s: %s\033[0m\n", test_name, result);
return err;
}
#define TEST_ARGS_NUM_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
#define TEST_ARGS_NUM(...) \
TEST_ARGS_NUM_HELPER(__VA_ARGS__, 2, 2, 2, 2, 2, 2, 2, 1, 0)
#define TEST_ARGS_CASE_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, N, ...) N
#define TEST_ARGS_CASE(...) \
TEST_ARGS_CASE_IMPL(__VA_ARGS__, 2, 2, 2, 2, 2, 2, 2, 1, 0)

#define SUBTEST_IMPL_WITH_2(subtest, ...) \
subtest_(subtest(__VA_ARGS__), TOSTRING(subtest))
#define SUBTEST_IMPL_WITH_1(subtest) subtest_(subtest(), TOSTRING(subtest))
#define SUBTEST_IMPL(num, ...) SUBTEST_IMPL_WITH_##num(__VA_ARGS__)
#define SUBTEST_HELPER(num, ...) SUBTEST_IMPL(num, __VA_ARGS__)
#define SUBTEST(...) SUBTEST_HELPER(TEST_ARGS_NUM(__VA_ARGS__), __VA_ARGS__)
#define SUBTEST_IMPL_(num, ...) SUBTEST_IMPL_WITH_##num(__VA_ARGS__)
#define SUBTEST_IMPL(num, ...) SUBTEST_IMPL_(num, __VA_ARGS__)
#define SUBTEST(...) SUBTEST_IMPL(TEST_ARGS_CASE(__VA_ARGS__), __VA_ARGS__)

#define nomp_test_assert(cond) \
{ \
Expand Down

0 comments on commit a2be3b0

Please sign in to comment.