Mercurial > hg > CbC > CbC_gcc
annotate libcpp/directives.c @ 136:4627f235cf2a
fix c-next example
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 08 Nov 2018 14:11:56 +0900 |
parents | 84e7813d76e9 |
children | 1830386684a0 |
rev | line source |
---|---|
0 | 1 /* CPP Library. (Directive handling.) |
131 | 2 Copyright (C) 1986-2018 Free Software Foundation, Inc. |
0 | 3 Contributed by Per Bothner, 1994-95. |
4 Based on CCCP program by Paul Rubin, June 1986 | |
5 Adapted to ANSI C, Richard Stallman, Jan 1987 | |
6 | |
7 This program is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3, or (at your option) any | |
10 later version. | |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with this program; see the file COPYING3. If not see | |
19 <http://www.gnu.org/licenses/>. */ | |
20 | |
21 #include "config.h" | |
22 #include "system.h" | |
23 #include "cpplib.h" | |
24 #include "internal.h" | |
25 #include "mkdeps.h" | |
26 #include "obstack.h" | |
27 | |
28 /* Stack of conditionals currently in progress | |
29 (including both successful and failing conditionals). */ | |
30 struct if_stack | |
31 { | |
32 struct if_stack *next; | |
111 | 33 source_location line; /* Line where condition started. */ |
0 | 34 const cpp_hashnode *mi_cmacro;/* macro name for #ifndef around entire file */ |
35 bool skip_elses; /* Can future #else / #elif be skipped? */ | |
36 bool was_skipping; /* If were skipping on entry. */ | |
37 int type; /* Most recent conditional for diagnostics. */ | |
38 }; | |
39 | |
40 /* Contains a registered pragma or pragma namespace. */ | |
41 typedef void (*pragma_cb) (cpp_reader *); | |
42 struct pragma_entry | |
43 { | |
44 struct pragma_entry *next; | |
45 const cpp_hashnode *pragma; /* Name and length. */ | |
46 bool is_nspace; | |
47 bool is_internal; | |
48 bool is_deferred; | |
49 bool allow_expansion; | |
50 union { | |
51 pragma_cb handler; | |
52 struct pragma_entry *space; | |
53 unsigned int ident; | |
54 } u; | |
55 }; | |
56 | |
57 /* Values for the origin field of struct directive. KANDR directives | |
58 come from traditional (K&R) C. STDC89 directives come from the | |
59 1989 C standard. EXTENSION directives are extensions. */ | |
60 #define KANDR 0 | |
61 #define STDC89 1 | |
62 #define EXTENSION 2 | |
63 | |
64 /* Values for the flags field of struct directive. COND indicates a | |
65 conditional; IF_COND an opening conditional. INCL means to treat | |
66 "..." and <...> as q-char and h-char sequences respectively. IN_I | |
67 means this directive should be handled even if -fpreprocessed is in | |
68 effect (these are the directives with callback hooks). | |
69 | |
70 EXPAND is set on directives that are always macro-expanded. */ | |
71 #define COND (1 << 0) | |
72 #define IF_COND (1 << 1) | |
73 #define INCL (1 << 2) | |
74 #define IN_I (1 << 3) | |
75 #define EXPAND (1 << 4) | |
76 #define DEPRECATED (1 << 5) | |
77 | |
78 /* Defines one #-directive, including how to handle it. */ | |
79 typedef void (*directive_handler) (cpp_reader *); | |
80 typedef struct directive directive; | |
81 struct directive | |
82 { | |
83 directive_handler handler; /* Function to handle directive. */ | |
84 const uchar *name; /* Name of directive. */ | |
85 unsigned short length; /* Length of name. */ | |
86 unsigned char origin; /* Origin of directive. */ | |
87 unsigned char flags; /* Flags describing this directive. */ | |
88 }; | |
89 | |
90 /* Forward declarations. */ | |
91 | |
92 static void skip_rest_of_line (cpp_reader *); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
93 static void check_eol (cpp_reader *, bool); |
0 | 94 static void start_directive (cpp_reader *); |
95 static void prepare_directive_trad (cpp_reader *); | |
96 static void end_directive (cpp_reader *, int); | |
97 static void directive_diagnostics (cpp_reader *, const directive *, int); | |
98 static void run_directive (cpp_reader *, int, const char *, size_t); | |
99 static char *glue_header_name (cpp_reader *); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
100 static const char *parse_include (cpp_reader *, int *, const cpp_token ***, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
101 source_location *); |
0 | 102 static void push_conditional (cpp_reader *, int, int, const cpp_hashnode *); |
103 static unsigned int read_flag (cpp_reader *, unsigned int); | |
104 static bool strtolinenum (const uchar *, size_t, linenum_type *, bool *); | |
131 | 105 static void do_diagnostic (cpp_reader *, enum cpp_diagnostic_level code, |
106 enum cpp_warning_reason reason, int); | |
0 | 107 static cpp_hashnode *lex_macro_node (cpp_reader *, bool); |
108 static int undefine_macros (cpp_reader *, cpp_hashnode *, void *); | |
109 static void do_include_common (cpp_reader *, enum include_type); | |
110 static struct pragma_entry *lookup_pragma_entry (struct pragma_entry *, | |
111 const cpp_hashnode *); | |
112 static int count_registered_pragmas (struct pragma_entry *); | |
113 static char ** save_registered_pragmas (struct pragma_entry *, char **); | |
114 static char ** restore_registered_pragmas (cpp_reader *, struct pragma_entry *, | |
115 char **); | |
116 static void do_pragma_once (cpp_reader *); | |
117 static void do_pragma_poison (cpp_reader *); | |
118 static void do_pragma_system_header (cpp_reader *); | |
119 static void do_pragma_dependency (cpp_reader *); | |
111 | 120 static void do_pragma_warning_or_error (cpp_reader *, bool error); |
121 static void do_pragma_warning (cpp_reader *); | |
122 static void do_pragma_error (cpp_reader *); | |
0 | 123 static void do_linemarker (cpp_reader *); |
124 static const cpp_token *get_token_no_padding (cpp_reader *); | |
125 static const cpp_token *get__Pragma_string (cpp_reader *); | |
111 | 126 static void destringize_and_run (cpp_reader *, const cpp_string *, |
127 source_location); | |
131 | 128 static bool parse_answer (cpp_reader *, int, source_location, cpp_macro **); |
129 static cpp_hashnode *parse_assertion (cpp_reader *, int, cpp_macro **); | |
130 static cpp_macro **find_answer (cpp_hashnode *, const cpp_macro *); | |
0 | 131 static void handle_assertion (cpp_reader *, const char *, int); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
132 static void do_pragma_push_macro (cpp_reader *); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
133 static void do_pragma_pop_macro (cpp_reader *); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
134 static void cpp_pop_definition (cpp_reader *, struct def_pragma_macro *); |
0 | 135 |
136 /* This is the table of directive handlers. It is ordered by | |
137 frequency of occurrence; the numbers at the end are directive | |
138 counts from all the source code I have lying around (egcs and libc | |
139 CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and | |
140 pcmcia-cs-3.0.9). This is no longer important as directive lookup | |
141 is now O(1). All extensions other than #warning, #include_next, | |
142 and #import are deprecated. The name is where the extension | |
143 appears to have come from. */ | |
144 | |
145 #define DIRECTIVE_TABLE \ | |
146 D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \ | |
147 D(include, T_INCLUDE, KANDR, INCL | EXPAND) /* 52262 */ \ | |
148 D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \ | |
149 D(ifdef, T_IFDEF, KANDR, COND | IF_COND) /* 22000 */ \ | |
150 D(if, T_IF, KANDR, COND | IF_COND | EXPAND) /* 18162 */ \ | |
151 D(else, T_ELSE, KANDR, COND) /* 9863 */ \ | |
152 D(ifndef, T_IFNDEF, KANDR, COND | IF_COND) /* 9675 */ \ | |
153 D(undef, T_UNDEF, KANDR, IN_I) /* 4837 */ \ | |
154 D(line, T_LINE, KANDR, EXPAND) /* 2465 */ \ | |
155 D(elif, T_ELIF, STDC89, COND | EXPAND) /* 610 */ \ | |
156 D(error, T_ERROR, STDC89, 0) /* 475 */ \ | |
157 D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \ | |
158 D(warning, T_WARNING, EXTENSION, 0) /* 22 */ \ | |
159 D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND) /* 19 */ \ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
160 D(ident, T_IDENT, EXTENSION, IN_I) /* 11 */ \ |
0 | 161 D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* 0 ObjC */ \ |
162 D(assert, T_ASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ | |
163 D(unassert, T_UNASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
164 D(sccs, T_SCCS, EXTENSION, IN_I) /* 0 SVR4? */ |
0 | 165 |
166 /* #sccs is synonymous with #ident. */ | |
167 #define do_sccs do_ident | |
168 | |
169 /* Use the table to generate a series of prototypes, an enum for the | |
170 directive names, and an array of directive handlers. */ | |
171 | |
172 #define D(name, t, o, f) static void do_##name (cpp_reader *); | |
173 DIRECTIVE_TABLE | |
174 #undef D | |
175 | |
176 #define D(n, tag, o, f) tag, | |
177 enum | |
178 { | |
179 DIRECTIVE_TABLE | |
180 N_DIRECTIVES | |
181 }; | |
182 #undef D | |
183 | |
184 #define D(name, t, origin, flags) \ | |
185 { do_##name, (const uchar *) #name, \ | |
186 sizeof #name - 1, origin, flags }, | |
187 static const directive dtable[] = | |
188 { | |
189 DIRECTIVE_TABLE | |
190 }; | |
191 #undef D | |
111 | 192 |
193 /* A NULL-terminated array of directive names for use | |
194 when suggesting corrections for misspelled directives. */ | |
195 #define D(name, t, origin, flags) #name, | |
196 static const char * const directive_names[] = { | |
197 DIRECTIVE_TABLE | |
198 NULL | |
199 }; | |
200 #undef D | |
201 | |
0 | 202 #undef DIRECTIVE_TABLE |
203 | |
204 /* Wrapper struct directive for linemarkers. | |
205 The origin is more or less true - the original K+R cpp | |
206 did use this notation in its preprocessed output. */ | |
207 static const directive linemarker_dir = | |
208 { | |
209 do_linemarker, UC"#", 1, KANDR, IN_I | |
210 }; | |
211 | |
212 #define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF) | |
213 | |
214 /* Skip any remaining tokens in a directive. */ | |
215 static void | |
216 skip_rest_of_line (cpp_reader *pfile) | |
217 { | |
218 /* Discard all stacked contexts. */ | |
219 while (pfile->context->prev) | |
220 _cpp_pop_context (pfile); | |
221 | |
222 /* Sweep up all tokens remaining on the line. */ | |
223 if (! SEEN_EOL ()) | |
224 while (_cpp_lex_token (pfile)->type != CPP_EOF) | |
225 ; | |
226 } | |
227 | |
111 | 228 /* Helper function for check_oel. */ |
229 | |
0 | 230 static void |
131 | 231 check_eol_1 (cpp_reader *pfile, bool expand, enum cpp_warning_reason reason) |
0 | 232 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
233 if (! SEEN_EOL () && (expand |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
234 ? cpp_get_token (pfile) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
235 : _cpp_lex_token (pfile))->type != CPP_EOF) |
111 | 236 cpp_pedwarning (pfile, reason, "extra tokens at end of #%s directive", |
237 pfile->directive->name); | |
238 } | |
239 | |
240 /* Variant of check_eol used for Wendif-labels warnings. */ | |
241 | |
242 static void | |
243 check_eol_endif_labels (cpp_reader *pfile) | |
244 { | |
245 check_eol_1 (pfile, false, CPP_W_ENDIF_LABELS); | |
246 } | |
247 | |
248 /* Ensure there are no stray tokens at the end of a directive. If | |
249 EXPAND is true, tokens macro-expanding to nothing are allowed. */ | |
250 | |
251 static void | |
252 check_eol (cpp_reader *pfile, bool expand) | |
253 { | |
254 check_eol_1 (pfile, expand, CPP_W_NONE); | |
0 | 255 } |
256 | |
257 /* Ensure there are no stray tokens other than comments at the end of | |
258 a directive, and gather the comments. */ | |
259 static const cpp_token ** | |
260 check_eol_return_comments (cpp_reader *pfile) | |
261 { | |
262 size_t c; | |
263 size_t capacity = 8; | |
264 const cpp_token **buf; | |
265 | |
266 buf = XNEWVEC (const cpp_token *, capacity); | |
267 c = 0; | |
268 if (! SEEN_EOL ()) | |
269 { | |
270 while (1) | |
271 { | |
272 const cpp_token *tok; | |
273 | |
274 tok = _cpp_lex_token (pfile); | |
275 if (tok->type == CPP_EOF) | |
276 break; | |
277 if (tok->type != CPP_COMMENT) | |
278 cpp_error (pfile, CPP_DL_PEDWARN, | |
279 "extra tokens at end of #%s directive", | |
280 pfile->directive->name); | |
281 else | |
282 { | |
283 if (c + 1 >= capacity) | |
284 { | |
285 capacity *= 2; | |
286 buf = XRESIZEVEC (const cpp_token *, buf, capacity); | |
287 } | |
288 buf[c] = tok; | |
289 ++c; | |
290 } | |
291 } | |
292 } | |
293 buf[c] = NULL; | |
294 return buf; | |
295 } | |
296 | |
297 /* Called when entering a directive, _Pragma or command-line directive. */ | |
298 static void | |
299 start_directive (cpp_reader *pfile) | |
300 { | |
301 /* Setup in-directive state. */ | |
302 pfile->state.in_directive = 1; | |
303 pfile->state.save_comments = 0; | |
304 pfile->directive_result.type = CPP_PADDING; | |
305 | |
306 /* Some handlers need the position of the # for diagnostics. */ | |
307 pfile->directive_line = pfile->line_table->highest_line; | |
308 } | |
309 | |
310 /* Called when leaving a directive, _Pragma or command-line directive. */ | |
311 static void | |
312 end_directive (cpp_reader *pfile, int skip_line) | |
313 { | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
314 if (CPP_OPTION (pfile, traditional)) |
0 | 315 { |
316 /* Revert change of prepare_directive_trad. */ | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
317 if (!pfile->state.in_deferred_pragma) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
318 pfile->state.prevent_expansion--; |
0 | 319 |
320 if (pfile->directive != &dtable[T_DEFINE]) | |
321 _cpp_remove_overlay (pfile); | |
322 } | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
323 else if (pfile->state.in_deferred_pragma) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
324 ; |
0 | 325 /* We don't skip for an assembler #. */ |
326 else if (skip_line) | |
327 { | |
328 skip_rest_of_line (pfile); | |
329 if (!pfile->keep_tokens) | |
330 { | |
331 pfile->cur_run = &pfile->base_run; | |
332 pfile->cur_token = pfile->base_run.base; | |
333 } | |
334 } | |
335 | |
336 /* Restore state. */ | |
337 pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); | |
338 pfile->state.in_directive = 0; | |
339 pfile->state.in_expression = 0; | |
340 pfile->state.angled_headers = 0; | |
341 pfile->directive = 0; | |
342 } | |
343 | |
344 /* Prepare to handle the directive in pfile->directive. */ | |
345 static void | |
346 prepare_directive_trad (cpp_reader *pfile) | |
347 { | |
348 if (pfile->directive != &dtable[T_DEFINE]) | |
349 { | |
350 bool no_expand = (pfile->directive | |
351 && ! (pfile->directive->flags & EXPAND)); | |
352 bool was_skipping = pfile->state.skipping; | |
353 | |
354 pfile->state.in_expression = (pfile->directive == &dtable[T_IF] | |
355 || pfile->directive == &dtable[T_ELIF]); | |
356 if (pfile->state.in_expression) | |
357 pfile->state.skipping = false; | |
358 | |
359 if (no_expand) | |
360 pfile->state.prevent_expansion++; | |
111 | 361 _cpp_scan_out_logical_line (pfile, NULL, false); |
0 | 362 if (no_expand) |
363 pfile->state.prevent_expansion--; | |
364 | |
365 pfile->state.skipping = was_skipping; | |
366 _cpp_overlay_buffer (pfile, pfile->out.base, | |
367 pfile->out.cur - pfile->out.base); | |
368 } | |
369 | |
370 /* Stop ISO C from expanding anything. */ | |
371 pfile->state.prevent_expansion++; | |
372 } | |
373 | |
374 /* Output diagnostics for a directive DIR. INDENTED is nonzero if | |
375 the '#' was indented. */ | |
376 static void | |
377 directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) | |
378 { | |
379 /* Issue -pedantic or deprecated warnings for extensions. We let | |
380 -pedantic take precedence if both are applicable. */ | |
381 if (! pfile->state.skipping) | |
382 { | |
383 if (dir->origin == EXTENSION | |
384 && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc)) | |
385 && CPP_PEDANTIC (pfile)) | |
386 cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); | |
387 else if (((dir->flags & DEPRECATED) != 0 | |
388 || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc))) | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
389 && CPP_OPTION (pfile, cpp_warn_deprecated)) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
390 cpp_warning (pfile, CPP_W_DEPRECATED, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
391 "#%s is a deprecated GCC extension", dir->name); |
0 | 392 } |
393 | |
394 /* Traditionally, a directive is ignored unless its # is in | |
395 column 1. Therefore in code intended to work with K+R | |
396 compilers, directives added by C89 must have their # | |
397 indented, and directives present in traditional C must not. | |
398 This is true even of directives in skipped conditional | |
399 blocks. #elif cannot be used at all. */ | |
400 if (CPP_WTRADITIONAL (pfile)) | |
401 { | |
402 if (dir == &dtable[T_ELIF]) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
403 cpp_warning (pfile, CPP_W_TRADITIONAL, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
404 "suggest not using #elif in traditional C"); |
0 | 405 else if (indented && dir->origin == KANDR) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
406 cpp_warning (pfile, CPP_W_TRADITIONAL, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
407 "traditional C ignores #%s with the # indented", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
408 dir->name); |
0 | 409 else if (!indented && dir->origin != KANDR) |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
410 cpp_warning (pfile, CPP_W_TRADITIONAL, |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
411 "suggest hiding #%s from traditional C with an indented #", |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
412 dir->name); |
0 | 413 } |
414 } | |
415 | |
416 /* Check if we have a known directive. INDENTED is nonzero if the | |
417 '#' of the directive was indented. This function is in this file | |
418 to save unnecessarily exporting dtable etc. to lex.c. Returns | |
419 nonzero if the line of tokens has been handled, zero if we should | |
420 continue processing the line. */ | |
421 int | |
422 _cpp_handle_directive (cpp_reader *pfile, int indented) | |
423 { | |
424 const directive *dir = 0; | |
425 const cpp_token *dname; | |
426 bool was_parsing_args = pfile->state.parsing_args; | |
427 bool was_discarding_output = pfile->state.discarding_output; | |
428 int skip = 1; | |
429 | |
430 if (was_discarding_output) | |
431 pfile->state.prevent_expansion = 0; | |
432 | |
433 if (was_parsing_args) | |
434 { | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
435 if (CPP_OPTION (pfile, cpp_pedantic)) |
0 | 436 cpp_error (pfile, CPP_DL_PEDWARN, |
437 "embedding a directive within macro arguments is not portable"); | |
438 pfile->state.parsing_args = 0; | |
439 pfile->state.prevent_expansion = 0; | |
440 } | |
441 start_directive (pfile); | |
442 dname = _cpp_lex_token (pfile); | |
443 | |
444 if (dname->type == CPP_NAME) | |
445 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
446 if (dname->val.node.node->is_directive) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
447 dir = &dtable[dname->val.node.node->directive_index]; |
0 | 448 } |
449 /* We do not recognize the # followed by a number extension in | |
450 assembler code. */ | |
451 else if (dname->type == CPP_NUMBER && CPP_OPTION (pfile, lang) != CLK_ASM) | |
452 { | |
453 dir = &linemarker_dir; | |
454 if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, preprocessed) | |
455 && ! pfile->state.skipping) | |
456 cpp_error (pfile, CPP_DL_PEDWARN, | |
457 "style of line directive is a GCC extension"); | |
458 } | |
459 | |
460 if (dir) | |
461 { | |
462 /* If we have a directive that is not an opening conditional, | |
463 invalidate any control macro. */ | |
464 if (! (dir->flags & IF_COND)) | |
465 pfile->mi_valid = false; | |
466 | |
467 /* Kluge alert. In order to be sure that code like this | |
468 | |
469 #define HASH # | |
470 HASH define foo bar | |
471 | |
472 does not cause '#define foo bar' to get executed when | |
473 compiled with -save-temps, we recognize directives in | |
474 -fpreprocessed mode only if the # is in column 1. macro.c | |
475 puts a space in front of any '#' at the start of a macro. | |
476 | |
477 We exclude the -fdirectives-only case because macro expansion | |
478 has not been performed yet, and block comments can cause spaces | |
111 | 479 to precede the directive. */ |
0 | 480 if (CPP_OPTION (pfile, preprocessed) |
481 && !CPP_OPTION (pfile, directives_only) | |
482 && (indented || !(dir->flags & IN_I))) | |
483 { | |
484 skip = 0; | |
485 dir = 0; | |
486 } | |
487 else | |
488 { | |
489 /* In failed conditional groups, all non-conditional | |
490 directives are ignored. Before doing that, whether | |
491 skipping or not, we should lex angle-bracketed headers | |
492 correctly, and maybe output some diagnostics. */ | |
493 pfile->state.angled_headers = dir->flags & INCL; | |
494 pfile->state.directive_wants_padding = dir->flags & INCL; | |
495 if (! CPP_OPTION (pfile, preprocessed)) | |
496 directive_diagnostics (pfile, dir, indented); | |
497 if (pfile->state.skipping && !(dir->flags & COND)) | |
498 dir = 0; | |
499 } | |
500 } | |
501 else if (dname->type == CPP_EOF) | |
502 ; /* CPP_EOF is the "null directive". */ | |
503 else | |
504 { | |
505 /* An unknown directive. Don't complain about it in assembly | |
506 source: we don't know where the comments are, and # may | |
507 introduce assembler pseudo-ops. Don't complain about invalid | |
508 directives in skipped conditional groups (6.10 p4). */ | |
509 if (CPP_OPTION (pfile, lang) == CLK_ASM) | |
510 skip = 0; | |
511 else if (!pfile->state.skipping) | |
111 | 512 { |
513 const char *unrecognized | |
514 = (const char *)cpp_token_as_text (pfile, dname); | |
515 const char *hint = NULL; | |
516 | |
517 /* Call back into gcc to get a spelling suggestion. Ideally | |
518 we'd just use best_match from gcc/spellcheck.h (and filter | |
519 out the uncommon directives), but that requires moving it | |
520 to a support library. */ | |
521 if (pfile->cb.get_suggestion) | |
522 hint = pfile->cb.get_suggestion (pfile, unrecognized, | |
523 directive_names); | |
524 | |
525 if (hint) | |
526 { | |
527 rich_location richloc (pfile->line_table, dname->src_loc); | |
528 source_range misspelled_token_range | |
529 = get_range_from_loc (pfile->line_table, dname->src_loc); | |
530 richloc.add_fixit_replace (misspelled_token_range, hint); | |
131 | 531 cpp_error_at (pfile, CPP_DL_ERROR, &richloc, |
532 "invalid preprocessing directive #%s;" | |
533 " did you mean #%s?", | |
534 unrecognized, hint); | |
111 | 535 } |
536 else | |
537 cpp_error (pfile, CPP_DL_ERROR, | |
538 "invalid preprocessing directive #%s", | |
539 unrecognized); | |
540 } | |
0 | 541 } |
542 | |
543 pfile->directive = dir; | |
544 if (CPP_OPTION (pfile, traditional)) | |
545 prepare_directive_trad (pfile); | |
546 | |
547 if (dir) | |
548 pfile->directive->handler (pfile); | |
549 else if (skip == 0) | |
550 _cpp_backup_tokens (pfile, 1); | |
551 | |
552 end_directive (pfile, skip); | |
553 if (was_parsing_args && !pfile->state.in_deferred_pragma) | |
554 { | |
555 /* Restore state when within macro args. */ | |
556 pfile->state.parsing_args = 2; | |
557 pfile->state.prevent_expansion = 1; | |
558 } | |
559 if (was_discarding_output) | |
560 pfile->state.prevent_expansion = 1; | |
561 return skip; | |
562 } | |
563 | |
564 /* Directive handler wrapper used by the command line option | |
565 processor. BUF is \n terminated. */ | |
566 static void | |
567 run_directive (cpp_reader *pfile, int dir_no, const char *buf, size_t count) | |
568 { | |
569 cpp_push_buffer (pfile, (const uchar *) buf, count, | |
570 /* from_stage3 */ true); | |
571 start_directive (pfile); | |
572 | |
573 /* This is a short-term fix to prevent a leading '#' being | |
574 interpreted as a directive. */ | |
575 _cpp_clean_line (pfile); | |
576 | |
577 pfile->directive = &dtable[dir_no]; | |
578 if (CPP_OPTION (pfile, traditional)) | |
579 prepare_directive_trad (pfile); | |
580 pfile->directive->handler (pfile); | |
581 end_directive (pfile, 1); | |
582 _cpp_pop_buffer (pfile); | |
583 } | |
584 | |
585 /* Checks for validity the macro name in #define, #undef, #ifdef and | |
586 #ifndef directives. IS_DEF_OR_UNDEF is true if this call is | |
587 processing a #define or #undefine directive, and false | |
588 otherwise. */ | |
589 static cpp_hashnode * | |
590 lex_macro_node (cpp_reader *pfile, bool is_def_or_undef) | |
591 { | |
592 const cpp_token *token = _cpp_lex_token (pfile); | |
593 | |
594 /* The token immediately after #define must be an identifier. That | |
595 identifier may not be "defined", per C99 6.10.8p4. | |
596 In C++, it may not be any of the "named operators" either, | |
597 per C++98 [lex.digraph], [lex.key]. | |
598 Finally, the identifier may not have been poisoned. (In that case | |
599 the lexer has issued the error message for us.) */ | |
600 | |
601 if (token->type == CPP_NAME) | |
602 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
603 cpp_hashnode *node = token->val.node.node; |
0 | 604 |
605 if (is_def_or_undef && node == pfile->spec_nodes.n_defined) | |
606 cpp_error (pfile, CPP_DL_ERROR, | |
607 "\"defined\" cannot be used as a macro name"); | |
111 | 608 else if (is_def_or_undef |
609 && (node == pfile->spec_nodes.n__has_include__ | |
610 || node == pfile->spec_nodes.n__has_include_next__)) | |
611 cpp_error (pfile, CPP_DL_ERROR, | |
612 "\"__has_include__\" cannot be used as a macro name"); | |
0 | 613 else if (! (node->flags & NODE_POISONED)) |
614 return node; | |
615 } | |
616 else if (token->flags & NAMED_OP) | |
617 cpp_error (pfile, CPP_DL_ERROR, | |
618 "\"%s\" cannot be used as a macro name as it is an operator in C++", | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
619 NODE_NAME (token->val.node.node)); |
0 | 620 else if (token->type == CPP_EOF) |
621 cpp_error (pfile, CPP_DL_ERROR, "no macro name given in #%s directive", | |
622 pfile->directive->name); | |
623 else | |
624 cpp_error (pfile, CPP_DL_ERROR, "macro names must be identifiers"); | |
625 | |
626 return NULL; | |
627 } | |
628 | |
629 /* Process a #define directive. Most work is done in macro.c. */ | |
630 static void | |
631 do_define (cpp_reader *pfile) | |
632 { | |
633 cpp_hashnode *node = lex_macro_node (pfile, true); | |
634 | |
635 if (node) | |
636 { | |
637 /* If we have been requested to expand comments into macros, | |
638 then re-enable saving of comments. */ | |
639 pfile->state.save_comments = | |
640 ! CPP_OPTION (pfile, discard_comments_in_macro_exp); | |
641 | |
642 if (pfile->cb.before_define) | |
643 pfile->cb.before_define (pfile); | |
644 | |
645 if (_cpp_create_definition (pfile, node)) | |
646 if (pfile->cb.define) | |
647 pfile->cb.define (pfile, pfile->directive_line, node); | |
648 | |
649 node->flags &= ~NODE_USED; | |
650 } | |
651 } | |
652 | |
653 /* Handle #undef. Mark the identifier NT_VOID in the hash table. */ | |
654 static void | |
655 do_undef (cpp_reader *pfile) | |
656 { | |
657 cpp_hashnode *node = lex_macro_node (pfile, true); | |
658 | |
659 if (node) | |
660 { | |
661 if (pfile->cb.before_define) | |
662 pfile->cb.before_define (pfile); | |
663 | |
664 if (pfile->cb.undef) | |
665 pfile->cb.undef (pfile, pfile->directive_line, node); | |
666 | |
667 /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified | |
668 identifier is not currently defined as a macro name. */ | |
131 | 669 if (cpp_macro_p (node)) |
0 | 670 { |
671 if (node->flags & NODE_WARN) | |
672 cpp_error (pfile, CPP_DL_WARNING, | |
673 "undefining \"%s\"", NODE_NAME (node)); | |
131 | 674 else if (cpp_builtin_macro_p (node) |
111 | 675 && CPP_OPTION (pfile, warn_builtin_macro_redefined)) |
676 cpp_warning_with_line (pfile, CPP_W_BUILTIN_MACRO_REDEFINED, | |
677 pfile->directive_line, 0, | |
678 "undefining \"%s\"", NODE_NAME (node)); | |
0 | 679 |
680 if (CPP_OPTION (pfile, warn_unused_macros)) | |
681 _cpp_warn_if_unused_macro (pfile, node, NULL); | |
682 | |
683 _cpp_free_definition (node); | |
684 } | |
685 } | |
686 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
687 check_eol (pfile, false); |
0 | 688 } |
689 | |
690 /* Undefine a single macro/assertion/whatever. */ | |
691 | |
692 static int | |
693 undefine_macros (cpp_reader *pfile ATTRIBUTE_UNUSED, cpp_hashnode *h, | |
694 void *data_p ATTRIBUTE_UNUSED) | |
695 { | |
696 /* Body of _cpp_free_definition inlined here for speed. | |
697 Macros and assertions no longer have anything to free. */ | |
698 h->type = NT_VOID; | |
131 | 699 h->value.answers = NULL; |
700 h->flags &= ~(NODE_POISONED|NODE_DISABLED|NODE_USED); | |
0 | 701 return 1; |
702 } | |
703 | |
704 /* Undefine all macros and assertions. */ | |
705 | |
706 void | |
707 cpp_undef_all (cpp_reader *pfile) | |
708 { | |
709 cpp_forall_identifiers (pfile, undefine_macros, NULL); | |
710 } | |
711 | |
712 | |
713 /* Helper routine used by parse_include. Reinterpret the current line | |
714 as an h-char-sequence (< ... >); we are looking at the first token | |
715 after the <. Returns a malloced filename. */ | |
716 static char * | |
717 glue_header_name (cpp_reader *pfile) | |
718 { | |
719 const cpp_token *token; | |
720 char *buffer; | |
721 size_t len, total_len = 0, capacity = 1024; | |
722 | |
723 /* To avoid lexed tokens overwriting our glued name, we can only | |
724 allocate from the string pool once we've lexed everything. */ | |
725 buffer = XNEWVEC (char, capacity); | |
726 for (;;) | |
727 { | |
728 token = get_token_no_padding (pfile); | |
729 | |
730 if (token->type == CPP_GREATER) | |
731 break; | |
732 if (token->type == CPP_EOF) | |
733 { | |
734 cpp_error (pfile, CPP_DL_ERROR, "missing terminating > character"); | |
735 break; | |
736 } | |
737 | |
738 len = cpp_token_len (token) + 2; /* Leading space, terminating \0. */ | |
739 if (total_len + len > capacity) | |
740 { | |
741 capacity = (capacity + len) * 2; | |
742 buffer = XRESIZEVEC (char, buffer, capacity); | |
743 } | |
744 | |
745 if (token->flags & PREV_WHITE) | |
746 buffer[total_len++] = ' '; | |
747 | |
748 total_len = (cpp_spell_token (pfile, token, (uchar *) &buffer[total_len], | |
749 true) | |
750 - (uchar *) buffer); | |
751 } | |
752 | |
753 buffer[total_len] = '\0'; | |
754 return buffer; | |
755 } | |
756 | |
757 /* Returns the file name of #include, #include_next, #import and | |
758 #pragma dependency. The string is malloced and the caller should | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
759 free it. Returns NULL on error. LOCATION is the source location |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
760 of the file name. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
761 |
0 | 762 static const char * |
763 parse_include (cpp_reader *pfile, int *pangle_brackets, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
764 const cpp_token ***buf, source_location *location) |
0 | 765 { |
766 char *fname; | |
767 const cpp_token *header; | |
768 | |
769 /* Allow macro expansion. */ | |
770 header = get_token_no_padding (pfile); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
771 *location = header->src_loc; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
772 if ((header->type == CPP_STRING && header->val.str.text[0] != 'R') |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
773 || header->type == CPP_HEADER_NAME) |
0 | 774 { |
775 fname = XNEWVEC (char, header->val.str.len - 1); | |
776 memcpy (fname, header->val.str.text + 1, header->val.str.len - 2); | |
777 fname[header->val.str.len - 2] = '\0'; | |
778 *pangle_brackets = header->type == CPP_HEADER_NAME; | |
779 } | |
780 else if (header->type == CPP_LESS) | |
781 { | |
782 fname = glue_header_name (pfile); | |
783 *pangle_brackets = 1; | |
784 } | |
785 else | |
786 { | |
787 const unsigned char *dir; | |
788 | |
789 if (pfile->directive == &dtable[T_PRAGMA]) | |
790 dir = UC"pragma dependency"; | |
791 else | |
792 dir = pfile->directive->name; | |
793 cpp_error (pfile, CPP_DL_ERROR, "#%s expects \"FILENAME\" or <FILENAME>", | |
794 dir); | |
795 | |
796 return NULL; | |
797 } | |
798 | |
799 if (pfile->directive == &dtable[T_PRAGMA]) | |
800 { | |
801 /* This pragma allows extra tokens after the file name. */ | |
802 } | |
803 else if (buf == NULL || CPP_OPTION (pfile, discard_comments)) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
804 check_eol (pfile, true); |
0 | 805 else |
806 { | |
807 /* If we are not discarding comments, then gather them while | |
808 doing the eol check. */ | |
809 *buf = check_eol_return_comments (pfile); | |
810 } | |
811 | |
812 return fname; | |
813 } | |
814 | |
815 /* Handle #include, #include_next and #import. */ | |
816 static void | |
817 do_include_common (cpp_reader *pfile, enum include_type type) | |
818 { | |
819 const char *fname; | |
820 int angle_brackets; | |
821 const cpp_token **buf = NULL; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
822 source_location location; |
0 | 823 |
824 /* Re-enable saving of comments if requested, so that the include | |
825 callback can dump comments which follow #include. */ | |
826 pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); | |
827 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
828 fname = parse_include (pfile, &angle_brackets, &buf, &location); |
0 | 829 if (!fname) |
830 { | |
831 if (buf) | |
832 XDELETEVEC (buf); | |
833 return; | |
834 } | |
835 | |
836 if (!*fname) | |
837 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
838 cpp_error_with_line (pfile, CPP_DL_ERROR, location, 0, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
839 "empty filename in #%s", |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
840 pfile->directive->name); |
0 | 841 XDELETEVEC (fname); |
842 if (buf) | |
843 XDELETEVEC (buf); | |
844 return; | |
845 } | |
846 | |
847 /* Prevent #include recursion. */ | |
848 if (pfile->line_table->depth >= CPP_STACK_MAX) | |
849 cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply"); | |
850 else | |
851 { | |
852 /* Get out of macro context, if we are. */ | |
853 skip_rest_of_line (pfile); | |
854 | |
855 if (pfile->cb.include) | |
856 pfile->cb.include (pfile, pfile->directive_line, | |
857 pfile->directive->name, fname, angle_brackets, | |
858 buf); | |
859 | |
111 | 860 _cpp_stack_include (pfile, fname, angle_brackets, type, location); |
0 | 861 } |
862 | |
863 XDELETEVEC (fname); | |
864 if (buf) | |
865 XDELETEVEC (buf); | |
866 } | |
867 | |
868 static void | |
869 do_include (cpp_reader *pfile) | |
870 { | |
871 do_include_common (pfile, IT_INCLUDE); | |
872 } | |
873 | |
874 static void | |
875 do_import (cpp_reader *pfile) | |
876 { | |
877 do_include_common (pfile, IT_IMPORT); | |
878 } | |
879 | |
880 static void | |
881 do_include_next (cpp_reader *pfile) | |
882 { | |
883 enum include_type type = IT_INCLUDE_NEXT; | |
884 | |
885 /* If this is the primary source file, warn and use the normal | |
886 search logic. */ | |
887 if (cpp_in_primary_file (pfile)) | |
888 { | |
889 cpp_error (pfile, CPP_DL_WARNING, | |
890 "#include_next in primary source file"); | |
891 type = IT_INCLUDE; | |
892 } | |
893 do_include_common (pfile, type); | |
894 } | |
895 | |
896 /* Subroutine of do_linemarker. Read possible flags after file name. | |
897 LAST is the last flag seen; 0 if this is the first flag. Return the | |
898 flag if it is valid, 0 at the end of the directive. Otherwise | |
899 complain. */ | |
900 static unsigned int | |
901 read_flag (cpp_reader *pfile, unsigned int last) | |
902 { | |
903 const cpp_token *token = _cpp_lex_token (pfile); | |
904 | |
905 if (token->type == CPP_NUMBER && token->val.str.len == 1) | |
906 { | |
907 unsigned int flag = token->val.str.text[0] - '0'; | |
908 | |
909 if (flag > last && flag <= 4 | |
910 && (flag != 4 || last == 3) | |
911 && (flag != 2 || last == 0)) | |
912 return flag; | |
913 } | |
914 | |
915 if (token->type != CPP_EOF) | |
916 cpp_error (pfile, CPP_DL_ERROR, "invalid flag \"%s\" in line directive", | |
917 cpp_token_as_text (pfile, token)); | |
918 return 0; | |
919 } | |
920 | |
921 /* Subroutine of do_line and do_linemarker. Convert a number in STR, | |
922 of length LEN, to binary; store it in NUMP, and return false if the | |
923 number was well-formed, true if not. WRAPPED is set to true if the | |
924 number did not fit into 'unsigned long'. */ | |
925 static bool | |
926 strtolinenum (const uchar *str, size_t len, linenum_type *nump, bool *wrapped) | |
927 { | |
928 linenum_type reg = 0; | |
929 linenum_type reg_prev = 0; | |
930 | |
931 uchar c; | |
932 *wrapped = false; | |
933 while (len--) | |
934 { | |
935 c = *str++; | |
936 if (!ISDIGIT (c)) | |
937 return true; | |
938 reg *= 10; | |
939 reg += c - '0'; | |
940 if (reg < reg_prev) | |
941 *wrapped = true; | |
942 reg_prev = reg; | |
943 } | |
944 *nump = reg; | |
945 return false; | |
946 } | |
947 | |
948 /* Interpret #line command. | |
949 Note that the filename string (if any) is a true string constant | |
950 (escapes are interpreted), unlike in #line. */ | |
951 static void | |
952 do_line (cpp_reader *pfile) | |
953 { | |
111 | 954 struct line_maps *line_table = pfile->line_table; |
955 const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table); | |
0 | 956 |
957 /* skip_rest_of_line() may cause line table to be realloc()ed so note down | |
958 sysp right now. */ | |
959 | |
111 | 960 unsigned char map_sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (map); |
0 | 961 const cpp_token *token; |
111 | 962 const char *new_file = ORDINARY_MAP_FILE_NAME (map); |
0 | 963 linenum_type new_lineno; |
964 | |
965 /* C99 raised the minimum limit on #line numbers. */ | |
966 linenum_type cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767; | |
967 bool wrapped; | |
968 | |
969 /* #line commands expand macros. */ | |
970 token = cpp_get_token (pfile); | |
971 if (token->type != CPP_NUMBER | |
972 || strtolinenum (token->val.str.text, token->val.str.len, | |
973 &new_lineno, &wrapped)) | |
974 { | |
975 if (token->type == CPP_EOF) | |
976 cpp_error (pfile, CPP_DL_ERROR, "unexpected end of file after #line"); | |
977 else | |
978 cpp_error (pfile, CPP_DL_ERROR, | |
979 "\"%s\" after #line is not a positive integer", | |
980 cpp_token_as_text (pfile, token)); | |
981 return; | |
982 } | |
983 | |
984 if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap || wrapped)) | |
985 cpp_error (pfile, CPP_DL_PEDWARN, "line number out of range"); | |
986 else if (wrapped) | |
987 cpp_error (pfile, CPP_DL_WARNING, "line number out of range"); | |
988 | |
989 token = cpp_get_token (pfile); | |
990 if (token->type == CPP_STRING) | |
991 { | |
992 cpp_string s = { 0, 0 }; | |
993 if (cpp_interpret_string_notranslate (pfile, &token->val.str, 1, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
994 &s, CPP_STRING)) |
0 | 995 new_file = (const char *)s.text; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
996 check_eol (pfile, true); |
0 | 997 } |
998 else if (token->type != CPP_EOF) | |
999 { | |
1000 cpp_error (pfile, CPP_DL_ERROR, "\"%s\" is not a valid filename", | |
1001 cpp_token_as_text (pfile, token)); | |
1002 return; | |
1003 } | |
1004 | |
1005 skip_rest_of_line (pfile); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1006 _cpp_do_file_change (pfile, LC_RENAME_VERBATIM, new_file, new_lineno, |
0 | 1007 map_sysp); |
111 | 1008 line_table->seen_line_directive = true; |
0 | 1009 } |
1010 | |
1011 /* Interpret the # 44 "file" [flags] notation, which has slightly | |
1012 different syntax and semantics from #line: Flags are allowed, | |
1013 and we never complain about the line number being too big. */ | |
1014 static void | |
1015 do_linemarker (cpp_reader *pfile) | |
1016 { | |
111 | 1017 struct line_maps *line_table = pfile->line_table; |
1018 const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table); | |
0 | 1019 const cpp_token *token; |
111 | 1020 const char *new_file = ORDINARY_MAP_FILE_NAME (map); |
0 | 1021 linenum_type new_lineno; |
111 | 1022 unsigned int new_sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (map); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1023 enum lc_reason reason = LC_RENAME_VERBATIM; |
0 | 1024 int flag; |
1025 bool wrapped; | |
1026 | |
1027 /* Back up so we can get the number again. Putting this in | |
1028 _cpp_handle_directive risks two calls to _cpp_backup_tokens in | |
1029 some circumstances, which can segfault. */ | |
1030 _cpp_backup_tokens (pfile, 1); | |
1031 | |
1032 /* #line commands expand macros. */ | |
1033 token = cpp_get_token (pfile); | |
1034 if (token->type != CPP_NUMBER | |
1035 || strtolinenum (token->val.str.text, token->val.str.len, | |
1036 &new_lineno, &wrapped)) | |
1037 { | |
1038 /* Unlike #line, there does not seem to be a way to get an EOF | |
1039 here. So, it should be safe to always spell the token. */ | |
1040 cpp_error (pfile, CPP_DL_ERROR, | |
1041 "\"%s\" after # is not a positive integer", | |
1042 cpp_token_as_text (pfile, token)); | |
1043 return; | |
1044 } | |
1045 | |
1046 token = cpp_get_token (pfile); | |
1047 if (token->type == CPP_STRING) | |
1048 { | |
1049 cpp_string s = { 0, 0 }; | |
1050 if (cpp_interpret_string_notranslate (pfile, &token->val.str, | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1051 1, &s, CPP_STRING)) |
0 | 1052 new_file = (const char *)s.text; |
1053 | |
1054 new_sysp = 0; | |
1055 flag = read_flag (pfile, 0); | |
1056 if (flag == 1) | |
1057 { | |
1058 reason = LC_ENTER; | |
1059 /* Fake an include for cpp_included (). */ | |
1060 _cpp_fake_include (pfile, new_file); | |
1061 flag = read_flag (pfile, flag); | |
1062 } | |
1063 else if (flag == 2) | |
1064 { | |
1065 reason = LC_LEAVE; | |
1066 flag = read_flag (pfile, flag); | |
1067 } | |
1068 if (flag == 3) | |
1069 { | |
1070 new_sysp = 1; | |
1071 flag = read_flag (pfile, flag); | |
1072 if (flag == 4) | |
1073 new_sysp = 2; | |
1074 } | |
1075 pfile->buffer->sysp = new_sysp; | |
1076 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1077 check_eol (pfile, false); |
0 | 1078 } |
1079 else if (token->type != CPP_EOF) | |
1080 { | |
1081 cpp_error (pfile, CPP_DL_ERROR, "\"%s\" is not a valid filename", | |
1082 cpp_token_as_text (pfile, token)); | |
1083 return; | |
1084 } | |
1085 | |
1086 skip_rest_of_line (pfile); | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1087 |
111 | 1088 if (reason == LC_LEAVE) |
1089 { | |
1090 /* Reread map since cpp_get_token can invalidate it with a | |
1091 reallocation. */ | |
1092 map = LINEMAPS_LAST_ORDINARY_MAP (line_table); | |
131 | 1093 const line_map_ordinary *from |
1094 = linemap_included_from_linemap (line_table, map); | |
111 | 1095 if (MAIN_FILE_P (map) |
131 | 1096 || (from |
111 | 1097 && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0)) |
1098 { | |
1099 cpp_warning (pfile, CPP_W_NONE, | |
1100 "file \"%s\" linemarker ignored due to " | |
1101 "incorrect nesting", new_file); | |
1102 return; | |
1103 } | |
1104 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1105 /* Compensate for the increment in linemap_add that occurs in |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1106 _cpp_do_file_change. We're currently at the start of the line |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1107 *following* the #line directive. A separate source_location for this |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1108 location makes no sense (until we do the LC_LEAVE), and |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1109 complicates LAST_SOURCE_LINE_LOCATION. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1110 pfile->line_table->highest_location--; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1111 |
0 | 1112 _cpp_do_file_change (pfile, reason, new_file, new_lineno, new_sysp); |
111 | 1113 line_table->seen_line_directive = true; |
0 | 1114 } |
1115 | |
1116 /* Arrange the file_change callback. pfile->line has changed to | |
1117 FILE_LINE of TO_FILE, for reason REASON. SYSP is 1 for a system | |
1118 header, 2 for a system header that needs to be extern "C" protected, | |
1119 and zero otherwise. */ | |
1120 void | |
1121 _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason, | |
1122 const char *to_file, linenum_type file_line, | |
1123 unsigned int sysp) | |
1124 { | |
111 | 1125 linemap_assert (reason != LC_ENTER_MACRO); |
0 | 1126 const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, |
1127 to_file, file_line); | |
111 | 1128 const line_map_ordinary *ord_map = NULL; |
0 | 1129 if (map != NULL) |
111 | 1130 { |
1131 ord_map = linemap_check_ordinary (map); | |
1132 linemap_line_start (pfile->line_table, | |
1133 ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map), | |
1134 127); | |
1135 } | |
0 | 1136 |
1137 if (pfile->cb.file_change) | |
111 | 1138 pfile->cb.file_change (pfile, ord_map); |
0 | 1139 } |
1140 | |
1141 /* Report a warning or error detected by the program we are | |
1142 processing. Use the directive's tokens in the error message. */ | |
1143 static void | |
131 | 1144 do_diagnostic (cpp_reader *pfile, enum cpp_diagnostic_level code, |
1145 enum cpp_warning_reason reason, int print_dir) | |
0 | 1146 { |
1147 const unsigned char *dir_name; | |
1148 unsigned char *line; | |
1149 source_location src_loc = pfile->cur_token[-1].src_loc; | |
1150 | |
1151 if (print_dir) | |
1152 dir_name = pfile->directive->name; | |
1153 else | |
1154 dir_name = NULL; | |
1155 pfile->state.prevent_expansion++; | |
1156 line = cpp_output_line_to_string (pfile, dir_name); | |
1157 pfile->state.prevent_expansion--; | |
1158 | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1159 if (code == CPP_DL_WARNING_SYSHDR && reason) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1160 cpp_warning_with_line_syshdr (pfile, reason, src_loc, 0, "%s", line); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1161 else if (code == CPP_DL_WARNING && reason) |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1162 cpp_warning_with_line (pfile, reason, src_loc, 0, "%s", line); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1163 else |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1164 cpp_error_with_line (pfile, code, src_loc, 0, "%s", line); |
0 | 1165 free (line); |
1166 } | |
1167 | |
1168 static void | |
1169 do_error (cpp_reader *pfile) | |
1170 { | |
131 | 1171 do_diagnostic (pfile, CPP_DL_ERROR, CPP_W_NONE, 1); |
0 | 1172 } |
1173 | |
1174 static void | |
1175 do_warning (cpp_reader *pfile) | |
1176 { | |
1177 /* We want #warning diagnostics to be emitted in system headers too. */ | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
1178 do_diagnostic (pfile, CPP_DL_WARNING_SYSHDR, CPP_W_WARNING_DIRECTIVE, 1); |
0 | 1179 } |
1180 | |
1181 /* Report program identification. */ | |
1182 static void | |
1183 do_ident (cpp_reader *pfile) | |
1184 { | |
1185 const cpp_token *str = cpp_get_token (pfile); | |
1186 | |
1187 if (str->type != CPP_STRING) | |
1188 cpp_error (pfile, CPP_DL_ERROR, "invalid #%s directive", | |
1189 pfile->directive->name); | |
1190 else if (pfile->cb.ident) | |
1191 pfile->cb.ident (pfile, pfile->directive_line, &str->val.str); | |
1192 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1193 check_eol (pfile, false); |
0 | 1194 } |
1195 | |
1196 /* Lookup a PRAGMA name in a singly-linked CHAIN. Returns the | |
1197 matching entry, or NULL if none is found. The returned entry could | |
1198 be the start of a namespace chain, or a pragma. */ | |
1199 static struct pragma_entry * | |
1200 lookup_pragma_entry (struct pragma_entry *chain, const cpp_hashnode *pragma) | |
1201 { | |
1202 while (chain && chain->pragma != pragma) | |
1203 chain = chain->next; | |
1204 | |
1205 return chain; | |
1206 } | |
1207 | |
1208 /* Create and insert a blank pragma entry at the beginning of a | |
1209 singly-linked CHAIN. */ | |
1210 static struct pragma_entry * | |
1211 new_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain) | |
1212 { | |
1213 struct pragma_entry *new_entry; | |
1214 | |
1215 new_entry = (struct pragma_entry *) | |
1216 _cpp_aligned_alloc (pfile, sizeof (struct pragma_entry)); | |
1217 | |
1218 memset (new_entry, 0, sizeof (struct pragma_entry)); | |
1219 new_entry->next = *chain; | |
1220 | |
1221 *chain = new_entry; | |
1222 return new_entry; | |
1223 } | |
1224 | |
1225 /* Register a pragma NAME in namespace SPACE. If SPACE is null, it | |
1226 goes in the global namespace. */ | |
1227 static struct pragma_entry * | |
1228 register_pragma_1 (cpp_reader *pfile, const char *space, const char *name, | |
1229 bool allow_name_expansion) | |
1230 { | |
1231 struct pragma_entry **chain = &pfile->pragmas; | |
1232 struct pragma_entry *entry; | |
1233 const cpp_hashnode *node; | |
1234 | |
1235 if (space) | |
1236 { | |
1237 node = cpp_lookup (pfile, UC space, strlen (space)); | |
1238 entry = lookup_pragma_entry (*chain, node); | |
1239 if (!entry) | |
1240 { | |
1241 entry = new_pragma_entry (pfile, chain); | |
1242 entry->pragma = node; | |
1243 entry->is_nspace = true; | |
1244 entry->allow_expansion = allow_name_expansion; | |
1245 } | |
1246 else if (!entry->is_nspace) | |
1247 goto clash; | |
1248 else if (entry->allow_expansion != allow_name_expansion) | |
1249 { | |
1250 cpp_error (pfile, CPP_DL_ICE, | |
1251 "registering pragmas in namespace \"%s\" with mismatched " | |
1252 "name expansion", space); | |
1253 return NULL; | |
1254 } | |
1255 chain = &entry->u.space; | |
1256 } | |
1257 else if (allow_name_expansion) | |
1258 { | |
1259 cpp_error (pfile, CPP_DL_ICE, | |
1260 "registering pragma \"%s\" with name expansion " | |
1261 "and no namespace", name); | |
1262 return NULL; | |
1263 } | |
1264 | |
1265 /* Check for duplicates. */ | |
1266 node = cpp_lookup (pfile, UC name, strlen (name)); | |
1267 entry = lookup_pragma_entry (*chain, node); | |
1268 if (entry == NULL) | |
1269 { | |
1270 entry = new_pragma_entry (pfile, chain); | |
1271 entry->pragma = node; | |
1272 return entry; | |
1273 } | |
1274 | |
1275 if (entry->is_nspace) | |
1276 clash: | |
1277 cpp_error (pfile, CPP_DL_ICE, | |
1278 "registering \"%s\" as both a pragma and a pragma namespace", | |
1279 NODE_NAME (node)); | |
1280 else if (space) | |
1281 cpp_error (pfile, CPP_DL_ICE, "#pragma %s %s is already registered", | |
1282 space, name); | |
1283 else | |
1284 cpp_error (pfile, CPP_DL_ICE, "#pragma %s is already registered", name); | |
1285 | |
1286 return NULL; | |
1287 } | |
1288 | |
1289 /* Register a cpplib internal pragma SPACE NAME with HANDLER. */ | |
1290 static void | |
1291 register_pragma_internal (cpp_reader *pfile, const char *space, | |
1292 const char *name, pragma_cb handler) | |
1293 { | |
1294 struct pragma_entry *entry; | |
1295 | |
1296 entry = register_pragma_1 (pfile, space, name, false); | |
1297 entry->is_internal = true; | |
1298 entry->u.handler = handler; | |
1299 } | |
1300 | |
1301 /* Register a pragma NAME in namespace SPACE. If SPACE is null, it | |
1302 goes in the global namespace. HANDLER is the handler it will call, | |
1303 which must be non-NULL. If ALLOW_EXPANSION is set, allow macro | |
1304 expansion while parsing pragma NAME. This function is exported | |
1305 from libcpp. */ | |
1306 void | |
1307 cpp_register_pragma (cpp_reader *pfile, const char *space, const char *name, | |
1308 pragma_cb handler, bool allow_expansion) | |
1309 { | |
1310 struct pragma_entry *entry; | |
1311 | |
1312 if (!handler) | |
1313 { | |
1314 cpp_error (pfile, CPP_DL_ICE, "registering pragma with NULL handler"); | |
1315 return; | |
1316 } | |
1317 | |
1318 entry = register_pragma_1 (pfile, space, name, false); | |
1319 if (entry) | |
1320 { | |
1321 entry->allow_expansion = allow_expansion; | |
1322 entry->u.handler = handler; | |
1323 } | |
1324 } | |
1325 | |
1326 /* Similarly, but create mark the pragma for deferred processing. | |
1327 When found, a CPP_PRAGMA token will be insertted into the stream | |
1328 with IDENT in the token->u.pragma slot. */ | |
1329 void | |
1330 cpp_register_deferred_pragma (cpp_reader *pfile, const char *space, | |
1331 const char *name, unsigned int ident, | |
1332 bool allow_expansion, bool allow_name_expansion) | |
1333 { | |
1334 struct pragma_entry *entry; | |
1335 | |
1336 entry = register_pragma_1 (pfile, space, name, allow_name_expansion); | |
1337 if (entry) | |
1338 { | |
1339 entry->is_deferred = true; | |
1340 entry->allow_expansion = allow_expansion; | |
1341 entry->u.ident = ident; | |
1342 } | |
1343 } | |
1344 | |
1345 /* Register the pragmas the preprocessor itself handles. */ | |
1346 void | |
1347 _cpp_init_internal_pragmas (cpp_reader *pfile) | |
1348 { | |
1349 /* Pragmas in the global namespace. */ | |
1350 register_pragma_internal (pfile, 0, "once", do_pragma_once); | |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1351 register_pragma_internal (pfile, 0, "push_macro", do_pragma_push_macro); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1352 register_pragma_internal (pfile, 0, "pop_macro", do_pragma_pop_macro); |
0 | 1353 |
1354 /* New GCC-specific pragmas should be put in the GCC namespace. */ | |
1355 register_pragma_internal (pfile, "GCC", "poison", do_pragma_poison); | |
1356 register_pragma_internal (pfile, "GCC", "system_header", | |
1357 do_pragma_system_header); | |
1358 register_pragma_internal (pfile, "GCC", "dependency", do_pragma_dependency); | |
111 | 1359 register_pragma_internal (pfile, "GCC", "warning", do_pragma_warning); |
1360 register_pragma_internal (pfile, "GCC", "error", do_pragma_error); | |
0 | 1361 } |
1362 | |
1363 /* Return the number of registered pragmas in PE. */ | |
1364 | |
1365 static int | |
1366 count_registered_pragmas (struct pragma_entry *pe) | |
1367 { | |
1368 int ct = 0; | |
1369 for (; pe != NULL; pe = pe->next) | |
1370 { | |
1371 if (pe->is_nspace) | |
1372 ct += count_registered_pragmas (pe->u.space); | |
1373 ct++; | |
1374 } | |
1375 return ct; | |
1376 } | |
1377 | |
1378 /* Save into SD the names of the registered pragmas referenced by PE, | |
1379 and return a pointer to the next free space in SD. */ | |
1380 | |
1381 static char ** | |
1382 save_registered_pragmas (struct pragma_entry *pe, char **sd) | |
1383 { | |
1384 for (; pe != NULL; pe = pe->next) | |
1385 { | |
1386 if (pe->is_nspace) | |
1387 sd = save_registered_pragmas (pe->u.space, sd); | |
1388 *sd++ = (char *) xmemdup (HT_STR (&pe->pragma->ident), | |
1389 HT_LEN (&pe->pragma->ident), | |
1390 HT_LEN (&pe->pragma->ident) + 1); | |
1391 } | |
1392 return sd; | |
1393 } | |
1394 | |
1395 /* Return a newly-allocated array which saves the names of the | |
1396 registered pragmas. */ | |
1397 | |
1398 char ** | |
1399 _cpp_save_pragma_names (cpp_reader *pfile) | |
1400 { | |
1401 int ct = count_registered_pragmas (pfile->pragmas); | |
1402 char **result = XNEWVEC (char *, ct); | |
1403 (void) save_registered_pragmas (pfile->pragmas, result); | |
1404 return result; | |
1405 } | |
1406 | |
1407 /* Restore from SD the names of the registered pragmas referenced by PE, | |
1408 and return a pointer to the next unused name in SD. */ | |
1409 | |
1410 static char ** | |
1411 restore_registered_pragmas (cpp_reader *pfile, struct pragma_entry *pe, | |
1412 char **sd) | |
1413 { | |
1414 for (; pe != NULL; pe = pe->next) | |
1415 { | |
1416 if (pe->is_nspace) | |
1417 sd = restore_registered_pragmas (pfile, pe->u.space, sd); | |
1418 pe->pragma = cpp_lookup (pfile, UC *sd, strlen (*sd)); | |
1419 free (*sd); | |
1420 sd++; | |
1421 } | |
1422 return sd; | |
1423 } | |
1424 | |
1425 /* Restore the names of the registered pragmas from SAVED. */ | |
1426 | |
1427 void | |
1428 _cpp_restore_pragma_names (cpp_reader *pfile, char **saved) | |
1429 { | |
1430 (void) restore_registered_pragmas (pfile, pfile->pragmas, saved); | |
1431 free (saved); | |
1432 } | |
1433 | |
1434 /* Pragmata handling. We handle some, and pass the rest on to the | |
1435 front end. C99 defines three pragmas and says that no macro | |
1436 expansion is to be performed on them; whether or not macro | |
1437 expansion happens for other pragmas is implementation defined. | |
1438 This implementation allows for a mix of both, since GCC did not | |
1439 traditionally macro expand its (few) pragmas, whereas OpenMP | |
1440 specifies that macro expansion should happen. */ | |
1441 static void | |
1442 do_pragma (cpp_reader *pfile) | |
1443 { | |
1444 const struct pragma_entry *p = NULL; | |
111 | 1445 const cpp_token *token, *pragma_token; |
1446 source_location pragma_token_virt_loc = 0; | |
0 | 1447 cpp_token ns_token; |
1448 unsigned int count = 1; | |
1449 | |
1450 pfile->state.prevent_expansion++; | |
1451 | |
111 | 1452 pragma_token = token = cpp_get_token_with_location (pfile, |
1453 &pragma_token_virt_loc); | |
0 | 1454 ns_token = *token; |
1455 if (token->type == CPP_NAME) | |
1456 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1457 p = lookup_pragma_entry (pfile->pragmas, token->val.node.node); |
0 | 1458 if (p && p->is_nspace) |
1459 { | |
1460 bool allow_name_expansion = p->allow_expansion; | |
1461 if (allow_name_expansion) | |
1462 pfile->state.prevent_expansion--; | |
111 | 1463 |
0 | 1464 token = cpp_get_token (pfile); |
1465 if (token->type == CPP_NAME) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1466 p = lookup_pragma_entry (p->u.space, token->val.node.node); |
0 | 1467 else |
1468 p = NULL; | |
1469 if (allow_name_expansion) | |
1470 pfile->state.prevent_expansion++; | |
1471 count = 2; | |
1472 } | |
1473 } | |
1474 | |
1475 if (p) | |
1476 { | |
1477 if (p->is_deferred) | |
1478 { | |
111 | 1479 pfile->directive_result.src_loc = pragma_token_virt_loc; |
0 | 1480 pfile->directive_result.type = CPP_PRAGMA; |
1481 pfile->directive_result.flags = pragma_token->flags; | |
1482 pfile->directive_result.val.pragma = p->u.ident; | |
1483 pfile->state.in_deferred_pragma = true; | |
1484 pfile->state.pragma_allow_expansion = p->allow_expansion; | |
1485 if (!p->allow_expansion) | |
1486 pfile->state.prevent_expansion++; | |
1487 } | |
1488 else | |
1489 { | |
1490 /* Since the handler below doesn't get the line number, that | |
1491 it might need for diagnostics, make sure it has the right | |
1492 numbers in place. */ | |
1493 if (pfile->cb.line_change) | |
1494 (*pfile->cb.line_change) (pfile, pragma_token, false); | |
1495 if (p->allow_expansion) | |
1496 pfile->state.prevent_expansion--; | |
1497 (*p->u.handler) (pfile); | |
1498 if (p->allow_expansion) | |
1499 pfile->state.prevent_expansion++; | |
1500 } | |
1501 } | |
1502 else if (pfile->cb.def_pragma) | |
1503 { | |
1504 if (count == 1 || pfile->context->prev == NULL) | |
1505 _cpp_backup_tokens (pfile, count); | |
1506 else | |
1507 { | |
1508 /* Invalid name comes from macro expansion, _cpp_backup_tokens | |
1509 won't allow backing 2 tokens. */ | |
1510 /* ??? The token buffer is leaked. Perhaps if def_pragma hook | |
1511 reads both tokens, we could perhaps free it, but if it doesn't, | |
1512 we don't know the exact lifespan. */ | |
1513 cpp_token *toks = XNEWVEC (cpp_token, 2); | |
1514 toks[0] = ns_token; | |
1515 toks[0].flags |= NO_EXPAND; | |
1516 toks[1] = *token; | |
1517 toks[1].flags |= NO_EXPAND; | |
1518 _cpp_push_token_context (pfile, NULL, toks, 2); | |
1519 } | |
1520 pfile->cb.def_pragma (pfile, pfile->directive_line); | |
1521 } | |
1522 | |
1523 pfile->state.prevent_expansion--; | |
1524 } | |
1525 | |
1526 /* Handle #pragma once. */ | |
1527 static void | |
1528 do_pragma_once (cpp_reader *pfile) | |
1529 { | |
1530 if (cpp_in_primary_file (pfile)) | |
1531 cpp_error (pfile, CPP_DL_WARNING, "#pragma once in main file"); | |
1532 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1533 check_eol (pfile, false); |
0 | 1534 _cpp_mark_file_once_only (pfile, pfile->buffer->file); |
1535 } | |
1536 | |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1537 /* Handle #pragma push_macro(STRING). */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1538 static void |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1539 do_pragma_push_macro (cpp_reader *pfile) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1540 { |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1541 cpp_hashnode *node; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1542 size_t defnlen; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1543 const uchar *defn = NULL; |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1544 char *macroname, *dest; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1545 const char *limit, *src; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1546 const cpp_token *txt; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1547 struct def_pragma_macro *c; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1548 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1549 txt = get__Pragma_string (pfile); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1550 if (!txt) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1551 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1552 source_location src_loc = pfile->cur_token[-1].src_loc; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1553 cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0, |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1554 "invalid #pragma push_macro directive"); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1555 check_eol (pfile, false); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1556 skip_rest_of_line (pfile); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1557 return; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1558 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1559 dest = macroname = (char *) alloca (txt->val.str.len + 2); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1560 src = (const char *) (txt->val.str.text + 1 + (txt->val.str.text[0] == 'L')); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1561 limit = (const char *) (txt->val.str.text + txt->val.str.len - 1); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1562 while (src < limit) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1563 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1564 /* We know there is a character following the backslash. */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1565 if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1566 src++; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1567 *dest++ = *src++; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1568 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1569 *dest = 0; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1570 check_eol (pfile, false); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1571 skip_rest_of_line (pfile); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1572 c = XNEW (struct def_pragma_macro); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1573 memset (c, 0, sizeof (struct def_pragma_macro)); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1574 c->name = XNEWVAR (char, strlen (macroname) + 1); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1575 strcpy (c->name, macroname); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1576 c->next = pfile->pushed_macros; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1577 node = _cpp_lex_identifier (pfile, c->name); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1578 if (node->type == NT_VOID) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1579 c->is_undef = 1; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1580 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1581 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1582 defn = cpp_macro_definition (pfile, node); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1583 defnlen = ustrlen (defn); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1584 c->definition = XNEWVEC (uchar, defnlen + 2); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1585 c->definition[defnlen] = '\n'; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1586 c->definition[defnlen + 1] = 0; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1587 c->line = node->value.macro->line; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1588 c->syshdr = node->value.macro->syshdr; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1589 c->used = node->value.macro->used; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1590 memcpy (c->definition, defn, defnlen); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1591 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1592 |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1593 pfile->pushed_macros = c; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1594 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1595 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1596 /* Handle #pragma pop_macro(STRING). */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1597 static void |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1598 do_pragma_pop_macro (cpp_reader *pfile) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1599 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1600 char *macroname, *dest; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1601 const char *limit, *src; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1602 const cpp_token *txt; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1603 struct def_pragma_macro *l = NULL, *c = pfile->pushed_macros; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1604 txt = get__Pragma_string (pfile); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1605 if (!txt) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1606 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1607 source_location src_loc = pfile->cur_token[-1].src_loc; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1608 cpp_error_with_line (pfile, CPP_DL_ERROR, src_loc, 0, |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1609 "invalid #pragma pop_macro directive"); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1610 check_eol (pfile, false); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1611 skip_rest_of_line (pfile); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1612 return; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1613 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1614 dest = macroname = (char *) alloca (txt->val.str.len + 2); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1615 src = (const char *) (txt->val.str.text + 1 + (txt->val.str.text[0] == 'L')); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1616 limit = (const char *) (txt->val.str.text + txt->val.str.len - 1); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1617 while (src < limit) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1618 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1619 /* We know there is a character following the backslash. */ |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1620 if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1621 src++; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1622 *dest++ = *src++; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1623 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1624 *dest = 0; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1625 check_eol (pfile, false); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1626 skip_rest_of_line (pfile); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1627 |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1628 while (c != NULL) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1629 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1630 if (!strcmp (c->name, macroname)) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1631 { |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1632 if (!l) |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1633 pfile->pushed_macros = c->next; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1634 else |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1635 l->next = c->next; |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1636 cpp_pop_definition (pfile, c); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1637 free (c->definition); |
47
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1638 free (c->name); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1639 free (c); |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1640 break; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1641 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1642 l = c; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1643 c = c->next; |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1644 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1645 } |
3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
1646 |
0 | 1647 /* Handle #pragma GCC poison, to poison one or more identifiers so |
1648 that the lexer produces a hard error for each subsequent usage. */ | |
1649 static void | |
1650 do_pragma_poison (cpp_reader *pfile) | |
1651 { | |
1652 const cpp_token *tok; | |
1653 cpp_hashnode *hp; | |
1654 | |
1655 pfile->state.poisoned_ok = 1; | |
1656 for (;;) | |
1657 { | |
1658 tok = _cpp_lex_token (pfile); | |
1659 if (tok->type == CPP_EOF) | |
1660 break; | |
1661 if (tok->type != CPP_NAME) | |
1662 { | |
1663 cpp_error (pfile, CPP_DL_ERROR, | |
1664 "invalid #pragma GCC poison directive"); | |
1665 break; | |
1666 } | |
1667 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1668 hp = tok->val.node.node; |
0 | 1669 if (hp->flags & NODE_POISONED) |
1670 continue; | |
1671 | |
131 | 1672 if (cpp_macro_p (hp)) |
0 | 1673 cpp_error (pfile, CPP_DL_WARNING, "poisoning existing macro \"%s\"", |
1674 NODE_NAME (hp)); | |
1675 _cpp_free_definition (hp); | |
1676 hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC; | |
1677 } | |
1678 pfile->state.poisoned_ok = 0; | |
1679 } | |
1680 | |
1681 /* Mark the current header as a system header. This will suppress | |
1682 some categories of warnings (notably those from -pedantic). It is | |
1683 intended for use in system libraries that cannot be implemented in | |
1684 conforming C, but cannot be certain that their headers appear in a | |
1685 system include directory. To prevent abuse, it is rejected in the | |
1686 primary source file. */ | |
1687 static void | |
1688 do_pragma_system_header (cpp_reader *pfile) | |
1689 { | |
1690 if (cpp_in_primary_file (pfile)) | |
1691 cpp_error (pfile, CPP_DL_WARNING, | |
1692 "#pragma system_header ignored outside include file"); | |
1693 else | |
1694 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1695 check_eol (pfile, false); |
0 | 1696 skip_rest_of_line (pfile); |
1697 cpp_make_system_header (pfile, 1, 0); | |
1698 } | |
1699 } | |
1700 | |
1701 /* Check the modified date of the current include file against a specified | |
1702 file. Issue a diagnostic, if the specified file is newer. We use this to | |
1703 determine if a fixed header should be refixed. */ | |
1704 static void | |
1705 do_pragma_dependency (cpp_reader *pfile) | |
1706 { | |
1707 const char *fname; | |
1708 int angle_brackets, ordering; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1709 source_location location; |
0 | 1710 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1711 fname = parse_include (pfile, &angle_brackets, NULL, &location); |
0 | 1712 if (!fname) |
1713 return; | |
1714 | |
1715 ordering = _cpp_compare_file_date (pfile, fname, angle_brackets); | |
1716 if (ordering < 0) | |
1717 cpp_error (pfile, CPP_DL_WARNING, "cannot find source file %s", fname); | |
1718 else if (ordering > 0) | |
1719 { | |
1720 cpp_error (pfile, CPP_DL_WARNING, | |
1721 "current file is older than %s", fname); | |
1722 if (cpp_get_token (pfile)->type != CPP_EOF) | |
1723 { | |
1724 _cpp_backup_tokens (pfile, 1); | |
131 | 1725 do_diagnostic (pfile, CPP_DL_WARNING, CPP_W_NONE, 0); |
0 | 1726 } |
1727 } | |
1728 | |
1729 free ((void *) fname); | |
1730 } | |
1731 | |
111 | 1732 /* Issue a diagnostic with the message taken from the pragma. If |
1733 ERROR is true, the diagnostic is a warning, otherwise, it is an | |
1734 error. */ | |
1735 static void | |
1736 do_pragma_warning_or_error (cpp_reader *pfile, bool error) | |
1737 { | |
1738 const cpp_token *tok = _cpp_lex_token (pfile); | |
1739 cpp_string str; | |
1740 if (tok->type != CPP_STRING | |
1741 || !cpp_interpret_string_notranslate (pfile, &tok->val.str, 1, &str, | |
1742 CPP_STRING) | |
1743 || str.len == 0) | |
1744 { | |
1745 cpp_error (pfile, CPP_DL_ERROR, "invalid \"#pragma GCC %s\" directive", | |
1746 error ? "error" : "warning"); | |
1747 return; | |
1748 } | |
1749 cpp_error (pfile, error ? CPP_DL_ERROR : CPP_DL_WARNING, | |
1750 "%s", str.text); | |
1751 free ((void *)str.text); | |
1752 } | |
1753 | |
1754 /* Issue a warning diagnostic. */ | |
1755 static void | |
1756 do_pragma_warning (cpp_reader *pfile) | |
1757 { | |
1758 do_pragma_warning_or_error (pfile, false); | |
1759 } | |
1760 | |
1761 /* Issue an error diagnostic. */ | |
1762 static void | |
1763 do_pragma_error (cpp_reader *pfile) | |
1764 { | |
1765 do_pragma_warning_or_error (pfile, true); | |
1766 } | |
1767 | |
0 | 1768 /* Get a token but skip padding. */ |
1769 static const cpp_token * | |
1770 get_token_no_padding (cpp_reader *pfile) | |
1771 { | |
1772 for (;;) | |
1773 { | |
1774 const cpp_token *result = cpp_get_token (pfile); | |
1775 if (result->type != CPP_PADDING) | |
1776 return result; | |
1777 } | |
1778 } | |
1779 | |
1780 /* Check syntax is "(string-literal)". Returns the string on success, | |
1781 or NULL on failure. */ | |
1782 static const cpp_token * | |
1783 get__Pragma_string (cpp_reader *pfile) | |
1784 { | |
1785 const cpp_token *string; | |
1786 const cpp_token *paren; | |
1787 | |
1788 paren = get_token_no_padding (pfile); | |
1789 if (paren->type == CPP_EOF) | |
1790 _cpp_backup_tokens (pfile, 1); | |
1791 if (paren->type != CPP_OPEN_PAREN) | |
1792 return NULL; | |
1793 | |
1794 string = get_token_no_padding (pfile); | |
1795 if (string->type == CPP_EOF) | |
1796 _cpp_backup_tokens (pfile, 1); | |
1797 if (string->type != CPP_STRING && string->type != CPP_WSTRING | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1798 && string->type != CPP_STRING32 && string->type != CPP_STRING16 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1799 && string->type != CPP_UTF8STRING) |
0 | 1800 return NULL; |
1801 | |
1802 paren = get_token_no_padding (pfile); | |
1803 if (paren->type == CPP_EOF) | |
1804 _cpp_backup_tokens (pfile, 1); | |
1805 if (paren->type != CPP_CLOSE_PAREN) | |
1806 return NULL; | |
1807 | |
1808 return string; | |
1809 } | |
1810 | |
1811 /* Destringize IN into a temporary buffer, by removing the first \ of | |
1812 \" and \\ sequences, and process the result as a #pragma directive. */ | |
1813 static void | |
111 | 1814 destringize_and_run (cpp_reader *pfile, const cpp_string *in, |
1815 source_location expansion_loc) | |
0 | 1816 { |
1817 const unsigned char *src, *limit; | |
1818 char *dest, *result; | |
1819 cpp_context *saved_context; | |
1820 cpp_token *saved_cur_token; | |
1821 tokenrun *saved_cur_run; | |
1822 cpp_token *toks; | |
1823 int count; | |
1824 const struct directive *save_directive; | |
1825 | |
1826 dest = result = (char *) alloca (in->len - 1); | |
1827 src = in->text + 1 + (in->text[0] == 'L'); | |
1828 limit = in->text + in->len - 1; | |
1829 while (src < limit) | |
1830 { | |
1831 /* We know there is a character following the backslash. */ | |
1832 if (*src == '\\' && (src[1] == '\\' || src[1] == '"')) | |
1833 src++; | |
1834 *dest++ = *src++; | |
1835 } | |
1836 *dest = '\n'; | |
1837 | |
1838 /* Ugh; an awful kludge. We are really not set up to be lexing | |
1839 tokens when in the middle of a macro expansion. Use a new | |
1840 context to force cpp_get_token to lex, and so skip_rest_of_line | |
1841 doesn't go beyond the end of the text. Also, remember the | |
1842 current lexing position so we can return to it later. | |
1843 | |
1844 Something like line-at-a-time lexing should remove the need for | |
1845 this. */ | |
1846 saved_context = pfile->context; | |
1847 saved_cur_token = pfile->cur_token; | |
1848 saved_cur_run = pfile->cur_run; | |
1849 | |
111 | 1850 pfile->context = XCNEW (cpp_context); |
0 | 1851 |
1852 /* Inline run_directive, since we need to delay the _cpp_pop_buffer | |
1853 until we've read all of the tokens that we want. */ | |
1854 cpp_push_buffer (pfile, (const uchar *) result, dest - result, | |
1855 /* from_stage3 */ true); | |
1856 /* ??? Antique Disgusting Hack. What does this do? */ | |
1857 if (pfile->buffer->prev) | |
1858 pfile->buffer->file = pfile->buffer->prev->file; | |
1859 | |
1860 start_directive (pfile); | |
1861 _cpp_clean_line (pfile); | |
1862 save_directive = pfile->directive; | |
1863 pfile->directive = &dtable[T_PRAGMA]; | |
1864 do_pragma (pfile); | |
1865 end_directive (pfile, 1); | |
1866 pfile->directive = save_directive; | |
1867 | |
1868 /* We always insert at least one token, the directive result. It'll | |
1869 either be a CPP_PADDING or a CPP_PRAGMA. In the later case, we | |
1870 need to insert *all* of the tokens, including the CPP_PRAGMA_EOL. */ | |
1871 | |
1872 /* If we're not handling the pragma internally, read all of the tokens from | |
1873 the string buffer now, while the string buffer is still installed. */ | |
1874 /* ??? Note that the token buffer allocated here is leaked. It's not clear | |
1875 to me what the true lifespan of the tokens are. It would appear that | |
1876 the lifespan is the entire parse of the main input stream, in which case | |
1877 this may not be wrong. */ | |
1878 if (pfile->directive_result.type == CPP_PRAGMA) | |
1879 { | |
1880 int maxcount; | |
1881 | |
1882 count = 1; | |
1883 maxcount = 50; | |
1884 toks = XNEWVEC (cpp_token, maxcount); | |
1885 toks[0] = pfile->directive_result; | |
1886 | |
1887 do | |
1888 { | |
1889 if (count == maxcount) | |
1890 { | |
1891 maxcount = maxcount * 3 / 2; | |
1892 toks = XRESIZEVEC (cpp_token, toks, maxcount); | |
1893 } | |
1894 toks[count] = *cpp_get_token (pfile); | |
111 | 1895 /* _Pragma is a builtin, so we're not within a macro-map, and so |
1896 the token locations are set to bogus ordinary locations | |
1897 near to, but after that of the "_Pragma". | |
1898 Paper over this by setting them equal to the location of the | |
1899 _Pragma itself (PR preprocessor/69126). */ | |
1900 toks[count].src_loc = expansion_loc; | |
0 | 1901 /* Macros have been already expanded by cpp_get_token |
1902 if the pragma allowed expansion. */ | |
1903 toks[count++].flags |= NO_EXPAND; | |
1904 } | |
1905 while (toks[count-1].type != CPP_PRAGMA_EOL); | |
1906 } | |
1907 else | |
1908 { | |
1909 count = 1; | |
1910 toks = XNEW (cpp_token); | |
1911 toks[0] = pfile->directive_result; | |
1912 | |
1913 /* If we handled the entire pragma internally, make sure we get the | |
1914 line number correct for the next token. */ | |
1915 if (pfile->cb.line_change) | |
1916 pfile->cb.line_change (pfile, pfile->cur_token, false); | |
1917 } | |
1918 | |
1919 /* Finish inlining run_directive. */ | |
1920 pfile->buffer->file = NULL; | |
1921 _cpp_pop_buffer (pfile); | |
1922 | |
1923 /* Reset the old macro state before ... */ | |
1924 XDELETE (pfile->context); | |
1925 pfile->context = saved_context; | |
1926 pfile->cur_token = saved_cur_token; | |
1927 pfile->cur_run = saved_cur_run; | |
1928 | |
1929 /* ... inserting the new tokens we collected. */ | |
1930 _cpp_push_token_context (pfile, NULL, toks, count); | |
1931 } | |
1932 | |
1933 /* Handle the _Pragma operator. Return 0 on error, 1 if ok. */ | |
1934 int | |
111 | 1935 _cpp_do__Pragma (cpp_reader *pfile, source_location expansion_loc) |
0 | 1936 { |
1937 const cpp_token *string = get__Pragma_string (pfile); | |
1938 pfile->directive_result.type = CPP_PADDING; | |
1939 | |
1940 if (string) | |
1941 { | |
111 | 1942 destringize_and_run (pfile, &string->val.str, expansion_loc); |
0 | 1943 return 1; |
1944 } | |
1945 cpp_error (pfile, CPP_DL_ERROR, | |
1946 "_Pragma takes a parenthesized string literal"); | |
1947 return 0; | |
1948 } | |
1949 | |
1950 /* Handle #ifdef. */ | |
1951 static void | |
1952 do_ifdef (cpp_reader *pfile) | |
1953 { | |
1954 int skip = 1; | |
1955 | |
1956 if (! pfile->state.skipping) | |
1957 { | |
1958 cpp_hashnode *node = lex_macro_node (pfile, false); | |
1959 | |
1960 if (node) | |
1961 { | |
111 | 1962 /* Do not treat conditional macros as being defined. This is due to |
1963 the powerpc and spu ports using conditional macros for 'vector', | |
1964 'bool', and 'pixel' to act as conditional keywords. This messes | |
1965 up tests like #ifndef bool. */ | |
131 | 1966 skip = !cpp_macro_p (node) || (node->flags & NODE_CONDITIONAL); |
0 | 1967 _cpp_mark_macro_used (node); |
131 | 1968 _cpp_maybe_notify_macro_use (pfile, node); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1969 if (pfile->cb.used) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1970 pfile->cb.used (pfile, pfile->directive_line, node); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1971 check_eol (pfile, false); |
0 | 1972 } |
1973 } | |
1974 | |
1975 push_conditional (pfile, skip, T_IFDEF, 0); | |
1976 } | |
1977 | |
1978 /* Handle #ifndef. */ | |
1979 static void | |
1980 do_ifndef (cpp_reader *pfile) | |
1981 { | |
1982 int skip = 1; | |
1983 cpp_hashnode *node = 0; | |
1984 | |
1985 if (! pfile->state.skipping) | |
1986 { | |
1987 node = lex_macro_node (pfile, false); | |
1988 | |
1989 if (node) | |
1990 { | |
111 | 1991 /* Do not treat conditional macros as being defined. This is due to |
1992 the powerpc and spu ports using conditional macros for 'vector', | |
1993 'bool', and 'pixel' to act as conditional keywords. This messes | |
1994 up tests like #ifndef bool. */ | |
131 | 1995 skip = (cpp_macro_p (node) |
1996 && !(node->flags & NODE_CONDITIONAL)); | |
0 | 1997 _cpp_mark_macro_used (node); |
131 | 1998 _cpp_maybe_notify_macro_use (pfile, node); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
1999 if (pfile->cb.used) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2000 pfile->cb.used (pfile, pfile->directive_line, node); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2001 check_eol (pfile, false); |
0 | 2002 } |
2003 } | |
2004 | |
2005 push_conditional (pfile, skip, T_IFNDEF, node); | |
2006 } | |
2007 | |
2008 /* _cpp_parse_expr puts a macro in a "#if !defined ()" expression in | |
2009 pfile->mi_ind_cmacro so we can handle multiple-include | |
2010 optimizations. If macro expansion occurs in the expression, we | |
2011 cannot treat it as a controlling conditional, since the expansion | |
2012 could change in the future. That is handled by cpp_get_token. */ | |
2013 static void | |
2014 do_if (cpp_reader *pfile) | |
2015 { | |
2016 int skip = 1; | |
2017 | |
2018 if (! pfile->state.skipping) | |
2019 skip = _cpp_parse_expr (pfile, true) == false; | |
2020 | |
2021 push_conditional (pfile, skip, T_IF, pfile->mi_ind_cmacro); | |
2022 } | |
2023 | |
2024 /* Flip skipping state if appropriate and continue without changing | |
2025 if_stack; this is so that the error message for missing #endif's | |
2026 etc. will point to the original #if. */ | |
2027 static void | |
2028 do_else (cpp_reader *pfile) | |
2029 { | |
2030 cpp_buffer *buffer = pfile->buffer; | |
2031 struct if_stack *ifs = buffer->if_stack; | |
2032 | |
2033 if (ifs == NULL) | |
2034 cpp_error (pfile, CPP_DL_ERROR, "#else without #if"); | |
2035 else | |
2036 { | |
2037 if (ifs->type == T_ELSE) | |
2038 { | |
2039 cpp_error (pfile, CPP_DL_ERROR, "#else after #else"); | |
2040 cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, | |
2041 "the conditional began here"); | |
2042 } | |
2043 ifs->type = T_ELSE; | |
2044 | |
2045 /* Skip any future (erroneous) #elses or #elifs. */ | |
2046 pfile->state.skipping = ifs->skip_elses; | |
2047 ifs->skip_elses = true; | |
2048 | |
2049 /* Invalidate any controlling macro. */ | |
2050 ifs->mi_cmacro = 0; | |
2051 | |
2052 /* Only check EOL if was not originally skipping. */ | |
2053 if (!ifs->was_skipping && CPP_OPTION (pfile, warn_endif_labels)) | |
111 | 2054 check_eol_endif_labels (pfile); |
0 | 2055 } |
2056 } | |
2057 | |
2058 /* Handle a #elif directive by not changing if_stack either. See the | |
2059 comment above do_else. */ | |
2060 static void | |
2061 do_elif (cpp_reader *pfile) | |
2062 { | |
2063 cpp_buffer *buffer = pfile->buffer; | |
2064 struct if_stack *ifs = buffer->if_stack; | |
2065 | |
2066 if (ifs == NULL) | |
2067 cpp_error (pfile, CPP_DL_ERROR, "#elif without #if"); | |
2068 else | |
2069 { | |
2070 if (ifs->type == T_ELSE) | |
2071 { | |
2072 cpp_error (pfile, CPP_DL_ERROR, "#elif after #else"); | |
2073 cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, | |
2074 "the conditional began here"); | |
2075 } | |
2076 ifs->type = T_ELIF; | |
2077 | |
111 | 2078 /* See DR#412: "Only the first group whose control condition |
2079 evaluates to true (nonzero) is processed; any following groups | |
2080 are skipped and their controlling directives are processed as | |
2081 if they were in a group that is skipped." */ | |
2082 if (ifs->skip_elses) | |
2083 pfile->state.skipping = 1; | |
2084 else | |
0 | 2085 { |
111 | 2086 pfile->state.skipping = ! _cpp_parse_expr (pfile, false); |
2087 ifs->skip_elses = ! pfile->state.skipping; | |
0 | 2088 } |
2089 | |
2090 /* Invalidate any controlling macro. */ | |
2091 ifs->mi_cmacro = 0; | |
2092 } | |
2093 } | |
2094 | |
2095 /* #endif pops the if stack and resets pfile->state.skipping. */ | |
2096 static void | |
2097 do_endif (cpp_reader *pfile) | |
2098 { | |
2099 cpp_buffer *buffer = pfile->buffer; | |
2100 struct if_stack *ifs = buffer->if_stack; | |
2101 | |
2102 if (ifs == NULL) | |
2103 cpp_error (pfile, CPP_DL_ERROR, "#endif without #if"); | |
2104 else | |
2105 { | |
2106 /* Only check EOL if was not originally skipping. */ | |
2107 if (!ifs->was_skipping && CPP_OPTION (pfile, warn_endif_labels)) | |
111 | 2108 check_eol_endif_labels (pfile); |
0 | 2109 |
2110 /* If potential control macro, we go back outside again. */ | |
2111 if (ifs->next == 0 && ifs->mi_cmacro) | |
2112 { | |
2113 pfile->mi_valid = true; | |
2114 pfile->mi_cmacro = ifs->mi_cmacro; | |
2115 } | |
2116 | |
2117 buffer->if_stack = ifs->next; | |
2118 pfile->state.skipping = ifs->was_skipping; | |
2119 obstack_free (&pfile->buffer_ob, ifs); | |
2120 } | |
2121 } | |
2122 | |
2123 /* Push an if_stack entry for a preprocessor conditional, and set | |
2124 pfile->state.skipping to SKIP. If TYPE indicates the conditional | |
2125 is #if or #ifndef, CMACRO is a potentially controlling macro, and | |
2126 we need to check here that we are at the top of the file. */ | |
2127 static void | |
2128 push_conditional (cpp_reader *pfile, int skip, int type, | |
2129 const cpp_hashnode *cmacro) | |
2130 { | |
2131 struct if_stack *ifs; | |
2132 cpp_buffer *buffer = pfile->buffer; | |
2133 | |
2134 ifs = XOBNEW (&pfile->buffer_ob, struct if_stack); | |
2135 ifs->line = pfile->directive_line; | |
2136 ifs->next = buffer->if_stack; | |
2137 ifs->skip_elses = pfile->state.skipping || !skip; | |
2138 ifs->was_skipping = pfile->state.skipping; | |
2139 ifs->type = type; | |
2140 /* This condition is effectively a test for top-of-file. */ | |
2141 if (pfile->mi_valid && pfile->mi_cmacro == 0) | |
2142 ifs->mi_cmacro = cmacro; | |
2143 else | |
2144 ifs->mi_cmacro = 0; | |
2145 | |
2146 pfile->state.skipping = skip; | |
2147 buffer->if_stack = ifs; | |
2148 } | |
2149 | |
2150 /* Read the tokens of the answer into the macro pool, in a directive | |
2151 of type TYPE. Only commit the memory if we intend it as permanent | |
2152 storage, i.e. the #assert case. Returns 0 on success, and sets | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2153 ANSWERP to point to the answer. PRED_LOC is the location of the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2154 predicate. */ |
131 | 2155 static bool |
2156 parse_answer (cpp_reader *pfile, int type, source_location pred_loc, | |
2157 cpp_macro **answer_ptr) | |
0 | 2158 { |
2159 /* In a conditional, it is legal to not have an open paren. We | |
2160 should save the following token in this case. */ | |
131 | 2161 const cpp_token *paren = cpp_get_token (pfile); |
0 | 2162 |
2163 /* If not a paren, see if we're OK. */ | |
2164 if (paren->type != CPP_OPEN_PAREN) | |
2165 { | |
2166 /* In a conditional no answer is a test for any answer. It | |
2167 could be followed by any token. */ | |
2168 if (type == T_IF) | |
2169 { | |
2170 _cpp_backup_tokens (pfile, 1); | |
131 | 2171 return true; |
0 | 2172 } |
2173 | |
2174 /* #unassert with no answer is valid - it removes all answers. */ | |
2175 if (type == T_UNASSERT && paren->type == CPP_EOF) | |
131 | 2176 return true; |
0 | 2177 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2178 cpp_error_with_line (pfile, CPP_DL_ERROR, pred_loc, 0, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2179 "missing '(' after predicate"); |
131 | 2180 return false; |
0 | 2181 } |
2182 | |
131 | 2183 cpp_macro *answer = _cpp_new_macro (pfile, cmk_assert, |
2184 _cpp_reserve_room (pfile, 0, | |
2185 sizeof (cpp_macro))); | |
2186 answer->parm.next = NULL; | |
2187 unsigned count = 0; | |
2188 for (;;) | |
0 | 2189 { |
2190 const cpp_token *token = cpp_get_token (pfile); | |
2191 | |
2192 if (token->type == CPP_CLOSE_PAREN) | |
2193 break; | |
2194 | |
2195 if (token->type == CPP_EOF) | |
2196 { | |
2197 cpp_error (pfile, CPP_DL_ERROR, "missing ')' to complete answer"); | |
131 | 2198 return false; |
0 | 2199 } |
2200 | |
131 | 2201 answer = (cpp_macro *)_cpp_reserve_room |
2202 (pfile, sizeof (cpp_macro) + count * sizeof (cpp_token), | |
2203 sizeof (cpp_token)); | |
2204 answer->exp.tokens[count++] = *token; | |
0 | 2205 } |
2206 | |
131 | 2207 if (!count) |
0 | 2208 { |
2209 cpp_error (pfile, CPP_DL_ERROR, "predicate's answer is empty"); | |
131 | 2210 return false; |
0 | 2211 } |
2212 | |
131 | 2213 /* Drop whitespace at start, for answer equivalence purposes. */ |
2214 answer->exp.tokens[0].flags &= ~PREV_WHITE; | |
0 | 2215 |
131 | 2216 answer->count = count; |
2217 *answer_ptr = answer; | |
2218 | |
2219 return true; | |
0 | 2220 } |
2221 | |
2222 /* Parses an assertion directive of type TYPE, returning a pointer to | |
131 | 2223 the hash node of the predicate, or 0 on error. The node is |
2224 guaranteed to be disjoint from the macro namespace, so can only | |
2225 have type 'NT_VOID'. If an answer was supplied, it is placed in | |
2226 *ANSWER_PTR, which is otherwise set to 0. */ | |
0 | 2227 static cpp_hashnode * |
131 | 2228 parse_assertion (cpp_reader *pfile, int type, cpp_macro **answer_ptr) |
0 | 2229 { |
2230 cpp_hashnode *result = 0; | |
2231 | |
2232 /* We don't expand predicates or answers. */ | |
2233 pfile->state.prevent_expansion++; | |
2234 | |
131 | 2235 *answer_ptr = NULL; |
2236 | |
2237 const cpp_token *predicate = cpp_get_token (pfile); | |
0 | 2238 if (predicate->type == CPP_EOF) |
2239 cpp_error (pfile, CPP_DL_ERROR, "assertion without predicate"); | |
2240 else if (predicate->type != CPP_NAME) | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2241 cpp_error_with_line (pfile, CPP_DL_ERROR, predicate->src_loc, 0, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2242 "predicate must be an identifier"); |
131 | 2243 else if (parse_answer (pfile, type, predicate->src_loc, answer_ptr)) |
0 | 2244 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2245 unsigned int len = NODE_LEN (predicate->val.node.node); |
0 | 2246 unsigned char *sym = (unsigned char *) alloca (len + 1); |
2247 | |
2248 /* Prefix '#' to get it out of macro namespace. */ | |
2249 sym[0] = '#'; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2250 memcpy (sym + 1, NODE_NAME (predicate->val.node.node), len); |
0 | 2251 result = cpp_lookup (pfile, sym, len + 1); |
2252 } | |
2253 | |
2254 pfile->state.prevent_expansion--; | |
131 | 2255 |
0 | 2256 return result; |
2257 } | |
2258 | |
2259 /* Returns a pointer to the pointer to CANDIDATE in the answer chain, | |
2260 or a pointer to NULL if the answer is not in the chain. */ | |
131 | 2261 static cpp_macro ** |
2262 find_answer (cpp_hashnode *node, const cpp_macro *candidate) | |
0 | 2263 { |
2264 unsigned int i; | |
131 | 2265 cpp_macro **result = NULL; |
0 | 2266 |
131 | 2267 for (result = &node->value.answers; *result; result = &(*result)->parm.next) |
0 | 2268 { |
131 | 2269 cpp_macro *answer = *result; |
0 | 2270 |
2271 if (answer->count == candidate->count) | |
2272 { | |
2273 for (i = 0; i < answer->count; i++) | |
131 | 2274 if (!_cpp_equiv_tokens (&answer->exp.tokens[i], |
2275 &candidate->exp.tokens[i])) | |
0 | 2276 break; |
2277 | |
2278 if (i == answer->count) | |
2279 break; | |
2280 } | |
2281 } | |
2282 | |
2283 return result; | |
2284 } | |
2285 | |
2286 /* Test an assertion within a preprocessor conditional. Returns | |
2287 nonzero on failure, zero on success. On success, the result of | |
2288 the test is written into VALUE, otherwise the value 0. */ | |
2289 int | |
2290 _cpp_test_assertion (cpp_reader *pfile, unsigned int *value) | |
2291 { | |
131 | 2292 cpp_macro *answer; |
2293 cpp_hashnode *node = parse_assertion (pfile, T_IF, &answer); | |
0 | 2294 |
2295 /* For recovery, an erroneous assertion expression is handled as a | |
2296 failing assertion. */ | |
2297 *value = 0; | |
2298 | |
2299 if (node) | |
131 | 2300 { |
2301 if (node->value.answers) | |
2302 *value = !answer || *find_answer (node, answer); | |
2303 } | |
0 | 2304 else if (pfile->cur_token[-1].type == CPP_EOF) |
2305 _cpp_backup_tokens (pfile, 1); | |
2306 | |
2307 /* We don't commit the memory for the answer - it's temporary only. */ | |
2308 return node == 0; | |
2309 } | |
2310 | |
2311 /* Handle #assert. */ | |
2312 static void | |
2313 do_assert (cpp_reader *pfile) | |
2314 { | |
131 | 2315 cpp_macro *answer; |
2316 cpp_hashnode *node = parse_assertion (pfile, T_ASSERT, &answer); | |
0 | 2317 |
2318 if (node) | |
2319 { | |
2320 /* Place the new answer in the answer list. First check there | |
2321 is not a duplicate. */ | |
131 | 2322 if (*find_answer (node, answer)) |
0 | 2323 { |
131 | 2324 cpp_error (pfile, CPP_DL_WARNING, "\"%s\" re-asserted", |
2325 NODE_NAME (node) + 1); | |
2326 return; | |
0 | 2327 } |
2328 | |
131 | 2329 /* Commit or allocate storage for the answer. */ |
2330 answer = (cpp_macro *)_cpp_commit_buff | |
2331 (pfile, sizeof (cpp_macro) - sizeof (cpp_token) | |
2332 + sizeof (cpp_token) * answer->count); | |
0 | 2333 |
131 | 2334 /* Chain into the list. */ |
2335 answer->parm.next = node->value.answers; | |
2336 node->value.answers = answer; | |
2337 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2338 check_eol (pfile, false); |
0 | 2339 } |
2340 } | |
2341 | |
2342 /* Handle #unassert. */ | |
2343 static void | |
2344 do_unassert (cpp_reader *pfile) | |
2345 { | |
131 | 2346 cpp_macro *answer; |
2347 cpp_hashnode *node = parse_assertion (pfile, T_UNASSERT, &answer); | |
0 | 2348 |
2349 /* It isn't an error to #unassert something that isn't asserted. */ | |
131 | 2350 if (node) |
0 | 2351 { |
2352 if (answer) | |
2353 { | |
131 | 2354 cpp_macro **p = find_answer (node, answer); |
0 | 2355 |
131 | 2356 /* Remove the assert from the list. */ |
2357 if (cpp_macro *temp = *p) | |
2358 *p = temp->parm.next; | |
0 | 2359 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2360 check_eol (pfile, false); |
0 | 2361 } |
2362 else | |
2363 _cpp_free_definition (node); | |
2364 } | |
2365 | |
2366 /* We don't commit the memory for the answer - it's temporary only. */ | |
2367 } | |
2368 | |
2369 /* These are for -D, -U, -A. */ | |
2370 | |
2371 /* Process the string STR as if it appeared as the body of a #define. | |
2372 If STR is just an identifier, define it with value 1. | |
2373 If STR has anything after the identifier, then it should | |
2374 be identifier=definition. */ | |
2375 void | |
2376 cpp_define (cpp_reader *pfile, const char *str) | |
2377 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2378 char *buf; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
47
diff
changeset
|
2379 const char *p; |
0 | 2380 size_t count; |
2381 | |
2382 /* Copy the entire option so we can modify it. | |
2383 Change the first "=" in the string to a space. If there is none, | |
2384 tack " 1" on the end. */ | |
2385 | |
2386 count = strlen (str); | |
2387 buf = (char *) alloca (count + 3); | |
2388 memcpy (buf, str, count); | |
2389 | |
2390 p = strchr (str, '='); | |
2391 if (p) | |
2392 buf[p - str] = ' '; | |
2393 else | |
2394 { | |
2395 buf[count++] = ' '; | |
2396 buf[count++] = '1'; | |
2397 } | |
2398 buf[count] = '\n'; | |
2399 | |
2400 run_directive (pfile, T_DEFINE, buf, count); | |
2401 } | |
2402 | |
2403 | |
2404 /* Use to build macros to be run through cpp_define() as | |
2405 described above. | |
2406 Example: cpp_define_formatted (pfile, "MACRO=%d", value); */ | |
2407 | |
2408 void | |
2409 cpp_define_formatted (cpp_reader *pfile, const char *fmt, ...) | |
2410 { | |
111 | 2411 char *ptr; |
0 | 2412 |
2413 va_list ap; | |
2414 va_start (ap, fmt); | |
111 | 2415 ptr = xvasprintf (fmt, ap); |
0 | 2416 va_end (ap); |
2417 | |
2418 cpp_define (pfile, ptr); | |
2419 free (ptr); | |
2420 } | |
2421 | |
2422 | |
2423 /* Slight variant of the above for use by initialize_builtins. */ | |
2424 void | |
2425 _cpp_define_builtin (cpp_reader *pfile, const char *str) | |
2426 { | |
2427 size_t len = strlen (str); | |
2428 char *buf = (char *) alloca (len + 1); | |
2429 memcpy (buf, str, len); | |
2430 buf[len] = '\n'; | |
2431 run_directive (pfile, T_DEFINE, buf, len); | |
2432 } | |
2433 | |
2434 /* Process MACRO as if it appeared as the body of an #undef. */ | |
2435 void | |
2436 cpp_undef (cpp_reader *pfile, const char *macro) | |
2437 { | |
2438 size_t len = strlen (macro); | |
2439 char *buf = (char *) alloca (len + 1); | |
2440 memcpy (buf, macro, len); | |
2441 buf[len] = '\n'; | |
2442 run_directive (pfile, T_UNDEF, buf, len); | |
2443 } | |
2444 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2445 /* Replace a previous definition DEF of the macro STR. If DEF is NULL, |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2446 or first element is zero, then the macro should be undefined. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2447 static void |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2448 cpp_pop_definition (cpp_reader *pfile, struct def_pragma_macro *c) |
0 | 2449 { |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2450 cpp_hashnode *node = _cpp_lex_identifier (pfile, c->name); |
0 | 2451 if (node == NULL) |
2452 return; | |
2453 | |
2454 if (pfile->cb.before_define) | |
2455 pfile->cb.before_define (pfile); | |
2456 | |
131 | 2457 if (cpp_macro_p (node)) |
0 | 2458 { |
2459 if (pfile->cb.undef) | |
2460 pfile->cb.undef (pfile, pfile->directive_line, node); | |
2461 if (CPP_OPTION (pfile, warn_unused_macros)) | |
2462 _cpp_warn_if_unused_macro (pfile, node, NULL); | |
131 | 2463 _cpp_free_definition (node); |
0 | 2464 } |
2465 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2466 if (c->is_undef) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2467 return; |
131 | 2468 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2469 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2470 size_t namelen; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2471 const uchar *dn; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2472 cpp_hashnode *h = NULL; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2473 cpp_buffer *nbuf; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2474 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2475 namelen = ustrcspn (c->definition, "( \n"); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2476 h = cpp_lookup (pfile, c->definition, namelen); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2477 dn = c->definition + namelen; |
0 | 2478 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2479 nbuf = cpp_push_buffer (pfile, dn, ustrchr (dn, '\n') - dn, true); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2480 if (nbuf != NULL) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2481 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2482 _cpp_clean_line (pfile); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2483 nbuf->sysp = 1; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2484 if (!_cpp_create_definition (pfile, h)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2485 abort (); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2486 _cpp_pop_buffer (pfile); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2487 } |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2488 else |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2489 abort (); |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2490 h->value.macro->line = c->line; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2491 h->value.macro->syshdr = c->syshdr; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2492 h->value.macro->used = c->used; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
2493 } |
0 | 2494 } |
2495 | |
2496 /* Process the string STR as if it appeared as the body of a #assert. */ | |
2497 void | |
2498 cpp_assert (cpp_reader *pfile, const char *str) | |
2499 { | |
2500 handle_assertion (pfile, str, T_ASSERT); | |
2501 } | |
2502 | |
2503 /* Process STR as if it appeared as the body of an #unassert. */ | |
2504 void | |
2505 cpp_unassert (cpp_reader *pfile, const char *str) | |
2506 { | |
2507 handle_assertion (pfile, str, T_UNASSERT); | |
2508 } | |
2509 | |
2510 /* Common code for cpp_assert (-A) and cpp_unassert (-A-). */ | |
2511 static void | |
2512 handle_assertion (cpp_reader *pfile, const char *str, int type) | |
2513 { | |
2514 size_t count = strlen (str); | |
2515 const char *p = strchr (str, '='); | |
2516 | |
2517 /* Copy the entire option so we can modify it. Change the first | |
2518 "=" in the string to a '(', and tack a ')' on the end. */ | |
2519 char *buf = (char *) alloca (count + 2); | |
2520 | |
2521 memcpy (buf, str, count); | |
2522 if (p) | |
2523 { | |
2524 buf[p - str] = '('; | |
2525 buf[count++] = ')'; | |
2526 } | |
2527 buf[count] = '\n'; | |
2528 str = buf; | |
2529 | |
2530 run_directive (pfile, type, str, count); | |
2531 } | |
2532 | |
2533 /* The options structure. */ | |
2534 cpp_options * | |
2535 cpp_get_options (cpp_reader *pfile) | |
2536 { | |
2537 return &pfile->opts; | |
2538 } | |
2539 | |
2540 /* The callbacks structure. */ | |
2541 cpp_callbacks * | |
2542 cpp_get_callbacks (cpp_reader *pfile) | |
2543 { | |
2544 return &pfile->cb; | |
2545 } | |
2546 | |
2547 /* Copy the given callbacks structure to our own. */ | |
2548 void | |
2549 cpp_set_callbacks (cpp_reader *pfile, cpp_callbacks *cb) | |
2550 { | |
2551 pfile->cb = *cb; | |
2552 } | |
2553 | |
2554 /* The dependencies structure. (Creates one if it hasn't already been.) */ | |
2555 struct deps * | |
2556 cpp_get_deps (cpp_reader *pfile) | |
2557 { | |
2558 if (!pfile->deps) | |
2559 pfile->deps = deps_init (); | |
2560 return pfile->deps; | |
2561 } | |
2562 | |
2563 /* Push a new buffer on the buffer stack. Returns the new buffer; it | |
2564 doesn't fail. It does not generate a file change call back; that | |
2565 is the responsibility of the caller. */ | |
2566 cpp_buffer * | |
2567 cpp_push_buffer (cpp_reader *pfile, const uchar *buffer, size_t len, | |
2568 int from_stage3) | |
2569 { | |
2570 cpp_buffer *new_buffer = XOBNEW (&pfile->buffer_ob, cpp_buffer); | |
2571 | |
2572 /* Clears, amongst other things, if_stack and mi_cmacro. */ | |
2573 memset (new_buffer, 0, sizeof (cpp_buffer)); | |
2574 | |
2575 new_buffer->next_line = new_buffer->buf = buffer; | |
2576 new_buffer->rlimit = buffer + len; | |
2577 new_buffer->from_stage3 = from_stage3; | |
2578 new_buffer->prev = pfile->buffer; | |
2579 new_buffer->need_line = true; | |
2580 | |
2581 pfile->buffer = new_buffer; | |
2582 | |
2583 return new_buffer; | |
2584 } | |
2585 | |
2586 /* Pops a single buffer, with a file change call-back if appropriate. | |
2587 Then pushes the next -include file, if any remain. */ | |
2588 void | |
2589 _cpp_pop_buffer (cpp_reader *pfile) | |
2590 { | |
2591 cpp_buffer *buffer = pfile->buffer; | |
2592 struct _cpp_file *inc = buffer->file; | |
2593 struct if_stack *ifs; | |
111 | 2594 const unsigned char *to_free; |
0 | 2595 |
2596 /* Walk back up the conditional stack till we reach its level at | |
2597 entry to this file, issuing error messages. */ | |
2598 for (ifs = buffer->if_stack; ifs; ifs = ifs->next) | |
2599 cpp_error_with_line (pfile, CPP_DL_ERROR, ifs->line, 0, | |
2600 "unterminated #%s", dtable[ifs->type].name); | |
2601 | |
2602 /* In case of a missing #endif. */ | |
2603 pfile->state.skipping = 0; | |
2604 | |
2605 /* _cpp_do_file_change expects pfile->buffer to be the new one. */ | |
2606 pfile->buffer = buffer->prev; | |
2607 | |
111 | 2608 to_free = buffer->to_free; |
0 | 2609 free (buffer->notes); |
2610 | |
2611 /* Free the buffer object now; we may want to push a new buffer | |
2612 in _cpp_push_next_include_file. */ | |
2613 obstack_free (&pfile->buffer_ob, buffer); | |
2614 | |
2615 if (inc) | |
2616 { | |
111 | 2617 _cpp_pop_file_buffer (pfile, inc, to_free); |
0 | 2618 |
2619 _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0); | |
2620 } | |
2621 } | |
2622 | |
2623 /* Enter all recognized directives in the hash table. */ | |
2624 void | |
2625 _cpp_init_directives (cpp_reader *pfile) | |
2626 { | |
2627 unsigned int i; | |
2628 cpp_hashnode *node; | |
2629 | |
2630 for (i = 0; i < (unsigned int) N_DIRECTIVES; i++) | |
2631 { | |
2632 node = cpp_lookup (pfile, dtable[i].name, dtable[i].length); | |
2633 node->is_directive = 1; | |
2634 node->directive_index = i; | |
2635 } | |
2636 } | |
111 | 2637 |
2638 /* Extract header file from a bracket include. Parsing starts after '<'. | |
2639 The string is malloced and must be freed by the caller. */ | |
2640 char * | |
2641 _cpp_bracket_include(cpp_reader *pfile) | |
2642 { | |
2643 return glue_header_name (pfile); | |
2644 } | |
2645 |