sval: update smatch_helper.c
[smatch.git] / test-dissect.c
bloba2548b7f2a133f5c4d2579f5240aa4d613d1b64e
1 #include "dissect.h"
3 static unsigned dotc_stream;
5 static inline char storage(struct symbol *sym)
7 int t = sym->type;
8 unsigned m = sym->ctype.modifiers;
10 if (m & MOD_INLINE || t == SYM_STRUCT || t == SYM_UNION /*|| t == SYM_ENUM*/)
11 return sym->pos.stream == dotc_stream ? 's' : 'g';
13 return (m & MOD_STATIC) ? 's' : (m & MOD_NONLOCAL) ? 'g' : 'l';
16 static inline const char *show_mode(unsigned mode)
18 static char str[3];
20 if (mode == -1)
21 return "def";
23 #define U(u_r) "-rwm"[(mode / u_r) & 3]
24 str[0] = U(U_R_AOF);
25 str[1] = U(U_R_VAL);
26 str[2] = U(U_R_PTR);
27 #undef U
29 return str;
32 static void print_usage(struct position *pos, struct symbol *sym, unsigned mode)
34 static unsigned curr_stream = -1;
36 if (curr_stream != pos->stream) {
37 curr_stream = pos->stream;
38 printf("\nFILE: %s\n\n", stream_name(curr_stream));
41 printf("%4d:%-3d %c %-5.3s",
42 pos->line, pos->pos, storage(sym), show_mode(mode));
45 static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
47 print_usage(pos, sym, mode);
49 if (!sym->ident)
50 sym->ident = MK_IDENT("__asm__");
52 printf("%-32.*s %s\n",
53 sym->ident->len, sym->ident->name,
54 show_typename(sym->ctype.base_type));
57 static void r_member(unsigned mode, struct position *pos, struct symbol *sym, struct symbol *mem)
59 struct ident *ni, *si, *mi;
61 print_usage(pos, sym, mode);
63 ni = MK_IDENT("?");
64 si = sym->ident ?: ni;
65 /* mem == NULL means entire struct accessed */
66 mi = mem ? (mem->ident ?: ni) : MK_IDENT("*");
68 printf("%.*s.%-*.*s %s\n",
69 si->len, si->name,
70 32-1 - si->len, mi->len, mi->name,
71 show_typename(mem ? mem->ctype.base_type : sym));
74 static void r_symdef(struct symbol *sym)
76 r_symbol(-1, &sym->pos, sym);
79 int main(int argc, char **argv)
81 static struct reporter reporter = {
82 .r_symdef = r_symdef,
83 .r_symbol = r_symbol,
84 .r_member = r_member,
86 struct string_list *filelist = NULL;
87 char *file;
89 sparse_initialize(argc, argv, &filelist);
91 FOR_EACH_PTR_NOTAG(filelist, file) {
92 dotc_stream = input_stream_nr;
93 dissect(__sparse(file), &reporter);
94 } END_FOR_EACH_PTR_NOTAG(file);
96 return 0;