2000-07-03 Donn Terry (donnte@microsoft.com)
[official-gcc.git] / gcc / cpplib.c
blob9e93e4dbf9423294ccd528eb347b8cfba3fcde13
1 /* CPP Library.
2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 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
11 later version.
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. */
22 #include "config.h"
23 #include "system.h"
25 #include "cpplib.h"
26 #include "cpphash.h"
27 #include "intl.h"
28 #include "obstack.h"
29 #include "symcat.h"
31 #ifdef HAVE_MMAP_FILE
32 # include <sys/mman.h>
33 #endif
35 /* Stack of conditionals currently in progress
36 (including both successful and failing conditionals). */
38 struct if_stack
40 struct if_stack *next;
41 unsigned int lineno; /* line number where condition started */
42 unsigned int colno; /* and column */
43 int was_skipping; /* value of pfile->skipping before this if */
44 const cpp_hashnode *cmacro; /* macro name for #ifndef around entire file */
45 int type; /* type of last directive seen in this group */
48 /* Forward declarations. */
50 static void validate_else PARAMS ((cpp_reader *, const U_CHAR *));
51 static int parse_include PARAMS ((cpp_reader *, const U_CHAR *, int,
52 const U_CHAR **, unsigned int *,
53 int *));
54 static void push_conditional PARAMS ((cpp_reader *, int, int,
55 const cpp_hashnode *));
56 static void pass_thru_directive PARAMS ((cpp_reader *));
57 static int read_line_number PARAMS ((cpp_reader *, int *));
58 static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int,
59 unsigned long *));
61 static const cpp_hashnode *
62 parse_ifdef PARAMS ((cpp_reader *, const U_CHAR *));
63 static const cpp_hashnode *
64 detect_if_not_defined PARAMS ((cpp_reader *));
65 static cpp_hashnode *
66 get_define_node PARAMS ((cpp_reader *));
67 static void dump_macro_name PARAMS ((cpp_reader *, cpp_hashnode *));
68 static void unwind_if_stack PARAMS ((cpp_reader *, cpp_buffer *));
70 /* Utility. */
71 #define str_match(sym, len, str) \
72 ((len) == (sizeof (str) - 1) && !ustrncmp ((sym), U(str), sizeof (str) - 1))
74 /* This is the table of directive handlers. It is ordered by
75 frequency of occurrence; the numbers at the end are directive
76 counts from all the source code I have lying around (egcs and libc
77 CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and
78 pcmcia-cs-3.0.9).
80 The entries with a dash and a name after the count are extensions,
81 of which all but #warning and #include_next are deprecated. The name
82 is where the extension appears to have come from. */
84 /* #sccs is not always recognized. */
85 #ifdef SCCS_DIRECTIVE
86 # define SCCS_ENTRY D(sccs, T_SCCS, EXTENSION, 0)
87 #else
88 # define SCCS_ENTRY /* nothing */
89 #endif
91 #define DIRECTIVE_TABLE \
92 D(define, T_DEFINE = 0, KANDR, COMMENTS) /* 270554 */ \
93 D(include, T_INCLUDE, KANDR, EXPAND | INCL) /* 52262 */ \
94 D(endif, T_ENDIF, KANDR, COND) /* 45855 */ \
95 D(ifdef, T_IFDEF, KANDR, COND) /* 22000 */ \
96 D(if, T_IF, KANDR, COND | EXPAND) /* 18162 */ \
97 D(else, T_ELSE, KANDR, COND) /* 9863 */ \
98 D(ifndef, T_IFNDEF, KANDR, COND) /* 9675 */ \
99 D(undef, T_UNDEF, KANDR, 0) /* 4837 */ \
100 D(line, T_LINE, KANDR, EXPAND) /* 2465 */ \
101 D(elif, T_ELIF, KANDR, COND | EXPAND) /* 610 */ \
102 D(error, T_ERROR, STDC89, 0) /* 475 */ \
103 D(pragma, T_PRAGMA, STDC89, 0) /* 195 */ \
104 D(warning, T_WARNING, EXTENSION, 0) /* 22 GNU */ \
105 D(include_next, T_INCLUDE_NEXT, EXTENSION, EXPAND | INCL) /* 19 GNU */ \
106 D(ident, T_IDENT, EXTENSION, 0) /* 11 SVR4 */ \
107 D(import, T_IMPORT, EXTENSION, EXPAND | INCL) /* 0 ObjC */ \
108 D(assert, T_ASSERT, EXTENSION, 0) /* 0 SVR4 */ \
109 D(unassert, T_UNASSERT, EXTENSION, 0) /* 0 SVR4 */ \
110 SCCS_ENTRY /* 0 SVR2? */
112 /* Use the table to generate a series of prototypes, an enum for the
113 directive names, and an array of directive handlers. */
115 /* The directive-processing functions are declared to return int
116 instead of void, because some old compilers have trouble with
117 pointers to functions returning void. */
119 /* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */
120 #define D(name, t, o, f) static int CONCAT2(do_,name) PARAMS ((cpp_reader *));
121 DIRECTIVE_TABLE
122 #undef D
124 #define D(n, tag, o, f) tag,
125 enum
127 DIRECTIVE_TABLE
128 N_DIRECTIVES
130 #undef D
132 /* Don't invoke CONCAT2 with any whitespace or K&R cc will fail. */
133 #define D(name, t, origin, flags) \
134 { CONCAT2(do_,name), (const U_CHAR *) STRINGX(name), \
135 sizeof STRINGX(name) - 1, origin, flags },
136 static const struct directive dtable[] =
138 DIRECTIVE_TABLE
140 #undef D
141 #undef DIRECTIVE_TABLE
143 /* Check if a token's name matches that of a known directive. Put in
144 this file to save exporting dtable and other unneeded information. */
145 const struct directive *
146 _cpp_check_directive (pfile, token, bol)
147 cpp_reader *pfile;
148 const cpp_token *token;
149 int bol;
151 const U_CHAR *name = token->val.name.text;
152 size_t len = token->val.name.len;
153 unsigned int i;
155 /* If we are rescanning preprocessed input, don't obey any directives
156 other than # nnn. */
157 if (CPP_OPTION (pfile, preprocessed))
158 return 0;
160 for (i = 0; i < N_DIRECTIVES; i++)
161 if (dtable[i].length == len && !memcmp (dtable[i].name, name, len))
163 /* If we are skipping a failed conditional group, all non-conditional
164 directives are ignored. */
165 if (pfile->skipping && !(dtable[i].flags & COND))
166 return 0;
168 /* In -traditional mode, a directive is ignored unless its #
169 is in column 1. */
170 if (!bol && dtable[i].origin == KANDR && CPP_WTRADITIONAL (pfile))
171 cpp_warning (pfile, "traditional C ignores #%s with the # indented",
172 dtable[i].name);
174 if (!bol && CPP_TRADITIONAL (pfile))
175 return 0;
177 /* Issue -pedantic warnings for extended directives. */
178 if (CPP_PEDANTIC (pfile) && dtable[i].origin == EXTENSION)
179 cpp_pedwarn (pfile, "ISO C does not allow #%s", dtable[i].name);
181 /* -Wtraditional gives warnings about directives with inappropriate
182 indentation of #. */
183 if (bol && dtable[i].origin != KANDR && CPP_WTRADITIONAL (pfile))
184 cpp_warning (pfile,
185 "suggest hiding #%s from traditional C with an indented #",
186 dtable[i].name);
188 return &dtable[i];
191 return 0;
194 const struct directive *
195 _cpp_check_linemarker (pfile, token, bol)
196 cpp_reader *pfile;
197 const cpp_token *token ATTRIBUTE_UNUSED;
198 int bol;
200 /* # followed by a number is equivalent to #line. Do not recognize
201 this form in assembly language source files or skipped
202 conditional groups. Complain about this form if we're being
203 pedantic, but not if this is regurgitated input (preprocessed or
204 fed back in by the C++ frontend). */
205 if (pfile->skipping || CPP_OPTION (pfile, lang_asm))
206 return 0;
208 if (CPP_PEDANTIC (pfile) && CPP_BUFFER (pfile)->inc
209 && ! CPP_OPTION (pfile, preprocessed))
210 cpp_pedwarn (pfile, "# followed by integer");
212 /* In -traditional mode, a directive is ignored unless its #
213 is in column 1. */
214 if (!bol && CPP_WTRADITIONAL (pfile))
215 cpp_warning (pfile, "traditional C ignores #%s with the # indented",
216 dtable[T_LINE].name);
218 if (!bol && CPP_TRADITIONAL (pfile))
219 return 0;
221 return &dtable[T_LINE];
224 static void
225 dump_macro_name (pfile, node)
226 cpp_reader *pfile;
227 cpp_hashnode *node;
229 CPP_PUTS (pfile, "#define ", sizeof "#define " - 1);
230 CPP_PUTS (pfile, node->name, node->length);
233 /* Pass the current directive through to the output file. */
234 static void
235 pass_thru_directive (pfile)
236 cpp_reader *pfile;
238 /* XXX This output may be genuinely needed even when there is no
239 printer. */
240 if (! pfile->printer)
241 return;
242 /* Flush first (temporary). */
243 cpp_output_tokens (pfile, pfile->printer, pfile->token_list.line);
244 _cpp_dump_list (pfile, &pfile->token_list, pfile->first_directive_token, 1);
247 static cpp_hashnode *
248 get_define_node (pfile)
249 cpp_reader *pfile;
251 cpp_hashnode *node;
252 const cpp_token *token;
253 const U_CHAR *sym;
254 unsigned int len;
256 /* Skip any -C comments. */
257 while ((token = cpp_get_token (pfile))->type == CPP_COMMENT)
260 if (token->type != CPP_NAME)
262 cpp_error_with_line (pfile, pfile->token_list.line, token->col,
263 "macro names must be identifiers");
264 return 0;
267 /* That identifier is not allowed to be "defined". See predefined
268 macro names (6.10.8.4). */
269 len = token->val.name.len;
270 sym = token->val.name.text;
271 if (str_match (sym, len, "defined"))
273 cpp_error_with_line (pfile, pfile->token_list.line, token->col,
274 "\"defined\" is not a legal macro name");
275 return 0;
278 node = cpp_lookup (pfile, sym, len);
279 /* Check for poisoned identifiers now. */
280 if (node->type == T_POISON)
282 cpp_error (pfile, "attempt to use poisoned \"%.*s\"", (int) len, sym);
283 return 0;
286 return node;
289 /* Process a #define command. */
290 static int
291 do_define (pfile)
292 cpp_reader *pfile;
294 cpp_hashnode *node;
296 if ((node = get_define_node (pfile)))
297 if (_cpp_create_definition (pfile, node))
299 if (CPP_OPTION (pfile, debug_output)
300 || CPP_OPTION (pfile, dump_macros) == dump_definitions)
301 _cpp_dump_definition (pfile, node);
302 else if (CPP_OPTION (pfile, dump_macros) == dump_names)
303 dump_macro_name (pfile, node);
305 return 0;
308 /* Remove the definition of a symbol from the symbol table. */
309 static int
310 do_undef (pfile)
311 cpp_reader *pfile;
313 cpp_hashnode *node = get_define_node (pfile);
315 if (cpp_get_token (pfile)->type != CPP_EOF)
316 cpp_pedwarn (pfile, "junk on line after #undef");
318 /* 6.10.3.5 paragraph 2: [#undef] is ignored if the specified identifier
319 is not currently defined as a macro name. */
320 if (node && node->type != T_VOID)
322 /* If we are generating additional info for debugging (with -g) we
323 need to pass through all effective #undef commands. */
324 if (CPP_OPTION (pfile, debug_output)
325 || CPP_OPTION (pfile, dump_macros) == dump_definitions
326 || CPP_OPTION (pfile, dump_macros) == dump_names)
327 pass_thru_directive (pfile);
329 if (node->type != T_MACRO)
330 cpp_warning (pfile, "undefining \"%s\"", node->name);
332 _cpp_free_definition (node);
333 node->type = T_VOID;
336 return 0;
340 /* Handle #include and #import. */
342 static int
343 parse_include (pfile, dir, trail, strp, lenp, abp)
344 cpp_reader *pfile;
345 const U_CHAR *dir;
346 int trail;
347 const U_CHAR **strp;
348 unsigned int *lenp;
349 int *abp;
351 const cpp_token *name = cpp_get_token (pfile);
353 if (name->type != CPP_STRING && name->type != CPP_HEADER_NAME)
355 if (name->type == CPP_LESS)
356 name = _cpp_glue_header_name (pfile);
357 else
359 cpp_error (pfile, "#%s expects \"FILENAME\" or <FILENAME>", dir);
360 return 1;
363 if (name->val.name.len == 0)
365 cpp_error (pfile, "empty file name in #%s", dir);
366 return 1;
369 if (!trail && cpp_get_token (pfile)->type != CPP_EOF)
370 cpp_error (pfile, "junk at end of #%s", dir);
372 *lenp = name->val.name.len;
373 *strp = name->val.name.text;
374 *abp = (name->type == CPP_HEADER_NAME);
375 return 0;
378 static int
379 do_include (pfile)
380 cpp_reader *pfile;
382 unsigned int len;
383 const U_CHAR *str;
384 int ab;
386 if (parse_include (pfile, dtable[T_INCLUDE].name, 0, &str, &len, &ab))
387 return 0;
389 _cpp_execute_include (pfile, str, len, 0, 0, ab);
390 if (CPP_OPTION (pfile, dump_includes))
391 pass_thru_directive (pfile);
392 return 0;
395 static int
396 do_import (pfile)
397 cpp_reader *pfile;
399 unsigned int len;
400 const U_CHAR *str;
401 int ab;
403 if (CPP_OPTION (pfile, warn_import)
404 && !CPP_IN_SYSTEM_HEADER (pfile) && !pfile->import_warning)
406 pfile->import_warning = 1;
407 cpp_warning (pfile,
408 "#import is obsolete, use an #ifndef wrapper in the header file");
411 if (parse_include (pfile, dtable[T_IMPORT].name, 0, &str, &len, &ab))
412 return 0;
414 _cpp_execute_include (pfile, str, len, 1, 0, ab);
415 if (CPP_OPTION (pfile, dump_includes))
416 pass_thru_directive (pfile);
417 return 0;
420 static int
421 do_include_next (pfile)
422 cpp_reader *pfile;
424 unsigned int len;
425 const U_CHAR *str;
426 struct file_name_list *search_start = 0;
427 int ab;
429 if (parse_include (pfile, dtable[T_INCLUDE_NEXT].name, 0, &str, &len, &ab))
430 return 0;
432 /* For #include_next, skip in the search path past the dir in which
433 the current file was found. If this is the last directory in the
434 search path, don't include anything. If the current file was
435 specified with an absolute path, use the normal search logic. If
436 this is the primary source file, use the normal search logic and
437 generate a warning. */
438 if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)))
440 if (CPP_BUFFER (pfile)->inc->foundhere)
442 search_start = CPP_BUFFER (pfile)->inc->foundhere->next;
443 if (!search_start)
444 return 0;
447 else
448 cpp_warning (pfile, "#include_next in primary source file");
450 _cpp_execute_include (pfile, str, len, 0, search_start, ab);
451 if (CPP_OPTION (pfile, dump_includes))
452 pass_thru_directive (pfile);
454 return 0;
457 /* Subroutine of do_line. Read next token from PFILE without adding it to
458 the output buffer. If it is a number between 1 and 4, store it in *NUM
459 and return 1; otherwise, return 0 and complain if we aren't at the end
460 of the directive. */
462 static int
463 read_line_number (pfile, num)
464 cpp_reader *pfile;
465 int *num;
467 const cpp_token *tok = cpp_get_token (pfile);
468 enum cpp_ttype type = tok->type;
469 const U_CHAR *p = tok->val.name.text;
470 unsigned int len = tok->val.name.len;
472 if (type == CPP_NUMBER && len == 1 && p[0] >= '1' && p[0] <= '4')
474 *num = p[0] - '0';
475 return 1;
477 else
479 if (type != CPP_EOF)
480 cpp_error (pfile, "invalid format #line");
481 return 0;
485 /* Another subroutine of do_line. Convert a number in STR, of length
486 LEN, to binary; store it in NUMP, and return 0 if the number was
487 legal, 1 if not. Temporary, hopefully. */
488 static int
489 strtoul_for_line (str, len, nump)
490 const U_CHAR *str;
491 unsigned int len;
492 unsigned long *nump;
494 unsigned long reg = 0;
495 U_CHAR c;
496 while (len--)
498 c = *str++;
499 if (!ISDIGIT (c))
500 return 1;
501 reg *= 10;
502 reg += c - '0';
504 *nump = reg;
505 return 0;
508 /* Interpret #line command.
509 Note that the filename string (if any) is treated as if it were an
510 include filename. That means no escape handling. */
512 static int
513 do_line (pfile)
514 cpp_reader *pfile;
516 cpp_buffer *ip = CPP_BUFFER (pfile);
517 unsigned long new_lineno, old_lineno;
518 /* C99 raised the minimum limit on #line numbers. */
519 unsigned int cap = CPP_OPTION (pfile, c99) ? 2147483647 : 32767;
520 int action_number = 0;
521 enum cpp_ttype type;
522 const U_CHAR *str;
523 char *fname;
524 unsigned int len;
525 const cpp_token *tok;
527 tok = cpp_get_token (pfile);
528 type = tok->type;
529 str = tok->val.name.text;
530 len = tok->val.name.len;
532 if (type != CPP_NUMBER || strtoul_for_line (str, len, &new_lineno))
534 cpp_error (pfile, "token after #line is not a positive integer");
535 goto done;
538 if (CPP_PEDANTIC (pfile) && (new_lineno == 0 || new_lineno > cap))
539 cpp_pedwarn (pfile, "line number out of range");
541 old_lineno = ip->lineno;
542 ip->lineno = new_lineno;
543 tok = cpp_get_token (pfile);
544 type = tok->type;
545 str = tok->val.name.text;
546 len = tok->val.name.len;
548 if (type == CPP_EOF)
549 goto done;
550 else if (type != CPP_STRING)
552 cpp_error (pfile, "second token after #line is not a string");
553 ip->lineno = old_lineno; /* malformed #line should have no effect */
554 goto done;
557 fname = alloca (len + 1);
558 memcpy (fname, str, len);
559 fname[len] = '\0';
561 if (strcmp (fname, ip->nominal_fname))
563 if (!strcmp (fname, ip->inc->name))
564 ip->nominal_fname = ip->inc->name;
565 else
566 ip->nominal_fname = _cpp_fake_include (pfile, fname);
569 if (read_line_number (pfile, &action_number) == 0)
570 return 0;
572 if (CPP_PEDANTIC (pfile))
573 cpp_pedwarn (pfile, "garbage at end of #line");
575 /* This is somewhat questionable: change the buffer stack
576 depth so that output_line_command thinks we've stacked
577 another buffer. */
578 if (action_number == 1)
580 pfile->buffer_stack_depth++;
581 cpp_make_system_header (pfile, ip, 0);
582 read_line_number (pfile, &action_number);
584 else if (action_number == 2)
586 pfile->buffer_stack_depth--;
587 cpp_make_system_header (pfile, ip, 0);
588 read_line_number (pfile, &action_number);
590 if (action_number == 3)
592 cpp_make_system_header (pfile, ip, 1);
593 read_line_number (pfile, &action_number);
595 if (action_number == 4)
597 cpp_make_system_header (pfile, ip, 2);
598 read_line_number (pfile, &action_number);
600 return 0;
602 done:
603 return 0;
607 * Report an error detected by the program we are processing.
608 * Use the text of the line in the error message.
609 * (We use error because it prints the filename & line#.)
612 static int
613 do_error (pfile)
614 cpp_reader *pfile;
616 U_CHAR *text, *limit;
618 text = pfile->limit;
619 _cpp_dump_list (pfile, &pfile->token_list, pfile->first_directive_token, 0);
620 limit = pfile->limit;
621 pfile->limit = text;
622 cpp_error (pfile, "%.*s", (int)(limit - text), text);
624 return 0;
628 * Report a warning detected by the program we are processing.
629 * Use the text of the line in the warning message, then continue.
632 static int
633 do_warning (pfile)
634 cpp_reader *pfile;
636 U_CHAR *text, *limit;
638 text = pfile->limit;
639 _cpp_dump_list (pfile, &pfile->token_list, pfile->first_directive_token, 0);
640 limit = pfile->limit;
641 pfile->limit = text;
642 cpp_warning (pfile, "%.*s", (int)(limit - text), text);
643 return 0;
646 /* Report program identification. */
648 static int
649 do_ident (pfile)
650 cpp_reader *pfile;
652 /* Next token should be a string constant. */
653 if (cpp_get_token (pfile)->type == CPP_STRING)
654 /* And then a newline. */
655 if (cpp_get_token (pfile)->type == CPP_EOF)
657 /* Good - ship it. */
658 pass_thru_directive (pfile);
659 return 0;
662 cpp_error (pfile, "invalid #ident");
663 return 0;
666 /* Pragmata handling. We handle some of these, and pass the rest on
667 to the front end. C99 defines three pragmas and says that no macro
668 expansion is to be performed on them; whether or not macro
669 expansion happens for other pragmas is implementation defined.
670 This implementation never macro-expands the text after #pragma.
672 We currently do not support the _Pragma operator. Support for that
673 has to be coordinated with the front end. Proposed implementation:
674 both #pragma blah blah and _Pragma("blah blah") become
675 __builtin_pragma(blah blah) and we teach the parser about that. */
677 /* Sub-handlers for the pragmas needing treatment here.
678 They return 1 if the token buffer is to be popped, 0 if not. */
679 struct pragma_entry
681 const char *name;
682 int (*handler) PARAMS ((cpp_reader *));
685 static int pragma_dispatch
686 PARAMS ((cpp_reader *, const struct pragma_entry *,
687 const U_CHAR *, size_t));
688 static int do_pragma_once PARAMS ((cpp_reader *));
689 static int do_pragma_implementation PARAMS ((cpp_reader *));
690 static int do_pragma_poison PARAMS ((cpp_reader *));
691 static int do_pragma_system_header PARAMS ((cpp_reader *));
692 static int do_pragma_gcc PARAMS ((cpp_reader *));
693 static int do_pragma_dependency PARAMS ((cpp_reader *));
695 static const struct pragma_entry top_pragmas[] =
697 {"once", do_pragma_once},
698 {"implementation", do_pragma_implementation},
699 {"poison", do_pragma_poison},
700 {"GCC", do_pragma_gcc},
701 {NULL, NULL}
704 static const struct pragma_entry gcc_pragmas[] =
706 {"implementation", do_pragma_implementation},
707 {"poison", do_pragma_poison},
708 {"system_header", do_pragma_system_header},
709 {"dependency", do_pragma_dependency},
710 {NULL, NULL}
713 static int pragma_dispatch (pfile, table, p, len)
714 cpp_reader *pfile;
715 const struct pragma_entry *table;
716 const U_CHAR *p;
717 size_t len;
719 for (; table->name; table++)
720 if (strlen (table->name) == len && !memcmp (p, table->name, len))
721 return (*table->handler) (pfile);
722 return 0;
725 static int
726 do_pragma (pfile)
727 cpp_reader *pfile;
729 const cpp_token *tok;
730 int pop;
732 tok = cpp_get_token (pfile);
733 if (tok->type == CPP_EOF)
734 return 0;
735 else if (tok->type != CPP_NAME)
737 cpp_error (pfile, "malformed #pragma directive");
738 return 0;
741 pop = pragma_dispatch (pfile, top_pragmas,
742 tok->val.name.text, tok->val.name.len);
743 if (!pop)
744 pass_thru_directive (pfile);
745 return 0;
748 static int
749 do_pragma_gcc (pfile)
750 cpp_reader *pfile;
752 const cpp_token *tok;
754 tok = cpp_get_token (pfile);
755 if (tok->type == CPP_EOF)
756 return 1;
757 else if (tok->type != CPP_NAME)
758 return 0;
760 return pragma_dispatch (pfile, gcc_pragmas,
761 tok->val.name.text, tok->val.name.len);
764 static int
765 do_pragma_once (pfile)
766 cpp_reader *pfile;
768 cpp_buffer *ip = CPP_BUFFER (pfile);
770 /* Allow #pragma once in system headers, since that's not the user's
771 fault. */
772 if (!CPP_IN_SYSTEM_HEADER (pfile))
773 cpp_warning (pfile, "#pragma once is obsolete");
775 if (CPP_PREV_BUFFER (ip) == NULL)
776 cpp_warning (pfile, "#pragma once outside include file");
777 else
778 ip->inc->cmacro = NEVER_REREAD;
780 return 1;
783 static int
784 do_pragma_implementation (pfile)
785 cpp_reader *pfile;
787 /* Be quiet about `#pragma implementation' for a file only if it hasn't
788 been included yet. */
789 const cpp_token *tok = cpp_get_token (pfile);
790 char *copy;
792 if (tok->type == CPP_EOF)
793 return 0;
794 else if (tok->type != CPP_STRING
795 || cpp_get_token (pfile)->type != CPP_EOF)
797 cpp_error (pfile, "malformed #pragma implementation");
798 return 1;
801 /* Make a NUL-terminated copy of the string. */
802 copy = alloca (tok->val.name.len + 1);
803 memcpy (copy, tok->val.name.text, tok->val.name.len);
804 copy[tok->val.name.len] = '\0';
806 if (cpp_included (pfile, copy))
807 cpp_warning (pfile,
808 "#pragma implementation for %s appears after file is included",
809 copy);
810 return 0;
813 static int
814 do_pragma_poison (pfile)
815 cpp_reader *pfile;
817 /* Poison these symbols so that all subsequent usage produces an
818 error message. */
819 const cpp_token *tok;
820 cpp_hashnode *hp;
821 int writeit;
823 /* As a rule, don't include #pragma poison commands in output,
824 unless the user asks for them. */
825 writeit = (CPP_OPTION (pfile, debug_output)
826 || CPP_OPTION (pfile, dump_macros) == dump_definitions
827 || CPP_OPTION (pfile, dump_macros) == dump_names);
829 for (;;)
831 tok = cpp_get_token (pfile);
832 if (tok->type == CPP_EOF)
833 break;
834 if (tok->type != CPP_NAME)
836 cpp_error (pfile, "invalid #pragma poison directive");
837 return 1;
840 hp = cpp_lookup (pfile, tok->val.name.text, tok->val.name.len);
841 if (hp->type == T_POISON)
842 ; /* It is allowed to poison the same identifier twice. */
843 else
845 if (hp->type != T_VOID)
846 cpp_warning (pfile, "poisoning existing macro \"%s\"", hp->name);
847 _cpp_free_definition (hp);
848 hp->type = T_POISON;
851 return !writeit;
854 /* Mark the current header as a system header. This will suppress
855 some categories of warnings (notably those from -pedantic). It is
856 intended for use in system libraries that cannot be implemented in
857 conforming C, but cannot be certain that their headers appear in a
858 system include directory. To prevent abuse, it is rejected in the
859 primary source file. */
860 static int
861 do_pragma_system_header (pfile)
862 cpp_reader *pfile;
864 cpp_buffer *ip = CPP_BUFFER (pfile);
865 if (CPP_PREV_BUFFER (ip) == NULL)
866 cpp_warning (pfile, "#pragma system_header outside include file");
867 else
868 cpp_make_system_header (pfile, ip, 1);
870 return 1;
873 /* Check the modified date of the current include file against a specified
874 file. Issue a diagnostic, if the specified file is newer. We use this to
875 determine if a fixed header should be refixed. */
876 static int
877 do_pragma_dependency (pfile)
878 cpp_reader *pfile;
880 const U_CHAR *name;
881 unsigned int len;
882 int ordering, ab;
883 char left, right;
885 if (parse_include (pfile, U"pragma dependency", 1, &name, &len, &ab))
886 return 1;
888 left = ab ? '<' : '"';
889 right = ab ? '>' : '"';
891 ordering = _cpp_compare_file_date (pfile, name, len, ab);
892 if (ordering < 0)
893 cpp_warning (pfile, "cannot find source %c%s%c", left, name, right);
894 else if (ordering > 0)
896 const cpp_token *msg = cpp_get_token (pfile);
898 cpp_warning (pfile, "current file is older than %c%s%c",
899 left, name, right);
900 if (msg->type != CPP_EOF)
902 U_CHAR *text, *limit;
904 text = pfile->limit;
905 _cpp_dump_list (pfile, &pfile->token_list, msg, 0);
906 limit = pfile->limit;
907 pfile->limit = text;
908 cpp_warning (pfile, "%.*s", (int)(limit - text), text);
911 return 1;
914 /* Just ignore #sccs, on systems where we define it at all. */
915 #ifdef SCCS_DIRECTIVE
916 static int
917 do_sccs (pfile)
918 cpp_reader *pfile ATTRIBUTE_UNUSED;
920 return 0;
922 #endif
924 /* We've found an `#if' directive. If the only thing before it in
925 this file is white space, and if it is of the form
926 `#if ! defined SYMBOL', then SYMBOL is a possible controlling macro
927 for inclusion of this file. (See redundant_include_p in cppfiles.c
928 for an explanation of controlling macros.) If so, return the
929 hash node for SYMBOL. Otherwise, return NULL. */
931 static const cpp_hashnode *
932 detect_if_not_defined (pfile)
933 cpp_reader *pfile;
935 const cpp_token *token;
936 cpp_hashnode *cmacro = 0;
938 /* We are guaranteed that tokens are consecutive and end in CPP_EOF. */
939 token = pfile->first_directive_token + 2;
941 if (token->type != CPP_NOT)
942 return 0;
944 token++;
945 if (token->type != CPP_NAME
946 || !str_match (token->val.name.text, token->val.name.len, "defined"))
947 return 0;
949 token++;
950 if (token->type == CPP_OPEN_PAREN)
951 token++;
953 if (token->type != CPP_NAME)
954 return 0;
956 cmacro = cpp_lookup (pfile, token->val.name.text, token->val.name.len);
958 if (token[-1].type == CPP_OPEN_PAREN)
960 token++;
961 if (token->type != CPP_CLOSE_PAREN)
962 return 0;
965 token++;
966 if (token->type != CPP_EOF)
967 return 0;
969 return cmacro;
972 /* Parse an #ifdef or #ifndef directive. Returns the hash node of the
973 macro being tested, and issues various error messages. */
975 static const cpp_hashnode *
976 parse_ifdef (pfile, name)
977 cpp_reader *pfile;
978 const U_CHAR *name;
980 const U_CHAR *ident;
981 unsigned int len;
982 enum cpp_ttype type;
983 const cpp_hashnode *node = 0;
985 const cpp_token *token = cpp_get_token (pfile);
986 type = token->type;
987 ident = token->val.name.text;
988 len = token->val.name.len;
990 if (!CPP_TRADITIONAL (pfile))
992 if (type == CPP_EOF)
993 cpp_pedwarn (pfile, "#%s with no argument", name);
994 else if (type != CPP_NAME)
995 cpp_pedwarn (pfile, "#%s with invalid argument", name);
996 else if (cpp_get_token (pfile)->type != CPP_EOF)
997 cpp_pedwarn (pfile, "garbage at end of #%s", name);
1000 if (type == CPP_NAME)
1001 node = cpp_lookup (pfile, ident, len);
1002 if (node && node->type == T_POISON)
1003 cpp_error (pfile, "attempt to use poisoned identifier \"%s\"", node->name);
1005 return node;
1008 /* #ifdef is dead simple. */
1010 static int
1011 do_ifdef (pfile)
1012 cpp_reader *pfile;
1014 int def = 0;
1015 const cpp_hashnode *node = 0;
1017 if (! pfile->skipping)
1019 node = parse_ifdef (pfile, dtable[T_IFDEF].name);
1020 if (node)
1021 def = (node->type != T_VOID && node->type != T_POISON);
1024 push_conditional (pfile, !def, T_IFDEF, 0);
1025 return 0;
1028 /* #ifndef is a tad more complex, because we need to check for a
1029 no-reinclusion wrapper. */
1031 static int
1032 do_ifndef (pfile)
1033 cpp_reader *pfile;
1035 int start_of_file = 0;
1036 int def = 0;
1037 const cpp_hashnode *cmacro = 0;
1039 if (! pfile->skipping)
1041 start_of_file = (pfile->token_list.flags & BEG_OF_FILE);
1042 cmacro = parse_ifdef (pfile, dtable[T_IFNDEF].name);
1043 if (cmacro)
1044 def = cmacro->type != T_VOID;
1047 push_conditional (pfile, def, T_IFNDEF, start_of_file ? cmacro : 0);
1048 return 0;
1051 /* #if is straightforward; just call _cpp_parse_expr, then conditional_skip.
1052 Also, check for a reinclude preventer of the form #if !defined (MACRO). */
1054 static int
1055 do_if (pfile)
1056 cpp_reader *pfile;
1058 const cpp_hashnode *cmacro = 0;
1059 int value = 0;
1061 if (! pfile->skipping)
1063 cmacro = detect_if_not_defined (pfile);
1064 value = _cpp_parse_expr (pfile);
1066 push_conditional (pfile, value == 0, T_IF, cmacro);
1067 return 0;
1070 /* #else flips pfile->skipping and continues without changing
1071 if_stack; this is so that the error message for missing #endif's
1072 etc. will point to the original #if. */
1074 static int
1075 do_else (pfile)
1076 cpp_reader *pfile;
1078 struct if_stack *ifs = CPP_BUFFER (pfile)->if_stack;
1079 validate_else (pfile, dtable[T_ELSE].name);
1081 if (ifs == NULL)
1083 cpp_error (pfile, "#else without #if");
1084 return 0;
1086 if (ifs->type == T_ELSE)
1088 cpp_error (pfile, "#else after #else");
1089 cpp_error_with_line (pfile, ifs->lineno, ifs->colno,
1090 "the conditional began here");
1093 /* #ifndef can't have its special treatment for containing the whole file
1094 if it has a #else clause. */
1095 ifs->cmacro = 0;
1096 ifs->type = T_ELSE;
1097 if (! ifs->was_skipping)
1099 /* If pfile->skipping is 2, one of the blocks in an #if/#elif/... chain
1100 succeeded, so we mustn't do the else block. */
1101 if (pfile->skipping < 2)
1102 pfile->skipping = ! pfile->skipping;
1104 return 0;
1108 * handle a #elif directive by not changing if_stack either.
1109 * see the comment above do_else.
1112 static int
1113 do_elif (pfile)
1114 cpp_reader *pfile;
1116 struct if_stack *ifs = CPP_BUFFER (pfile)->if_stack;
1118 if (ifs == NULL)
1120 cpp_error (pfile, "#elif without #if");
1121 return 0;
1123 if (ifs->type == T_ELSE)
1125 cpp_error (pfile, "#elif after #else");
1126 cpp_error_with_line (pfile, ifs->lineno, ifs->colno,
1127 "the conditional began here");
1130 ifs->type = T_ELIF;
1131 if (ifs->was_skipping)
1132 return 0; /* Don't evaluate a nested #if */
1134 if (pfile->skipping != 1)
1136 pfile->skipping = 2; /* one block succeeded, so don't do any others */
1137 return 0;
1140 pfile->skipping = ! _cpp_parse_expr (pfile);
1141 return 0;
1144 /* #endif pops the if stack and resets pfile->skipping. */
1146 static int
1147 do_endif (pfile)
1148 cpp_reader *pfile;
1150 struct if_stack *ifs = CPP_BUFFER (pfile)->if_stack;
1152 validate_else (pfile, dtable[T_ENDIF].name);
1154 if (ifs == NULL)
1155 cpp_error (pfile, "#endif without #if");
1156 else
1158 CPP_BUFFER (pfile)->if_stack = ifs->next;
1159 pfile->skipping = ifs->was_skipping;
1160 pfile->potential_control_macro = ifs->cmacro;
1161 obstack_free (pfile->buffer_ob, ifs);
1163 return 0;
1167 /* Push an if_stack entry and set pfile->skipping accordingly.
1168 If this is a #ifndef starting at the beginning of a file,
1169 CMACRO is the macro name tested by the #ifndef. */
1171 static void
1172 push_conditional (pfile, skip, type, cmacro)
1173 cpp_reader *pfile;
1174 int skip;
1175 int type;
1176 const cpp_hashnode *cmacro;
1178 struct if_stack *ifs;
1180 ifs = xobnew (pfile->buffer_ob, struct if_stack);
1181 ifs->lineno = _cpp_get_line (pfile, &ifs->colno);
1182 ifs->next = CPP_BUFFER (pfile)->if_stack;
1183 ifs->cmacro = cmacro;
1184 ifs->was_skipping = pfile->skipping;
1185 ifs->type = type;
1187 if (!pfile->skipping)
1188 pfile->skipping = skip;
1190 CPP_BUFFER (pfile)->if_stack = ifs;
1193 /* Issue -pedantic warning for text which is not a comment following
1194 an #else or #endif. */
1196 static void
1197 validate_else (pfile, directive)
1198 cpp_reader *pfile;
1199 const U_CHAR *directive;
1201 if (CPP_PEDANTIC (pfile) && cpp_get_token (pfile)->type != CPP_EOF)
1202 cpp_pedwarn (pfile, "ISO C forbids text after #%s", directive);
1205 /* Called when we reach the end of a file. Walk back up the
1206 conditional stack till we reach its level at entry to this file,
1207 issuing error messages. Then force skipping off. */
1208 static void
1209 unwind_if_stack (pfile, pbuf)
1210 cpp_reader *pfile;
1211 cpp_buffer *pbuf;
1213 struct if_stack *ifs, *nifs;
1215 for (ifs = pbuf->if_stack; ifs; ifs = nifs)
1217 cpp_error_with_line (pfile, ifs->lineno, ifs->colno, "unterminated #%s",
1218 dtable[ifs->type].name);
1219 nifs = ifs->next;
1220 /* No need to free - they'll all go away with the buffer. */
1222 pfile->skipping = 0;
1225 /* Parses an assertion, returning a pointer to the hash node of the
1226 predicate, or 0 on error. If an answer was supplied, it is
1227 allocated and placed in ANSWERP, otherwise it is set to 0. We use
1228 _cpp_get_raw_token, since we cannot assume tokens are consecutive
1229 in a #if statement (we may be in a macro), and we don't want to
1230 macro expand. */
1231 cpp_hashnode *
1232 _cpp_parse_assertion (pfile, answerp)
1233 cpp_reader *pfile;
1234 struct answer **answerp;
1236 struct answer *answer = 0;
1237 cpp_toklist *list;
1238 U_CHAR *sym;
1239 const cpp_token *token, *predicate;
1240 const struct directive *d = pfile->token_list.directive;
1241 unsigned int len = 0;
1243 predicate = _cpp_get_raw_token (pfile);
1244 if (predicate->type == CPP_EOF)
1246 cpp_error (pfile, "assertion without predicate");
1247 return 0;
1249 else if (predicate->type != CPP_NAME)
1251 cpp_error (pfile, "predicate must be an identifier");
1252 return 0;
1255 token = _cpp_get_raw_token (pfile);
1256 if (token->type != CPP_OPEN_PAREN)
1258 /* #unassert and #if are OK without predicate. */
1259 if (d == &dtable[T_UNASSERT])
1261 if (token->type == CPP_EOF)
1262 goto lookup_node;
1264 else if (d != &dtable[T_ASSERT])
1266 _cpp_push_token (pfile, token);
1267 goto lookup_node;
1269 cpp_error (pfile, "missing '(' after predicate");
1270 return 0;
1273 /* Allocate a struct answer, and copy the answer to it. */
1274 answer = (struct answer *) xmalloc (sizeof (struct answer));
1275 list = &answer->list;
1276 _cpp_init_toklist (list, NO_DUMMY_TOKEN);
1278 for (;;)
1280 cpp_token *dest;
1282 token = _cpp_get_raw_token (pfile);
1284 if (token->type == CPP_EOF)
1286 cpp_error (pfile, "missing ')' to complete answer");
1287 goto error;
1289 if (token->type == CPP_CLOSE_PAREN)
1290 break;
1292 /* Copy the token. */
1293 _cpp_expand_token_space (list, 1);
1294 dest = &list->tokens[list->tokens_used++];
1295 *dest = *token;
1297 if (token_spellings[token->type].type > SPELL_NONE)
1299 _cpp_expand_name_space (list, token->val.name.len);
1300 dest->val.name.text = list->namebuf + list->name_used;
1301 memcpy (list->namebuf + list->name_used,
1302 token->val.name.text, token->val.name.len);
1303 list->name_used += token->val.name.len;
1307 if (list->tokens_used == 0)
1309 cpp_error (pfile, "predicate's answer is empty");
1310 goto error;
1313 /* Drop whitespace at start. */
1314 list->tokens[0].flags &= ~PREV_WHITE;
1316 if ((d == &dtable[T_ASSERT] || d == &dtable[T_UNASSERT])
1317 && token[1].type != CPP_EOF)
1319 cpp_error (pfile, "junk at end of assertion");
1320 goto error;
1323 lookup_node:
1324 *answerp = answer;
1325 len = predicate->val.name.len;
1326 sym = alloca (len + 1);
1328 /* Prefix '#' to get it out of macro namespace. */
1329 sym[0] = '#';
1330 memcpy (sym + 1, predicate->val.name.text, len);
1331 return cpp_lookup (pfile, sym, len + 1);
1333 error:
1334 FREE_ANSWER (answer);
1335 return 0;
1338 /* Returns a pointer to the pointer to the answer in the answer chain,
1339 or a pointer to NULL if the answer is not in the chain. */
1340 struct answer **
1341 _cpp_find_answer (node, candidate)
1342 cpp_hashnode *node;
1343 const cpp_toklist *candidate;
1345 struct answer **result;
1347 for (result = &node->value.answers; *result; result = &(*result)->next)
1348 if (_cpp_equiv_toklists (&(*result)->list, candidate))
1349 break;
1351 return result;
1354 #define WARNING(msgid) do { cpp_warning(pfile, msgid); goto error; } while (0)
1355 #define ERROR(msgid) do { cpp_error(pfile, msgid); goto error; } while (0)
1356 #define ICE(msgid) do { cpp_ice(pfile, msgid); goto error; } while (0)
1357 static int
1358 do_assert (pfile)
1359 cpp_reader *pfile;
1361 struct answer *new_answer;
1362 cpp_hashnode *node;
1364 node = _cpp_parse_assertion (pfile, &new_answer);
1365 if (node)
1367 new_answer->next = 0;
1368 new_answer->list.line = pfile->token_list.line;
1369 new_answer->list.file = pfile->token_list.file;
1371 if (node->type == T_ASSERTION)
1373 if (*_cpp_find_answer (node, &new_answer->list))
1374 goto err;
1375 new_answer->next = node->value.answers;
1377 node->type = T_ASSERTION;
1378 node->value.answers = new_answer;
1380 return 0;
1382 err:
1383 cpp_warning (pfile, "\"%.*s\" re-asserted",
1384 node->length - 1, node->name + 1);
1385 FREE_ANSWER (new_answer);
1386 return 0;
1389 static int
1390 do_unassert (pfile)
1391 cpp_reader *pfile;
1393 cpp_hashnode *node;
1394 struct answer *answer, *temp, *next;
1396 node = _cpp_parse_assertion (pfile, &answer);
1397 if (node)
1399 /* It isn't an error to #unassert something that isn't asserted. */
1400 if (node->type == T_ASSERTION)
1402 if (answer)
1404 struct answer **p = _cpp_find_answer (node, &answer->list);
1406 temp = *p;
1407 if (temp)
1409 *p = temp->next;
1410 FREE_ANSWER (temp);
1412 if (node->value.answers == 0)
1413 node->type = T_VOID;
1415 else
1417 for (temp = node->value.answers; temp; temp = next)
1419 next = temp->next;
1420 FREE_ANSWER (temp);
1422 node->type = T_VOID;
1426 if (answer)
1427 FREE_ANSWER (answer);
1429 return 0;
1432 /* These are for -D, -U, -A. */
1434 /* Process the string STR as if it appeared as the body of a #define.
1435 If STR is just an identifier, define it with value 1.
1436 If STR has anything after the identifier, then it should
1437 be identifier=definition. */
1439 void
1440 cpp_define (pfile, str)
1441 cpp_reader *pfile;
1442 const char *str;
1444 char *buf, *p;
1445 size_t count;
1447 p = strchr (str, '=');
1448 /* Copy the entire option so we can modify it.
1449 Change the first "=" in the string to a space. If there is none,
1450 tack " 1" on the end. Then add a newline and a NUL. */
1452 if (p)
1454 count = strlen (str) + 2;
1455 buf = (char *) alloca (count);
1456 memcpy (buf, str, count - 2);
1457 buf[p - str] = ' ';
1458 buf[count - 2] = '\n';
1459 buf[count - 1] = '\0';
1461 else
1463 count = strlen (str) + 4;
1464 buf = (char *) alloca (count);
1465 memcpy (buf, str, count - 4);
1466 strcpy (&buf[count-4], " 1\n");
1469 _cpp_run_directive (pfile, &dtable[T_DEFINE], buf, count - 1);
1472 /* Process MACRO as if it appeared as the body of an #undef. */
1473 void
1474 cpp_undef (pfile, macro)
1475 cpp_reader *pfile;
1476 const char *macro;
1478 _cpp_run_directive (pfile, &dtable[T_UNDEF], macro, strlen (macro));
1481 /* Process the string STR as if it appeared as the body of a #assert. */
1482 void
1483 cpp_assert (pfile, str)
1484 cpp_reader *pfile;
1485 const char *str;
1487 _cpp_run_directive (pfile, &dtable[T_ASSERT], str, strlen (str));
1490 /* Process STR as if it appeared as the body of an #unassert. */
1491 void
1492 cpp_unassert (pfile, str)
1493 cpp_reader *pfile;
1494 const char *str;
1496 _cpp_run_directive (pfile, &dtable[T_UNASSERT], str, strlen (str));
1499 /* Determine whether the identifier ID, of length LEN, is a defined macro. */
1501 cpp_defined (pfile, id, len)
1502 cpp_reader *pfile;
1503 const U_CHAR *id;
1504 int len;
1506 cpp_hashnode *hp = cpp_lookup (pfile, id, len);
1507 if (hp->type == T_POISON)
1509 cpp_error (pfile, "attempt to use poisoned \"%s\"", hp->name);
1510 return 0;
1512 return (hp->type != T_VOID);
1515 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1516 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1517 as the new input buffer.
1518 Return the new buffer, or NULL on failure. */
1520 cpp_buffer *
1521 cpp_push_buffer (pfile, buffer, length)
1522 cpp_reader *pfile;
1523 const U_CHAR *buffer;
1524 long length;
1526 cpp_buffer *buf = CPP_BUFFER (pfile);
1527 cpp_buffer *new;
1528 if (++pfile->buffer_stack_depth == CPP_STACK_MAX)
1530 cpp_fatal (pfile, "#include recursion too deep");
1531 return NULL;
1534 new = xobnew (pfile->buffer_ob, cpp_buffer);
1535 memset (new, 0, sizeof (cpp_buffer));
1537 new->buf = new->cur = buffer;
1538 new->rlimit = buffer + length;
1539 new->prev = buf;
1541 CPP_BUFFER (pfile) = new;
1542 return new;
1545 cpp_buffer *
1546 cpp_pop_buffer (pfile)
1547 cpp_reader *pfile;
1549 cpp_buffer *buf = CPP_BUFFER (pfile);
1551 unwind_if_stack (pfile, buf);
1552 #ifdef HAVE_MMAP_FILE
1553 if (buf->mapped)
1554 munmap ((caddr_t) buf->buf, buf->rlimit - buf->buf);
1555 else
1556 #endif
1557 if (buf->inc)
1558 free ((PTR) buf->buf);
1560 if (buf->inc)
1562 if (pfile->system_include_depth)
1563 pfile->system_include_depth--;
1564 if (pfile->include_depth)
1565 pfile->include_depth--;
1566 if (pfile->potential_control_macro)
1568 if (buf->inc->cmacro != NEVER_REREAD)
1569 buf->inc->cmacro = pfile->potential_control_macro;
1570 pfile->potential_control_macro = 0;
1572 pfile->input_stack_listing_current = 0;
1573 /* If the file will not be included again, then close it. */
1574 if (DO_NOT_REREAD (buf->inc))
1576 close (buf->inc->fd);
1577 buf->inc->fd = -1;
1581 CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
1582 obstack_free (pfile->buffer_ob, buf);
1583 pfile->buffer_stack_depth--;
1584 return CPP_BUFFER (pfile);
1587 #define obstack_chunk_alloc xmalloc
1588 #define obstack_chunk_free free
1589 void
1590 _cpp_init_stacks (pfile)
1591 cpp_reader *pfile;
1593 pfile->buffer_ob = xnew (struct obstack);
1594 obstack_init (pfile->buffer_ob);
1597 void
1598 _cpp_cleanup_stacks (pfile)
1599 cpp_reader *pfile;
1601 obstack_free (pfile->buffer_ob, 0);
1602 free (pfile->buffer_ob);