Have the GLR tests be `warning' checked, and fix the warnings.

* data/glr.c (YYFPRINTF): Always define it, not only when YYDEBUG
(yyuserAction, yyreportAmbiguity): `Use' all the arguments.
(yyremoveDeletes): `yyi' and `yyj' are size_t.
Use YYFPRINTF when under if (YYDEBUG) to avoid empty `if' bodies.
(yyaddDeferredAction): static.
(yyglrReduce): yyi, yyk, amd yyposn are size_t.
(yyreportParseError): yyprefix is const.
yytokenp is used only when verbose.
(yy__GNUC__): Replace with __GNUC__.
(yypdumpstack): yyi is size_t.
(yypreference): Un-yy local variables and arguments, to avoid
clashes with `yyr1'.  Anyway, we are not in the user name space.
(yytname_size): be an int, as is compared with ints.
* tests/testsuite.at (AT_COMPILE, AT_PARSER_CHECK): New.
Use them.
* tests/cxx-gram.at: Use quotation to protect $1.
Use AT_COMPILE to enable warnings hunts.
Prototype yylex and yyerror.
`Use' argc.
Include `string.h', not `strings.h'.
Produce and prototype stmtMerge only when used.
yylex takes a location.
This commit is contained in:
Akim Demaille
2002-06-30 17:35:06 +00:00
parent 97650f4efc
commit 1154ccedaf
11 changed files with 238 additions and 120 deletions

View File

@@ -1,3 +1,31 @@
2002-06-30 Akim Demaille <akim@epita.fr>
Have the GLR tests be `warning' checked, and fix the warnings.
* data/glr.c (YYFPRINTF): Always define it, not only when YYDEBUG
(yyuserAction, yyreportAmbiguity): `Use' all the arguments.
(yyremoveDeletes): `yyi' and `yyj' are size_t.
Use YYFPRINTF when under if (YYDEBUG) to avoid empty `if' bodies.
(yyaddDeferredAction): static.
(yyglrReduce): yyi, yyk, amd yyposn are size_t.
(yyreportParseError): yyprefix is const.
yytokenp is used only when verbose.
(yy__GNUC__): Replace with __GNUC__.
(yypdumpstack): yyi is size_t.
(yypreference): Un-yy local variables and arguments, to avoid
clashes with `yyr1'. Anyway, we are not in the user name space.
(yytname_size): be an int, as is compared with ints.
* tests/testsuite.at (AT_COMPILE, AT_PARSER_CHECK): New.
Use them.
* tests/cxx-gram.at: Use quotation to protect $1.
Use AT_COMPILE to enable warnings hunts.
Prototype yylex and yyerror.
`Use' argc.
Include `string.h', not `strings.h'.
Produce and prototype stmtMerge only when used.
yylex takes a location.
2002-06-30 Akim Demaille <akim@epita.fr> 2002-06-30 Akim Demaille <akim@epita.fr>
We spend a lot of time in quotearg, in particular when --verbose. We spend a lot of time in quotearg, in particular when --verbose.

View File

@@ -197,8 +197,24 @@ static YYLTYPE yyloc_default;
# define yyfalse 0 # define yyfalse 0
#endif #endif
#if ! defined (yy__GNUC__) /*-----------------.
# define inline | GCC extensions. |
`-----------------*/
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if !defined (__GNUC__) || __GNUC__ < 2 || \
(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
# define __attribute__(Spec) /* empty */
# endif
#endif
#ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
#if ! defined (__GNUC__)
# define inline
#endif #endif
/* YYFINAL -- State number of the termination state. */ /* YYFINAL -- State number of the termination state. */
@@ -259,7 +275,7 @@ static const char *const yytname[] =
]b4_tname[ ]b4_tname[
}; };
#define yytname_size (sizeof (yytname) / sizeof (yytname[0])) #define yytname_size ((int) (sizeof (yytname) / sizeof (yytname[0])))
#endif #endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
@@ -428,7 +444,8 @@ do { \
multiple parsers can coexist. */ multiple parsers can coexist. */
int yydebug; int yydebug;
#else /* !YYDEBUG */ #else /* !YYDEBUG */
# define YYDPRINTF(Args) /* Avoid empty `if' bodies. */
# define YYDPRINTF(Args) {}
#endif /* !YYDEBUG */ #endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */ /* YYINITDEPTH -- initial size of the parser's stacks. */
@@ -569,6 +586,9 @@ static YYRESULTTAG
yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack) YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack)
{ {
/* Avoid `unused' warnings in there are no $n. */
(void) yystack;
if (yyrhslen == 0) if (yyrhslen == 0)
{ {
*yyvalp = yyval_default; *yyvalp = yyval_default;
@@ -624,6 +644,10 @@ static YYSTYPE
yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
{ {
YYSTYPE yyval = *yy0; YYSTYPE yyval = *yy0;
/* `Use' the arguments. */
(void) yy0;
(void) yy1;
switch (yyn) switch (yyn)
{ {
b4_mergers b4_mergers
@@ -720,8 +744,9 @@ yyhasResolvedValue (yyGLRState* yystate)
return yystate->yyresolved; return yystate->yyresolved;
} }
void yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, static void
yyGLRState* yyrhs, yyRuleNum yyrule) yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
yyGLRState* yyrhs, yyRuleNum yyrule)
{ {
yySemanticOption* yynewItem; yySemanticOption* yynewItem;
yynewItem = &yystack->yynextFree->yyoption; yynewItem = &yystack->yynextFree->yyoption;
@@ -882,13 +907,13 @@ yyundeleteLastStack (yyGLRStack* yystack)
static inline void static inline void
yyremoveDeletes (yyGLRStack* yystack) yyremoveDeletes (yyGLRStack* yystack)
{ {
int yyi, yyj; size_t yyi, yyj;
yyi = yyj = 0; yyi = yyj = 0;
while (yyj < yystack->yytops.yysize) while (yyj < yystack->yytops.yysize)
{ {
if (yystack->yytops.yystates[yyi] == NULL) if (yystack->yytops.yystates[yyi] == NULL)
{ {
if (YYDEBUG && yyi == yyj) if (yyi == yyj)
YYDPRINTF ((stderr, "Removing dead stacks.\n")); YYDPRINTF ((stderr, "Removing dead stacks.\n"));
yystack->yytops.yysize -= 1; yystack->yytops.yysize -= 1;
} }
@@ -1022,9 +1047,10 @@ yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
* added to the options for the existing state's semantic value. * added to the options for the existing state's semantic value.
*/ */
static inline YYRESULTTAG static inline YYRESULTTAG
yyglrReduce (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, bool yyforceEval) yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
bool yyforceEval)
{ {
int yyposn = yystack->yytops.yystates[yyk]->yyposn; size_t yyposn = yystack->yytops.yystates[yyk]->yyposn;
if (yyforceEval || yystack->yysplitPoint == NULL) if (yyforceEval || yystack->yysplitPoint == NULL)
{ {
@@ -1041,7 +1067,8 @@ yyglrReduce (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, bool yyforceEval)
} }
else else
{ {
int yyi, yyn; size_t yyi;
int yyn;
yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk]; yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
yyStateNum yynewLRState; yyStateNum yynewLRState;
@@ -1153,23 +1180,23 @@ yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
* parsing state; return 0 if no combination is possible, * parsing state; return 0 if no combination is possible,
* 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
static int static int
yypreference (yySemanticOption* yyy0, yySemanticOption* yyy1) yypreference (yySemanticOption* y0, yySemanticOption* y1)
{ {
yyRuleNum yyr0 = yyy0->yyrule, yyr1 = yyy1->yyrule; yyRuleNum r0 = y0->yyrule, r1 = y1->yyrule;
int yyp0 = yydprec[yyr0], yyp1 = yydprec[yyr1]; int p0 = yydprec[r0], p1 = yydprec[r1];
if (yyp0 == yyp1) if (p0 == p1)
{ {
if (yymerger[yyr0] == 0 || yymerger[yyr0] != yymerger[yyr1]) if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1])
return 0; return 0;
else else
return 1; return 1;
} }
if (yyp0 == 0 || yyp1 == 0) if (p0 == 0 || p1 == 0)
return 0; return 0;
if (yyp0 < yyp1) if (p0 < p1)
return 3; return 3;
if (yyp0 > yyp1) if (p0 > p1)
return 2; return 2;
return 0; return 0;
} }
@@ -1269,6 +1296,10 @@ static void
yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
yyGLRStack* yystack) yyGLRStack* yystack)
{ {
/* `Unused' warnings. */
(void) yyx0;
(void) yyx1;
#if YYDEBUG #if YYDEBUG
YYFPRINTF (stderr, "Ambiguity detected.\n"); YYFPRINTF (stderr, "Ambiguity detected.\n");
YYFPRINTF (stderr, "Option 1,\n"); YYFPRINTF (stderr, "Option 1,\n");
@@ -1453,13 +1484,16 @@ yyprocessOneStack (yyGLRStack* yystack, int yyk,
static void static void
yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
{ {
yySymbol* const yytokenp = yystack->yytokenp; /* `Unused' warnings. */
(void) yylvalp;
(void) yyllocp;
if (yystack->yyerrState == 0) if (yystack->yyerrState == 0)
{ {
#if YYERROR_VERBOSE #if YYERROR_VERBOSE
yySymbol* const yytokenp = yystack->yytokenp;
int yyn, yyx, yycount, yysize; int yyn, yyx, yycount, yysize;
char* yyprefix; const char* yyprefix;
char* yyp; char* yyp;
char* yymsg; char* yymsg;
yyn = yypact[yystack->yytops.yystates[0]->yylrState]; yyn = yypact[yystack->yytops.yystates[0]->yylrState];
@@ -1510,7 +1544,8 @@ static void
yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
{ {
yySymbol* const yytokenp = yystack->yytokenp; yySymbol* const yytokenp = yystack->yytokenp;
int yyk, yyj; size_t yyk;
int yyj;
if (yystack->yyerrState == 0) if (yystack->yyerrState == 0)
yystack->yyerrState = 3; yystack->yyerrState = 3;
@@ -1717,11 +1752,14 @@ yyparse (YYPARSE_PARAM_ARG)
} }
/* DEBUGGING ONLY */ /* DEBUGGING ONLY */
static void yypstack (yyGLRStack* yystack, int yyk) ATTRIBUTE_UNUSED;
static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
void static void
yypstates (yyGLRState* yyst) yypstates (yyGLRState* yyst)
{ {
void yy_yypstack (yyGLRState* yys) static void
yy_yypstack (yyGLRState* yys)
{ {
if (yys->yypred == NULL) if (yys->yypred == NULL)
fprintf (stderr, "%d@%d", yys->yylrState, yys->yyposn); fprintf (stderr, "%d@%d", yys->yylrState, yys->yyposn);
@@ -1739,7 +1777,7 @@ yypstates (yyGLRState* yyst)
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }
void static void
yypstack (yyGLRStack* yystack, int yyk) yypstack (yyGLRStack* yystack, int yyk)
{ {
yypstates (yystack->yytops.yystates[yyk]); yypstates (yystack->yytops.yystates[yyk]);
@@ -1749,11 +1787,11 @@ yypstack (yyGLRStack* yystack, int yyk)
((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems) ((YYX) == NULL ? -1 : (yyGLRStackItem*) (YYX) - yystack->yyitems)
void static void
yypdumpstack (yyGLRStack* yystack) yypdumpstack (yyGLRStack* yystack)
{ {
yyGLRStackItem* yyp; yyGLRStackItem* yyp;
int yyi; size_t yyi;
for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1) for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
{ {
fprintf (stderr, "%3d. ", yyp - yystack->yyitems); fprintf (stderr, "%3d. ", yyp - yystack->yyitems);

View File

@@ -73,8 +73,8 @@ main (void)
]]) ]])
AT_CHECK([bison input.y -d -v -o input.c]) AT_CHECK([bison input.y -d -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input], 0, AT_PARSER_CHECK([./input], 0,
[[0123456789 [[0123456789
]]) ]])
@@ -144,8 +144,8 @@ main (void)
]]) ]])
AT_CHECK([bison input.y -d -v -o input.c]) AT_CHECK([bison input.y -d -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input], 0, AT_PARSER_CHECK([./input], 0,
[[15 [[15
]]) ]])
@@ -296,8 +296,8 @@ main (void)
]]) ]])
AT_CHECK([bison input.y --location -d -v -o input.c]) AT_CHECK([bison input.y --location -d -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input], 1, AT_PARSER_CHECK([./input], 1,
[[sending: 'x' (value = 0, line 0) [[sending: 'x' (value = 0, line 0)
thing(0): 'x'(0) thing(0): 'x'(0)
sending: 'x' (value = 1, line 10) sending: 'x' (value = 1, line 10)

View File

@@ -290,7 +290,7 @@ m4_define([_AT_CHECK_CALC],
[AT_DATA([[input]], [AT_DATA([[input]],
[[$2 [[$2
]]) ]])
AT_CHECK([./calc input], 0, [], [stderr])dnl AT_PARSER_CHECK([./calc input], 0, [], [stderr])dnl
AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0,
[m4_bmatch([$1], [--debug], [m4_bmatch([$1], [--debug],
[$3], [0]) [$3], [0])
@@ -317,11 +317,11 @@ AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0,
# of expected lines on stderr. # of expected lines on stderr.
m4_define([_AT_CHECK_CALC_ERROR], m4_define([_AT_CHECK_CALC_ERROR],
[m4_bmatch([$2], [^/], [m4_bmatch([$2], [^/],
[AT_CHECK([./calc $2], 0, [], [stderr])], [AT_PARSER_CHECK([./calc $2], 0, [], [stderr])],
[AT_DATA([[input]], [AT_DATA([[input]],
[[$2 [[$2
]]) ]])
AT_CHECK([./calc input], 0, [], [stderr])]) AT_PARSER_CHECK([./calc input], 0, [], [stderr])])
m4_bmatch([$1], [--debug], m4_bmatch([$1], [--debug],
[AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3 [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3
@@ -372,7 +372,7 @@ AT_DATA_CALC_Y([$1])
AT_CHECK([bison calc.y -o calc.c m4_bpatsubst([$1], [--yyerror-verbose])], AT_CHECK([bison calc.y -o calc.c m4_bpatsubst([$1], [--yyerror-verbose])],
[0], [], []) [0], [], [])
AT_CHECK([$CC $CFLAGS $CPPFLAGS calc.c -o calc], 0, [], [ignore]) AT_COMPILE([calc])
# Test the priorities. # Test the priorities.
_AT_CHECK_CALC([$1], _AT_CHECK_CALC([$1],

View File

@@ -102,22 +102,22 @@ main (int argc, const char *argv[])
# Specify the output files to avoid problems on different file systems. # Specify the output files to avoid problems on different file systems.
AT_CHECK([bison input.y -o input.c]) AT_CHECK([bison input.y -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input '0<0']) AT_PARSER_CHECK([./input '0<0'])
# FIXME: This is an actual bug, but a new one, in the sense that # FIXME: This is an actual bug, but a new one, in the sense that
# no one has ever spotted it! The messages are *wrong*: there should # no one has ever spotted it! The messages are *wrong*: there should
# be nothing there, it should be expected eof. # be nothing there, it should be expected eof.
AT_CHECK([./input '0<0<0'], [1], [], AT_PARSER_CHECK([./input '0<0<0'], [1], [],
[parse error, unexpected '<', expecting '<' or '>' [parse error, unexpected '<', expecting '<' or '>'
]) ])
AT_CHECK([./input '0>0']) AT_PARSER_CHECK([./input '0>0'])
AT_CHECK([./input '0>0>0'], [1], [], AT_PARSER_CHECK([./input '0>0>0'], [1], [],
[parse error, unexpected '>', expecting '<' or '>' [parse error, unexpected '>', expecting '<' or '>'
]) ])
AT_CHECK([./input '0<0>0'], [1], [], AT_PARSER_CHECK([./input '0<0>0'], [1], [],
[parse error, unexpected '>', expecting '<' or '>' [parse error, unexpected '>', expecting '<' or '>'
]) ])

View File

@@ -1,5 +1,5 @@
# Checking the output filenames. -*- Autotest -*- # Checking GLR Parsing. -*- Autotest -*-
# Copyright 2000, 2001 Free Software Foundation, Inc. # Copyright 2002 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -18,22 +18,34 @@
AT_BANNER([[C++ Type Syntax (GLR).]]) AT_BANNER([[C++ Type Syntax (GLR).]])
# _AT_TEST_GLR_CALC(`$1',DECL, RESOLVE1, RESOLVE2) # _AT_TEST_GLR_CALC(DECL, RESOLVE1, RESOLVE2)
# (first argument is a literal $1; it's a trick). # -------------------------------------------
# Store into types.y the calc program, with DECL inserted as a declaration, # Store into types.y the calc program, with DECL inserted as a declaration,
# and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for # and with RESOLVE1 and RESOLVE2 as annotations on the conflicted rule for
# stmt. Then compile the result. # stmt. Then compile the result.
m4_define([_AT_TEST_GLR_CALC], m4_define([_AT_TEST_GLR_CALC],
[AT_DATA([types.y], [AT_DATA([types.y],
[[/* Simplified C++ Type and Expression Grammar */ [[/* Simplified C++ Type and Expression Grammar. */
$2 $1
%{ %{
#include <stdio.h> #include <stdio.h>
#define YYSTYPE const char* #define YYSTYPE const char*
static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1); #define YYLTYPE int
]m4_bmatch([$2], [stmtMerge],
[ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
#define YYINITDEPTH 10 #define YYINITDEPTH 10
int yyerror (const char *s);
#if YYPURE
]m4_bmatch([$1], [location],
[ int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);],
[ int yylex (YYSTYPE *lvalp);])[
#else
int yylex (void);
#endif
%} %}
%token TYPENAME ID %token TYPENAME ID
@@ -45,53 +57,65 @@ $2
%% %%
prog : prog :
| prog stmt { printf ("\n"); } | prog stmt { printf ("\n"); }
; ;
stmt : expr ';' $3 stmt : expr ';' $2
| decl $4 | decl $3
| error ';' | error ';'
| '@' { YYACCEPT; } | '@' { YYACCEPT; }
; ;
expr : ID { printf ("%s ", $$); } expr : ID { printf ("%s ", $$); }
| TYPENAME '(' expr ')' | TYPENAME '(' expr ')'
{ printf ("%s <cast> ", $1); } { printf ("%s <cast> ", ]$[1); }
| expr '+' expr { printf ("+ "); } | expr '+' expr { printf ("+ "); }
| expr '=' expr { printf ("= "); } | expr '=' expr { printf ("= "); }
; ;
decl : TYPENAME declarator ';' decl : TYPENAME declarator ';'
{ printf ("%s <declare> ", $1); } { printf ("%s <declare> ", ]$[1); }
| TYPENAME declarator '=' expr ';' | TYPENAME declarator '=' expr ';'
{ printf ("%s <init-declare> ", $1); } { printf ("%s <init-declare> ", ]$[1); }
; ;
declarator : ID { printf ("\"%s\" ", $1); } declarator : ID { printf ("\"%s\" ", ]$[1); }
| '(' declarator ')' | '(' declarator ')'
; ;
%% %%
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <strings.h> #include <string.h>
main (int argc, char** argv) int
main (int argc, char** argv)
{ {
freopen (argv[1], "r", stdin); assert (argc = 2);
assert (freopen (argv[1], "r", stdin));
exit (yyparse ()); exit (yyparse ());
} }
#if YYPURE #if YYPURE
int yylex (YYSTYPE *lvalp) int
#define yylval (*lvalp) ]m4_bmatch([$1], [location],
[yylex (YYSTYPE *lvalp, YYLTYPE *llocp)],
[yylex (YYSTYPE *lvalp)])[
#else #else
int yylex () int
yylex ()
#endif #endif
{ {
char buffer[256]; char buffer[256];
int c; int c;
#if YYPURE
# define yylval (*lvalp)
]m4_bmatch([$1], [location],[ (void) llocp;])[
#endif
while (1) { while (1) {
c = getchar (); c = getchar ();
switch (c) { switch (c) {
@@ -118,12 +142,19 @@ yyerror (const char *s)
return 0; return 0;
} }
static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1) ]]
m4_bmatch([$2], [stmtMerge],
[[static YYSTYPE
stmtMerge (YYSTYPE x0, YYSTYPE x1)
{ {
/* Use the arguments. */
(void) x0;
(void) x1;
printf ("<OR> "); printf ("<OR> ");
return ""; return "";
} }
]]) ]])
)
AT_DATA([test-input], AT_DATA([test-input],
[[ [[
@@ -151,8 +182,8 @@ z + q;
This is total garbage, but it should be ignored. This is total garbage, but it should be ignored.
]]) ]])
AT_CHECK([bison types.y], 0, [], ignore) AT_CHECK([bison types.y -o types.c], 0, [], ignore)
AT_CHECK([gcc -o types types.tab.c], 0, [], ignore) AT_COMPILE([types])
]) ])
m4_define([_AT_RESOLVED_GLR_OUTPUT], m4_define([_AT_RESOLVED_GLR_OUTPUT],
@@ -168,22 +199,22 @@ z q +
]]) ]])
m4_define([_AT_AMBIG_GLR_OUTPUT], m4_define([_AT_AMBIG_GLR_OUTPUT],
[[z q + [[z q +
"x" T <declare> "x" T <declare>
"x" y T <init-declare> "x" y T <init-declare>
x y = x y =
x T <cast> y + x T <cast> y +
"x" T <declare> x T <cast> <OR> "x" T <declare> x T <cast> <OR>
"y" z q + T <init-declare> y T <cast> z q + = <OR> "y" z q + T <init-declare> y T <cast> z q + = <OR>
y y
z q + z q +
]]) ]])
m4_define([_AT_GLR_STDERR], m4_define([_AT_GLR_STDERR],
[[parse error [[parse error
]]) ]])
m4_define([_AT_VERBOSE_GLR_STDERR], m4_define([_AT_VERBOSE_GLR_STDERR],
[[parse error, unexpected ID, expecting '=' or '+' or ')' [[parse error, unexpected ID, expecting '=' or '+' or ')'
]]) ]])
@@ -192,57 +223,63 @@ m4_define([_AT_VERBOSE_GLR_STDERR],
## ---------------------------------------------------- ## ## ---------------------------------------------------- ##
AT_SETUP([GLR: Resolve ambiguity, impure, no locations]) AT_SETUP([GLR: Resolve ambiguity, impure, no locations])
_AT_TEST_GLR_CALC([$1],[],[%dprec 1],[%dprec 2]) _AT_TEST_GLR_CALC([],[%dprec 1],[%dprec 2])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
_AT_GLR_STDERR) _AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Resolve ambiguity, impure, locations]) AT_SETUP([GLR: Resolve ambiguity, impure, locations])
_AT_TEST_GLR_CALC([$1],[%locations],[%dprec 1],[%dprec 2]) _AT_TEST_GLR_CALC([%locations],[%dprec 1],[%dprec 2])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
_AT_GLR_STDERR) _AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Resolve ambiguity, pure, no locations]) AT_SETUP([GLR: Resolve ambiguity, pure, no locations])
_AT_TEST_GLR_CALC([$1],[%pure-parser],[%dprec 1],[%dprec 2]) _AT_TEST_GLR_CALC([%pure-parser],[%dprec 1],[%dprec 2])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT,
_AT_GLR_STDERR) _AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Resolve ambiguity, pure, locations]) AT_SETUP([GLR: Resolve ambiguity, pure, locations])
_AT_TEST_GLR_CALC([$1],[%pure-parser _AT_TEST_GLR_CALC([%pure-parser
%locations],[%dprec 1],[%dprec 2]) %locations],[%dprec 1],[%dprec 2])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_RESOLVED_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
_AT_GLR_STDERR) _AT_RESOLVED_GLR_OUTPUT,
_AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Merge conflicting parses, impure, no locations]) AT_SETUP([GLR: Merge conflicting parses, impure, no locations])
_AT_TEST_GLR_CALC([$1],[],[%merge <stmtMerge>],[%merge <stmtMerge>]) _AT_TEST_GLR_CALC([],[%merge <stmtMerge>],[%merge <stmtMerge>])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
_AT_GLR_STDERR) _AT_AMBIG_GLR_OUTPUT,
_AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Merge conflicting parses, impure, locations]) AT_SETUP([GLR: Merge conflicting parses, impure, locations])
_AT_TEST_GLR_CALC([$1],[%locations],[%merge <stmtMerge>],[%merge <stmtMerge>]) _AT_TEST_GLR_CALC([%locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
_AT_GLR_STDERR) _AT_AMBIG_GLR_OUTPUT,
_AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Merge conflicting parses, pure, no locations]) AT_SETUP([GLR: Merge conflicting parses, pure, no locations])
_AT_TEST_GLR_CALC([$1],[%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>]) _AT_TEST_GLR_CALC([%pure-parser],[%merge <stmtMerge>],[%merge <stmtMerge>])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
_AT_GLR_STDERR) _AT_AMBIG_GLR_OUTPUT,
_AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Merge conflicting parses, pure, locations]) AT_SETUP([GLR: Merge conflicting parses, pure, locations])
_AT_TEST_GLR_CALC([$1],[%pure-parser _AT_TEST_GLR_CALC([%pure-parser
%locations],[%merge <stmtMerge>],[%merge <stmtMerge>]) %locations],[%merge <stmtMerge>],[%merge <stmtMerge>])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, _AT_AMBIG_GLR_OUTPUT, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
_AT_GLR_STDERR) _AT_AMBIG_GLR_OUTPUT,
_AT_GLR_STDERR)
AT_CLEANUP AT_CLEANUP
AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations]) AT_SETUP([GLR: Verbose messages, resolve ambiguity, impure, no locations])
_AT_TEST_GLR_CALC([$1],[%error-verbose], _AT_TEST_GLR_CALC([%error-verbose],
[%merge <stmtMerge>],[%merge <stmtMerge>]) [%merge <stmtMerge>],[%merge <stmtMerge>])
AT_CHECK([[./types test-input | sed 's/ *$//']], 0, AT_PARSER_CHECK([[./types test-input | sed 's/ *$//']], 0,
_AT_AMBIG_GLR_OUTPUT, _AT_VERBOSE_GLR_STDERR) _AT_AMBIG_GLR_OUTPUT,
_AT_VERBOSE_GLR_STDERR)
AT_CLEANUP AT_CLEANUP

View File

@@ -123,7 +123,7 @@ main (void)
# Link and execute, just to make sure everything is fine (and in # Link and execute, just to make sure everything is fine (and in
# particular, that MY_LLOC is indeed defined somewhere). # particular, that MY_LLOC is indeed defined somewhere).
AT_CHECK([$CC $CFLAGS $CPPFLAGS caller.c input.c -o caller], 0, [], [ignore]) AT_COMPILE([caller], [caller.c input.c])
AT_CHECK([./caller]) AT_PARSER_CHECK([./caller])
AT_CLEANUP AT_CLEANUP

View File

@@ -182,8 +182,8 @@ main (void)
]]) ]])
AT_CHECK([bison input.y -d -v -o input.c]) AT_CHECK([bison input.y -d -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS main.c input.c -o input], 0, [], [ignore]) AT_COMPILE([input], [input.c main.c])
AT_CHECK([./input], 0, AT_PARSER_CHECK([./input], 0,
[[[1], [[[1],
]]) ]])

View File

@@ -51,7 +51,7 @@ exp: MY_TOKEN;
]]) ]])
AT_CHECK([bison input.y -o input.c]) AT_CHECK([bison input.y -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c]) AT_COMPILE([input], [-c input.c])
AT_CLEANUP AT_CLEANUP
@@ -329,7 +329,7 @@ exp: "a";
]]) ]])
AT_CHECK([bison input.y -o input.c]) AT_CHECK([bison input.y -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c]) AT_COMPILE([input], [input.c -c])
AT_CLEANUP AT_CLEANUP

View File

@@ -21,6 +21,21 @@
# We need a recent Autotest. # We need a recent Autotest.
m4_version_prereq([2.52g]) m4_version_prereq([2.52g])
# AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c])
# ----------------------------------------
#
m4_define([AT_COMPILE],
[AT_CHECK([$CC $CFLAGS $CPPFLAGS m4_default([$2], [$1.c]) -o $1], 0,
[], [ignore])])
# AT_PARSER_CHECK(COMMAND, EXIT-STATUS, EXPOUT, EXPERR)
# -----------------------------------------------------
# So that we can run `./testsuite PREPARSER='valgrind -q' for instance.
m4_define([AT_PARSER_CHECK],
[AT_CHECK([$PREPARSER $1], [$2], [$3], [$4])])
AT_INIT AT_INIT
AT_TESTED([bison]) AT_TESTED([bison])

View File

@@ -132,8 +132,8 @@ AT_SETUP([Big triangle])
# it gets killed too. Of course the parser is to be cleaned. # it gets killed too. Of course the parser is to be cleaned.
AT_DATA_TRIANGULAR_GRAMMAR([input.y], [200]) AT_DATA_TRIANGULAR_GRAMMAR([input.y], [200])
AT_CHECK([bison input.y -v -o input.c]) AT_CHECK([bison input.y -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input]) AT_PARSER_CHECK([./input])
AT_CLEANUP AT_CLEANUP
@@ -231,8 +231,8 @@ AT_SETUP([Big horizontal])
# #
AT_DATA_HORIZONTAL_GRAMMAR([input.y], [1000]) AT_DATA_HORIZONTAL_GRAMMAR([input.y], [1000])
AT_CHECK([bison input.y -v -o input.c]) AT_CHECK([bison input.y -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input]) AT_PARSER_CHECK([./input])
AT_CLEANUP AT_CLEANUP
@@ -350,8 +350,8 @@ AT_SETUP([Many lookaheads])
AT_DATA_LOOKAHEADS_GRAMMAR([input.y], [1000]) AT_DATA_LOOKAHEADS_GRAMMAR([input.y], [1000])
AT_CHECK([bison input.y -v -o input.c]) AT_CHECK([bison input.y -v -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
AT_CHECK([./input]) AT_PARSER_CHECK([./input])
AT_CLEANUP AT_CLEANUP
@@ -407,7 +407,7 @@ main (int argc, const char **argv)
} }
]]) ]])
AT_CHECK([bison input.y -o input.c]) AT_CHECK([bison input.y -o input.c])
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) AT_COMPILE([input])
]) ])
@@ -420,12 +420,12 @@ AT_SETUP([Exploding the Stack Size with Alloca])
AT_DATA_STACK_TORTURE AT_DATA_STACK_TORTURE
# Below the limit of 200. # Below the limit of 200.
AT_CHECK([./input 20], 0, [], [ignore]) AT_PARSER_CHECK([./input 20], 0, [], [ignore])
# Two enlargements: 2 * 2 * 200. # Two enlargements: 2 * 2 * 200.
AT_CHECK([./input 900], 0, [], [ignore]) AT_PARSER_CHECK([./input 900], 0, [], [ignore])
# Fails: beyond the limit of 10,000 (which we don't reach anyway since we # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
# multiply by two starting at 200 => 5120 is the last possible). # multiply by two starting at 200 => 5120 is the last possible).
AT_CHECK([./input 10000], 1, [], [ignore]) AT_PARSER_CHECK([./input 10000], 1, [], [ignore])
AT_CLEANUP AT_CLEANUP
@@ -441,11 +441,11 @@ AT_SETUP([Exploding the Stack Size with Malloc])
AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]]) AT_DATA_STACK_TORTURE([[#define YYSTACK_USE_ALLOCA 0]])
# Below the limit of 200. # Below the limit of 200.
AT_CHECK([./input 20], 0, [], [ignore]) AT_PARSER_CHECK([./input 20], 0, [], [ignore])
# Two enlargements: 2 * 2 * 200. # Two enlargements: 2 * 2 * 200.
AT_CHECK([./input 900], 0, [], [ignore]) AT_PARSER_CHECK([./input 900], 0, [], [ignore])
# Fails: beyond the limit of 10,000 (which we don't reach anyway since we # Fails: beyond the limit of 10,000 (which we don't reach anyway since we
# multiply by two starting at 200 => 5120 is the possible). # multiply by two starting at 200 => 5120 is the possible).
AT_CHECK([./input 10000], 1, [], [ignore]) AT_PARSER_CHECK([./input 10000], 1, [], [ignore])
AT_CLEANUP AT_CLEANUP