linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 11/34] ptrlist: mechanically replace head-list-nr triplets by an iterator struct
Date: Fri,  7 Jul 2017 15:39:39 +0200	[thread overview]
Message-ID: <20170707134002.49500-12-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170707134002.49500-1-luc.vanoostenryck@gmail.com>

---
 ptrlist.h | 174 ++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 84 insertions(+), 90 deletions(-)

diff --git a/ptrlist.h b/ptrlist.h
index f856a54eb..8941c339a 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -111,180 +111,174 @@ static inline void *last_ptr_list(struct ptr_list *list)
 	return __PTR_STRIP_TAG(ptr_cur_entry(&cur));
 }
 
-#define PTR_DEREF(__head, idx, PTR_ENTRY) ({						\
-	struct ptr_list *__list = __head;						\
-	while (__list && __list->nr == 0) {						\
-		__list = __list->next;							\
-		if (__list == __head)							\
-			__list = NULL;							\
-	}										\
-	__list ? PTR_ENTRY(__list, idx) : NULL;						\
-})
-
-#define DO_PREPARE(head, ptr, __head, __list, __nr, PTR_ENTRY)				\
+#define DO_PREPARE(head, ptr, __cur, PTR_ENTRY)						\
 	do {										\
-		struct ptr_list *__head = (struct ptr_list *) (head);			\
-		struct ptr_list *__list = __head;					\
-		int __nr = 0;								\
+		struct ptr_cur __cur;							\
+		__cur.h = (struct ptr_list *) (head);					\
+		__cur.l = __cur.h;							\
+		__cur.n = 0;								\
 		CHECK_TYPE(head,ptr);							\
-		ptr = PTR_DEREF(__head, 0, PTR_ENTRY);					\
+		if (__cur.h) ptr = PTR_ENTRY(__cur.h, 0);				\
+		else ptr = NULL
 
-#define DO_NEXT(ptr, __head, __list, __nr, PTR_ENTRY)					\
+#define DO_NEXT(ptr, __cur, PTR_ENTRY)							\
 		if (ptr) {								\
-			if (++__nr < __list->nr) {					\
-				ptr = PTR_ENTRY(__list,__nr);				\
+			if (++__cur.n < __cur.l->nr) {					\
+				ptr = PTR_ENTRY(__cur.l,__cur.n);			\
 			} else {							\
 				ptr = NULL;						\
 				do							\
-					__list = __list->next;				\
-				while (__list->nr == 0 && __list != __head);		\
-				if (__list != __head) {					\
-					__nr = 0;					\
-					ptr = PTR_ENTRY(__list,0);			\
+					__cur.l = __cur.l->next;			\
+				while (__cur.l->nr == 0 && __cur.l != __cur.h);		\
+				if (__cur.l != __cur.h) {				\
+					__cur.n = 0;					\
+					ptr = PTR_ENTRY(__cur.l,0);			\
 				}							\
 			}								\
 		}
 
-#define DO_RESET(ptr, __head, __list, __nr, PTR_ENTRY)					\
+#define DO_RESET(ptr, __cur, PTR_ENTRY)						\
 	do {										\
-		__nr = 0;								\
-		__list = __head;							\
-		if (__head) ptr = PTR_DEREF(__head, 0, PTR_ENTRY);			\
+		__cur.n = 0;								\
+		__cur.l = __cur.h;							\
+		if (__cur.h) ptr = PTR_ENTRY(__cur.h, 0);				\
 	} while (0)
 
-#define DO_FINISH(ptr, __head, __list, __nr)						\
-		(void)(__nr); /* Sanity-check nesting */				\
+#define DO_FINISH(ptr, __cur)								\
+		(void)(__cur.n); /* Sanity-check nesting */				\
 	} while (0)
 
 #define PREPARE_PTR_LIST(head, ptr) \
-	DO_PREPARE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY)
+	DO_PREPARE(head, ptr, __cur##ptr, PTR_ENTRY)
 
 #define NEXT_PTR_LIST(ptr) \
-	DO_NEXT(ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY)
+	DO_NEXT(ptr, __cur##ptr, PTR_ENTRY)
 
 #define RESET_PTR_LIST(ptr) \
-	DO_RESET(ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY)
+	DO_RESET(ptr, __cur##ptr, PTR_ENTRY)
 
 #define FINISH_PTR_LIST(ptr) \
-	DO_FINISH(ptr, __head##ptr, __list##ptr, __nr##ptr)
+	DO_FINISH(ptr, __cur##ptr)
 
-#define DO_FOR_EACH(head, ptr, __head, __list, __nr, PTR_ENTRY) do {			\
-	struct ptr_list *__head = (struct ptr_list *) (head);				\
-	struct ptr_list *__list = __head;						\
+#define DO_FOR_EACH(head, ptr, __cur, PTR_ENTRY) do {					\
+	struct ptr_cur __cur;								\
+	__cur.h = (struct ptr_list *) (head);						\
+	__cur.l = __cur.h;								\
 	CHECK_TYPE(head,ptr);								\
-	if (!__head) break;								\
-	do { int __nr;									\
-		for (__nr = 0; __nr < __list->nr; __nr++) {				\
-			ptr = PTR_ENTRY(__list,__nr);					\
+	if (!__cur.h) break;								\
+	do {										\
+		for (__cur.n = 0; __cur.n < __cur.l->nr; __cur.n++) {			\
+			ptr = PTR_ENTRY(__cur.l,__cur.n);				\
 
-#define DO_END_FOR_EACH(ptr, __head, __list, __nr)					\
+#define DO_END_FOR_EACH(ptr, __cur)							\
 		}									\
-	} while ((__list = __list->next) != __head);					\
+	} while ((__cur.l = __cur.l->next) != __cur.h);					\
 } while (0)
 
-#define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do {		\
-	struct ptr_list *__head = (struct ptr_list *) (head);				\
-	struct ptr_list *__list = __head;						\
+#define DO_FOR_EACH_REVERSE(head, ptr, __cur, PTR_ENTRY) do {				\
+	struct ptr_cur __cur;								\
+	__cur.h = (struct ptr_list *) (head);						\
+	__cur.l = __cur.h;								\
 	CHECK_TYPE(head,ptr);								\
-	if (!__head) break;								\
-	do { int __nr;									\
-		__list = __list->prev;							\
-		__nr = __list->nr;							\
-		while (--__nr >= 0) {							\
-			ptr = PTR_ENTRY(__list,__nr);					\
+	if (!__cur.h) break;								\
+	do {										\
+		__cur.l = __cur.l->prev;						\
+		__cur.n = __cur.l->nr;							\
+		while (--__cur.n >= 0) {						\
+			ptr = PTR_ENTRY(__cur.l,__cur.n);				\
 
 
-#define DO_END_FOR_EACH_REVERSE(ptr, __head, __list, __nr)				\
+#define DO_END_FOR_EACH_REVERSE(ptr, __cur)						\
 		}									\
-	} while (__list != __head);							\
+	} while (__cur.l != __cur.h);							\
 } while (0)
 
-#define DO_REVERSE(ptr, __head, __list, __nr, new, __newhead,				\
-		   __newlist, __newnr, PTR_ENTRY) do { 					\
-	struct ptr_list *__newhead = __head;						\
-	struct ptr_list *__newlist = __list;						\
-	int __newnr = __nr;								\
+#define DO_REVERSE(ptr, __cur, new, __newcur, PTR_ENTRY) do {				\
+	struct ptr_cur __newcur;							\
+	__newcur.h = __cur.h;								\
+	__newcur.l = __cur.l;								\
+	__newcur.n = __cur.n;								\
 	new = ptr;									\
 	goto __inside##new;								\
 	do {										\
-		__newlist = __newlist->prev;						\
-		__newnr = __newlist->nr;						\
+		__newcur.l = __newcur.l->prev;						\
+		__newcur.n = __newcur.l->nr;						\
 	__inside##new:									\
-		while (--__newnr >= 0) {						\
-			new = PTR_ENTRY(__newlist,__newnr);				\
+		while (--__newcur.n >= 0) {						\
+			new = PTR_ENTRY(__newcur.l,__newcur.n);				\
 
 #define RECURSE_PTR_REVERSE(ptr, new)							\
-	DO_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr,				\
-		   new, __head##new, __list##new, __nr##new, PTR_ENTRY)
+	DO_REVERSE(ptr, __cur##ptr,							\
+		   new, __cur##new, PTR_ENTRY)
 
-#define DO_THIS_ADDRESS(ptr, __head, __list, __nr)					\
-	((__typeof__(&(ptr))) (__list->list + __nr))
+#define DO_THIS_ADDRESS(ptr, __cur)							\
+	((__typeof__(&(ptr))) (__cur.l->list + __cur.n))
 
 #define FOR_EACH_PTR(head, ptr) \
-	DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY)
+	DO_FOR_EACH(head, ptr, __cur##ptr, PTR_ENTRY)
 
 #define END_FOR_EACH_PTR(ptr) \
-	DO_END_FOR_EACH(ptr, __head##ptr, __list##ptr, __nr##ptr)
+	DO_END_FOR_EACH(ptr, __cur##ptr)
 
 #define FOR_EACH_PTR_NOTAG(head, ptr) \
-	DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_NOTAG)
+	DO_FOR_EACH(head, ptr, __cur##ptr, PTR_ENTRY_NOTAG)
 
 #define END_FOR_EACH_PTR_NOTAG(ptr) END_FOR_EACH_PTR(ptr)
 
 #define FOR_EACH_PTR_REVERSE(head, ptr) \
-	DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY)
+	DO_FOR_EACH_REVERSE(head, ptr, __cur##ptr, PTR_ENTRY)
 
 #define END_FOR_EACH_PTR_REVERSE(ptr) \
-	DO_END_FOR_EACH_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr)
+	DO_END_FOR_EACH_REVERSE(ptr, __cur##ptr)
 
 #define FOR_EACH_PTR_REVERSE_NOTAG(head, ptr) \
-	DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_NOTAG)
+	DO_FOR_EACH_REVERSE(head, ptr, __cur##ptr, PTR_ENTRY_NOTAG)
 
 #define END_FOR_EACH_PTR_REVERSE_NOTAG(ptr) END_FOR_EACH_PTR_REVERSE(ptr)
 
 #define THIS_ADDRESS(ptr) \
-	DO_THIS_ADDRESS(ptr, __head##ptr, __list##ptr, __nr##ptr)
+	DO_THIS_ADDRESS(ptr, __cur##ptr)
 
 extern void split_ptr_list_head(struct ptr_list *);
 
-#define DO_SPLIT(ptr, __head, __list, __nr) do {					\
-	split_ptr_list_head(__list);							\
-	if (__nr >= __list->nr) {							\
-		__nr -= __list->nr;							\
-		__list = __list->next;							\
+#define DO_SPLIT(ptr, __cur) do {							\
+	split_ptr_list_head(__cur.l);							\
+	if (__cur.n >= __cur.l->nr) {							\
+		__cur.n -= __cur.l->nr;							\
+		__cur.l = __cur.l->next;						\
 	};										\
 } while (0)
 
-#define DO_INSERT_CURRENT(new, ptr, __head, __list, __nr) do {				\
+#define DO_INSERT_CURRENT(new, ptr, __cur) do {						\
 	void **__this, **__last;							\
-	if (__list->nr == LIST_NODE_NR)							\
-		DO_SPLIT(ptr, __head, __list, __nr);					\
-	__this = __list->list + __nr;							\
-	__last = __list->list + __list->nr - 1;						\
+	if (__cur.l->nr == LIST_NODE_NR)						\
+		DO_SPLIT(ptr, __cur);							\
+	__this = __cur.l->list + __cur.n;						\
+	__last = __cur.l->list + __cur.l->nr - 1;					\
 	while (__last >= __this) {							\
 		__last[1] = __last[0];							\
 		__last--;								\
 	}										\
 	*__this = (new);								\
-	__list->nr++;									\
+	__cur.l->nr++;									\
 } while (0)
 
 #define INSERT_CURRENT(new, ptr) \
-	DO_INSERT_CURRENT(new, ptr, __head##ptr, __list##ptr, __nr##ptr)
+	DO_INSERT_CURRENT(new, ptr, __cur##ptr)
 
-#define DO_DELETE_CURRENT(ptr, __head, __list, __nr) do {				\
-	void **__this = __list->list + __nr;						\
-	void **__last = __list->list + __list->nr - 1;					\
+#define DO_DELETE_CURRENT(ptr, __cur) do {						\
+	void **__this = __cur.l->list + __cur.n;					\
+	void **__last = __cur.l->list + __cur.l->nr - 1;				\
 	while (__this < __last) {							\
 		__this[0] = __this[1];							\
 		__this++;								\
 	}										\
 	*__this = (void *)0xf0f0f0f0;							\
-	__list->nr--; __nr--;								\
+	__cur.l->nr--; __cur.n--;							\
 } while (0)
 
 #define DELETE_CURRENT_PTR(ptr) \
-	DO_DELETE_CURRENT(ptr, __head##ptr, __list##ptr, __nr##ptr)
+	DO_DELETE_CURRENT(ptr, __cur##ptr)
 
 #define REPLACE_CURRENT_PTR(ptr, new_ptr)						\
 	do { *THIS_ADDRESS(ptr) = (new_ptr); } while (0)
-- 
2.13.0


  parent reply	other threads:[~2017-07-07 13:40 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-07 13:39 [RFC 00/34] ptrlist rework with iterator Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 01/34] ptrlist: simplify DO_FOR_EACH/DO_END_FOR_EACH Luc Van Oostenryck
2017-07-08 15:31   ` Christopher Li
2017-07-07 13:39 ` [PATCH 02/34] ptrlist: simplify DO_FOR_EACH_REVERSE/ Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 03/34] ptrlist: simplify DO_NEXT link walking Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 04/34] ptrlist: add helper __PTR_STRIP_TAG() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 05/34] ptrlist: introduce the ptr_list iterator structure Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 06/34] ptrlist: add ptr_cur_entry() to get iterator's current entry Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 07/34] ptrlist: add forward iterator Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 08/34] ptrlist: let first_ptr_list() use the iterator API Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 09/34] ptrlist: add backward iterator Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 10/34] ptrlist: let lastst_ptr_list() use the iterator API Luc Van Oostenryck
2017-07-07 13:39 ` Luc Van Oostenryck [this message]
2017-07-07 13:39 ` [PATCH 12/34] ptrlist: simplify initialization of DO_REVERSE()'s cursor Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 13/34] ptrlist: abstract away iterator initialization Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 14/34] ptrlist: CUR_ENTRY/CUR_ENTRY_NOTAG Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 15/34] ptrlist: use iterator API for PREPARE/NEXT_PTR_LIST() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 16/34] ptrlist: use iterator API for RESET_PTR_LIST() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 17/34] ptrlist: use iterator for FOR_EACH_PTR() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 18/34] ptrlist: use iterator for FOR_EACH_PTR_REVERSE() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 19/34] ptrlist: remove unneeded DO_INIT() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 20/34] ptrlist: use the iterator API for DO_INSERT_CURRENT() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 21/34] ptrlist: extract ptr_cur_insert from ptrlist.h Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 22/34] ptrlist: simplify ptr_cur_insert() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 23/34] ptrlist: use the iterator API for DO_DELETE_CURRENT() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 24/34] ptrlist: extract prt_cur_delete() from ptrlist.h Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 25/34] ptrlist: let delete_ptr_list() use the iterator API Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 26/34] ptrlist: let replace_ptr_list_entry() " Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 27/34] ptrlist: let concat_ptr_list() " Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 28/34] ptrlist: let undo_ptr_list_last() " Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 29/34] ptrlist: let delete_ptr_list_last() " Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 30/34] ptrlist: simplify common case for __add_ptr_list() Luc Van Oostenryck
2017-07-07 13:39 ` [PATCH 31/34] ptrlist: explicitely tagged Luc Van Oostenryck
2017-07-07 13:40 ` [PATCH 32/34] ptrlist: tag/notag common case Luc Van Oostenryck
2017-07-07 13:40 ` [PATCH 33/34] ptrlist: drop the now unneeded _NOTAG versions Luc Van Oostenryck
2017-07-07 13:40 ` [PATCH 34/34] ptrlist: addr vs entry Luc Van Oostenryck
2017-07-07 13:51 ` [RFC 00/34] ptrlist rework with iterator Luc Van Oostenryck
2017-07-08 15:13 ` Christopher Li
2017-07-09  6:50   ` Luc Van Oostenryck
2017-07-09  8:25     ` Christopher Li
2017-07-09  9:52       ` Luc Van Oostenryck
2017-07-09 10:34         ` Dibyendu Majumdar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170707134002.49500-12-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).