* [PATCH] dissect: introduce dissect_ctx
@ 2020-02-06 17:01 Oleg Nesterov
2020-02-06 20:45 ` Luc Van Oostenryck
0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2020-02-06 17:01 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
Points to the current function or to the global variable in case of
compound initializer.
Kill the ugly test-dissect.c:storage() and change print_usage() to
report dissect_ctx->ident instead.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
dissect.c | 17 +++++++++++++++--
dissect.h | 2 ++
test-dissect.c | 21 ++++++++-------------
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/dissect.c b/dissect.c
index 60fccbd..54e11d2 100644
--- a/dissect.c
+++ b/dissect.c
@@ -51,6 +51,8 @@
typedef unsigned usage_t;
+struct symbol *dissect_ctx;
+
static struct reporter *reporter;
static struct symbol *return_type;
@@ -211,7 +213,7 @@ static void report_memdef(struct symbol *sym, struct symbol *mem)
static void examine_sym_node(struct symbol *node, struct symbol *parent)
{
- struct symbol *base;
+ struct symbol *base, *dctx;
struct ident *name;
if (node->examined)
@@ -240,6 +242,9 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
return;
base->evaluated = 1;
+ dctx = dissect_ctx;
+ dissect_ctx = NULL;
+
if (base->ident || deanon(base, name, parent))
reporter->r_symdef(base);
@@ -248,6 +253,7 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)
DO_LIST(base->symbol_list, mem,
examine_sym_node(mem, parent);
report_memdef(parent, mem));
+ dissect_ctx = dctx;
default:
return;
}
@@ -582,6 +588,7 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *exp
static inline struct symbol *do_symbol(struct symbol *sym)
{
struct symbol *type = base_type(sym);
+ struct symbol *dctx = dissect_ctx;
reporter->r_symdef(sym);
@@ -590,14 +597,20 @@ static inline struct symbol *do_symbol(struct symbol *sym)
if (!sym->initializer)
break;
reporter->r_symbol(U_W_VAL, &sym->pos, sym);
+ if (!dctx)
+ dissect_ctx = sym;
do_initializer(type, sym->initializer);
+ dissect_ctx = dctx;
break; case SYM_FN:
- do_sym_list(type->arguments);
+ dissect_ctx = sym;
return_type = base_type(type);
+ do_sym_list(type->arguments);
do_statement(U_VOID, sym->ctype.modifiers & MOD_INLINE
? type->inline_stmt
: type->stmt);
+ dissect_ctx = dctx;
+ return_type = NULL;
}
return type;
diff --git a/dissect.h b/dissect.h
index 1f5b1d9..efe2c0b 100644
--- a/dissect.h
+++ b/dissect.h
@@ -25,6 +25,8 @@ struct reporter
void (*r_member)(unsigned, struct position *, struct symbol *, struct symbol *);
};
+extern struct symbol *dissect_ctx;
+
extern void dissect(struct symbol_list *, struct reporter *);
#endif
diff --git a/test-dissect.c b/test-dissect.c
index e725eec..d93a2a0 100644
--- a/test-dissect.c
+++ b/test-dissect.c
@@ -2,17 +2,6 @@
static unsigned dotc_stream;
-static inline char storage(struct symbol *sym)
-{
- int t = sym->type;
- unsigned m = sym->ctype.modifiers;
-
- if (m & MOD_INLINE || t == SYM_STRUCT || t == SYM_UNION /*|| t == SYM_ENUM*/)
- return sym->pos.stream == dotc_stream ? 's' : 'g';
-
- return (m & MOD_STATIC) ? 's' : (m & MOD_NONLOCAL) ? 'g' : 'l';
-}
-
static inline const char *show_mode(unsigned mode)
{
static char str[3];
@@ -32,14 +21,20 @@ static inline const char *show_mode(unsigned mode)
static void print_usage(struct position *pos, struct symbol *sym, unsigned mode)
{
static unsigned curr_stream = -1;
+ static struct ident null;
+ struct ident *ctx = &null;
if (curr_stream != pos->stream) {
curr_stream = pos->stream;
printf("\nFILE: %s\n\n", stream_name(curr_stream));
}
- printf("%4d:%-3d %c %-5.3s",
- pos->line, pos->pos, storage(sym), show_mode(mode));
+ if (dissect_ctx)
+ ctx = dissect_ctx->ident;
+
+ printf("%4d:%-3d %-16.*s %-5.3s",
+ pos->line, pos->pos, ctx->len, ctx->name, show_mode(mode));
+
}
static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)
--
2.5.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] dissect: introduce dissect_ctx
2020-02-06 17:01 [PATCH] dissect: introduce dissect_ctx Oleg Nesterov
@ 2020-02-06 20:45 ` Luc Van Oostenryck
2020-02-07 10:01 ` Oleg Nesterov
0 siblings, 1 reply; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-02-06 20:45 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Alexey Gladkov, linux-sparse
On Thu, Feb 06, 2020 at 06:01:32PM +0100, Oleg Nesterov wrote:
> Points to the current function or to the global variable in case of
> compound initializer.
>
> Kill the ugly test-dissect.c:storage() and change print_usage() to
> report dissect_ctx->ident instead.
Having the ful ident will be good, I think, but the cost is to have
to maintain this context. I suppose it would be too painful to
propgate this context via an additional argument to all involved
functions?
-- Luc
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dissect: introduce dissect_ctx
2020-02-06 20:45 ` Luc Van Oostenryck
@ 2020-02-07 10:01 ` Oleg Nesterov
2020-02-07 11:21 ` Luc Van Oostenryck
0 siblings, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2020-02-07 10:01 UTC (permalink / raw)
To: Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse
On 02/06, Luc Van Oostenryck wrote:
>
> On Thu, Feb 06, 2020 at 06:01:32PM +0100, Oleg Nesterov wrote:
> > Points to the current function or to the global variable in case of
> > compound initializer.
> >
> > Kill the ugly test-dissect.c:storage() and change print_usage() to
> > report dissect_ctx->ident instead.
>
> Having the ful ident will be good, I think, but the cost is to have
> to maintain this context. I suppose it would be too painful to
> propgate this context via an additional argument to all involved
> functions?
Oh, I'd prefer to not do this. This needs to add the additional "ctx"
arg to every do_.*() function in dissect.c, and for what? IMHO, this
will just complicate the code for no reason.
I can unexport the global "struct symbol *dissect_ctx" introduced by
this patch and pass it as the additional (new) argument to every to
every callback, but I'd like to do this later, along with other
"incompatible" changes for the new tool Alexey is working on.
Thanks,
Oleg.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] dissect: introduce dissect_ctx
2020-02-07 10:01 ` Oleg Nesterov
@ 2020-02-07 11:21 ` Luc Van Oostenryck
0 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-02-07 11:21 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: Alexey Gladkov, linux-sparse
On Fri, Feb 07, 2020 at 11:01:50AM +0100, Oleg Nesterov wrote:
> On 02/06, Luc Van Oostenryck wrote:
> >
> > On Thu, Feb 06, 2020 at 06:01:32PM +0100, Oleg Nesterov wrote:
> > > Points to the current function or to the global variable in case of
> > > compound initializer.
> > >
> > > Kill the ugly test-dissect.c:storage() and change print_usage() to
> > > report dissect_ctx->ident instead.
> >
> > Having the ful ident will be good, I think, but the cost is to have
> > to maintain this context. I suppose it would be too painful to
> > propgate this context via an additional argument to all involved
> > functions?
>
> Oh, I'd prefer to not do this. This needs to add the additional "ctx"
> arg to every do_.*() function in dissect.c, and for what? IMHO, this
> will just complicate the code for no reason.
Yes, I guessed so. No problem.
-- Luc
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-02-07 11:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-06 17:01 [PATCH] dissect: introduce dissect_ctx Oleg Nesterov
2020-02-06 20:45 ` Luc Van Oostenryck
2020-02-07 10:01 ` Oleg Nesterov
2020-02-07 11:21 ` Luc Van Oostenryck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).