0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef MODUTILS_GENKSYMS_H
0013 #define MODUTILS_GENKSYMS_H 1
0014
0015 #include <stdio.h>
0016
0017 enum symbol_type {
0018 SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION,
0019 SYM_ENUM_CONST
0020 };
0021
0022 enum symbol_status {
0023 STATUS_UNCHANGED, STATUS_DEFINED, STATUS_MODIFIED
0024 };
0025
0026 struct string_list {
0027 struct string_list *next;
0028 enum symbol_type tag;
0029 int in_source_file;
0030 char *string;
0031 };
0032
0033 struct symbol {
0034 struct symbol *hash_next;
0035 const char *name;
0036 enum symbol_type type;
0037 struct string_list *defn;
0038 struct symbol *expansion_trail;
0039 struct symbol *visited;
0040 int is_extern;
0041 int is_declared;
0042 enum symbol_status status;
0043 int is_override;
0044 };
0045
0046 typedef struct string_list **yystype;
0047 #define YYSTYPE yystype
0048
0049 extern int cur_line;
0050 extern char *cur_filename;
0051 extern int in_source_file;
0052
0053 struct symbol *find_symbol(const char *name, enum symbol_type ns, int exact);
0054 struct symbol *add_symbol(const char *name, enum symbol_type type,
0055 struct string_list *defn, int is_extern);
0056 void export_symbol(const char *);
0057
0058 void free_node(struct string_list *list);
0059 void free_list(struct string_list *s, struct string_list *e);
0060 struct string_list *copy_node(struct string_list *);
0061 struct string_list *copy_list_range(struct string_list *start,
0062 struct string_list *end);
0063
0064 int yylex(void);
0065 int yyparse(void);
0066
0067 void error_with_pos(const char *, ...) __attribute__ ((format(printf, 1, 2)));
0068
0069
0070 #define xmalloc(size) ({ void *__ptr = malloc(size); \
0071 if(!__ptr && size != 0) { \
0072 fprintf(stderr, "out of memory\n"); \
0073 exit(1); \
0074 } \
0075 __ptr; })
0076 #define xstrdup(str) ({ char *__str = strdup(str); \
0077 if (!__str) { \
0078 fprintf(stderr, "out of memory\n"); \
0079 exit(1); \
0080 } \
0081 __str; })
0082
0083 #endif