148fb7bfaSmrg /* Generic single linked list to keep various information
2*b1e83836Smrg Copyright (C) 1993-2022 Free Software Foundation, Inc.
348fb7bfaSmrg Contributed by Kresten Krab Thorup.
448fb7bfaSmrg
548fb7bfaSmrg This file is part of GCC.
648fb7bfaSmrg
748fb7bfaSmrg GCC is free software; you can redistribute it and/or modify
848fb7bfaSmrg it under the terms of the GNU General Public License as published by
948fb7bfaSmrg the Free Software Foundation; either version 3, or (at your option)
1048fb7bfaSmrg any later version.
1148fb7bfaSmrg
1248fb7bfaSmrg GCC is distributed in the hope that it will be useful,
1348fb7bfaSmrg but WITHOUT ANY WARRANTY; without even the implied warranty of
1448fb7bfaSmrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1548fb7bfaSmrg GNU General Public License for more details.
1648fb7bfaSmrg
1748fb7bfaSmrg Under Section 7 of GPL version 3, you are granted additional
1848fb7bfaSmrg permissions described in the GCC Runtime Library Exception, version
1948fb7bfaSmrg 3.1, as published by the Free Software Foundation.
2048fb7bfaSmrg
2148fb7bfaSmrg You should have received a copy of the GNU General Public License and
2248fb7bfaSmrg a copy of the GCC Runtime Library Exception along with this program;
2348fb7bfaSmrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
2448fb7bfaSmrg <http://www.gnu.org/licenses/>. */
2548fb7bfaSmrg
2648fb7bfaSmrg #ifndef __GNU_OBJC_LIST_H
2748fb7bfaSmrg #define __GNU_OBJC_LIST_H
2848fb7bfaSmrg
2948fb7bfaSmrg struct objc_list
3048fb7bfaSmrg {
3148fb7bfaSmrg void *head;
3248fb7bfaSmrg struct objc_list *tail;
3348fb7bfaSmrg };
3448fb7bfaSmrg
3548fb7bfaSmrg /* Return a cons cell produced from (head . tail). */
3648fb7bfaSmrg static inline struct objc_list*
list_cons(void * head,struct objc_list * tail)3748fb7bfaSmrg list_cons (void* head, struct objc_list* tail)
3848fb7bfaSmrg {
3948fb7bfaSmrg struct objc_list* cell;
4048fb7bfaSmrg
4148fb7bfaSmrg cell = (struct objc_list*)objc_malloc (sizeof (struct objc_list));
4248fb7bfaSmrg cell->head = head;
4348fb7bfaSmrg cell->tail = tail;
4448fb7bfaSmrg return cell;
4548fb7bfaSmrg }
4648fb7bfaSmrg
4748fb7bfaSmrg /* Remove the element at the head by replacing it by its
4848fb7bfaSmrg successor. */
4948fb7bfaSmrg static inline void
list_remove_head(struct objc_list ** list)5048fb7bfaSmrg list_remove_head (struct objc_list** list)
5148fb7bfaSmrg {
5248fb7bfaSmrg if ((*list)->tail)
5348fb7bfaSmrg {
5448fb7bfaSmrg /* Fetch next. */
5548fb7bfaSmrg struct objc_list* tail = (*list)->tail;
5648fb7bfaSmrg
5748fb7bfaSmrg /* Copy next to list head. */
5848fb7bfaSmrg *(*list) = *tail;
5948fb7bfaSmrg
6048fb7bfaSmrg /* Free next. */
6148fb7bfaSmrg objc_free (tail);
6248fb7bfaSmrg }
6348fb7bfaSmrg else
6448fb7bfaSmrg {
6548fb7bfaSmrg /* Inly one element in list. */
6648fb7bfaSmrg objc_free (*list);
6748fb7bfaSmrg (*list) = 0;
6848fb7bfaSmrg }
6948fb7bfaSmrg }
7048fb7bfaSmrg
7148fb7bfaSmrg
7248fb7bfaSmrg /* Map FUNCTION over all elements in LIST. */
7348fb7bfaSmrg static inline void
list_mapcar(struct objc_list * list,void (* function)(void *))7448fb7bfaSmrg list_mapcar (struct objc_list* list, void(*function)(void*))
7548fb7bfaSmrg {
7648fb7bfaSmrg while (list)
7748fb7bfaSmrg {
7848fb7bfaSmrg (*function) (list->head);
7948fb7bfaSmrg list = list->tail;
8048fb7bfaSmrg }
8148fb7bfaSmrg }
8248fb7bfaSmrg
8348fb7bfaSmrg /* Free list (backwards recursive). */
8448fb7bfaSmrg static inline void
list_free(struct objc_list * list)8548fb7bfaSmrg list_free (struct objc_list* list)
8648fb7bfaSmrg {
8748fb7bfaSmrg if(list)
8848fb7bfaSmrg {
8948fb7bfaSmrg list_free (list->tail);
9048fb7bfaSmrg objc_free (list);
9148fb7bfaSmrg }
9248fb7bfaSmrg }
9348fb7bfaSmrg
9448fb7bfaSmrg #endif /* not __GNU_OBJC_LIST_H */
95