[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] parsing: record used associativity and print useless ones
From: |
Valentin Tolmer |
Subject: |
[PATCH 1/2] parsing: record used associativity and print useless ones |
Date: |
Wed, 30 Jan 2013 10:26:53 +0100 |
Record which symbol associativity is used, and display useless ones.
* src/symtab.h, src/symtab.c (register_assoc, print_assoc_warnings): New
* src/symtab.c (init_assoc, is_assoc_used): New
* src/main.c: Use print_assoc_warnings
* src/conflicts.c: Use register_assoc
---
src/conflicts.c | 3 +++
src/main.c | 2 ++
src/symtab.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/symtab.h | 8 +++++++
4 files changed, 77 insertions(+)
diff --git a/src/conflicts.c b/src/conflicts.c
index 696d0a0..bb5e231 100644
--- a/src/conflicts.c
+++ b/src/conflicts.c
@@ -303,16 +303,19 @@ resolve_sr_conflict (state *s, int ruleno, symbol
**errors, int *nerrs)
break;
case right_assoc:
+ register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, right_resolution);
flush_reduce (lookahead_tokens, i);
break;
case left_assoc:
+ register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, left_resolution);
flush_shift (s, i);
break;
case non_assoc:
+ register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, nonassoc_resolution);
flush_shift (s, i);
flush_reduce (lookahead_tokens, i);
diff --git a/src/main.c b/src/main.c
index 2ab87fb..4add238 100644
--- a/src/main.c
+++ b/src/main.c
@@ -146,6 +146,8 @@ main (int argc, char *argv[])
print_precedence_warnings ();
+ print_assoc_warnings ();
+
/* Output file names. */
compute_output_file_names ();
diff --git a/src/symtab.c b/src/symtab.c
index d7a3c68..32bb416 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -52,6 +52,12 @@ location startsymbol_location;
static symgraph **prec_nodes;
+/*-----------------------------------.
+| Store which associativity is used. |
+`-----------------------------------*/
+
+bool *used_assoc = NULL;
+
/*---------------------------------.
| Create a new symbol, named TAG. |
`---------------------------------*/
@@ -1096,3 +1102,61 @@ print_precedence_warnings (void)
}
free_symgraphlink (unused);
}
+
+/*---------------------------------------.
+| Initialize association tracking table. |
+`---------------------------------------*/
+
+static void
+init_assoc (void)
+{
+ int i;
+ used_assoc = xcalloc(nsyms, sizeof(*used_assoc));
+ for (i = 0; i < nsyms; ++i)
+ used_assoc[i] = false;
+}
+
+/*------------------------------------------------------------------.
+| Test if the associativity for the symbols is defined and useless. |
+`------------------------------------------------------------------*/
+
+static inline bool
+is_assoc_useless (symbol *s)
+{
+ return s
+ && s->assoc != undef_assoc
+ && s->assoc != precedence_assoc
+ && !used_assoc[s->number];
+}
+
+/*-------------------------------.
+| Register a used associativity. |
+`-------------------------------*/
+
+void
+register_assoc (int i, int j)
+{
+ if (!used_assoc)
+ init_assoc ();
+ used_assoc[i] = true;
+ used_assoc[j] = true;
+}
+
+/*------------------------------------------------------.
+| Print a warning for each unused symbol associativity. |
+`------------------------------------------------------*/
+
+void
+print_assoc_warnings (void)
+{
+ int i;
+ if (!used_assoc)
+ init_assoc ();
+ for (i = 0; i < nsyms; ++i)
+ {
+ symbol *s = symbols[i];
+ if (is_assoc_useless (s))
+ complain (&s->location, Wother, _("useless associativity for %s"),
+ s->tag);
+ }
+}
diff --git a/src/symtab.h b/src/symtab.h
index c1edac5..6a4648e 100644
--- a/src/symtab.h
+++ b/src/symtab.h
@@ -270,6 +270,14 @@ void register_precedence (graphid first, graphid snd);
void print_precedence_warnings (void);
+/*----------------------.
+| Symbol associativity |
+`----------------------*/
+
+void register_assoc (int i, int j);
+
+void print_assoc_warnings (void);
+
/*-----------------.
| Semantic types. |
`-----------------*/
--
1.7.9.5