1 /* CPP Library. (Directive handling.)
2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Contributed by Per Bothner, 1994-95.
5 Based on CCCP program by Paul Rubin, June 1986
6 Adapted to ANSI C, Richard Stallman, Jan 1987
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
29 /* Chained list of answers to an assertion. */
37 /* Stack of conditionals currently in progress
38 (including both successful and failing conditionals). */
41 struct if_stack
*next
;
42 unsigned int line
; /* Line where condition started. */
43 const cpp_hashnode
*mi_cmacro
;/* macro name for #ifndef around entire file */
44 bool skip_elses
; /* Can future #else / #elif be skipped? */
45 bool was_skipping
; /* If were skipping on entry. */
46 int type
; /* Most recent conditional, for diagnostics. */
49 /* Contains a registered pragma or pragma namespace. */
50 typedef void (*pragma_cb
) PARAMS ((cpp_reader
*));
53 struct pragma_entry
*next
;
54 const cpp_hashnode
*pragma
; /* Name and length. */
58 struct pragma_entry
*space
;
62 /* Values for the origin field of struct directive. KANDR directives
63 come from traditional (K&R) C. STDC89 directives come from the
64 1989 C standard. EXTENSION directives are extensions. */
69 /* Values for the flags field of struct directive. COND indicates a
70 conditional; IF_COND an opening conditional. INCL means to treat
71 "..." and <...> as q-char and h-char sequences respectively. IN_I
72 means this directive should be handled even if -fpreprocessed is in
73 effect (these are the directives with callback hooks). */
75 #define IF_COND (1 << 1)
79 /* Defines one #-directive, including how to handle it. */
80 typedef void (*directive_handler
) PARAMS ((cpp_reader
*));
81 typedef struct directive directive
;
84 directive_handler handler
; /* Function to handle directive. */
85 const U_CHAR
*name
; /* Name of directive. */
86 unsigned short length
; /* Length of name. */
87 unsigned char origin
; /* Origin of directive. */
88 unsigned char flags
; /* Flags describing this directive. */
91 /* Forward declarations. */
93 static void skip_rest_of_line
PARAMS ((cpp_reader
*));
94 static void check_eol
PARAMS ((cpp_reader
*));
95 static void start_directive
PARAMS ((cpp_reader
*));
96 static void end_directive
PARAMS ((cpp_reader
*, int));
97 static void directive_diagnostics
98 PARAMS ((cpp_reader
*, const directive
*, int));
99 static void run_directive
PARAMS ((cpp_reader
*, int,
100 const char *, size_t));
101 static const cpp_token
*glue_header_name
PARAMS ((cpp_reader
*));
102 static const cpp_token
*parse_include
PARAMS ((cpp_reader
*));
103 static void push_conditional
PARAMS ((cpp_reader
*, int, int,
104 const cpp_hashnode
*));
105 static unsigned int read_flag
PARAMS ((cpp_reader
*, unsigned int));
106 static int strtoul_for_line
PARAMS ((const U_CHAR
*, unsigned int,
108 static void do_diagnostic
PARAMS ((cpp_reader
*, enum error_type
, int));
109 static cpp_hashnode
*lex_macro_node
PARAMS ((cpp_reader
*));
110 static void do_include_common
PARAMS ((cpp_reader
*, enum include_type
));
111 static struct pragma_entry
*lookup_pragma_entry
112 PARAMS ((struct pragma_entry
*, const cpp_hashnode
*pragma
));
113 static struct pragma_entry
*insert_pragma_entry
114 PARAMS ((cpp_reader
*, struct pragma_entry
**, const cpp_hashnode
*,
116 static void do_pragma_once
PARAMS ((cpp_reader
*));
117 static void do_pragma_poison
PARAMS ((cpp_reader
*));
118 static void do_pragma_system_header
PARAMS ((cpp_reader
*));
119 static void do_pragma_dependency
PARAMS ((cpp_reader
*));
120 static const cpp_token
*get_token_no_padding
PARAMS ((cpp_reader
*));
121 static const cpp_token
*get__Pragma_string
PARAMS ((cpp_reader
*));
122 static void destringize_and_run
PARAMS ((cpp_reader
*, const cpp_string
*));
123 static int parse_answer
PARAMS ((cpp_reader
*, struct answer
**, int));
124 static cpp_hashnode
*parse_assertion
PARAMS ((cpp_reader
*, struct answer
**,
126 static struct answer
** find_answer
PARAMS ((cpp_hashnode
*,
127 const struct answer
*));
128 static void handle_assertion
PARAMS ((cpp_reader
*, const char *, int));
130 /* This is the table of directive handlers. It is ordered by
131 frequency of occurrence; the numbers at the end are directive
132 counts from all the source code I have lying around (egcs and libc
133 CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and
134 pcmcia-cs-3.0.9). This is no longer important as directive lookup
135 is now O(1). All extensions other than #warning and #include_next
136 are deprecated. The name is where the extension appears to have
139 #define DIRECTIVE_TABLE \
140 D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \
141 D(include, T_INCLUDE, KANDR, INCL) /* 52262 */ \
142 D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \
143 D(ifdef, T_IFDEF, KANDR, COND | IF_COND) /* 22000 */ \
144 D(if, T_IF, KANDR, COND | IF_COND) /* 18162 */ \
145 D(else, T_ELSE, KANDR, COND) /* 9863 */ \
146 D(ifndef, T_IFNDEF, KANDR, COND | IF_COND) /* 9675 */ \
147 D(undef, T_UNDEF, KANDR, IN_I) /* 4837 */ \
148 D(line, T_LINE, KANDR, IN_I) /* 2465 */ \
149 D(elif, T_ELIF, STDC89, COND) /* 610 */ \
150 D(error, T_ERROR, STDC89, 0) /* 475 */ \
151 D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \
152 D(warning, T_WARNING, EXTENSION, 0) /* 22 */ \
153 D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL) /* 19 */ \
154 D(ident, T_IDENT, EXTENSION, IN_I) /* 11 */ \
155 D(import, T_IMPORT, EXTENSION, INCL) /* 0 ObjC */ \
156 D(assert, T_ASSERT, EXTENSION, 0) /* 0 SVR4 */ \
157 D(unassert, T_UNASSERT, EXTENSION, 0) /* 0 SVR4 */ \
158 SCCS_ENTRY /* 0 SVR4? */
160 /* #sccs is not always recognized. */
161 #ifdef SCCS_DIRECTIVE
162 # define SCCS_ENTRY D(sccs, T_SCCS, EXTENSION, 0)
164 # define SCCS_ENTRY /* nothing */
167 /* Use the table to generate a series of prototypes, an enum for the
168 directive names, and an array of directive handlers. */
170 /* The directive-processing functions are declared to return int
171 instead of void, because some old compilers have trouble with
172 pointers to functions returning void. */
174 /* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */
175 #define D(name, t, o, f) static void CONCAT2(do_,name) PARAMS ((cpp_reader *));
179 #define D(n, tag, o, f) tag,
187 /* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */
188 #define D(name, t, origin, flags) \
189 { CONCAT2(do_,name), (const U_CHAR *) STRINGX(name), \
190 sizeof STRINGX(name) - 1, origin, flags },
191 static const directive dtable
[] =
196 #undef DIRECTIVE_TABLE
198 #define SEEN_EOL() (pfile->cur_token[-1].type == CPP_EOF)
200 /* Skip any remaining tokens in a directive. */
202 skip_rest_of_line (pfile
)
205 /* Discard all stacked contexts. */
206 while (pfile
->context
!= &pfile
->base_context
)
207 _cpp_pop_context (pfile
);
209 /* Sweep up all tokens remaining on the line. */
211 while (_cpp_lex_token (pfile
)->type
!= CPP_EOF
)
215 /* Ensure there are no stray tokens at the end of a directive. */
220 if (! SEEN_EOL () && _cpp_lex_token (pfile
)->type
!= CPP_EOF
)
221 cpp_pedwarn (pfile
, "extra tokens at end of #%s directive",
222 pfile
->directive
->name
);
225 /* Called when entering a directive, _Pragma or command-line directive. */
227 start_directive (pfile
)
230 /* Setup in-directive state. */
231 pfile
->state
.in_directive
= 1;
232 pfile
->state
.save_comments
= 0;
234 /* Some handlers need the position of the # for diagnostics. */
235 pfile
->directive_line
= pfile
->line
;
238 /* Called when leaving a directive, _Pragma or command-line directive. */
240 end_directive (pfile
, skip_line
)
244 /* We don't skip for an assembler #. */
247 skip_rest_of_line (pfile
);
248 if (!pfile
->keep_tokens
)
250 pfile
->cur_run
= &pfile
->base_run
;
251 pfile
->cur_token
= pfile
->base_run
.base
;
256 pfile
->state
.save_comments
= ! CPP_OPTION (pfile
, discard_comments
);
257 pfile
->state
.in_directive
= 0;
258 pfile
->state
.angled_headers
= 0;
259 pfile
->state
.line_extension
= 0;
260 pfile
->directive
= 0;
263 /* Output diagnostics for a directive DIR. INDENTED is non-zero if
264 the '#' was indented. */
266 directive_diagnostics (pfile
, dir
, indented
)
268 const directive
*dir
;
271 if (pfile
->state
.line_extension
)
273 if (CPP_PEDANTIC (pfile
)
274 && ! pfile
->state
.skipping
)
275 cpp_pedwarn (pfile
, "style of line directive is a GCC extension");
279 /* Issue -pedantic warnings for extensions. */
280 if (CPP_PEDANTIC (pfile
)
281 && ! pfile
->state
.skipping
282 && dir
->origin
== EXTENSION
)
283 cpp_pedwarn (pfile
, "#%s is a GCC extension", dir
->name
);
285 /* Traditionally, a directive is ignored unless its # is in
286 column 1. Therefore in code intended to work with K+R
287 compilers, directives added by C89 must have their #
288 indented, and directives present in traditional C must not.
289 This is true even of directives in skipped conditional
291 if (CPP_WTRADITIONAL (pfile
))
293 if (dir
== &dtable
[T_ELIF
])
294 cpp_warning (pfile
, "suggest not using #elif in traditional C");
295 else if (indented
&& dir
->origin
== KANDR
)
297 "traditional C ignores #%s with the # indented",
299 else if (!indented
&& dir
->origin
!= KANDR
)
301 "suggest hiding #%s from traditional C with an indented #",
307 /* Check if we have a known directive. INDENTED is non-zero if the
308 '#' of the directive was indented. This function is in this file
309 to save unnecessarily exporting dtable etc. to cpplex.c. Returns
310 non-zero if the line of tokens has been handled, zero if we should
311 continue processing the line. */
313 _cpp_handle_directive (pfile
, indented
)
317 const directive
*dir
= 0;
318 const cpp_token
*dname
;
321 start_directive (pfile
);
322 dname
= _cpp_lex_token (pfile
);
324 if (dname
->type
== CPP_NAME
)
326 if (dname
->val
.node
->directive_index
)
327 dir
= &dtable
[dname
->val
.node
->directive_index
- 1];
329 /* We do not recognise the # followed by a number extension in
331 else if (dname
->type
== CPP_NUMBER
&& CPP_OPTION (pfile
, lang
) != CLK_ASM
)
333 dir
= &dtable
[T_LINE
];
334 pfile
->state
.line_extension
= 1;
339 /* If we have a directive that is not an opening conditional,
340 invalidate any control macro. */
341 if (! (dir
->flags
& IF_COND
))
342 pfile
->mi_valid
= false;
344 /* Kluge alert. In order to be sure that code like this
349 does not cause '#define foo bar' to get executed when
350 compiled with -save-temps, we recognize directives in
351 -fpreprocessed mode only if the # is in column 1. cppmacro.c
352 puts a space in front of any '#' at the start of a macro. */
353 if (CPP_OPTION (pfile
, preprocessed
)
354 && (indented
|| !(dir
->flags
& IN_I
)))
361 /* In failed conditional groups, all non-conditional
362 directives are ignored. Before doing that, whether
363 skipping or not, we should lex angle-bracketed headers
364 correctly, and maybe output some diagnostics. */
365 pfile
->state
.angled_headers
= dir
->flags
& INCL
;
366 if (! CPP_OPTION (pfile
, preprocessed
))
367 directive_diagnostics (pfile
, dir
, indented
);
368 if (pfile
->state
.skipping
&& !(dir
->flags
& COND
))
372 else if (dname
->type
== CPP_EOF
)
373 ; /* CPP_EOF is the "null directive". */
376 /* An unknown directive. Don't complain about it in assembly
377 source: we don't know where the comments are, and # may
378 introduce assembler pseudo-ops. Don't complain about invalid
379 directives in skipped conditional groups (6.10 p4). */
380 if (CPP_OPTION (pfile
, lang
) == CLK_ASM
)
382 else if (!pfile
->state
.skipping
)
383 cpp_error (pfile
, "invalid preprocessing directive #%s",
384 cpp_token_as_text (pfile
, dname
));
389 pfile
->directive
= dir
;
390 (*pfile
->directive
->handler
) (pfile
);
393 _cpp_backup_tokens (pfile
, 1);
395 end_directive (pfile
, skip
);
399 /* Directive handler wrapper used by the command line option
402 run_directive (pfile
, dir_no
, buf
, count
)
408 cpp_push_buffer (pfile
, (const U_CHAR
*) buf
, count
,
409 /* from_stage3 */ true, 1);
410 start_directive (pfile
);
411 /* We don't want a leading # to be interpreted as a directive. */
412 pfile
->buffer
->saved_flags
= 0;
413 pfile
->directive
= &dtable
[dir_no
];
414 (void) (*pfile
->directive
->handler
) (pfile
);
415 end_directive (pfile
, 1);
416 _cpp_pop_buffer (pfile
);
419 /* Checks for validity the macro name in #define, #undef, #ifdef and
420 #ifndef directives. */
421 static cpp_hashnode
*
422 lex_macro_node (pfile
)
426 const cpp_token
*token
= _cpp_lex_token (pfile
);
428 /* The token immediately after #define must be an identifier. That
429 identifier may not be "defined", per C99 6.10.8p4.
430 In C++, it may not be any of the "named operators" either,
431 per C++98 [lex.digraph], [lex.key].
432 Finally, the identifier may not have been poisoned. (In that case
433 the lexer has issued the error message for us.) */
435 if (token
->type
!= CPP_NAME
)
437 if (token
->type
== CPP_EOF
)
438 cpp_error (pfile
, "no macro name given in #%s directive",
439 pfile
->directive
->name
);
440 else if (token
->flags
& NAMED_OP
)
442 "\"%s\" cannot be used as a macro name as it is an operator in C++",
443 NODE_NAME (token
->val
.node
));
445 cpp_error (pfile
, "macro names must be identifiers");
450 node
= token
->val
.node
;
451 if (node
->flags
& NODE_POISONED
)
454 if (node
== pfile
->spec_nodes
.n_defined
)
456 cpp_error (pfile
, "\"%s\" cannot be used as a macro name",
464 /* Process a #define directive. Most work is done in cppmacro.c. */
469 cpp_hashnode
*node
= lex_macro_node (pfile
);
473 if (_cpp_create_definition (pfile
, node
))
474 if (pfile
->cb
.define
)
475 (*pfile
->cb
.define
) (pfile
, pfile
->directive_line
, node
);
479 /* Handle #undef. Mark the identifier NT_VOID in the hash table. */
484 cpp_hashnode
*node
= lex_macro_node (pfile
);
486 /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier
487 is not currently defined as a macro name. */
488 if (node
&& node
->type
== NT_MACRO
)
491 (*pfile
->cb
.undef
) (pfile
, pfile
->directive_line
, node
);
493 if (node
->flags
& NODE_WARN
)
494 cpp_warning (pfile
, "undefining \"%s\"", NODE_NAME (node
));
496 _cpp_free_definition (node
);
501 /* Helper routine used by parse_include. Reinterpret the current line
502 as an h-char-sequence (< ... >); we are looking at the first token
503 after the <. Returns the header as a token, or NULL on failure. */
504 static const cpp_token
*
505 glue_header_name (pfile
)
508 cpp_token
*header
= NULL
;
509 const cpp_token
*token
;
513 /* To avoid lexed tokens overwriting our glued name, we can only
514 allocate from the string pool once we've lexed everything. */
516 dest
= BUFF_FRONT (pfile
->u_buff
);
519 token
= cpp_get_token (pfile
);
521 if (token
->type
== CPP_GREATER
|| token
->type
== CPP_EOF
)
524 /* + 1 for terminating NUL. */
525 len
= cpp_token_len (token
) + 1;
526 if ((size_t) (BUFF_LIMIT (pfile
->u_buff
) - dest
) < len
)
528 size_t len_so_far
= dest
- BUFF_FRONT (pfile
->u_buff
);
529 _cpp_extend_buff (pfile
, &pfile
->u_buff
, len
);
530 dest
= BUFF_FRONT (pfile
->u_buff
) + len_so_far
;
533 if (token
->flags
& PREV_WHITE
)
536 dest
= cpp_spell_token (pfile
, token
, dest
);
539 if (token
->type
== CPP_EOF
)
540 cpp_error (pfile
, "missing terminating > character");
543 header
= _cpp_temp_token (pfile
);
544 header
->type
= CPP_HEADER_NAME
;
546 header
->val
.str
.len
= dest
- BUFF_FRONT (pfile
->u_buff
);
547 header
->val
.str
.text
= BUFF_FRONT (pfile
->u_buff
);
549 BUFF_FRONT (pfile
->u_buff
) = dest
;
555 /* Returns the header string of #include, #include_next, #import and
556 #pragma dependency. Returns NULL on error. */
557 static const cpp_token
*
558 parse_include (pfile
)
561 const unsigned char *dir
;
562 const cpp_token
*header
;
564 if (pfile
->directive
== &dtable
[T_PRAGMA
])
565 dir
= U
"pragma dependency";
567 dir
= pfile
->directive
->name
;
569 /* Allow macro expansion. */
570 header
= cpp_get_token (pfile
);
571 if (header
->type
!= CPP_STRING
&& header
->type
!= CPP_HEADER_NAME
)
573 if (header
->type
!= CPP_LESS
)
575 cpp_error (pfile
, "#%s expects \"FILENAME\" or <FILENAME>", dir
);
579 header
= glue_header_name (pfile
);
584 if (header
->val
.str
.len
== 0)
586 cpp_error (pfile
, "empty file name in #%s", dir
);
593 /* Handle #include, #include_next and #import. */
595 do_include_common (pfile
, type
)
597 enum include_type type
;
599 const cpp_token
*header
;
601 /* For #include_next, if this is the primary source file, warn and
602 use the normal search logic. */
603 if (type
== IT_INCLUDE_NEXT
&& ! pfile
->buffer
->prev
)
605 cpp_warning (pfile
, "#include_next in primary source file");
608 else if (type
== IT_IMPORT
&& CPP_OPTION (pfile
, warn_import
))
610 CPP_OPTION (pfile
, warn_import
) = 0;
612 "#import is obsolete, use an #ifndef wrapper in the header file");
615 header
= parse_include (pfile
);
618 /* Prevent #include recursion. */
619 if (pfile
->line_maps
.depth
>= CPP_STACK_MAX
)
620 cpp_fatal (pfile
, "#include nested too deeply");
624 /* Get out of macro context, if we are. */
625 skip_rest_of_line (pfile
);
626 if (pfile
->cb
.include
)
627 (*pfile
->cb
.include
) (pfile
, pfile
->directive_line
,
628 pfile
->directive
->name
, header
);
630 _cpp_execute_include (pfile
, header
, type
);
639 do_include_common (pfile
, IT_INCLUDE
);
646 do_include_common (pfile
, IT_IMPORT
);
650 do_include_next (pfile
)
653 do_include_common (pfile
, IT_INCLUDE_NEXT
);
656 /* Subroutine of do_line. Read possible flags after file name. LAST
657 is the last flag seen; 0 if this is the first flag. Return the flag
658 if it is valid, 0 at the end of the directive. Otherwise complain. */
660 read_flag (pfile
, last
)
664 const cpp_token
*token
= _cpp_lex_token (pfile
);
666 if (token
->type
== CPP_NUMBER
&& token
->val
.str
.len
== 1)
668 unsigned int flag
= token
->val
.str
.text
[0] - '0';
670 if (flag
> last
&& flag
<= 4
671 && (flag
!= 4 || last
== 3)
672 && (flag
!= 2 || last
== 0))
676 if (token
->type
!= CPP_EOF
)
677 cpp_error (pfile
, "invalid flag \"%s\" in line directive",
678 cpp_token_as_text (pfile
, token
));
682 /* Another subroutine of do_line. Convert a number in STR, of length
683 LEN, to binary; store it in NUMP, and return 0 if the number was
684 well-formed, 1 if not. Temporary, hopefully. */
686 strtoul_for_line (str
, len
, nump
)
691 unsigned long reg
= 0;
705 /* Interpret #line command.
706 Note that the filename string (if any) is treated as if it were an
707 include filename. That means no escape handling. */
712 const cpp_token
*token
;
713 const char *new_file
= pfile
->map
->to_file
;
714 unsigned long new_lineno
;
715 unsigned int cap
, new_sysp
= pfile
->map
->sysp
;
716 enum lc_reason reason
= LC_RENAME
;
718 /* C99 raised the minimum limit on #line numbers. */
719 cap
= CPP_OPTION (pfile
, c99
) ? 2147483647 : 32767;
721 /* Putting this in _cpp_handle_directive risks two calls to
722 _cpp_backup_tokens in some circumstances, which can segfault. */
723 if (pfile
->state
.line_extension
)
724 _cpp_backup_tokens (pfile
, 1);
726 /* #line commands expand macros. */
727 token
= cpp_get_token (pfile
);
728 if (token
->type
!= CPP_NUMBER
729 || strtoul_for_line (token
->val
.str
.text
, token
->val
.str
.len
,
732 cpp_error (pfile
, "\"%s\" after #line is not a positive integer",
733 cpp_token_as_text (pfile
, token
));
737 if (CPP_PEDANTIC (pfile
) && ! pfile
->state
.line_extension
738 && (new_lineno
== 0 || new_lineno
> cap
))
739 cpp_pedwarn (pfile
, "line number out of range");
741 token
= cpp_get_token (pfile
);
742 if (token
->type
== CPP_STRING
)
744 new_file
= (const char *) token
->val
.str
.text
;
746 /* Only accept flags for the # 55 form. */
747 if (pfile
->state
.line_extension
)
752 flag
= read_flag (pfile
, 0);
756 /* Fake an include for cpp_included (). */
757 _cpp_fake_include (pfile
, new_file
);
758 flag
= read_flag (pfile
, flag
);
763 flag
= read_flag (pfile
, flag
);
768 flag
= read_flag (pfile
, flag
);
775 else if (token
->type
!= CPP_EOF
)
777 cpp_error (pfile
, "\"%s\" is not a valid filename",
778 cpp_token_as_text (pfile
, token
));
782 skip_rest_of_line (pfile
);
783 _cpp_do_file_change (pfile
, reason
, new_file
, new_lineno
, new_sysp
);
786 /* Arrange the file_change callback. pfile->line has changed to
787 FILE_LINE of TO_FILE, for reason REASON. SYSP is 1 for a system
788 header, 2 for a system header that needs to be extern "C" protected,
789 and zero otherwise. */
791 _cpp_do_file_change (pfile
, reason
, to_file
, file_line
, sysp
)
793 enum lc_reason reason
;
795 unsigned int file_line
;
798 pfile
->map
= add_line_map (&pfile
->line_maps
, reason
, sysp
,
799 pfile
->line
, to_file
, file_line
);
801 if (pfile
->cb
.file_change
)
802 (*pfile
->cb
.file_change
) (pfile
, pfile
->map
);
805 /* Report a warning or error detected by the program we are
806 processing. Use the directive's tokens in the error message. */
808 do_diagnostic (pfile
, code
, print_dir
)
810 enum error_type code
;
813 if (_cpp_begin_message (pfile
, code
, 0, 0))
816 fprintf (stderr
, "#%s ", pfile
->directive
->name
);
817 pfile
->state
.prevent_expansion
++;
818 cpp_output_line (pfile
, stderr
);
819 pfile
->state
.prevent_expansion
--;
827 do_diagnostic (pfile
, ERROR
, 1);
834 /* We want #warning diagnostics to be emitted in system headers too. */
835 do_diagnostic (pfile
, WARNING_SYSHDR
, 1);
838 /* Report program identification. */
843 const cpp_token
*str
= cpp_get_token (pfile
);
845 if (str
->type
!= CPP_STRING
)
846 cpp_error (pfile
, "invalid #ident directive");
847 else if (pfile
->cb
.ident
)
848 (*pfile
->cb
.ident
) (pfile
, pfile
->directive_line
, &str
->val
.str
);
853 /* Lookup a PRAGMA name in a singly-linked CHAIN. Returns the
854 matching entry, or NULL if none is found. The returned entry could
855 be the start of a namespace chain, or a pragma. */
856 static struct pragma_entry
*
857 lookup_pragma_entry (chain
, pragma
)
858 struct pragma_entry
*chain
;
859 const cpp_hashnode
*pragma
;
861 while (chain
&& chain
->pragma
!= pragma
)
867 /* Create and insert a pragma entry for NAME at the beginning of a
868 singly-linked CHAIN. If handler is NULL, it is a namespace,
869 otherwise it is a pragma and its handler. */
870 static struct pragma_entry
*
871 insert_pragma_entry (pfile
, chain
, pragma
, handler
)
873 struct pragma_entry
**chain
;
874 const cpp_hashnode
*pragma
;
877 struct pragma_entry
*new;
879 new = (struct pragma_entry
*)
880 _cpp_aligned_alloc (pfile
, sizeof (struct pragma_entry
));
881 new->pragma
= pragma
;
885 new->u
.handler
= handler
;
898 /* Register a pragma NAME in namespace SPACE. If SPACE is null, it
899 goes in the global namespace. HANDLER is the handler it will call,
900 which must be non-NULL. */
902 cpp_register_pragma (pfile
, space
, name
, handler
)
908 struct pragma_entry
**chain
= &pfile
->pragmas
;
909 struct pragma_entry
*entry
;
910 const cpp_hashnode
*node
;
917 node
= cpp_lookup (pfile
, U space
, strlen (space
));
918 entry
= lookup_pragma_entry (*chain
, node
);
920 entry
= insert_pragma_entry (pfile
, chain
, node
, NULL
);
921 else if (!entry
->is_nspace
)
923 chain
= &entry
->u
.space
;
926 /* Check for duplicates. */
927 node
= cpp_lookup (pfile
, U name
, strlen (name
));
928 entry
= lookup_pragma_entry (*chain
, node
);
931 if (entry
->is_nspace
)
934 "registering \"%s\" as both a pragma and a pragma namespace",
937 cpp_ice (pfile
, "#pragma %s %s is already registered", space
, name
);
939 cpp_ice (pfile
, "#pragma %s is already registered", name
);
942 insert_pragma_entry (pfile
, chain
, node
, handler
);
945 /* Register the pragmas the preprocessor itself handles. */
947 _cpp_init_internal_pragmas (pfile
)
950 /* Pragmas in the global namespace. */
951 cpp_register_pragma (pfile
, 0, "poison", do_pragma_poison
);
952 cpp_register_pragma (pfile
, 0, "once", do_pragma_once
);
954 /* New GCC-specific pragmas should be put in the GCC namespace. */
955 cpp_register_pragma (pfile
, "GCC", "poison", do_pragma_poison
);
956 cpp_register_pragma (pfile
, "GCC", "system_header", do_pragma_system_header
);
957 cpp_register_pragma (pfile
, "GCC", "dependency", do_pragma_dependency
);
960 /* Pragmata handling. We handle some, and pass the rest on to the
961 front end. C99 defines three pragmas and says that no macro
962 expansion is to be performed on them; whether or not macro
963 expansion happens for other pragmas is implementation defined.
964 This implementation never macro-expands the text after #pragma. */
969 const struct pragma_entry
*p
= NULL
;
970 const cpp_token
*token
;
971 unsigned int count
= 1;
973 pfile
->state
.prevent_expansion
++;
975 token
= cpp_get_token (pfile
);
976 if (token
->type
== CPP_NAME
)
978 p
= lookup_pragma_entry (pfile
->pragmas
, token
->val
.node
);
979 if (p
&& p
->is_nspace
)
982 token
= cpp_get_token (pfile
);
983 if (token
->type
== CPP_NAME
)
984 p
= lookup_pragma_entry (p
->u
.space
, token
->val
.node
);
990 /* FIXME. This is an awful kludge to get the front ends to update
991 their notion of line number for diagnostic purposes. The line
992 number should be passed to the handler and they should do it
993 themselves. Stand-alone CPP must ignore us, otherwise it will
994 prefix the directive with spaces, hence the 1. Ugh. */
995 if (pfile
->cb
.line_change
)
996 (*pfile
->cb
.line_change
)(pfile
, token
, 1);
999 (*p
->u
.handler
) (pfile
);
1000 else if (pfile
->cb
.def_pragma
)
1002 _cpp_backup_tokens (pfile
, count
);
1003 (*pfile
->cb
.def_pragma
) (pfile
, pfile
->directive_line
);
1006 pfile
->state
.prevent_expansion
--;
1009 /* Handle #pragma once. */
1011 do_pragma_once (pfile
)
1014 cpp_warning (pfile
, "#pragma once is obsolete");
1016 if (pfile
->buffer
->prev
== NULL
)
1017 cpp_warning (pfile
, "#pragma once in main file");
1019 _cpp_never_reread (pfile
->buffer
->inc
);
1024 /* Handle #pragma poison, to poison one or more identifiers so that
1025 the lexer produces a hard error for each subsequent usage. */
1027 do_pragma_poison (pfile
)
1030 const cpp_token
*tok
;
1033 pfile
->state
.poisoned_ok
= 1;
1036 tok
= _cpp_lex_token (pfile
);
1037 if (tok
->type
== CPP_EOF
)
1039 if (tok
->type
!= CPP_NAME
)
1041 cpp_error (pfile
, "invalid #pragma GCC poison directive");
1046 if (hp
->flags
& NODE_POISONED
)
1049 if (hp
->type
== NT_MACRO
)
1050 cpp_warning (pfile
, "poisoning existing macro \"%s\"", NODE_NAME (hp
));
1051 _cpp_free_definition (hp
);
1052 hp
->flags
|= NODE_POISONED
| NODE_DIAGNOSTIC
;
1054 pfile
->state
.poisoned_ok
= 0;
1057 /* Mark the current header as a system header. This will suppress
1058 some categories of warnings (notably those from -pedantic). It is
1059 intended for use in system libraries that cannot be implemented in
1060 conforming C, but cannot be certain that their headers appear in a
1061 system include directory. To prevent abuse, it is rejected in the
1062 primary source file. */
1064 do_pragma_system_header (pfile
)
1067 cpp_buffer
*buffer
= pfile
->buffer
;
1069 if (buffer
->prev
== 0)
1070 cpp_warning (pfile
, "#pragma system_header ignored outside include file");
1074 skip_rest_of_line (pfile
);
1075 cpp_make_system_header (pfile
, 1, 0);
1079 /* Check the modified date of the current include file against a specified
1080 file. Issue a diagnostic, if the specified file is newer. We use this to
1081 determine if a fixed header should be refixed. */
1083 do_pragma_dependency (pfile
)
1086 const cpp_token
*header
;
1089 header
= parse_include (pfile
);
1093 ordering
= _cpp_compare_file_date (pfile
, header
);
1095 cpp_warning (pfile
, "cannot find source %s",
1096 cpp_token_as_text (pfile
, header
));
1097 else if (ordering
> 0)
1099 cpp_warning (pfile
, "current file is older than %s",
1100 cpp_token_as_text (pfile
, header
));
1101 if (cpp_get_token (pfile
)->type
!= CPP_EOF
)
1103 _cpp_backup_tokens (pfile
, 1);
1104 do_diagnostic (pfile
, WARNING
, 0);
1109 /* Get a token but skip padding. */
1110 static const cpp_token
*
1111 get_token_no_padding (pfile
)
1116 const cpp_token
*result
= cpp_get_token (pfile
);
1117 if (result
->type
!= CPP_PADDING
)
1122 /* Check syntax is "(string-literal)". Returns the string on success,
1123 or NULL on failure. */
1124 static const cpp_token
*
1125 get__Pragma_string (pfile
)
1128 const cpp_token
*string
;
1130 if (get_token_no_padding (pfile
)->type
!= CPP_OPEN_PAREN
)
1133 string
= get_token_no_padding (pfile
);
1134 if (string
->type
!= CPP_STRING
&& string
->type
!= CPP_WSTRING
)
1137 if (get_token_no_padding (pfile
)->type
!= CPP_CLOSE_PAREN
)
1143 /* Destringize IN into a temporary buffer, by removing the first \ of
1144 \" and \\ sequences, and process the result as a #pragma directive. */
1146 destringize_and_run (pfile
, in
)
1148 const cpp_string
*in
;
1150 const unsigned char *src
, *limit
;
1151 char *dest
, *result
;
1153 dest
= result
= alloca (in
->len
+ 1);
1154 for (src
= in
->text
, limit
= src
+ in
->len
; src
< limit
;)
1156 /* We know there is a character following the backslash. */
1157 if (*src
== '\\' && (src
[1] == '\\' || src
[1] == '"'))
1163 run_directive (pfile
, T_PRAGMA
, result
, dest
- result
);
1166 /* Handle the _Pragma operator. */
1168 _cpp_do__Pragma (pfile
)
1171 const cpp_token
*string
= get__Pragma_string (pfile
);
1174 cpp_error (pfile
, "_Pragma takes a parenthesized string literal");
1177 /* Ideally, we'd like
1178 token1 _Pragma ("foo") token2
1185 Getting these correct line markers is a little tricky. */
1187 unsigned int orig_line
= pfile
->line
;
1188 destringize_and_run (pfile
, &string
->val
.str
);
1189 pfile
->line
= orig_line
;
1190 pfile
->buffer
->saved_flags
= BOL
;
1194 /* Just ignore #sccs, on systems where we define it at all. */
1195 #ifdef SCCS_DIRECTIVE
1198 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
1203 /* Handle #ifdef. */
1210 if (! pfile
->state
.skipping
)
1212 const cpp_hashnode
*node
= lex_macro_node (pfile
);
1215 skip
= node
->type
!= NT_MACRO
;
1221 push_conditional (pfile
, skip
, T_IFDEF
, 0);
1224 /* Handle #ifndef. */
1230 const cpp_hashnode
*node
= 0;
1232 if (! pfile
->state
.skipping
)
1234 node
= lex_macro_node (pfile
);
1236 skip
= node
->type
== NT_MACRO
;
1242 push_conditional (pfile
, skip
, T_IFNDEF
, node
);
1245 /* _cpp_parse_expr puts a macro in a "#if !defined ()" expression in
1246 pfile->mi_ind_cmacro so we can handle multiple-include
1247 optimisations. If macro expansion occurs in the expression, we
1248 cannot treat it as a controlling conditional, since the expansion
1249 could change in the future. That is handled by cpp_get_token. */
1256 if (! pfile
->state
.skipping
)
1257 skip
= _cpp_parse_expr (pfile
) == 0;
1259 push_conditional (pfile
, skip
, T_IF
, pfile
->mi_ind_cmacro
);
1262 /* Flip skipping state if appropriate and continue without changing
1263 if_stack; this is so that the error message for missing #endif's
1264 etc. will point to the original #if. */
1269 cpp_buffer
*buffer
= pfile
->buffer
;
1270 struct if_stack
*ifs
= buffer
->if_stack
;
1273 cpp_error (pfile
, "#else without #if");
1276 if (ifs
->type
== T_ELSE
)
1278 cpp_error (pfile
, "#else after #else");
1279 cpp_error_with_line (pfile
, ifs
->line
, 0,
1280 "the conditional began here");
1284 /* Skip any future (erroneous) #elses or #elifs. */
1285 pfile
->state
.skipping
= ifs
->skip_elses
;
1286 ifs
->skip_elses
= true;
1288 /* Invalidate any controlling macro. */
1291 /* Only check EOL if was not originally skipping. */
1292 if (!ifs
->was_skipping
)
1297 /* Handle a #elif directive by not changing if_stack either. See the
1298 comment above do_else. */
1303 cpp_buffer
*buffer
= pfile
->buffer
;
1304 struct if_stack
*ifs
= buffer
->if_stack
;
1307 cpp_error (pfile
, "#elif without #if");
1310 if (ifs
->type
== T_ELSE
)
1312 cpp_error (pfile
, "#elif after #else");
1313 cpp_error_with_line (pfile
, ifs
->line
, 0,
1314 "the conditional began here");
1318 /* Only evaluate this if we aren't skipping elses. During
1319 evaluation, set skipping to false to get lexer warnings. */
1320 if (ifs
->skip_elses
)
1321 pfile
->state
.skipping
= 1;
1324 pfile
->state
.skipping
= 0;
1325 pfile
->state
.skipping
= ! _cpp_parse_expr (pfile
);
1326 ifs
->skip_elses
= ! pfile
->state
.skipping
;
1329 /* Invalidate any controlling macro. */
1334 /* #endif pops the if stack and resets pfile->state.skipping. */
1339 cpp_buffer
*buffer
= pfile
->buffer
;
1340 struct if_stack
*ifs
= buffer
->if_stack
;
1343 cpp_error (pfile
, "#endif without #if");
1346 /* Only check EOL if was not originally skipping. */
1347 if (!ifs
->was_skipping
)
1350 /* If potential control macro, we go back outside again. */
1351 if (ifs
->next
== 0 && ifs
->mi_cmacro
)
1353 pfile
->mi_valid
= true;
1354 pfile
->mi_cmacro
= ifs
->mi_cmacro
;
1357 buffer
->if_stack
= ifs
->next
;
1358 pfile
->state
.skipping
= ifs
->was_skipping
;
1359 obstack_free (&pfile
->buffer_ob
, ifs
);
1363 /* Push an if_stack entry for a preprocessor conditional, and set
1364 pfile->state.skipping to SKIP. If TYPE indicates the conditional
1365 is #if or #ifndef, CMACRO is a potentially controlling macro, and
1366 we need to check here that we are at the top of the file. */
1368 push_conditional (pfile
, skip
, type
, cmacro
)
1372 const cpp_hashnode
*cmacro
;
1374 struct if_stack
*ifs
;
1375 cpp_buffer
*buffer
= pfile
->buffer
;
1377 ifs
= xobnew (&pfile
->buffer_ob
, struct if_stack
);
1378 ifs
->line
= pfile
->directive_line
;
1379 ifs
->next
= buffer
->if_stack
;
1380 ifs
->skip_elses
= pfile
->state
.skipping
|| !skip
;
1381 ifs
->was_skipping
= pfile
->state
.skipping
;
1383 /* This condition is effectively a test for top-of-file. */
1384 if (pfile
->mi_valid
&& pfile
->mi_cmacro
== 0)
1385 ifs
->mi_cmacro
= cmacro
;
1389 pfile
->state
.skipping
= skip
;
1390 buffer
->if_stack
= ifs
;
1393 /* Read the tokens of the answer into the macro pool, in a directive
1394 of type TYPE. Only commit the memory if we intend it as permanent
1395 storage, i.e. the #assert case. Returns 0 on success, and sets
1396 ANSWERP to point to the answer. */
1398 parse_answer (pfile
, answerp
, type
)
1400 struct answer
**answerp
;
1403 const cpp_token
*paren
;
1404 struct answer
*answer
;
1405 unsigned int acount
;
1407 /* In a conditional, it is legal to not have an open paren. We
1408 should save the following token in this case. */
1409 paren
= cpp_get_token (pfile
);
1411 /* If not a paren, see if we're OK. */
1412 if (paren
->type
!= CPP_OPEN_PAREN
)
1414 /* In a conditional no answer is a test for any answer. It
1415 could be followed by any token. */
1418 _cpp_backup_tokens (pfile
, 1);
1422 /* #unassert with no answer is valid - it removes all answers. */
1423 if (type
== T_UNASSERT
&& paren
->type
== CPP_EOF
)
1426 cpp_error (pfile
, "missing '(' after predicate");
1430 for (acount
= 0;; acount
++)
1433 const cpp_token
*token
= cpp_get_token (pfile
);
1436 if (token
->type
== CPP_CLOSE_PAREN
)
1439 if (token
->type
== CPP_EOF
)
1441 cpp_error (pfile
, "missing ')' to complete answer");
1445 /* struct answer includes the space for one token. */
1446 room_needed
= (sizeof (struct answer
) + acount
* sizeof (cpp_token
));
1448 if (BUFF_ROOM (pfile
->a_buff
) < room_needed
)
1449 _cpp_extend_buff (pfile
, &pfile
->a_buff
, sizeof (struct answer
));
1451 dest
= &((struct answer
*) BUFF_FRONT (pfile
->a_buff
))->first
[acount
];
1454 /* Drop whitespace at start, for answer equivalence purposes. */
1456 dest
->flags
&= ~PREV_WHITE
;
1461 cpp_error (pfile
, "predicate's answer is empty");
1465 answer
= (struct answer
*) BUFF_FRONT (pfile
->a_buff
);
1466 answer
->count
= acount
;
1467 answer
->next
= NULL
;
1473 /* Parses an assertion directive of type TYPE, returning a pointer to
1474 the hash node of the predicate, or 0 on error. If an answer was
1475 supplied, it is placed in ANSWERP, otherwise it is set to 0. */
1476 static cpp_hashnode
*
1477 parse_assertion (pfile
, answerp
, type
)
1479 struct answer
**answerp
;
1482 cpp_hashnode
*result
= 0;
1483 const cpp_token
*predicate
;
1485 /* We don't expand predicates or answers. */
1486 pfile
->state
.prevent_expansion
++;
1489 predicate
= cpp_get_token (pfile
);
1490 if (predicate
->type
== CPP_EOF
)
1491 cpp_error (pfile
, "assertion without predicate");
1492 else if (predicate
->type
!= CPP_NAME
)
1493 cpp_error (pfile
, "predicate must be an identifier");
1494 else if (parse_answer (pfile
, answerp
, type
) == 0)
1496 unsigned int len
= NODE_LEN (predicate
->val
.node
);
1497 unsigned char *sym
= alloca (len
+ 1);
1499 /* Prefix '#' to get it out of macro namespace. */
1501 memcpy (sym
+ 1, NODE_NAME (predicate
->val
.node
), len
);
1502 result
= cpp_lookup (pfile
, sym
, len
+ 1);
1505 pfile
->state
.prevent_expansion
--;
1509 /* Returns a pointer to the pointer to CANDIDATE in the answer chain,
1510 or a pointer to NULL if the answer is not in the chain. */
1511 static struct answer
**
1512 find_answer (node
, candidate
)
1514 const struct answer
*candidate
;
1517 struct answer
**result
;
1519 for (result
= &node
->value
.answers
; *result
; result
= &(*result
)->next
)
1521 struct answer
*answer
= *result
;
1523 if (answer
->count
== candidate
->count
)
1525 for (i
= 0; i
< answer
->count
; i
++)
1526 if (! _cpp_equiv_tokens (&answer
->first
[i
], &candidate
->first
[i
]))
1529 if (i
== answer
->count
)
1537 /* Test an assertion within a preprocessor conditional. Returns
1538 non-zero on failure, zero on success. On success, the result of
1539 the test is written into VALUE. */
1541 _cpp_test_assertion (pfile
, value
)
1545 struct answer
*answer
;
1548 node
= parse_assertion (pfile
, &answer
, T_IF
);
1550 *value
= (node
->type
== NT_ASSERTION
&&
1551 (answer
== 0 || *find_answer (node
, answer
) != 0));
1553 /* We don't commit the memory for the answer - it's temporary only. */
1557 /* Handle #assert. */
1562 struct answer
*new_answer
;
1565 node
= parse_assertion (pfile
, &new_answer
, T_ASSERT
);
1568 /* Place the new answer in the answer list. First check there
1569 is not a duplicate. */
1570 new_answer
->next
= 0;
1571 if (node
->type
== NT_ASSERTION
)
1573 if (*find_answer (node
, new_answer
))
1575 cpp_warning (pfile
, "\"%s\" re-asserted", NODE_NAME (node
) + 1);
1578 new_answer
->next
= node
->value
.answers
;
1581 node
->type
= NT_ASSERTION
;
1582 node
->value
.answers
= new_answer
;
1583 BUFF_FRONT (pfile
->a_buff
) += (sizeof (struct answer
)
1584 + (new_answer
->count
- 1)
1585 * sizeof (cpp_token
));
1590 /* Handle #unassert. */
1596 struct answer
*answer
;
1598 node
= parse_assertion (pfile
, &answer
, T_UNASSERT
);
1599 /* It isn't an error to #unassert something that isn't asserted. */
1600 if (node
&& node
->type
== NT_ASSERTION
)
1604 struct answer
**p
= find_answer (node
, answer
), *temp
;
1606 /* Remove the answer from the list. */
1611 /* Did we free the last answer? */
1612 if (node
->value
.answers
== 0)
1613 node
->type
= NT_VOID
;
1618 _cpp_free_definition (node
);
1621 /* We don't commit the memory for the answer - it's temporary only. */
1624 /* These are for -D, -U, -A. */
1626 /* Process the string STR as if it appeared as the body of a #define.
1627 If STR is just an identifier, define it with value 1.
1628 If STR has anything after the identifier, then it should
1629 be identifier=definition. */
1631 cpp_define (pfile
, str
)
1638 /* Copy the entire option so we can modify it.
1639 Change the first "=" in the string to a space. If there is none,
1640 tack " 1" on the end. */
1642 count
= strlen (str
);
1643 buf
= (char *) alloca (count
+ 3);
1644 memcpy (buf
, str
, count
);
1646 p
= strchr (str
, '=');
1656 run_directive (pfile
, T_DEFINE
, buf
, count
);
1659 /* Slight variant of the above for use by initialize_builtins. */
1661 _cpp_define_builtin (pfile
, str
)
1665 run_directive (pfile
, T_DEFINE
, str
, strlen (str
));
1668 /* Process MACRO as if it appeared as the body of an #undef. */
1670 cpp_undef (pfile
, macro
)
1674 run_directive (pfile
, T_UNDEF
, macro
, strlen (macro
));
1677 /* Process the string STR as if it appeared as the body of a #assert. */
1679 cpp_assert (pfile
, str
)
1683 handle_assertion (pfile
, str
, T_ASSERT
);
1686 /* Process STR as if it appeared as the body of an #unassert. */
1688 cpp_unassert (pfile
, str
)
1692 handle_assertion (pfile
, str
, T_UNASSERT
);
1695 /* Common code for cpp_assert (-A) and cpp_unassert (-A-). */
1697 handle_assertion (pfile
, str
, type
)
1702 size_t count
= strlen (str
);
1703 const char *p
= strchr (str
, '=');
1707 /* Copy the entire option so we can modify it. Change the first
1708 "=" in the string to a '(', and tack a ')' on the end. */
1709 char *buf
= (char *) alloca (count
+ 2);
1711 memcpy (buf
, str
, count
);
1718 run_directive (pfile
, type
, str
, count
);
1721 /* The number of errors for a given reader. */
1726 return pfile
->errors
;
1729 /* The options structure. */
1731 cpp_get_options (pfile
)
1734 return &pfile
->opts
;
1737 /* The callbacks structure. */
1739 cpp_get_callbacks (pfile
)
1745 /* The line map set. */
1746 const struct line_maps
*
1747 cpp_get_line_maps (pfile
)
1750 return &pfile
->line_maps
;
1753 /* Copy the given callbacks structure to our own. */
1755 cpp_set_callbacks (pfile
, cb
)
1762 /* Push a new buffer on the buffer stack. Returns the new buffer; it
1763 doesn't fail. It does not generate a file change call back; that
1764 is the responsibility of the caller. */
1766 cpp_push_buffer (pfile
, buffer
, len
, from_stage3
, return_at_eof
)
1768 const U_CHAR
*buffer
;
1773 cpp_buffer
*new = xobnew (&pfile
->buffer_ob
, cpp_buffer
);
1775 /* Clears, amongst other things, if_stack and mi_cmacro. */
1776 memset (new, 0, sizeof (cpp_buffer
));
1778 new->line_base
= new->buf
= new->cur
= buffer
;
1779 new->rlimit
= buffer
+ len
;
1780 new->from_stage3
= from_stage3
;
1781 new->prev
= pfile
->buffer
;
1782 new->return_at_eof
= return_at_eof
;
1783 new->saved_flags
= BOL
;
1785 pfile
->buffer
= new;
1790 /* If called from do_line, pops a single buffer. Otherwise pops all
1791 buffers until a real file is reached. Generates appropriate
1794 _cpp_pop_buffer (pfile
)
1797 cpp_buffer
*buffer
= pfile
->buffer
;
1798 struct if_stack
*ifs
;
1799 bool pushed
= false;
1801 /* Walk back up the conditional stack till we reach its level at
1802 entry to this file, issuing error messages. */
1803 for (ifs
= buffer
->if_stack
; ifs
; ifs
= ifs
->next
)
1804 cpp_error_with_line (pfile
, ifs
->line
, 0,
1805 "unterminated #%s", dtable
[ifs
->type
].name
);
1807 /* In case of a missing #endif. */
1808 pfile
->state
.skipping
= 0;
1810 /* Update the reader's buffer before _cpp_do_file_change. */
1811 pfile
->buffer
= buffer
->prev
;
1814 pushed
= _cpp_pop_file_buffer (pfile
, buffer
->inc
);
1817 obstack_free (&pfile
->buffer_ob
, buffer
);
1820 /* Enter all recognised directives in the hash table. */
1822 _cpp_init_directives (pfile
)
1828 for (i
= 0; i
< (unsigned int) N_DIRECTIVES
; i
++)
1830 node
= cpp_lookup (pfile
, dtable
[i
].name
, dtable
[i
].length
);
1831 node
->directive_index
= i
+ 1;