136ac495dSmrg /* Generic single linked list to keep various information
2*8feb0f0bSmrg Copyright (C) 1993-2020 Free Software Foundation, Inc.
336ac495dSmrg Contributed by Kresten Krab Thorup.
436ac495dSmrg
536ac495dSmrg This file is part of GCC.
636ac495dSmrg
736ac495dSmrg GCC is free software; you can redistribute it and/or modify
836ac495dSmrg it under the terms of the GNU General Public License as published by
936ac495dSmrg the Free Software Foundation; either version 3, or (at your option)
1036ac495dSmrg any later version.
1136ac495dSmrg
1236ac495dSmrg GCC is distributed in the hope that it will be useful,
1336ac495dSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of
1436ac495dSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1536ac495dSmrg GNU General Public License for more details.
1636ac495dSmrg
1736ac495dSmrg Under Section 7 of GPL version 3, you are granted additional
1836ac495dSmrg permissions described in the GCC Runtime Library Exception, version
1936ac495dSmrg 3.1, as published by the Free Software Foundation.
2036ac495dSmrg
2136ac495dSmrg You should have received a copy of the GNU General Public License and
2236ac495dSmrg a copy of the GCC Runtime Library Exception along with this program;
2336ac495dSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2436ac495dSmrg <http://www.gnu.org/licenses/>. */
2536ac495dSmrg
2636ac495dSmrg #ifndef __GNU_OBJC_LIST_H
2736ac495dSmrg #define __GNU_OBJC_LIST_H
2836ac495dSmrg
2936ac495dSmrg struct objc_list
3036ac495dSmrg {
3136ac495dSmrg void *head;
3236ac495dSmrg struct objc_list *tail;
3336ac495dSmrg };
3436ac495dSmrg
3536ac495dSmrg /* Return a cons cell produced from (head . tail). */
3636ac495dSmrg static inline struct objc_list*
list_cons(void * head,struct objc_list * tail)3736ac495dSmrg list_cons (void* head, struct objc_list* tail)
3836ac495dSmrg {
3936ac495dSmrg struct objc_list* cell;
4036ac495dSmrg
4136ac495dSmrg cell = (struct objc_list*)objc_malloc (sizeof (struct objc_list));
4236ac495dSmrg cell->head = head;
4336ac495dSmrg cell->tail = tail;
4436ac495dSmrg return cell;
4536ac495dSmrg }
4636ac495dSmrg
4736ac495dSmrg /* Remove the element at the head by replacing it by its
4836ac495dSmrg successor. */
4936ac495dSmrg static inline void
list_remove_head(struct objc_list ** list)5036ac495dSmrg list_remove_head (struct objc_list** list)
5136ac495dSmrg {
5236ac495dSmrg if ((*list)->tail)
5336ac495dSmrg {
5436ac495dSmrg /* Fetch next. */
5536ac495dSmrg struct objc_list* tail = (*list)->tail;
5636ac495dSmrg
5736ac495dSmrg /* Copy next to list head. */
5836ac495dSmrg *(*list) = *tail;
5936ac495dSmrg
6036ac495dSmrg /* Free next. */
6136ac495dSmrg objc_free (tail);
6236ac495dSmrg }
6336ac495dSmrg else
6436ac495dSmrg {
6536ac495dSmrg /* Inly one element in list. */
6636ac495dSmrg objc_free (*list);
6736ac495dSmrg (*list) = 0;
6836ac495dSmrg }
6936ac495dSmrg }
7036ac495dSmrg
7136ac495dSmrg
7236ac495dSmrg /* Map FUNCTION over all elements in LIST. */
7336ac495dSmrg static inline void
list_mapcar(struct objc_list * list,void (* function)(void *))7436ac495dSmrg list_mapcar (struct objc_list* list, void(*function)(void*))
7536ac495dSmrg {
7636ac495dSmrg while (list)
7736ac495dSmrg {
7836ac495dSmrg (*function) (list->head);
7936ac495dSmrg list = list->tail;
8036ac495dSmrg }
8136ac495dSmrg }
8236ac495dSmrg
8336ac495dSmrg /* Free list (backwards recursive). */
8436ac495dSmrg static inline void
list_free(struct objc_list * list)8536ac495dSmrg list_free (struct objc_list* list)
8636ac495dSmrg {
8736ac495dSmrg if(list)
8836ac495dSmrg {
8936ac495dSmrg list_free (list->tail);
9036ac495dSmrg objc_free (list);
9136ac495dSmrg }
9236ac495dSmrg }
9336ac495dSmrg
9436ac495dSmrg #endif /* not __GNU_OBJC_LIST_H */
95