]> git.saurik.com Git - bison.git/blame - tests/push.at
Convert underscores to dashes in some %define variable names.
[bison.git] / tests / push.at
CommitLineData
eb1b0740 1# Checking Push Parsing. -*- Autotest -*-
812775a0 2# Copyright (C) 2007, 2009 Free Software Foundation, Inc.
eb1b0740 3
f16b0819 4# This program is free software: you can redistribute it and/or modify
eb1b0740 5# it under the terms of the GNU General Public License as published by
f16b0819
PE
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
eb1b0740
JD
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
f16b0819 13#
eb1b0740 14# You should have received a copy of the GNU General Public License
f16b0819 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
eb1b0740
JD
16
17AT_BANNER([[Push Parsing Tests]])
18
19## ---------------------------------------------- ##
20## Push Parsing: Memory Leak for Early Deletion. ##
21## ---------------------------------------------- ##
22
23AT_SETUP([[Push Parsing: Memory Leak for Early Deletion]])
24
25# Requires Valgrind.
26
27AT_DATA_GRAMMAR([[input.y]],
28[[
29%{
30 #include <assert.h>
31 #include <stdio.h>
32 #define YYINITDEPTH 1
33 void yyerror (char const *msg);
34%}
35
812775a0 36%define api.pure %define api.push-pull "push"
eb1b0740
JD
37
38%%
39
40start: 'a' 'b' 'c' ;
41
42%%
43
44void
45yyerror (char const *msg)
46{
47 fprintf (stderr, "%s\n", msg);
48}
49
50int
51main (void)
52{
5d31a216
JD
53 yypstate *ps;
54
55 /* Make sure we don't try to free ps->yyss in this case. */
56 ps = yypstate_new ();
57 yypstate_delete (ps);
58
59 /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
60 parse did not return on success, syntax error, or memory exhaustion. */
61 ps = yypstate_new ();
62 assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
63 yypstate_delete (ps);
64
65 ps = yypstate_new ();
66 assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
67 assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE);
68 yypstate_delete (ps);
eb1b0740
JD
69
70 return 0;
71}
72]])
73
da730230 74AT_BISON_CHECK([[-o input.c input.y]])
eb1b0740
JD
75AT_COMPILE([[input]])
76AT_PARSER_CHECK([[./input]])
77
78AT_CLEANUP
1b17b01d 79
1b17b01d
JD
80## ----------------------------------------- ##
81## Push Parsing: Multiple impure instances. ##
82## ----------------------------------------- ##
83
84AT_SETUP([[Push Parsing: Multiple impure instances]])
85
333e670c 86m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [
1b17b01d
JD
87AT_DATA_GRAMMAR([[input.y]],
88[[
89%{
90 #include <assert.h>
91 #include <stdio.h>
92 void yyerror (char const *msg);
93 int yylex (void);
94%}
95
812775a0 96%define api.push-pull "]$1["
1b17b01d
JD
97
98%%
99
100start: ;
101
102%%
103
104void
105yyerror (char const *msg)
106{
107 fprintf (stderr, "%s\n", msg);
108}
109
110int
111yylex (void)
112{
113 return 0;
114}
115
116int
117main (void)
118{
119 yypstate *ps;
120 int i;
121
122 for (i = 0; i < 2; ++i)
123 {
124 ps = yypstate_new ();
125 assert (ps);
126 assert (yypstate_new () == NULL);
333e670c 127 ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
1b17b01d
JD
128 yychar = 0;
129 assert (yypush_parse (ps) == 0);
130 assert (yypstate_new () == NULL);
333e670c 131 ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[;
1b17b01d
JD
132 yypstate_delete (ps);
133 }
134
135 return 0;
136}
137]])
138
da730230 139AT_BISON_CHECK([[-o input.c input.y]])
1b17b01d 140AT_COMPILE([[input]])
333e670c
JD
141AT_PARSER_CHECK([[./input]])
142])
143
144AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]])
145AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[push]])
146
147m4_popdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK])
1b17b01d
JD
148
149AT_CLEANUP
d782395d
JD
150
151## ------------------------------------- ##
152## Push Parsing: Unsupported Skeletons. ##
153## ------------------------------------- ##
154
155AT_SETUP([[Push Parsing: Unsupported Skeletons]])
156
157AT_DATA([[input.y]],
158[[%glr-parser
812775a0 159%define api.push-pull "push"
d782395d
JD
160%%
161start: ;
162]])
163
da730230 164AT_BISON_CHECK([[input.y]], [0], [],
812775a0 165[[input.y:2.9-21: warning: %define variable `api.push-pull' is not used
d782395d
JD
166]])
167
168AT_CLEANUP