bison-patches
[Top][All Lists]
Advanced

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

[PATCH 2/3] style: fix comments and more debug trace


From: Akim Demaille
Subject: [PATCH 2/3] style: fix comments and more debug trace
Date: Fri, 7 Aug 2020 07:35:07 +0200

* src/location.c, src/symtab.h, src/symtab.c: here.
---
 src/location.c   |  4 +++-
 src/parse-gram.c |  3 +--
 src/parse-gram.y |  3 +--
 src/symtab.c     | 20 ++++++++++++++------
 src/symtab.h     |  2 +-
 5 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/location.c b/src/location.c
index 1c0aa1fd..418a728d 100644
--- a/src/location.c
+++ b/src/location.c
@@ -155,7 +155,9 @@ int
 location_print (location loc, FILE *out)
 {
   int res = 0;
-  if (trace_flag & trace_locations)
+  if (location_empty (loc))
+    res += fprintf (out, "(empty location)");
+  else if (trace_flag & trace_locations)
     {
       res += boundary_print (&loc.start, out);
       res += fprintf (out, "-");
diff --git a/src/parse-gram.c b/src/parse-gram.c
index fae69b50..d8eb81cc 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -3147,8 +3147,7 @@ char_name (char c)
     }
 }
 
-static
-void
+static void
 current_lhs (symbol *sym, location loc, named_ref *ref)
 {
   current_lhs_symbol = sym;
diff --git a/src/parse-gram.y b/src/parse-gram.y
index cd706263..925e0773 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -1158,8 +1158,7 @@ char_name (char c)
     }
 }
 
-static
-void
+static void
 current_lhs (symbol *sym, location loc, named_ref *ref)
 {
   current_lhs_symbol = sym;
diff --git a/src/symtab.c b/src/symtab.c
index 678f4def..6c416b0b 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -243,7 +243,11 @@ semantic_type_new (uniqstr tag, const location *loc)
 | Print a symbol.  |
 `-----------------*/
 
-#define SYMBOL_ATTR_PRINT(Attr)                         \
+#define SYMBOL_INT_ATTR_PRINT(Attr)                     \
+  if (s->content)                                       \
+    fprintf (f, " %s = %d", #Attr, s->content->Attr)
+
+#define SYMBOL_STR_ATTR_PRINT(Attr)                     \
   if (s->content && s->content->Attr)                   \
     fprintf (f, " %s { %s }", #Attr, s->content->Attr)
 
@@ -264,7 +268,11 @@ symbol_print (symbol const *s, FILE *f)
                : c == nterm_sym    ? "nterm"
                : NULL, /* abort.  */
                s->tag);
-      SYMBOL_ATTR_PRINT (type_name);
+      putc (' ', f);
+      location_print (s->location, f);
+      SYMBOL_INT_ATTR_PRINT (code);
+      SYMBOL_INT_ATTR_PRINT (number);
+      SYMBOL_STR_ATTR_PRINT (type_name);
       SYMBOL_CODE_PRINT (destructor);
       SYMBOL_CODE_PRINT (printer);
     }
@@ -573,9 +581,9 @@ symbol_class_set (symbol *sym, symbol_class class, location 
loc, bool declaring)
 }
 
 
-/*------------------------------------------------.
-| Set the USER_TOKEN_NUMBER associated with SYM.  |
-`------------------------------------------------*/
+/*----------------------------.
+| Set the token code of SYM.  |
+`----------------------------*/
 
 void
 symbol_code_set (symbol *sym, int code, location loc)
@@ -1000,7 +1008,7 @@ symbol_cmp (void const *a, void const *b)
 }
 
 /* Store in *SORTED an array of pointers to the symbols contained in
-   TABLE, sorted (alphabetically) by tag. */
+   TABLE, sorted by order of appearance (i.e., by location). */
 
 static void
 table_sort (struct hash_table *table, symbol ***sorted)
diff --git a/src/symtab.h b/src/symtab.h
index 7bfd310c..e85e5468 100644
--- a/src/symtab.h
+++ b/src/symtab.h
@@ -227,7 +227,7 @@ void symbol_precedence_set (symbol *sym, int prec, assoc a, 
location loc);
 void symbol_class_set (symbol *sym, symbol_class class, location loc,
                        bool declaring);
 
-/** Set the \c code associated with \c sym.  */
+/** Set the token \c code of \c sym, specified by the user at \c loc.  */
 void symbol_code_set (symbol *sym, int code, location loc);
 
 
-- 
2.28.0




reply via email to

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