aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib.h
blob: 7e80a57da34f68e33e77b335d765c73aeeab2f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef LIST_H
#define LIST_H

extern unsigned int hexval(unsigned int c);

struct ident;
struct token;
struct symbol;
struct symbol_list;
struct statement;
struct statement_list;

struct token *skip_to(struct token *, int);
struct token *expect(struct token *, int, const char *);
extern void warn(struct token *, const char *, ...);
extern void error(struct token *, const char *, ...);

#define __DECLARE_ALLOCATOR(type, x)		\
	extern type *__alloc_##x(int);		\
	extern void show_##x##_alloc(void);	\
	extern void clear_##x##_alloc(void);
#define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)

DECLARE_ALLOCATOR(ident);
DECLARE_ALLOCATOR(token);
DECLARE_ALLOCATOR(symbol);
DECLARE_ALLOCATOR(expression);
DECLARE_ALLOCATOR(statement);
DECLARE_ALLOCATOR(string);
__DECLARE_ALLOCATOR(void, bytes);

#define LIST_NODE_NR (14)

struct ptr_list {
	int nr;
	void *list[LIST_NODE_NR];
	struct ptr_list *next;
};

void iterate(struct ptr_list *,void (*callback)(void *));
extern void add_ptr_list(struct ptr_list **, void *);

static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
{
	add_ptr_list((struct ptr_list **)list, sym);
}

static inline void add_statement(struct statement_list **list, struct statement *stmt)
{
	add_ptr_list((struct ptr_list **)list, stmt);
}

static inline void symbol_iterate(struct symbol_list *list, void (*callback)(struct symbol *))
{
	iterate((struct ptr_list *)list, (void (*)(void *))callback);
}

static inline void statement_iterate(struct statement_list *list, void (*callback)(struct statement *))
{
	iterate((struct ptr_list *)list, (void (*)(void *))callback);
}

#endif