1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#ifndef MODUTILS_GENKSYMS_H
24#define MODUTILS_GENKSYMS_H 1
25
26#include <stdio.h>
27
28enum symbol_type {
29 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION
30};
31
32struct string_list {
33 struct string_list *next;
34 enum symbol_type tag;
35 char *string;
36};
37
38struct symbol {
39 struct symbol *hash_next;
40 const char *name;
41 enum symbol_type type;
42 struct string_list *defn;
43 struct symbol *expansion_trail;
44 struct symbol *visited;
45 int is_extern;
46};
47
48typedef struct string_list **yystype;
49#define YYSTYPE yystype
50
51extern int cur_line;
52extern char *cur_filename;
53
54struct symbol *find_symbol(const char *name, enum symbol_type ns);
55struct symbol *add_symbol(const char *name, enum symbol_type type,
56 struct string_list *defn, int is_extern);
57void export_symbol(const char *);
58
59void free_node(struct string_list *list);
60void free_list(struct string_list *s, struct string_list *e);
61struct string_list *copy_node(struct string_list *);
62
63int yylex(void);
64int yyparse(void);
65
66void error_with_pos(const char *, ...);
67
68
69#define xmalloc(size) ({ void *__ptr = malloc(size); \
70 if(!__ptr && size != 0) { \
71 fprintf(stderr, "out of memory\n"); \
72 exit(1); \
73 } \
74 __ptr; })
75#define xstrdup(str) ({ char *__str = strdup(str); \
76 if (!__str) { \
77 fprintf(stderr, "out of memory\n"); \
78 exit(1); \
79 } \
80 __str; })
81
82#endif
83