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
));
61 if (sym
->type
== SYM_STRUCT
|| sym
->type
== SYM_UNION
)
66 if (sym
->type
!= SYM_BAD
&& sym
->ctype
.base_type
->type
!= SYM_FN
)
69 if (sym
->type
== SYM_NODE
|| sym
->type
== SYM_BAD
)
78 warning(*pos
, "r_symbol bad sym type=%d kind=%d", sym
->type
, sym
->kind
);
81 static void r_member(unsigned mode
, struct position
*pos
, struct symbol
*sym
, struct symbol
*mem
)
83 struct ident
*ni
, *si
, *mi
;
85 print_usage(pos
, sym
, mode
);
87 ni
= built_in_ident("?");
88 si
= sym
->ident
?: ni
;
89 /* mem == NULL means entire struct accessed */
90 mi
= mem
? (mem
->ident
?: ni
) : built_in_ident("*");
92 printf("%c m %.*s.%-*.*s %s\n",
93 symscope(sym
), si
->len
, si
->name
,
94 32-1 - si
->len
, mi
->len
, mi
->name
,
95 show_typename(mem
? mem
->ctype
.base_type
: sym
));
97 if (sym
->ident
&& sym
->kind
!= 's')
98 warning(*pos
, "r_member bad sym type=%d kind=%d", sym
->type
, sym
->kind
);
99 if (mem
&& mem
->kind
!= 'm')
100 warning(*pos
, "r_member bad mem->kind = %d", mem
->kind
);
103 static void r_symdef(struct symbol
*sym
)
105 r_symbol(-1, &sym
->pos
, sym
);
108 static void r_memdef(struct symbol
*sym
, struct symbol
*mem
)
110 r_member(-1, &mem
->pos
, sym
, mem
);
113 int main(int argc
, char **argv
)
115 static struct reporter reporter
= {
116 .r_symdef
= r_symdef
,
117 .r_memdef
= r_memdef
,
118 .r_symbol
= r_symbol
,
119 .r_member
= r_member
,
122 struct string_list
*filelist
= NULL
;
123 sparse_initialize(argc
, argv
, &filelist
);
124 dissect(&reporter
, filelist
);