[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Fix variadic declaration of yyerror() and yylex() function p
From: |
Jeannot Langlois |
Subject: |
Re: [PATCH] Fix variadic declaration of yyerror() and yylex() function prototypes |
Date: |
Sun, 29 May 2005 13:25:33 -0400 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040913) |
Paul Eggert wrote:
Jeannot Langlois <address@hidden> writes:
Are these declarations another possible mistake by the test case
writer? Shouldn't these test case use "static int yyerror(...)" since
they assert "%yacc" ? (Should I change these test cases to use "void"
too? Or maybe there's something I didn't get...?)
The idea here, as I understand it, is to change Bison so that it
assumes "int" when in Yacc mode and "void" otherwise. If so, then
yes, we should fix the test cases to agree with this new convention.
Hi Paul,
Ok, so things were as I assumed then -- I just wanted to make sure I
didn't get anything wrong as I felt quite surprised when I noticed I had
to modify the testsuite again since some older testcases were modified
between version 2.0 and 2.0a to use an incorrect return type for yyerror().
Now with this new patch everything should be fixed (AFAIK). The
testsuite passes all tests (except for the two doxygen ones which were
skipped since I don't have doxygen installed). I have tested my own
reentrant/glr grammar and the yyerror() prototype is generated
properly. Of course I haven't created small grammars to test all
scenarios, as I trust the testsuite to handle most of these important cases.
So new patch is attached, generated from Bison-2.0a. Please ensure you
review it before commit to help ensure it won't break anything it shouldn't.
Patch should be applied within Bison-2.0a's base directory using "patch
-p0 < yylex_yyerror_autogeneration.diff".
Regards,
--
*Jeannot Langlois*
B. Sc. Computer Science / B. Sc. Informatique
Software Developer / Programmeur-Analyste
System/Network Administrator / Administrateur Système/Réseau
**
LINUX_LOGO
diff -r -u data/c.m4 data/c.m4
--- data/c.m4 2005-05-14 02:52:28.000000000 -0400
+++ data/c.m4 2005-05-28 20:36:29.000000000 -0400
@@ -322,6 +322,14 @@
[[#]line $1 $2])])
+# b4_yacc_flag
+# Expand IF-TRUE, if yacc_flag, IF-FALSE otherwise
+# ------------------------------------------------
+m4_define([b4_yyyacc_mode_if],
+[m4_if(b4_yacc_flag, [1], [$1], [$2])]
+)
+
+
# b4_symbol_actions(FILENAME, LINENO,
# SYMBOL-TAG, SYMBOL-NUM,
# SYMBOL-ACTION, SYMBOL-TYPENAME)
diff -r -u data/glr.c data/glr.c
--- data/glr.c 2005-05-22 01:25:16.000000000 -0400
+++ data/glr.c 2005-05-28 20:40:55.000000000 -0400
@@ -49,6 +49,17 @@
m4_define([b4_user_formals],
[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
+# b4_alt_user_formals
+# -------------------------
+m4_define([b4_alt_user_formals],
+[m4_ifset([b4_parse_param], [b4_c_ansi_formals(b4_parse_param), ])])
+
+# b4_yyerror_params
+# -----------------
+m4_define([b4_yyerror_params],
+[b4_pure_if([b4_location_if([YYLTYPE *yylocationp,
])[]b4_alt_user_formals[]])]dnl
+[const char* yymsg]dnl
+)
# b4_yyerror_args
# ---------------
@@ -412,10 +423,19 @@
]b4_stos[
};
-
+
/* Prevent warning if -Wmissing-prototypes. */
]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
+/* Prevent warning if -Wmissing-prototypes. */
+]b4_c_ansi_function_decl([yylex], [int], b4_lex_param)[
+
+/* Prevent warning if -Wmissing-prototypes. */
+]b4_yyyacc_mode_if(
+[]b4_c_function_decl([yyerror], [int], b4_yyerror_params)[],
+[]b4_c_function_decl([yyerror], [void], b4_yyerror_params)[]
+)[
+
/* Error token number */
#define YYTERROR 1
diff -r -u data/yacc.c data/yacc.c
--- data/yacc.c 2005-05-21 13:12:32.000000000 -0400
+++ data/yacc.c 2005-05-28 20:40:39.000000000 -0400
@@ -63,6 +63,15 @@
m4_ifdef([b4_lex_param], b4_lex_param)))
+# b4_yyerror_params
+# ----------------
+m4_define([b4_yyecho_pp], $1)
+
+m4_define([b4_yyerror_params],
+[b4_Pure_if([b4_location_if([YYLTYPE *yylocationp, ])]dnl
+m4_ifset([b4_parse_param], [[m4_map_sep([b4_yyecho_pp], [, ],
m4_dquote(m4_map_sep([b4_yyecho_pp], [, ], m4_dquote(b4_parse_param))))]][[,
]]))]dnl
+[const char* yymsg]dnl
+)
## ------------ ##
## Data Types. ##
@@ -742,6 +751,24 @@
#endif /* ! YYPARSE_PARAM */
+/* Prevent warnings from -Wmissing-prototypes. */
+
+#ifdef YYLEX_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yylex (void *YYLEX_PARAM);
+# else
+int yylex ();
+# endif
+#else
+b4_c_function_decl([yylex], [int], b4_lex_param)
+#endif /* ! YYLEX_PARAM */
+
+/* Prevent warnings from -Wmissing-prototypes. */
+b4_yyyacc_mode_if(
+b4_c_function_decl([yyerror], [int], b4_yyerror_params),
+b4_c_function_decl([yyerror], [void], b4_yyerror_params)
+)
+
m4_divert_push([KILL])# ======================== M4 code.
# b4_declare_parser_variables
# ---------------------------
diff -r -u src/output.c src/output.c
--- src/output.c 2005-05-14 02:52:29.000000000 -0400
+++ src/output.c 2005-05-28 20:36:13.000000000 -0400
@@ -599,6 +599,7 @@
MUSCLE_INSERT_BOOL ("locations_flag", locations_flag);
MUSCLE_INSERT_BOOL ("pure", pure_parser);
MUSCLE_INSERT_BOOL ("synclines_flag", !no_lines_flag);
+ MUSCLE_INSERT_BOOL ("yacc_flag", yacc_flag);
/* File names. */
MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
diff -r -u tests/testsuite tests/testsuite
--- tests/testsuite 2005-05-22 03:02:00.000000000 -0400
+++ tests/testsuite 2005-05-28 17:19:06.000000000 -0400
@@ -16056,7 +16056,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -16111,7 +16111,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -20848,7 +20848,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -20903,7 +20903,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -23494,7 +23494,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -23549,7 +23549,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -24948,7 +24948,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -25003,7 +25003,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -26402,7 +26402,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (YYLTYPE *yylloc,
+static int yyerror (YYLTYPE *yylloc,
semantic_value *result, int *count,
const char *s
);
@@ -26457,7 +26457,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (YYLTYPE *yylloc,
semantic_value *result, int *count,
const char *s)
@@ -33846,7 +33846,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -33901,7 +33901,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -38638,7 +38638,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -38693,7 +38693,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -41034,7 +41034,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (
+static int yyerror (
const char *s
);
@@ -41089,7 +41089,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (
const char *s)
@@ -42238,7 +42238,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (YYLTYPE *yylloc,
+static int yyerror (YYLTYPE *yylloc,
const char *s
);
@@ -42293,7 +42293,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (YYLTYPE *yylloc,
const char *s)
@@ -43442,7 +43442,7 @@
/* yyerror receives the location if:
- %location & %pure & %glr
- %location & %pure & %yacc & %parse-param. */
-static void yyerror (YYLTYPE *yylloc,
+static int yyerror (YYLTYPE *yylloc,
semantic_value *result, int *count,
const char *s
);
@@ -43497,7 +43497,7 @@
/* The input. */
static FILE *yyin;
-static void
+static int
yyerror (YYLTYPE *yylloc,
semantic_value *result, int *count,
const char *s)
@@ -58959,7 +58959,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -59089,7 +59089,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -59098,7 +59098,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -59333,7 +59332,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -59466,7 +59465,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -59475,7 +59474,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -59710,7 +59708,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -59840,7 +59838,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -59849,7 +59847,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -60084,7 +60081,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -60217,7 +60214,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -60226,7 +60223,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -60461,7 +60457,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -60591,7 +60587,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -60600,7 +60596,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -60840,7 +60835,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -60973,7 +60968,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -60982,7 +60977,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -61222,7 +61216,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -61352,7 +61346,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -61361,7 +61355,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -61601,7 +61594,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -61734,7 +61727,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -61743,7 +61736,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -61983,7 +61975,7 @@
# define ERROR_PARAMETERS char const *s
#endif
int yylex (LEX_PARAMETERS);
- int yyerror (ERROR_PARAMETERS);
+ void yyerror (ERROR_PARAMETERS);
%}
%token TYPENAME ID
@@ -62113,7 +62105,7 @@
}
}
-int
+void
yyerror (ERROR_PARAMETERS)
{
#if YYPURE && YYLSP_NEEDED
@@ -62122,7 +62114,6 @@
abort ();
#endif
fprintf (stderr, "%s\n", s);
- return 0;
}
@@ -62324,7 +62315,7 @@
#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
int yylex (void);
-int yyerror (char const *msg);
+void yyerror (char const *msg);
%}
@@ -62360,11 +62351,11 @@
return yyparse ();
}
-int
+void
yyerror (char const *msg)
{
fprintf (stderr, "%s\n", msg);
- exit (4);
+ exit(4);
}