4 * Basic helper routine descriptions for 'sparse'.
6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
12 extern unsigned int hexval(unsigned int c
);
28 struct statement_list
;
30 struct expression_list
;
32 struct token
*skip_to(struct token
*, int);
33 struct token
*expect(struct token
*, int, const char *);
34 extern void warn(struct position
, const char *, ...);
35 extern void error(struct position
, const char *, ...);
37 #define __DECLARE_ALLOCATOR(type, x) \
38 extern type *__alloc_##x(int); \
39 extern void show_##x##_alloc(void); \
40 extern void clear_##x##_alloc(void);
41 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
43 DECLARE_ALLOCATOR(ident
);
44 DECLARE_ALLOCATOR(token
);
45 DECLARE_ALLOCATOR(symbol
);
46 DECLARE_ALLOCATOR(expression
);
47 DECLARE_ALLOCATOR(statement
);
48 DECLARE_ALLOCATOR(string
);
49 DECLARE_ALLOCATOR(scope
);
50 __DECLARE_ALLOCATOR(void, bytes
);
52 #define LIST_NODE_NR (29)
56 struct ptr_list
*prev
;
57 struct ptr_list
*next
;
58 void *list
[LIST_NODE_NR
];
61 #define ITERATE_FIRST 1
62 #define ITERATE_LAST 2
63 void iterate(struct ptr_list
*,void (*callback
)(void *, void *, int), void*);
64 extern void add_ptr_list(struct ptr_list
**, void *);
65 extern void free_ptr_list(struct ptr_list
**);
66 extern int ptr_list_size(struct ptr_list
*);
67 extern char **handle_switch(char *arg
, char **next
);
68 extern void add_pre_buffer(const char *fmt
, ...);
70 extern unsigned int pre_buffer_size
;
71 extern unsigned char pre_buffer
[8192];
72 extern int include_fd
;
74 extern int preprocess_only
;
76 extern void create_builtin_stream(void);
78 #define symbol_list_size(list) ptr_list_size((struct ptr_list *)(list))
79 #define statement_list_size(list) ptr_list_size((struct ptr_list *)(list))
80 #define expression_list_size(list) ptr_list_size((struct ptr_list *)(list))
82 static inline void add_symbol(struct symbol_list
**list
, struct symbol
*sym
)
84 add_ptr_list((struct ptr_list
**)list
, sym
);
87 static inline void add_statement(struct statement_list
**list
, struct statement
*stmt
)
89 add_ptr_list((struct ptr_list
**)list
, stmt
);
92 static inline void add_expression(struct expression_list
**list
, struct expression
*expr
)
94 add_ptr_list((struct ptr_list
**)list
, expr
);
97 static inline void symbol_iterate(struct symbol_list
*list
, void (*callback
)(struct symbol
*, void *, int), void *data
)
99 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
102 static inline void statement_iterate(struct statement_list
*list
, void (*callback
)(struct statement
*, void *, int), void *data
)
104 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
107 static inline void expression_iterate(struct expression_list
*list
, void (*callback
)(struct expression
*, void *, int), void *data
)
109 iterate((struct ptr_list
*)list
, (void (*)(void *, void *, int))callback
, data
);
112 #define PREPARE_PTR_LIST(head, ptr) \
114 struct ptr_list *__head##ptr = (struct ptr_list *) (head); \
115 struct ptr_list *__list##ptr = __head##ptr; \
117 if (__head##ptr) ptr = (__typeof__(ptr)) __head##ptr->list[0]; \
120 #define NEXT_PTR_LIST(ptr) \
122 if (++__nr##ptr < __list##ptr->nr) { \
123 ptr = (__typeof__(ptr)) __list##ptr->list[__nr##ptr]; \
125 __list##ptr = __list##ptr->next; \
127 if (__list##ptr != __head##ptr) { \
129 ptr = (__typeof__(ptr)) __list##ptr->list[0]; \
134 #define RESET_PTR_LIST(ptr) do { \
136 __list##ptr = __head##ptr; \
137 if (__head##ptr) ptr = (__typeof__(ptr)) __head##ptr->list[0]; \
141 #define FINISH_PTR_LIST(ptr) \
142 (void)(__nr##ptr); /* Sanity-check nesting */ \
145 #define FOR_EACH_PTR(head, ptr) do { \
146 struct ptr_list *__head = (struct ptr_list *) (head); \
147 struct ptr_list *__list = __head; \
148 int __flag = ITERATE_FIRST; \
151 for (__i = 0; __i < __list->nr; __i++) { \
152 if (__i == __list->nr-1 && __list->next == __head) \
153 __flag |= ITERATE_LAST; \
155 ptr = (__typeof__(ptr)) (__list->list[__i]); \
158 #define END_FOR_EACH_PTR } while (0); \
162 } while ((__list = __list->next) != __head); \
166 #define FOR_EACH_PTR_REVERSE(head, ptr) do { \
167 struct ptr_list *__head = (struct ptr_list *) (head); \
168 struct ptr_list *__list = __head; \
169 int __flag = ITERATE_FIRST; \
172 __list = __list->prev; \
174 while (--__i >= 0) { \
175 if (__i == 0 && __list == __head) \
176 __flag |= ITERATE_LAST; \
178 ptr = (__typeof__(ptr)) (__list->list[__i]); \
181 #define END_FOR_EACH_PTR_REVERSE } while (0); \
185 } while (__list != __head); \
189 #define THIS_ADDRESS(x) \
190 ((__typeof__(&(x))) (__list->list + __i))