]> git.saurik.com Git - bison.git/commitdiff
Merge remote-tracking branch 'origin/maint'
authorAkim Demaille <akim@lrde.epita.fr>
Mon, 3 Dec 2012 15:27:23 +0000 (16:27 +0100)
committerAkim Demaille <akim@lrde.epita.fr>
Mon, 3 Dec 2012 15:27:23 +0000 (16:27 +0100)
* origin/maint:
  parser: accept #line NUM
  m4: use a safer pattern to enable/disable output
  tests: beware of gnulib's need for config.h
  gnulib: update
  yacc.c, glr.c: check and fix the display of locations
  formatting changes
  glr.c: remove stray macro

Conflicts:
data/c.m4
data/glr.cc
data/lalr1.cc
data/lalr1.java
data/location.cc
data/stack.hh
data/yacc.c
src/scan-gram.l

18 files changed:
THANKS
data/bison.m4
data/c.m4
data/glr.c
data/glr.cc
data/lalr1.cc
data/lalr1.java
data/location.cc
data/stack.hh
data/yacc.c
lib/.gitignore
lib/yyerror.c
m4/.gitignore
src/location.c
src/scan-gram.l
tests/actions.at
tests/skeletons.at
tests/torture.at

diff --git a/THANKS b/THANKS
index 0c6a81726e7547c8bf9e60c020241368a0a2c4fd..909a6e004bd1b0a9e38a3dee6e5ca22885c676f3 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -58,6 +58,7 @@ Jim Kent                  jkent@arch.sel.sony.com
 Jim Meyering              jim@meyering.net
 Joel E. Denny             joeldenny@joeldenny.org
 Johan van Selst           johans@stack.nl
+Jonathan Fabrizio         jonathan.fabrizio@lrde.epita.fr
 Jonathan Nieder           jrnieder@gmail.com
 Juan Manuel Guerrero      juan.guerrero@gmx.de
 Kees Zeelenberg           kzlg@users.sourceforge.net
index c652b2ec409fa7040145ea35465339d9f137f5ba..bd8af095a55252d19de108ddc8398a2def08447e 100644 (file)
@@ -61,6 +61,30 @@ This special exception was added by the Free Software Foundation in
 version 2.2 of Bison.])])
 
 
+## -------- ##
+## Output.  ##
+## -------- ##
+
+# b4_output_begin(FILE)
+# ---------------------
+# Enable output, i.e., send to diversion 0, expand after "#", and
+# generate the tag to output into FILE.  Must be followed by EOL.
+m4_define([b4_output_begin],
+[m4_changecom()
+m4_divert_push(0)dnl
+@output(m4_unquote([$1])@)@dnl
+])
+
+
+# b4_output_end()
+# ---------------
+# Output nothing, restore # as comment character (no expansions after #).
+m4_define([b4_output_end],
+[m4_divert_pop(0)
+m4_changecom([#])
+])
+
+
 ## ---------------- ##
 ## Error handling.  ##
 ## ---------------- ##
index 91126a82b84ef325cb83ed406f5d4b0fdf33c2a1..6c2f552583ef3757f1c44996fd586c45c1039ea6 100644 (file)
--- a/data/c.m4
+++ b/data/c.m4
@@ -610,14 +610,40 @@ m4_define([b4_yy_location_print_define],
 
 #ifndef YY_LOCATION_PRINT
 # if defined ]b4_api_PREFIX[LTYPE_IS_TRIVIAL && ]b4_api_PREFIX[LTYPE_IS_TRIVIAL
+
+/* Print *YYLOCP on YYO.  Private, do not rely on its existence. */
+
+__attribute__((__unused__))
+]b4_function_define([yy_location_print_],
+    [static unsigned],
+               [[FILE *yyo],                    [yyo]],
+               [[YYLTYPE const * const yylocp], [yylocp]])[
+{
+  unsigned res = 0;
+  int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
+  if (0 <= yylocp->first_line)
+    {
+      res += fprintf (yyo, "%d", yylocp->first_line);
+      if (0 <= yylocp->first_column)
+        res += fprintf (yyo, ".%d", yylocp->first_column);
+    }
+  if (0 <= yylocp->last_line)
+    {
+      if (yylocp->first_line < yylocp->last_line)
+        {
+          res += fprintf (yyo, "-%d", yylocp->last_line);
+          if (0 <= end_col)
+            res += fprintf (yyo, ".%d", end_col);
+        }
+      else if (0 <= end_col && yylocp->first_column < end_col)
+        res += fprintf (yyo, "-%d", end_col);
+    }
+  return res;
+ }
+
 #  define YY_LOCATION_PRINT(File, Loc)                                   \
-  do {                                                                   \
-    fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column);       \
-    if ((Loc).first_line < (Loc).last_line)                              \
-      fprintf (File, "-%d.%d", (Loc).last_line,  (Loc).last_column - 1); \
-    else if ((Loc).first_column < (Loc).last_column - 1)                 \
-      fprintf (File, "-%d", (Loc).last_column - 1);                      \
-  } while (0)
+  yy_location_print_ (File, &(Loc))
+
 # else
 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
 # endif
index 9038c7475d0d42e66829154d9f608862d4786cb1..1e82e5891ff472b1ce75c9cae3bf8b2cca979f02 100644 (file)
@@ -188,13 +188,10 @@ m4_if(b4_skeleton, ["glr.c"],
 ## Output files.  ##
 ## -------------- ##
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
-@output(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Skeleton implementation for Bison GLR parsers in C],
-             [2002-2012])
-[
+             [2002-2012])[
+
 /* C GLR parser skeleton written by Paul Hilfinger.  */
 
 ]b4_identification
@@ -305,13 +302,6 @@ b4_percent_code_get[]dnl
 # endif
 #endif
 
-]b4_locations_if([#define YYOPTIONAL_LOC(Name) Name],[
-#ifdef __cplusplus
-# define YYOPTIONAL_LOC(Name) /* empty */
-#else
-# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
-#endif])[
-
 #ifndef YYASSERT
 # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
 #endif
@@ -2560,17 +2550,17 @@ yypdumpstack (yyGLRStack* yystackp)
 }
 #endif
 ]b4_epilogue[]dnl
-dnl
-dnl glr.cc produces its own header.
-dnl
+b4_output_end()
+
+# glr.cc produces its own header.
 m4_if(b4_skeleton, ["glr.c"],
 [b4_defines_if(
-[@output(b4_spec_defines_file@)@
+[b4_output_begin([b4_spec_defines_file])
 b4_copyright([Skeleton interface for Bison GLR parsers in C],
              [2002-2012])[
 
 ]b4_cpp_guard_open([b4_spec_defines_file])[
 ]b4_shared_declarations[
 ]b4_cpp_guard_close([b4_spec_defines_file])[
-]])])dnl
-m4_divert_pop(0)
+]b4_output_end()
+])])
index 8841f10be51d31b646c7859cfb1b26289b6afae9..3cecfd8eb4ca406f4d44e71b99ce3446f0b9fc17 100644 (file)
@@ -319,8 +319,7 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
 ]b4_cpp_guard_open([b4_spec_defines_file])[
 ]b4_shared_declarations[
 ]b4_cpp_guard_close([b4_spec_defines_file])[
-]m4_divert_pop(0)
-m4_changecom[#])])
+]b4_output_end()])
 
 # Let glr.c (and b4_shared_declarations) believe that the user
 # arguments include the parser itself.
index 34eef13801a661d2db596f4d0da6612f7521d1fd..fa3a48d484af0e623b108a4ba504786c2d6e4ff9 100644 (file)
@@ -352,12 +352,11 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
 ]b4_cpp_guard_open([b4_spec_defines_file])[
 ]b4_shared_declarations[
 ]b4_cpp_guard_close([b4_spec_defines_file])
-m4_divert_pop(0)dnl
+b4_output_end()
 ])
 
 
-m4_divert_push(0)dnl
-@output(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
 b4_percent_code_get([[top]])[]dnl
 m4_if(b4_prefix, [yy], [],
@@ -1141,5 +1140,7 @@ b4_error_verbose_if([state_type yystate, int yytoken],
 ]b4_token_ctor_if([], [b4_yytranslate_define])[
 ]b4_namespace_close[
 ]b4_epilogue[]dnl
-m4_divert_pop(0)
+b4_output_end()
+
+
 m4_popdef([b4_copyright_years])dnl
index 1cfaef38caf15686beb2d9731ae46215d5af92b5..02079fd0a2f63efb1578f3bd2081fd6edc9fff71 100644 (file)
@@ -30,8 +30,7 @@ m4_define([b4_symbol_no_destructor_assert],
                         [b4_symbol_action_location([$1], [destructor])])])])
 b4_symbol_foreach([b4_symbol_no_destructor_assert])
 
-m4_divert_push(0)dnl
-@output(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
              [2007-2012])
 
@@ -874,4 +873,4 @@ b4_percent_code_get[]dnl
 }
 
 b4_epilogue[]dnl
-m4_divert_pop(0)dnl
+b4_output_end()
index 5879ea374e581bf331b67d30a67baa3c589cb5b1..b49028f9559ac6ec0236486def75ea0fa92451c8 100644 (file)
@@ -268,8 +268,7 @@ m4_define([b4_location_define],
 # We do want M4 expansion after # for CPP macros.
 m4_changecom()
 b4_defines_if([
-m4_divert_push(0)dnl
-@output(b4_dir_prefix[]position.hh@)@
+b4_output_begin([b4_dir_prefix[]position.hh])
 b4_copyright([Positions for Bison parsers in C++])[
 
 /**
@@ -289,7 +288,10 @@ b4_copyright([Positions for Bison parsers in C++])[
 ]b4_position_define[
 ]b4_namespace_close[
 ]b4_cpp_guard_close([b4_dir_prefix[]position.hh])
-@output(b4_dir_prefix[]location.hh@)@
+b4_output_end()
+
+
+b4_output_begin([b4_dir_prefix[]location.hh])
 b4_copyright([Locations for Bison parsers in C++])[
 
 /**
@@ -305,7 +307,8 @@ b4_copyright([Locations for Bison parsers in C++])[
 ]b4_location_define[
 ]b4_namespace_close[
 ]b4_cpp_guard_close([b4_dir_prefix[]location.hh])
-m4_divert_pop(0)
-])# b4_defines_if
-m4_popdef([b4_copyright_years])dnl
-m4_changecom([#])
+b4_output_end()
+])
+
+
+m4_popdef([b4_copyright_years])
index bd94eb2da5dded1256f7ed840257ae72d4adebf3..4fd136fd2d55f9203aed75b2728be67665aeae9e 100644 (file)
@@ -119,10 +119,7 @@ m4_define([b4_stack_define],
 ]])
 
 b4_defines_if(
-[# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
-@output(b4_dir_prefix[]stack.hh@)@
+[b4_output_begin([b4_dir_prefix[]stack.hh])
 b4_copyright([Stack handling for Bison parsers in C++])[
 
 /**
@@ -139,7 +136,7 @@ b4_copyright([Stack handling for Bison parsers in C++])[
 ]b4_namespace_close[
 
 ]b4_cpp_guard_close([b4_dir_prefix[]stack.hh])
-m4_divert_pop(0)
-m4_popdef([b4_copyright_years])dnl
-m4_changecom([#])
+b4_output_end()
 ])
+
+m4_popdef([b4_copyright_years])
index 2b6d10acbb3b7e5c67bf9d881a4d2951a42b6bf3..9bd80280bd7d26cdbe06c46b56d706b10f76b456 100644 (file)
@@ -326,10 +326,7 @@ m4_define([b4_shared_declarations],
 ## Output files.  ##
 ## -------------- ##
 
-# We do want M4 expansion after # for CPP macros.
-m4_changecom()
-m4_divert_push(0)dnl
-@output(b4_parser_file_name@)@
+b4_output_begin([b4_parser_file_name])
 b4_copyright([Bison implementation for Yacc-like parsers in C])[
 
 /* C LALR(1) parser skeleton written by Richard Stallman, by
@@ -1941,11 +1938,12 @@ yypushreturn:]])[
   return yyresult;
 }
 ]b4_epilogue[]dnl
+b4_output_end()
+
 b4_defines_if(
-[@output(b4_spec_defines_file@)@
-b4_copyright([Bison interface for Yacc-like parsers in C])[
+[b4_output_begin([b4_spec_defines_file])[
+]b4_copyright([Bison interface for Yacc-like parsers in C])[
 
 ]b4_shared_declarations[
-]])dnl b4_defines_if
-m4_divert_pop(0)
-m4_popdef([b4_copyright_years])
+]b4_output_end()
+])# b4_defines_if
index e62b99c31b56485a4780d3754d55da6eab5fe10a..ba37d129a39e3ddcdcb50559cb030dadf013fa77 100644 (file)
 /xstrndup.h
 /binary-io.c
 /xsize.c
+/bitrotate.c
+/math.c
+/sig-handler.c
+/stdio.c
+/unistd.c
+/wctype-h.c
index c9f492f8433ac5d30fca1f3617ba6bbbb0cc0ad2..332e91e2c8b739e751c24d32208ade80d5c3ca21 100644 (file)
@@ -17,6 +17,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include <config.h>
+
 #include <stdio.h>
 
 int yyerror (char const *);
index 3dfdf6adc8f4e963c4c89dd9b3207710f8f21cc5..80193dbb1778cd0db3a88e4f1188ea0eb0aa5201 100644 (file)
@@ -48,7 +48,6 @@
 /hash.m4
 /iconv.m4
 /include_next.m4
-/inline.m4
 /intdiv0.m4
 /intl.m4
 /intl.m4~
index a749415878e2c1f0708beb54f0a814d5d18c18ba..c27ad1449f3a5983cd5e4e11f58b6922c0128108 100644 (file)
@@ -107,7 +107,7 @@ location_print (FILE *out, location loc)
                   quotearg_n_style (3, escape_quoting_style, loc.start.file));
   if (0 <= loc.start.line)
     {
-      res += fprintf(out, ":%d", loc.start.line);
+      res += fprintf (out, ":%d", loc.start.line);
       if (0 <= loc.start.column)
         res += fprintf (out, ".%d", loc.start.column);
     }
@@ -118,7 +118,7 @@ location_print (FILE *out, location loc)
                                         loc.end.file));
       if (0 <= loc.end.line)
         {
-          res += fprintf(out, ":%d", loc.end.line);
+          res += fprintf (out, ":%d", loc.end.line);
           if (0 <= end_col)
             res += fprintf (out, ".%d", end_col);
         }
index f5c9b88f013463dac4f9931c55531333e86aca3c..e6f42ea934c57a539f659d869100855821032739 100644 (file)
@@ -193,7 +193,7 @@ eqopt    ([[:space:]]*=)?
 
   /* #line directives are not documented, and may be withdrawn or
      modified in future versions of Bison.  */
-  ^"#line "{int}" \"".*"\"\n" {
+  ^"#line "{int}(" \"".*"\"")?"\n" {
     handle_syncline (yytext + sizeof "#line " - 1, *loc);
   }
 }
@@ -974,23 +974,27 @@ convert_ucn_to_byte (char const *ucn)
 }
 
 
-/*----------------------------------------------------------------.
-| Handle '#line INT "FILE"'.  ARGS has already skipped '#line '.  |
-`----------------------------------------------------------------*/
+/*---------------------------------------------------------------------.
+| Handle '#line INT( "FILE")?\n'.  ARGS has already skipped '#line '.  |
+`---------------------------------------------------------------------*/
 
 static void
 handle_syncline (char *args, location loc)
 {
-  char *after_num;
-  unsigned long int lineno = strtoul (args, &after_num, 10);
-  char *file = strchr (after_num, '"') + 1;
-  *strchr (file, '"') = '\0';
+  char *file;
+  unsigned long int lineno = strtoul (args, &file, 10);
   if (INT_MAX <= lineno)
     {
       complain (&loc, Wother, _("line number overflow"));
       lineno = INT_MAX;
     }
-  current_file = uniqstr_new (file);
+
+  file = strchr (file, '"');
+  if (file)
+    {
+      *strchr (file + 1, '"') = '\0';
+      current_file = uniqstr_new (file + 1);
+    }
   boundary_set (&scanner_cursor, current_file, lineno, 1);
 }
 
index 8278293dfcac0e64d16d27dae5d58086b28b8ee8..c148391d731435cfef9af6fbed189e3a7a601871 100644 (file)
@@ -174,6 +174,81 @@ m4_popdef([AT_TEST])
 
 
 
+## ---------------- ##
+## Location Print.  ##
+## ---------------- ##
+
+# AT_TEST(SKELETON-NAME, DIRECTIVES, [MORE-DIRECTIVES], [LOCATION = 1.1])
+# -----------------------------------------------------------------------
+# Check that the initial location is correct.
+m4_pushdef([AT_TEST],
+[AT_SETUP([Location print: $1 $2])
+
+AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" $2])
+AT_DATA_GRAMMAR([[input.y]],
+[[%defines /* FIXME: Required by lalr1.cc in Bison 2.6. */
+%locations
+%debug
+%skeleton "$1"
+]$2[
+]$3[
+%code
+{
+# include <stdio.h>
+# include <stdlib.h> // getenv
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
+}
+%%
+exp:;
+%%
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE[
+
+int
+main (void)
+{
+#define TEST(L1, C1, L2, C2)          \
+  ]AT_LOC_FIRST_LINE[ = L1;           \
+  ]AT_LOC_FIRST_COLUMN[ = C1;         \
+  ]AT_LOC_LAST_LINE[ = L2;            \
+  ]AT_LOC_LAST_COLUMN[ = C2;          \
+  ]YY_LOCATION_PRINT(stdout, AT_LOC)[;\
+  putchar ('\n');
+
+  TEST(1, 1, 1, 1);
+  TEST(2, 1, 2, 10);
+  TEST(3, 1, 4, 1);
+  TEST(5, 1, 6, 10);
+
+  TEST(7, 2, 0, 2);
+  TEST(8, 0, 8, 0);
+}
+]])
+
+AT_FULL_COMPILE([input])
+AT_PARSER_CHECK([./input], 0,
+[[1.1
+2.1-9
+3.1-4.0
+5.1-6.9
+7.2
+8.0
+]])
+AT_BISON_OPTION_POPDEFS
+AT_CLEANUP
+])
+
+## FIXME: test Java, and iterate over skeletons.
+AT_TEST([yacc.c])
+AT_TEST([glr.c])
+#AT_TEST([lalr1.cc])
+#AT_TEST([glr.cc])
+
+m4_popdef([AT_TEST])
+
+
+
 ## ---------------- ##
 ## Exotic Dollars.  ##
 ## ---------------- ##
index dafc74dab987bf2211d113b5d0639ff2616539df..8632df16bf81cc383eb64eff04e4504701978187 100644 (file)
@@ -114,10 +114,10 @@ main (void)
 }
 ]])
 
-AT_DATA([[input-cmd-line.y]],
+AT_DATA_GRAMMAR([[input-cmd-line.y]],
 [AT_GRAM])
 
-AT_DATA([[input-gram.y]],
+AT_DATA_GRAMMAR([[input-gram.y]],
 [[%skeleton "yacc.c"]
 AT_GRAM])
 
index 5aa18900e6155a4705b25fa761d3ed0ea06f19fc..ac9e91ea67e1c45466ceb2f317747d4ceec472f9 100644 (file)
@@ -269,6 +269,7 @@ print <<EOF;
 %error-verbose
 %debug
 %{
+]AT_DATA_SOURCE_PROLOGUE[
 # include <stdio.h>
 # include <stdlib.h>
 # include <assert.h>
@@ -383,7 +384,7 @@ m4_define([AT_DATA_STACK_TORTURE],
 [AT_BISON_OPTION_PUSHDEFS([$2])
 # A grammar of parens growing the stack thanks to right recursion.
 # exp:
-AT_DATA([input.y],
+AT_DATA_GRAMMAR([input.y],
 [[%{
 #include <errno.h>
 #include <limits.h>