Add symbol scoping for proper parsing.
[smatch.git] / lib.h
blob7e8e16f62e0024af2c2e2af550f4af5f7ada4b7a
1 #ifndef LIST_H
2 #define LIST_H
4 extern unsigned int hexval(unsigned int c);
6 struct ident;
7 struct token;
8 struct symbol;
9 struct symbol_list;
10 struct statement;
11 struct statement_list;
13 struct token *skip_to(struct token *, int);
14 struct token *expect(struct token *, int, const char *);
15 extern void warn(struct token *, const char *, ...);
16 extern void error(struct token *, const char *, ...);
18 #define __DECLARE_ALLOCATOR(type, x) \
19 extern type *__alloc_##x(int); \
20 extern void show_##x##_alloc(void); \
21 extern void clear_##x##_alloc(void);
22 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
24 DECLARE_ALLOCATOR(ident);
25 DECLARE_ALLOCATOR(token);
26 DECLARE_ALLOCATOR(symbol);
27 DECLARE_ALLOCATOR(expression);
28 DECLARE_ALLOCATOR(statement);
29 DECLARE_ALLOCATOR(string);
30 __DECLARE_ALLOCATOR(void, bytes);
32 #define LIST_NODE_NR (29)
34 struct ptr_list {
35 int nr;
36 struct ptr_list *prev;
37 struct ptr_list *next;
38 void *list[LIST_NODE_NR];
41 void iterate(struct ptr_list *,void (*callback)(void *));
42 extern void add_ptr_list(struct ptr_list **, void *);
44 static inline void add_symbol(struct symbol_list **list, struct symbol *sym)
46 add_ptr_list((struct ptr_list **)list, sym);
49 static inline void add_statement(struct statement_list **list, struct statement *stmt)
51 add_ptr_list((struct ptr_list **)list, stmt);
54 static inline void symbol_iterate(struct symbol_list *list, void (*callback)(struct symbol *))
56 iterate((struct ptr_list *)list, (void (*)(void *))callback);
59 static inline void statement_iterate(struct statement_list *list, void (*callback)(struct statement *))
61 iterate((struct ptr_list *)list, (void (*)(void *))callback);
64 #endif