3 static inline const char *show_mode(unsigned mode
)
10 #define U(u_r) "-rwm"[(mode / u_r) & 3]
19 static void print_usage(struct position
*pos
, struct symbol
*sym
, unsigned mode
)
21 static unsigned curr_stream
= -1;
22 static struct ident null
;
23 struct ident
*ctx
= &null
;
25 if (curr_stream
!= pos
->stream
) {
26 curr_stream
= pos
->stream
;
27 printf("\nFILE: %s\n\n", stream_name(curr_stream
));
31 ctx
= dissect_ctx
->ident
;
33 printf("%4d:%-3d %-16.*s %s ",
34 pos
->line
, pos
->pos
, ctx
->len
, ctx
->name
, show_mode(mode
));
38 static char symscope(struct symbol
*sym
)
40 if (sym_is_local(sym
)) {
42 warning(sym
->pos
, "no context");
48 static void r_symbol(unsigned mode
, struct position
*pos
, struct symbol
*sym
)
50 print_usage(pos
, sym
, mode
);
53 sym
->ident
= built_in_ident("__asm__");
55 printf("%c %c %-32.*s %s\n",
56 symscope(sym
), sym
->kind
, sym
->ident
->len
, sym
->ident
->name
,
57 show_typename(sym
->ctype
.base_type
));
63 if (sym
->type
== SYM_STRUCT
|| sym
->type
== SYM_UNION
)
69 if (sym
->type
!= SYM_BAD
&& sym
->ctype
.base_type
->type
!= SYM_FN
)
72 if (sym
->type
== SYM_NODE
|| sym
->type
== SYM_BAD
)
81 warning(*pos
, "r_symbol bad sym type=%d kind=%d", sym
->type
, sym
->kind
);
84 static void r_member(unsigned mode
, struct position
*pos
, struct symbol
*sym
, struct symbol
*mem
)
86 struct ident
*ni
, *si
, *mi
;
88 print_usage(pos
, sym
, mode
);
90 ni
= built_in_ident("?");
91 si
= sym
->ident
?: ni
;
92 /* mem == NULL means entire struct accessed */
93 mi
= mem
? (mem
->ident
?: ni
) : built_in_ident("*");
95 printf("%c m %.*s.%-*.*s %s\n",
96 symscope(sym
), si
->len
, si
->name
,
97 32-1 - si
->len
, mi
->len
, mi
->name
,
98 show_typename(mem
? mem
->ctype
.base_type
: sym
));
100 if (sym
->ident
&& sym
->kind
!= 's')
101 warning(*pos
, "r_member bad sym type=%d kind=%d", sym
->type
, sym
->kind
);
102 if (mem
&& mem
->kind
!= 'm')
103 warning(*pos
, "r_member bad mem->kind = %d", mem
->kind
);
106 static void r_symdef(struct symbol
*sym
)
108 r_symbol(-1, &sym
->pos
, sym
);
111 static void r_memdef(struct symbol
*sym
, struct symbol
*mem
)
113 r_member(-1, &mem
->pos
, sym
, mem
);
116 int main(int argc
, char **argv
)
118 static struct reporter reporter
= {
119 .r_symdef
= r_symdef
,
120 .r_memdef
= r_memdef
,
121 .r_symbol
= r_symbol
,
122 .r_member
= r_member
,
125 struct string_list
*filelist
= NULL
;
126 sparse_initialize(argc
, argv
, &filelist
);
127 dissect(&reporter
, filelist
);