1 # Executing Actions. -*- Autotest -*-
3 # Copyright (C) 2002, 2004-2005, 2007, 2009-2015 Free Software
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 AT_BANNER([[User Actions.]])
22 # _AT_SYNCLINES_COMPILE(FILE)
23 # ---------------------------
24 # Compile FILE expecting an error, and save in the file stdout the
25 # normalized output. Ignore the exit status, since some compilers
26 # (e.g. c89 on IRIX 6.5) trigger warnings on '#error', instead of
28 m4_define([_AT_SYNCLINES_COMPILE],
29 [AT_CHECK([$CC $CFLAGS $CPPFLAGS -c $1], [ignore], [], [stderr])
31 # Transform stderr into something like this:
33 # input.y:4: #error "4"
35 # In case GCC displays column information, strip it down.
37 # input.y:4:2: #error "4" or
38 # input.y:4.2: #error "4" or
39 # input.y:4:2: error: #error "4"
41 # input.y:4: #error "4"
43 # It may also issue more context information:
45 # input.y: In function 'yyparse':
46 # input.y:8: #error "8"
48 # input.y:4: #error "8"
50 # The message may include a caret-error (indented by GCC 4.8,
53 # input.y:1:2: error: #error "1"
57 # Possibly distcc adds its bits.
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
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
68 # The compiler might end by the number of messages issued (Clang 3.2):
70 # syncline.c:1:2: error: "1"
75 # When c++ is used to compiler C, we might have more messages (Clang 3.2):
77 # clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
80 # xlc reports things like:
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
85 # Newer GCCs go further and if the function is declared static, complain
87 AT_CHECK([[$PERL -p -0777 - stderr <<\EOF
88 # 1. Remove useless lines.
91 s/^distcc\[\d+\] .*\n//gm;
93 s/^clang: warning: treating 'c' input as 'c\+\+'.*\n//gm;
95 s/^[^:]*: In function '[^']+':\n//gm;
97 s/^ *#error.*\n *\^\n//gm;
99 s/^1 error generated\.\n//gm;
101 # 2. Normalize the lines we kept.
103 # xlc messages. Remove also error identifier (e.g., "1540-0218 (S)").
104 s/^"(.*?)", line ([\w.]*): \d+-\d+ \(.\) /$][1:$][2: /gm;
106 s/^([^:]+:\d+)[.:][^:]+:(.+)$/$][1:$][2/gm;
107 # Map all combinations of "error: " and "#error: " to "#error ".
108 s/^([^:]+:\d+):( |#error|error|:)+/$][1: #error /gm;
116 # AT_SYNCLINES_COMPILE(FILE)
117 # --------------------------
118 # Compile FILE expecting an error, and save in the file stdout the
119 # normalized output. If we can't get a trustable location
120 # from the compiler, just skip the test.
122 # It seems impossible to find a generic scheme to check the location
123 # of an error. Even requiring GCC is not sufficient, since for instance
124 # the version modified by Apple:
126 # | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
127 # | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
128 # | 19991024 (release) configure:2124: $? = 0
132 # | input.y:2: #error "2"
137 # | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
138 m4_define([AT_SYNCLINES_COMPILE],
139 [# Check if we can trust location translation.
140 AT_DATA([syncline.c],
148 _AT_SYNCLINES_COMPILE([syncline.c])
149 AT_CHECK([[test "`cat stdout`" = 'syncline.c:4: @%:@error "4"' || exit 77]])
151 # Then work for real.
152 _AT_SYNCLINES_COMPILE([$1])
156 # AT_TEST(TITLE, INPUT, ERROR-MSG)
157 # --------------------------------
158 # Check that compiling the parser produced from INPUT cause GCC
159 # to issue ERROR-MSG.
160 m4_pushdef([AT_TEST],
162 AT_BISON_OPTION_PUSHDEFS
164 AT_DATA([[input.y]], [$2])
165 AT_BISON_CHECK([-o input.c input.y])
166 AT_SYNCLINES_COMPILE([input.c])
167 AT_CHECK([cat stdout], 0, [$3])
168 AT_BISON_OPTION_POPDEFS
173 ## ------------------- ##
174 ## Prologue syncline. ##
175 ## ------------------- ##
178 AT_TEST([Prologue syncline],
181 ]AT_YYERROR_DECLARE_EXTERN[
182 ]AT_YYLEX_DECLARE_EXTERN[
188 [input.y:2: #error "2"
192 ## ----------------- ##
193 ## %union syncline. ##
194 ## ----------------- ##
196 AT_TEST([%union syncline],
202 ]AT_YYERROR_DECLARE_EXTERN[
203 ]AT_YYLEX_DECLARE_EXTERN[
209 [input.y:2: #error "2"
213 ## ---------------------- ##
214 ## %union name syncline. ##
215 ## ---------------------- ##
217 # Check that invalid union names are properly reported in the
219 AT_SETUP([%union name syncline])
220 AT_BISON_OPTION_PUSHDEFS
227 ]AT_YYERROR_DECLARE_EXTERN[
228 ]AT_YYLEX_DECLARE_EXTERN[
235 AT_BISON_CHECK([-o input.c input.y])
236 AT_SYNCLINES_COMPILE([input.c])
237 AT_CHECK([[grep '^input.y:1' stdout]], 0, [ignore])
238 AT_BISON_OPTION_POPDEFS
242 ## ----------------------- ##
243 ## Postprologue syncline. ##
244 ## ----------------------- ##
246 AT_TEST([Postprologue syncline],
248 ]AT_YYERROR_DECLARE_EXTERN[
249 ]AT_YYLEX_DECLARE_EXTERN[
262 [input.y:10: #error "10"
266 ## ----------------- ##
267 ## Action syncline. ##
268 ## ----------------- ##
270 AT_TEST([Action syncline],
272 ]AT_YYERROR_DECLARE_EXTERN[
273 ]AT_YYLEX_DECLARE_EXTERN[
281 [input.y:8: #error "8"
285 ## ------------------- ##
286 ## Epilogue syncline. ##
287 ## ------------------- ##
289 AT_TEST([Epilogue syncline],
291 ]AT_YYERROR_DECLARE_EXTERN[
292 ]AT_YYLEX_DECLARE_EXTERN[
299 [input.y:8: #error "8"
302 ## -------------------- ##
303 ## %code top syncline. ##
304 ## -------------------- ##
306 AT_TEST([%code top syncline],
311 ]AT_YYERROR_DECLARE_EXTERN[
312 ]AT_YYLEX_DECLARE_EXTERN[
318 [input.y:2: #error "2"
327 m4_pushdef([AT_TEST],
328 [AT_SETUP([%no-lines: $1])
330 AT_BISON_OPTION_PUSHDEFS([%skeleton "$1" %defines])
331 AT_DATA_GRAMMAR([input.y],
332 [%skeleton "$1" %defines
334 ]AT_YYERROR_DECLARE_EXTERN[
335 ]AT_YYLEX_DECLARE_EXTERN[
340 AT_BISON_CHECK([--no-lines -o input.AT_SKEL_CC_IF([cc], [c]) -d input.y])
341 AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1)
342 AT_BISON_OPTION_POPDEFS