OSDN Git Service

* config/i386/i386.c (override_options): Define c3-2 as a 686 with SSE.
[pf3gnuchains/gcc-fork.git] / gcc / cpperror.c
1 /* Default error handlers for CPP Library.
2    Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1998, 1999, 2000,
3    2001, 2002  Free Software Foundation, Inc.
4    Written by Per Bothner, 1994.
5    Based on CCCP program by Paul Rubin, June 1986
6    Adapted to ANSI C, Richard Stallman, Jan 1987
7
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22  In other words, you are welcome to use, share and improve this program.
23  You are forbidden to forbid anyone else to use, share and improve
24  what you give them.   Help stamp out software-hoarding!  */
25
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "cpplib.h"
31 #include "cpphash.h"
32 #include "intl.h"
33
34 static void print_location PARAMS ((cpp_reader *, unsigned int, unsigned int));
35
36 /* Print the logical file location (LINE, COL) in preparation for a
37    diagnostic.  Outputs the #include chain if it has changed.  A line
38    of zero suppresses the include stack, and outputs the program name
39    instead.  */
40 static void
41 print_location (pfile, line, col)
42      cpp_reader *pfile;
43      unsigned int line, col;
44 {
45   if (!pfile->buffer || line == 0)
46     fprintf (stderr, "%s: ", progname);
47   else
48     {
49       const struct line_map *map;
50
51       map = lookup_line (&pfile->line_maps, line);
52       print_containing_files (&pfile->line_maps, map);
53
54       line = SOURCE_LINE (map, line);
55       if (col == 0)
56         col = 1;
57
58       if (line == 0)
59         fprintf (stderr, "%s:", map->to_file);
60       else if (CPP_OPTION (pfile, show_column) == 0)
61         fprintf (stderr, "%s:%u:", map->to_file, line);
62       else
63         fprintf (stderr, "%s:%u:%u:", map->to_file, line, col);
64
65       fputc (' ', stderr);
66     }
67 }
68
69 /* Set up for a diagnostic: print the file and line, bump the error
70    counter, etc.  LINE is the logical line number; zero means to print
71    at the location of the previously lexed token, which tends to be
72    the correct place by default.  Returns 0 if the error has been
73    suppressed.  */
74 int
75 _cpp_begin_message (pfile, code, line, column)
76      cpp_reader *pfile;
77      int code;
78      unsigned int line, column;
79 {
80   int level = DL_EXTRACT (code);
81
82   switch (level)
83     {
84     case DL_WARNING:
85     case DL_PEDWARN:
86       if (CPP_IN_SYSTEM_HEADER (pfile)
87           && ! CPP_OPTION (pfile, warn_system_headers))
88         return 0;
89       /* Fall through.  */
90
91     case DL_WARNING_SYSHDR:
92       if (CPP_OPTION (pfile, warnings_are_errors)
93           || (level == DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors)))
94         {
95           if (CPP_OPTION (pfile, inhibit_errors))
96             return 0;
97           level = DL_ERROR;
98           pfile->errors++;
99         }
100       else if (CPP_OPTION (pfile, inhibit_warnings))
101         return 0;
102       break;
103
104     case DL_ERROR:
105       if (CPP_OPTION (pfile, inhibit_errors))
106         return 0;
107       /* ICEs cannot be inhibited.  */
108     case DL_ICE:
109       pfile->errors++;
110       break;
111     }
112
113   print_location (pfile, line, column);
114   if (DL_WARNING_P (level))
115     fputs (_("warning: "), stderr);
116   else if (level == DL_ICE)
117     fputs (_("internal error: "), stderr);
118
119   return 1;
120 }
121
122 /* Don't remove the blank before do, as otherwise the exgettext
123    script will mistake this as a function definition */
124 #define v_message(msgid, ap) \
125  do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0)
126
127 /* Exported interface.  */
128
129 /* Print an error at the location of the previously lexed token.  */
130 void
131 cpp_error VPARAMS ((cpp_reader * pfile, int level, const char *msgid, ...))
132 {
133   unsigned int line, column;
134
135   VA_OPEN (ap, msgid);
136   VA_FIXEDARG (ap, cpp_reader *, pfile);
137   VA_FIXEDARG (ap, int, level);
138   VA_FIXEDARG (ap, const char *, msgid);
139
140   if (pfile->buffer)
141     {
142       if (CPP_OPTION (pfile, traditional))
143         {
144           if (pfile->state.in_directive)
145             line = pfile->directive_line;
146           else
147             line = pfile->line;
148           column = 0;
149         }
150       else
151         {
152           line = pfile->cur_token[-1].line;
153           column = pfile->cur_token[-1].col;
154         }
155     }
156   else
157     line = column = 0;
158
159   if (_cpp_begin_message (pfile, level, line, column))
160     v_message (msgid, ap);
161
162   VA_CLOSE (ap);
163 }
164
165 /* Print an error at a specific location.  */
166 void
167 cpp_error_with_line VPARAMS ((cpp_reader *pfile, int level,
168                               unsigned int line, unsigned int column,
169                               const char *msgid, ...))
170 {
171   VA_OPEN (ap, msgid);
172   VA_FIXEDARG (ap, cpp_reader *, pfile);
173   VA_FIXEDARG (ap, int, level);
174   VA_FIXEDARG (ap, unsigned int, line);
175   VA_FIXEDARG (ap, unsigned int, column);
176   VA_FIXEDARG (ap, const char *, msgid);
177
178   if (_cpp_begin_message (pfile, level, line, column))
179     v_message (msgid, ap);
180
181   VA_CLOSE (ap);
182 }
183
184 void
185 cpp_errno (pfile, level, msgid)
186      cpp_reader *pfile;
187      int level;
188      const char *msgid;
189 {
190   if (msgid[0] == '\0')
191     msgid = _("stdout");
192
193   cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno));
194 }