bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/8] allow modification on retrieved code_props.


From: Akim Demaille
Subject: [PATCH 1/8] allow modification on retrieved code_props.
Date: Mon, 23 Jul 2012 14:06:00 +0200

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 ec5579f..2dfb170 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 24ef5d9..cacd256 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 ab3f12e..a502dfd 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 e2bf2d3..31c4696 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.
 
-- 
1.7.11.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]