From 70946cff5eaf230a65ad8581773a535e293f0c85 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 22 Jul 2012 17:46:34 +0200 Subject: [PATCH] allow modification on retrieved code_props. The logic to compute the %printer or %destructor to used (i.e., a code_props) is implemented twice: one, of course, in symbol_code_props_get, and another time in symbol_check_defined to record the fact that a code_props is used (so that we can reported unused ones). Let the former use the latter. I would probably use "mutable" in C++ and keep these guys const, but this is C. And casting away constness triggers warnings. * src/scan-code.h, src/scan-code.l (code_props_none): Is not const. * src/symtab.h, src/symtab.c (symbol_code_props_get): The symbol is not const. (symbol_check_defined): Use it. --- src/scan-code.h | 2 +- src/scan-code.l | 2 +- src/symtab.c | 15 ++++----------- src/symtab.h | 3 +-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/scan-code.h b/src/scan-code.h index ec5579f3..2dfb1704 100644 --- a/src/scan-code.h +++ b/src/scan-code.h @@ -103,7 +103,7 @@ void code_props_none_init (code_props *self); } /** Initialized by \c CODE_PROPS_NONE_INIT with no further modification. */ -extern code_props const code_props_none; +extern code_props code_props_none; /** * \pre diff --git a/src/scan-code.l b/src/scan-code.l index 24ef5d92..cacd2561 100644 --- a/src/scan-code.l +++ b/src/scan-code.l @@ -890,7 +890,7 @@ code_props_none_init (code_props *self) *self = code_props_none; } -code_props const code_props_none = CODE_PROPS_NONE_INIT; +code_props code_props_none = CODE_PROPS_NONE_INIT; void code_props_plain_init (code_props *self, char const *code, diff --git a/src/symtab.c b/src/symtab.c index ab3f12e7..a502dfd1 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -274,9 +274,8 @@ semantic_type_code_props_set (semantic_type *type, | Get the computed %destructor or %printer for SYM. | `---------------------------------------------------*/ -code_props const * -symbol_code_props_get (symbol const *sym, - code_props_type kind) +code_props * +symbol_code_props_get (symbol *sym, code_props_type kind) { /* Per-symbol code props. */ if (sym->props[kind].code) @@ -285,7 +284,7 @@ symbol_code_props_get (symbol const *sym, /* Per-type code props. */ if (sym->type_name) { - code_props const *code = + code_props *code = &semantic_type_get (sym->type_name, NULL)->props[kind]; if (code->code) return code; @@ -421,13 +420,7 @@ symbol_check_defined (symbol *sym) } for (int i = 0; i < 2; ++i) - if (sym->props[i].kind == CODE_PROPS_NONE && sym->type_name) - { - semantic_type *sem_type = semantic_type_get (sym->type_name, NULL); - if (sem_type - && sem_type->props[i].kind != CODE_PROPS_NONE) - sem_type->props[i].is_used = true; - } + symbol_code_props_get (sym, i)->is_used = true; /* Set the semantic type status associated to the current symbol to 'declared' so that we could check semantic types unnecessary uses. */ diff --git a/src/symtab.h b/src/symtab.h index e2bf2d38..31c46960 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -181,8 +181,7 @@ void symbol_code_props_set (symbol *sym, code_props_type kind, /** Get the computed \c \%destructor or \c %printer for \c sym, which was initialized with \c code_props_none_init if there's no \c \%destructor or \c %printer. */ -code_props const *symbol_code_props_get (symbol const *sym, - code_props_type kind); +code_props *symbol_code_props_get (symbol *sym, code_props_type kind); /** Set the \c precedence associated with \c sym. -- 2.45.2