bison-patches
[Top][All Lists]
Advanced

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

Include file into the locations


From: Akim Demaille
Subject: Include file into the locations
Date: 09 Jul 2002 18:22:48 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

Paul, you are CC'd because the following patch includes a simple
change to quotearg.h: protect it against multiple inclusions.  I
understand fighting for single inclusion of system header is the right
to do, but for simple modules, I much prefer `#include == #import'.
Does it makes sense for the real quotearg.h?

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * lib/quotearg.h: Protect against multiple inclusions.
        * src/location.h (location_t): Add a `file' member.
        (LOCATION_RESET, LOCATION_PRINT): Adjust.
        * src/complain.c (warn_at, complain_at, fatal_at): Drop
        `error_one_per_line' support.

Index: lib/quotearg.h
===================================================================
RCS file: /cvsroot/bison/bison/lib/quotearg.h,v
retrieving revision 1.2
diff -u -u -r1.2 quotearg.h
--- lib/quotearg.h 30 Nov 2001 14:04:24 -0000 1.2
+++ lib/quotearg.h 9 Jul 2002 16:18:10 -0000
@@ -17,6 +17,9 @@

 /* Written by Paul Eggert <address@hidden> */

+#ifndef QUOTEARG_H_
+# define QUOTEARG_H_ 1
+
 /* Basic quoting styles.  */
 enum quoting_style
   {
@@ -30,9 +33,9 @@
   };

 /* For now, --quoting-style=literal is the default, but this may change.  */
-#ifndef DEFAULT_QUOTING_STYLE
-# define DEFAULT_QUOTING_STYLE literal_quoting_style
-#endif
+# ifndef DEFAULT_QUOTING_STYLE
+#  define DEFAULT_QUOTING_STYLE literal_quoting_style
+# endif

 /* Names of quoting styles and their corresponding values.  */
 extern char const *const quoting_style_args[];
@@ -40,13 +43,13 @@

 struct quoting_options;

-#ifndef PARAMS
-# if defined PROTOTYPES || defined __STDC__
-#  define PARAMS(Args) Args
-# else
-#  define PARAMS(Args) ()
+# ifndef PARAMS
+#  if defined PROTOTYPES || defined __STDC__
+#   define PARAMS(Args) Args
+#  else
+#   define PARAMS(Args) ()
+#  endif
 # endif
-#endif

 /* The functions listed below set and use a hidden variable
    that contains the default quoting style options.  */
@@ -107,3 +110,5 @@

 /* Equivalent to quotearg_char (ARG, ':').  */
 char *quotearg_colon PARAMS ((char const *arg));
+
+#endif /* !QUOTEARG_H_ */
Index: src/complain.c
===================================================================
RCS file: /cvsroot/bison/bison/src/complain.c,v
retrieving revision 1.10
diff -u -u -r1.10 complain.c
--- src/complain.c 9 Jul 2002 15:54:39 -0000 1.10
+++ src/complain.c 9 Jul 2002 16:18:10 -0000
@@ -41,9 +41,6 @@
 void exit ();
 #endif

-/* To get error_one_per_line. */
-#include "error.h"
-
 #include "complain.h"

 #ifndef HAVE_DECL_STRERROR_R
@@ -128,20 +125,6 @@
   va_list args;
 #endif

-  if (error_one_per_line)
-    {
-      static const char *old_infile;
-      static int old_lineno;
-
-      if (old_lineno == location.first_line &&
-         (infile == old_infile || !strcmp (old_infile, infile)))
-       /* Simply return and print nothing.  */
-       return;
-
-      old_infile = infile;
-      old_lineno = location.first_line;
-    }
-
   fflush (stdout);
   LOCATION_PRINT (stderr, location);
   fputs (": ", stderr);
@@ -177,20 +160,6 @@
 #ifdef VA_START
   va_list args;
 #endif
-
-  if (error_one_per_line)
-    {
-      static const char *old_infile;
-      static int old_lineno;
-
-      if (old_lineno == location.first_line &&
-         (infile == old_infile || !strcmp (old_infile, infile)))
-       /* Simply return and print nothing.  */
-       return;
-
-      old_infile = infile;
-      old_lineno = location.first_line;
-    }

   fflush (stdout);
   LOCATION_PRINT (stderr, location);
Index: src/location.c
===================================================================
RCS file: /cvsroot/bison/bison/src/location.c,v
retrieving revision 1.1
diff -u -u -r1.1 location.c
--- src/location.c 15 Jun 2002 18:21:11 -0000 1.1
+++ src/location.c 9 Jul 2002 16:18:10 -0000
@@ -18,7 +18,7 @@
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */

-
+#include "system.h"
 #include "location.h"

-location_t empty_location = { 0, 0, 0, 0 };
+location_t empty_location = { NULL, 0, 0, 0, 0 };
Index: src/location.h
===================================================================
RCS file: /cvsroot/bison/bison/src/location.h,v
retrieving revision 1.2
diff -u -u -r1.2 location.h
--- src/location.h 15 Jun 2002 18:21:11 -0000 1.2
+++ src/location.h 9 Jul 2002 16:18:10 -0000
@@ -20,9 +20,11 @@

 #ifndef LOCATION_H_
 # define LOCATION_H_
+# include "quotearg.h"

 typedef struct location_s
 {
+  const char *file;
   int first_line;
   int first_column;
   int last_line;
@@ -31,36 +33,52 @@
 #define YYLTYPE location_t

 /* Initialize LOC. */
-# define LOCATION_RESET(Loc)                  \
-  (Loc).first_column = (Loc).first_line = 1;  \
-  (Loc).last_column =  (Loc).last_line = 1;
+# define LOCATION_RESET(Loc)                   \
+do {                                           \
+  (Loc).file = NULL;                           \
+  (Loc).first_column = (Loc).first_line = 1;   \
+  (Loc).last_column =  (Loc).last_line = 1;    \
+} while (0)

 /* Advance of NUM columns. */
-# define LOCATION_COLUMNS(Loc, Num)           \
-  (Loc).last_column += Num;
+# define LOCATION_COLUMNS(Loc, Num)            \
+do {                                           \
+  (Loc).last_column += Num;                    \
+} while (0)
+

 /* Advance of NUM lines. */
-# define LOCATION_LINES(Loc, Num)             \
-  (Loc).last_column = 1;                      \
-  (Loc).last_line += Num;
+# define LOCATION_LINES(Loc, Num)              \
+do {                                           \
+  (Loc).last_column = 1;                       \
+  (Loc).last_line += Num;                      \
+} while (0)
+

 /* Restart: move the first cursor to the last position. */
-# define LOCATION_STEP(Loc)                   \
-  (Loc).first_column = (Loc).last_column;     \
-  (Loc).first_line = (Loc).last_line;
+# define LOCATION_STEP(Loc)                    \
+do {                                           \
+  (Loc).first_column = (Loc).last_column;      \
+  (Loc).first_line = (Loc).last_line;          \
+} while (0)
+

 /* Output LOC on the stream OUT. */
-# define LOCATION_PRINT(Out, Loc)                               \
-  fprintf (stderr, "%s:", infile);                             \
-  if ((Loc).first_line != (Loc).last_line)                      \
-    fprintf (Out, "%d.%d-%d.%d",                                \
-             (Loc).first_line, (Loc).first_column,              \
-             (Loc).last_line, (Loc).last_column - 1);           \
-  else if ((Loc).first_column < (Loc).last_column - 1)          \
-    fprintf (Out, "%d.%d-%d", (Loc).first_line,                 \
-             (Loc).first_column, (Loc).last_column - 1);        \
-  else                                                          \
-    fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column)
+# define LOCATION_PRINT(Out, Loc)                                      \
+do {                                                                   \
+  fprintf (stderr, "%s:", quotearg_style (escape_quoting_style,        \
+                                         (Loc).file));                 \
+  if ((Loc).first_line != (Loc).last_line)                             \
+    fprintf (Out, "%d.%d-%d.%d",                                       \
+             (Loc).first_line, (Loc).first_column,                     \
+             (Loc).last_line, (Loc).last_column - 1);                  \
+  else if ((Loc).first_column < (Loc).last_column - 1)                 \
+    fprintf (Out, "%d.%d-%d", (Loc).first_line,                                
\
+             (Loc).first_column, (Loc).last_column - 1);               \
+  else                                                                 \
+    fprintf (Out, "%d.%d", (Loc).first_line, (Loc).first_column);      \
+} while (0)
+


 extern location_t empty_location;
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.21
diff -u -u -r1.21 scan-gram.l
--- src/scan-gram.l 9 Jul 2002 15:54:39 -0000 1.21
+++ src/scan-gram.l 9 Jul 2002 16:18:21 -0000
@@ -34,13 +34,14 @@
 #define YY_USER_INIT                           \
 do {                                           \
   LOCATION_RESET (*yylloc);                    \
+  yylloc->file = infile;                       \
    /* This is only to avoid GCC warnings. */   \
   if (yycontrol) {;};                          \
 } while (0)

-#define YY_USER_ACTION  LOCATION_COLUMNS (*yylloc, yyleng)
+#define YY_USER_ACTION  LOCATION_COLUMNS (*yylloc, yyleng);
 #define YY_LINES        LOCATION_LINES (*yylloc, yyleng);
-#define YY_STEP         LOCATION_STEP (*yylloc)
+#define YY_STEP         LOCATION_STEP (*yylloc);

 /* STRING_OBSTACK -- Used to store all the characters that we need to
    keep (to construct ID, STRINGS etc.).  Use the following macros to



reply via email to

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