]>
Commit | Line | Data |
---|---|---|
eb1b0740 JD |
1 | # Checking Push Parsing. -*- Autotest -*- |
2 | # Copyright (C) 2007 Free Software Foundation, Inc. | |
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 | |
17 | AT_BANNER([[Push Parsing Tests]]) | |
18 | ||
19 | ## ---------------------------------------------- ## | |
20 | ## Push Parsing: Memory Leak for Early Deletion. ## | |
21 | ## ---------------------------------------------- ## | |
22 | ||
23 | AT_SETUP([[Push Parsing: Memory Leak for Early Deletion]]) | |
24 | ||
25 | # Requires Valgrind. | |
26 | ||
27 | AT_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 | ||
d9df47b6 | 36 | %define api.pure %define api.push_pull "push" |
eb1b0740 JD |
37 | |
38 | %% | |
39 | ||
40 | start: 'a' 'b' 'c' ; | |
41 | ||
42 | %% | |
43 | ||
44 | void | |
45 | yyerror (char const *msg) | |
46 | { | |
47 | fprintf (stderr, "%s\n", msg); | |
48 | } | |
49 | ||
50 | int | |
51 | main (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 | 74 | AT_BISON_CHECK([[-o input.c input.y]]) |
eb1b0740 JD |
75 | AT_COMPILE([[input]]) |
76 | AT_PARSER_CHECK([[./input]]) | |
77 | ||
78 | AT_CLEANUP | |
1b17b01d | 79 | |
1b17b01d JD |
80 | ## ----------------------------------------- ## |
81 | ## Push Parsing: Multiple impure instances. ## | |
82 | ## ----------------------------------------- ## | |
83 | ||
84 | AT_SETUP([[Push Parsing: Multiple impure instances]]) | |
85 | ||
86 | AT_DATA_GRAMMAR([[input.y]], | |
87 | [[ | |
88 | %{ | |
89 | #include <assert.h> | |
90 | #include <stdio.h> | |
91 | void yyerror (char const *msg); | |
92 | int yylex (void); | |
93 | %} | |
94 | ||
c373bf8b | 95 | %define api.push_pull "both" |
1b17b01d JD |
96 | |
97 | %% | |
98 | ||
99 | start: ; | |
100 | ||
101 | %% | |
102 | ||
103 | void | |
104 | yyerror (char const *msg) | |
105 | { | |
106 | fprintf (stderr, "%s\n", msg); | |
107 | } | |
108 | ||
109 | int | |
110 | yylex (void) | |
111 | { | |
112 | return 0; | |
113 | } | |
114 | ||
115 | int | |
116 | main (void) | |
117 | { | |
118 | yypstate *ps; | |
119 | int i; | |
120 | ||
121 | for (i = 0; i < 2; ++i) | |
122 | { | |
123 | ps = yypstate_new (); | |
124 | assert (ps); | |
125 | assert (yypstate_new () == NULL); | |
126 | assert (yyparse () == 2); | |
127 | yychar = 0; | |
128 | assert (yypush_parse (ps) == 0); | |
129 | assert (yypstate_new () == NULL); | |
130 | assert (yyparse () == 2); | |
131 | yypstate_delete (ps); | |
132 | } | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ]]) | |
137 | ||
da730230 | 138 | AT_BISON_CHECK([[-o input.c input.y]]) |
1b17b01d JD |
139 | AT_COMPILE([[input]]) |
140 | AT_PARSER_CHECK([[./input]], 0, [], | |
141 | [[cannot allocate multiple impure push-parser instances | |
142 | cannot allocate multiple impure push-parser instances | |
143 | cannot allocate multiple impure push-parser instances | |
144 | cannot allocate multiple impure push-parser instances | |
145 | cannot allocate multiple impure push-parser instances | |
146 | cannot allocate multiple impure push-parser instances | |
147 | cannot allocate multiple impure push-parser instances | |
148 | cannot allocate multiple impure push-parser instances | |
149 | ]]) | |
150 | ||
151 | AT_CLEANUP | |
d782395d JD |
152 | |
153 | ## ------------------------------------- ## | |
154 | ## Push Parsing: Unsupported Skeletons. ## | |
155 | ## ------------------------------------- ## | |
156 | ||
157 | AT_SETUP([[Push Parsing: Unsupported Skeletons]]) | |
158 | ||
159 | AT_DATA([[input.y]], | |
160 | [[%glr-parser | |
c373bf8b | 161 | %define api.push_pull "push" |
d782395d JD |
162 | %% |
163 | start: ; | |
164 | ]]) | |
165 | ||
da730230 | 166 | AT_BISON_CHECK([[input.y]], [0], [], |
c373bf8b | 167 | [[input.y:2.9-21: warning: %define variable `api.push_pull' is not used |
d782395d JD |
168 | ]]) |
169 | ||
170 | AT_CLEANUP |