From b088dc6f5e3c5c815b90a62042faf3472dc79244 Mon Sep 17 00:00:00 2001
From: Akim Demaille <akim@lrde.epita.fr>
Date: Fri, 26 Jul 2013 13:45:41 +0200
Subject: [PATCH] symtab: avoid compiler warnings

../../src/symtab.c: In function 'declare_precedence_relation':
../../src/symtab.c:249:21: error: 'functionPtr' may be used uninitialized in this function [-Werror=maybe-uninitialized]
       (*functionPtr)(l1->content.sym->prec_node, l2->content.sym->prec_node,
                     ^
cc1: all warnings being treated as errors

* src/symtab.c (add_link_t, add_link_function): New, to help the compiler
see the add_link function is always defined.
Also simplifies the code.
---
 src/conflicts.c |  2 +-
 src/symtab.c    | 36 ++++++++++++++++++++----------------
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/conflicts.c b/src/conflicts.c
index c5db933..5162ade 100644
--- a/src/conflicts.c
+++ b/src/conflicts.c
@@ -374,7 +374,7 @@ set_conflicts (state *s, symbol **errors)
      check for shift-reduce conflict, and try to resolve using
      precedence.  */
   for (i = 0; i < reds->num; ++i)
-    if (reds->rules[i]->prec// && reds->rules[i]->prec->prec
+    if (reds->rules[i]->prec /* && reds->rules[i]->prec->prec */
         && !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
       resolve_sr_conflict (s, i, errors, &nerrs);
 
diff --git a/src/symtab.c b/src/symtab.c
index 28a1a82..bab82ef 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -222,6 +222,22 @@ add_prec_equal_link (prec_node *s1, prec_node *s2, bool transitive,
   create_prec_equal_link (s2, s1, transitive, loc);
 }
 
+/* The function to use to register \a c type relations.  */
+typedef void (*add_link_t) (prec_node *, prec_node *, bool, location);
+static add_link_t
+add_link_function (prec_rel_comparator c)
+{
+  switch (c)
+    {
+    case prec_superior_strict:
+    case prec_superior:
+      return &add_prec_link;
+    case prec_equal:
+      return &add_prec_equal_link;
+    }
+  abort ();
+}
+
 /*---------------------------------------------------------------------.
 | Handle the precedence declaration between the elements of S1 and S2. |
 `---------------------------------------------------------------------*/
@@ -230,24 +246,12 @@ void
 declare_precedence_relation (symbol_list *s1, symbol_list *s2,
                              prec_rel_comparator c, location loc)
 {
-  void (*functionPtr) (prec_node *, prec_node *, bool, location);
-  bool transitive = true;
-  switch (c)
-    {
-    case prec_superior_strict:
-      transitive = false;
-      /* Fall-through */
-    case prec_superior:
-      functionPtr = &add_prec_link;
-      break;
-    case prec_equal:
-      functionPtr = &add_prec_equal_link;
-      break;
-    }
+  add_link_t add_link = add_link_function (c);
+  bool transitive = c != prec_superior_strict;
   for (symbol_list *l1 = s1; l1; l1 = l1->next)
     for (symbol_list *l2 = s2; l2; l2 = l2->next)
-      (*functionPtr)(l1->content.sym->prec_node, l2->content.sym->prec_node,
-                     transitive, loc);
+      add_link (l1->content.sym->prec_node, l2->content.sym->prec_node,
+                transitive, loc);
   symbol_list_free (s1);
   symbol_list_free (s2);
 }
-- 
1.8.3.3

