From 2bcaba3bc02cc21c310de5f3ce85c0c900103994 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 6 Feb 2023 22:15:56 +0100 Subject: [PATCH] Factorize into smaller macros --- m-i-list.h | 17 ++++++++++++----- m-i-shared.h | 12 ++++++++++-- m-prioqueue.h | 15 ++++++++++----- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/m-i-list.h b/m-i-list.h index 7e86ae32..a7cc4576 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -122,6 +122,7 @@ typedef struct m_il1st_head_s { ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) + /* Contract respected by all intrusive lists */ #define M_IL1ST_CONTRACT(name, list) do { \ M_ASSERT(list != NULL); \ @@ -160,6 +161,14 @@ typedef struct m_il1st_head_s { it_t: iterator of the intrusive list (name##_it_t) */ #define M_IL1ST_DEF_P3(name, type, oplist, list_t, it_t) \ + M_IL1ST_DEF_TYPE(name, type, oplist, list_t, it_t) \ + M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + M_IL1ST_DEF_CORE(name, type, oplist, list_t, it_t) \ + /* Used of internal macro from m-list */ \ + M_L1ST_ITBASE_DEF(name, type, oplist, list_t, it_t) + +/* Define the type of an intrusive list */ +#define M_IL1ST_DEF_TYPE(name, type, oplist, list_t, it_t) \ \ /* Define the list as a structure containing pointers \ * to the front & back nodes */ \ @@ -183,8 +192,9 @@ typedef struct m_il1st_head_s { typedef type M_C(name, _subtype_ct); \ typedef list_t M_C(name, _ct); \ typedef it_t M_C(name, _it_ct); \ - \ - M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + +/* Define core functions for intrusive lists */ +#define M_IL1ST_DEF_CORE(name, type, oplist, list_t, it_t) \ \ static inline void \ M_C(name, _init)(list_t list) \ @@ -653,9 +663,6 @@ typedef struct m_il1st_head_s { it->prev = next; \ M_IL1ST_CONTRACT(name, list); \ } \ - \ - /* Used of internal macro from m-list */ \ - M_L1ST_ITBASE_DEF(name, type, oplist, list_t, it_t) #if M_USE_SMALL_NAME diff --git a/m-i-shared.h b/m-i-shared.h index 3d6f2221..636a5298 100644 --- a/m-i-shared.h +++ b/m-i-shared.h @@ -101,6 +101,7 @@ M_BEGIN_PROTECTED_CODE ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) + // Deferred evaluatioin #define M_ISHAR3D_PTR_DEF_P1(arg) M_ID( M_ISHAR3D_PTR_DEF_P2 arg ) @@ -113,6 +114,12 @@ M_BEGIN_PROTECTED_CODE M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(ISHARED_PTR_DEF): the given argument is not a valid oplist: " #oplist) #define M_ISHAR3D_PTR_DEF_P3(name, type, oplist, shared_t) \ + M_ISHAR3D_PTR_DEF_TYPE(name, type, oplist, shared_t) \ + M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + M_ISHAR3D_PTR_DEF_CORE(name, type, oplist, shared_t) \ + +/* Define the types */ +#define M_ISHAR3D_PTR_DEF_TYPE(name, type, oplist, shared_t) \ \ /* The shared pointer is only a pointer to the type */ \ typedef type *shared_t; \ @@ -120,8 +127,9 @@ M_BEGIN_PROTECTED_CODE /* Define internal types for oplist */ \ typedef shared_t M_C(name, _ct); \ typedef type M_C(name, _subtype_ct); \ - \ - M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + +/* Define the core functions */ +#define M_ISHAR3D_PTR_DEF_CORE(name, type, oplist, shared_t) \ \ static inline shared_t \ M_C(name, _init)(type *ptr) \ diff --git a/m-prioqueue.h b/m-prioqueue.h index ab157199..3dfff22f 100644 --- a/m-prioqueue.h +++ b/m-prioqueue.h @@ -127,9 +127,15 @@ - it_t: iterator of the container */ #define M_PR1OQUEUE_DEF_P3(name, type, oplist, prioqueue_t, it_t) \ - \ /* Definition of the internal array used to construct the priority queue */ \ ARRAY_DEF(M_C(name, _array), type, oplist) \ + M_PR1OQUEUE_DEF_TYPE(name, type, oplist, prioqueue_t, it_t) \ + M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + M_PR1OQUEUE_DEF_CORE(name, type, oplist, prioqueue_t, it_t) \ + M_EMPLACE_QUEUE_DEF(name, prioqueue_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) + +/* Define the types */ +#define M_PR1OQUEUE_DEF_TYPE(name, type, oplist, prioqueue_t, it_t) \ \ /* Define the priority queue over the defined array */ \ typedef struct M_C(name, _s) { \ @@ -146,8 +152,9 @@ typedef prioqueue_t M_C(name, _ct); \ typedef type M_C(name, _subtype_ct); \ typedef it_t M_C(name, _it_ct); \ - \ - M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ + +/* Define the core functions */ +#define M_PR1OQUEUE_DEF_CORE(name, type, oplist, prioqueue_t, it_t) \ \ static inline void \ M_C(name, _init)(prioqueue_t p) \ @@ -483,8 +490,6 @@ return M_C(name, _array_in_serial)(p->array, f); \ } \ ,/* No in_SERIAL */) \ - \ - M_EMPLACE_QUEUE_DEF(name, prioqueue_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) // TODO: set all & remove all function