From a945ec3929db92bcebd8c93f2842ff6b2ea84dd4 Mon Sep 17 00:00:00 2001
From: Akim Demaille <akim@epita.fr>
Date: Tue, 16 Jul 2002 14:04:06 +0000
Subject: [PATCH] * src/assoc.c, src/asssoc.h (assoc_t, assoc_to_string): New.
 Adjust all former `associativity' dependencies. * src/symtab.c (symbol_new):
 Default associativity is `undef', not `right'.
 (symbol_check_alias_consistence): Adjust.

---
 ChangeLog        |  8 ++++++++
 src/Makefile.am  |  1 +
 src/assoc.c      | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/assoc.h      | 35 +++++++++++++++++++++++++++++++++++
 src/parse-gram.c |  4 ++--
 src/parse-gram.h |  2 +-
 src/parse-gram.y |  4 ++--
 src/symtab.c     | 17 +++++++----------
 src/symtab.h     | 15 +++------------
 9 files changed, 102 insertions(+), 27 deletions(-)
 create mode 100644 src/assoc.c
 create mode 100644 src/assoc.h

diff --git a/ChangeLog b/ChangeLog
index 7d942691..a903fdd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2002-07-16  Akim Demaille  <akim@epita.fr>
+
+	* src/assoc.c, src/asssoc.h (assoc_t, assoc_to_string): New.
+	Adjust all former `associativity' dependencies.
+	* src/symtab.c (symbol_new): Default associativity is `undef', not
+	`right'.
+	(symbol_check_alias_consistence): Adjust.
+
 2002-07-09  Akim Demaille  <akim@epita.fr>
 
 	* doc/bison.texinfo: Properly set the ``header'' part.
diff --git a/src/Makefile.am b/src/Makefile.am
index c3edda8d..f46d032b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,6 +37,7 @@ bin_PROGRAMS = bison
 
 bison_SOURCES = 				  \
 	LR0.c LR0.h				  \
+	assoc.c assoc.h				  \
 	closure.c closure.h			  \
 	complain.c complain.h			  \
 	conflicts.c conflicts.h			  \
diff --git a/src/assoc.c b/src/assoc.c
new file mode 100644
index 00000000..226a3519
--- /dev/null
+++ b/src/assoc.c
@@ -0,0 +1,43 @@
+/* Associativity information.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+
+   This file is part of Bison, the GNU Compiler Compiler.
+
+   Bison is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   Bison is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bison; see the file COPYING.  If not, write to
+   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include "system.h"
+#include "assoc.h"
+
+
+const char *
+assoc_to_string (assoc_t assoc)
+{
+  switch (assoc)
+    {
+    case undef_assoc:
+      return "undefined associativity";
+
+    case right_assoc:
+      return "%right";
+
+    case left_assoc:
+      return "%left";
+
+    case non_assoc:
+      return "%nonassoc";
+    }
+  return NULL;
+}
diff --git a/src/assoc.h b/src/assoc.h
new file mode 100644
index 00000000..dd62e194
--- /dev/null
+++ b/src/assoc.h
@@ -0,0 +1,35 @@
+/* Associativity information.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+
+   This file is part of Bison, the GNU Compiler Compiler.
+
+   Bison is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   Bison is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Bison; see the file COPYING.  If not, write to
+   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef ASSOC_H_
+# define ASSOC_H_
+
+/* Associativity values for tokens and rules.  */
+typedef enum
+{
+  undef_assoc,
+  right_assoc,
+  left_assoc,
+  non_assoc
+} assoc_t;
+
+const char *assoc_to_string PARAMS ((assoc_t assoc));
+
+#endif /* !ASSOC_H_ */
diff --git a/src/parse-gram.c b/src/parse-gram.c
index 175ca0f9..45c72386 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -105,7 +105,7 @@ symbol_class current_class = unknown_sym;
 char *current_type = 0;
 symbol_t *current_lhs;
 location_t current_lhs_location;
-associativity current_assoc;
+assoc_t current_assoc;
 int current_prec = 0;
 braced_code_t current_braced_code = action_braced_code;
 
@@ -231,7 +231,7 @@ typedef union {
   symbol_list_t *list;
   int integer;
   char *string;
-  associativity assoc;
+  assoc_t assoc;
 } yystype;
 /* Line 187 of /usr/local/share/bison/yacc.c.  */
 #line 238 "parse-gram.c"
diff --git a/src/parse-gram.h b/src/parse-gram.h
index fc18e77d..d8939d29 100644
--- a/src/parse-gram.h
+++ b/src/parse-gram.h
@@ -134,7 +134,7 @@ typedef union {
   symbol_list_t *list;
   int integer;
   char *string;
-  associativity assoc;
+  assoc_t assoc;
 } yystype;
 /* Line 1271 of /usr/local/share/bison/yacc.c.  */
 #line 141 "y.tab.h"
diff --git a/src/parse-gram.y b/src/parse-gram.y
index c29bc529..d777daec 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -78,7 +78,7 @@ symbol_class current_class = unknown_sym;
 char *current_type = 0;
 symbol_t *current_lhs;
 location_t current_lhs_location;
-associativity current_assoc;
+assoc_t current_assoc;
 int current_prec = 0;
 braced_code_t current_braced_code = action_braced_code;
 %}
@@ -91,7 +91,7 @@ braced_code_t current_braced_code = action_braced_code;
   symbol_list_t *list;
   int integer;
   char *string;
-  associativity assoc;
+  assoc_t assoc;
 };
 
 /* Define the tokens together with there human representation. */
diff --git a/src/symtab.c b/src/symtab.c
index afc0c1c8..ef03b284 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -55,7 +55,7 @@ symbol_new (const char *tag, location_t location)
 
   res->number = NUMBER_UNDEFINED;
   res->prec = 0;
-  res->assoc = right_assoc;
+  res->assoc = undef_assoc;
   res->user_token_number = USER_NUMBER_UNDEFINED;
 
   res->alias = NULL;
@@ -129,7 +129,7 @@ symbol_printer_set (symbol_t *symbol, char *printer, location_t location)
 
 void
 symbol_precedence_set (symbol_t *symbol,
-		       int prec, associativity assoc, location_t location)
+		       int prec, assoc_t assoc, location_t location)
 {
   if (assoc != undef_assoc)
     {
@@ -288,15 +288,12 @@ symbol_check_alias_consistence (symbol_t *this)
 
       if (this->assoc != this->alias->assoc)
 	{
-	  /* FIXME: For some reason (probably the S/R => keep the S),
-	     the right assoc is chosen has the ``not set''.  This is
-	     not nice, fix this!  */
-	  if (this->assoc != right_assoc
-	      && this->alias->assoc != right_assoc)
+	  if (this->assoc != undef_assoc && this->alias->assoc != undef_assoc)
 	    complain_at (this->alias->location,
-			 _("conflicting associativities for %s and %s"),
-			 this->tag, this->alias->tag);
-	  if (this->assoc != 0)
+			 _("conflicting associativities for %s (%s) and %s (%s)"),
+			 this->tag, assoc_to_string (this->assoc),
+			 this->alias->tag, assoc_to_string (this->alias->assoc));
+	  if (this->assoc != undef_assoc)
 	    this->alias->assoc = this->assoc;
 	  else
 	    this->assoc = this->alias->assoc;
diff --git a/src/symtab.h b/src/symtab.h
index 4dd463f3..5abe3896 100644
--- a/src/symtab.h
+++ b/src/symtab.h
@@ -23,21 +23,12 @@
 # define SYMTAB_H_
 
 # include "location.h"
+# include "assoc.h"
 
 /*----------.
 | Symbols.  |
 `----------*/
 
-/* Associativity values for tokens and rules.  */
-typedef enum
-{
-  undef_assoc,
-  right_assoc,
-  left_assoc,
-  non_assoc
-} associativity;
-
-
 /* Symbol classes.  */
 typedef enum
 {
@@ -68,7 +59,7 @@ struct symbol_s
 
   symbol_number_t number;
   short prec;
-  associativity assoc;
+  assoc_t assoc;
   int user_token_number;
 
   /* Points to the other in the identifier-symbol pair for an alias.
@@ -118,7 +109,7 @@ void symbol_printer_set PARAMS ((symbol_t *symbol,
 /* Set the PRECEDENCE associated to SYMBOL.  Ensures that SYMBOL is a
    terminal.  Does nothing if invoked with UNDEF_ASSOC as ASSOC.  */
 void symbol_precedence_set PARAMS ((symbol_t *symbol,
-				    int prec, associativity assoc,
+				    int prec, assoc_t assoc,
 				    location_t location));
 
 /* Set the CLASS associated to SYMBOL.  */
-- 
2.47.2