OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libobjc/] [objc/] [objc-list.h] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Generic single linked list to keep various information
2
   Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
3
   Contributed by Kresten Krab Thorup.
4
 
5
This file is part of GCC.
6
 
7
GCC is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
10
any later version.
11
 
12
GCC is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING.  If not, write to
19
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20
Boston, MA 02110-1301, USA.  */
21
 
22
/* As a special exception, if you link this library with files compiled with
23
   GCC to produce an executable, this does not cause the resulting executable
24
   to be covered by the GNU General Public License. This exception does not
25
   however invalidate any other reasons why the executable file might be
26
   covered by the GNU General Public License.  */
27
 
28
#ifndef __GNU_OBJC_LIST_H
29
#define __GNU_OBJC_LIST_H
30
 
31
#ifdef __cplusplus
32
extern "C" {
33
#endif /* __cplusplus */
34
 
35
struct objc_list {
36
  void *head;
37
  struct objc_list *tail;
38
};
39
 
40
/* Return a cons cell produced from (head . tail) */
41
 
42
static inline struct objc_list*
43
list_cons(void* head, struct objc_list* tail)
44
{
45
  struct objc_list* cell;
46
 
47
  cell = (struct objc_list*)objc_malloc(sizeof(struct objc_list));
48
  cell->head = head;
49
  cell->tail = tail;
50
  return cell;
51
}
52
 
53
/* Return the length of a list, list_length(NULL) returns zero */
54
 
55
static inline int
56
list_length(struct objc_list* list)
57
{
58
  int i = 0;
59
  while(list)
60
    {
61
      i += 1;
62
      list = list->tail;
63
    }
64
  return i;
65
}
66
 
67
/* Return the Nth element of LIST, where N count from zero.  If N
68
   larger than the list length, NULL is returned  */
69
 
70
static inline void*
71
list_nth(int indx, struct objc_list* list)
72
{
73
  while(indx-- != 0)
74
    {
75
      if(list->tail)
76
        list = list->tail;
77
      else
78
        return 0;
79
    }
80
  return list->head;
81
}
82
 
83
/* Remove the element at the head by replacing it by its successor */
84
 
85
static inline void
86
list_remove_head(struct objc_list** list)
87
{
88
  if ((*list)->tail)
89
    {
90
      struct objc_list* tail = (*list)->tail; /* fetch next */
91
      *(*list) = *tail;         /* copy next to list head */
92
      objc_free(tail);                  /* free next */
93
    }
94
  else                          /* only one element in list */
95
    {
96
      objc_free(*list);
97
      (*list) = 0;
98
    }
99
}
100
 
101
 
102
/* Remove the element with `car' set to ELEMENT */
103
 
104
static inline void
105
list_remove_elem(struct objc_list** list, void* elem)
106
{
107
  while (*list) {
108
    if ((*list)->head == elem)
109
      list_remove_head(list);
110
    list = &((*list)->tail);
111
  }
112
}
113
 
114
/* Map FUNCTION over all elements in LIST */
115
 
116
static inline void
117
list_mapcar(struct objc_list* list, void(*function)(void*))
118
{
119
  while(list)
120
    {
121
      (*function)(list->head);
122
      list = list->tail;
123
    }
124
}
125
 
126
/* Return element that has ELEM as car */
127
 
128
static inline struct objc_list**
129
list_find(struct objc_list** list, void* elem)
130
{
131
  while(*list)
132
    {
133
    if ((*list)->head == elem)
134
      return list;
135
    list = &((*list)->tail);
136
    }
137
  return NULL;
138
}
139
 
140
/* Free list (backwards recursive) */
141
 
142
static void
143
list_free(struct objc_list* list)
144
{
145
  if(list)
146
    {
147
      list_free(list->tail);
148
      objc_free(list);
149
    }
150
}
151
 
152
#ifdef __cplusplus
153
}
154
#endif /* __cplusplus */
155
 
156
#endif /* not __GNU_OBJC_LIST_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.