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
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. */
30 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) \
31 ? CPP_BUFFER (pfile)->cur[N] : EOF)
32 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
33 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
34 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
36 /* `struct directive' defines one #-directive, including how to handle it. */
40 unsigned int length
; /* Length of name */
41 const char *name
; /* Name of directive */
42 int (*func
) /* Function to handle directive */
43 PARAMS ((cpp_reader
*));
46 /* Stack of conditionals currently in progress
47 (including both successful and failing conditionals). */
51 struct if_stack
*next
;
52 int lineno
; /* line number where condition started */
53 int if_succeeded
; /* truth of last condition in this group */
54 const U_CHAR
*control_macro
; /* macro name for #ifndef around entire file */
55 int type
; /* type of last directive seen in this group */
57 typedef struct if_stack IF_STACK
;
59 /* Forward declarations. */
61 static void validate_else
PARAMS ((cpp_reader
*, const char *));
62 static int parse_ifdef
PARAMS ((cpp_reader
*, const char *));
63 static unsigned int parse_include
PARAMS ((cpp_reader
*, const char *));
64 static void conditional_skip
PARAMS ((cpp_reader
*, int, int,
66 static void skip_if_group
PARAMS ((cpp_reader
*));
67 static void pass_thru_directive
PARAMS ((const U_CHAR
*, size_t,
69 static int read_line_number
PARAMS ((cpp_reader
*, int *));
70 static U_CHAR
*detect_if_not_defined
PARAMS ((cpp_reader
*));
71 static int consider_directive_while_skipping
72 PARAMS ((cpp_reader
*, IF_STACK
*));
73 static int get_macro_name
PARAMS ((cpp_reader
*));
75 /* This is the table of directive handlers. It is ordered by
76 frequency of occurrence; the numbers at the end are directive
77 counts from all the source code I have lying around (egcs and libc
78 CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and
81 The entries with a dash and a name after the count are extensions,
82 of which all but #warning and #include_next are deprecated. The name
83 is where the extension appears to have come from. */
85 #define DIRECTIVE_TABLE \
86 D("define", do_define, T_DEFINE) /* 270554 */ \
87 D("include", do_include, T_INCLUDE) /* 52262 */ \
88 D("endif", do_endif, T_ENDIF) /* 45855 */ \
89 D("ifdef", do_ifdef, T_IFDEF) /* 22000 */ \
90 D("if", do_if, T_IF) /* 18162 */ \
91 D("else", do_else, T_ELSE) /* 9863 */ \
92 D("ifndef", do_ifndef, T_IFNDEF) /* 9675 */ \
93 D("undef", do_undef, T_UNDEF) /* 4837 */ \
94 D("line", do_line, T_LINE) /* 2465 */ \
95 D("elif", do_elif, T_ELIF) /* 610 */ \
96 D("error", do_error, T_ERROR) /* 475 */ \
97 D("pragma", do_pragma, T_PRAGMA) /* 195 */ \
98 D("warning", do_warning, T_WARNING) /* 22 - GNU */ \
99 D("include_next", do_include_next, T_INCLUDE_NEXT) /* 19 - GNU */ \
100 D("ident", do_ident, T_IDENT) /* 11 - SVR4 */ \
101 D("import", do_import, T_IMPORT) /* 0 - ObjC */ \
102 D("assert", do_assert, T_ASSERT) /* 0 - SVR4 */ \
103 D("unassert", do_unassert, T_UNASSERT) /* 0 - SVR4 */ \
104 D("sccs", do_sccs, T_SCCS) /* 0 - SVR2? */
106 /* Use the table to generate a series of prototypes, an enum for the
107 directive names, and an array of directive handlers. */
109 /* The directive-processing functions are declared to return int
110 instead of void, because some old compilers have trouble with
111 pointers to functions returning void. */
113 #define D(name, fun, tag) static int fun PARAMS ((cpp_reader *));
117 #define D(name, fun, tag) tag,
125 #define D(name, fun, tag) { sizeof name - 1, name, fun },
126 static const struct directive dtable
[] =
131 #undef DIRECTIVE_TABLE
133 /* Handle a possible # directive.
134 '#' has already been read. */
137 _cpp_handle_directive (pfile
)
143 long old_written
= CPP_WRITTEN (pfile
);
145 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
147 cpp_ice (pfile
, "handle_directive called on macro buffer");
151 _cpp_skip_hspace (pfile
);
154 /* # followed by a number is equivalent to #line. Do not recognize
155 this form in assembly language source files. Complain about this
156 form if we're being pedantic, but not if this is regurgitated
157 input (preprocessed or fed back in by the C++ frontend). */
158 if (c
>= '0' && c
<= '9')
160 if (CPP_OPTIONS (pfile
)->lang_asm
)
163 if (CPP_PEDANTIC (pfile
)
164 && ! CPP_OPTIONS (pfile
)->preprocessed
165 && ! CPP_BUFFER (pfile
)->manual_pop
)
166 cpp_pedwarn (pfile
, "`#' followed by integer");
171 /* If we are rescanning preprocessed input, don't obey any directives
173 if (CPP_OPTIONS (pfile
)->preprocessed
)
176 /* Now find the directive name. */
177 CPP_PUTC (pfile
, '#');
178 _cpp_parse_name (pfile
, GETC());
179 ident
= pfile
->token_buffer
+ old_written
+ 1;
180 len
= CPP_PWRITTEN (pfile
) - ident
;
183 /* A line of just `#' becomes blank. A line with something
184 other than an identifier after the # is reparsed as a non-
186 CPP_SET_WRITTEN (pfile
, old_written
);
187 return (PEEKC() == '\n');
190 /* Decode the keyword and call the appropriate expansion routine. */
191 for (i
= 0; i
< N_DIRECTIVES
; i
++)
193 if (dtable
[i
].length
== len
194 && !strncmp (dtable
[i
].name
, ident
, len
))
197 if (i
== N_DIRECTIVES
)
198 /* # identifier, but not a legit directive. Pass onward as a
199 CPP_DIRECTIVE token anyway - let the consumer worry about it. */
202 CPP_SET_WRITTEN (pfile
, old_written
);
204 if (pfile
->no_directives
)
206 cpp_error (pfile
, "`#%s' may not be used inside a macro argument",
208 _cpp_skip_rest_of_line (pfile
);
211 (*dtable
[i
].func
) (pfile
);
216 /* Pass a directive through to the output file.
217 BUF points to the contents of the directive, as a contiguous string.
218 LEN is the length of the string pointed to by BUF.
219 KEYWORD is the keyword-table entry for the directive. */
222 pass_thru_directive (buf
, len
, pfile
, keyword
)
228 const struct directive
*kt
= &dtable
[keyword
];
229 register unsigned klen
= kt
->length
;
231 CPP_RESERVE (pfile
, 1 + klen
+ len
);
232 CPP_PUTC_Q (pfile
, '#');
233 CPP_PUTS_Q (pfile
, kt
->name
, klen
);
234 if (len
!= 0 && buf
[0] != ' ')
235 CPP_PUTC_Q (pfile
, ' ');
236 CPP_PUTS_Q (pfile
, buf
, len
);
239 /* Subroutine of do_define: determine the name of the macro to be
243 get_macro_name (pfile
)
248 here
= CPP_WRITTEN (pfile
);
249 pfile
->no_macro_expand
++;
250 if (_cpp_get_directive_token (pfile
) != CPP_NAME
)
252 cpp_error (pfile
, "`#define' must be followed by an identifier");
256 len
= CPP_WRITTEN (pfile
) - here
;
257 if (len
== 7 && !strncmp (pfile
->token_buffer
+ here
, "defined", 7))
259 cpp_error (pfile
, "`defined' is not a legal macro name");
263 pfile
->no_macro_expand
--;
267 _cpp_skip_rest_of_line (pfile
);
268 pfile
->no_macro_expand
--;
272 /* Process a #define command. */
286 here
= CPP_WRITTEN (pfile
);
287 len
= get_macro_name (pfile
);
291 /* Copy out the name so we can pop the token buffer. */
292 len
= CPP_WRITTEN (pfile
) - here
;
293 sym
= (U_CHAR
*) alloca (len
+ 1);
294 memcpy (sym
, pfile
->token_buffer
+ here
, len
);
296 CPP_SET_WRITTEN (pfile
, here
);
298 /* If the next character, with no intervening whitespace, is '(',
299 then this is a function-like macro. */
303 else if (c
!= '\n' && !is_hspace (c
))
304 /* Otherwise, C99 requires white space after the name. We treat it
305 as an object-like macro if this happens, with a warning. */
306 cpp_pedwarn (pfile
, "missing white space after `#define %.*s'", len
, sym
);
308 def
= _cpp_create_definition (pfile
, funlike
);
312 slot
= _cpp_lookup_slot (pfile
, sym
, len
, 1, &hash
);
316 HASHNODE
*hp
= *slot
;
318 /* Redefining a macro is ok if the definitions are the same. */
319 if (hp
->type
== T_MACRO
)
320 ok
= ! _cpp_compare_defs (pfile
, def
, hp
->value
.defn
);
321 /* Redefining a constant is ok with -D. */
322 else if (hp
->type
== T_CONST
|| hp
->type
== T_STDC
)
323 ok
= ! CPP_OPTIONS (pfile
)->done_initializing
;
324 /* Otherwise it's not ok. */
327 /* Print the warning or error if it's not ok. */
330 if (hp
->type
== T_POISON
)
331 cpp_error (pfile
, "redefining poisoned `%.*s'", len
, sym
);
333 cpp_pedwarn (pfile
, "`%.*s' redefined", len
, sym
);
334 if (hp
->type
== T_MACRO
&& CPP_OPTIONS (pfile
)->done_initializing
)
336 DEFINITION
*d
= hp
->value
.defn
;
337 cpp_pedwarn_with_file_and_line (pfile
, d
->file
, d
->line
, d
->col
,
338 "this is the location of the previous definition");
341 if (hp
->type
!= T_POISON
)
343 /* Replace the old definition. */
344 if (hp
->type
== T_MACRO
)
345 _cpp_free_definition (hp
->value
.defn
);
347 hp
->value
.defn
= def
;
352 HASHNODE
*hp
= _cpp_make_hashnode (sym
, len
, T_MACRO
, hash
);
353 hp
->value
.defn
= def
;
357 if (CPP_OPTIONS (pfile
)->debug_output
358 || CPP_OPTIONS (pfile
)->dump_macros
== dump_definitions
)
359 _cpp_dump_definition (pfile
, sym
, len
, def
);
360 else if (CPP_OPTIONS (pfile
)->dump_macros
== dump_names
)
361 pass_thru_directive (sym
, len
, pfile
, T_DEFINE
);
367 * write out a #line command, for instance, after an #include file.
368 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
372 _cpp_output_line_command (pfile
, file_change
)
374 enum file_change_code file_change
;
379 if (CPP_OPTIONS (pfile
)->no_line_commands
380 || CPP_OPTIONS (pfile
)->no_output
)
383 ip
= cpp_file_buffer (pfile
);
384 cpp_buf_line_and_col (ip
, &line
, NULL
);
386 /* If the current file has not changed, we omit the #line if it would
387 appear to be a no-op, and we output a few newlines instead
388 if we want to increase the line number by a small amount.
389 We cannot do this if pfile->lineno is zero, because that means we
390 haven't output any line commands yet. (The very first line command
391 output is a `same_file' command.) */
392 if (file_change
== same_file
&& pfile
->lineno
!= 0)
394 if (line
== pfile
->lineno
)
397 /* If the inherited line number is a little too small,
398 output some newlines instead of a #line command. */
399 if (line
> pfile
->lineno
&& line
< pfile
->lineno
+ 8)
401 CPP_RESERVE (pfile
, 20);
402 while (line
> pfile
->lineno
)
404 CPP_PUTC_Q (pfile
, '\n');
411 CPP_RESERVE (pfile
, 4 * strlen (ip
->nominal_fname
) + 50);
412 CPP_PUTS_Q (pfile
, "# ", 2);
414 sprintf ((char *) CPP_PWRITTEN (pfile
), "%ld ", line
);
415 CPP_ADJUST_WRITTEN (pfile
, strlen (CPP_PWRITTEN (pfile
)));
417 _cpp_quote_string (pfile
, ip
->nominal_fname
);
418 if (file_change
!= same_file
&& file_change
!= rename_file
)
420 CPP_PUTC_Q (pfile
, ' ');
421 CPP_PUTC_Q (pfile
, file_change
== enter_file
? '1' : '2');
423 /* Tell cc1 if following text comes from a system header file. */
424 if (ip
->system_header_p
)
426 CPP_PUTC_Q (pfile
, ' ');
427 CPP_PUTC_Q (pfile
, '3');
429 #ifndef NO_IMPLICIT_EXTERN_C
430 /* Tell cc1plus if following text should be treated as C. */
431 if (ip
->system_header_p
== 2 && CPP_OPTIONS (pfile
)->cplusplus
)
433 CPP_PUTC_Q (pfile
, ' ');
434 CPP_PUTC_Q (pfile
, '4');
437 CPP_PUTC_Q (pfile
, '\n');
438 pfile
->lineno
= line
;
441 /* Handle #include and #import. */
444 parse_include (pfile
, name
)
448 long old_written
= CPP_WRITTEN (pfile
);
449 enum cpp_token token
;
452 pfile
->parsing_include_directive
++;
453 token
= _cpp_get_directive_token (pfile
);
454 pfile
->parsing_include_directive
--;
456 len
= CPP_WRITTEN (pfile
) - old_written
;
458 if (token
== CPP_STRING
)
459 ; /* No special treatment required. */
461 else if (token
== CPP_NAME
)
463 /* Support '#include xyz' like VAX-C. It is taken as
464 '#include <xyz.h>' and generates a warning. */
465 cpp_warning (pfile
, "#%s filename is obsolete, use #%s <filename.h>",
468 /* Rewrite the token to <xyz.h>. */
469 CPP_RESERVE (pfile
, 4);
471 memmove (pfile
->token_buffer
+ old_written
+ 1,
472 pfile
->token_buffer
+ old_written
,
473 CPP_WRITTEN (pfile
) - old_written
);
474 pfile
->token_buffer
[old_written
] = '<';
475 CPP_PUTS_Q (pfile
, ".h>", 2);
480 cpp_error (pfile
, "`#%s' expects \"FILENAME\" or <FILENAME>", name
);
481 CPP_SET_WRITTEN (pfile
, old_written
);
482 _cpp_skip_rest_of_line (pfile
);
486 CPP_NUL_TERMINATE (pfile
);
487 CPP_ADJUST_WRITTEN (pfile
, 1);
489 if (_cpp_get_directive_token (pfile
) != CPP_VSPACE
)
491 cpp_error (pfile
, "junk at end of `#%s'", name
);
492 _cpp_skip_rest_of_line (pfile
);
495 CPP_SET_WRITTEN (pfile
, old_written
);
498 cpp_error (pfile
, "empty file name in `#%s'", name
);
510 len
= parse_include (pfile
, dtable
[T_INCLUDE
].name
);
511 token
= alloca (len
+ 1);
512 strcpy (token
, CPP_PWRITTEN (pfile
));
514 if (CPP_OPTIONS (pfile
)->dump_includes
)
515 pass_thru_directive (token
, len
, pfile
, T_INCLUDE
);
517 _cpp_execute_include (pfile
, token
, len
, 0, 0);
528 if (CPP_PEDANTIC (pfile
))
529 cpp_pedwarn (pfile
, "ANSI C does not allow `#import'");
531 if (CPP_OPTIONS (pfile
)->warn_import
532 && !CPP_BUFFER (pfile
)->system_header_p
&& !pfile
->import_warning
)
534 pfile
->import_warning
= 1;
536 "#import is obsolete, use an #ifndef wrapper in the header file");
539 len
= parse_include (pfile
, dtable
[T_IMPORT
].name
);
540 token
= alloca (len
+ 1);
541 strcpy (token
, CPP_PWRITTEN (pfile
));
543 if (CPP_OPTIONS (pfile
)->dump_includes
)
544 pass_thru_directive (token
, len
, pfile
, T_IMPORT
);
546 _cpp_execute_include (pfile
, token
, len
, 1, 0);
551 do_include_next (pfile
)
556 struct file_name_list
*search_start
= 0;
558 if (CPP_PEDANTIC (pfile
))
559 cpp_pedwarn (pfile
, "ANSI C does not allow `#include_next'");
561 len
= parse_include (pfile
, dtable
[T_INCLUDE_NEXT
].name
);
563 token
= alloca (len
+ 1);
564 strcpy (token
, CPP_PWRITTEN (pfile
));
566 if (CPP_OPTIONS (pfile
)->dump_includes
)
567 pass_thru_directive (token
, len
, pfile
, T_INCLUDE_NEXT
);
569 /* For #include_next, skip in the search path past the dir in which the
570 containing file was found. Treat files specified using an absolute path
571 as if there are no more directories to search. Treat the primary source
572 file like any other included source, but generate a warning. */
573 if (CPP_PREV_BUFFER (CPP_BUFFER (pfile
)))
575 if (CPP_BUFFER (pfile
)->ihash
->foundhere
!= ABSOLUTE_PATH
)
576 search_start
= CPP_BUFFER (pfile
)->ihash
->foundhere
->next
;
579 cpp_warning (pfile
, "#include_next in primary source file");
581 _cpp_execute_include (pfile
, token
, len
, 0, search_start
);
585 /* Subroutine of do_line. Read next token from PFILE without adding it to
586 the output buffer. If it is a number between 1 and 4, store it in *NUM
587 and return 1; otherwise, return 0 and complain if we aren't at the end
591 read_line_number (pfile
, num
)
595 long save_written
= CPP_WRITTEN (pfile
);
597 enum cpp_token token
= _cpp_get_directive_token (pfile
);
598 CPP_SET_WRITTEN (pfile
, save_written
);
599 p
= pfile
->token_buffer
+ save_written
;
601 if (token
== CPP_NUMBER
&& *p
>= '1' && *p
<= '4' && p
[1] == '\0')
608 if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
)
609 cpp_error (pfile
, "invalid format `#line' command");
614 /* Interpret #line command.
615 Note that the filename string (if any) is treated as if it were an
616 include filename. That means no escape handling. */
622 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
624 long old_written
= CPP_WRITTEN (pfile
);
625 enum file_change_code file_change
= same_file
;
626 enum cpp_token token
;
629 token
= _cpp_get_directive_token (pfile
);
631 if (token
!= CPP_NUMBER
)
633 cpp_error (pfile
, "token after `#line' is not an integer");
634 goto bad_line_directive
;
637 new_lineno
= strtol (pfile
->token_buffer
+ old_written
, &x
, 10);
640 cpp_error (pfile
, "token after `#line' is not an integer");
641 goto bad_line_directive
;
643 CPP_SET_WRITTEN (pfile
, old_written
);
645 if (CPP_PEDANTIC (pfile
) && (new_lineno
<= 0 || new_lineno
> 32767))
646 cpp_pedwarn (pfile
, "line number out of range in `#line' command");
648 token
= _cpp_get_directive_token (pfile
);
650 if (token
== CPP_STRING
)
652 U_CHAR
*fname
= pfile
->token_buffer
+ old_written
+ 1;
653 U_CHAR
*end_name
= CPP_PWRITTEN (pfile
) - 1;
654 int action_number
= 0;
656 file_change
= rename_file
;
658 if (read_line_number (pfile
, &action_number
))
660 if (CPP_PEDANTIC (pfile
))
661 cpp_pedwarn (pfile
, "garbage at end of `#line' command");
663 if (action_number
== 1)
665 file_change
= enter_file
;
666 read_line_number (pfile
, &action_number
);
668 else if (action_number
== 2)
670 file_change
= leave_file
;
671 read_line_number (pfile
, &action_number
);
673 if (action_number
== 3)
675 ip
->system_header_p
= 1;
676 read_line_number (pfile
, &action_number
);
678 if (action_number
== 4)
680 ip
->system_header_p
= 2;
681 read_line_number (pfile
, &action_number
);
687 if (strcmp (fname
, ip
->nominal_fname
))
689 const char *newname
, *oldname
;
690 if (!strcmp (fname
, ip
->ihash
->name
))
691 newname
= ip
->ihash
->name
;
692 else if (ip
->last_nominal_fname
693 && !strcmp (fname
, ip
->last_nominal_fname
))
694 newname
= ip
->last_nominal_fname
;
696 newname
= xstrdup (fname
);
698 oldname
= ip
->nominal_fname
;
699 ip
->nominal_fname
= newname
;
701 if (ip
->last_nominal_fname
702 && ip
->last_nominal_fname
!= oldname
703 && ip
->last_nominal_fname
!= newname
704 && ip
->last_nominal_fname
!= ip
->ihash
->name
)
705 free ((void *) ip
->last_nominal_fname
);
707 if (newname
== ip
->ihash
->name
)
708 ip
->last_nominal_fname
= NULL
;
710 ip
->last_nominal_fname
= oldname
;
713 else if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
)
715 cpp_error (pfile
, "token after `#line %d' is not a string", new_lineno
);
716 goto bad_line_directive
;
719 /* The Newline at the end of this line remains to be processed.
720 To put the next line at the specified line number,
721 we must store a line number now that is one less. */
722 ip
->lineno
= new_lineno
- 1;
723 CPP_SET_WRITTEN (pfile
, old_written
);
724 _cpp_output_line_command (pfile
, file_change
);
728 _cpp_skip_rest_of_line (pfile
);
729 CPP_SET_WRITTEN (pfile
, old_written
);
733 /* Remove the definition of a symbol from the symbol table.
734 According to the C standard, it is not an error to undef
735 something that has no definitions. */
742 U_CHAR
*buf
, *name
, *limit
;
744 long here
= CPP_WRITTEN (pfile
);
745 enum cpp_token token
;
747 _cpp_skip_hspace (pfile
);
751 cpp_error (pfile
, "token after #undef is not an identifier");
752 _cpp_skip_rest_of_line (pfile
);
756 _cpp_parse_name (pfile
, c
);
757 buf
= pfile
->token_buffer
+ here
;
758 limit
= CPP_PWRITTEN(pfile
);
760 /* Copy out the token so we can pop the token buffer. */
762 name
= (U_CHAR
*) alloca (len
+ 1);
763 memcpy (name
, buf
, len
);
766 token
= _cpp_get_directive_token (pfile
);
767 if (token
!= CPP_VSPACE
)
769 cpp_pedwarn (pfile
, "junk on line after #undef");
770 _cpp_skip_rest_of_line (pfile
);
772 CPP_SET_WRITTEN (pfile
, here
);
774 slot
= _cpp_lookup_slot (pfile
, name
, len
, 0, 0);
777 HASHNODE
*hp
= *slot
;
778 /* If we are generating additional info for debugging (with -g) we
779 need to pass through all effective #undef commands. */
780 if (CPP_OPTIONS (pfile
)->debug_output
)
781 pass_thru_directive (name
, len
, pfile
, T_UNDEF
);
782 if (hp
->type
== T_POISON
)
783 cpp_error (pfile
, "cannot undefine poisoned `%s'", hp
->name
);
786 if (hp
->type
!= T_MACRO
)
787 cpp_warning (pfile
, "undefining `%s'", hp
->name
);
789 htab_clear_slot (pfile
->hashtab
, (void **)slot
);
797 * Report an error detected by the program we are processing.
798 * Use the text of the line in the error message.
799 * (We use error because it prints the filename & line#.)
806 const U_CHAR
*text
, *limit
;
808 _cpp_skip_hspace (pfile
);
809 text
= CPP_BUFFER (pfile
)->cur
;
810 _cpp_skip_rest_of_line (pfile
);
811 limit
= CPP_BUFFER (pfile
)->cur
;
813 cpp_error (pfile
, "#error %.*s", (int)(limit
- text
), text
);
818 * Report a warning detected by the program we are processing.
819 * Use the text of the line in the warning message, then continue.
826 const U_CHAR
*text
, *limit
;
828 _cpp_skip_hspace (pfile
);
829 text
= CPP_BUFFER (pfile
)->cur
;
830 _cpp_skip_rest_of_line (pfile
);
831 limit
= CPP_BUFFER (pfile
)->cur
;
833 if (CPP_PEDANTIC (pfile
))
834 cpp_pedwarn (pfile
, "ANSI C does not allow `#warning'");
836 cpp_warning (pfile
, "#warning %.*s", (int)(limit
- text
), text
);
840 /* Report program identification. */
846 long old_written
= CPP_WRITTEN (pfile
);
848 /* Allow #ident in system headers, since that's not user's fault. */
849 if (CPP_PEDANTIC (pfile
))
850 cpp_pedwarn (pfile
, "ANSI C does not allow `#ident'");
852 CPP_PUTS (pfile
, "#ident ", 7);
854 /* Next token should be a string constant. */
855 if (_cpp_get_directive_token (pfile
) == CPP_STRING
)
856 /* And then a newline. */
857 if (_cpp_get_directive_token (pfile
) == CPP_VSPACE
)
858 /* Good - ship it. */
861 cpp_error (pfile
, "invalid #ident");
862 _cpp_skip_rest_of_line (pfile
);
863 CPP_SET_WRITTEN (pfile
, old_written
); /* discard directive */
868 /* Pragmata handling. We handle some of these, and pass the rest on
869 to the front end. C99 defines three pragmas and says that no macro
870 expansion is to be performed on them; whether or not macro
871 expansion happens for other pragmas is implementation defined.
872 This implementation never macro-expands the text after #pragma.
874 We currently do not support the _Pragma operator. Support for that
875 has to be coordinated with the front end. Proposed implementation:
876 both #pragma blah blah and _Pragma("blah blah") become
877 __builtin_pragma(blah blah) and we teach the parser about that. */
879 /* Sub-handlers for the pragmas needing treatment here.
880 They return 1 if the token buffer is to be popped, 0 if not. */
881 static int do_pragma_once
PARAMS ((cpp_reader
*));
882 static int do_pragma_implementation
PARAMS ((cpp_reader
*));
883 static int do_pragma_poison
PARAMS ((cpp_reader
*));
884 static int do_pragma_default
PARAMS ((cpp_reader
*));
893 enum cpp_token token
;
895 here
= CPP_WRITTEN (pfile
);
896 CPP_PUTS (pfile
, "#pragma ", 8);
898 key
= CPP_WRITTEN (pfile
);
899 pfile
->no_macro_expand
++;
900 token
= _cpp_get_directive_token (pfile
);
901 if (token
!= CPP_NAME
)
903 if (token
== CPP_VSPACE
)
909 buf
= pfile
->token_buffer
+ key
;
910 CPP_PUTC (pfile
, ' ');
912 #define tokis(x) !strncmp((char *) buf, x, sizeof(x) - 1)
914 pop
= do_pragma_once (pfile
);
915 else if (tokis ("implementation"))
916 pop
= do_pragma_implementation (pfile
);
917 else if (tokis ("poison"))
918 pop
= do_pragma_poison (pfile
);
920 pop
= do_pragma_default (pfile
);
923 if (_cpp_get_directive_token (pfile
) != CPP_VSPACE
)
927 CPP_SET_WRITTEN (pfile
, here
);
928 pfile
->no_macro_expand
--;
932 cpp_error (pfile
, "malformed #pragma directive");
933 _cpp_skip_rest_of_line (pfile
);
935 CPP_SET_WRITTEN (pfile
, here
);
936 pfile
->no_macro_expand
--;
941 do_pragma_default (pfile
)
944 while (_cpp_get_directive_token (pfile
) != CPP_VSPACE
)
945 CPP_PUTC (pfile
, ' ');
950 do_pragma_once (pfile
)
953 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
955 /* Allow #pragma once in system headers, since that's not the user's
957 if (!ip
->system_header_p
)
958 cpp_warning (pfile
, "`#pragma once' is obsolete");
960 if (CPP_PREV_BUFFER (ip
) == NULL
)
961 cpp_warning (pfile
, "`#pragma once' outside include file");
963 ip
->ihash
->control_macro
= (const U_CHAR
*) ""; /* never repeat */
969 do_pragma_implementation (pfile
)
972 /* Be quiet about `#pragma implementation' for a file only if it hasn't
973 been included yet. */
974 enum cpp_token token
;
975 long written
= CPP_WRITTEN (pfile
);
980 token
= _cpp_get_directive_token (pfile
);
981 if (token
== CPP_VSPACE
)
983 else if (token
!= CPP_STRING
)
985 cpp_error (pfile
, "malformed #pragma implementation");
989 /* Trim the leading and trailing quote marks from the string. */
990 name
= pfile
->token_buffer
+ written
+ 1;
991 len
= CPP_PWRITTEN (pfile
) - name
;
992 copy
= (U_CHAR
*) alloca (len
);
993 memcpy (copy
, name
, len
- 1);
994 copy
[len
- 1] = '\0';
996 if (cpp_included (pfile
, copy
))
998 "`#pragma implementation' for `%s' appears after file is included",
1004 do_pragma_poison (pfile
)
1007 /* Poison these symbols so that all subsequent usage produces an
1013 enum cpp_token token
;
1017 /* As a rule, don't include #pragma poison commands in output,
1018 unless the user asks for them. */
1019 writeit
= (CPP_OPTIONS (pfile
)->debug_output
1020 || CPP_OPTIONS (pfile
)->dump_macros
== dump_definitions
1021 || CPP_OPTIONS (pfile
)->dump_macros
== dump_names
);
1025 written
= CPP_WRITTEN (pfile
);
1026 token
= _cpp_get_directive_token (pfile
);
1027 if (token
== CPP_VSPACE
)
1029 if (token
!= CPP_NAME
)
1031 cpp_error (pfile
, "invalid #pragma poison directive");
1032 _cpp_skip_rest_of_line (pfile
);
1036 p
= pfile
->token_buffer
+ written
;
1038 slot
= _cpp_lookup_slot (pfile
, p
, len
, 1, &hash
);
1041 HASHNODE
*hp
= *slot
;
1042 if (hp
->type
!= T_POISON
)
1044 cpp_warning (pfile
, "poisoning existing macro `%s'", p
);
1045 if (hp
->type
== T_MACRO
)
1046 _cpp_free_definition (hp
->value
.defn
);
1048 hp
->type
= T_POISON
;
1053 HASHNODE
*hp
= _cpp_make_hashnode (p
, len
, T_POISON
, hash
);
1054 hp
->value
.cpval
= 0;
1058 CPP_PUTC (pfile
, ' ');
1063 /* Just ignore #sccs, on systems where we define it at all. */
1068 #ifdef SCCS_DIRECTIVE
1069 if (CPP_PEDANTIC (pfile
))
1070 cpp_pedwarn (pfile
, "ANSI C does not allow `#sccs'");
1072 cpp_error (pfile
, "undefined or invalid # directive `sccs'");
1074 _cpp_skip_rest_of_line (pfile
);
1079 /* We've found an `#if' directive. If the only thing before it in
1080 this file is white space, and if it is of the form
1081 `#if ! defined SYMBOL', then SYMBOL is a possible controlling macro
1082 for inclusion of this file. (See redundant_include_p in cppfiles.c
1083 for an explanation of controlling macros.) If so, return a
1084 malloc'd copy of SYMBOL. Otherwise, return NULL. */
1087 detect_if_not_defined (pfile
)
1090 U_CHAR
*control_macro
= 0;
1092 if (pfile
->only_seen_white
== 2)
1095 enum cpp_token token
;
1098 int need_rparen
= 0;
1100 /* Save state required for restore. */
1101 pfile
->no_macro_expand
++;
1102 CPP_SET_MARK (pfile
);
1103 base_offset
= CPP_WRITTEN (pfile
);
1106 if (_cpp_get_directive_token (pfile
) != CPP_OTHER
1107 || CPP_WRITTEN (pfile
) != (size_t) base_offset
+ 1
1108 || CPP_PWRITTEN (pfile
)[-1] != '!')
1111 /* ...then `defined', */
1112 token_offset
= CPP_WRITTEN (pfile
);
1113 token
= _cpp_get_directive_token (pfile
);
1114 if (token
!= CPP_NAME
)
1116 ident
= pfile
->token_buffer
+ token_offset
;
1117 CPP_NUL_TERMINATE (pfile
);
1118 if (strcmp (ident
, "defined"))
1121 /* ...then an optional '(' and the name, */
1122 token_offset
= CPP_WRITTEN (pfile
);
1123 token
= _cpp_get_directive_token (pfile
);
1124 if (token
== CPP_LPAREN
)
1126 token_offset
= CPP_WRITTEN (pfile
);
1127 token
= _cpp_get_directive_token (pfile
);
1128 if (token
!= CPP_NAME
)
1132 else if (token
!= CPP_NAME
)
1135 ident
= pfile
->token_buffer
+ token_offset
;
1136 CPP_NUL_TERMINATE (pfile
);
1138 /* ...then the ')', if necessary, */
1139 if ((!need_rparen
|| _cpp_get_directive_token (pfile
) == CPP_RPAREN
)
1140 /* ...and make sure there's nothing else on the line. */
1141 && _cpp_get_directive_token (pfile
) == CPP_VSPACE
)
1142 control_macro
= (U_CHAR
*) xstrdup (ident
);
1145 CPP_SET_WRITTEN (pfile
, base_offset
);
1146 pfile
->no_macro_expand
--;
1147 CPP_GOTO_MARK (pfile
);
1150 return control_macro
;
1154 * #if is straightforward; just call _cpp_parse_expr, then conditional_skip.
1155 * Also, check for a reinclude preventer of the form #if !defined (MACRO).
1162 U_CHAR
*control_macro
= detect_if_not_defined (pfile
);
1163 int value
= _cpp_parse_expr (pfile
);
1164 conditional_skip (pfile
, value
== 0, T_IF
, control_macro
);
1169 * handle a #elif directive by not changing if_stack either.
1170 * see the comment above do_else.
1177 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
1179 cpp_error (pfile
, "`#elif' not within a conditional");
1184 if (pfile
->if_stack
->type
== T_ELSE
)
1186 cpp_error (pfile
, "`#elif' after `#else'");
1187 cpp_error_with_line (pfile
, pfile
->if_stack
->lineno
, -1,
1188 "the conditional began here");
1190 pfile
->if_stack
->type
= T_ELIF
;
1193 if (pfile
->if_stack
->if_succeeded
)
1194 skip_if_group (pfile
);
1197 if (_cpp_parse_expr (pfile
) == 0)
1198 skip_if_group (pfile
);
1201 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
1202 _cpp_output_line_command (pfile
, same_file
);
1208 /* Parse an #ifdef or #ifndef directive. Returns 1 for defined, 0 for
1209 not defined; the macro tested is left in the token buffer (but
1213 parse_ifdef (pfile
, name
)
1219 enum cpp_token token
;
1220 long old_written
= CPP_WRITTEN (pfile
);
1223 pfile
->no_macro_expand
++;
1224 token
= _cpp_get_directive_token (pfile
);
1225 pfile
->no_macro_expand
--;
1227 ident
= pfile
->token_buffer
+ old_written
;
1228 len
= CPP_WRITTEN (pfile
) - old_written
;
1230 if (token
== CPP_VSPACE
)
1232 if (! CPP_TRADITIONAL (pfile
))
1233 cpp_pedwarn (pfile
, "`#%s' with no argument", name
);
1237 else if (token
== CPP_NAME
)
1239 defined
= cpp_defined (pfile
, ident
, len
);
1240 CPP_NUL_TERMINATE (pfile
);
1241 CPP_ADJUST_WRITTEN (pfile
, 1);
1246 if (! CPP_TRADITIONAL (pfile
))
1247 cpp_error (pfile
, "`#%s' with invalid argument", name
);
1250 if (!CPP_TRADITIONAL (pfile
))
1252 if (_cpp_get_directive_token (pfile
) == CPP_VSPACE
)
1255 cpp_pedwarn (pfile
, "garbage at end of `#%s' argument", name
);
1257 _cpp_skip_rest_of_line (pfile
);
1260 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
1264 /* #ifdef is dead simple. */
1270 int skip
= ! parse_ifdef (pfile
, dtable
[T_IFDEF
].name
);
1271 conditional_skip (pfile
, skip
, T_IFDEF
, 0);
1275 /* #ifndef is a tad more complex, because we need to check for a
1276 no-reinclusion wrapper. */
1282 int start_of_file
, skip
;
1283 U_CHAR
*control_macro
= 0;
1285 start_of_file
= pfile
->only_seen_white
== 2;
1286 skip
= parse_ifdef (pfile
, dtable
[T_IFNDEF
].name
);
1288 if (start_of_file
&& !skip
)
1289 control_macro
= xstrdup (CPP_PWRITTEN (pfile
));
1291 conditional_skip (pfile
, skip
, T_IFNDEF
, control_macro
);
1295 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
1296 If this is a #ifndef starting at the beginning of a file,
1297 CONTROL_MACRO is the macro name tested by the #ifndef.
1298 Otherwise, CONTROL_MACRO is 0. */
1301 conditional_skip (pfile
, skip
, type
, control_macro
)
1305 U_CHAR
*control_macro
;
1309 temp
= (IF_STACK
*) xcalloc (1, sizeof (IF_STACK
));
1310 temp
->lineno
= CPP_BUFFER (pfile
)->lineno
;
1311 temp
->next
= pfile
->if_stack
;
1312 temp
->control_macro
= control_macro
;
1313 pfile
->if_stack
= temp
;
1315 pfile
->if_stack
->type
= type
;
1318 skip_if_group (pfile
);
1321 ++pfile
->if_stack
->if_succeeded
;
1322 _cpp_output_line_command (pfile
, same_file
);
1326 /* Subroutine of skip_if_group. Examine one preprocessing directive and
1327 return 0 if skipping should continue, 1 if it should halt. Also
1328 adjusts the if_stack as appropriate.
1329 The `#' has been read, but not the identifier. */
1332 consider_directive_while_skipping (pfile
, stack
)
1337 const struct directive
*kt
;
1342 _cpp_skip_hspace (pfile
);
1344 ident
= CPP_WRITTEN (pfile
);
1345 _cpp_parse_name (pfile
, GETC());
1346 len
= CPP_WRITTEN (pfile
) - ident
;
1348 CPP_SET_WRITTEN (pfile
, ident
);
1350 for (i
= 0; i
< N_DIRECTIVES
; i
++)
1353 if (kt
->length
== len
1354 && strncmp (pfile
->token_buffer
+ ident
, kt
->name
, kt
->length
) == 0)
1360 temp
= (IF_STACK
*) xmalloc (sizeof (IF_STACK
));
1361 temp
->next
= pfile
->if_stack
;
1362 pfile
->if_stack
= temp
;
1367 if (pfile
->if_stack
!= stack
)
1368 validate_else (pfile
, dtable
[i
].name
);
1371 if (pfile
->if_stack
== stack
)
1375 pfile
->if_stack
->type
= i
;
1380 if (pfile
->if_stack
!= stack
)
1381 validate_else (pfile
, dtable
[i
].name
);
1383 if (pfile
->if_stack
== stack
)
1386 temp
= pfile
->if_stack
;
1387 pfile
->if_stack
= temp
->next
;
1396 /* Don't let erroneous code go by. */
1397 if (!CPP_OPTIONS (pfile
)->lang_asm
&& CPP_PEDANTIC (pfile
))
1398 cpp_pedwarn (pfile
, "invalid preprocessor directive name");
1402 /* skip to #endif, #else, or #elif. adjust line numbers, etc.
1403 * leaves input ptr at the sharp sign found.
1406 skip_if_group (pfile
)
1410 IF_STACK
*save_if_stack
= pfile
->if_stack
; /* don't pop past here */
1411 const U_CHAR
*beg_of_line
;
1414 old_written
= CPP_WRITTEN (pfile
);
1418 beg_of_line
= CPP_BUFFER (pfile
)->cur
;
1420 if (! CPP_TRADITIONAL (pfile
))
1421 _cpp_skip_hspace (pfile
);
1425 CPP_BUMP_LINE (pfile
);
1430 if (consider_directive_while_skipping (pfile
, save_if_stack
))
1434 return; /* Caller will issue error. */
1437 _cpp_skip_rest_of_line (pfile
);
1441 return; /* Caller will issue error. */
1443 CPP_BUMP_LINE (pfile
);
1446 /* Back up to the beginning of this line. Caller will process the
1448 CPP_BUFFER (pfile
)->cur
= beg_of_line
;
1449 pfile
->only_seen_white
= 1;
1453 * handle a #else directive. Do this by just continuing processing
1454 * without changing if_stack ; this is so that the error message
1455 * for missing #endif's etc. will point to the original #if. It
1456 * is possible that something different would be better.
1463 validate_else (pfile
, dtable
[T_ELSE
].name
);
1464 _cpp_skip_rest_of_line (pfile
);
1466 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
1468 cpp_error (pfile
, "`#else' not within a conditional");
1473 /* #ifndef can't have its special treatment for containing the whole file
1474 if it has a #else clause. */
1475 pfile
->if_stack
->control_macro
= 0;
1477 if (pfile
->if_stack
->type
== T_ELSE
)
1479 cpp_error (pfile
, "`#else' after `#else'");
1480 cpp_error_with_line (pfile
, pfile
->if_stack
->lineno
, -1,
1481 "the conditional began here");
1483 pfile
->if_stack
->type
= T_ELSE
;
1486 if (pfile
->if_stack
->if_succeeded
)
1487 skip_if_group (pfile
);
1490 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
1491 _cpp_output_line_command (pfile
, same_file
);
1497 * unstack after #endif command
1504 validate_else (pfile
, dtable
[T_ENDIF
].name
);
1505 _cpp_skip_rest_of_line (pfile
);
1507 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
1508 cpp_error (pfile
, "`#endif' not within a conditional");
1511 IF_STACK
*temp
= pfile
->if_stack
;
1512 pfile
->if_stack
= temp
->next
;
1513 if (temp
->control_macro
!= 0)
1515 /* This #endif matched a #ifndef at the start of the file.
1516 See if it is at the end of the file. */
1519 CPP_SET_MARK (pfile
);
1523 _cpp_skip_hspace (pfile
);
1528 CPP_GOTO_MARK (pfile
);
1532 /* This #endif ends a #ifndef
1533 that contains all of the file (aside from whitespace).
1534 Arrange not to include the file again
1535 if the macro that was tested is defined. */
1536 CPP_BUFFER (pfile
)->ihash
->control_macro
= temp
->control_macro
;
1540 _cpp_output_line_command (pfile
, same_file
);
1545 /* Issue -pedantic warning for text which is not a comment following
1546 an #else or #endif. Do not warn in system headers, as this is harmless
1547 and very common on old systems. */
1550 validate_else (pfile
, directive
)
1552 const char *directive
;
1554 if (! CPP_PEDANTIC (pfile
))
1557 _cpp_skip_hspace (pfile
);
1558 if (PEEKC () != '\n')
1560 "text following `#%s' violates ANSI standard", directive
);
1564 _cpp_handle_eof (pfile
)
1567 cpp_buffer
*next_buf
= CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
1568 struct if_stack
*ifs
, *nifs
;
1570 /* Unwind the conditional stack and generate error messages. */
1571 for (ifs
= pfile
->if_stack
;
1572 ifs
!= CPP_BUFFER (pfile
)->if_stack
;
1575 cpp_error_with_line (pfile
, ifs
->lineno
, -1,
1576 "unterminated `#%s' conditional",
1577 dtable
[ifs
->type
].name
);
1582 pfile
->if_stack
= ifs
;
1584 if (CPP_BUFFER (pfile
)->nominal_fname
&& next_buf
!= NULL
)
1586 /* We're about to return from an #include file.
1587 Emit #line information now (as part of the CPP_POP) result.
1588 But the #line refers to the file we will pop to. */
1589 cpp_buffer
*cur_buffer
= CPP_BUFFER (pfile
);
1590 CPP_BUFFER (pfile
) = next_buf
;
1591 pfile
->input_stack_listing_current
= 0;
1592 _cpp_output_line_command (pfile
, leave_file
);
1593 CPP_BUFFER (pfile
) = cur_buffer
;
1596 CPP_BUFFER (pfile
)->seen_eof
= 1;
1605 HASHNODE
*base
, *this;
1606 HASHNODE
**bslot
, **tslot
;
1608 unsigned long bhash
, thash
;
1610 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
)
1611 cpp_pedwarn (pfile
, "ANSI C does not allow `#assert'");
1613 _cpp_skip_hspace (pfile
);
1614 sym
= CPP_PWRITTEN (pfile
); /* remember where it starts */
1615 ret
= _cpp_parse_assertion (pfile
);
1620 cpp_error (pfile
, "missing token-sequence in `#assert'");
1624 _cpp_skip_hspace (pfile
);
1626 if (c
!= EOF
&& c
!= '\n')
1628 cpp_error (pfile
, "junk at end of `#assert'");
1632 tlen
= strlen (sym
);
1633 blen
= (U_CHAR
*) strchr (sym
, '(') - sym
;
1634 tslot
= _cpp_lookup_slot (pfile
, sym
, tlen
, 1, &thash
);
1637 cpp_warning (pfile
, "`%s' re-asserted", sym
);
1641 bslot
= _cpp_lookup_slot (pfile
, sym
, blen
, 1, &bhash
);
1643 *bslot
= base
= _cpp_make_hashnode (sym
, blen
, T_ASSERT
, bhash
);
1647 if (base
->type
!= T_ASSERT
)
1649 /* Token clash - but with what?! */
1650 cpp_ice (pfile
, "base->type != T_ASSERT in do_assert");
1654 *tslot
= this = _cpp_make_hashnode (sym
, tlen
, T_ASSERT
, thash
);
1655 this->value
.aschain
= base
->value
.aschain
;
1656 base
->value
.aschain
= this;
1658 pfile
->limit
= sym
; /* Pop */
1662 _cpp_skip_rest_of_line (pfile
);
1663 pfile
->limit
= sym
; /* Pop */
1673 long baselen
, thislen
;
1674 HASHNODE
*base
, *this, *next
;
1676 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
)
1677 cpp_pedwarn (pfile
, "ANSI C does not allow `#unassert'");
1679 _cpp_skip_hspace (pfile
);
1681 sym
= CPP_PWRITTEN (pfile
); /* remember where it starts */
1682 ret
= _cpp_parse_assertion (pfile
);
1686 _cpp_skip_hspace (pfile
);
1688 if (c
!= EOF
&& c
!= '\n')
1689 cpp_error (pfile
, "junk at end of `#unassert'");
1691 thislen
= strlen (sym
);
1694 base
= _cpp_lookup (pfile
, sym
, thislen
);
1696 goto error
; /* It isn't an error to #undef what isn't #defined,
1697 so it isn't an error to #unassert what isn't
1698 #asserted either. */
1700 for (this = base
->value
.aschain
; this; this = next
)
1702 next
= this->value
.aschain
;
1703 htab_remove_elt (pfile
->hashtab
, this);
1705 htab_remove_elt (pfile
->hashtab
, base
);
1709 baselen
= (U_CHAR
*) strchr (sym
, '(') - sym
;
1710 base
= _cpp_lookup (pfile
, sym
, baselen
);
1711 if (! base
) goto error
;
1712 this = _cpp_lookup (pfile
, sym
, thislen
);
1713 if (! this) goto error
;
1716 while (next
->value
.aschain
!= this)
1717 next
= next
->value
.aschain
;
1719 next
->value
.aschain
= this->value
.aschain
;
1720 htab_remove_elt (pfile
->hashtab
, this);
1722 if (base
->value
.aschain
== NULL
)
1723 /* Last answer for this predicate deleted. */
1724 htab_remove_elt (pfile
->hashtab
, base
);
1727 pfile
->limit
= sym
; /* Pop */
1730 _cpp_skip_rest_of_line (pfile
);
1731 pfile
->limit
= sym
; /* Pop */
1735 /* These are for -D, -U, -A. */
1737 /* Process the string STR as if it appeared as the body of a #define.
1738 If STR is just an identifier, define it with value 1.
1739 If STR has anything after the identifier, then it should
1740 be identifier=definition. */
1743 cpp_define (pfile
, str
)
1750 p
= strchr (str
, '=');
1751 /* Copy the entire option so we can modify it.
1752 Change the first "=" in the string to a space. If there is none,
1753 tack " 1" on the end. Then add a newline and a NUL. */
1757 count
= strlen (str
) + 2;
1758 buf
= alloca (count
);
1759 memcpy (buf
, str
, count
- 2);
1761 buf
[count
- 2] = '\n';
1762 buf
[count
- 1] = '\0';
1766 count
= strlen (str
) + 4;
1767 buf
= alloca (count
);
1768 memcpy (buf
, str
, count
- 4);
1769 strcpy (&buf
[count
-4], " 1\n");
1772 if (cpp_push_buffer (pfile
, buf
, count
- 1) != NULL
)
1775 cpp_pop_buffer (pfile
);
1779 /* Process MACRO as if it appeared as the body of an #undef. */
1781 cpp_undef (pfile
, macro
)
1785 /* Copy the string so we can append a newline. */
1786 size_t len
= strlen (macro
);
1787 char *buf
= alloca (len
+ 2);
1788 memcpy (buf
, macro
, len
);
1790 buf
[len
+ 1] = '\0';
1791 if (cpp_push_buffer (pfile
, buf
, len
+ 1))
1794 cpp_pop_buffer (pfile
);
1798 /* Process the string STR as if it appeared as the body of a #assert. */
1800 cpp_assert (pfile
, str
)
1804 if (cpp_push_buffer (pfile
, str
, strlen (str
)) != NULL
)
1807 cpp_pop_buffer (pfile
);
1811 /* Process STR as if it appeared as the body of an #unassert. */
1813 cpp_unassert (pfile
, str
)
1817 if (cpp_push_buffer (pfile
, str
, strlen (str
)) != NULL
)
1819 do_unassert (pfile
);
1820 cpp_pop_buffer (pfile
);
1824 /* Determine whether the identifier ID, of length LEN, is a defined macro. */
1826 cpp_defined (pfile
, id
, len
)
1831 HASHNODE
*hp
= _cpp_lookup (pfile
, id
, len
);
1832 if (hp
&& hp
->type
== T_POISON
)
1834 cpp_error (pfile
, "attempt to use poisoned `%s'", hp
->name
);
1837 return (hp
!= NULL
);