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