]>
Commit | Line | Data |
---|---|---|
642cb8f8 | 1 | # Executing Actions. -*- Autotest -*- |
6e30ede8 | 2 | |
3209eb1c | 3 | # Copyright (C) 2002, 2004-2005, 2007, 2009-2015 Free Software |
1462fcee | 4 | # Foundation, Inc. |
642cb8f8 | 5 | |
f16b0819 | 6 | # This program is free software: you can redistribute it and/or modify |
642cb8f8 | 7 | # it under the terms of the GNU General Public License as published by |
f16b0819 PE |
8 | # the Free Software Foundation, either version 3 of the License, or |
9 | # (at your option) any later version. | |
10 | # | |
642cb8f8 AD |
11 | # This program is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
f16b0819 | 15 | # |
642cb8f8 | 16 | # You should have received a copy of the GNU General Public License |
f16b0819 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
642cb8f8 AD |
18 | |
19 | AT_BANNER([[User Actions.]]) | |
20 | ||
865b9df1 | 21 | |
0b0370ff AD |
22 | # _AT_SYNCLINES_COMPILE(FILE) |
23 | # --------------------------- | |
4e8d992c AD |
24 | # Compile FILE expecting an error, and save in the file stdout the |
25 | # normalized output. Ignore the exit status, since some compilers | |
4c9b8f13 | 26 | # (e.g. c89 on IRIX 6.5) trigger warnings on '#error', instead of |
4e8d992c | 27 | # errors. |
0b0370ff | 28 | m4_define([_AT_SYNCLINES_COMPILE], |
f32b346d | 29 | [AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr]) |
0bb672d8 AD |
30 | |
31 | # Transform stderr into something like this: | |
32 | # | |
33 | # input.y:4: #error "4" | |
34 | # | |
865b9df1 AD |
35 | # In case GCC displays column information, strip it down. |
36 | # | |
4d1801f1 PE |
37 | # input.y:4:2: #error "4" or |
38 | # input.y:4.2: #error "4" or | |
39 | # input.y:4:2: error: #error "4" | |
865b9df1 AD |
40 | # => |
41 | # input.y:4: #error "4" | |
42 | # | |
bdc360ae AD |
43 | # It may also issue more context information: |
44 | # | |
45 | # input.y: In function 'yyparse': | |
46 | # input.y:8: #error "8" | |
47 | # => | |
48 | # input.y:4: #error "8" | |
49 | # | |
2cf5f72e AD |
50 | # The message may include a caret-error (indented by GCC 4.8, |
51 | # not by clang 3.2): | |
0bb672d8 AD |
52 | # |
53 | # input.y:1:2: error: #error "1" | |
54 | # #error "1" | |
55 | # ^ | |
bdc360ae | 56 | # |
d4dcde2b | 57 | # Possibly distcc adds its bits. |
bdc360ae AD |
58 | # |
59 | # distcc[33187] ERROR: compile (null) on localhost failed | |
60 | # syncline.c:1:2: error: #error "1" | |
61 | # distcc[33185] ERROR: compile syncline.c on localhost failed | |
62 | # | |
63 | # or even | |
64 | # | |
65 | # distcc[35882] (dcc_connect_by_name) ERROR: failed to look up host "chrisimac": Unknown host | |
66 | # distcc[35882] Warning: failed to distribute input.c to chrisimac/4, running locally instead | |
2cf5f72e AD |
67 | # |
68 | # The compiler might end by the number of messages issued (Clang 3.2): | |
69 | # | |
70 | # syncline.c:1:2: error: "1" | |
71 | # #error "1" | |
72 | # ^ | |
73 | # 1 error generated. | |
d4dcde2b AD |
74 | # |
75 | # When c++ is used to compiler C, we might have more messages (Clang 3.2): | |
76 | # | |
77 | # clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated | |
0b0370ff AD |
78 | # |
79 | # | |
80 | # xlc reports things like: | |
81 | # | |
82 | # "input.yy", line 80.21: 1540-0218 (S) The call does not match any parameter list for "operator<<". | |
83 | # "/usr/vacpp/include/iosfwd", line 32.6: 1506-205 (S) #error This file to be used only with IBM VisualAge C++ v4 and later compilers | |
d4dcde2b | 84 | |
ff020c30 | 85 | AT_CHECK([[$PERL -p -0777 - stderr <<\EOF |
2cf5f72e AD |
86 | # 1. Remove useless lines. |
87 | ||
88 | # distcc clutter. | |
1914a781 | 89 | s/^distcc\[\d+\] .*\n//gm; |
d4dcde2b AD |
90 | # c vs. c++. |
91 | s/^clang: warning: treating 'c' input as 'c\+\+'.*\n//gm; | |
2cf5f72e | 92 | # Function context. |
1914a781 | 93 | s/^[^:]*: In function '[^']+':\n//gm; |
2cf5f72e AD |
94 | # Caret error. |
95 | s/^ *#error.*\n *\^\n//gm; | |
96 | # Number of errors. | |
97 | s/^1 error generated\.\n//gm; | |
98 | ||
99 | # 2. Normalize the lines we kept. | |
100 | ||
0b0370ff AD |
101 | # xlc messages. Remove also error identifier (e.g., "1540-0218 (S)"). |
102 | s/^"(.*?)", line ([\w.]*): \d+-\d+ \(.\) /$][1:$][2: /gm; | |
2cf5f72e AD |
103 | # Remove column. |
104 | s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm; | |
105 | # Map all combinations of "error: " and "#error: " to "#error ". | |
106 | s/^([^:]+:\d+):( |#error|error|:)+/$][1: #error /gm; | |
0bb672d8 AD |
107 | EOF |
108 | ]], | |
1914a781 | 109 | 0, [stdout]) |
865b9df1 AD |
110 | ]) |
111 | ||
0b0370ff AD |
112 | |
113 | ||
114 | # AT_SYNCLINES_COMPILE(FILE) | |
115 | # -------------------------- | |
116 | # Compile FILE expecting an error, and save in the file stdout the | |
117 | # normalized output. If we can't get a trustable location | |
118 | # from the compiler, just skip the test. | |
119 | # | |
865b9df1 AD |
120 | # It seems impossible to find a generic scheme to check the location |
121 | # of an error. Even requiring GCC is not sufficient, since for instance | |
122 | # the version modified by Apple: | |
123 | # | |
124 | # | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs | |
125 | # | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2 | |
126 | # | 19991024 (release) configure:2124: $? = 0 | |
127 | # | |
128 | # instead of: | |
129 | # | |
130 | # | input.y:2: #error "2" | |
131 | # | |
132 | # it reports: | |
133 | # | |
134 | # | input.y:2: "2" | |
135 | # | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode | |
0b0370ff AD |
136 | m4_define([AT_SYNCLINES_COMPILE], |
137 | [# Check if we can trust location translation. | |
865b9df1 | 138 | AT_DATA([syncline.c], |
a668f486 AD |
139 | [[static void foo(void) |
140 | { | |
141 | #error "3" | |
142 | } | |
865b9df1 | 143 | ]]) |
642cb8f8 | 144 | |
0b0370ff | 145 | _AT_SYNCLINES_COMPILE([syncline.c]) |
a668f486 | 146 | AT_CHECK([[test "`cat stdout`" = 'syncline.c:3: @%:@error "3"' || exit 77]]) |
865b9df1 | 147 | |
0b0370ff AD |
148 | # Then work for real. |
149 | _AT_SYNCLINES_COMPILE([$1]) | |
150 | ]) | |
151 | ||
152 | ||
153 | # AT_TEST(TITLE, INPUT, ERROR-MSG) | |
154 | # -------------------------------- | |
155 | # Check that compiling the parser produced from INPUT cause GCC | |
156 | # to issue ERROR-MSG. | |
157 | m4_pushdef([AT_TEST], | |
158 | [AT_SETUP([$1]) | |
159 | AT_BISON_OPTION_PUSHDEFS | |
160 | ||
865b9df1 | 161 | AT_DATA([[input.y]], [$2]) |
da730230 | 162 | AT_BISON_CHECK([-o input.c input.y]) |
865b9df1 | 163 | AT_SYNCLINES_COMPILE([input.c]) |
bdc360ae | 164 | AT_CHECK([cat stdout], 0, [$3]) |
55f48c48 | 165 | AT_BISON_OPTION_POPDEFS |
642cb8f8 AD |
166 | AT_CLEANUP |
167 | ]) | |
168 | ||
169 | ||
06f2ac78 AD |
170 | ## ------------------- ## |
171 | ## Prologue syncline. ## | |
172 | ## ------------------- ## | |
642cb8f8 AD |
173 | |
174 | ||
06f2ac78 | 175 | AT_TEST([Prologue syncline], |
642cb8f8 AD |
176 | [[%{ |
177 | #error "2" | |
55f48c48 AD |
178 | ]AT_YYERROR_DECLARE_EXTERN[ |
179 | ]AT_YYLEX_DECLARE_EXTERN[ | |
642cb8f8 AD |
180 | %} |
181 | %% | |
182 | exp: '0'; | |
55f48c48 | 183 | %% |
642cb8f8 AD |
184 | ]], |
185 | [input.y:2: #error "2" | |
186 | ]) | |
187 | ||
188 | ||
06f2ac78 AD |
189 | ## ----------------- ## |
190 | ## %union syncline. ## | |
191 | ## ----------------- ## | |
642cb8f8 | 192 | |
06f2ac78 | 193 | AT_TEST([%union syncline], |
642cb8f8 AD |
194 | [[%union { |
195 | #error "2" | |
0f53f222 | 196 | char dummy; |
642cb8f8 | 197 | } |
5683e9b2 | 198 | %{ |
55f48c48 AD |
199 | ]AT_YYERROR_DECLARE_EXTERN[ |
200 | ]AT_YYLEX_DECLARE_EXTERN[ | |
5683e9b2 | 201 | %} |
642cb8f8 AD |
202 | %% |
203 | exp: '0'; | |
55f48c48 | 204 | %% |
642cb8f8 AD |
205 | ]], |
206 | [input.y:2: #error "2" | |
207 | ]) | |
208 | ||
209 | ||
827bc59c AD |
210 | ## ---------------------- ## |
211 | ## %union name syncline. ## | |
212 | ## ---------------------- ## | |
213 | ||
214 | # Check that invalid union names are properly reported in the | |
215 | # source file. | |
216 | AT_SETUP([%union name syncline]) | |
217 | AT_BISON_OPTION_PUSHDEFS | |
218 | AT_DATA([[input.y]], | |
219 | [[%union break | |
220 | { | |
221 | char dummy; | |
222 | } | |
223 | %{ | |
224 | ]AT_YYERROR_DECLARE_EXTERN[ | |
225 | ]AT_YYLEX_DECLARE_EXTERN[ | |
226 | %} | |
227 | %% | |
228 | exp: '0'; | |
229 | %% | |
230 | ]]) | |
231 | ||
232 | AT_BISON_CHECK([-o input.c input.y]) | |
233 | AT_SYNCLINES_COMPILE([input.c]) | |
234 | AT_CHECK([[grep '^input.y:1' stdout]], 0, [ignore]) | |
235 | AT_BISON_OPTION_POPDEFS | |
236 | AT_CLEANUP | |
237 | ||
238 | ||
06f2ac78 AD |
239 | ## ----------------------- ## |
240 | ## Postprologue syncline. ## | |
241 | ## ----------------------- ## | |
642cb8f8 | 242 | |
06f2ac78 | 243 | AT_TEST([Postprologue syncline], |
642cb8f8 | 244 | [[%{ |
55f48c48 AD |
245 | ]AT_YYERROR_DECLARE_EXTERN[ |
246 | ]AT_YYLEX_DECLARE_EXTERN[ | |
642cb8f8 AD |
247 | %} |
248 | %union | |
249 | { | |
250 | int ival; | |
251 | } | |
252 | %{ | |
5683e9b2 | 253 | #error "10" |
642cb8f8 AD |
254 | %} |
255 | %% | |
256 | exp: '0'; | |
55f48c48 | 257 | %% |
642cb8f8 | 258 | ]], |
5683e9b2 | 259 | [input.y:10: #error "10" |
642cb8f8 AD |
260 | ]) |
261 | ||
262 | ||
06f2ac78 AD |
263 | ## ----------------- ## |
264 | ## Action syncline. ## | |
265 | ## ----------------- ## | |
642cb8f8 | 266 | |
06f2ac78 | 267 | AT_TEST([Action syncline], |
5683e9b2 | 268 | [[%{ |
55f48c48 AD |
269 | ]AT_YYERROR_DECLARE_EXTERN[ |
270 | ]AT_YYLEX_DECLARE_EXTERN[ | |
5683e9b2 AD |
271 | %} |
272 | %% | |
642cb8f8 AD |
273 | exp: |
274 | { | |
5683e9b2 | 275 | #error "8" |
642cb8f8 AD |
276 | }; |
277 | ]], | |
5683e9b2 | 278 | [input.y:8: #error "8" |
642cb8f8 AD |
279 | ]) |
280 | ||
281 | ||
06f2ac78 AD |
282 | ## ------------------- ## |
283 | ## Epilogue syncline. ## | |
284 | ## ------------------- ## | |
642cb8f8 | 285 | |
06f2ac78 | 286 | AT_TEST([Epilogue syncline], |
5683e9b2 | 287 | [[%{ |
55f48c48 AD |
288 | ]AT_YYERROR_DECLARE_EXTERN[ |
289 | ]AT_YYLEX_DECLARE_EXTERN[ | |
5683e9b2 AD |
290 | %} |
291 | %% | |
642cb8f8 AD |
292 | exp: '0'; |
293 | %% | |
5683e9b2 | 294 | #error "8" |
642cb8f8 | 295 | ]], |
5683e9b2 | 296 | [input.y:8: #error "8" |
642cb8f8 | 297 | ]) |
1914a781 | 298 | |
e94ca80b AD |
299 | ## -------------------- ## |
300 | ## %code top syncline. ## | |
301 | ## -------------------- ## | |
302 | ||
303 | AT_TEST([%code top syncline], | |
304 | [[%code top { | |
305 | #error "2" | |
306 | } | |
307 | %{ | |
308 | ]AT_YYERROR_DECLARE_EXTERN[ | |
309 | ]AT_YYLEX_DECLARE_EXTERN[ | |
310 | %} | |
311 | %% | |
312 | exp: '0'; | |
313 | %% | |
314 | ]], | |
315 | [input.y:2: #error "2" | |
316 | ]) | |
317 | ||
318 | m4_popdef([AT_TEST]) | |
319 | ||
320 | ## ----------- ## | |
321 | ## %no-lines. ## | |
322 | ## ----------- ## | |
323 | ||
324 | m4_pushdef([AT_TEST], | |
781eaf90 | 325 | [AT_SETUP([%no-lines: $1]) |
e94ca80b AD |
326 | |
327 | AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines]) | |
328 | AT_DATA_GRAMMAR([input.y], | |
329 | [%skeleton "$1" %defines | |
330 | %{ | |
331 | ]AT_YYERROR_DECLARE_EXTERN[ | |
332 | ]AT_YYLEX_DECLARE_EXTERN[ | |
333 | %} | |
334 | %% | |
335 | exp: '0' | |
336 | ]) | |
337 | AT_BISON_CHECK([--no-lines -o input.AT_SKEL_CC_IF([cc], [c]) -d input.y]) | |
338 | AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1) | |
339 | AT_BISON_OPTION_POPDEFS | |
340 | ||
341 | AT_CLEANUP | |
342 | ]) | |
343 | ||
344 | AT_TEST([yacc.c]) | |
345 | AT_TEST([glr.c]) | |
346 | AT_TEST([lalr1.cc]) | |
347 | AT_TEST([glr.cc]) | |
348 | ||
1914a781 | 349 | m4_popdef([AT_TEST]) |