2 Copyright (C) 1986, 87, 89, 92-98, 1999 Free Software Foundation, Inc.
3 Contributed by Per Bothner, 1994-95.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
29 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
31 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? 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))
35 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
36 (Note that it is false while we're expanding macro *arguments*.) */
37 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->data != NULL)
39 /* Move all backslash-newline pairs out of embarrassing places.
40 Exchange all such pairs following BP
41 with any potentially-embarrassing characters that follow them.
42 Potentially-embarrassing characters are / and *
43 (because a backslash-newline inside a comment delimiter
44 would cause it not to be recognized). */
47 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
49 /* Same, but assume we've already read the potential '\\' into C. */
50 #define NEWLINE_FIX1(C) do { \
51 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
54 /* Forward declarations. */
56 static char *my_strerror PROTO ((int));
57 static void validate_else PROTO ((cpp_reader *, char *));
58 static HOST_WIDEST_INT eval_if_expression PROTO ((cpp_reader *));
60 static void conditional_skip PROTO ((cpp_reader *, int,
61 enum node_type, U_CHAR *));
62 static void skip_if_group PROTO ((cpp_reader *));
63 static int parse_name PARAMS ((cpp_reader *, int));
65 /* External declarations. */
67 extern HOST_WIDEST_INT cpp_parse_expr PARAMS ((cpp_reader *));
69 /* `struct directive' defines one #-directive, including how to handle it. */
72 int length; /* Length of name */
73 int (*func) /* Function to handle directive */
74 PARAMS ((cpp_reader *, struct directive *));
75 char *name; /* Name of directive */
76 enum node_type type; /* Code which describes which directive. */
79 /* These functions are declared to return int instead of void since they
80 are going to be placed in a table and some old compilers have trouble with
81 pointers to functions returning void. */
83 static int do_define PARAMS ((cpp_reader *, struct directive *));
84 static int do_line PARAMS ((cpp_reader *, struct directive *));
85 static int do_include PARAMS ((cpp_reader *, struct directive *));
86 static int do_undef PARAMS ((cpp_reader *, struct directive *));
87 static int do_error PARAMS ((cpp_reader *, struct directive *));
88 static int do_pragma PARAMS ((cpp_reader *, struct directive *));
89 static int do_ident PARAMS ((cpp_reader *, struct directive *));
90 static int do_if PARAMS ((cpp_reader *, struct directive *));
91 static int do_xifdef PARAMS ((cpp_reader *, struct directive *));
92 static int do_else PARAMS ((cpp_reader *, struct directive *));
93 static int do_elif PARAMS ((cpp_reader *, struct directive *));
94 static int do_endif PARAMS ((cpp_reader *, struct directive *));
96 static int do_sccs PARAMS ((cpp_reader *, struct directive *));
98 static int do_assert PARAMS ((cpp_reader *, struct directive *));
99 static int do_unassert PARAMS ((cpp_reader *, struct directive *));
100 static int do_warning PARAMS ((cpp_reader *, struct directive *));
102 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
103 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
105 /* Here is the actual list of #-directives, most-often-used first.
106 The initialize_builtins function assumes #define is the very first. */
108 static struct directive directive_table[] = {
109 { 6, do_define, "define", T_DEFINE },
110 { 5, do_xifdef, "ifdef", T_IFDEF },
111 { 6, do_xifdef, "ifndef", T_IFNDEF },
112 { 7, do_include, "include", T_INCLUDE },
113 { 12, do_include, "include_next", T_INCLUDE_NEXT },
114 { 6, do_include, "import", T_IMPORT },
115 { 5, do_endif, "endif", T_ENDIF },
116 { 4, do_else, "else", T_ELSE },
117 { 2, do_if, "if", T_IF },
118 { 4, do_elif, "elif", T_ELIF },
119 { 5, do_undef, "undef", T_UNDEF },
120 { 5, do_error, "error", T_ERROR },
121 { 7, do_warning, "warning", T_WARNING },
122 { 6, do_pragma, "pragma", T_PRAGMA },
123 { 4, do_line, "line", T_LINE },
124 { 5, do_ident, "ident", T_IDENT },
125 #ifdef SCCS_DIRECTIVE
126 { 4, do_sccs, "sccs", T_SCCS },
128 { 6, do_assert, "assert", T_ASSERT },
129 { 8, do_unassert, "unassert", T_UNASSERT },
130 { -1, 0, "", T_UNUSED }
133 /* Place into PFILE a quoted string representing the string SRC.
134 Caller must reserve enough space in pfile->token_buffer. */
137 quote_string (pfile, src)
143 CPP_PUTC_Q (pfile, '\"');
145 switch ((c = *src++))
149 CPP_PUTC_Q (pfile, c);
152 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
153 CPP_ADJUST_WRITTEN (pfile, 4);
159 CPP_PUTC_Q (pfile, '\\');
160 CPP_PUTC_Q (pfile, c);
164 CPP_PUTC_Q (pfile, '\"');
165 CPP_NUL_TERMINATE_Q (pfile);
170 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
173 cpp_grow_buffer (pfile, n)
177 long old_written = CPP_WRITTEN (pfile);
178 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
179 pfile->token_buffer = (U_CHAR *)
180 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
181 CPP_SET_WRITTEN (pfile, old_written);
184 /* Process the string STR as if it appeared as the body of a #define
185 If STR is just an identifier, define it with value 1.
186 If STR has anything after the identifier, then it should
187 be identifier=definition. */
190 cpp_define (pfile, str)
197 /* Copy the entire option so we can modify it. */
198 count = strlen (str) + 3;
199 buf = (U_CHAR *) alloca (count);
200 memcpy (buf, str, count - 2);
201 /* Change the first "=" in the string to a space. If there is none,
202 tack " 1" on the end. */
203 p = strchr (buf, '=');
210 strcpy (&buf[count-3], " 1");
212 if (cpp_push_buffer (pfile, buf, count - 1) != NULL)
214 do_define (pfile, NULL);
215 cpp_pop_buffer (pfile);
219 /* Process the string STR as if it appeared as the body of a #assert. */
221 cpp_assert (pfile, str)
225 if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
227 do_assert (pfile, NULL);
228 cpp_pop_buffer (pfile);
233 static enum cpp_token
234 null_underflow (pfile)
235 cpp_reader *pfile ATTRIBUTE_UNUSED;
241 null_cleanup (pbuf, pfile)
242 cpp_buffer *pbuf ATTRIBUTE_UNUSED;
243 cpp_reader *pfile ATTRIBUTE_UNUSED;
248 /* Assuming we have read '/'.
249 If this is the start of a comment (followed by '*' or '/'),
250 skip to the end of the comment, and return ' '.
251 Return EOF if we reached the end of file before the end of the comment.
252 If not the start of a comment, return '/'. */
255 skip_comment (pfile, linep)
260 while (PEEKC() == '\\' && PEEKN(1) == '\n')
275 while (c == '\\' && PEEKC() == '\n')
279 FORWARD(1), c = GETC();
281 if (prev_c == '*' && c == '/')
283 if (c == '\n' && linep)
287 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
294 return ' '; /* Allow // to be terminated by EOF. */
295 while (c == '\\' && PEEKC() == '\n')
304 /* Don't consider final '\n' to be part of comment. */
314 /* Skip whitespace \-newline and comments. Does not macro-expand. */
317 cpp_skip_hspace (pfile)
327 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
328 cpp_pedwarn (pfile, "%s in preprocessing directive",
329 c == '\f' ? "formfeed" : "vertical tab");
335 c = skip_comment (pfile, NULL);
338 if (c == EOF || c == '/')
341 else if (c == '\\' && PEEKN(1) == '\n') {
344 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
345 && is_hor_space[PEEKN(1)])
351 /* Read the rest of the current line.
352 The line is appended to PFILE's output buffer. */
355 copy_rest_of_line (pfile)
358 struct cpp_options *opts = CPP_OPTIONS (pfile);
375 goto scan_directive_token;
379 if (nextc == '*' || (opts->cplusplus_comments && nextc == '/'))
380 goto scan_directive_token;
384 if (CPP_PEDANTIC (pfile))
385 cpp_pedwarn (pfile, "%s in preprocessing directive",
386 c == '\f' ? "formfeed" : "vertical tab");
392 scan_directive_token:
394 cpp_get_token (pfile);
400 CPP_NUL_TERMINATE (pfile);
404 skip_rest_of_line (pfile)
407 long old = CPP_WRITTEN (pfile);
408 copy_rest_of_line (pfile);
409 CPP_SET_WRITTEN (pfile, old);
412 /* Handle a possible # directive.
413 '#' has already been read. */
416 handle_directive (pfile)
419 register struct directive *kt;
422 long old_written = CPP_WRITTEN (pfile);
424 cpp_skip_hspace (pfile);
427 if (c >= '0' && c <= '9')
429 /* Handle # followed by a line number. */
430 if (CPP_PEDANTIC (pfile))
431 cpp_pedwarn (pfile, "`#' followed by integer");
432 do_line (pfile, NULL);
433 goto done_a_directive;
436 /* Now find the directive name. */
437 CPP_PUTC (pfile, '#');
438 parse_name (pfile, GETC());
439 ident = pfile->token_buffer + old_written + 1;
440 ident_length = CPP_PWRITTEN (pfile) - ident;
441 if (ident_length == 0 && PEEKC() == '\n')
443 /* A line of just `#' becomes blank. */
444 goto done_a_directive;
448 if (ident_length == 0 || !is_idstart[*ident]) {
450 while (is_idchar[*p]) {
451 if (*p < '0' || *p > '9')
455 /* Avoid error for `###' and similar cases unless -pedantic. */
457 while (*p == '#' || is_hor_space[*p]) p++;
459 if (pedantic && !lang_asm)
460 cpp_warning (pfile, "invalid preprocessor directive");
466 cpp_error (pfile, "invalid preprocessor directive name");
472 * Decode the keyword and call the appropriate expansion
473 * routine, after moving the input pointer up to the next line.
475 for (kt = directive_table; ; kt++) {
477 goto not_a_directive;
478 if (kt->length == ident_length
479 && !strncmp (kt->name, ident, ident_length))
483 /* We may want to pass through #define, #undef, #pragma, and #include.
484 Other directives may create output, but we don't want the directive
485 itself out, so we pop it now. For example conditionals may emit
486 #failed ... #endfailed stuff. */
488 if (! (kt->type == T_DEFINE
489 || kt->type == T_PRAGMA
490 || (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)
491 && CPP_OPTIONS (pfile)->dump_includes)))
492 CPP_SET_WRITTEN (pfile, old_written);
494 (*kt->func) (pfile, kt);
496 if (kt->type == T_DEFINE)
498 if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
500 /* Skip "#define". */
501 U_CHAR *p = pfile->token_buffer + old_written + 7;
503 SKIP_WHITE_SPACE (p);
504 while (is_idchar[*p]) p++;
506 CPP_PUTC (pfile, '\n');
508 else if (CPP_OPTIONS (pfile)->dump_macros != dump_definitions)
509 CPP_SET_WRITTEN (pfile, old_written);
519 /* Pass a directive through to the output file.
520 BUF points to the contents of the directive, as a contiguous string.
521 m LIMIT points to the first character past the end of the directive.
522 KEYWORD is the keyword-table entry for the directive. */
525 pass_thru_directive (buf, limit, pfile, keyword)
528 struct directive *keyword;
530 register unsigned keyword_length = keyword->length;
532 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
533 CPP_PUTC_Q (pfile, '#');
534 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
535 if (limit != buf && buf[0] != ' ')
536 CPP_PUTC_Q (pfile, ' ');
537 CPP_PUTS_Q (pfile, buf, limit - buf);
539 CPP_PUTS_Q (pfile, '\n');
540 /* Count the line we have just made in the output,
541 to get in sync properly. */
546 /* Check a purported macro name SYMNAME, and yield its length.
547 ASSERTION is nonzero if this is really for an assertion name. */
550 check_macro_name (pfile, symname, assertion)
558 for (p = symname; is_idchar[*p]; p++)
560 sym_length = p - symname;
562 || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
564 assertion ? "invalid assertion name" : "invalid macro name");
565 else if (!is_idstart[*symname]
566 || (! strncmp (symname, "defined", 7) && sym_length == 7)) {
567 U_CHAR *msg; /* what pain... */
568 msg = (U_CHAR *) alloca (sym_length + 1);
569 bcopy (symname, msg, sym_length);
573 ? "invalid assertion name `%s'"
574 : "invalid macro name `%s'"),
581 /* Process a #define command.
582 KEYWORD is the keyword-table entry for #define,
583 or NULL for a "predefined" macro. */
586 do_define (pfile, keyword)
588 struct directive *keyword;
593 int save_put_out_comments;
595 U_CHAR *macro, *buf, *end;
597 here = CPP_WRITTEN (pfile);
599 save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
600 CPP_OPTIONS (pfile)->put_out_comments = CPP_TRADITIONAL (pfile);
601 copy_rest_of_line (pfile);
602 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
604 /* Copy out the line so we can pop the token buffer. */
605 buf = pfile->token_buffer + here;
606 end = CPP_PWRITTEN (pfile);
607 macro = alloca (end - buf + 1);
608 bcopy (buf, macro, end - buf + 1);
609 end = macro + (end - buf);
611 CPP_SET_WRITTEN (pfile, here);
614 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
615 if (pcp_outfile && keyword)
616 pass_thru_directive (macro, end, pfile, keyword);
619 mdef = create_definition (macro, end, pfile, keyword == NULL);
623 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
625 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
628 /* Redefining a precompiled key is ok. */
629 if (hp->type == T_PCSTRING)
631 /* Redefining a macro is ok if the definitions are the same. */
632 else if (hp->type == T_MACRO)
633 ok = ! compare_defs (pfile, mdef.defn, hp->value.defn);
634 /* Redefining a constant is ok with -D. */
635 else if (hp->type == T_CONST || hp->type == T_STDC)
636 ok = ! CPP_OPTIONS (pfile)->done_initializing;
637 /* Print the warning if it's not ok. */
640 /* If we are passing through #define and #undef directives, do
641 that for this re-definition now. */
642 if (CPP_OPTIONS (pfile)->debug_output && keyword)
643 pass_thru_directive (macro, end, pfile, keyword);
645 cpp_pedwarn (pfile, "`%.*s' redefined", mdef.symlen, mdef.symnam);
646 if (hp->type == T_MACRO)
647 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
648 "this is the location of the previous definition");
650 /* Replace the old definition. */
652 hp->value.defn = mdef.defn;
656 /* If we are passing through #define and #undef directives, do
657 that for this new definition now. */
658 if (CPP_OPTIONS (pfile)->debug_output && keyword)
659 pass_thru_directive (macro, end, pfile, keyword);
660 cpp_install (pfile, mdef.symnam, mdef.symlen, T_MACRO,
661 (char *) mdef.defn, hashcode);
672 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
673 If BUFFER != NULL, then use the LENGTH characters in BUFFER
674 as the new input buffer.
675 Return the new buffer, or NULL on failure. */
678 cpp_push_buffer (pfile, buffer, length)
683 cpp_buffer *buf = CPP_BUFFER (pfile);
685 if (++pfile->buffer_stack_depth == CPP_STACK_MAX)
687 cpp_fatal (pfile, "macro or `#include' recursion too deep");
691 new = xcalloc (sizeof (cpp_buffer), 1);
693 new->if_stack = pfile->if_stack;
694 new->cleanup = null_cleanup;
695 new->underflow = null_underflow;
696 new->buf = new->cur = buffer;
697 new->alimit = new->rlimit = buffer + length;
700 CPP_BUFFER (pfile) = new;
705 cpp_pop_buffer (pfile)
708 cpp_buffer *buf = CPP_BUFFER (pfile);
709 (*buf->cleanup) (buf, pfile);
710 CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
712 pfile->buffer_stack_depth--;
713 return CPP_BUFFER (pfile);
716 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
717 Pop the buffer when done. */
720 cpp_scan_buffer (pfile)
723 cpp_buffer *buffer = CPP_BUFFER (pfile);
726 enum cpp_token token = cpp_get_token (pfile);
727 if (token == CPP_EOF) /* Should not happen ... */
729 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
731 cpp_pop_buffer (pfile);
738 * Rescan a string (which may have escape marks) into pfile's buffer.
739 * Place the result in pfile->token_buffer.
741 * The input is copied before it is scanned, so it is safe to pass
742 * it something from the token_buffer that will get overwritten
743 * (because it follows CPP_WRITTEN). This is used by do_include.
747 cpp_expand_to_buffer (pfile, buf, length)
752 register cpp_buffer *ip;
758 int odepth = indepth;
764 /* Set up the input on the input stack. */
766 buf1 = (U_CHAR *) alloca (length + 1);
767 memcpy (buf1, buf, length);
770 ip = cpp_push_buffer (pfile, buf1, length);
775 ip->lineno = obuf.lineno = 1;
778 /* Scan the input, create the output. */
779 cpp_scan_buffer (pfile);
781 CPP_NUL_TERMINATE (pfile);
785 adjust_position (buf, limit, linep, colp)
795 (*linep)++, (*colp) = 1;
801 /* Move line_base forward, updating lineno and colno. */
804 update_position (pbuf)
805 register cpp_buffer *pbuf;
807 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
808 unsigned char *new_pos = pbuf->cur;
809 register struct parse_marker *mark;
810 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
812 if (pbuf->buf + mark->position < new_pos)
813 new_pos = pbuf->buf + mark->position;
815 pbuf->line_base += new_pos - old_pos;
816 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
820 cpp_buf_line_and_col (pbuf, linep, colp)
821 register cpp_buffer *pbuf;
829 *linep = pbuf->lineno;
831 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
840 /* Return the cpp_buffer that corresponds to a file (not a macro). */
843 cpp_file_buffer (pfile)
846 cpp_buffer *ip = CPP_BUFFER (pfile);
848 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
849 if (ip->fname != NULL)
855 count_newlines (buf, limit)
856 register U_CHAR *buf;
857 register U_CHAR *limit;
859 register long count = 0;
870 * write out a #line command, for instance, after an #include file.
871 * If CONDITIONAL is nonzero, we can omit the #line if it would
872 * appear to be a no-op, and we can output a few newlines instead
873 * if we want to increase the line number by a small amount.
874 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
878 output_line_command (pfile, conditional, file_change)
881 enum file_change_code file_change;
884 cpp_buffer *ip = CPP_BUFFER (pfile);
886 if (ip->fname == NULL)
889 update_position (ip);
891 if (CPP_OPTIONS (pfile)->no_line_commands
892 || CPP_OPTIONS (pfile)->no_output)
895 line = CPP_BUFFER (pfile)->lineno;
896 col = CPP_BUFFER (pfile)->colno;
897 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
899 if (CPP_OPTIONS (pfile)->no_line_commands)
903 if (line == pfile->lineno)
906 /* If the inherited line number is a little too small,
907 output some newlines instead of a #line command. */
908 if (line > pfile->lineno && line < pfile->lineno + 8) {
909 CPP_RESERVE (pfile, 20);
910 while (line > pfile->lineno) {
911 CPP_PUTC_Q (pfile, '\n');
919 /* Don't output a line number of 0 if we can help it. */
920 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
921 && *ip->bufp == '\n') {
927 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
929 #ifdef OUTPUT_LINE_COMMANDS
930 static char sharp_line[] = "#line ";
932 static char sharp_line[] = "# ";
934 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
937 sprintf ((char *) CPP_PWRITTEN (pfile), "%ld ", line);
938 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
940 quote_string (pfile, ip->nominal_fname);
941 if (file_change != same_file) {
942 CPP_PUTC_Q (pfile, ' ');
943 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
945 /* Tell cc1 if following text comes from a system header file. */
946 if (ip->system_header_p) {
947 CPP_PUTC_Q (pfile, ' ');
948 CPP_PUTC_Q (pfile, '3');
950 #ifndef NO_IMPLICIT_EXTERN_C
951 /* Tell cc1plus if following text should be treated as C. */
952 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
953 CPP_PUTC_Q (pfile, ' ');
954 CPP_PUTC_Q (pfile, '4');
957 CPP_PUTC_Q (pfile, '\n');
958 pfile->lineno = line;
962 /* Like cpp_get_token, except that it does not read past end-of-line.
963 Also, horizontal space is skipped, and macros are popped. */
965 static enum cpp_token
966 get_directive_token (pfile)
971 long old_written = CPP_WRITTEN (pfile);
972 enum cpp_token token;
973 cpp_skip_hspace (pfile);
974 if (PEEKC () == '\n')
976 token = cpp_get_token (pfile);
980 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
982 /* ... else fall though ... */
983 case CPP_HSPACE: case CPP_COMMENT:
984 CPP_SET_WRITTEN (pfile, old_written);
992 /* Handle #include and #import.
993 This function expects to see "fname" or <fname> on the input.
995 The input is normally in part of the output_buffer following
996 CPP_WRITTEN, and will get overwritten by output_line_command.
997 I.e. in input file specification has been popped by handle_directive.
1001 do_include (pfile, keyword)
1003 struct directive *keyword;
1005 int importing = (keyword->type == T_IMPORT);
1006 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
1007 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
1008 int before; /* included before? */
1013 enum cpp_token token;
1015 /* Chain of dirs to search */
1016 struct include_hash *ihash;
1017 struct file_name_list *search_start;
1019 long old_written = CPP_WRITTEN (pfile);
1023 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1026 cpp_pedwarn (pfile, "ANSI C does not allow `#import'");
1028 cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'");
1031 if (importing && CPP_OPTIONS (pfile)->warn_import
1032 && !CPP_OPTIONS (pfile)->inhibit_warnings
1033 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
1035 pfile->import_warning = 1;
1036 cpp_warning (pfile, "`#import' is obsolete, use an #ifndef wrapper in the header file");
1039 pfile->parsing_include_directive++;
1040 token = get_directive_token (pfile);
1041 pfile->parsing_include_directive--;
1043 if (token == CPP_STRING)
1045 fbeg = pfile->token_buffer + old_written + 1;
1046 fend = CPP_PWRITTEN (pfile) - 1;
1048 if (fbeg[-1] == '<')
1052 else if (token == CPP_NAME)
1054 /* Support '#include xyz' like VAX-C to allow for easy use of
1055 * all the decwindow include files. It defaults to '#include
1056 * <xyz.h>' and generates a warning. */
1058 "VAX-C-style include specification found, use '#include <filename.h>' !");
1061 /* Append the missing `.h' to the name. */
1062 CPP_PUTS (pfile, ".h", 3)
1063 CPP_NUL_TERMINATE_Q (pfile);
1065 fbeg = pfile->token_buffer + old_written;
1066 fend = CPP_PWRITTEN (pfile);
1072 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
1073 CPP_SET_WRITTEN (pfile, old_written);
1074 skip_rest_of_line (pfile);
1078 token = get_directive_token (pfile);
1079 if (token != CPP_VSPACE)
1081 cpp_error (pfile, "junk at end of `#include'");
1082 skip_rest_of_line (pfile);
1085 CPP_SET_WRITTEN (pfile, old_written);
1091 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
1097 for (fp = CPP_BUFFER (pfile);
1098 fp != CPP_NULL_BUFFER (pfile);
1099 fp = CPP_PREV_BUFFER (fp))
1100 if (fp->fname != NULL)
1103 if (fp == CPP_NULL_BUFFER (pfile))
1105 cpp_fatal (pfile, "cpp internal error: fp == NULL_BUFFER in do_include");
1109 /* For #include_next, skip in the search path past the dir in which the
1110 containing file was found. Treat files specified using an absolute path
1111 as if there are no more directories to search. Treat the primary source
1112 file like any other included source, but generate a warning. */
1113 if (skip_dirs && CPP_PREV_BUFFER(fp) != CPP_NULL_BUFFER (pfile))
1115 if (fp->ihash->foundhere != ABSOLUTE_PATH)
1116 search_start = fp->ihash->foundhere->next;
1121 cpp_warning (pfile, "#include_next in primary source file");
1124 search_start = CPP_OPTIONS (pfile)->bracket_include;
1127 if (!CPP_OPTIONS (pfile)->ignore_srcdir)
1130 search_start = fp->actual_dir;
1133 search_start = CPP_OPTIONS (pfile)->quote_include;
1139 cpp_error (pfile, "No include path in which to find %s", fbeg);
1143 fd = find_include_file (pfile, fbeg, search_start, &ihash, &before);
1150 if (CPP_OPTIONS (pfile)->print_deps_missing_files
1151 && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
1152 (pfile->system_include_depth > 0)))
1154 if (!angle_brackets)
1155 deps_output (pfile, fbeg, ' ');
1159 struct file_name_list *ptr;
1160 /* If requested as a system header, assume it belongs in
1161 the first system header directory. */
1162 if (CPP_OPTIONS (pfile)->bracket_include)
1163 ptr = CPP_OPTIONS (pfile)->bracket_include;
1165 ptr = CPP_OPTIONS (pfile)->quote_include;
1167 p = (char *) alloca (strlen (ptr->name)
1168 + strlen (fbeg) + 2);
1169 if (*ptr->name != '\0')
1171 strcpy (p, ptr->name);
1175 deps_output (pfile, p, ' ');
1178 /* If -M was specified, and this header file won't be added to
1179 the dependency list, then don't count this as an error,
1180 because we can still produce correct output. Otherwise, we
1181 can't produce correct output, because there may be
1182 dependencies we need inside the missing file, and we don't
1183 know what directory this missing file exists in. */
1184 else if (CPP_PRINT_DEPS (pfile)
1185 && (CPP_PRINT_DEPS (pfile)
1186 <= (angle_brackets || (pfile->system_include_depth > 0))))
1187 cpp_warning (pfile, "No include path in which to find %s", fbeg);
1189 cpp_error_from_errno (pfile, fbeg);
1194 /* For -M, add the file to the dependencies on its first inclusion. */
1195 if (!before && (CPP_PRINT_DEPS (pfile)
1196 > (angle_brackets || (pfile->system_include_depth > 0))))
1197 deps_output (pfile, ihash->name, ' ');
1199 /* Handle -H option. */
1200 if (CPP_OPTIONS(pfile)->print_include_names)
1202 fp = CPP_BUFFER (pfile);
1203 while ((fp = CPP_PREV_BUFFER (fp)) != CPP_NULL_BUFFER (pfile))
1205 fprintf (stderr, " %s\n", ihash->name);
1208 /* Actually process the file */
1211 ihash->control_macro = "";
1213 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
1220 pfile->system_include_depth++; /* Decremented in file_cleanup. */
1222 if (finclude (pfile, fd, ihash))
1224 output_line_command (pfile, 0, enter_file);
1225 pfile->only_seen_white = 2;
1231 /* Interpret #line command.
1232 Note that the filename string (if any) is treated as if it were an
1233 include filename. That means no escape handling. */
1236 do_line (pfile, keyword)
1238 struct directive *keyword ATTRIBUTE_UNUSED;
1240 cpp_buffer *ip = CPP_BUFFER (pfile);
1242 long old_written = CPP_WRITTEN (pfile);
1243 enum file_change_code file_change = same_file;
1244 enum cpp_token token;
1247 token = get_directive_token (pfile);
1249 if (token != CPP_NUMBER)
1251 cpp_error (pfile, "token after `#line' is not an integer");
1252 goto bad_line_directive;
1255 new_lineno = strtol (pfile->token_buffer + old_written, &x, 10);
1258 cpp_error (pfile, "token after `#line' is not an integer");
1259 goto bad_line_directive;
1261 CPP_SET_WRITTEN (pfile, old_written);
1263 if (CPP_PEDANTIC (pfile) && new_lineno <= 0)
1264 cpp_pedwarn (pfile, "line number out of range in `#line' command");
1266 token = get_directive_token (pfile);
1268 if (token == CPP_STRING)
1270 U_CHAR *fname = pfile->token_buffer + old_written + 1;
1271 U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1;
1272 long num_start = CPP_WRITTEN (pfile);
1274 token = get_directive_token (pfile);
1275 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
1277 U_CHAR *p = pfile->token_buffer + num_start;
1278 if (CPP_PEDANTIC (pfile))
1279 cpp_pedwarn (pfile, "garbage at end of `#line' command");
1281 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
1283 cpp_error (pfile, "invalid format `#line' command");
1284 goto bad_line_directive;
1287 file_change = enter_file;
1289 file_change = leave_file;
1291 ip->system_header_p = 1;
1292 else /* if (*p == '4') */
1293 ip->system_header_p = 2;
1295 CPP_SET_WRITTEN (pfile, num_start);
1296 token = get_directive_token (pfile);
1297 p = pfile->token_buffer + num_start;
1298 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4'))
1300 ip->system_header_p = *p == '3' ? 1 : 2;
1301 token = get_directive_token (pfile);
1303 if (token != CPP_VSPACE)
1305 cpp_error (pfile, "invalid format `#line' command");
1306 goto bad_line_directive;
1312 if (strcmp (fname, ip->nominal_fname))
1314 char *newname, *oldname;
1315 if (!strcmp (fname, ip->fname))
1316 newname = ip->fname;
1317 else if (ip->last_nominal_fname
1318 && !strcmp (fname, ip->last_nominal_fname))
1319 newname = ip->last_nominal_fname;
1321 newname = xstrdup (fname);
1323 oldname = ip->nominal_fname;
1324 ip->nominal_fname = newname;
1326 if (ip->last_nominal_fname
1327 && ip->last_nominal_fname != oldname
1328 && ip->last_nominal_fname != newname
1329 && ip->last_nominal_fname != ip->fname)
1330 free (ip->last_nominal_fname);
1332 if (newname == ip->fname)
1333 ip->last_nominal_fname = NULL;
1335 ip->last_nominal_fname = oldname;
1338 else if (token != CPP_VSPACE && token != CPP_EOF)
1340 cpp_error (pfile, "token after `#line %d' is not a string", new_lineno);
1341 goto bad_line_directive;
1344 /* The Newline at the end of this line remains to be processed.
1345 To put the next line at the specified line number,
1346 we must store a line number now that is one less. */
1347 ip->lineno = new_lineno - 1;
1348 CPP_SET_WRITTEN (pfile, old_written);
1349 output_line_command (pfile, 0, file_change);
1353 skip_rest_of_line (pfile);
1354 CPP_SET_WRITTEN (pfile, old_written);
1358 /* Remove the definition of a symbol from the symbol table.
1359 According to the C standard, it is not an error to undef
1360 something that has no definitions. */
1362 do_undef (pfile, keyword)
1364 struct directive *keyword;
1368 U_CHAR *buf, *name, *limit;
1370 long here = CPP_WRITTEN (pfile);
1371 enum cpp_token token;
1373 cpp_skip_hspace (pfile);
1375 if (! is_idstart[c])
1377 cpp_error (pfile, "token after #undef is not an identifier");
1378 skip_rest_of_line (pfile);
1382 parse_name (pfile, c);
1383 buf = pfile->token_buffer + here;
1384 limit = CPP_PWRITTEN(pfile);
1386 /* Copy out the token so we can pop the token buffer. */
1387 name = alloca (limit - buf + 1);
1388 bcopy(buf, name, limit - buf);
1389 name[limit - buf] = '\0';
1391 token = get_directive_token (pfile);
1392 if (token != CPP_VSPACE && token != CPP_POP)
1394 cpp_pedwarn (pfile, "junk on line after #undef");
1395 skip_rest_of_line (pfile);
1398 CPP_SET_WRITTEN (pfile, here);
1401 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
1402 if (pcp_outfile && keyword)
1403 pass_thru_directive (buf, limit, pfile, keyword);
1406 sym_length = check_macro_name (pfile, buf, 0);
1408 while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
1410 /* If we are generating additional info for debugging (with -g) we
1411 need to pass through all effective #undef commands. */
1412 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1413 pass_thru_directive (name, name+sym_length, pfile, keyword);
1414 if (hp->type != T_MACRO)
1415 cpp_warning (pfile, "undefining `%s'", hp->name);
1422 /* Wrap do_undef for -U processing. */
1424 cpp_undef (pfile, macro)
1428 if (cpp_push_buffer (pfile, macro, strlen (macro)))
1430 do_undef (pfile, NULL);
1431 cpp_pop_buffer (pfile);
1437 * Report an error detected by the program we are processing.
1438 * Use the text of the line in the error message.
1439 * (We use error because it prints the filename & line#.)
1443 do_error (pfile, keyword)
1445 struct directive *keyword ATTRIBUTE_UNUSED;
1447 long here = CPP_WRITTEN (pfile);
1449 copy_rest_of_line (pfile);
1450 text = pfile->token_buffer + here;
1451 SKIP_WHITE_SPACE(text);
1453 cpp_error (pfile, "#error %s", text);
1454 CPP_SET_WRITTEN (pfile, here);
1459 * Report a warning detected by the program we are processing.
1460 * Use the text of the line in the warning message, then continue.
1464 do_warning (pfile, keyword)
1466 struct directive *keyword ATTRIBUTE_UNUSED;
1469 long here = CPP_WRITTEN(pfile);
1470 copy_rest_of_line (pfile);
1471 text = pfile->token_buffer + here;
1472 SKIP_WHITE_SPACE(text);
1474 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1475 cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
1477 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
1478 if -pedantic-errors is given, #warning should cause an error. */
1479 cpp_pedwarn (pfile, "#warning %s", text);
1480 CPP_SET_WRITTEN (pfile, here);
1484 /* Report program identification. */
1487 do_ident (pfile, keyword)
1489 struct directive *keyword ATTRIBUTE_UNUSED;
1491 /* Allow #ident in system headers, since that's not user's fault. */
1492 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1493 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
1495 skip_rest_of_line (pfile); /* Correct? Appears to match cccp. */
1500 /* Just check for some recognized pragmas that need validation here,
1501 and leave the text in the token buffer to be output. */
1504 do_pragma (pfile, keyword)
1506 struct directive *keyword ATTRIBUTE_UNUSED;
1508 long here = CPP_WRITTEN (pfile);
1511 copy_rest_of_line (pfile);
1512 buf = pfile->token_buffer + here;
1513 SKIP_WHITE_SPACE (buf);
1515 if (!strncmp (buf, "once", 4))
1517 cpp_buffer *ip = NULL;
1519 /* Allow #pragma once in system headers, since that's not the user's
1521 if (!CPP_BUFFER (pfile)->system_header_p)
1522 cpp_warning (pfile, "`#pragma once' is obsolete");
1524 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
1526 if (ip == CPP_NULL_BUFFER (pfile))
1528 if (ip->fname != NULL)
1532 if (CPP_PREV_BUFFER (ip) == CPP_NULL_BUFFER (pfile))
1533 cpp_warning (pfile, "`#pragma once' outside include file");
1535 ip->ihash->control_macro = ""; /* never repeat */
1538 if (!strncmp (buf, "implementation", 14))
1540 /* Be quiet about `#pragma implementation' for a file only if it hasn't
1541 been included yet. */
1542 struct include_hash *ptr;
1543 U_CHAR *p = buf + 14, *fname, *fcopy;
1544 SKIP_WHITE_SPACE (p);
1545 if (*p == '\n' || *p != '\"')
1549 p = (U_CHAR *) index (fname, '\"');
1551 fcopy = alloca (p - fname + 1);
1552 bcopy (fname, fcopy, p - fname);
1553 fcopy[p-fname] = '\0';
1555 ptr = include_hash (pfile, fcopy, 0);
1558 "`#pragma implementation' for `%s' appears after file is included",
1565 #ifdef SCCS_DIRECTIVE
1566 /* Just ignore #sccs, on systems where we define it at all. */
1569 do_sccs (pfile, keyword)
1571 struct directive *keyword ATTRIBUTE_UNUSED;
1573 if (CPP_PEDANTIC (pfile))
1574 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
1575 skip_rest_of_line (pfile);
1581 * handle #if command by
1582 * 1) inserting special `defined' keyword into the hash table
1583 * that gets turned into 0 or 1 by special_symbol (thus,
1584 * if the luser has a symbol called `defined' already, it won't
1585 * work inside the #if command)
1586 * 2) rescan the input into a temporary output buffer
1587 * 3) pass the output buffer to the yacc parser and collect a value
1588 * 4) clean up the mess left from steps 1 and 2.
1589 * 5) call conditional_skip to skip til the next #endif (etc.),
1590 * or not, depending on the value from step 3.
1594 do_if (pfile, keyword)
1596 struct directive *keyword ATTRIBUTE_UNUSED;
1598 HOST_WIDEST_INT value = eval_if_expression (pfile);
1599 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
1604 * handle a #elif directive by not changing if_stack either.
1605 * see the comment above do_else.
1609 do_elif (pfile, keyword)
1611 struct directive *keyword ATTRIBUTE_UNUSED;
1613 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
1614 cpp_error (pfile, "`#elif' not within a conditional");
1617 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
1618 cpp_error (pfile, "`#elif' after `#else'");
1620 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
1622 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
1623 && strcmp (pfile->if_stack->fname,
1624 CPP_BUFFER (pfile)->nominal_fname) != 0)
1625 fprintf (stderr, ", file %s", pfile->if_stack->fname);
1626 fprintf (stderr, ")\n");
1628 pfile->if_stack->type = T_ELIF;
1631 if (pfile->if_stack->if_succeeded)
1632 skip_if_group (pfile);
1634 HOST_WIDEST_INT value = eval_if_expression (pfile);
1636 skip_if_group (pfile);
1638 ++pfile->if_stack->if_succeeded; /* continue processing input */
1639 output_line_command (pfile, 1, same_file);
1646 * evaluate a #if expression in BUF, of length LENGTH,
1647 * then parse the result as a C expression and return the value as an int.
1650 static HOST_WIDEST_INT
1651 eval_if_expression (pfile)
1654 HOST_WIDEST_INT value;
1655 long old_written = CPP_WRITTEN (pfile);
1657 pfile->pcp_inside_if = 1;
1658 value = cpp_parse_expr (pfile);
1659 pfile->pcp_inside_if = 0;
1661 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
1667 * routine to handle ifdef/ifndef. Try to look up the symbol,
1668 * then do or don't skip to the #endif/#else/#elif depending
1669 * on what directive is actually being processed.
1673 do_xifdef (pfile, keyword)
1675 struct directive *keyword;
1678 cpp_buffer *ip = CPP_BUFFER (pfile);
1681 enum cpp_token token;
1682 int start_of_file = 0;
1683 U_CHAR *control_macro = 0;
1684 int old_written = CPP_WRITTEN (pfile);
1686 /* Detect a #ifndef at start of file (not counting comments). */
1687 if (ip->fname != 0 && keyword->type == T_IFNDEF)
1688 start_of_file = pfile->only_seen_white == 2;
1690 pfile->no_macro_expand++;
1691 token = get_directive_token (pfile);
1692 pfile->no_macro_expand--;
1694 ident = pfile->token_buffer + old_written;
1695 ident_length = CPP_WRITTEN (pfile) - old_written;
1696 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
1698 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
1700 skip = (keyword->type == T_IFDEF);
1701 if (! CPP_TRADITIONAL (pfile))
1702 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
1704 else if (token == CPP_NAME)
1706 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
1707 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
1708 if (start_of_file && !skip)
1710 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
1711 bcopy (ident, control_macro, ident_length + 1);
1716 skip = (keyword->type == T_IFDEF);
1717 if (! CPP_TRADITIONAL (pfile))
1718 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
1721 if (!CPP_TRADITIONAL (pfile))
1723 cpp_skip_hspace (pfile);
1725 if (c != EOF && c != '\n')
1726 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
1728 skip_rest_of_line (pfile);
1732 /* Output a precondition for this macro. */
1733 if (hp && hp->value.defn->predefined)
1734 fprintf (pcp_outfile, "#define %s\n", hp->name);
1737 fprintf (pcp_outfile, "#undef ");
1738 while (is_idchar[*cp]) /* Ick! */
1739 fputc (*cp++, pcp_outfile);
1740 putc ('\n', pcp_outfile);
1744 conditional_skip (pfile, skip, T_IF, control_macro);
1748 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
1749 If this is a #ifndef starting at the beginning of a file,
1750 CONTROL_MACRO is the macro name tested by the #ifndef.
1751 Otherwise, CONTROL_MACRO is 0. */
1754 conditional_skip (pfile, skip, type, control_macro)
1757 enum node_type type;
1758 U_CHAR *control_macro;
1760 IF_STACK_FRAME *temp;
1762 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
1763 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
1765 temp->lineno = CPP_BUFFER (pfile)->lineno;
1767 temp->next = pfile->if_stack;
1768 temp->control_macro = control_macro;
1769 pfile->if_stack = temp;
1771 pfile->if_stack->type = type;
1774 skip_if_group (pfile);
1777 ++pfile->if_stack->if_succeeded;
1778 output_line_command (pfile, 1, same_file);
1782 /* Subroutine of skip_if_group. Examine one preprocessing directive and
1783 return 0 if skipping should continue, 1 if it should halt. Also
1784 adjusts the if_stack as appropriate.
1785 The `#' has been read, but not the identifier. */
1788 consider_directive_while_skipping (pfile, stack)
1790 IF_STACK_FRAME *stack;
1792 long ident_len, ident;
1793 struct directive *kt;
1794 IF_STACK_FRAME *temp;
1796 cpp_skip_hspace (pfile);
1798 ident = CPP_WRITTEN (pfile);
1799 parse_name (pfile, GETC());
1800 ident_len = CPP_WRITTEN (pfile) - ident;
1802 CPP_SET_WRITTEN (pfile, ident);
1804 for (kt = directive_table; kt->length >= 0; kt++)
1805 if (kt->length == ident_len
1806 && strncmp (pfile->token_buffer + ident, kt->name, kt->length) == 0)
1812 temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
1813 temp->next = pfile->if_stack;
1814 pfile->if_stack = temp;
1815 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
1816 temp->type = kt->type;
1820 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
1821 validate_else (pfile, "#else");
1824 if (pfile->if_stack->type == T_ELSE)
1825 cpp_error (pfile, "`%s' after `#else'", kt->name);
1827 if (pfile->if_stack == stack)
1831 pfile->if_stack->type = kt->type;
1836 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
1837 validate_else (pfile, "#endif");
1839 if (pfile->if_stack == stack)
1842 temp = pfile->if_stack;
1843 pfile->if_stack = temp->next;
1851 /* Don't let erroneous code go by. */
1852 if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile))
1853 cpp_pedwarn (pfile, "invalid preprocessor directive name");
1857 /* skip to #endif, #else, or #elif. adjust line numbers, etc.
1858 * leaves input ptr at the sharp sign found.
1861 skip_if_group (pfile)
1865 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
1866 U_CHAR *beg_of_line;
1869 if (CPP_OPTIONS (pfile)->output_conditionals)
1871 CPP_PUTS (pfile, "#failed\n", 8);
1873 output_line_command (pfile, 1, same_file);
1876 old_written = CPP_WRITTEN (pfile);
1880 beg_of_line = CPP_BUFFER (pfile)->cur;
1882 if (! CPP_TRADITIONAL (pfile))
1883 cpp_skip_hspace (pfile);
1887 if (CPP_OPTIONS (pfile)->output_conditionals)
1888 CPP_PUTC (pfile, c);
1893 if (consider_directive_while_skipping (pfile, save_if_stack))
1897 return; /* Caller will issue error. */
1900 if (CPP_OPTIONS (pfile)->output_conditionals)
1902 CPP_PUTS (pfile, beg_of_line, CPP_BUFFER (pfile)->cur - beg_of_line);
1903 copy_rest_of_line (pfile);
1907 copy_rest_of_line (pfile);
1908 CPP_SET_WRITTEN (pfile, old_written); /* discard it */
1913 return; /* Caller will issue error. */
1917 if (CPP_OPTIONS (pfile)->output_conditionals)
1918 CPP_PUTC (pfile, c);
1922 /* Back up to the beginning of this line. Caller will process the
1924 CPP_BUFFER (pfile)->cur = beg_of_line;
1925 pfile->only_seen_white = 1;
1926 if (CPP_OPTIONS (pfile)->output_conditionals)
1928 CPP_PUTS (pfile, "#endfailed\n", 11);
1934 * handle a #else directive. Do this by just continuing processing
1935 * without changing if_stack ; this is so that the error message
1936 * for missing #endif's etc. will point to the original #if. It
1937 * is possible that something different would be better.
1941 do_else (pfile, keyword)
1943 struct directive *keyword ATTRIBUTE_UNUSED;
1945 cpp_buffer *ip = CPP_BUFFER (pfile);
1947 if (CPP_PEDANTIC (pfile))
1948 validate_else (pfile, "#else");
1949 skip_rest_of_line (pfile);
1951 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
1952 cpp_error (pfile, "`#else' not within a conditional");
1955 /* #ifndef can't have its special treatment for containing the whole file
1956 if it has a #else clause. */
1957 pfile->if_stack->control_macro = 0;
1959 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
1960 cpp_error (pfile, "`#else' after `#else'");
1961 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
1962 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
1963 fprintf (stderr, ", file %s", pfile->if_stack->fname);
1964 fprintf (stderr, ")\n");
1966 pfile->if_stack->type = T_ELSE;
1969 if (pfile->if_stack->if_succeeded)
1970 skip_if_group (pfile);
1972 ++pfile->if_stack->if_succeeded; /* continue processing input */
1973 output_line_command (pfile, 1, same_file);
1979 * unstack after #endif command
1983 do_endif (pfile, keyword)
1985 struct directive *keyword ATTRIBUTE_UNUSED;
1987 if (CPP_PEDANTIC (pfile))
1988 validate_else (pfile, "#endif");
1989 skip_rest_of_line (pfile);
1991 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
1992 cpp_error (pfile, "unbalanced `#endif'");
1995 IF_STACK_FRAME *temp = pfile->if_stack;
1996 pfile->if_stack = temp->next;
1997 if (temp->control_macro != 0)
1999 /* This #endif matched a #ifndef at the start of the file.
2000 See if it is at the end of the file. */
2001 struct parse_marker start_mark;
2004 parse_set_mark (&start_mark, pfile);
2008 cpp_skip_hspace (pfile);
2013 parse_goto_mark (&start_mark, pfile);
2014 parse_clear_mark (&start_mark);
2018 /* This #endif ends a #ifndef
2019 that contains all of the file (aside from whitespace).
2020 Arrange not to include the file again
2021 if the macro that was tested is defined. */
2022 struct cpp_buffer *ip;
2023 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2024 if (ip->fname != NULL)
2026 ip->ihash->control_macro = temp->control_macro;
2030 output_line_command (pfile, 1, same_file);
2035 /* When an #else or #endif is found while skipping failed conditional,
2036 if -pedantic was specified, this is called to warn about text after
2037 the command name. P points to the first char after the command name. */
2040 validate_else (pfile, directive)
2045 cpp_skip_hspace (pfile);
2047 if (c != EOF && c != '\n')
2049 "text following `%s' violates ANSI standard", directive);
2052 /* Get the next token, and add it to the text in pfile->token_buffer.
2053 Return the kind of token we got. */
2056 cpp_get_token (pfile)
2059 register int c, c2, c3;
2061 long start_line, start_column;
2062 enum cpp_token token;
2063 struct cpp_options *opts = CPP_OPTIONS (pfile);
2070 if (CPP_BUFFER (pfile)->seen_eof)
2072 if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) == CPP_NULL_BUFFER (pfile))
2075 cpp_pop_buffer (pfile);
2080 cpp_buffer *next_buf
2081 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
2082 CPP_BUFFER (pfile)->seen_eof = 1;
2083 if (CPP_BUFFER (pfile)->nominal_fname
2084 && next_buf != CPP_NULL_BUFFER (pfile))
2086 /* We're about to return from an #include file.
2087 Emit #line information now (as part of the CPP_POP) result.
2088 But the #line refers to the file we will pop to. */
2089 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
2090 CPP_BUFFER (pfile) = next_buf;
2091 pfile->input_stack_listing_current = 0;
2092 output_line_command (pfile, 0, leave_file);
2093 CPP_BUFFER (pfile) = cur_buffer;
2103 struct parse_marker start_mark;
2105 if (PEEKC () == '=')
2107 if (opts->put_out_comments)
2108 parse_set_mark (&start_mark, pfile);
2110 cpp_buf_line_and_col (cpp_file_buffer (pfile),
2111 &start_line, &start_column);
2112 c = skip_comment (pfile, &newlines);
2113 if (opts->put_out_comments && (c == '/' || c == EOF))
2114 parse_clear_mark (&start_mark);
2119 cpp_error_with_line (pfile, start_line, start_column,
2120 "unterminated comment");
2123 c = '/'; /* Initial letter of comment. */
2125 /* Comments are equivalent to spaces.
2126 For -traditional, a comment is equivalent to nothing. */
2127 if (opts->put_out_comments)
2129 cpp_buffer *pbuf = CPP_BUFFER (pfile);
2130 U_CHAR *start = pbuf->buf + start_mark.position;
2131 int len = pbuf->cur - start;
2132 CPP_RESERVE(pfile, 1 + len);
2133 CPP_PUTC_Q (pfile, c);
2134 CPP_PUTS_Q (pfile, start, len);
2135 pfile->lineno += newlines;
2136 parse_clear_mark (&start_mark);
2139 else if (CPP_TRADITIONAL (pfile))
2146 /* This may not work if cpp_get_token is called recursively,
2147 since many places look for horizontal space. */
2150 /* Copy the newlines into the output buffer, in order to
2151 avoid the pain of a #line every time a multiline comment
2153 CPP_RESERVE(pfile, newlines);
2154 while (--newlines >= 0)
2156 CPP_PUTC_Q (pfile, '\n');
2162 CPP_RESERVE(pfile, 1);
2163 CPP_PUTC_Q (pfile, ' ');
2167 if (opts->for_lint) {
2170 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
2172 if (lintcmd != NULL) {
2173 /* I believe it is always safe to emit this newline: */
2175 bcopy ("#pragma lint ", (char *) obp, 13);
2177 bcopy (lintcmd, (char *) obp, cmdlen);
2182 bcopy (argbp, (char *) obp, arglen);
2186 /* OK, now bring us back to the state we were in before we entered
2187 this branch. We need #line because the newline for the pragma
2188 could mess things up. */
2189 output_line_command (pfile, 0, same_file);
2190 *(obp++) = ' '; /* just in case, if comments are copied thru */
2198 /* If this is expanding a macro definition, don't recognize
2199 preprocessor directives. */
2202 /* If this is expand_into_temp_buffer, recognize them
2203 only after an actual newline at this level,
2204 not at the beginning of the input level. */
2205 if (ip->fname == 0 && beg_of_line == ip->buf)
2211 if (!pfile->only_seen_white)
2213 if (handle_directive (pfile))
2214 return CPP_DIRECTIVE;
2215 pfile->only_seen_white = 0;
2221 /* A single quoted string is treated like a double -- some
2222 programs (e.g., troff) are perverse this way */
2223 cpp_buf_line_and_col (cpp_file_buffer (pfile),
2224 &start_line, &start_column);
2225 old_written = CPP_WRITTEN (pfile);
2226 CPP_PUTC (pfile, c);
2232 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2234 /* try harder: this string crosses a macro expansion
2235 boundary. This can happen naturally if -traditional.
2236 Otherwise, only -D can make a macro with an unmatched
2238 cpp_pop_buffer (pfile);
2241 if (!CPP_TRADITIONAL (pfile))
2243 cpp_error_with_line (pfile, start_line, start_column,
2244 "unterminated string or character constant");
2245 if (pfile->multiline_string_line != start_line
2246 && pfile->multiline_string_line != 0)
2247 cpp_error_with_line (pfile,
2248 pfile->multiline_string_line, -1,
2249 "possible real start of unterminated constant");
2250 pfile->multiline_string_line = 0;
2254 CPP_PUTC (pfile, cc);
2258 /* Traditionally, end of line ends a string constant with
2259 no error. So exit the loop and record the new line. */
2260 if (CPP_TRADITIONAL (pfile))
2264 cpp_error_with_line (pfile, start_line, start_column,
2265 "unterminated character constant");
2268 if (CPP_PEDANTIC (pfile)
2269 && pfile->multiline_string_line == 0)
2271 cpp_pedwarn_with_line (pfile, start_line, start_column,
2272 "string constant runs past end of line");
2274 if (pfile->multiline_string_line == 0)
2275 pfile->multiline_string_line = start_line;
2282 /* Backslash newline is replaced by nothing at all. */
2283 CPP_ADJUST_WRITTEN (pfile, -1);
2288 /* ANSI stupidly requires that in \\ the second \
2289 is *not* prevented from combining with a newline. */
2292 CPP_PUTC (pfile, cc);
2304 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
2305 CPP_PWRITTEN (pfile));
2306 pfile->only_seen_white = 0;
2307 return c == '\'' ? CPP_CHAR : CPP_STRING;
2310 if (!opts->dollars_in_ident)
2315 if (opts->cplusplus && PEEKC () == ':')
2324 if (c2 == c || c2 == '=')
2334 if (PEEKC () == '=')
2341 if (c2 == '-' && opts->chill)
2343 /* Chill style comment */
2344 if (opts->put_out_comments)
2345 parse_set_mark (&start_mark, pfile);
2346 FORWARD(1); /* Skip second '-'. */
2354 /* Don't consider final '\n' to be part of comment. */
2360 goto return_comment;
2362 if (c2 == '-' || c2 == '=' || c2 == '>')
2367 if (pfile->parsing_include_directive)
2371 CPP_PUTC (pfile, c);
2376 if (c == '\n' || c == EOF)
2379 "missing '>' in `#include <FILENAME>'");
2385 /* else fall through */
2394 CPP_RESERVE (pfile, 4);
2395 CPP_PUTC (pfile, c);
2396 CPP_PUTC (pfile, c2);
2400 CPP_PUTC_Q (pfile, GETC ());
2401 CPP_NUL_TERMINATE_Q (pfile);
2402 pfile->only_seen_white = 0;
2406 if (CPP_BUFFER (pfile)->has_escapes)
2411 if (pfile->output_escapes)
2412 CPP_PUTS (pfile, "@-", 2);
2413 parse_name (pfile, GETC ());
2416 else if (is_space [c])
2418 CPP_RESERVE (pfile, 2);
2419 if (pfile->output_escapes)
2420 CPP_PUTC_Q (pfile, '@');
2421 CPP_PUTC_Q (pfile, c);
2425 if (pfile->output_escapes)
2427 CPP_PUTS (pfile, "@@", 2);
2437 CPP_RESERVE(pfile, 2);
2438 CPP_PUTC_Q (pfile, '.');
2442 /* FIXME - misses the case "..\\\n." */
2443 if (c2 == '.' && PEEKN(1) == '.')
2445 CPP_RESERVE(pfile, 4);
2446 CPP_PUTC_Q (pfile, '.');
2447 CPP_PUTC_Q (pfile, '.');
2448 CPP_PUTC_Q (pfile, '.');
2450 CPP_NUL_TERMINATE_Q (pfile);
2451 pfile->only_seen_white = 0;
2458 pfile->only_seen_white = 0;
2460 CPP_RESERVE(pfile, 3);
2461 CPP_PUTC_Q (pfile, c);
2462 CPP_PUTC_Q (pfile, GETC ());
2463 CPP_NUL_TERMINATE_Q (pfile);
2469 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
2471 CPP_PUTC (pfile, c);
2477 case '0': case '1': case '2': case '3': case '4':
2478 case '5': case '6': case '7': case '8': case '9':
2483 CPP_RESERVE (pfile, 2);
2484 CPP_PUTC_Q (pfile, c);
2489 if (!is_idchar[c] && c != '.'
2490 && ((c2 != 'e' && c2 != 'E'
2491 && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
2492 || (c != '+' && c != '-')))
2497 CPP_NUL_TERMINATE_Q (pfile);
2498 pfile->only_seen_white = 0;
2500 case 'b': case 'c': case 'd': case 'h': case 'o':
2501 case 'B': case 'C': case 'D': case 'H': case 'O':
2502 if (opts->chill && PEEKC () == '\'')
2504 pfile->only_seen_white = 0;
2505 CPP_RESERVE (pfile, 2);
2506 CPP_PUTC_Q (pfile, c);
2507 CPP_PUTC_Q (pfile, '\'');
2513 goto chill_number_eof;
2516 if (c == '\\' && PEEKC() == '\n')
2523 CPP_PUTC (pfile, c);
2527 CPP_RESERVE (pfile, 2);
2528 CPP_PUTC_Q (pfile, c);
2529 CPP_NUL_TERMINATE_Q (pfile);
2536 CPP_NUL_TERMINATE (pfile);
2543 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
2544 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
2545 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
2546 case 'x': case 'y': case 'z':
2547 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
2548 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
2549 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2554 unsigned char *ident;
2555 int before_name_written = CPP_WRITTEN (pfile);
2557 parse_name (pfile, c);
2558 pfile->only_seen_white = 0;
2559 if (pfile->no_macro_expand)
2561 ident = pfile->token_buffer + before_name_written;
2562 ident_len = CPP_PWRITTEN (pfile) - ident;
2563 hp = cpp_lookup (pfile, ident, ident_len, -1);
2566 if (hp->type == T_DISABLED)
2568 if (pfile->output_escapes)
2569 { /* Return "@-IDENT", followed by '\0'. */
2571 CPP_RESERVE (pfile, 3);
2572 ident = pfile->token_buffer + before_name_written;
2573 CPP_ADJUST_WRITTEN (pfile, 2);
2574 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
2581 /* If macro wants an arglist, verify that a '(' follows.
2582 first skip all whitespace, copying it to the output
2583 after the macro name. Then, if there is no '(',
2584 decide this is not a macro call and leave things that way. */
2585 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
2587 struct parse_marker macro_mark;
2588 int is_macro_call, macbuf_whitespace = 0;
2590 parse_set_mark (¯o_mark, pfile);
2593 cpp_skip_hspace (pfile);
2595 is_macro_call = c == '(';
2604 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2606 if (macro_mark.position !=
2607 (CPP_BUFFER (pfile)->cur
2608 - CPP_BUFFER (pfile)->buf))
2609 macbuf_whitespace = 1;
2611 parse_clear_mark (¯o_mark);
2612 cpp_pop_buffer (pfile);
2613 parse_set_mark (¯o_mark, pfile);
2621 parse_goto_mark (¯o_mark, pfile);
2622 if (macbuf_whitespace)
2623 CPP_PUTC (pfile, ' ');
2625 parse_clear_mark (¯o_mark);
2629 /* This is now known to be a macro call.
2630 Expand the macro, reading arguments as needed,
2631 and push the expansion on the input stack. */
2632 macroexpand (pfile, hp);
2633 CPP_SET_WRITTEN (pfile, before_name_written);
2637 case ' ': case '\t': case '\v': case '\r':
2640 CPP_PUTC (pfile, c);
2642 if (c == EOF || !is_hor_space[c])
2656 CPP_PUTC (pfile, c);
2657 if (pfile->only_seen_white == 0)
2658 pfile->only_seen_white = 1;
2660 output_line_command (pfile, 1, same_file);
2663 case '(': token = CPP_LPAREN; goto char1;
2664 case ')': token = CPP_RPAREN; goto char1;
2665 case '{': token = CPP_LBRACE; goto char1;
2666 case '}': token = CPP_RBRACE; goto char1;
2667 case ',': token = CPP_COMMA; goto char1;
2668 case ';': token = CPP_SEMICOLON; goto char1;
2674 pfile->only_seen_white = 0;
2675 CPP_PUTC (pfile, c);
2681 /* Like cpp_get_token, but skip spaces and comments. */
2684 cpp_get_non_space_token (pfile)
2687 int old_written = CPP_WRITTEN (pfile);
2690 enum cpp_token token = cpp_get_token (pfile);
2691 if (token != CPP_COMMENT && token != CPP_POP
2692 && token != CPP_HSPACE && token != CPP_VSPACE)
2694 CPP_SET_WRITTEN (pfile, old_written);
2698 /* Parse an identifier starting with C. */
2701 parse_name (pfile, c)
2702 cpp_reader *pfile; int c;
2708 if (c == '\\' && PEEKC() == '\n')
2717 if (c == '$' && CPP_PEDANTIC (pfile))
2718 cpp_pedwarn (pfile, "`$' in identifier");
2720 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
2721 CPP_PUTC_Q (pfile, c);
2726 CPP_NUL_TERMINATE_Q (pfile);
2730 /* Read an assertion into the token buffer, converting to
2731 canonical form: `#predicate(a n swe r)' The next non-whitespace
2732 character to read should be the first letter of the predicate.
2733 Returns 0 for syntax error, 1 for bare predicate, 2 for predicate
2734 with answer (see callers for why). In case of 0, an error has been
2737 parse_assertion (pfile)
2741 cpp_skip_hspace (pfile);
2743 if (! is_idstart[c])
2745 cpp_error (pfile, "assertion predicate is not an identifier");
2748 CPP_PUTC(pfile, '#');
2750 parse_name(pfile, c);
2755 if (is_hor_space[c])
2756 cpp_skip_hspace (pfile);
2762 CPP_PUTC(pfile, '(');
2765 while ((c = GETC()) != ')')
2767 if (is_hor_space[c])
2771 CPP_PUTC(pfile, ' ');
2775 else if (c == '\\' && PEEKC() == '\n')
2777 else if (c == '\n' || c == EOF)
2779 if (c == '\n') FORWARD(-1);
2780 cpp_error (pfile, "un-terminated assertion answer");
2790 if (pfile->limit[-1] == ' ')
2791 pfile->limit[-1] = ')';
2792 else if (pfile->limit[-1] == '(')
2794 cpp_error (pfile, "empty token sequence in assertion");
2798 CPP_PUTC(pfile, ')');
2800 CPP_NUL_TERMINATE(pfile);
2805 do_assert (pfile, keyword)
2807 struct directive *keyword ATTRIBUTE_UNUSED;
2811 HASHNODE *base, *this;
2812 int baselen, thislen;
2814 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
2815 && !CPP_BUFFER (pfile)->system_header_p)
2816 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
2818 cpp_skip_hspace (pfile);
2819 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
2820 ret = parse_assertion (pfile);
2825 cpp_error (pfile, "missing token-sequence in `#assert'");
2829 cpp_skip_hspace (pfile);
2831 if (c != EOF && c != '\n')
2833 cpp_error (pfile, "junk at end of `#assert'");
2837 thislen = strlen (sym);
2838 baselen = index (sym, '(') - sym;
2839 this = cpp_lookup (pfile, sym, thislen, -1);
2842 cpp_warning (pfile, "`%s' re-asserted", sym);
2846 base = cpp_lookup (pfile, sym, baselen, -1);
2848 base = cpp_install (pfile, sym, baselen, T_ASSERT, 0, -1);
2849 else if (base->type != T_ASSERT)
2851 /* Token clash - but with what?! */
2853 "cpp internal error: base->type != T_ASSERT in do_assert");
2857 this = cpp_install (pfile, sym, thislen, T_ASSERT,
2858 (char *)base->value.aschain, -1);
2859 base->value.aschain = this;
2861 pfile->limit = sym; /* Pop */
2865 pfile->limit = sym; /* Pop */
2866 skip_rest_of_line (pfile);
2871 do_unassert (pfile, keyword)
2873 struct directive *keyword ATTRIBUTE_UNUSED;
2877 long baselen, thislen;
2878 HASHNODE *base, *this, *next;
2880 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
2881 && !CPP_BUFFER (pfile)->system_header_p)
2882 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
2884 cpp_skip_hspace (pfile);
2886 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
2887 ret = parse_assertion (pfile);
2891 cpp_skip_hspace (pfile);
2893 if (c != EOF && c != '\n')
2894 cpp_error (pfile, "junk at end of `#unassert'");
2896 thislen = strlen (sym);
2899 base = cpp_lookup (pfile, sym, thislen, -1);
2901 goto error; /* It isn't an error to #undef what isn't #defined,
2902 so it isn't an error to #unassert what isn't
2903 #asserted either. */
2905 for (this = base->value.aschain; this; this = next)
2907 next = this->value.aschain;
2908 delete_macro (this);
2910 delete_macro (base);
2914 baselen = index (sym, '(') - sym;
2915 base = cpp_lookup (pfile, sym, baselen, -1);
2916 if (! base) goto error;
2917 this = cpp_lookup (pfile, sym, thislen, -1);
2918 if (! this) goto error;
2921 while (next->value.aschain != this)
2922 next = next->value.aschain;
2924 next->value.aschain = this->value.aschain;
2925 delete_macro (this);
2927 if (base->value.aschain == NULL)
2928 delete_macro (base); /* Last answer for this predicate deleted. */
2931 pfile->limit = sym; /* Pop */
2934 pfile->limit = sym; /* Pop */
2935 skip_rest_of_line (pfile);
2940 cpp_read_check_assertion (pfile)
2943 char *name = CPP_PWRITTEN (pfile);
2947 FORWARD (1); /* Skip '#' */
2948 cpp_skip_hspace (pfile);
2949 if (! parse_assertion (pfile))
2953 hp = cpp_lookup (pfile, name, (char *)CPP_PWRITTEN (pfile) - name, -1);
2957 pfile->limit = name;
2961 /* Initialize PMARK to remember the current position of PFILE. */
2964 parse_set_mark (pmark, pfile)
2965 struct parse_marker *pmark;
2968 cpp_buffer *pbuf = CPP_BUFFER (pfile);
2969 pmark->next = pbuf->marks;
2970 pbuf->marks = pmark;
2972 pmark->position = pbuf->cur - pbuf->buf;
2975 /* Cleanup PMARK - we no longer need it. */
2978 parse_clear_mark (pmark)
2979 struct parse_marker *pmark;
2981 struct parse_marker **pp = &pmark->buf->marks;
2982 for (; ; pp = &(*pp)->next) {
2983 if (*pp == NULL) abort ();
2984 if (*pp == pmark) break;
2989 /* Backup the current position of PFILE to that saved in PMARK. */
2992 parse_goto_mark (pmark, pfile)
2993 struct parse_marker *pmark;
2996 cpp_buffer *pbuf = CPP_BUFFER (pfile);
2997 if (pbuf != pmark->buf)
2998 cpp_fatal (pfile, "internal error %s", "parse_goto_mark");
2999 pbuf->cur = pbuf->buf + pmark->position;
3002 /* Reset PMARK to point to the current position of PFILE. (Same
3003 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
3006 parse_move_mark (pmark, pfile)
3007 struct parse_marker *pmark;
3010 cpp_buffer *pbuf = CPP_BUFFER (pfile);
3011 if (pbuf != pmark->buf)
3012 cpp_fatal (pfile, "internal error %s", "parse_move_mark");
3013 pmark->position = pbuf->cur - pbuf->buf;
3018 cpp_print_file_and_line (pfile)
3021 cpp_buffer *ip = cpp_file_buffer (pfile);
3026 cpp_buf_line_and_col (ip, &line, &col);
3027 cpp_file_line_for_message (pfile, ip->nominal_fname,
3028 line, pfile->show_column ? col : -1);
3033 v_cpp_error (pfile, msgid, ap)
3038 cpp_print_containing_files (pfile);
3039 cpp_print_file_and_line (pfile);
3040 v_cpp_message (pfile, 1, msgid, ap);
3044 cpp_error VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3046 #ifndef ANSI_PROTOTYPES
3052 VA_START(ap, msgid);
3054 #ifndef ANSI_PROTOTYPES
3055 pfile = va_arg (ap, cpp_reader *);
3056 msgid = va_arg (ap, const char *);
3059 v_cpp_error (pfile, msgid, ap);
3063 /* Print error message but don't count it. */
3066 v_cpp_warning (pfile, msgid, ap)
3071 if (CPP_OPTIONS (pfile)->inhibit_warnings)
3074 if (CPP_OPTIONS (pfile)->warnings_are_errors)
3077 cpp_print_containing_files (pfile);
3078 cpp_print_file_and_line (pfile);
3079 v_cpp_message (pfile, 0, msgid, ap);
3083 cpp_warning VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3085 #ifndef ANSI_PROTOTYPES
3091 VA_START (ap, msgid);
3093 #ifndef ANSI_PROTOTYPES
3094 pfile = va_arg (ap, cpp_reader *);
3095 msgid = va_arg (ap, const char *);
3098 v_cpp_warning (pfile, msgid, ap);
3102 /* Print an error message and maybe count it. */
3105 cpp_pedwarn VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3107 #ifndef ANSI_PROTOTYPES
3113 VA_START (ap, msgid);
3115 #ifndef ANSI_PROTOTYPES
3116 pfile = va_arg (ap, cpp_reader *);
3117 msgid = va_arg (ap, const char *);
3120 if (CPP_OPTIONS (pfile)->pedantic_errors)
3121 v_cpp_error (pfile, msgid, ap);
3123 v_cpp_warning (pfile, msgid, ap);
3128 v_cpp_error_with_line (pfile, line, column, msgid, ap)
3135 cpp_buffer *ip = cpp_file_buffer (pfile);
3137 cpp_print_containing_files (pfile);
3140 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
3142 v_cpp_message (pfile, 1, msgid, ap);
3146 cpp_error_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3147 const char *msgid, ...))
3149 #ifndef ANSI_PROTOTYPES
3157 VA_START (ap, msgid);
3159 #ifndef ANSI_PROTOTYPES
3160 pfile = va_arg (ap, cpp_reader *);
3161 line = va_arg (ap, int);
3162 column = va_arg (ap, int);
3163 msgid = va_arg (ap, const char *);
3166 v_cpp_error_with_line(pfile, line, column, msgid, ap);
3171 v_cpp_warning_with_line (pfile, line, column, msgid, ap)
3180 if (CPP_OPTIONS (pfile)->inhibit_warnings)
3183 if (CPP_OPTIONS (pfile)->warnings_are_errors)
3186 cpp_print_containing_files (pfile);
3188 ip = cpp_file_buffer (pfile);
3191 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
3193 v_cpp_message (pfile, 0, msgid, ap);
3197 cpp_warning_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3198 const char *msgid, ...))
3200 #ifndef ANSI_PROTOTYPES
3208 VA_START (ap, msgid);
3210 #ifndef ANSI_PROTOTYPES
3211 pfile = va_arg (ap, cpp_reader *);
3212 line = va_arg (ap, int);
3213 column = va_arg (ap, int);
3214 msgid = va_arg (ap, const char *);
3217 v_cpp_warning_with_line (pfile, line, column, msgid, ap);
3222 cpp_pedwarn_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3223 const char *msgid, ...))
3225 #ifndef ANSI_PROTOTYPES
3233 VA_START (ap, msgid);
3235 #ifndef ANSI_PROTOTYPES
3236 pfile = va_arg (ap, cpp_reader *);
3237 line = va_arg (ap, int);
3238 column = va_arg (ap, int);
3239 msgid = va_arg (ap, const char *);
3242 if (CPP_OPTIONS (pfile)->pedantic_errors)
3243 v_cpp_error_with_line (pfile, column, line, msgid, ap);
3245 v_cpp_warning_with_line (pfile, line, column, msgid, ap);
3249 /* Report a warning (or an error if pedantic_errors)
3250 giving specified file name and line number, not current. */
3253 cpp_pedwarn_with_file_and_line VPROTO ((cpp_reader *pfile, char *file, int line,
3254 const char *msgid, ...))
3256 #ifndef ANSI_PROTOTYPES
3264 VA_START (ap, msgid);
3266 #ifndef ANSI_PROTOTYPES
3267 pfile = va_arg (ap, cpp_reader *);
3268 file = va_arg (ap, char *);
3269 line = va_arg (ap, int);
3270 msgid = va_arg (ap, const char *);
3273 if (!CPP_OPTIONS (pfile)->pedantic_errors
3274 && CPP_OPTIONS (pfile)->inhibit_warnings)
3277 cpp_file_line_for_message (pfile, file, line, -1);
3278 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msgid, ap);
3282 /* my_strerror - return the descriptive text associated with an
3286 my_strerror (errnum)
3292 #ifndef HAVE_STRERROR
3293 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
3295 result = strerror (errnum);
3298 /* VAXCRTL's strerror() takes an optional second argument, which only
3299 matters when the first argument is EVMSERR. However, it's simplest
3300 just to pass it unconditionally. `vaxc$errno' is declared in
3301 <errno.h>, and maintained by the library in parallel with `errno'.
3302 We assume that caller's `errnum' either matches the last setting of
3303 `errno' by the library or else does not have the value `EVMSERR'. */
3305 result = strerror (errnum, vaxc$errno);
3309 result = "errno = ?";
3314 /* Error including a message from `errno'. */
3317 cpp_error_from_errno (pfile, name)
3321 cpp_message_from_errno (pfile, 1, name);
3325 cpp_message_from_errno (pfile, is_error, name)
3331 cpp_buffer *ip = cpp_file_buffer (pfile);
3333 cpp_print_containing_files (pfile);
3336 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
3338 cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
3342 cpp_perror_with_name (pfile, name)
3346 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
3350 * No pre-compiled header file support.
3352 * Possibly different enum token codes for each C/C++ token.
3354 * Find and cleanup remaining uses of static variables,
3356 * Support -dM flag (dump_all_macros).
3358 * Support for_lint flag.