1*38fd1498Szrj /* CPP Library.
2*38fd1498Szrj Copyright (C) 1986-2018 Free Software Foundation, Inc.
3*38fd1498Szrj Contributed by Per Bothner, 1994-95.
4*38fd1498Szrj Based on CCCP program by Paul Rubin, June 1986
5*38fd1498Szrj Adapted to ANSI C, Richard Stallman, Jan 1987
6*38fd1498Szrj
7*38fd1498Szrj This program is free software; you can redistribute it and/or modify it
8*38fd1498Szrj under the terms of the GNU General Public License as published by the
9*38fd1498Szrj Free Software Foundation; either version 3, or (at your option) any
10*38fd1498Szrj later version.
11*38fd1498Szrj
12*38fd1498Szrj This program is distributed in the hope that it will be useful,
13*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*38fd1498Szrj GNU General Public License for more details.
16*38fd1498Szrj
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with this program; see the file COPYING3. If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>. */
20*38fd1498Szrj
21*38fd1498Szrj #include "config.h"
22*38fd1498Szrj #include "system.h"
23*38fd1498Szrj #include "cpplib.h"
24*38fd1498Szrj #include "internal.h"
25*38fd1498Szrj #include "mkdeps.h"
26*38fd1498Szrj #include "localedir.h"
27*38fd1498Szrj #include "filenames.h"
28*38fd1498Szrj
29*38fd1498Szrj #ifndef ENABLE_CANONICAL_SYSTEM_HEADERS
30*38fd1498Szrj #ifdef HAVE_DOS_BASED_FILE_SYSTEM
31*38fd1498Szrj #define ENABLE_CANONICAL_SYSTEM_HEADERS 1
32*38fd1498Szrj #else
33*38fd1498Szrj #define ENABLE_CANONICAL_SYSTEM_HEADERS 0
34*38fd1498Szrj #endif
35*38fd1498Szrj #endif
36*38fd1498Szrj
37*38fd1498Szrj static void init_library (void);
38*38fd1498Szrj static void mark_named_operators (cpp_reader *, int);
39*38fd1498Szrj static void read_original_filename (cpp_reader *);
40*38fd1498Szrj static void read_original_directory (cpp_reader *);
41*38fd1498Szrj static void post_options (cpp_reader *);
42*38fd1498Szrj
43*38fd1498Szrj /* If we have designated initializers (GCC >2.7) these tables can be
44*38fd1498Szrj initialized, constant data. Otherwise, they have to be filled in at
45*38fd1498Szrj runtime. */
46*38fd1498Szrj #if HAVE_DESIGNATED_INITIALIZERS
47*38fd1498Szrj
48*38fd1498Szrj #define init_trigraph_map() /* Nothing. */
49*38fd1498Szrj #define TRIGRAPH_MAP \
50*38fd1498Szrj __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = {
51*38fd1498Szrj
52*38fd1498Szrj #define END };
53*38fd1498Szrj #define s(p, v) [p] = v,
54*38fd1498Szrj
55*38fd1498Szrj #else
56*38fd1498Szrj
57*38fd1498Szrj #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
58*38fd1498Szrj static void init_trigraph_map (void) { \
59*38fd1498Szrj unsigned char *x = _cpp_trigraph_map;
60*38fd1498Szrj
61*38fd1498Szrj #define END }
62*38fd1498Szrj #define s(p, v) x[p] = v;
63*38fd1498Szrj
64*38fd1498Szrj #endif
65*38fd1498Szrj
66*38fd1498Szrj TRIGRAPH_MAP
67*38fd1498Szrj s('=', '#') s(')', ']') s('!', '|')
68*38fd1498Szrj s('(', '[') s('\'', '^') s('>', '}')
69*38fd1498Szrj s('/', '\\') s('<', '{') s('-', '~')
70*38fd1498Szrj END
71*38fd1498Szrj
72*38fd1498Szrj #undef s
73*38fd1498Szrj #undef END
74*38fd1498Szrj #undef TRIGRAPH_MAP
75*38fd1498Szrj
76*38fd1498Szrj /* A set of booleans indicating what CPP features each source language
77*38fd1498Szrj requires. */
78*38fd1498Szrj struct lang_flags
79*38fd1498Szrj {
80*38fd1498Szrj char c99;
81*38fd1498Szrj char cplusplus;
82*38fd1498Szrj char extended_numbers;
83*38fd1498Szrj char extended_identifiers;
84*38fd1498Szrj char c11_identifiers;
85*38fd1498Szrj char std;
86*38fd1498Szrj char digraphs;
87*38fd1498Szrj char uliterals;
88*38fd1498Szrj char rliterals;
89*38fd1498Szrj char user_literals;
90*38fd1498Szrj char binary_constants;
91*38fd1498Szrj char digit_separators;
92*38fd1498Szrj char trigraphs;
93*38fd1498Szrj char utf8_char_literals;
94*38fd1498Szrj char va_opt;
95*38fd1498Szrj };
96*38fd1498Szrj
97*38fd1498Szrj static const struct lang_flags lang_defaults[] =
98*38fd1498Szrj { /* c99 c++ xnum xid c11 std digr ulit rlit udlit bincst digsep trig u8chlit vaopt */
99*38fd1498Szrj /* GNUC89 */ { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
100*38fd1498Szrj /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
101*38fd1498Szrj /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
102*38fd1498Szrj /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
103*38fd1498Szrj /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
104*38fd1498Szrj /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
105*38fd1498Szrj /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
106*38fd1498Szrj /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
107*38fd1498Szrj /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 },
108*38fd1498Szrj /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
109*38fd1498Szrj /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 },
110*38fd1498Szrj /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
111*38fd1498Szrj /* CXX11 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0 },
112*38fd1498Szrj /* GNUCXX14 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1 },
113*38fd1498Szrj /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
114*38fd1498Szrj /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 },
115*38fd1498Szrj /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0 },
116*38fd1498Szrj /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 },
117*38fd1498Szrj /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1 },
118*38fd1498Szrj /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
119*38fd1498Szrj };
120*38fd1498Szrj
121*38fd1498Szrj /* Sets internal flags correctly for a given language. */
122*38fd1498Szrj void
cpp_set_lang(cpp_reader * pfile,enum c_lang lang)123*38fd1498Szrj cpp_set_lang (cpp_reader *pfile, enum c_lang lang)
124*38fd1498Szrj {
125*38fd1498Szrj const struct lang_flags *l = &lang_defaults[(int) lang];
126*38fd1498Szrj
127*38fd1498Szrj CPP_OPTION (pfile, lang) = lang;
128*38fd1498Szrj
129*38fd1498Szrj CPP_OPTION (pfile, c99) = l->c99;
130*38fd1498Szrj CPP_OPTION (pfile, cplusplus) = l->cplusplus;
131*38fd1498Szrj CPP_OPTION (pfile, extended_numbers) = l->extended_numbers;
132*38fd1498Szrj CPP_OPTION (pfile, extended_identifiers) = l->extended_identifiers;
133*38fd1498Szrj CPP_OPTION (pfile, c11_identifiers) = l->c11_identifiers;
134*38fd1498Szrj CPP_OPTION (pfile, std) = l->std;
135*38fd1498Szrj CPP_OPTION (pfile, digraphs) = l->digraphs;
136*38fd1498Szrj CPP_OPTION (pfile, uliterals) = l->uliterals;
137*38fd1498Szrj CPP_OPTION (pfile, rliterals) = l->rliterals;
138*38fd1498Szrj CPP_OPTION (pfile, user_literals) = l->user_literals;
139*38fd1498Szrj CPP_OPTION (pfile, binary_constants) = l->binary_constants;
140*38fd1498Szrj CPP_OPTION (pfile, digit_separators) = l->digit_separators;
141*38fd1498Szrj CPP_OPTION (pfile, trigraphs) = l->trigraphs;
142*38fd1498Szrj CPP_OPTION (pfile, utf8_char_literals) = l->utf8_char_literals;
143*38fd1498Szrj CPP_OPTION (pfile, va_opt) = l->va_opt;
144*38fd1498Szrj }
145*38fd1498Szrj
146*38fd1498Szrj /* Initialize library global state. */
147*38fd1498Szrj static void
init_library(void)148*38fd1498Szrj init_library (void)
149*38fd1498Szrj {
150*38fd1498Szrj static int initialized = 0;
151*38fd1498Szrj
152*38fd1498Szrj if (! initialized)
153*38fd1498Szrj {
154*38fd1498Szrj initialized = 1;
155*38fd1498Szrj
156*38fd1498Szrj _cpp_init_lexer ();
157*38fd1498Szrj
158*38fd1498Szrj /* Set up the trigraph map. This doesn't need to do anything if
159*38fd1498Szrj we were compiled with a compiler that supports C99 designated
160*38fd1498Szrj initializers. */
161*38fd1498Szrj init_trigraph_map ();
162*38fd1498Szrj
163*38fd1498Szrj #ifdef ENABLE_NLS
164*38fd1498Szrj (void) bindtextdomain (PACKAGE, LOCALEDIR);
165*38fd1498Szrj #endif
166*38fd1498Szrj }
167*38fd1498Szrj }
168*38fd1498Szrj
169*38fd1498Szrj /* Initialize a cpp_reader structure. */
170*38fd1498Szrj cpp_reader *
cpp_create_reader(enum c_lang lang,cpp_hash_table * table,struct line_maps * line_table)171*38fd1498Szrj cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
172*38fd1498Szrj struct line_maps *line_table)
173*38fd1498Szrj {
174*38fd1498Szrj cpp_reader *pfile;
175*38fd1498Szrj
176*38fd1498Szrj /* Initialize this instance of the library if it hasn't been already. */
177*38fd1498Szrj init_library ();
178*38fd1498Szrj
179*38fd1498Szrj pfile = XCNEW (cpp_reader);
180*38fd1498Szrj memset (&pfile->base_context, 0, sizeof (pfile->base_context));
181*38fd1498Szrj
182*38fd1498Szrj cpp_set_lang (pfile, lang);
183*38fd1498Szrj CPP_OPTION (pfile, warn_multichar) = 1;
184*38fd1498Szrj CPP_OPTION (pfile, discard_comments) = 1;
185*38fd1498Szrj CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1;
186*38fd1498Szrj CPP_OPTION (pfile, tabstop) = 8;
187*38fd1498Szrj CPP_OPTION (pfile, operator_names) = 1;
188*38fd1498Szrj CPP_OPTION (pfile, warn_trigraphs) = 2;
189*38fd1498Szrj CPP_OPTION (pfile, warn_endif_labels) = 1;
190*38fd1498Szrj CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1;
191*38fd1498Szrj CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0;
192*38fd1498Szrj CPP_OPTION (pfile, cpp_warn_deprecated) = 1;
193*38fd1498Szrj CPP_OPTION (pfile, cpp_warn_long_long) = 0;
194*38fd1498Szrj CPP_OPTION (pfile, dollars_in_ident) = 1;
195*38fd1498Szrj CPP_OPTION (pfile, warn_dollars) = 1;
196*38fd1498Szrj CPP_OPTION (pfile, warn_variadic_macros) = 1;
197*38fd1498Szrj CPP_OPTION (pfile, warn_builtin_macro_redefined) = 1;
198*38fd1498Szrj CPP_OPTION (pfile, cpp_warn_implicit_fallthrough) = 0;
199*38fd1498Szrj /* By default, track locations of tokens resulting from macro
200*38fd1498Szrj expansion. The '2' means, track the locations with the highest
201*38fd1498Szrj accuracy. Read the comments for struct
202*38fd1498Szrj cpp_options::track_macro_expansion to learn about the other
203*38fd1498Szrj values. */
204*38fd1498Szrj CPP_OPTION (pfile, track_macro_expansion) = 2;
205*38fd1498Szrj CPP_OPTION (pfile, warn_normalize) = normalized_C;
206*38fd1498Szrj CPP_OPTION (pfile, warn_literal_suffix) = 1;
207*38fd1498Szrj CPP_OPTION (pfile, canonical_system_headers)
208*38fd1498Szrj = ENABLE_CANONICAL_SYSTEM_HEADERS;
209*38fd1498Szrj CPP_OPTION (pfile, ext_numeric_literals) = 1;
210*38fd1498Szrj CPP_OPTION (pfile, warn_date_time) = 0;
211*38fd1498Szrj
212*38fd1498Szrj /* Default CPP arithmetic to something sensible for the host for the
213*38fd1498Szrj benefit of dumb users like fix-header. */
214*38fd1498Szrj CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long);
215*38fd1498Szrj CPP_OPTION (pfile, char_precision) = CHAR_BIT;
216*38fd1498Szrj CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int);
217*38fd1498Szrj CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int);
218*38fd1498Szrj CPP_OPTION (pfile, unsigned_char) = 0;
219*38fd1498Szrj CPP_OPTION (pfile, unsigned_wchar) = 1;
220*38fd1498Szrj CPP_OPTION (pfile, bytes_big_endian) = 1; /* does not matter */
221*38fd1498Szrj
222*38fd1498Szrj /* Default to no charset conversion. */
223*38fd1498Szrj CPP_OPTION (pfile, narrow_charset) = _cpp_default_encoding ();
224*38fd1498Szrj CPP_OPTION (pfile, wide_charset) = 0;
225*38fd1498Szrj
226*38fd1498Szrj /* Default the input character set to UTF-8. */
227*38fd1498Szrj CPP_OPTION (pfile, input_charset) = _cpp_default_encoding ();
228*38fd1498Szrj
229*38fd1498Szrj /* A fake empty "directory" used as the starting point for files
230*38fd1498Szrj looked up without a search path. Name cannot be '/' because we
231*38fd1498Szrj don't want to prepend anything at all to filenames using it. All
232*38fd1498Szrj other entries are correct zero-initialized. */
233*38fd1498Szrj pfile->no_search_path.name = (char *) "";
234*38fd1498Szrj
235*38fd1498Szrj /* Initialize the line map. */
236*38fd1498Szrj pfile->line_table = line_table;
237*38fd1498Szrj
238*38fd1498Szrj /* Initialize lexer state. */
239*38fd1498Szrj pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
240*38fd1498Szrj
241*38fd1498Szrj /* Set up static tokens. */
242*38fd1498Szrj pfile->avoid_paste.type = CPP_PADDING;
243*38fd1498Szrj pfile->avoid_paste.val.source = NULL;
244*38fd1498Szrj pfile->eof.type = CPP_EOF;
245*38fd1498Szrj pfile->eof.flags = 0;
246*38fd1498Szrj
247*38fd1498Szrj /* Create a token buffer for the lexer. */
248*38fd1498Szrj _cpp_init_tokenrun (&pfile->base_run, 250);
249*38fd1498Szrj pfile->cur_run = &pfile->base_run;
250*38fd1498Szrj pfile->cur_token = pfile->base_run.base;
251*38fd1498Szrj
252*38fd1498Szrj /* Initialize the base context. */
253*38fd1498Szrj pfile->context = &pfile->base_context;
254*38fd1498Szrj pfile->base_context.c.macro = 0;
255*38fd1498Szrj pfile->base_context.prev = pfile->base_context.next = 0;
256*38fd1498Szrj
257*38fd1498Szrj /* Aligned and unaligned storage. */
258*38fd1498Szrj pfile->a_buff = _cpp_get_buff (pfile, 0);
259*38fd1498Szrj pfile->u_buff = _cpp_get_buff (pfile, 0);
260*38fd1498Szrj
261*38fd1498Szrj /* Initialize table for push_macro/pop_macro. */
262*38fd1498Szrj pfile->pushed_macros = 0;
263*38fd1498Szrj
264*38fd1498Szrj /* Do not force token locations by default. */
265*38fd1498Szrj pfile->forced_token_location_p = NULL;
266*38fd1498Szrj
267*38fd1498Szrj /* Initialize source_date_epoch to -2 (not yet set). */
268*38fd1498Szrj pfile->source_date_epoch = (time_t) -2;
269*38fd1498Szrj
270*38fd1498Szrj /* The expression parser stack. */
271*38fd1498Szrj _cpp_expand_op_stack (pfile);
272*38fd1498Szrj
273*38fd1498Szrj /* Initialize the buffer obstack. */
274*38fd1498Szrj obstack_specify_allocation (&pfile->buffer_ob, 0, 0, xmalloc, free);
275*38fd1498Szrj
276*38fd1498Szrj _cpp_init_files (pfile);
277*38fd1498Szrj
278*38fd1498Szrj _cpp_init_hashtable (pfile, table);
279*38fd1498Szrj
280*38fd1498Szrj return pfile;
281*38fd1498Szrj }
282*38fd1498Szrj
283*38fd1498Szrj /* Set the line_table entry in PFILE. This is called after reading a
284*38fd1498Szrj PCH file, as the old line_table will be incorrect. */
285*38fd1498Szrj void
cpp_set_line_map(cpp_reader * pfile,struct line_maps * line_table)286*38fd1498Szrj cpp_set_line_map (cpp_reader *pfile, struct line_maps *line_table)
287*38fd1498Szrj {
288*38fd1498Szrj pfile->line_table = line_table;
289*38fd1498Szrj }
290*38fd1498Szrj
291*38fd1498Szrj /* Free resources used by PFILE. Accessing PFILE after this function
292*38fd1498Szrj returns leads to undefined behavior. Returns the error count. */
293*38fd1498Szrj void
cpp_destroy(cpp_reader * pfile)294*38fd1498Szrj cpp_destroy (cpp_reader *pfile)
295*38fd1498Szrj {
296*38fd1498Szrj cpp_context *context, *contextn;
297*38fd1498Szrj struct def_pragma_macro *pmacro;
298*38fd1498Szrj tokenrun *run, *runn;
299*38fd1498Szrj int i;
300*38fd1498Szrj
301*38fd1498Szrj free (pfile->op_stack);
302*38fd1498Szrj
303*38fd1498Szrj while (CPP_BUFFER (pfile) != NULL)
304*38fd1498Szrj _cpp_pop_buffer (pfile);
305*38fd1498Szrj
306*38fd1498Szrj free (pfile->out.base);
307*38fd1498Szrj
308*38fd1498Szrj if (pfile->macro_buffer)
309*38fd1498Szrj {
310*38fd1498Szrj free (pfile->macro_buffer);
311*38fd1498Szrj pfile->macro_buffer = NULL;
312*38fd1498Szrj pfile->macro_buffer_len = 0;
313*38fd1498Szrj }
314*38fd1498Szrj
315*38fd1498Szrj if (pfile->deps)
316*38fd1498Szrj deps_free (pfile->deps);
317*38fd1498Szrj obstack_free (&pfile->buffer_ob, 0);
318*38fd1498Szrj
319*38fd1498Szrj _cpp_destroy_hashtable (pfile);
320*38fd1498Szrj _cpp_cleanup_files (pfile);
321*38fd1498Szrj _cpp_destroy_iconv (pfile);
322*38fd1498Szrj
323*38fd1498Szrj _cpp_free_buff (pfile->a_buff);
324*38fd1498Szrj _cpp_free_buff (pfile->u_buff);
325*38fd1498Szrj _cpp_free_buff (pfile->free_buffs);
326*38fd1498Szrj
327*38fd1498Szrj for (run = &pfile->base_run; run; run = runn)
328*38fd1498Szrj {
329*38fd1498Szrj runn = run->next;
330*38fd1498Szrj free (run->base);
331*38fd1498Szrj if (run != &pfile->base_run)
332*38fd1498Szrj free (run);
333*38fd1498Szrj }
334*38fd1498Szrj
335*38fd1498Szrj for (context = pfile->base_context.next; context; context = contextn)
336*38fd1498Szrj {
337*38fd1498Szrj contextn = context->next;
338*38fd1498Szrj free (context);
339*38fd1498Szrj }
340*38fd1498Szrj
341*38fd1498Szrj if (pfile->comments.entries)
342*38fd1498Szrj {
343*38fd1498Szrj for (i = 0; i < pfile->comments.count; i++)
344*38fd1498Szrj free (pfile->comments.entries[i].comment);
345*38fd1498Szrj
346*38fd1498Szrj free (pfile->comments.entries);
347*38fd1498Szrj }
348*38fd1498Szrj if (pfile->pushed_macros)
349*38fd1498Szrj {
350*38fd1498Szrj do
351*38fd1498Szrj {
352*38fd1498Szrj pmacro = pfile->pushed_macros;
353*38fd1498Szrj pfile->pushed_macros = pmacro->next;
354*38fd1498Szrj free (pmacro->name);
355*38fd1498Szrj free (pmacro);
356*38fd1498Szrj }
357*38fd1498Szrj while (pfile->pushed_macros);
358*38fd1498Szrj }
359*38fd1498Szrj
360*38fd1498Szrj free (pfile);
361*38fd1498Szrj }
362*38fd1498Szrj
363*38fd1498Szrj /* This structure defines one built-in identifier. A node will be
364*38fd1498Szrj entered in the hash table under the name NAME, with value VALUE.
365*38fd1498Szrj
366*38fd1498Szrj There are two tables of these. builtin_array holds all the
367*38fd1498Szrj "builtin" macros: these are handled by builtin_macro() in
368*38fd1498Szrj macro.c. Builtin is somewhat of a misnomer -- the property of
369*38fd1498Szrj interest is that these macros require special code to compute their
370*38fd1498Szrj expansions. The value is a "cpp_builtin_type" enumerator.
371*38fd1498Szrj
372*38fd1498Szrj operator_array holds the C++ named operators. These are keywords
373*38fd1498Szrj which act as aliases for punctuators. In C++, they cannot be
374*38fd1498Szrj altered through #define, and #if recognizes them as operators. In
375*38fd1498Szrj C, these are not entered into the hash table at all (but see
376*38fd1498Szrj <iso646.h>). The value is a token-type enumerator. */
377*38fd1498Szrj struct builtin_macro
378*38fd1498Szrj {
379*38fd1498Szrj const uchar *const name;
380*38fd1498Szrj const unsigned short len;
381*38fd1498Szrj const unsigned short value;
382*38fd1498Szrj const bool always_warn_if_redefined;
383*38fd1498Szrj };
384*38fd1498Szrj
385*38fd1498Szrj #define B(n, t, f) { DSC(n), t, f }
386*38fd1498Szrj static const struct builtin_macro builtin_array[] =
387*38fd1498Szrj {
388*38fd1498Szrj B("__TIMESTAMP__", BT_TIMESTAMP, false),
389*38fd1498Szrj B("__TIME__", BT_TIME, false),
390*38fd1498Szrj B("__DATE__", BT_DATE, false),
391*38fd1498Szrj B("__FILE__", BT_FILE, false),
392*38fd1498Szrj B("__BASE_FILE__", BT_BASE_FILE, false),
393*38fd1498Szrj B("__LINE__", BT_SPECLINE, true),
394*38fd1498Szrj B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL, true),
395*38fd1498Szrj B("__COUNTER__", BT_COUNTER, true),
396*38fd1498Szrj B("__has_attribute", BT_HAS_ATTRIBUTE, true),
397*38fd1498Szrj B("__has_cpp_attribute", BT_HAS_ATTRIBUTE, true),
398*38fd1498Szrj /* Keep builtins not used for -traditional-cpp at the end, and
399*38fd1498Szrj update init_builtins() if any more are added. */
400*38fd1498Szrj B("_Pragma", BT_PRAGMA, true),
401*38fd1498Szrj B("__STDC__", BT_STDC, true),
402*38fd1498Szrj };
403*38fd1498Szrj #undef B
404*38fd1498Szrj
405*38fd1498Szrj struct builtin_operator
406*38fd1498Szrj {
407*38fd1498Szrj const uchar *const name;
408*38fd1498Szrj const unsigned short len;
409*38fd1498Szrj const unsigned short value;
410*38fd1498Szrj };
411*38fd1498Szrj
412*38fd1498Szrj #define B(n, t) { DSC(n), t }
413*38fd1498Szrj static const struct builtin_operator operator_array[] =
414*38fd1498Szrj {
415*38fd1498Szrj B("and", CPP_AND_AND),
416*38fd1498Szrj B("and_eq", CPP_AND_EQ),
417*38fd1498Szrj B("bitand", CPP_AND),
418*38fd1498Szrj B("bitor", CPP_OR),
419*38fd1498Szrj B("compl", CPP_COMPL),
420*38fd1498Szrj B("not", CPP_NOT),
421*38fd1498Szrj B("not_eq", CPP_NOT_EQ),
422*38fd1498Szrj B("or", CPP_OR_OR),
423*38fd1498Szrj B("or_eq", CPP_OR_EQ),
424*38fd1498Szrj B("xor", CPP_XOR),
425*38fd1498Szrj B("xor_eq", CPP_XOR_EQ)
426*38fd1498Szrj };
427*38fd1498Szrj #undef B
428*38fd1498Szrj
429*38fd1498Szrj /* Mark the C++ named operators in the hash table. */
430*38fd1498Szrj static void
mark_named_operators(cpp_reader * pfile,int flags)431*38fd1498Szrj mark_named_operators (cpp_reader *pfile, int flags)
432*38fd1498Szrj {
433*38fd1498Szrj const struct builtin_operator *b;
434*38fd1498Szrj
435*38fd1498Szrj for (b = operator_array;
436*38fd1498Szrj b < (operator_array + ARRAY_SIZE (operator_array));
437*38fd1498Szrj b++)
438*38fd1498Szrj {
439*38fd1498Szrj cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
440*38fd1498Szrj hp->flags |= flags;
441*38fd1498Szrj hp->is_directive = 0;
442*38fd1498Szrj hp->directive_index = b->value;
443*38fd1498Szrj }
444*38fd1498Szrj }
445*38fd1498Szrj
446*38fd1498Szrj /* Helper function of cpp_type2name. Return the string associated with
447*38fd1498Szrj named operator TYPE. */
448*38fd1498Szrj const char *
cpp_named_operator2name(enum cpp_ttype type)449*38fd1498Szrj cpp_named_operator2name (enum cpp_ttype type)
450*38fd1498Szrj {
451*38fd1498Szrj const struct builtin_operator *b;
452*38fd1498Szrj
453*38fd1498Szrj for (b = operator_array;
454*38fd1498Szrj b < (operator_array + ARRAY_SIZE (operator_array));
455*38fd1498Szrj b++)
456*38fd1498Szrj {
457*38fd1498Szrj if (type == b->value)
458*38fd1498Szrj return (const char *) b->name;
459*38fd1498Szrj }
460*38fd1498Szrj
461*38fd1498Szrj return NULL;
462*38fd1498Szrj }
463*38fd1498Szrj
464*38fd1498Szrj void
cpp_init_special_builtins(cpp_reader * pfile)465*38fd1498Szrj cpp_init_special_builtins (cpp_reader *pfile)
466*38fd1498Szrj {
467*38fd1498Szrj const struct builtin_macro *b;
468*38fd1498Szrj size_t n = ARRAY_SIZE (builtin_array);
469*38fd1498Szrj
470*38fd1498Szrj if (CPP_OPTION (pfile, traditional))
471*38fd1498Szrj n -= 2;
472*38fd1498Szrj else if (! CPP_OPTION (pfile, stdc_0_in_system_headers)
473*38fd1498Szrj || CPP_OPTION (pfile, std))
474*38fd1498Szrj n--;
475*38fd1498Szrj
476*38fd1498Szrj for (b = builtin_array; b < builtin_array + n; b++)
477*38fd1498Szrj {
478*38fd1498Szrj if (b->value == BT_HAS_ATTRIBUTE
479*38fd1498Szrj && (CPP_OPTION (pfile, lang) == CLK_ASM
480*38fd1498Szrj || pfile->cb.has_attribute == NULL))
481*38fd1498Szrj continue;
482*38fd1498Szrj cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
483*38fd1498Szrj hp->type = NT_MACRO;
484*38fd1498Szrj hp->flags |= NODE_BUILTIN;
485*38fd1498Szrj if (b->always_warn_if_redefined)
486*38fd1498Szrj hp->flags |= NODE_WARN;
487*38fd1498Szrj hp->value.builtin = (enum cpp_builtin_type) b->value;
488*38fd1498Szrj }
489*38fd1498Szrj }
490*38fd1498Szrj
491*38fd1498Szrj /* Read the builtins table above and enter them, and language-specific
492*38fd1498Szrj macros, into the hash table. HOSTED is true if this is a hosted
493*38fd1498Szrj environment. */
494*38fd1498Szrj void
cpp_init_builtins(cpp_reader * pfile,int hosted)495*38fd1498Szrj cpp_init_builtins (cpp_reader *pfile, int hosted)
496*38fd1498Szrj {
497*38fd1498Szrj cpp_init_special_builtins (pfile);
498*38fd1498Szrj
499*38fd1498Szrj if (!CPP_OPTION (pfile, traditional)
500*38fd1498Szrj && (! CPP_OPTION (pfile, stdc_0_in_system_headers)
501*38fd1498Szrj || CPP_OPTION (pfile, std)))
502*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC__ 1");
503*38fd1498Szrj
504*38fd1498Szrj if (CPP_OPTION (pfile, cplusplus))
505*38fd1498Szrj {
506*38fd1498Szrj if (CPP_OPTION (pfile, lang) == CLK_CXX2A
507*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_GNUCXX2A)
508*38fd1498Szrj _cpp_define_builtin (pfile, "__cplusplus 201709L");
509*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_CXX17
510*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_GNUCXX17)
511*38fd1498Szrj _cpp_define_builtin (pfile, "__cplusplus 201703L");
512*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_CXX14
513*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_GNUCXX14)
514*38fd1498Szrj _cpp_define_builtin (pfile, "__cplusplus 201402L");
515*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_CXX11
516*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_GNUCXX11)
517*38fd1498Szrj _cpp_define_builtin (pfile, "__cplusplus 201103L");
518*38fd1498Szrj else
519*38fd1498Szrj _cpp_define_builtin (pfile, "__cplusplus 199711L");
520*38fd1498Szrj }
521*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_ASM)
522*38fd1498Szrj _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
523*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_STDC94)
524*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
525*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_STDC17
526*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_GNUC17)
527*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_VERSION__ 201710L");
528*38fd1498Szrj else if (CPP_OPTION (pfile, lang) == CLK_STDC11
529*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_GNUC11)
530*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_VERSION__ 201112L");
531*38fd1498Szrj else if (CPP_OPTION (pfile, c99))
532*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
533*38fd1498Szrj
534*38fd1498Szrj if (CPP_OPTION (pfile, uliterals)
535*38fd1498Szrj && !(CPP_OPTION (pfile, cplusplus)
536*38fd1498Szrj && (CPP_OPTION (pfile, lang) == CLK_GNUCXX
537*38fd1498Szrj || CPP_OPTION (pfile, lang) == CLK_CXX98)))
538*38fd1498Szrj {
539*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_UTF_16__ 1");
540*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_UTF_32__ 1");
541*38fd1498Szrj }
542*38fd1498Szrj
543*38fd1498Szrj if (hosted)
544*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_HOSTED__ 1");
545*38fd1498Szrj else
546*38fd1498Szrj _cpp_define_builtin (pfile, "__STDC_HOSTED__ 0");
547*38fd1498Szrj
548*38fd1498Szrj if (CPP_OPTION (pfile, objc))
549*38fd1498Szrj _cpp_define_builtin (pfile, "__OBJC__ 1");
550*38fd1498Szrj }
551*38fd1498Szrj
552*38fd1498Szrj /* Sanity-checks are dependent on command-line options, so it is
553*38fd1498Szrj called as a subroutine of cpp_read_main_file. */
554*38fd1498Szrj #if CHECKING_P
555*38fd1498Szrj static void sanity_checks (cpp_reader *);
sanity_checks(cpp_reader * pfile)556*38fd1498Szrj static void sanity_checks (cpp_reader *pfile)
557*38fd1498Szrj {
558*38fd1498Szrj cppchar_t test = 0;
559*38fd1498Szrj size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part);
560*38fd1498Szrj
561*38fd1498Szrj /* Sanity checks for assumptions about CPP arithmetic and target
562*38fd1498Szrj type precisions made by cpplib. */
563*38fd1498Szrj test--;
564*38fd1498Szrj if (test < 1)
565*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE, "cppchar_t must be an unsigned type");
566*38fd1498Szrj
567*38fd1498Szrj if (CPP_OPTION (pfile, precision) > max_precision)
568*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE,
569*38fd1498Szrj "preprocessor arithmetic has maximum precision of %lu bits;"
570*38fd1498Szrj " target requires %lu bits",
571*38fd1498Szrj (unsigned long) max_precision,
572*38fd1498Szrj (unsigned long) CPP_OPTION (pfile, precision));
573*38fd1498Szrj
574*38fd1498Szrj if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision))
575*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE,
576*38fd1498Szrj "CPP arithmetic must be at least as precise as a target int");
577*38fd1498Szrj
578*38fd1498Szrj if (CPP_OPTION (pfile, char_precision) < 8)
579*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE, "target char is less than 8 bits wide");
580*38fd1498Szrj
581*38fd1498Szrj if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision))
582*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE,
583*38fd1498Szrj "target wchar_t is narrower than target char");
584*38fd1498Szrj
585*38fd1498Szrj if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision))
586*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE,
587*38fd1498Szrj "target int is narrower than target char");
588*38fd1498Szrj
589*38fd1498Szrj /* This is assumed in eval_token() and could be fixed if necessary. */
590*38fd1498Szrj if (sizeof (cppchar_t) > sizeof (cpp_num_part))
591*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE,
592*38fd1498Szrj "CPP half-integer narrower than CPP character");
593*38fd1498Szrj
594*38fd1498Szrj if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T)
595*38fd1498Szrj cpp_error (pfile, CPP_DL_ICE,
596*38fd1498Szrj "CPP on this host cannot handle wide character constants over"
597*38fd1498Szrj " %lu bits, but the target requires %lu bits",
598*38fd1498Szrj (unsigned long) BITS_PER_CPPCHAR_T,
599*38fd1498Szrj (unsigned long) CPP_OPTION (pfile, wchar_precision));
600*38fd1498Szrj }
601*38fd1498Szrj #else
602*38fd1498Szrj # define sanity_checks(PFILE)
603*38fd1498Szrj #endif
604*38fd1498Szrj
605*38fd1498Szrj /* This is called after options have been parsed, and partially
606*38fd1498Szrj processed. */
607*38fd1498Szrj void
cpp_post_options(cpp_reader * pfile)608*38fd1498Szrj cpp_post_options (cpp_reader *pfile)
609*38fd1498Szrj {
610*38fd1498Szrj int flags;
611*38fd1498Szrj
612*38fd1498Szrj sanity_checks (pfile);
613*38fd1498Szrj
614*38fd1498Szrj post_options (pfile);
615*38fd1498Szrj
616*38fd1498Szrj /* Mark named operators before handling command line macros. */
617*38fd1498Szrj flags = 0;
618*38fd1498Szrj if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
619*38fd1498Szrj flags |= NODE_OPERATOR;
620*38fd1498Szrj if (CPP_OPTION (pfile, warn_cxx_operator_names))
621*38fd1498Szrj flags |= NODE_DIAGNOSTIC | NODE_WARN_OPERATOR;
622*38fd1498Szrj if (flags != 0)
623*38fd1498Szrj mark_named_operators (pfile, flags);
624*38fd1498Szrj }
625*38fd1498Szrj
626*38fd1498Szrj /* Setup for processing input from the file named FNAME, or stdin if
627*38fd1498Szrj it is the empty string. Return the original filename
628*38fd1498Szrj on success (e.g. foo.i->foo.c), or NULL on failure. */
629*38fd1498Szrj const char *
cpp_read_main_file(cpp_reader * pfile,const char * fname)630*38fd1498Szrj cpp_read_main_file (cpp_reader *pfile, const char *fname)
631*38fd1498Szrj {
632*38fd1498Szrj const source_location loc = 0;
633*38fd1498Szrj
634*38fd1498Szrj if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
635*38fd1498Szrj {
636*38fd1498Szrj if (!pfile->deps)
637*38fd1498Szrj pfile->deps = deps_init ();
638*38fd1498Szrj
639*38fd1498Szrj /* Set the default target (if there is none already). */
640*38fd1498Szrj deps_add_default_target (pfile->deps, fname);
641*38fd1498Szrj }
642*38fd1498Szrj
643*38fd1498Szrj pfile->main_file
644*38fd1498Szrj = _cpp_find_file (pfile, fname, &pfile->no_search_path, false, 0, false,
645*38fd1498Szrj loc);
646*38fd1498Szrj if (_cpp_find_failed (pfile->main_file))
647*38fd1498Szrj return NULL;
648*38fd1498Szrj
649*38fd1498Szrj _cpp_stack_file (pfile, pfile->main_file, false, loc);
650*38fd1498Szrj
651*38fd1498Szrj /* For foo.i, read the original filename foo.c now, for the benefit
652*38fd1498Szrj of the front ends. */
653*38fd1498Szrj if (CPP_OPTION (pfile, preprocessed))
654*38fd1498Szrj {
655*38fd1498Szrj read_original_filename (pfile);
656*38fd1498Szrj fname =
657*38fd1498Szrj ORDINARY_MAP_FILE_NAME
658*38fd1498Szrj ((LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table)));
659*38fd1498Szrj }
660*38fd1498Szrj return fname;
661*38fd1498Szrj }
662*38fd1498Szrj
663*38fd1498Szrj /* For preprocessed files, if the first tokens are of the form # NUM.
664*38fd1498Szrj handle the directive so we know the original file name. This will
665*38fd1498Szrj generate file_change callbacks, which the front ends must handle
666*38fd1498Szrj appropriately given their state of initialization. */
667*38fd1498Szrj static void
read_original_filename(cpp_reader * pfile)668*38fd1498Szrj read_original_filename (cpp_reader *pfile)
669*38fd1498Szrj {
670*38fd1498Szrj const cpp_token *token, *token1;
671*38fd1498Szrj
672*38fd1498Szrj /* Lex ahead; if the first tokens are of the form # NUM, then
673*38fd1498Szrj process the directive, otherwise back up. */
674*38fd1498Szrj token = _cpp_lex_direct (pfile);
675*38fd1498Szrj if (token->type == CPP_HASH)
676*38fd1498Szrj {
677*38fd1498Szrj pfile->state.in_directive = 1;
678*38fd1498Szrj token1 = _cpp_lex_direct (pfile);
679*38fd1498Szrj _cpp_backup_tokens (pfile, 1);
680*38fd1498Szrj pfile->state.in_directive = 0;
681*38fd1498Szrj
682*38fd1498Szrj /* If it's a #line directive, handle it. */
683*38fd1498Szrj if (token1->type == CPP_NUMBER
684*38fd1498Szrj && _cpp_handle_directive (pfile, token->flags & PREV_WHITE))
685*38fd1498Szrj {
686*38fd1498Szrj read_original_directory (pfile);
687*38fd1498Szrj return;
688*38fd1498Szrj }
689*38fd1498Szrj }
690*38fd1498Szrj
691*38fd1498Szrj /* Backup as if nothing happened. */
692*38fd1498Szrj _cpp_backup_tokens (pfile, 1);
693*38fd1498Szrj }
694*38fd1498Szrj
695*38fd1498Szrj /* For preprocessed files, if the tokens following the first filename
696*38fd1498Szrj line is of the form # <line> "/path/name//", handle the
697*38fd1498Szrj directive so we know the original current directory. */
698*38fd1498Szrj static void
read_original_directory(cpp_reader * pfile)699*38fd1498Szrj read_original_directory (cpp_reader *pfile)
700*38fd1498Szrj {
701*38fd1498Szrj const cpp_token *hash, *token;
702*38fd1498Szrj
703*38fd1498Szrj /* Lex ahead; if the first tokens are of the form # NUM, then
704*38fd1498Szrj process the directive, otherwise back up. */
705*38fd1498Szrj hash = _cpp_lex_direct (pfile);
706*38fd1498Szrj if (hash->type != CPP_HASH)
707*38fd1498Szrj {
708*38fd1498Szrj _cpp_backup_tokens (pfile, 1);
709*38fd1498Szrj return;
710*38fd1498Szrj }
711*38fd1498Szrj
712*38fd1498Szrj token = _cpp_lex_direct (pfile);
713*38fd1498Szrj
714*38fd1498Szrj if (token->type != CPP_NUMBER)
715*38fd1498Szrj {
716*38fd1498Szrj _cpp_backup_tokens (pfile, 2);
717*38fd1498Szrj return;
718*38fd1498Szrj }
719*38fd1498Szrj
720*38fd1498Szrj token = _cpp_lex_direct (pfile);
721*38fd1498Szrj
722*38fd1498Szrj if (token->type != CPP_STRING
723*38fd1498Szrj || ! (token->val.str.len >= 5
724*38fd1498Szrj && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-2])
725*38fd1498Szrj && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-3])))
726*38fd1498Szrj {
727*38fd1498Szrj _cpp_backup_tokens (pfile, 3);
728*38fd1498Szrj return;
729*38fd1498Szrj }
730*38fd1498Szrj
731*38fd1498Szrj if (pfile->cb.dir_change)
732*38fd1498Szrj {
733*38fd1498Szrj char *debugdir = (char *) alloca (token->val.str.len - 3);
734*38fd1498Szrj
735*38fd1498Szrj memcpy (debugdir, (const char *) token->val.str.text + 1,
736*38fd1498Szrj token->val.str.len - 4);
737*38fd1498Szrj debugdir[token->val.str.len - 4] = '\0';
738*38fd1498Szrj
739*38fd1498Szrj pfile->cb.dir_change (pfile, debugdir);
740*38fd1498Szrj }
741*38fd1498Szrj }
742*38fd1498Szrj
743*38fd1498Szrj /* This is called at the end of preprocessing. It pops the last
744*38fd1498Szrj buffer and writes dependency output.
745*38fd1498Szrj
746*38fd1498Szrj Maybe it should also reset state, such that you could call
747*38fd1498Szrj cpp_start_read with a new filename to restart processing. */
748*38fd1498Szrj void
cpp_finish(cpp_reader * pfile,FILE * deps_stream)749*38fd1498Szrj cpp_finish (cpp_reader *pfile, FILE *deps_stream)
750*38fd1498Szrj {
751*38fd1498Szrj /* Warn about unused macros before popping the final buffer. */
752*38fd1498Szrj if (CPP_OPTION (pfile, warn_unused_macros))
753*38fd1498Szrj cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL);
754*38fd1498Szrj
755*38fd1498Szrj /* lex.c leaves the final buffer on the stack. This it so that
756*38fd1498Szrj it returns an unending stream of CPP_EOFs to the client. If we
757*38fd1498Szrj popped the buffer, we'd dereference a NULL buffer pointer and
758*38fd1498Szrj segfault. It's nice to allow the client to do worry-free excess
759*38fd1498Szrj cpp_get_token calls. */
760*38fd1498Szrj while (pfile->buffer)
761*38fd1498Szrj _cpp_pop_buffer (pfile);
762*38fd1498Szrj
763*38fd1498Szrj if (CPP_OPTION (pfile, deps.style) != DEPS_NONE
764*38fd1498Szrj && deps_stream)
765*38fd1498Szrj {
766*38fd1498Szrj deps_write (pfile->deps, deps_stream, 72);
767*38fd1498Szrj
768*38fd1498Szrj if (CPP_OPTION (pfile, deps.phony_targets))
769*38fd1498Szrj deps_phony_targets (pfile->deps, deps_stream);
770*38fd1498Szrj }
771*38fd1498Szrj
772*38fd1498Szrj /* Report on headers that could use multiple include guards. */
773*38fd1498Szrj if (CPP_OPTION (pfile, print_include_names))
774*38fd1498Szrj _cpp_report_missing_guards (pfile);
775*38fd1498Szrj }
776*38fd1498Szrj
777*38fd1498Szrj static void
post_options(cpp_reader * pfile)778*38fd1498Szrj post_options (cpp_reader *pfile)
779*38fd1498Szrj {
780*38fd1498Szrj /* -Wtraditional is not useful in C++ mode. */
781*38fd1498Szrj if (CPP_OPTION (pfile, cplusplus))
782*38fd1498Szrj CPP_OPTION (pfile, cpp_warn_traditional) = 0;
783*38fd1498Szrj
784*38fd1498Szrj /* Permanently disable macro expansion if we are rescanning
785*38fd1498Szrj preprocessed text. Read preprocesed source in ISO mode. */
786*38fd1498Szrj if (CPP_OPTION (pfile, preprocessed))
787*38fd1498Szrj {
788*38fd1498Szrj if (!CPP_OPTION (pfile, directives_only))
789*38fd1498Szrj pfile->state.prevent_expansion = 1;
790*38fd1498Szrj CPP_OPTION (pfile, traditional) = 0;
791*38fd1498Szrj }
792*38fd1498Szrj
793*38fd1498Szrj if (CPP_OPTION (pfile, warn_trigraphs) == 2)
794*38fd1498Szrj CPP_OPTION (pfile, warn_trigraphs) = !CPP_OPTION (pfile, trigraphs);
795*38fd1498Szrj
796*38fd1498Szrj if (CPP_OPTION (pfile, traditional))
797*38fd1498Szrj {
798*38fd1498Szrj CPP_OPTION (pfile, trigraphs) = 0;
799*38fd1498Szrj CPP_OPTION (pfile, warn_trigraphs) = 0;
800*38fd1498Szrj }
801*38fd1498Szrj }
802