dissect: minor fixes/cleanups
cover dissect: minor fixes/cleanups
Hello,
Preparations for the new functionality.
Oleg.
--- dissect.c | 42 +++++++++++++++++++----------------------- test-dissect.c | 7 +++---- 2 files changed, 22 insertions(+), 27 deletions(-)
PATCH 1/4 dissect: don't report anonymous members in initializers
Change report_member() to not call ->r_member(mem) if !mem->ident. This can only happen in initializer, the output gives no useful info but looks like a bug. Test-case:
struct {
union {
int x;
};
} var = {
{}
};before this patch:
1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var 6:9 s -w- :var.? union <noident>
after:
1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var
We also need to change no_member() to ensure we still report the bad initializers, this will be cleanuped later.
--- dissect.c | 4 ++-- test-dissect.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-)
dissect.c +2 -2
@@ -125,7 +125,7 @@ static inline struct symbol *no_member(struct ident *name) }; sym.ctype.base_type = &bad_ctype; - sym.ident = name; + sym.ident = name ?:built_in_ident ("?" );return &sym; }
@@ -135,7 +135,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos, {struct symbol *ret = mem->ctype.base_type; -if (reporter->r_member) +if (mem->ident && reporter->r_member) reporter->r_member (fix_mode (ret, mode), pos, type, mem);return ret;
test-dissect.c +3 -4
@@ -56,14 +56,13 @@ static void r_symbol(unsigned mode, struct position *pos, struct symbol *sym)static void r_member (unsigned mode,struct position *pos,struct symbol *sym,struct symbol *mem) { -struct ident *ni, *si, *mi; +struct ident *si, *mi;print_usage (pos, sym, mode); - ni =built_in_ident ("?" ); - si = sym->ident ?: ni; + si = sym->ident ?:built_in_ident ("?" );/* mem == NULL means entire struct accessed */ - mi = mem ? (mem->ident ?: ni) :built_in_ident ("*" ); + mi = mem ? mem->ident :built_in_ident ("*" ); printf("%.*s.%-*.*s %s\n", si->len, si->name,
Signature · 1 line
2.5.0
PATCH 2/4 dissect: turn mk_name() into deanon()
In reply to Oleg NesterovPreparation. Change mk_name() to initialize base->ident itself, simplify it, and rename to deanon().
Also change examine_sym_node() to accept "struct symbol *parent" rather than "struct ident *root". Currently it is only used as ->ident holder, but this will be changed.
--- dissect.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
dissect.c +14 -10
@@ -190,18 +190,22 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr)return ret; } -static inline struct ident *mk_name (struct ident *root,struct ident *node) +static bool deanon (struct symbol *base,struct ident *node,struct symbol *parent) { +struct ident *pi = parent ? parent->ident :NULL ;char name[256 ]; +if (!node) +return false; +snprintf (name,sizeof (name),"%.*s:%.*s" , - root ? root->len :0 , root ? root->name :"" , - node ? node->len :0 , node ? node->name :"" ); + pi ? pi->len :0 , pi ? pi->name :NULL , node->len, node->name); -return built_in_ident (name); + base->ident =built_in_ident (name); +return true; } -static void examine_sym_node (struct symbol *node,struct ident *root) +static void examine_sym_node (struct symbol *node,struct symbol *parent) {struct symbol *base;struct ident *name;
@@ -232,12 +236,12 @@ static void examine_sym_node(struct symbol *node, struct ident *root)return ; base->evaluated =1 ; -if (!base->ident && name) - base->ident =mk_name (root, name); -if (base->ident && reporter->r_symdef) - reporter->r_symdef (base); +if (base->ident ||deanon (base, name, parent)) { +if (reporter->r_symdef) + reporter->r_symdef (base); + }DO_LIST (base->symbol_list, mem, -examine_sym_node (mem, base->ident ?: root)); +examine_sym_node (mem, base->ident ? base : parent));default :return ; }
Signature · 1 line
2.5.0
PATCH 3/4 dissect: change deanon() to handle the !node case
In reply to Oleg NesterovChange deanon() to always initialize base->ident when parent != NULL but still return false to avoid the pointless ->r_symdef().
Test-case:
struct {
union {
int x;
};
} var = {
{ .x = 0 },
};before this patch:
1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var 6:12 s -w- ?.x int
after:
1:8 s def :var 5:3 g def var struct :var 5:3 g -w- var struct :var 6:12 s -w- :var.x int
--- dissect.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
dissect.c +3 -1
@@ -195,8 +195,10 @@ static bool deanon(struct symbol *base, struct ident *node, struct symbol *parenstruct ident *pi = parent ? parent->ident :NULL ;char name[256 ]; -if (!node) +if (!node) { + base->ident = pi;return false; + }snprintf (name,sizeof (name),"%.*s:%.*s" , pi ? pi->len :0 , pi ? pi->name :NULL , node->len, node->name);
Signature · 1 line
2.5.0
PATCH 4/4 dissect: disallow NULL pointers in struct reporter
In reply to Oleg NesterovThis makes dissect.c a bit more readable.
--- dissect.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)
dissect.c +4 -11
@@ -135,7 +135,7 @@ static struct symbol *report_member(usage_t mode, struct position *pos, {struct symbol *ret = mem->ctype.base_type; -if (mem->ident && reporter->r_member) +if (mem->ident) reporter->r_member (fix_mode (ret, mode), pos, type, mem);return ret;
@@ -146,9 +146,6 @@ static void report_implicit(usage_t mode, struct position *pos, struct symbol *tif (type->type !=SYM_STRUCT && type->type !=SYM_UNION )return ; -if (!reporter->r_member) -return ; -if (type->ident !=NULL ) reporter->r_member (mode, pos, type,NULL );
@@ -184,8 +181,7 @@ static struct symbol *report_symbol(usage_t mode, struct expression *expr)if (0 && ret->type ==SYM_ENUM )return report_member (mode, &expr->pos, ret, expr->symbol); -if (reporter->r_symbol) - reporter->r_symbol (fix_mode (ret, mode), &expr->pos, sym); + reporter->r_symbol (fix_mode (ret, mode), &expr->pos, sym);return ret; }
@@ -238,10 +234,8 @@ static void examine_sym_node(struct symbol *node, struct symbol *parent)return ; base->evaluated =1 ; -if (base->ident ||deanon (base, name, parent)) { -if (reporter->r_symdef) - reporter->r_symdef (base); - } +if (base->ident ||deanon (base, name, parent)) + reporter->r_symdef (base);DO_LIST (base->symbol_list, mem,examine_sym_node (mem, base->ident ? base : parent));default :
@@ -577,19 +571,15 @@ static struct symbol *do_initializer(struct symbol *type, struct expression *expstatic inline struct symbol *do_symbol (struct symbol *sym) { -struct symbol *type;
On Tue, Feb 04, 2020 at 05:51:19PM +0100, Oleg Nesterov wrote:
Thanks for theses patches and the following one.
-- Luc