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 /* Forward declarations. */
41 static char *my_strerror PROTO ((int));
42 static void validate_else PROTO ((cpp_reader *, char *));
43 static HOST_WIDEST_INT eval_if_expression PROTO ((cpp_reader *));
45 static void conditional_skip PROTO ((cpp_reader *, int,
46 enum node_type, U_CHAR *));
47 static void skip_if_group PROTO ((cpp_reader *));
49 static void parse_name PARAMS ((cpp_reader *, int));
50 static void parse_string PARAMS ((cpp_reader *, int));
51 static int parse_assertion PARAMS ((cpp_reader *));
53 /* External declarations. */
55 extern HOST_WIDEST_INT cpp_parse_expr PARAMS ((cpp_reader *));
57 /* `struct directive' defines one #-directive, including how to handle it. */
60 int length; /* Length of name */
61 int (*func) /* Function to handle directive */
62 PARAMS ((cpp_reader *, struct directive *));
63 char *name; /* Name of directive */
64 enum node_type type; /* Code which describes which directive. */
67 /* These functions are declared to return int instead of void since they
68 are going to be placed in a table and some old compilers have trouble with
69 pointers to functions returning void. */
71 static int do_define PARAMS ((cpp_reader *, struct directive *));
72 static int do_line PARAMS ((cpp_reader *, struct directive *));
73 static int do_include PARAMS ((cpp_reader *, struct directive *));
74 static int do_undef PARAMS ((cpp_reader *, struct directive *));
75 static int do_error PARAMS ((cpp_reader *, struct directive *));
76 static int do_pragma PARAMS ((cpp_reader *, struct directive *));
77 static int do_ident PARAMS ((cpp_reader *, struct directive *));
78 static int do_if PARAMS ((cpp_reader *, struct directive *));
79 static int do_xifdef PARAMS ((cpp_reader *, struct directive *));
80 static int do_else PARAMS ((cpp_reader *, struct directive *));
81 static int do_elif PARAMS ((cpp_reader *, struct directive *));
82 static int do_endif PARAMS ((cpp_reader *, struct directive *));
84 static int do_sccs PARAMS ((cpp_reader *, struct directive *));
86 static int do_assert PARAMS ((cpp_reader *, struct directive *));
87 static int do_unassert PARAMS ((cpp_reader *, struct directive *));
88 static int do_warning PARAMS ((cpp_reader *, struct directive *));
90 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
91 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
93 /* Here is the actual list of #-directives, most-often-used first.
94 The initialize_builtins function assumes #define is the very first. */
96 static struct directive directive_table[] = {
97 { 6, do_define, "define", T_DEFINE },
98 { 5, do_xifdef, "ifdef", T_IFDEF },
99 { 6, do_xifdef, "ifndef", T_IFNDEF },
100 { 7, do_include, "include", T_INCLUDE },
101 { 12, do_include, "include_next", T_INCLUDE_NEXT },
102 { 6, do_include, "import", T_IMPORT },
103 { 5, do_endif, "endif", T_ENDIF },
104 { 4, do_else, "else", T_ELSE },
105 { 2, do_if, "if", T_IF },
106 { 4, do_elif, "elif", T_ELIF },
107 { 5, do_undef, "undef", T_UNDEF },
108 { 5, do_error, "error", T_ERROR },
109 { 7, do_warning, "warning", T_WARNING },
110 { 6, do_pragma, "pragma", T_PRAGMA },
111 { 4, do_line, "line", T_LINE },
112 { 5, do_ident, "ident", T_IDENT },
113 #ifdef SCCS_DIRECTIVE
114 { 4, do_sccs, "sccs", T_SCCS },
116 { 6, do_assert, "assert", T_ASSERT },
117 { 8, do_unassert, "unassert", T_UNASSERT },
118 { -1, 0, "", T_UNUSED }
121 /* Place into PFILE a quoted string representing the string SRC.
122 Caller must reserve enough space in pfile->token_buffer. */
125 quote_string (pfile, src)
131 CPP_PUTC_Q (pfile, '\"');
133 switch ((c = *src++))
137 CPP_PUTC_Q (pfile, c);
140 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
141 CPP_ADJUST_WRITTEN (pfile, 4);
147 CPP_PUTC_Q (pfile, '\\');
148 CPP_PUTC_Q (pfile, c);
152 CPP_PUTC_Q (pfile, '\"');
153 CPP_NUL_TERMINATE_Q (pfile);
158 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
161 cpp_grow_buffer (pfile, n)
165 long old_written = CPP_WRITTEN (pfile);
166 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
167 pfile->token_buffer = (U_CHAR *)
168 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
169 CPP_SET_WRITTEN (pfile, old_written);
172 /* Process the string STR as if it appeared as the body of a #define
173 If STR is just an identifier, define it with value 1.
174 If STR has anything after the identifier, then it should
175 be identifier=definition. */
178 cpp_define (pfile, str)
185 /* Copy the entire option so we can modify it. */
186 count = strlen (str) + 3;
187 buf = (U_CHAR *) alloca (count);
188 memcpy (buf, str, count - 2);
189 /* Change the first "=" in the string to a space. If there is none,
190 tack " 1" on the end. */
191 p = (U_CHAR *) strchr (buf, '=');
198 strcpy (&buf[count-3], " 1");
200 if (cpp_push_buffer (pfile, buf, count - 1) != NULL)
202 do_define (pfile, NULL);
203 cpp_pop_buffer (pfile);
207 /* Process the string STR as if it appeared as the body of a #assert. */
209 cpp_assert (pfile, str)
213 if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
215 do_assert (pfile, NULL);
216 cpp_pop_buffer (pfile);
221 static enum cpp_token
222 null_underflow (pfile)
223 cpp_reader *pfile ATTRIBUTE_UNUSED;
229 null_cleanup (pbuf, pfile)
230 cpp_buffer *pbuf ATTRIBUTE_UNUSED;
231 cpp_reader *pfile ATTRIBUTE_UNUSED;
236 /* Skip a comment - C, C++, or Chill style. M is the first character
237 of the comment marker. If this really is a comment, skip to its
238 end and return ' '. If we hit end-of-file before end-of-comment,
239 return EOF. If this is not a comment, return M (which will be
243 skip_comment (pfile, m)
247 if (m == '/' && PEEKC() == '*')
253 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
259 cpp_error_with_line (pfile, line, col, "unterminated comment");
262 else if (c == '\n' || c == '\r')
263 CPP_BUMP_LINE (pfile);
264 else if (c == '/' && prev_c == '*')
266 else if (c == '*' && prev_c == '/'
267 && CPP_OPTIONS (pfile)->warn_comments)
268 cpp_warning (pfile, "`/*' within comment");
273 else if ((m == '/' && PEEKC() == '/'
274 && CPP_OPTIONS (pfile)->cplusplus_comments)
275 || (m == '-' && PEEKC() == '-'
276 && CPP_OPTIONS (pfile)->chill))
283 return ' '; /* Allow // to be terminated by EOF. */
286 /* Don't consider final '\n' to be part of comment. */
291 CPP_BUMP_LINE (pfile);
298 /* Identical to skip_comment except that it copies the comment into the
299 token_buffer. This is used if put_out_comments. */
301 copy_comment (pfile, m)
305 if (m == '/' && PEEKC() == '*')
310 CPP_PUTC (pfile, '/');
311 CPP_PUTC (pfile, '*');
313 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
319 cpp_error_with_line (pfile, line, col, "unterminated comment");
320 /* We must pretend this was a legitimate comment, so that the
321 output in token_buffer is not passed back tagged CPP_POP. */
326 CPP_BUMP_LINE (pfile);
334 CPP_BUMP_LINE (pfile);
336 else if (c == '/' && prev_c == '*')
338 else if (c == '*' && prev_c == '/'
339 && CPP_OPTIONS (pfile)->warn_comments)
340 cpp_warning (pfile, "`/*' within comment");
345 else if ((m == '/' && PEEKC() == '/'
346 && CPP_OPTIONS (pfile)->cplusplus_comments)
347 || (m == '-' && PEEKC() == '-'
348 && CPP_OPTIONS (pfile)->chill))
357 return ' '; /* Allow line comments to be terminated by EOF. */
360 /* Don't consider final '\n' to be part of comment. */
365 CPP_BUMP_LINE (pfile);
375 /* Skip whitespace \-newline and comments. Does not macro-expand. */
378 cpp_skip_hspace (pfile)
387 else if (is_hor_space[c])
389 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
390 cpp_pedwarn (pfile, "%s in preprocessing directive",
391 c == '\f' ? "formfeed" : "vertical tab");
395 CPP_BUFFER (pfile)->lineno++;
397 else if (c == '/' || c == '-')
399 c = skip_comment (pfile, c);
408 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
421 /* Read the rest of the current line.
422 The line is appended to PFILE's output buffer. */
425 copy_rest_of_line (pfile)
436 CPP_NUL_TERMINATE (pfile);
440 CPP_BUFFER (pfile)->lineno++;
444 parse_string (pfile, c);
447 if (PEEKC() == '*' && CPP_TRADITIONAL (pfile))
449 CPP_PUTS (pfile, "/**/", 4);
450 skip_comment (pfile, c);
453 /* else fall through */
455 c = skip_comment (pfile, c);
460 if (CPP_PEDANTIC (pfile))
461 cpp_pedwarn (pfile, "%s in preprocessing directive",
462 c == '\f' ? "formfeed" : "vertical tab");
470 /* FIXME: It is almost definitely a performance win to make this do
471 the scan itself. >75% of calls to copy_r_o_l are from here or
472 skip_if_group, which means the common case is to copy stuff into the
473 token_buffer only to discard it. */
475 skip_rest_of_line (pfile)
478 long old = CPP_WRITTEN (pfile);
479 copy_rest_of_line (pfile);
480 CPP_SET_WRITTEN (pfile, old);
483 /* Handle a possible # directive.
484 '#' has already been read. */
487 handle_directive (pfile)
491 register struct directive *kt;
494 long old_written = CPP_WRITTEN (pfile);
496 cpp_skip_hspace (pfile);
499 if (c >= '0' && c <= '9')
501 /* Handle # followed by a line number. */
502 if (CPP_PEDANTIC (pfile))
503 cpp_pedwarn (pfile, "`#' followed by integer");
504 do_line (pfile, NULL);
505 goto done_a_directive;
508 /* Now find the directive name. */
509 CPP_PUTC (pfile, '#');
510 parse_name (pfile, GETC());
511 ident = pfile->token_buffer + old_written + 1;
512 ident_length = CPP_PWRITTEN (pfile) - ident;
513 if (ident_length == 0 && PEEKC() == '\n')
515 /* A line of just `#' becomes blank. */
516 goto done_a_directive;
520 if (ident_length == 0 || !is_idstart[*ident]) {
522 while (is_idchar[*p]) {
523 if (*p < '0' || *p > '9')
527 /* Avoid error for `###' and similar cases unless -pedantic. */
529 while (*p == '#' || is_hor_space[*p]) p++;
531 if (pedantic && !lang_asm)
532 cpp_warning (pfile, "invalid preprocessor directive");
538 cpp_error (pfile, "invalid preprocessor directive name");
544 * Decode the keyword and call the appropriate expansion
545 * routine, after moving the input pointer up to the next line.
547 for (kt = directive_table; ; kt++) {
549 goto not_a_directive;
550 if (kt->length == ident_length
551 && !strncmp (kt->name, ident, ident_length))
555 /* We may want to pass through #define, #undef, #pragma, and #include.
556 Other directives may create output, but we don't want the directive
557 itself out, so we pop it now. For example conditionals may emit
558 #failed ... #endfailed stuff. */
560 if (! (kt->type == T_DEFINE
561 || kt->type == T_PRAGMA
562 || (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)
563 && CPP_OPTIONS (pfile)->dump_includes)))
564 CPP_SET_WRITTEN (pfile, old_written);
566 (*kt->func) (pfile, kt);
568 if (kt->type == T_DEFINE)
570 if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
572 /* Skip "#define". */
573 U_CHAR *p = pfile->token_buffer + old_written + 7;
575 SKIP_WHITE_SPACE (p);
576 while (is_idchar[*p]) p++;
578 CPP_PUTC (pfile, '\n');
580 else if (CPP_OPTIONS (pfile)->dump_macros != dump_definitions)
581 CPP_SET_WRITTEN (pfile, old_written);
591 /* Pass a directive through to the output file.
592 BUF points to the contents of the directive, as a contiguous string.
593 m LIMIT points to the first character past the end of the directive.
594 KEYWORD is the keyword-table entry for the directive. */
597 pass_thru_directive (buf, limit, pfile, keyword)
600 struct directive *keyword;
602 register unsigned keyword_length = keyword->length;
604 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
605 CPP_PUTC_Q (pfile, '#');
606 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
607 if (limit != buf && buf[0] != ' ')
608 CPP_PUTC_Q (pfile, ' ');
609 CPP_PUTS_Q (pfile, buf, limit - buf);
611 CPP_PUTS_Q (pfile, '\n');
612 /* Count the line we have just made in the output,
613 to get in sync properly. */
618 /* Check a purported macro name SYMNAME, and yield its length.
619 ASSERTION is nonzero if this is really for an assertion name. */
622 check_macro_name (pfile, symname, assertion)
630 for (p = symname; is_idchar[*p]; p++)
632 sym_length = p - symname;
634 || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
636 assertion ? "invalid assertion name" : "invalid macro name");
637 else if (!is_idstart[*symname]
638 || (! strncmp (symname, "defined", 7) && sym_length == 7)) {
639 U_CHAR *msg; /* what pain... */
640 msg = (U_CHAR *) alloca (sym_length + 1);
641 bcopy (symname, msg, sym_length);
645 ? "invalid assertion name `%s'"
646 : "invalid macro name `%s'"),
653 /* Process a #define command.
654 KEYWORD is the keyword-table entry for #define,
655 or NULL for a "predefined" macro. */
658 do_define (pfile, keyword)
660 struct directive *keyword;
666 U_CHAR *macro, *buf, *end;
668 here = CPP_WRITTEN (pfile);
669 copy_rest_of_line (pfile);
671 /* Copy out the line so we can pop the token buffer. */
672 buf = pfile->token_buffer + here;
673 end = CPP_PWRITTEN (pfile);
674 macro = alloca (end - buf + 1);
675 bcopy (buf, macro, end - buf + 1);
676 end = macro + (end - buf);
678 CPP_SET_WRITTEN (pfile, here);
681 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
682 if (pcp_outfile && keyword)
683 pass_thru_directive (macro, end, pfile, keyword);
686 mdef = create_definition (macro, end, pfile, keyword == NULL);
690 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
692 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
695 /* Redefining a precompiled key is ok. */
696 if (hp->type == T_PCSTRING)
698 /* Redefining a macro is ok if the definitions are the same. */
699 else if (hp->type == T_MACRO)
700 ok = ! compare_defs (pfile, mdef.defn, hp->value.defn);
701 /* Redefining a constant is ok with -D. */
702 else if (hp->type == T_CONST || hp->type == T_STDC)
703 ok = ! CPP_OPTIONS (pfile)->done_initializing;
704 /* Print the warning if it's not ok. */
707 /* If we are passing through #define and #undef directives, do
708 that for this re-definition now. */
709 if (CPP_OPTIONS (pfile)->debug_output && keyword)
710 pass_thru_directive (macro, end, pfile, keyword);
712 cpp_pedwarn (pfile, "`%.*s' redefined", mdef.symlen, mdef.symnam);
713 if (hp->type == T_MACRO)
714 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
715 "this is the location of the previous definition");
717 /* Replace the old definition. */
719 hp->value.defn = mdef.defn;
723 /* If we are passing through #define and #undef directives, do
724 that for this new definition now. */
725 if (CPP_OPTIONS (pfile)->debug_output && keyword)
726 pass_thru_directive (macro, end, pfile, keyword);
727 cpp_install (pfile, mdef.symnam, mdef.symlen, T_MACRO,
728 (char *) mdef.defn, hashcode);
739 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
740 If BUFFER != NULL, then use the LENGTH characters in BUFFER
741 as the new input buffer.
742 Return the new buffer, or NULL on failure. */
745 cpp_push_buffer (pfile, buffer, length)
750 cpp_buffer *buf = CPP_BUFFER (pfile);
752 if (++pfile->buffer_stack_depth == CPP_STACK_MAX)
754 cpp_fatal (pfile, "macro or `#include' recursion too deep");
758 new = (cpp_buffer *) xcalloc (sizeof (cpp_buffer), 1);
760 new->if_stack = pfile->if_stack;
761 new->cleanup = null_cleanup;
762 new->underflow = null_underflow;
763 new->buf = new->cur = buffer;
764 new->alimit = new->rlimit = buffer + length;
768 CPP_BUFFER (pfile) = new;
773 cpp_pop_buffer (pfile)
776 cpp_buffer *buf = CPP_BUFFER (pfile);
777 (*buf->cleanup) (buf, pfile);
778 CPP_BUFFER (pfile) = CPP_PREV_BUFFER (buf);
780 pfile->buffer_stack_depth--;
781 return CPP_BUFFER (pfile);
784 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
785 Pop the buffer when done. */
788 cpp_scan_buffer (pfile)
791 cpp_buffer *buffer = CPP_BUFFER (pfile);
794 enum cpp_token token = cpp_get_token (pfile);
795 if (token == CPP_EOF) /* Should not happen ... */
797 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
799 cpp_pop_buffer (pfile);
806 * Rescan a string (which may have escape marks) into pfile's buffer.
807 * Place the result in pfile->token_buffer.
809 * The input is copied before it is scanned, so it is safe to pass
810 * it something from the token_buffer that will get overwritten
811 * (because it follows CPP_WRITTEN). This is used by do_include.
815 cpp_expand_to_buffer (pfile, buf, length)
820 register cpp_buffer *ip;
826 int odepth = indepth;
832 /* Set up the input on the input stack. */
834 buf1 = (U_CHAR *) alloca (length + 1);
835 memcpy (buf1, buf, length);
838 ip = cpp_push_buffer (pfile, buf1, length);
843 ip->lineno = obuf.lineno = 1;
846 /* Scan the input, create the output. */
847 cpp_scan_buffer (pfile);
849 CPP_NUL_TERMINATE (pfile);
853 cpp_buf_line_and_col (pbuf, linep, colp)
854 register cpp_buffer *pbuf;
859 *linep = pbuf->lineno;
861 *colp = pbuf->cur - pbuf->line_base;
871 /* Return the cpp_buffer that corresponds to a file (not a macro). */
874 cpp_file_buffer (pfile)
877 cpp_buffer *ip = CPP_BUFFER (pfile);
879 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
880 if (ip->fname != NULL)
886 * write out a #line command, for instance, after an #include file.
887 * If CONDITIONAL is nonzero, we can omit the #line if it would
888 * appear to be a no-op, and we can output a few newlines instead
889 * if we want to increase the line number by a small amount.
890 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
894 output_line_command (pfile, conditional, file_change)
897 enum file_change_code file_change;
900 cpp_buffer *ip = CPP_BUFFER (pfile);
902 if (ip->fname == NULL)
905 if (CPP_OPTIONS (pfile)->no_line_commands
906 || CPP_OPTIONS (pfile)->no_output)
909 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
913 if (line == pfile->lineno)
916 /* If the inherited line number is a little too small,
917 output some newlines instead of a #line command. */
918 if (line > pfile->lineno && line < pfile->lineno + 8)
920 CPP_RESERVE (pfile, 20);
921 while (line > pfile->lineno)
923 CPP_PUTC_Q (pfile, '\n');
930 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
931 CPP_PUTS_Q (pfile, "# ", 2);
933 sprintf ((char *) CPP_PWRITTEN (pfile), "%ld ", line);
934 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
936 quote_string (pfile, ip->nominal_fname);
937 if (file_change != same_file)
939 CPP_PUTC_Q (pfile, ' ');
940 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
942 /* Tell cc1 if following text comes from a system header file. */
943 if (ip->system_header_p)
945 CPP_PUTC_Q (pfile, ' ');
946 CPP_PUTC_Q (pfile, '3');
948 #ifndef NO_IMPLICIT_EXTERN_C
949 /* Tell cc1plus if following text should be treated as C. */
950 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus)
952 CPP_PUTC_Q (pfile, ' ');
953 CPP_PUTC_Q (pfile, '4');
956 CPP_PUTC_Q (pfile, '\n');
957 pfile->lineno = line;
961 /* Like cpp_get_token, except that it does not read past end-of-line.
962 Also, horizontal space is skipped, and macros are popped. */
964 static enum cpp_token
965 get_directive_token (pfile)
970 long old_written = CPP_WRITTEN (pfile);
971 enum cpp_token token;
972 cpp_skip_hspace (pfile);
973 if (PEEKC () == '\n')
975 token = cpp_get_token (pfile);
979 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
981 /* ... else fall though ... */
982 case CPP_HSPACE: case CPP_COMMENT:
983 CPP_SET_WRITTEN (pfile, old_written);
991 /* Handle #include and #import.
992 This function expects to see "fname" or <fname> on the input.
994 The input is normally in part of the output_buffer following
995 CPP_WRITTEN, and will get overwritten by output_line_command.
996 I.e. in input file specification has been popped by handle_directive.
1000 do_include (pfile, keyword)
1002 struct directive *keyword;
1004 int importing = (keyword->type == T_IMPORT);
1005 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
1006 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
1007 int before; /* included before? */
1009 unsigned char *fbeg, *fend;
1012 enum cpp_token token;
1014 /* Chain of dirs to search */
1015 struct include_hash *ihash;
1016 struct file_name_list *search_start;
1018 long old_written = CPP_WRITTEN (pfile);
1022 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1025 cpp_pedwarn (pfile, "ANSI C does not allow `#import'");
1027 cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'");
1030 if (importing && CPP_OPTIONS (pfile)->warn_import
1031 && !CPP_OPTIONS (pfile)->inhibit_warnings
1032 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
1034 pfile->import_warning = 1;
1035 cpp_warning (pfile, "`#import' is obsolete, use an #ifndef wrapper in the header file");
1038 pfile->parsing_include_directive++;
1039 token = get_directive_token (pfile);
1040 pfile->parsing_include_directive--;
1042 if (token == CPP_STRING)
1044 fbeg = pfile->token_buffer + old_written + 1;
1045 fend = CPP_PWRITTEN (pfile) - 1;
1047 if (fbeg[-1] == '<')
1051 else if (token == CPP_NAME)
1053 /* Support '#include xyz' like VAX-C to allow for easy use of
1054 * all the decwindow include files. It defaults to '#include
1055 * <xyz.h>' and generates a warning. */
1057 "VAX-C-style include specification found, use '#include <filename.h>' !");
1060 /* Append the missing `.h' to the name. */
1061 CPP_PUTS (pfile, ".h", 3)
1062 CPP_NUL_TERMINATE_Q (pfile);
1064 fbeg = pfile->token_buffer + old_written;
1065 fend = CPP_PWRITTEN (pfile);
1071 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
1072 CPP_SET_WRITTEN (pfile, old_written);
1073 skip_rest_of_line (pfile);
1077 token = get_directive_token (pfile);
1078 if (token != CPP_VSPACE)
1080 cpp_error (pfile, "junk at end of `#include'");
1081 skip_rest_of_line (pfile);
1084 CPP_SET_WRITTEN (pfile, old_written);
1090 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
1096 for (fp = CPP_BUFFER (pfile);
1097 fp != CPP_NULL_BUFFER (pfile);
1098 fp = CPP_PREV_BUFFER (fp))
1099 if (fp->fname != NULL)
1102 if (fp == CPP_NULL_BUFFER (pfile))
1104 cpp_fatal (pfile, "cpp internal error: fp == NULL_BUFFER in do_include");
1108 /* For #include_next, skip in the search path past the dir in which the
1109 containing file was found. Treat files specified using an absolute path
1110 as if there are no more directories to search. Treat the primary source
1111 file like any other included source, but generate a warning. */
1112 if (skip_dirs && CPP_PREV_BUFFER(fp) != CPP_NULL_BUFFER (pfile))
1114 if (fp->ihash->foundhere != ABSOLUTE_PATH)
1115 search_start = fp->ihash->foundhere->next;
1120 cpp_warning (pfile, "#include_next in primary source file");
1123 search_start = CPP_OPTIONS (pfile)->bracket_include;
1126 if (!CPP_OPTIONS (pfile)->ignore_srcdir)
1129 search_start = fp->actual_dir;
1132 search_start = CPP_OPTIONS (pfile)->quote_include;
1138 cpp_error (pfile, "No include path in which to find %s", fbeg);
1142 fd = find_include_file (pfile, fbeg, search_start, &ihash, &before);
1149 if (CPP_OPTIONS (pfile)->print_deps_missing_files
1150 && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
1151 (pfile->system_include_depth > 0)))
1153 if (!angle_brackets)
1154 deps_output (pfile, fbeg, ' ');
1158 struct file_name_list *ptr;
1159 /* If requested as a system header, assume it belongs in
1160 the first system header directory. */
1161 if (CPP_OPTIONS (pfile)->bracket_include)
1162 ptr = CPP_OPTIONS (pfile)->bracket_include;
1164 ptr = CPP_OPTIONS (pfile)->quote_include;
1166 p = (char *) alloca (strlen (ptr->name)
1167 + strlen (fbeg) + 2);
1168 if (*ptr->name != '\0')
1170 strcpy (p, ptr->name);
1174 deps_output (pfile, p, ' ');
1177 /* If -M was specified, and this header file won't be added to
1178 the dependency list, then don't count this as an error,
1179 because we can still produce correct output. Otherwise, we
1180 can't produce correct output, because there may be
1181 dependencies we need inside the missing file, and we don't
1182 know what directory this missing file exists in. */
1183 else if (CPP_PRINT_DEPS (pfile)
1184 && (CPP_PRINT_DEPS (pfile)
1185 <= (angle_brackets || (pfile->system_include_depth > 0))))
1186 cpp_warning (pfile, "No include path in which to find %s", fbeg);
1188 cpp_error_from_errno (pfile, fbeg);
1193 /* For -M, add the file to the dependencies on its first inclusion. */
1194 if (!before && (CPP_PRINT_DEPS (pfile)
1195 > (angle_brackets || (pfile->system_include_depth > 0))))
1196 deps_output (pfile, ihash->name, ' ');
1198 /* Handle -H option. */
1199 if (CPP_OPTIONS(pfile)->print_include_names)
1201 fp = CPP_BUFFER (pfile);
1202 while ((fp = CPP_PREV_BUFFER (fp)) != CPP_NULL_BUFFER (pfile))
1204 fprintf (stderr, " %s\n", ihash->name);
1207 /* Actually process the file */
1210 ihash->control_macro = "";
1212 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
1219 pfile->system_include_depth++; /* Decremented in file_cleanup. */
1221 if (finclude (pfile, fd, ihash))
1223 output_line_command (pfile, 0, enter_file);
1224 pfile->only_seen_white = 2;
1230 /* Interpret #line command.
1231 Note that the filename string (if any) is treated as if it were an
1232 include filename. That means no escape handling. */
1235 do_line (pfile, keyword)
1237 struct directive *keyword ATTRIBUTE_UNUSED;
1239 cpp_buffer *ip = CPP_BUFFER (pfile);
1241 long old_written = CPP_WRITTEN (pfile);
1242 enum file_change_code file_change = same_file;
1243 enum cpp_token token;
1246 token = get_directive_token (pfile);
1248 if (token != CPP_NUMBER)
1250 cpp_error (pfile, "token after `#line' is not an integer");
1251 goto bad_line_directive;
1254 new_lineno = strtol (pfile->token_buffer + old_written, &x, 10);
1257 cpp_error (pfile, "token after `#line' is not an integer");
1258 goto bad_line_directive;
1260 CPP_SET_WRITTEN (pfile, old_written);
1262 if (CPP_PEDANTIC (pfile) && new_lineno <= 0)
1263 cpp_pedwarn (pfile, "line number out of range in `#line' command");
1265 token = get_directive_token (pfile);
1267 if (token == CPP_STRING)
1269 U_CHAR *fname = pfile->token_buffer + old_written + 1;
1270 U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1;
1271 long num_start = CPP_WRITTEN (pfile);
1273 token = get_directive_token (pfile);
1274 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
1276 U_CHAR *p = pfile->token_buffer + num_start;
1277 if (CPP_PEDANTIC (pfile))
1278 cpp_pedwarn (pfile, "garbage at end of `#line' command");
1280 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
1282 cpp_error (pfile, "invalid format `#line' command");
1283 goto bad_line_directive;
1286 file_change = enter_file;
1288 file_change = leave_file;
1290 ip->system_header_p = 1;
1291 else /* if (*p == '4') */
1292 ip->system_header_p = 2;
1294 CPP_SET_WRITTEN (pfile, num_start);
1295 token = get_directive_token (pfile);
1296 p = pfile->token_buffer + num_start;
1297 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4'))
1299 ip->system_header_p = *p == '3' ? 1 : 2;
1300 token = get_directive_token (pfile);
1302 if (token != CPP_VSPACE)
1304 cpp_error (pfile, "invalid format `#line' command");
1305 goto bad_line_directive;
1311 if (strcmp (fname, ip->nominal_fname))
1313 char *newname, *oldname;
1314 if (!strcmp (fname, ip->fname))
1315 newname = ip->fname;
1316 else if (ip->last_nominal_fname
1317 && !strcmp (fname, ip->last_nominal_fname))
1318 newname = ip->last_nominal_fname;
1320 newname = xstrdup (fname);
1322 oldname = ip->nominal_fname;
1323 ip->nominal_fname = newname;
1325 if (ip->last_nominal_fname
1326 && ip->last_nominal_fname != oldname
1327 && ip->last_nominal_fname != newname
1328 && ip->last_nominal_fname != ip->fname)
1329 free (ip->last_nominal_fname);
1331 if (newname == ip->fname)
1332 ip->last_nominal_fname = NULL;
1334 ip->last_nominal_fname = oldname;
1337 else if (token != CPP_VSPACE && token != CPP_EOF)
1339 cpp_error (pfile, "token after `#line %d' is not a string", new_lineno);
1340 goto bad_line_directive;
1343 /* The Newline at the end of this line remains to be processed.
1344 To put the next line at the specified line number,
1345 we must store a line number now that is one less. */
1346 ip->lineno = new_lineno - 1;
1347 CPP_SET_WRITTEN (pfile, old_written);
1348 output_line_command (pfile, 0, file_change);
1352 skip_rest_of_line (pfile);
1353 CPP_SET_WRITTEN (pfile, old_written);
1357 /* Remove the definition of a symbol from the symbol table.
1358 According to the C standard, it is not an error to undef
1359 something that has no definitions. */
1361 do_undef (pfile, keyword)
1363 struct directive *keyword;
1367 U_CHAR *buf, *name, *limit;
1369 long here = CPP_WRITTEN (pfile);
1370 enum cpp_token token;
1372 cpp_skip_hspace (pfile);
1374 if (! is_idstart[c])
1376 cpp_error (pfile, "token after #undef is not an identifier");
1377 skip_rest_of_line (pfile);
1381 parse_name (pfile, c);
1382 buf = pfile->token_buffer + here;
1383 limit = CPP_PWRITTEN(pfile);
1385 /* Copy out the token so we can pop the token buffer. */
1386 name = alloca (limit - buf + 1);
1387 bcopy(buf, name, limit - buf);
1388 name[limit - buf] = '\0';
1390 token = get_directive_token (pfile);
1391 if (token != CPP_VSPACE && token != CPP_POP)
1393 cpp_pedwarn (pfile, "junk on line after #undef");
1394 skip_rest_of_line (pfile);
1397 CPP_SET_WRITTEN (pfile, here);
1400 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
1401 if (pcp_outfile && keyword)
1402 pass_thru_directive (buf, limit, pfile, keyword);
1405 sym_length = check_macro_name (pfile, buf, 0);
1407 while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
1409 /* If we are generating additional info for debugging (with -g) we
1410 need to pass through all effective #undef commands. */
1411 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1412 pass_thru_directive (name, name+sym_length, pfile, keyword);
1413 if (hp->type != T_MACRO)
1414 cpp_warning (pfile, "undefining `%s'", hp->name);
1421 /* Wrap do_undef for -U processing. */
1423 cpp_undef (pfile, macro)
1427 if (cpp_push_buffer (pfile, macro, strlen (macro)))
1429 do_undef (pfile, NULL);
1430 cpp_pop_buffer (pfile);
1436 * Report an error detected by the program we are processing.
1437 * Use the text of the line in the error message.
1438 * (We use error because it prints the filename & line#.)
1442 do_error (pfile, keyword)
1444 struct directive *keyword ATTRIBUTE_UNUSED;
1446 long here = CPP_WRITTEN (pfile);
1448 copy_rest_of_line (pfile);
1449 text = pfile->token_buffer + here;
1450 SKIP_WHITE_SPACE(text);
1452 cpp_error (pfile, "#error %s", text);
1453 CPP_SET_WRITTEN (pfile, here);
1458 * Report a warning detected by the program we are processing.
1459 * Use the text of the line in the warning message, then continue.
1463 do_warning (pfile, keyword)
1465 struct directive *keyword ATTRIBUTE_UNUSED;
1468 long here = CPP_WRITTEN(pfile);
1469 copy_rest_of_line (pfile);
1470 text = pfile->token_buffer + here;
1471 SKIP_WHITE_SPACE(text);
1473 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1474 cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
1476 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
1477 if -pedantic-errors is given, #warning should cause an error. */
1478 cpp_pedwarn (pfile, "#warning %s", text);
1479 CPP_SET_WRITTEN (pfile, here);
1483 /* Report program identification. */
1486 do_ident (pfile, keyword)
1488 struct directive *keyword ATTRIBUTE_UNUSED;
1490 /* Allow #ident in system headers, since that's not user's fault. */
1491 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
1492 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
1494 skip_rest_of_line (pfile); /* Correct? Appears to match cccp. */
1499 /* Just check for some recognized pragmas that need validation here,
1500 and leave the text in the token buffer to be output. */
1503 do_pragma (pfile, keyword)
1505 struct directive *keyword ATTRIBUTE_UNUSED;
1507 long here = CPP_WRITTEN (pfile);
1510 copy_rest_of_line (pfile);
1511 buf = pfile->token_buffer + here;
1512 SKIP_WHITE_SPACE (buf);
1514 if (!strncmp (buf, "once", 4))
1516 cpp_buffer *ip = NULL;
1518 /* Allow #pragma once in system headers, since that's not the user's
1520 if (!CPP_BUFFER (pfile)->system_header_p)
1521 cpp_warning (pfile, "`#pragma once' is obsolete");
1523 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
1525 if (ip == CPP_NULL_BUFFER (pfile))
1527 if (ip->fname != NULL)
1531 if (CPP_PREV_BUFFER (ip) == CPP_NULL_BUFFER (pfile))
1532 cpp_warning (pfile, "`#pragma once' outside include file");
1534 ip->ihash->control_macro = ""; /* never repeat */
1537 if (!strncmp (buf, "implementation", 14))
1539 /* Be quiet about `#pragma implementation' for a file only if it hasn't
1540 been included yet. */
1541 struct include_hash *ptr;
1542 U_CHAR *p = buf + 14, *fname, *fcopy;
1543 SKIP_WHITE_SPACE (p);
1544 if (*p == '\n' || *p != '\"')
1548 p = (U_CHAR *) index (fname, '\"');
1550 fcopy = alloca (p - fname + 1);
1551 bcopy (fname, fcopy, p - fname);
1552 fcopy[p-fname] = '\0';
1554 ptr = include_hash (pfile, fcopy, 0);
1557 "`#pragma implementation' for `%s' appears after file is included",
1564 #ifdef SCCS_DIRECTIVE
1565 /* Just ignore #sccs, on systems where we define it at all. */
1568 do_sccs (pfile, keyword)
1570 struct directive *keyword ATTRIBUTE_UNUSED;
1572 if (CPP_PEDANTIC (pfile))
1573 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
1574 skip_rest_of_line (pfile);
1580 * handle #if command by
1581 * 1) inserting special `defined' keyword into the hash table
1582 * that gets turned into 0 or 1 by special_symbol (thus,
1583 * if the luser has a symbol called `defined' already, it won't
1584 * work inside the #if command)
1585 * 2) rescan the input into a temporary output buffer
1586 * 3) pass the output buffer to the yacc parser and collect a value
1587 * 4) clean up the mess left from steps 1 and 2.
1588 * 5) call conditional_skip to skip til the next #endif (etc.),
1589 * or not, depending on the value from step 3.
1593 do_if (pfile, keyword)
1595 struct directive *keyword ATTRIBUTE_UNUSED;
1597 HOST_WIDEST_INT value = eval_if_expression (pfile);
1598 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
1603 * handle a #elif directive by not changing if_stack either.
1604 * see the comment above do_else.
1608 do_elif (pfile, keyword)
1610 struct directive *keyword ATTRIBUTE_UNUSED;
1612 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
1613 cpp_error (pfile, "`#elif' not within a conditional");
1616 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
1617 cpp_error (pfile, "`#elif' after `#else'");
1619 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
1621 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
1622 && strcmp (pfile->if_stack->fname,
1623 CPP_BUFFER (pfile)->nominal_fname) != 0)
1624 fprintf (stderr, ", file %s", pfile->if_stack->fname);
1625 fprintf (stderr, ")\n");
1627 pfile->if_stack->type = T_ELIF;
1630 if (pfile->if_stack->if_succeeded)
1631 skip_if_group (pfile);
1633 HOST_WIDEST_INT value = eval_if_expression (pfile);
1635 skip_if_group (pfile);
1637 ++pfile->if_stack->if_succeeded; /* continue processing input */
1638 output_line_command (pfile, 1, same_file);
1645 * evaluate a #if expression in BUF, of length LENGTH,
1646 * then parse the result as a C expression and return the value as an int.
1649 static HOST_WIDEST_INT
1650 eval_if_expression (pfile)
1653 HOST_WIDEST_INT value;
1654 long old_written = CPP_WRITTEN (pfile);
1656 pfile->pcp_inside_if = 1;
1657 value = cpp_parse_expr (pfile);
1658 pfile->pcp_inside_if = 0;
1660 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
1666 * routine to handle ifdef/ifndef. Try to look up the symbol,
1667 * then do or don't skip to the #endif/#else/#elif depending
1668 * on what directive is actually being processed.
1672 do_xifdef (pfile, keyword)
1674 struct directive *keyword;
1677 cpp_buffer *ip = CPP_BUFFER (pfile);
1680 enum cpp_token token;
1681 int start_of_file = 0;
1682 U_CHAR *control_macro = 0;
1683 int old_written = CPP_WRITTEN (pfile);
1685 /* Detect a #ifndef at start of file (not counting comments). */
1686 if (ip->fname != 0 && keyword->type == T_IFNDEF)
1687 start_of_file = pfile->only_seen_white == 2;
1689 pfile->no_macro_expand++;
1690 token = get_directive_token (pfile);
1691 pfile->no_macro_expand--;
1693 ident = pfile->token_buffer + old_written;
1694 ident_length = CPP_WRITTEN (pfile) - old_written;
1695 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
1697 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
1699 skip = (keyword->type == T_IFDEF);
1700 if (! CPP_TRADITIONAL (pfile))
1701 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
1703 else if (token == CPP_NAME)
1705 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
1706 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
1707 if (start_of_file && !skip)
1709 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
1710 bcopy (ident, control_macro, ident_length + 1);
1715 skip = (keyword->type == T_IFDEF);
1716 if (! CPP_TRADITIONAL (pfile))
1717 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
1720 if (!CPP_TRADITIONAL (pfile))
1722 cpp_skip_hspace (pfile);
1724 if (c != EOF && c != '\n')
1725 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
1727 skip_rest_of_line (pfile);
1731 /* Output a precondition for this macro. */
1732 if (hp && hp->value.defn->predefined)
1733 fprintf (pcp_outfile, "#define %s\n", hp->name);
1736 fprintf (pcp_outfile, "#undef ");
1737 while (is_idchar[*cp]) /* Ick! */
1738 fputc (*cp++, pcp_outfile);
1739 putc ('\n', pcp_outfile);
1743 conditional_skip (pfile, skip, T_IF, control_macro);
1747 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
1748 If this is a #ifndef starting at the beginning of a file,
1749 CONTROL_MACRO is the macro name tested by the #ifndef.
1750 Otherwise, CONTROL_MACRO is 0. */
1753 conditional_skip (pfile, skip, type, control_macro)
1756 enum node_type type;
1757 U_CHAR *control_macro;
1759 IF_STACK_FRAME *temp;
1761 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
1762 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
1764 temp->lineno = CPP_BUFFER (pfile)->lineno;
1766 temp->next = pfile->if_stack;
1767 temp->control_macro = control_macro;
1768 pfile->if_stack = temp;
1770 pfile->if_stack->type = type;
1773 skip_if_group (pfile);
1776 ++pfile->if_stack->if_succeeded;
1777 output_line_command (pfile, 1, same_file);
1781 /* Subroutine of skip_if_group. Examine one preprocessing directive and
1782 return 0 if skipping should continue, 1 if it should halt. Also
1783 adjusts the if_stack as appropriate.
1784 The `#' has been read, but not the identifier. */
1787 consider_directive_while_skipping (pfile, stack)
1789 IF_STACK_FRAME *stack;
1791 long ident_len, ident;
1792 struct directive *kt;
1793 IF_STACK_FRAME *temp;
1795 cpp_skip_hspace (pfile);
1797 ident = CPP_WRITTEN (pfile);
1798 parse_name (pfile, GETC());
1799 ident_len = CPP_WRITTEN (pfile) - ident;
1801 CPP_SET_WRITTEN (pfile, ident);
1803 for (kt = directive_table; kt->length >= 0; kt++)
1804 if (kt->length == ident_len
1805 && strncmp (pfile->token_buffer + ident, kt->name, kt->length) == 0)
1811 temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
1812 temp->next = pfile->if_stack;
1813 pfile->if_stack = temp;
1814 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
1815 temp->type = kt->type;
1819 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
1820 validate_else (pfile, "#else");
1823 if (pfile->if_stack->type == T_ELSE)
1824 cpp_error (pfile, "`%s' after `#else'", kt->name);
1826 if (pfile->if_stack == stack)
1830 pfile->if_stack->type = kt->type;
1835 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
1836 validate_else (pfile, "#endif");
1838 if (pfile->if_stack == stack)
1841 temp = pfile->if_stack;
1842 pfile->if_stack = temp->next;
1850 /* Don't let erroneous code go by. */
1851 if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile))
1852 cpp_pedwarn (pfile, "invalid preprocessor directive name");
1856 /* skip to #endif, #else, or #elif. adjust line numbers, etc.
1857 * leaves input ptr at the sharp sign found.
1860 skip_if_group (pfile)
1864 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
1865 U_CHAR *beg_of_line;
1868 if (CPP_OPTIONS (pfile)->output_conditionals)
1870 CPP_PUTS (pfile, "#failed\n", 8);
1872 output_line_command (pfile, 1, same_file);
1875 old_written = CPP_WRITTEN (pfile);
1879 beg_of_line = CPP_BUFFER (pfile)->cur;
1881 if (! CPP_TRADITIONAL (pfile))
1882 cpp_skip_hspace (pfile);
1886 if (CPP_OPTIONS (pfile)->output_conditionals)
1887 CPP_PUTC (pfile, c);
1888 CPP_BUMP_LINE (pfile);
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)
1919 CPP_PUTC (pfile, c);
1922 CPP_BUMP_LINE (pfile);
1926 /* Back up to the beginning of this line. Caller will process the
1928 CPP_BUFFER (pfile)->cur = beg_of_line;
1929 pfile->only_seen_white = 1;
1930 if (CPP_OPTIONS (pfile)->output_conditionals)
1932 CPP_PUTS (pfile, "#endfailed\n", 11);
1938 * handle a #else directive. Do this by just continuing processing
1939 * without changing if_stack ; this is so that the error message
1940 * for missing #endif's etc. will point to the original #if. It
1941 * is possible that something different would be better.
1945 do_else (pfile, keyword)
1947 struct directive *keyword ATTRIBUTE_UNUSED;
1949 cpp_buffer *ip = CPP_BUFFER (pfile);
1951 if (CPP_PEDANTIC (pfile))
1952 validate_else (pfile, "#else");
1953 skip_rest_of_line (pfile);
1955 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
1956 cpp_error (pfile, "`#else' not within a conditional");
1959 /* #ifndef can't have its special treatment for containing the whole file
1960 if it has a #else clause. */
1961 pfile->if_stack->control_macro = 0;
1963 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
1964 cpp_error (pfile, "`#else' after `#else'");
1965 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
1966 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
1967 fprintf (stderr, ", file %s", pfile->if_stack->fname);
1968 fprintf (stderr, ")\n");
1970 pfile->if_stack->type = T_ELSE;
1973 if (pfile->if_stack->if_succeeded)
1974 skip_if_group (pfile);
1976 ++pfile->if_stack->if_succeeded; /* continue processing input */
1977 output_line_command (pfile, 1, same_file);
1983 * unstack after #endif command
1987 do_endif (pfile, keyword)
1989 struct directive *keyword ATTRIBUTE_UNUSED;
1991 if (CPP_PEDANTIC (pfile))
1992 validate_else (pfile, "#endif");
1993 skip_rest_of_line (pfile);
1995 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
1996 cpp_error (pfile, "unbalanced `#endif'");
1999 IF_STACK_FRAME *temp = pfile->if_stack;
2000 pfile->if_stack = temp->next;
2001 if (temp->control_macro != 0)
2003 /* This #endif matched a #ifndef at the start of the file.
2004 See if it is at the end of the file. */
2007 parse_set_mark (pfile);
2011 cpp_skip_hspace (pfile);
2016 parse_goto_mark (pfile);
2020 /* This #endif ends a #ifndef
2021 that contains all of the file (aside from whitespace).
2022 Arrange not to include the file again
2023 if the macro that was tested is defined. */
2024 struct cpp_buffer *ip;
2025 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2026 if (ip->fname != NULL)
2028 ip->ihash->control_macro = (char *) temp->control_macro;
2032 output_line_command (pfile, 1, same_file);
2037 /* When an #else or #endif is found while skipping failed conditional,
2038 if -pedantic was specified, this is called to warn about text after
2039 the command name. P points to the first char after the command name. */
2042 validate_else (pfile, directive)
2047 cpp_skip_hspace (pfile);
2049 if (c != EOF && c != '\n')
2051 "text following `%s' violates ANSI standard", directive);
2054 /* Get the next token, and add it to the text in pfile->token_buffer.
2055 Return the kind of token we got. */
2058 cpp_get_token (pfile)
2061 register int c, c2, c3;
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 if (PEEKC () == '=')
2107 if (opts->put_out_comments)
2108 c = copy_comment (pfile, c);
2110 c = skip_comment (pfile, c);
2116 /* Comments are equivalent to spaces.
2117 For -traditional, a comment is equivalent to nothing. */
2118 if (opts->traditional || opts->put_out_comments)
2122 CPP_PUTC (pfile, c);
2126 if (opts->for_lint) {
2129 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
2131 if (lintcmd != NULL) {
2132 /* I believe it is always safe to emit this newline: */
2134 bcopy ("#pragma lint ", (char *) obp, 13);
2136 bcopy (lintcmd, (char *) obp, cmdlen);
2141 bcopy (argbp, (char *) obp, arglen);
2145 /* OK, now bring us back to the state we were in before we entered
2146 this branch. We need #line because the newline for the pragma
2147 could mess things up. */
2148 output_line_command (pfile, 0, same_file);
2149 *(obp++) = ' '; /* just in case, if comments are copied thru */
2157 /* If this is expanding a macro definition, don't recognize
2158 preprocessor directives. */
2161 /* If this is expand_into_temp_buffer, recognize them
2162 only after an actual newline at this level,
2163 not at the beginning of the input level. */
2164 if (ip->fname == 0 && beg_of_line == ip->buf)
2170 if (!pfile->only_seen_white)
2172 if (handle_directive (pfile))
2173 return CPP_DIRECTIVE;
2174 pfile->only_seen_white = 0;
2180 parse_string (pfile, c);
2181 pfile->only_seen_white = 0;
2182 return c == '\'' ? CPP_CHAR : CPP_STRING;
2185 if (!opts->dollars_in_ident)
2190 if (opts->cplusplus && PEEKC () == ':')
2198 if (c2 == c || c2 == '=')
2207 if (PEEKC () == '=')
2213 if (c2 == '-' && opts->chill)
2214 goto comment; /* Chill style comment */
2215 if (c2 == '-' || c2 == '=' || c2 == '>')
2220 if (pfile->parsing_include_directive)
2224 CPP_PUTC (pfile, c);
2228 if (c == '\n' || c == EOF)
2231 "missing '>' in `#include <FILENAME>'");
2236 /* Backslash newline is replaced by nothing. */
2237 CPP_ADJUST_WRITTEN (pfile, -1);
2238 CPP_BUMP_LINE (pfile);
2243 /* else fall through */
2251 CPP_RESERVE (pfile, 4);
2252 CPP_PUTC (pfile, c);
2253 CPP_PUTC (pfile, c2);
2256 CPP_PUTC_Q (pfile, GETC ());
2257 CPP_NUL_TERMINATE_Q (pfile);
2258 pfile->only_seen_white = 0;
2262 if (CPP_BUFFER (pfile)->has_escapes)
2267 if (pfile->output_escapes)
2268 CPP_PUTS (pfile, "@-", 2);
2269 parse_name (pfile, GETC ());
2274 CPP_RESERVE (pfile, 2);
2275 if (pfile->output_escapes)
2276 CPP_PUTC_Q (pfile, '@');
2277 CPP_PUTC_Q (pfile, c);
2281 if (pfile->output_escapes)
2283 CPP_PUTS (pfile, "@@", 2);
2292 CPP_RESERVE(pfile, 2);
2293 CPP_PUTC_Q (pfile, '.');
2297 if (c2 == '.' && PEEKN(1) == '.')
2299 CPP_RESERVE(pfile, 4);
2300 CPP_PUTC_Q (pfile, '.');
2301 CPP_PUTC_Q (pfile, '.');
2302 CPP_PUTC_Q (pfile, '.');
2304 CPP_NUL_TERMINATE_Q (pfile);
2305 pfile->only_seen_white = 0;
2312 pfile->only_seen_white = 0;
2313 CPP_RESERVE(pfile, 3);
2314 CPP_PUTC_Q (pfile, c);
2315 CPP_PUTC_Q (pfile, GETC ());
2316 CPP_NUL_TERMINATE_Q (pfile);
2321 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
2323 CPP_PUTC (pfile, c);
2329 case '0': case '1': case '2': case '3': case '4':
2330 case '5': case '6': case '7': case '8': case '9':
2335 CPP_RESERVE (pfile, 2);
2336 CPP_PUTC_Q (pfile, c);
2340 if (!is_idchar[c] && c != '.'
2341 && ((c2 != 'e' && c2 != 'E'
2342 && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
2343 || (c != '+' && c != '-')))
2348 CPP_NUL_TERMINATE_Q (pfile);
2349 pfile->only_seen_white = 0;
2351 case 'b': case 'c': case 'd': case 'h': case 'o':
2352 case 'B': case 'C': case 'D': case 'H': case 'O':
2353 if (opts->chill && PEEKC () == '\'')
2355 pfile->only_seen_white = 0;
2356 CPP_RESERVE (pfile, 2);
2357 CPP_PUTC_Q (pfile, c);
2358 CPP_PUTC_Q (pfile, '\'');
2364 goto chill_number_eof;
2367 CPP_PUTC (pfile, c);
2371 CPP_RESERVE (pfile, 2);
2372 CPP_PUTC_Q (pfile, c);
2373 CPP_NUL_TERMINATE_Q (pfile);
2380 CPP_NUL_TERMINATE (pfile);
2387 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
2388 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
2389 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
2390 case 'x': case 'y': case 'z':
2391 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
2392 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
2393 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2398 unsigned char *ident;
2399 int before_name_written = CPP_WRITTEN (pfile);
2401 parse_name (pfile, c);
2402 pfile->only_seen_white = 0;
2403 if (pfile->no_macro_expand)
2405 ident = pfile->token_buffer + before_name_written;
2406 ident_len = CPP_PWRITTEN (pfile) - ident;
2407 hp = cpp_lookup (pfile, ident, ident_len, -1);
2410 if (hp->type == T_DISABLED)
2412 if (pfile->output_escapes)
2413 { /* Return "@-IDENT", followed by '\0'. */
2415 CPP_RESERVE (pfile, 3);
2416 ident = pfile->token_buffer + before_name_written;
2417 CPP_ADJUST_WRITTEN (pfile, 2);
2418 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
2425 /* If macro wants an arglist, verify that a '(' follows.
2426 first skip all whitespace, copying it to the output
2427 after the macro name. Then, if there is no '(',
2428 decide this is not a macro call and leave things that way. */
2429 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
2431 int is_macro_call, macbuf_whitespace = 0;
2433 parse_set_mark (pfile);
2436 cpp_skip_hspace (pfile);
2438 is_macro_call = c == '(';
2447 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2449 if (CPP_BUFFER (pfile)->mark !=
2450 (CPP_BUFFER (pfile)->cur
2451 - CPP_BUFFER (pfile)->buf))
2452 macbuf_whitespace = 1;
2454 /* The mark goes away automatically when
2455 the buffer is popped. */
2456 cpp_pop_buffer (pfile);
2457 parse_set_mark (pfile);
2465 parse_goto_mark (pfile);
2466 if (macbuf_whitespace)
2467 CPP_PUTC (pfile, ' ');
2470 parse_clear_mark (pfile);
2474 /* This is now known to be a macro call.
2475 Expand the macro, reading arguments as needed,
2476 and push the expansion on the input stack. */
2477 macroexpand (pfile, hp);
2478 CPP_SET_WRITTEN (pfile, before_name_written);
2482 case ' ': case '\t': case '\v':
2485 CPP_PUTC (pfile, c);
2487 if (c == EOF || !is_hor_space[c])
2497 /* Backslash newline is ignored. */
2498 CPP_BUMP_LINE (pfile);
2502 CPP_PUTC (pfile, c);
2503 if (pfile->only_seen_white == 0)
2504 pfile->only_seen_white = 1;
2505 CPP_BUMP_LINE (pfile);
2507 if (CPP_BUFFER (pfile)->lineno != pfile->lineno)
2508 output_line_command (pfile, 1, same_file);
2511 case '(': token = CPP_LPAREN; goto char1;
2512 case ')': token = CPP_RPAREN; goto char1;
2513 case '{': token = CPP_LBRACE; goto char1;
2514 case '}': token = CPP_RBRACE; goto char1;
2515 case ',': token = CPP_COMMA; goto char1;
2516 case ';': token = CPP_SEMICOLON; goto char1;
2522 pfile->only_seen_white = 0;
2523 CPP_PUTC (pfile, c);
2529 /* Like cpp_get_token, but skip spaces and comments. */
2532 cpp_get_non_space_token (pfile)
2535 int old_written = CPP_WRITTEN (pfile);
2538 enum cpp_token token = cpp_get_token (pfile);
2539 if (token != CPP_COMMENT && token != CPP_POP
2540 && token != CPP_HSPACE && token != CPP_VSPACE)
2542 CPP_SET_WRITTEN (pfile, old_written);
2546 /* Parse an identifier starting with C. */
2549 parse_name (pfile, c)
2561 if (c == '$' && CPP_PEDANTIC (pfile))
2562 cpp_pedwarn (pfile, "`$' in identifier");
2564 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
2565 CPP_PUTC_Q (pfile, c);
2570 CPP_NUL_TERMINATE_Q (pfile);
2574 /* Parse a string starting with C. A single quoted string is treated
2575 like a double -- some programs (e.g., troff) are perverse this way.
2576 (However, a single quoted string is not allowed to extend over
2579 parse_string (pfile, c)
2583 long start_line, start_column;
2585 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2587 CPP_PUTC (pfile, c);
2593 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2595 /* try harder: this string crosses a macro expansion
2596 boundary. This can happen naturally if -traditional.
2597 Otherwise, only -D can make a macro with an unmatched
2599 cpp_pop_buffer (pfile);
2602 if (!CPP_TRADITIONAL (pfile))
2604 cpp_error_with_line (pfile, start_line, start_column,
2605 "unterminated string or character constant");
2606 if (pfile->multiline_string_line != start_line
2607 && pfile->multiline_string_line != 0)
2608 cpp_error_with_line (pfile,
2609 pfile->multiline_string_line, -1,
2610 "possible real start of unterminated constant");
2611 pfile->multiline_string_line = 0;
2615 CPP_PUTC (pfile, cc);
2619 CPP_BUMP_LINE (pfile);
2621 /* Traditionally, end of line ends a string constant with
2623 if (CPP_TRADITIONAL (pfile))
2625 /* Character constants may not extend over multiple lines. */
2628 cpp_error_with_line (pfile, start_line, start_column,
2629 "unterminated character constant");
2632 if (CPP_PEDANTIC (pfile) && pfile->multiline_string_line == 0)
2634 cpp_pedwarn_with_line (pfile, start_line, start_column,
2635 "string constant runs past end of line");
2637 if (pfile->multiline_string_line == 0)
2638 pfile->multiline_string_line = start_line;
2642 /* Backslash newline is replaced by nothing at all. */
2643 CPP_ADJUST_WRITTEN (pfile, -1);
2644 CPP_BUMP_LINE (pfile);
2650 CPP_PUTC (pfile, cc);
2662 /* Read an assertion into the token buffer, converting to
2663 canonical form: `#predicate(a n swe r)' The next non-whitespace
2664 character to read should be the first letter of the predicate.
2665 Returns 0 for syntax error, 1 for bare predicate, 2 for predicate
2666 with answer (see callers for why). In case of 0, an error has been
2669 parse_assertion (pfile)
2673 cpp_skip_hspace (pfile);
2675 if (! is_idstart[c])
2677 cpp_error (pfile, "assertion predicate is not an identifier");
2680 CPP_PUTC(pfile, '#');
2682 parse_name(pfile, c);
2687 if (is_hor_space[c] || c == '\r')
2688 cpp_skip_hspace (pfile);
2694 CPP_PUTC(pfile, '(');
2697 while ((c = GETC()) != ')')
2699 if (is_hor_space[c])
2703 CPP_PUTC(pfile, ' ');
2707 else if (c == '\n' || c == EOF)
2709 if (c == '\n') FORWARD(-1);
2710 cpp_error (pfile, "un-terminated assertion answer");
2714 CPP_BUMP_LINE (pfile);
2717 CPP_PUTC (pfile, c);
2722 if (pfile->limit[-1] == ' ')
2723 pfile->limit[-1] = ')';
2724 else if (pfile->limit[-1] == '(')
2726 cpp_error (pfile, "empty token sequence in assertion");
2730 CPP_PUTC (pfile, ')');
2732 CPP_NUL_TERMINATE (pfile);
2737 do_assert (pfile, keyword)
2739 struct directive *keyword ATTRIBUTE_UNUSED;
2743 HASHNODE *base, *this;
2744 int baselen, thislen;
2746 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
2747 && !CPP_BUFFER (pfile)->system_header_p)
2748 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
2750 cpp_skip_hspace (pfile);
2751 sym = (char *) CPP_PWRITTEN (pfile); /* remember where it starts */
2752 ret = parse_assertion (pfile);
2757 cpp_error (pfile, "missing token-sequence in `#assert'");
2761 cpp_skip_hspace (pfile);
2763 if (c != EOF && c != '\n')
2765 cpp_error (pfile, "junk at end of `#assert'");
2769 thislen = strlen (sym);
2770 baselen = index (sym, '(') - sym;
2771 this = cpp_lookup (pfile, sym, thislen, -1);
2774 cpp_warning (pfile, "`%s' re-asserted", sym);
2778 base = cpp_lookup (pfile, sym, baselen, -1);
2780 base = cpp_install (pfile, sym, baselen, T_ASSERT, 0, -1);
2781 else if (base->type != T_ASSERT)
2783 /* Token clash - but with what?! */
2785 "cpp internal error: base->type != T_ASSERT in do_assert");
2789 this = cpp_install (pfile, sym, thislen, T_ASSERT,
2790 (char *)base->value.aschain, -1);
2791 base->value.aschain = this;
2793 pfile->limit = (unsigned char *) sym; /* Pop */
2797 pfile->limit = (unsigned char *) sym; /* Pop */
2798 skip_rest_of_line (pfile);
2803 do_unassert (pfile, keyword)
2805 struct directive *keyword ATTRIBUTE_UNUSED;
2809 long baselen, thislen;
2810 HASHNODE *base, *this, *next;
2812 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
2813 && !CPP_BUFFER (pfile)->system_header_p)
2814 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
2816 cpp_skip_hspace (pfile);
2818 sym = (char *) CPP_PWRITTEN (pfile); /* remember where it starts */
2819 ret = parse_assertion (pfile);
2823 cpp_skip_hspace (pfile);
2825 if (c != EOF && c != '\n')
2826 cpp_error (pfile, "junk at end of `#unassert'");
2828 thislen = strlen (sym);
2831 base = cpp_lookup (pfile, sym, thislen, -1);
2833 goto error; /* It isn't an error to #undef what isn't #defined,
2834 so it isn't an error to #unassert what isn't
2835 #asserted either. */
2837 for (this = base->value.aschain; this; this = next)
2839 next = this->value.aschain;
2840 delete_macro (this);
2842 delete_macro (base);
2846 baselen = index (sym, '(') - sym;
2847 base = cpp_lookup (pfile, sym, baselen, -1);
2848 if (! base) goto error;
2849 this = cpp_lookup (pfile, sym, thislen, -1);
2850 if (! this) goto error;
2853 while (next->value.aschain != this)
2854 next = next->value.aschain;
2856 next->value.aschain = this->value.aschain;
2857 delete_macro (this);
2859 if (base->value.aschain == NULL)
2860 delete_macro (base); /* Last answer for this predicate deleted. */
2863 pfile->limit = (unsigned char *) sym; /* Pop */
2866 pfile->limit = (unsigned char *) sym; /* Pop */
2867 skip_rest_of_line (pfile);
2871 /* Process STR as if it appeared as the body of an #unassert. */
2873 cpp_unassert (pfile, str)
2877 if (cpp_push_buffer (pfile, str, strlen (str)) != NULL)
2879 do_assert (pfile, NULL);
2880 cpp_pop_buffer (pfile);
2885 cpp_read_check_assertion (pfile)
2888 U_CHAR *name = CPP_PWRITTEN (pfile);
2892 FORWARD (1); /* Skip '#' */
2893 cpp_skip_hspace (pfile);
2894 if (! parse_assertion (pfile))
2898 hp = cpp_lookup (pfile, name, CPP_PWRITTEN (pfile) - name, -1);
2902 pfile->limit = name;
2906 /* Remember the current position of PFILE. */
2909 parse_set_mark (pfile)
2912 cpp_buffer *ip = CPP_BUFFER (pfile);
2915 "cpp internal error: ip->mark != -1 in parse_set_mark");
2917 ip->mark = ip->cur - ip->buf;
2920 /* Clear the current mark - we no longer need it. */
2923 parse_clear_mark (pfile)
2926 cpp_buffer *ip = CPP_BUFFER (pfile);
2929 "cpp internal error: ip->mark == -1 in parse_clear_mark");
2934 /* Backup the current position of PFILE to that saved in its mark,
2935 and clear the mark. */
2938 parse_goto_mark (pfile)
2941 cpp_buffer *ip = CPP_BUFFER (pfile);
2944 "cpp internal error: ip->mark == -1 in parse_goto_mark");
2946 ip->cur = ip->buf + ip->mark;
2951 cpp_print_file_and_line (pfile)
2954 cpp_buffer *ip = cpp_file_buffer (pfile);
2959 cpp_buf_line_and_col (ip, &line, &col);
2960 cpp_file_line_for_message (pfile, ip->nominal_fname,
2961 line, pfile->show_column ? col : -1);
2966 v_cpp_error (pfile, msgid, ap)
2971 cpp_print_containing_files (pfile);
2972 cpp_print_file_and_line (pfile);
2973 v_cpp_message (pfile, 1, msgid, ap);
2977 cpp_error VPROTO ((cpp_reader * pfile, const char *msgid, ...))
2979 #ifndef ANSI_PROTOTYPES
2985 VA_START(ap, msgid);
2987 #ifndef ANSI_PROTOTYPES
2988 pfile = va_arg (ap, cpp_reader *);
2989 msgid = va_arg (ap, const char *);
2992 v_cpp_error (pfile, msgid, ap);
2996 /* Print error message but don't count it. */
2999 v_cpp_warning (pfile, msgid, ap)
3004 if (CPP_OPTIONS (pfile)->inhibit_warnings)
3007 if (CPP_OPTIONS (pfile)->warnings_are_errors)
3010 cpp_print_containing_files (pfile);
3011 cpp_print_file_and_line (pfile);
3012 v_cpp_message (pfile, 0, msgid, ap);
3016 cpp_warning VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3018 #ifndef ANSI_PROTOTYPES
3024 VA_START (ap, msgid);
3026 #ifndef ANSI_PROTOTYPES
3027 pfile = va_arg (ap, cpp_reader *);
3028 msgid = va_arg (ap, const char *);
3031 v_cpp_warning (pfile, msgid, ap);
3035 /* Print an error message and maybe count it. */
3038 cpp_pedwarn VPROTO ((cpp_reader * pfile, const char *msgid, ...))
3040 #ifndef ANSI_PROTOTYPES
3046 VA_START (ap, msgid);
3048 #ifndef ANSI_PROTOTYPES
3049 pfile = va_arg (ap, cpp_reader *);
3050 msgid = va_arg (ap, const char *);
3053 if (CPP_OPTIONS (pfile)->pedantic_errors)
3054 v_cpp_error (pfile, msgid, ap);
3056 v_cpp_warning (pfile, msgid, ap);
3061 v_cpp_error_with_line (pfile, line, column, msgid, ap)
3068 cpp_buffer *ip = cpp_file_buffer (pfile);
3070 cpp_print_containing_files (pfile);
3073 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
3075 v_cpp_message (pfile, 1, msgid, ap);
3079 cpp_error_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3080 const char *msgid, ...))
3082 #ifndef ANSI_PROTOTYPES
3090 VA_START (ap, msgid);
3092 #ifndef ANSI_PROTOTYPES
3093 pfile = va_arg (ap, cpp_reader *);
3094 line = va_arg (ap, int);
3095 column = va_arg (ap, int);
3096 msgid = va_arg (ap, const char *);
3099 v_cpp_error_with_line(pfile, line, column, msgid, ap);
3104 v_cpp_warning_with_line (pfile, line, column, msgid, ap)
3113 if (CPP_OPTIONS (pfile)->inhibit_warnings)
3116 if (CPP_OPTIONS (pfile)->warnings_are_errors)
3119 cpp_print_containing_files (pfile);
3121 ip = cpp_file_buffer (pfile);
3124 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
3126 v_cpp_message (pfile, 0, msgid, ap);
3130 cpp_warning_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3131 const char *msgid, ...))
3133 #ifndef ANSI_PROTOTYPES
3141 VA_START (ap, msgid);
3143 #ifndef ANSI_PROTOTYPES
3144 pfile = va_arg (ap, cpp_reader *);
3145 line = va_arg (ap, int);
3146 column = va_arg (ap, int);
3147 msgid = va_arg (ap, const char *);
3150 v_cpp_warning_with_line (pfile, line, column, msgid, ap);
3155 cpp_pedwarn_with_line VPROTO ((cpp_reader * pfile, int line, int column,
3156 const char *msgid, ...))
3158 #ifndef ANSI_PROTOTYPES
3166 VA_START (ap, msgid);
3168 #ifndef ANSI_PROTOTYPES
3169 pfile = va_arg (ap, cpp_reader *);
3170 line = va_arg (ap, int);
3171 column = va_arg (ap, int);
3172 msgid = va_arg (ap, const char *);
3175 if (CPP_OPTIONS (pfile)->pedantic_errors)
3176 v_cpp_error_with_line (pfile, column, line, msgid, ap);
3178 v_cpp_warning_with_line (pfile, line, column, msgid, ap);
3182 /* Report a warning (or an error if pedantic_errors)
3183 giving specified file name and line number, not current. */
3186 cpp_pedwarn_with_file_and_line VPROTO ((cpp_reader *pfile, char *file, int line,
3187 const char *msgid, ...))
3189 #ifndef ANSI_PROTOTYPES
3197 VA_START (ap, msgid);
3199 #ifndef ANSI_PROTOTYPES
3200 pfile = va_arg (ap, cpp_reader *);
3201 file = va_arg (ap, char *);
3202 line = va_arg (ap, int);
3203 msgid = va_arg (ap, const char *);
3206 if (!CPP_OPTIONS (pfile)->pedantic_errors
3207 && CPP_OPTIONS (pfile)->inhibit_warnings)
3210 cpp_file_line_for_message (pfile, file, line, -1);
3211 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msgid, ap);
3215 /* my_strerror - return the descriptive text associated with an
3219 my_strerror (errnum)
3225 #ifndef HAVE_STRERROR
3226 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
3228 result = strerror (errnum);
3231 /* VAXCRTL's strerror() takes an optional second argument, which only
3232 matters when the first argument is EVMSERR. However, it's simplest
3233 just to pass it unconditionally. `vaxc$errno' is declared in
3234 <errno.h>, and maintained by the library in parallel with `errno'.
3235 We assume that caller's `errnum' either matches the last setting of
3236 `errno' by the library or else does not have the value `EVMSERR'. */
3238 result = strerror (errnum, vaxc$errno);
3242 result = "errno = ?";
3247 /* Error including a message from `errno'. */
3250 cpp_error_from_errno (pfile, name)
3254 cpp_message_from_errno (pfile, 1, name);
3258 cpp_message_from_errno (pfile, is_error, name)
3264 cpp_buffer *ip = cpp_file_buffer (pfile);
3266 cpp_print_containing_files (pfile);
3269 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
3271 cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
3275 cpp_perror_with_name (pfile, name)
3279 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
3283 * No pre-compiled header file support.
3285 * Possibly different enum token codes for each C/C++ token.
3287 * Find and cleanup remaining uses of static variables,
3289 * Support -dM flag (dump_all_macros).
3291 * Support for_lint flag.