]> git.ipfire.org Git - thirdparty/gcc.git/blame - libobjc/objc-private/objc-list.h
Update copyright years.
[thirdparty/gcc.git] / libobjc / objc-private / objc-list.h
CommitLineData
88e17b57 1/* Generic single linked list to keep various information
8d9254fc 2 Copyright (C) 1993-2020 Free Software Foundation, Inc.
88e17b57
BE
3 Contributed by Kresten Krab Thorup.
4
6c82ad25 5This file is part of GCC.
88e17b57 6
6c82ad25 7GCC is free software; you can redistribute it and/or modify
88e17b57 8it under the terms of the GNU General Public License as published by
748086b7 9the Free Software Foundation; either version 3, or (at your option)
88e17b57
BE
10any later version.
11
6c82ad25 12GCC is distributed in the hope that it will be useful,
88e17b57
BE
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
88e17b57 25
88e17b57
BE
26#ifndef __GNU_OBJC_LIST_H
27#define __GNU_OBJC_LIST_H
28
9fd553cc
NP
29struct objc_list
30{
88e17b57
BE
31 void *head;
32 struct objc_list *tail;
33};
34
9fd553cc 35/* Return a cons cell produced from (head . tail). */
88e17b57 36static inline struct objc_list*
9fd553cc 37list_cons (void* head, struct objc_list* tail)
88e17b57
BE
38{
39 struct objc_list* cell;
40
9fd553cc 41 cell = (struct objc_list*)objc_malloc (sizeof (struct objc_list));
88e17b57
BE
42 cell->head = head;
43 cell->tail = tail;
44 return cell;
45}
46
9fd553cc
NP
47/* Remove the element at the head by replacing it by its
48 successor. */
88e17b57 49static inline void
9fd553cc 50list_remove_head (struct objc_list** list)
88e17b57
BE
51{
52 if ((*list)->tail)
53 {
9fd553cc
NP
54 /* Fetch next. */
55 struct objc_list* tail = (*list)->tail;
56
57 /* Copy next to list head. */
58 *(*list) = *tail;
59
60 /* Free next. */
61 objc_free (tail);
88e17b57 62 }
9fd553cc 63 else
88e17b57 64 {
9fd553cc
NP
65 /* Inly one element in list. */
66 objc_free (*list);
88e17b57
BE
67 (*list) = 0;
68 }
69}
70
71
9fd553cc 72/* Map FUNCTION over all elements in LIST. */
88e17b57 73static inline void
9fd553cc 74list_mapcar (struct objc_list* list, void(*function)(void*))
88e17b57 75{
9fd553cc 76 while (list)
88e17b57 77 {
9fd553cc 78 (*function) (list->head);
88e17b57
BE
79 list = list->tail;
80 }
81}
82
9fd553cc 83/* Free list (backwards recursive). */
3034b453 84static inline void
9fd553cc 85list_free (struct objc_list* list)
88e17b57
BE
86{
87 if(list)
88 {
9fd553cc
NP
89 list_free (list->tail);
90 objc_free (list);
88e17b57
BE
91 }
92}
6f0aa5e1 93
2e3120e8 94#endif /* not __GNU_OBJC_LIST_H */