2 Copyright (C) 1986, 87, 89, 92-97, 1998 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. */
30 #ifdef HAVE_SYS_TIMES_H
31 #include <sys/times.h>
34 #ifdef HAVE_SYS_RESOURCE_H
35 # include <sys/resource.h>
42 #ifndef GET_ENV_PATH_LIST
43 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
46 extern char *update_path PARAMS ((char *, char *));
48 /* By default, colon separates directories in a path. */
49 #ifndef PATH_SEPARATOR
50 #define PATH_SEPARATOR ':'
53 #ifndef STANDARD_INCLUDE_DIR
54 #define STANDARD_INCLUDE_DIR "/usr/include"
57 /* Symbols to predefine. */
60 static char *predefs = CPP_PREDEFINES;
62 static char *predefs = "";
65 /* We let tm.h override the types used here, to handle trivial differences
66 such as the choice of unsigned int or long unsigned int for size_t.
67 When machines start needing nontrivial differences in the size type,
68 it would be best to do something here to figure out automatically
69 from other information what type to use. */
71 /* The string value for __SIZE_TYPE__. */
74 #define SIZE_TYPE "long unsigned int"
77 /* The string value for __PTRDIFF_TYPE__. */
80 #define PTRDIFF_TYPE "long int"
83 /* The string value for __WCHAR_TYPE__. */
86 #define WCHAR_TYPE "int"
88 #define CPP_WCHAR_TYPE(PFILE) \
89 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
91 /* The string value for __USER_LABEL_PREFIX__ */
93 #ifndef USER_LABEL_PREFIX
94 #define USER_LABEL_PREFIX ""
97 /* The string value for __REGISTER_PREFIX__ */
99 #ifndef REGISTER_PREFIX
100 #define REGISTER_PREFIX ""
103 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
104 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
106 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
107 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
108 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
109 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
110 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
111 (Note that it is false while we're expanding marco *arguments*.) */
112 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
114 /* Move all backslash-newline pairs out of embarrassing places.
115 Exchange all such pairs following BP
116 with any potentially-embarrassing characters that follow them.
117 Potentially-embarrassing characters are / and *
118 (because a backslash-newline inside a comment delimiter
119 would cause it not to be recognized). */
121 #define NEWLINE_FIX \
122 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
124 /* Same, but assume we've already read the potential '\\' into C. */
125 #define NEWLINE_FIX1(C) do { \
126 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
130 struct cpp_pending *next;
135 /* Forward declarations. */
137 extern void cpp_hash_cleanup PARAMS ((cpp_reader *));
139 static char *my_strerror PROTO ((int));
140 static void make_assertion PROTO ((cpp_reader *, char *, U_CHAR *));
141 static void path_include PROTO ((cpp_reader *, char *));
142 static void initialize_builtins PROTO ((cpp_reader *));
143 static void initialize_char_syntax PROTO ((void));
145 static void trigraph_pcp ();
147 static void validate_else PROTO ((cpp_reader *, char *));
148 static int comp_def_part PROTO ((int, U_CHAR *, int, U_CHAR *,
151 extern void fancy_abort ();
153 static int check_macro_name PROTO ((cpp_reader *, U_CHAR *, char *));
154 static int compare_defs PROTO ((cpp_reader *,
155 DEFINITION *, DEFINITION *));
156 static HOST_WIDE_INT eval_if_expression PROTO ((cpp_reader *));
157 static int change_newlines PROTO ((U_CHAR *, int));
158 static void push_macro_expansion PARAMS ((cpp_reader *,
159 U_CHAR *, int, HASHNODE *));
160 static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
162 static void conditional_skip PROTO ((cpp_reader *, int,
163 enum node_type, U_CHAR *));
164 static void skip_if_group PROTO ((cpp_reader *));
165 static int parse_name PARAMS ((cpp_reader *, int));
166 static void print_help PROTO ((void));
168 /* Last arg to output_line_command. */
169 enum file_change_code {same_file, enter_file, leave_file};
171 /* External declarations. */
173 extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader *));
175 extern char *version_string;
176 extern struct tm *localtime ();
179 /* #include "file" looks in source file dir, then stack. */
180 /* #include <file> just looks in the stack. */
181 /* -I directories are added to the end, then the defaults are added. */
183 static struct default_include {
184 char *fname; /* The name of the directory. */
185 char *component; /* The component containing the directory */
186 int cplusplus; /* Only look here if we're compiling C++. */
187 int cxx_aware; /* Includes in this directory don't need to
188 be wrapped in extern "C" when compiling
190 } include_defaults_array[]
191 #ifdef INCLUDE_DEFAULTS
195 /* Pick up GNU C++ specific include files. */
196 { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
198 /* This is the dir for fixincludes. Put it just before
199 the files that we fix. */
200 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
201 /* For cross-compilation, this dir name is generated
202 automatically in Makefile.in. */
203 { CROSS_INCLUDE_DIR, "GCC",0, 0 },
204 #ifdef TOOL_INCLUDE_DIR
205 /* This is another place that the target system's headers might be. */
206 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
208 #else /* not CROSS_COMPILE */
209 #ifdef LOCAL_INCLUDE_DIR
210 /* This should be /usr/local/include and should come before
211 the fixincludes-fixed header files. */
212 { LOCAL_INCLUDE_DIR, 0, 0, 1 },
214 #ifdef TOOL_INCLUDE_DIR
215 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
216 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
217 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
219 /* This is the dir for fixincludes. Put it just before
220 the files that we fix. */
221 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
222 /* Some systems have an extra dir of include files. */
223 #ifdef SYSTEM_INCLUDE_DIR
224 { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
226 #ifndef STANDARD_INCLUDE_COMPONENT
227 #define STANDARD_INCLUDE_COMPONENT 0
229 { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
230 #endif /* not CROSS_COMPILE */
233 #endif /* no INCLUDE_DEFAULTS */
235 /* `struct directive' defines one #-directive, including how to handle it. */
238 int length; /* Length of name */
239 int (*func) /* Function to handle directive */
240 PARAMS ((cpp_reader *, struct directive *));
241 char *name; /* Name of directive */
242 enum node_type type; /* Code which describes which directive. */
245 /* These functions are declared to return int instead of void since they
246 are going to be placed in a table and some old compilers have trouble with
247 pointers to functions returning void. */
249 static int do_define PARAMS ((cpp_reader *, struct directive *));
250 static int do_line PARAMS ((cpp_reader *, struct directive *));
251 static int do_include PARAMS ((cpp_reader *, struct directive *));
252 static int do_undef PARAMS ((cpp_reader *, struct directive *));
253 static int do_error PARAMS ((cpp_reader *, struct directive *));
254 static int do_pragma PARAMS ((cpp_reader *, struct directive *));
255 static int do_ident PARAMS ((cpp_reader *, struct directive *));
256 static int do_if PARAMS ((cpp_reader *, struct directive *));
257 static int do_xifdef PARAMS ((cpp_reader *, struct directive *));
258 static int do_else PARAMS ((cpp_reader *, struct directive *));
259 static int do_elif PARAMS ((cpp_reader *, struct directive *));
260 static int do_endif PARAMS ((cpp_reader *, struct directive *));
261 #ifdef SCCS_DIRECTIVE
262 static int do_sccs PARAMS ((cpp_reader *, struct directive *));
264 static int do_assert PARAMS ((cpp_reader *, struct directive *));
265 static int do_unassert PARAMS ((cpp_reader *, struct directive *));
266 static int do_warning PARAMS ((cpp_reader *, struct directive *));
268 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
269 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
271 /* Here is the actual list of #-directives, most-often-used first.
272 The initialize_builtins function assumes #define is the very first. */
274 static struct directive directive_table[] = {
275 { 6, do_define, "define", T_DEFINE },
276 { 5, do_xifdef, "ifdef", T_IFDEF },
277 { 6, do_xifdef, "ifndef", T_IFNDEF },
278 { 7, do_include, "include", T_INCLUDE },
279 { 12, do_include, "include_next", T_INCLUDE_NEXT },
280 { 6, do_include, "import", T_IMPORT },
281 { 5, do_endif, "endif", T_ENDIF },
282 { 4, do_else, "else", T_ELSE },
283 { 2, do_if, "if", T_IF },
284 { 4, do_elif, "elif", T_ELIF },
285 { 5, do_undef, "undef", T_UNDEF },
286 { 5, do_error, "error", T_ERROR },
287 { 7, do_warning, "warning", T_WARNING },
288 { 6, do_pragma, "pragma", T_PRAGMA },
289 { 4, do_line, "line", T_LINE },
290 { 5, do_ident, "ident", T_IDENT },
291 #ifdef SCCS_DIRECTIVE
292 { 4, do_sccs, "sccs", T_SCCS },
294 { 6, do_assert, "assert", T_ASSERT },
295 { 8, do_unassert, "unassert", T_UNASSERT },
296 { -1, 0, "", T_UNUSED }
299 /* table to tell if char can be part of a C identifier. */
300 U_CHAR is_idchar[256] = { 0 };
301 /* table to tell if char can be first char of a c identifier. */
302 U_CHAR is_idstart[256] = { 0 };
303 /* table to tell if c is horizontal space. */
304 U_CHAR is_hor_space[256] = { 0 };
305 /* table to tell if c is horizontal or vertical space. */
306 U_CHAR is_space[256] = { 0 };
308 /* Initialize syntactic classifications of characters. */
310 initialize_char_syntax ()
315 * Set up is_idchar and is_idstart tables. These should be
316 * faster than saying (is_alpha (c) || c == '_'), etc.
317 * Set up these things before calling any routines tthat
319 * XXX We should setlocale(LC_CTYPE, "C") here for safety.
321 for (i = 0; i < 256; i++)
323 is_idchar[i] = ISALNUM (i);
324 is_idstart[i] = ISALPHA (i);
330 /* These will be reset later if -$ is in effect. */
334 /* horizontal space table */
335 is_hor_space[' '] = 1;
336 is_hor_space['\t'] = 1;
337 is_hor_space['\v'] = 1;
338 is_hor_space['\f'] = 1;
339 is_hor_space['\r'] = 1;
350 /* Place into PFILE a quoted string representing the string SRC.
351 Caller must reserve enough space in pfile->token_buffer. */
354 quote_string (pfile, src)
360 CPP_PUTC_Q (pfile, '\"');
362 switch ((c = *src++))
366 CPP_PUTC_Q (pfile, c);
369 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
370 CPP_ADJUST_WRITTEN (pfile, 4);
376 CPP_PUTC_Q (pfile, '\\');
377 CPP_PUTC_Q (pfile, c);
381 CPP_PUTC_Q (pfile, '\"');
382 CPP_NUL_TERMINATE_Q (pfile);
387 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
390 cpp_grow_buffer (pfile, n)
394 long old_written = CPP_WRITTEN (pfile);
395 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
396 pfile->token_buffer = (U_CHAR *)
397 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
398 CPP_SET_WRITTEN (pfile, old_written);
403 * process a given definition string, for initialization
404 * If STR is just an identifier, define it with value 1.
405 * If STR has anything after the identifier, then it should
406 * be identifier=definition.
410 cpp_define (pfile, str)
420 cpp_error (pfile, "malformed option `-D %s'", str);
423 while (is_idchar[*++p])
426 while (is_idchar[*++p] || *p == ',' || is_hor_space[*p])
429 p = (U_CHAR *) str; /* Error */
433 buf = (U_CHAR *) alloca (p - buf + 4);
434 strcpy ((char *)buf, str);
435 strcat ((char *)buf, " 1");
439 cpp_error (pfile, "malformed option `-D %s'", str);
445 /* Copy the entire option so we can modify it. */
446 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
447 strncpy (buf, str, p - str);
448 /* Change the = to a space. */
450 /* Scan for any backslash-newline and remove it. */
455 if (*p == '\\' && p[1] == '\n')
463 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
465 do_define (pfile, NULL);
466 cpp_pop_buffer (pfile);
470 /* Process the string STR as if it appeared as the body of a #assert.
471 OPTION is the option name for which STR was the argument. */
474 make_assertion (pfile, option, str)
481 /* Copy the entire option so we can modify it. */
482 buf = (U_CHAR *) alloca (strlen (str) + 1);
483 strcpy ((char *) buf, str);
484 /* Scan for any backslash-newline and remove it. */
488 if (*p == '\\' && p[1] == '\n')
497 if (!is_idstart[*p]) {
498 cpp_error (pfile, "malformed option `%s %s'", option, str);
501 while (is_idchar[*++p])
503 while (*p == ' ' || *p == '\t') p++;
504 if (! (*p == 0 || *p == '(')) {
505 cpp_error (pfile, "malformed option `%s %s'", option, str);
509 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
511 do_assert (pfile, NULL);
512 cpp_pop_buffer (pfile);
516 /* Given a colon-separated list of file names PATH,
517 add all the names to the search path for include files. */
520 path_include (pfile, path)
533 /* Find the end of this name. */
534 while (*q != 0 && *q != PATH_SEPARATOR) q++;
536 /* An empty name in the path stands for the current directory. */
537 name = (char *) xmalloc (2);
541 /* Otherwise use the directory that is named. */
542 name = (char *) xmalloc (q - p + 1);
543 bcopy (p, name, q - p);
547 append_include_chain (pfile,
548 &(CPP_OPTIONS (pfile)->bracket_include), name, 0);
550 /* Advance past this name. */
554 /* Skip the colon. */
560 cpp_options_init (opts)
563 bzero ((char *) opts, sizeof *opts);
564 opts->in_fname = NULL;
565 opts->out_fname = NULL;
567 opts->dollars_in_ident = 1;
568 initialize_char_syntax ();
570 opts->no_line_commands = 0;
571 opts->no_trigraphs = 1;
572 opts->put_out_comments = 0;
573 opts->print_include_names = 0;
574 opts->dump_macros = dump_none;
578 opts->cplusplus_comments = 1;
585 opts->pedantic_errors = 0;
586 opts->inhibit_warnings = 0;
587 opts->warn_comments = 0;
588 opts->warn_import = 1;
589 opts->warnings_are_errors = 0;
593 null_underflow (pfile)
594 cpp_reader *pfile ATTRIBUTE_UNUSED;
600 null_cleanup (pbuf, pfile)
601 cpp_buffer *pbuf ATTRIBUTE_UNUSED;
602 cpp_reader *pfile ATTRIBUTE_UNUSED;
608 macro_cleanup (pbuf, pfile)
610 cpp_reader *pfile ATTRIBUTE_UNUSED;
612 HASHNODE *macro = (HASHNODE *) pbuf->data;
613 if (macro->type == T_DISABLED)
614 macro->type = T_MACRO;
615 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
620 /* Assuming we have read '/'.
621 If this is the start of a comment (followed by '*' or '/'),
622 skip to the end of the comment, and return ' '.
623 Return EOF if we reached the end of file before the end of the comment.
624 If not the start of a comment, return '/'. */
627 skip_comment (pfile, linep)
632 while (PEEKC() == '\\' && PEEKN(1) == '\n')
647 while (c == '\\' && PEEKC() == '\n')
651 FORWARD(1), c = GETC();
653 if (prev_c == '*' && c == '/')
655 if (c == '\n' && linep)
659 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
666 return ' '; /* Allow // to be terminated by EOF. */
667 while (c == '\\' && PEEKC() == '\n')
676 /* Don't consider final '\n' to be part of comment. */
686 /* Skip whitespace \-newline and comments. Does not macro-expand. */
689 cpp_skip_hspace (pfile)
699 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
700 cpp_pedwarn (pfile, "%s in preprocessing directive",
701 c == '\f' ? "formfeed" : "vertical tab");
707 c = skip_comment (pfile, NULL);
710 if (c == EOF || c == '/')
713 else if (c == '\\' && PEEKN(1) == '\n') {
716 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
717 && is_hor_space[PEEKN(1)])
723 /* Read the rest of the current line.
724 The line is appended to PFILE's output buffer. */
727 copy_rest_of_line (pfile)
730 struct cpp_options *opts = CPP_OPTIONS (pfile);
747 goto scan_directive_token;
751 if (nextc == '*' || (opts->cplusplus_comments && nextc == '/'))
752 goto scan_directive_token;
756 if (CPP_PEDANTIC (pfile))
757 cpp_pedwarn (pfile, "%s in preprocessing directive",
758 c == '\f' ? "formfeed" : "vertical tab");
764 scan_directive_token:
766 cpp_get_token (pfile);
772 CPP_NUL_TERMINATE (pfile);
776 skip_rest_of_line (pfile)
779 long old = CPP_WRITTEN (pfile);
780 copy_rest_of_line (pfile);
781 CPP_SET_WRITTEN (pfile, old);
784 /* Handle a possible # directive.
785 '#' has already been read. */
788 handle_directive (pfile)
791 register struct directive *kt;
794 long old_written = CPP_WRITTEN (pfile);
796 cpp_skip_hspace (pfile);
799 if (c >= '0' && c <= '9')
801 /* Handle # followed by a line number. */
802 if (CPP_PEDANTIC (pfile))
803 cpp_pedwarn (pfile, "`#' followed by integer");
804 do_line (pfile, NULL);
805 goto done_a_directive;
808 /* Now find the directive name. */
809 CPP_PUTC (pfile, '#');
810 parse_name (pfile, GETC());
811 ident = pfile->token_buffer + old_written + 1;
812 ident_length = CPP_PWRITTEN (pfile) - ident;
813 if (ident_length == 0 && PEEKC() == '\n')
815 /* A line of just `#' becomes blank. */
816 goto done_a_directive;
820 if (ident_length == 0 || !is_idstart[*ident]) {
822 while (is_idchar[*p]) {
823 if (*p < '0' || *p > '9')
827 /* Avoid error for `###' and similar cases unless -pedantic. */
829 while (*p == '#' || is_hor_space[*p]) p++;
831 if (pedantic && !lang_asm)
832 cpp_warning (pfile, "invalid preprocessor directive");
838 cpp_error (pfile, "invalid preprocessor directive name");
844 * Decode the keyword and call the appropriate expansion
845 * routine, after moving the input pointer up to the next line.
847 for (kt = directive_table; ; kt++) {
849 goto not_a_directive;
850 if (kt->length == ident_length
851 && !strncmp (kt->name, ident, ident_length))
855 /* We may want to pass through #define, #pragma, and #include.
856 Other directives may create output, but we don't want the directive
857 itself out, so we pop it now. For example conditionals may emit
858 #failed ... #endfailed stuff. */
860 if (! (kt->type == T_DEFINE
861 || kt->type == T_PRAGMA
862 || (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)
863 && CPP_OPTIONS (pfile)->dump_includes)))
864 CPP_SET_WRITTEN (pfile, old_written);
866 (*kt->func) (pfile, kt);
868 if (kt->type == T_DEFINE)
870 if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
872 /* Skip "#define". */
873 U_CHAR *p = pfile->token_buffer + old_written + 7;
875 SKIP_WHITE_SPACE (p);
876 while (is_idchar[*p]) p++;
878 CPP_PUTC (pfile, '\n');
880 else if (CPP_OPTIONS (pfile)->dump_macros != dump_definitions)
881 CPP_SET_WRITTEN (pfile, old_written);
891 /* Pass a directive through to the output file.
892 BUF points to the contents of the directive, as a contiguous string.
893 m LIMIT points to the first character past the end of the directive.
894 KEYWORD is the keyword-table entry for the directive. */
897 pass_thru_directive (buf, limit, pfile, keyword)
900 struct directive *keyword;
902 register unsigned keyword_length = keyword->length;
904 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
905 CPP_PUTC_Q (pfile, '#');
906 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
907 if (limit != buf && buf[0] != ' ')
908 CPP_PUTC_Q (pfile, ' ');
909 CPP_PUTS_Q (pfile, buf, limit - buf);
911 CPP_PUTS_Q (pfile, '\n');
912 /* Count the line we have just made in the output,
913 to get in sync properly. */
918 /* The arglist structure is built by do_define to tell
919 collect_definition where the argument names begin. That
920 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
921 would contain pointers to the strings x, y, and z.
922 Collect_definition would then build a DEFINITION node,
923 with reflist nodes pointing to the places x, y, and z had
924 appeared. So the arglist is just convenience data passed
925 between these two routines. It is not kept around after
926 the current #define has been processed and entered into the
930 struct arglist *next;
937 /* Read a replacement list for a macro with parameters.
938 Build the DEFINITION structure.
939 Reads characters of text starting at BUF until END.
940 ARGLIST specifies the formal parameters to look for
941 in the text of the definition; NARGS is the number of args
942 in that list, or -1 for a macro name that wants no argument list.
943 MACRONAME is the macro name itself (so we can avoid recursive expansion)
944 and NAMELEN is its length in characters.
946 Note that comments, backslash-newlines, and leading white space
947 have already been deleted from the argument. */
950 collect_expansion (pfile, buf, limit, nargs, arglist)
954 struct arglist *arglist;
957 register U_CHAR *p, *lastp, *exp_p;
958 struct reflist *endpat = NULL;
959 /* Pointer to first nonspace after last ## seen. */
961 /* Pointer to first nonspace after last single-# seen. */
962 U_CHAR *stringify = 0;
964 int expected_delimiter = '\0';
966 /* Scan thru the replacement list, ignoring comments and quoted
967 strings, picking up on the macro calls. It does a linear search
968 thru the arg list on every potential symbol. Profiling might say
969 that something smarter should happen. */
974 /* Find the beginning of the trailing whitespace. */
976 while (p < limit && is_space[limit[-1]]) limit--;
978 /* Allocate space for the text in the macro definition.
979 Leading and trailing whitespace chars need 2 bytes each.
980 Each other input char may or may not need 1 byte,
981 so this is an upper bound. The extra 5 are for invented
982 leading and trailing newline-marker and final null. */
983 maxsize = (sizeof (DEFINITION)
985 /* Occurrences of '@' get doubled, so allocate extra space for them. */
989 defn = (DEFINITION *) xcalloc (1, maxsize);
992 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
997 /* Add one initial space escape-marker to prevent accidental
998 token-pasting (often removed by macroexpand). */
1002 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1003 cpp_error (pfile, "`##' at start of macro definition");
1007 /* Process the main body of the definition. */
1009 int skipped_arg = 0;
1010 register U_CHAR c = *p++;
1014 if (!CPP_TRADITIONAL (pfile)) {
1018 if (expected_delimiter != '\0') {
1019 if (c == expected_delimiter)
1020 expected_delimiter = '\0';
1022 expected_delimiter = c;
1026 if (p < limit && expected_delimiter) {
1027 /* In a string, backslash goes through
1028 and makes next char ordinary. */
1034 /* An '@' in a string or character constant stands for itself,
1035 and does not need to be escaped. */
1036 if (!expected_delimiter)
1041 /* # is ordinary inside a string. */
1042 if (expected_delimiter)
1044 if (p < limit && *p == '#') {
1045 /* ##: concatenate preceding and following tokens. */
1046 /* Take out the first #, discard preceding whitespace. */
1048 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1050 /* Skip the second #. */
1052 /* Discard following whitespace. */
1053 SKIP_WHITE_SPACE (p);
1056 cpp_error (pfile, "`##' at end of macro definition");
1057 } else if (nargs >= 0) {
1058 /* Single #: stringify following argument ref.
1059 Don't leave the # in the expansion. */
1061 SKIP_WHITE_SPACE (p);
1062 if (p == limit || ! is_idstart[*p]
1063 || (*p == 'L' && p + 1 < limit && (p[1] == '\'' || p[1] == '"')))
1065 "`#' operator is not followed by a macro argument name");
1072 /* In -traditional mode, recognize arguments inside strings and
1073 character constants, and ignore special properties of #.
1074 Arguments inside strings are considered "stringified", but no
1075 extra quote marks are supplied. */
1079 if (expected_delimiter != '\0') {
1080 if (c == expected_delimiter)
1081 expected_delimiter = '\0';
1083 expected_delimiter = c;
1087 /* Backslash quotes delimiters and itself, but not macro args. */
1088 if (expected_delimiter != 0 && p < limit
1089 && (*p == expected_delimiter || *p == '\\')) {
1096 if (expected_delimiter != '\0') /* No comments inside strings. */
1099 /* If we find a comment that wasn't removed by handle_directive,
1100 this must be -traditional. So replace the comment with
1104 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1107 /* Mark this as a concatenation-point, as if it had been ##. */
1115 /* Handle the start of a symbol. */
1116 if (is_idchar[c] && nargs > 0) {
1117 U_CHAR *id_beg = p - 1;
1121 while (p != limit && is_idchar[*p]) p++;
1122 id_len = p - id_beg;
1125 && ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '"'))) {
1126 register struct arglist *arg;
1128 for (arg = arglist; arg != NULL; arg = arg->next) {
1129 struct reflist *tpat;
1131 if (arg->name[0] == c
1132 && arg->length == id_len
1133 && strncmp (arg->name, id_beg, id_len) == 0) {
1134 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1135 if (CPP_TRADITIONAL (pfile)) {
1136 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1140 "macro arg `%.*s' would be stringified with -traditional.",
1144 /* If ANSI, don't actually substitute inside a string. */
1145 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1147 /* make a pat node for this arg and append it to the end of
1149 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1151 tpat->raw_before = concat == id_beg;
1152 tpat->raw_after = 0;
1153 tpat->rest_args = arg->rest_args;
1154 tpat->stringify = (CPP_TRADITIONAL (pfile)
1155 ? expected_delimiter != '\0'
1156 : stringify == id_beg);
1159 defn->pattern = tpat;
1161 endpat->next = tpat;
1164 tpat->argno = arg->argno;
1165 tpat->nchars = exp_p - lastp;
1167 register U_CHAR *p1 = p;
1168 SKIP_WHITE_SPACE (p1);
1169 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1170 tpat->raw_after = 1;
1172 lastp = exp_p; /* place to start copying from next time */
1179 /* If this was not a macro arg, copy it into the expansion. */
1180 if (! skipped_arg) {
1181 register U_CHAR *lim1 = p;
1185 if (stringify == id_beg)
1187 "`#' operator should be followed by a macro argument name");
1192 if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0)
1194 /* If ANSI, put in a "@ " marker to prevent token pasting.
1195 But not if "inside a string" (which in ANSI mode
1196 happens only for -D option). */
1203 defn->length = exp_p - defn->expansion;
1205 /* Crash now if we overrun the allocated size. */
1206 if (defn->length + 1 > maxsize)
1210 /* This isn't worth the time it takes. */
1211 /* give back excess storage */
1212 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1219 * special extension string that can be added to the last macro argument to
1220 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1221 * #define wow(a, b...) process (b, a, b)
1222 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1223 * { wow (one, two); } -> { process (two, one, two); }
1224 * if this "rest_arg" is used with the concat token '##' and if it is not
1225 * supplied then the token attached to with ## will not be outputted. Ex:
1226 * #define wow (a, b...) process (b ## , a, ## b)
1227 * { wow (1, 2); } -> { process (2, 1, 2); }
1228 * { wow (one); } -> { process (one); {
1230 static char rest_extension[] = "...";
1231 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1233 /* Create a DEFINITION node from a #define directive. Arguments are
1234 as for do_define. */
1237 create_definition (buf, limit, pfile, predefinition)
1238 U_CHAR *buf, *limit;
1242 U_CHAR *bp; /* temp ptr into input buffer */
1243 U_CHAR *symname; /* remember where symbol name starts */
1244 int sym_length; /* and how long it is */
1247 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1249 int arglengths = 0; /* Accumulate lengths of arg names
1250 plus number of args. */
1252 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1256 while (is_hor_space[*bp])
1259 symname = bp; /* remember where it starts */
1261 sym_length = check_macro_name (pfile, bp, "macro");
1264 /* Lossage will occur if identifiers or control keywords are broken
1265 across lines using backslash. This is not the right place to take
1269 struct arglist *arg_ptrs = NULL;
1272 bp++; /* skip '(' */
1273 SKIP_WHITE_SPACE (bp);
1275 /* Loop over macro argument names. */
1276 while (*bp != ')') {
1277 struct arglist *temp;
1279 temp = (struct arglist *) alloca (sizeof (struct arglist));
1281 temp->next = arg_ptrs;
1282 temp->argno = argno++;
1283 temp->rest_args = 0;
1287 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1289 if (!is_idstart[*bp])
1290 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1292 /* Find the end of the arg name. */
1293 while (is_idchar[*bp]) {
1295 /* do we have a "special" rest-args extension here? */
1296 if ((size_t)(limit - bp) > REST_EXTENSION_LENGTH
1297 && strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1299 temp->rest_args = 1;
1303 temp->length = bp - temp->name;
1305 bp += REST_EXTENSION_LENGTH;
1306 arglengths += temp->length + 2;
1307 SKIP_WHITE_SPACE (bp);
1308 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1309 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1314 SKIP_WHITE_SPACE (bp);
1317 cpp_error (pfile, "unterminated parameter list in `#define'");
1321 struct arglist *otemp;
1323 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1324 if (temp->length == otemp->length
1325 && strncmp (temp->name, otemp->name, temp->length) == 0) {
1328 name = (U_CHAR *) alloca (temp->length + 1);
1329 (void) strncpy (name, temp->name, temp->length);
1330 name[temp->length] = '\0';
1332 "duplicate argument name `%s' in `#define'", name);
1338 ++bp; /* skip paren */
1339 SKIP_WHITE_SPACE (bp);
1340 /* now everything from bp before limit is the definition. */
1341 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1342 defn->rest_args = rest_args;
1344 /* Now set defn->args.argnames to the result of concatenating
1345 the argument names in reverse order
1346 with comma-space between them. */
1347 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1349 struct arglist *temp;
1351 for (temp = arg_ptrs; temp; temp = temp->next) {
1352 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1354 if (temp->next != 0) {
1355 defn->args.argnames[i++] = ',';
1356 defn->args.argnames[i++] = ' ';
1359 defn->args.argnames[i] = 0;
1362 /* Simple expansion or empty definition. */
1366 if (is_hor_space[*bp]) {
1368 SKIP_WHITE_SPACE (bp);
1371 case '!': case '"': case '#': case '%': case '&': case '\'':
1372 case ')': case '*': case '+': case ',': case '-': case '.':
1373 case '/': case ':': case ';': case '<': case '=': case '>':
1374 case '?': case '[': case '\\': case ']': case '^': case '{':
1375 case '|': case '}': case '~':
1376 cpp_warning (pfile, "missing white space after `#define %.*s'",
1377 sym_length, symname);
1381 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1382 sym_length, symname);
1387 /* now everything from bp before limit is the definition. */
1388 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1389 defn->args.argnames = (U_CHAR *) "";
1395 /* OP is null if this is a predefinition */
1396 defn->predefined = predefinition;
1398 mdef.symnam = symname;
1399 mdef.symlen = sym_length;
1408 /* Check a purported macro name SYMNAME, and yield its length.
1409 USAGE is the kind of name this is intended for. */
1412 check_macro_name (pfile, symname, usage)
1420 for (p = symname; is_idchar[*p]; p++)
1422 sym_length = p - symname;
1424 || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
1425 cpp_error (pfile, "invalid %s name", usage);
1426 else if (!is_idstart[*symname]) {
1427 U_CHAR *msg; /* what pain... */
1428 msg = (U_CHAR *) alloca (sym_length + 1);
1429 bcopy (symname, msg, sym_length);
1430 msg[sym_length] = 0;
1431 cpp_error (pfile, "invalid %s name `%s'", usage, msg);
1433 if (! strncmp (symname, "defined", 7) && sym_length == 7)
1434 cpp_error (pfile, "invalid %s name `defined'", usage);
1439 /* Return zero if two DEFINITIONs are isomorphic. */
1442 compare_defs (pfile, d1, d2)
1444 DEFINITION *d1, *d2;
1446 register struct reflist *a1, *a2;
1447 register U_CHAR *p1 = d1->expansion;
1448 register U_CHAR *p2 = d2->expansion;
1451 if (d1->nargs != d2->nargs)
1453 if (CPP_PEDANTIC (pfile)
1454 && strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1456 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1457 a1 = a1->next, a2 = a2->next) {
1458 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1459 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1460 || a1->argno != a2->argno
1461 || a1->stringify != a2->stringify
1462 || a1->raw_before != a2->raw_before
1463 || a1->raw_after != a2->raw_after)
1471 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1472 p2, d2->length - (p2 - d2->expansion), 1))
1477 /* Return 1 if two parts of two macro definitions are effectively different.
1478 One of the parts starts at BEG1 and has LEN1 chars;
1479 the other has LEN2 chars at BEG2.
1480 Any sequence of whitespace matches any other sequence of whitespace.
1481 FIRST means these parts are the first of a macro definition;
1482 so ignore leading whitespace entirely.
1483 LAST means these parts are the last of a macro definition;
1484 so ignore trailing whitespace entirely. */
1487 comp_def_part (first, beg1, len1, beg2, len2, last)
1489 U_CHAR *beg1, *beg2;
1493 register U_CHAR *end1 = beg1 + len1;
1494 register U_CHAR *end2 = beg2 + len2;
1496 while (beg1 != end1 && is_space[*beg1]) beg1++;
1497 while (beg2 != end2 && is_space[*beg2]) beg2++;
1500 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1501 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1503 while (beg1 != end1 && beg2 != end2) {
1504 if (is_space[*beg1] && is_space[*beg2]) {
1505 while (beg1 != end1 && is_space[*beg1]) beg1++;
1506 while (beg2 != end2 && is_space[*beg2]) beg2++;
1507 } else if (*beg1 == *beg2) {
1511 return (beg1 != end1) || (beg2 != end2);
1514 /* Process a #define command.
1515 KEYWORD is the keyword-table entry for #define,
1516 or NULL for a "predefined" macro. */
1519 do_define (pfile, keyword)
1521 struct directive *keyword;
1526 int save_put_out_comments;
1528 U_CHAR *macro, *buf, *end;
1530 here = CPP_WRITTEN (pfile);
1532 save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1533 CPP_OPTIONS (pfile)->put_out_comments = CPP_TRADITIONAL (pfile);
1534 copy_rest_of_line (pfile);
1535 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1537 /* Copy out the line so we can pop the token buffer. */
1538 buf = pfile->token_buffer + here;
1539 end = CPP_PWRITTEN (pfile);
1540 macro = alloca (end - buf + 1);
1541 bcopy (buf, macro, end - buf + 1);
1542 end = macro + (end - buf);
1544 CPP_SET_WRITTEN (pfile, here);
1547 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1548 if (pcp_outfile && keyword)
1549 pass_thru_directive (macro, end, pfile, keyword);
1552 mdef = create_definition (macro, end, pfile, keyword == NULL);
1556 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
1558 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
1561 /* Redefining a precompiled key is ok. */
1562 if (hp->type == T_PCSTRING)
1564 /* Redefining a macro is ok if the definitions are the same. */
1565 else if (hp->type == T_MACRO)
1566 ok = ! compare_defs (pfile, mdef.defn, hp->value.defn);
1567 /* Redefining a constant is ok with -D. */
1568 else if (hp->type == T_CONST)
1569 ok = ! CPP_OPTIONS (pfile)->done_initializing;
1570 /* Print the warning if it's not ok. */
1573 U_CHAR *msg; /* what pain... */
1575 /* If we are passing through #define and #undef directives, do
1576 that for this re-definition now. */
1577 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1578 pass_thru_directive (macro, end, pfile, keyword);
1580 msg = (U_CHAR *) alloca (mdef.symlen + 22);
1582 bcopy (mdef.symnam, msg + 1, mdef.symlen);
1583 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
1584 cpp_pedwarn (pfile, msg);
1585 if (hp->type == T_MACRO)
1586 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1587 "this is the location of the previous definition");
1589 /* Replace the old definition. */
1591 hp->value.defn = mdef.defn;
1595 /* If we are passing through #define and #undef directives, do
1596 that for this new definition now. */
1597 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1598 pass_thru_directive (macro, end, pfile, keyword);
1599 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1600 (char *) mdef.defn, hashcode);
1610 /* This structure represents one parsed argument in a macro call.
1611 `raw' points to the argument text as written (`raw_length' is its length).
1612 `expanded' points to the argument's macro-expansion
1613 (its length is `expand_length').
1614 `stringified_length' is the length the argument would have
1616 `use_count' is the number of times this macro arg is substituted
1617 into the macro. If the actual use count exceeds 10,
1618 the value stored is 10. */
1620 /* raw and expanded are relative to ARG_BASE */
1621 #define ARG_BASE ((pfile)->token_buffer)
1624 /* Strings relative to pfile->token_buffer */
1625 long raw, expanded, stringified;
1626 int raw_length, expand_length;
1627 int stringified_length;
1632 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1633 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1634 as the new input buffer.
1635 Return the new buffer, or NULL on failure. */
1638 cpp_push_buffer (pfile, buffer, length)
1643 register cpp_buffer *buf = CPP_BUFFER (pfile);
1644 if (buf == pfile->buffer_stack)
1646 cpp_fatal (pfile, "%s: macro or `#include' recursion too deep",
1651 bzero ((char *) buf, sizeof (cpp_buffer));
1652 CPP_BUFFER (pfile) = buf;
1653 buf->if_stack = pfile->if_stack;
1654 buf->cleanup = null_cleanup;
1655 buf->underflow = null_underflow;
1656 buf->buf = buf->cur = buffer;
1657 buf->alimit = buf->rlimit = buffer + length;
1663 cpp_pop_buffer (pfile)
1666 cpp_buffer *buf = CPP_BUFFER (pfile);
1667 (*buf->cleanup) (buf, pfile);
1668 return ++CPP_BUFFER (pfile);
1671 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1672 Pop the buffer when done. */
1675 cpp_scan_buffer (pfile)
1678 cpp_buffer *buffer = CPP_BUFFER (pfile);
1681 enum cpp_token token = cpp_get_token (pfile);
1682 if (token == CPP_EOF) /* Should not happen ... */
1684 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
1686 cpp_pop_buffer (pfile);
1693 * Rescan a string (which may have escape marks) into pfile's buffer.
1694 * Place the result in pfile->token_buffer.
1696 * The input is copied before it is scanned, so it is safe to pass
1697 * it something from the token_buffer that will get overwritten
1698 * (because it follows CPP_WRITTEN). This is used by do_include.
1702 cpp_expand_to_buffer (pfile, buf, length)
1707 register cpp_buffer *ip;
1711 U_CHAR *limit = buf + length;
1714 int odepth = indepth;
1720 /* Set up the input on the input stack. */
1722 buf1 = (U_CHAR *) alloca (length + 1);
1724 register U_CHAR *p1 = buf;
1725 register U_CHAR *p2 = buf1;
1732 ip = cpp_push_buffer (pfile, buf1, length);
1735 ip->has_escapes = 1;
1737 ip->lineno = obuf.lineno = 1;
1740 /* Scan the input, create the output. */
1741 cpp_scan_buffer (pfile);
1744 if (indepth != odepth)
1748 CPP_NUL_TERMINATE (pfile);
1753 adjust_position (buf, limit, linep, colp)
1763 (*linep)++, (*colp) = 1;
1769 /* Move line_base forward, updating lineno and colno. */
1772 update_position (pbuf)
1773 register cpp_buffer *pbuf;
1775 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
1776 unsigned char *new_pos = pbuf->cur;
1777 register struct parse_marker *mark;
1778 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
1780 if (pbuf->buf + mark->position < new_pos)
1781 new_pos = pbuf->buf + mark->position;
1783 pbuf->line_base += new_pos - old_pos;
1784 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
1788 cpp_buf_line_and_col (pbuf, linep, colp)
1789 register cpp_buffer *pbuf;
1797 *linep = pbuf->lineno;
1798 *colp = pbuf->colno;
1799 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
1808 /* Return the cpp_buffer that corresponds to a file (not a macro). */
1811 cpp_file_buffer (pfile)
1814 cpp_buffer *ip = CPP_BUFFER (pfile);
1816 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
1817 if (ip->fname != NULL)
1823 count_newlines (buf, limit)
1824 register U_CHAR *buf;
1825 register U_CHAR *limit;
1827 register long count = 0;
1838 * write out a #line command, for instance, after an #include file.
1839 * If CONDITIONAL is nonzero, we can omit the #line if it would
1840 * appear to be a no-op, and we can output a few newlines instead
1841 * if we want to increase the line number by a small amount.
1842 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
1846 output_line_command (pfile, conditional, file_change)
1849 enum file_change_code file_change;
1852 cpp_buffer *ip = CPP_BUFFER (pfile);
1854 if (ip->fname == NULL)
1857 update_position (ip);
1859 if (CPP_OPTIONS (pfile)->no_line_commands
1860 || CPP_OPTIONS (pfile)->no_output)
1863 line = CPP_BUFFER (pfile)->lineno;
1864 col = CPP_BUFFER (pfile)->colno;
1865 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
1867 if (CPP_OPTIONS (pfile)->no_line_commands)
1871 if (line == pfile->lineno)
1874 /* If the inherited line number is a little too small,
1875 output some newlines instead of a #line command. */
1876 if (line > pfile->lineno && line < pfile->lineno + 8) {
1877 CPP_RESERVE (pfile, 20);
1878 while (line > pfile->lineno) {
1879 CPP_PUTC_Q (pfile, '\n');
1887 /* Don't output a line number of 0 if we can help it. */
1888 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
1889 && *ip->bufp == '\n') {
1895 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
1897 #ifdef OUTPUT_LINE_COMMANDS
1898 static char sharp_line[] = "#line ";
1900 static char sharp_line[] = "# ";
1902 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
1905 sprintf ((char *) CPP_PWRITTEN (pfile), "%ld ", line);
1906 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
1908 quote_string (pfile, ip->nominal_fname);
1909 if (file_change != same_file) {
1910 CPP_PUTC_Q (pfile, ' ');
1911 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
1913 /* Tell cc1 if following text comes from a system header file. */
1914 if (ip->system_header_p) {
1915 CPP_PUTC_Q (pfile, ' ');
1916 CPP_PUTC_Q (pfile, '3');
1918 #ifndef NO_IMPLICIT_EXTERN_C
1919 /* Tell cc1plus if following text should be treated as C. */
1920 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
1921 CPP_PUTC_Q (pfile, ' ');
1922 CPP_PUTC_Q (pfile, '4');
1925 CPP_PUTC_Q (pfile, '\n');
1926 pfile->lineno = line;
1930 * Parse a macro argument and append the info on PFILE's token_buffer.
1931 * REST_ARGS means to absorb the rest of the args.
1932 * Return nonzero to indicate a syntax error.
1935 static enum cpp_token
1936 macarg (pfile, rest_args)
1941 enum cpp_token token;
1942 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1943 CPP_OPTIONS (pfile)->put_out_comments = 0;
1945 /* Try to parse as much of the argument as exists at this
1946 input stack level. */
1947 pfile->no_macro_expand++;
1950 token = cpp_get_token (pfile);
1956 /* If we've hit end of file, it's an error (reported by caller).
1957 Ditto if it's the end of cpp_expand_to_buffer text.
1958 If we've hit end of macro, just continue. */
1959 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
1970 /* if we've returned to lowest level and
1971 we aren't absorbing all args */
1972 if (paren == 0 && rest_args == 0)
1976 /* Remove ',' or ')' from argument buffer. */
1977 CPP_ADJUST_WRITTEN (pfile, -1);
1984 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1985 pfile->no_macro_expand--;
1990 /* Turn newlines to spaces in the string of length LENGTH at START,
1991 except inside of string constants.
1992 The string is copied into itself with its beginning staying fixed. */
1995 change_newlines (start, length)
1999 register U_CHAR *ibp;
2000 register U_CHAR *obp;
2001 register U_CHAR *limit;
2005 limit = start + length;
2008 while (ibp < limit) {
2009 *obp++ = c = *ibp++;
2014 /* Notice and skip strings, so that we don't delete newlines in them. */
2017 while (ibp < limit) {
2018 *obp++ = c = *ibp++;
2021 if (c == '\n' && quotec == '\'')
2037 if (!pfile->timebuf) {
2038 time_t t = time ((time_t *) 0);
2039 pfile->timebuf = localtime (&t);
2041 return pfile->timebuf;
2044 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2045 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2049 * expand things like __FILE__. Place the expansion into the output
2050 * buffer *without* rescanning.
2054 special_symbol (hp, pfile)
2061 cpp_buffer *ip = NULL;
2064 int paren = 0; /* For special `defined' keyword */
2067 if (pcp_outfile && pcp_inside_if
2068 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2070 "Predefined macro `%s' used inside `#if' during precompilation",
2074 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2076 if (ip == CPP_NULL_BUFFER (pfile))
2078 cpp_error (pfile, "cccp error: not in any file?!");
2079 return; /* the show must go on */
2081 if (ip->fname != NULL)
2091 if (hp->type == T_BASE_FILE)
2093 while (CPP_PREV_BUFFER (ip) != CPP_NULL_BUFFER (pfile))
2094 ip = CPP_PREV_BUFFER (ip);
2096 string = ip->nominal_fname;
2100 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2101 quote_string (pfile, string);
2105 case T_INCLUDE_LEVEL:
2107 ip = CPP_BUFFER (pfile);
2108 for (; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
2109 if (ip->fname != NULL)
2112 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
2113 sprintf (buf, "%d", true_indepth - 1);
2117 buf = (char *) alloca (3 + strlen (version_string));
2118 sprintf (buf, "\"%s\"", version_string);
2121 #ifndef NO_BUILTIN_SIZE_TYPE
2127 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2128 case T_PTRDIFF_TYPE:
2134 buf = CPP_WCHAR_TYPE (pfile);
2137 case T_USER_LABEL_PREFIX_TYPE:
2138 buf = user_label_prefix;
2141 case T_REGISTER_PREFIX_TYPE:
2142 buf = REGISTER_PREFIX;
2146 buf = (char *) alloca (4 * sizeof (int));
2147 sprintf (buf, "%d", hp->value.ival);
2148 #ifdef STDC_0_IN_SYSTEM_HEADERS
2149 if (ip->system_header_p
2150 && hp->length == 8 && bcmp (hp->name, "__STDC__", 8) == 0
2151 && ! cpp_lookup (pfile, (U_CHAR *) "__STRICT_ANSI__", -1, -1))
2155 if (pcp_inside_if && pcp_outfile)
2156 /* Output a precondition for this macro use */
2157 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2163 long line = ip->lineno;
2164 long col = ip->colno;
2165 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2167 buf = (char *) alloca (10);
2168 sprintf (buf, "%ld", line);
2174 buf = (char *) alloca (20);
2175 timebuf = timestamp (pfile);
2176 if (hp->type == T_DATE)
2177 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2178 timebuf->tm_mday, timebuf->tm_year + 1900);
2180 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
2184 case T_SPEC_DEFINED:
2185 buf = " 0 "; /* Assume symbol is not defined */
2186 ip = CPP_BUFFER (pfile);
2187 SKIP_WHITE_SPACE (ip->cur);
2188 if (*ip->cur == '(')
2191 ip->cur++; /* Skip over the paren */
2192 SKIP_WHITE_SPACE (ip->cur);
2195 if (!is_idstart[*ip->cur])
2197 if (ip->cur[0] == 'L' && (ip->cur[1] == '\'' || ip->cur[1] == '"'))
2199 if ((hp = cpp_lookup (pfile, ip->cur, -1, -1)))
2202 if (pcp_outfile && pcp_inside_if
2203 && (hp->type == T_CONST
2204 || (hp->type == T_MACRO && hp->value.defn->predefined)))
2205 /* Output a precondition for this macro use. */
2206 fprintf (pcp_outfile, "#define %s\n", hp->name);
2212 if (pcp_outfile && pcp_inside_if)
2214 /* Output a precondition for this macro use */
2215 U_CHAR *cp = ip->bufp;
2216 fprintf (pcp_outfile, "#undef ");
2217 while (is_idchar[*cp]) /* Ick! */
2218 fputc (*cp++, pcp_outfile);
2219 putc ('\n', pcp_outfile);
2222 while (is_idchar[*ip->cur])
2224 SKIP_WHITE_SPACE (ip->cur);
2227 if (*ip->cur != ')')
2235 cpp_error (pfile, "`defined' without an identifier");
2239 cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */
2243 CPP_RESERVE (pfile, len + 1);
2244 CPP_PUTS_Q (pfile, buf, len);
2245 CPP_NUL_TERMINATE_Q (pfile);
2250 /* Write out a #define command for the special named MACRO_NAME
2251 to PFILE's token_buffer. */
2254 dump_special_to_buffer (pfile, macro_name)
2258 static char define_directive[] = "#define ";
2259 int macro_name_length = strlen (macro_name);
2260 output_line_command (pfile, 0, same_file);
2261 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
2262 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
2263 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
2264 CPP_PUTC_Q (pfile, ' ');
2265 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
2266 CPP_PUTC (pfile, '\n');
2269 /* Initialize the built-in macros. */
2272 initialize_builtins (pfile)
2275 install ((U_CHAR *)"__LINE__", -1, T_SPECLINE, 0, 0, -1);
2276 install ((U_CHAR *)"__DATE__", -1, T_DATE, 0, 0, -1);
2277 install ((U_CHAR *)"__FILE__", -1, T_FILE, 0, 0, -1);
2278 install ((U_CHAR *)"__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
2279 install ((U_CHAR *)"__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
2280 install ((U_CHAR *)"__VERSION__", -1, T_VERSION, 0, 0, -1);
2281 #ifndef NO_BUILTIN_SIZE_TYPE
2282 install ((U_CHAR *)"__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
2284 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2285 install ((U_CHAR *)"__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
2287 install ((U_CHAR *)"__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
2288 install ((U_CHAR *)"__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
2289 install ((U_CHAR *)"__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
2290 install ((U_CHAR *)"__TIME__", -1, T_TIME, 0, 0, -1);
2291 if (!CPP_TRADITIONAL (pfile))
2292 install ((U_CHAR *)"__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
2293 if (CPP_OPTIONS (pfile)->objc)
2294 install ((U_CHAR *)"__OBJC__", -1, T_CONST, 1, 0, -1);
2295 /* This is supplied using a -D by the compiler driver
2296 so that it is present only when truly compiling with GNU C. */
2297 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2299 if (CPP_OPTIONS (pfile)->debug_output)
2301 dump_special_to_buffer (pfile, "__BASE_FILE__");
2302 dump_special_to_buffer (pfile, "__VERSION__");
2303 #ifndef NO_BUILTIN_SIZE_TYPE
2304 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
2306 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2307 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
2309 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
2310 dump_special_to_buffer (pfile, "__DATE__");
2311 dump_special_to_buffer (pfile, "__TIME__");
2312 if (!CPP_TRADITIONAL (pfile))
2313 dump_special_to_buffer (pfile, "__STDC__");
2314 if (CPP_OPTIONS (pfile)->objc)
2315 dump_special_to_buffer (pfile, "__OBJC__");
2319 /* Return 1 iff a token ending in C1 followed directly by a token C2
2320 could cause mis-tokenization. */
2323 unsafe_chars (c1, c2)
2329 if (c2 == c1 || c2 == '=')
2333 case '0': case '1': case '2': case '3': case '4':
2334 case '5': case '6': case '7': case '8': case '9':
2335 case 'e': case 'E': case 'p': case 'P':
2336 if (c2 == '-' || c2 == '+')
2337 return 1; /* could extend a pre-processing number */
2340 if (c2 == '\'' || c2 == '\"')
2341 return 1; /* Could turn into L"xxx" or L'xxx'. */
2345 case 'a': case 'b': case 'c': case 'd': case 'f':
2346 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2347 case 'm': case 'n': case 'o': case 'q': case 'r':
2348 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2350 case 'A': case 'B': case 'C': case 'D': case 'F':
2351 case 'G': case 'H': case 'I': case 'J': case 'K':
2352 case 'M': case 'N': case 'O': case 'Q': case 'R':
2353 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2355 /* We're in the middle of either a name or a pre-processing number. */
2356 return (is_idchar[c2] || c2 == '.');
2357 case '<': case '>': case '!': case '%': case '#': case ':':
2358 case '^': case '&': case '|': case '*': case '/': case '=':
2359 return (c2 == c1 || c2 == '=');
2364 /* Expand a macro call.
2365 HP points to the symbol that is the macro being called.
2366 Put the result of expansion onto the input stack
2367 so that subsequent input by our caller will use it.
2369 If macro wants arguments, caller has already verified that
2370 an argument list follows; arguments come from the input stack. */
2373 macroexpand (pfile, hp)
2378 DEFINITION *defn = hp->value.defn;
2379 register U_CHAR *xbuf;
2380 long start_line, start_column;
2382 struct argdata *args;
2383 long old_written = CPP_WRITTEN (pfile);
2385 int start_line = instack[indepth].lineno;
2387 int rest_args, rest_zero;
2391 CHECK_DEPTH (return;);
2395 /* This macro is being used inside a #if, which means it must be */
2396 /* recorded as a precondition. */
2397 if (pcp_inside_if && pcp_outfile && defn->predefined)
2398 dump_single_macro (hp, pcp_outfile);
2401 pfile->output_escapes++;
2402 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2404 nargs = defn->nargs;
2408 enum cpp_token token;
2410 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2412 for (i = 0; i < nargs; i++)
2414 args[i].raw = args[i].expanded = 0;
2415 args[i].raw_length = 0;
2416 args[i].expand_length = args[i].stringified_length = -1;
2417 args[i].use_count = 0;
2420 /* Parse all the macro args that are supplied. I counts them.
2421 The first NARGS args are stored in ARGS.
2422 The rest are discarded. If rest_args is set then we assume
2423 macarg absorbed the rest of the args. */
2427 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2432 if (i < nargs || (nargs == 0 && i == 0))
2434 /* if we are working on last arg which absorbs rest of args... */
2435 if (i == nargs - 1 && defn->rest_args)
2437 args[i].raw = CPP_WRITTEN (pfile);
2438 token = macarg (pfile, rest_args);
2439 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2440 args[i].newlines = 0; /* FIXME */
2443 token = macarg (pfile, 0);
2444 if (token == CPP_EOF || token == CPP_POP)
2446 cpp_error_with_line (pfile, start_line, start_column,
2447 "unterminated macro call");
2451 } while (token == CPP_COMMA);
2453 /* If we got one arg but it was just whitespace, call that 0 args. */
2456 register U_CHAR *bp = ARG_BASE + args[0].raw;
2457 register U_CHAR *lim = bp + args[0].raw_length;
2458 /* cpp.texi says for foo ( ) we provide one argument.
2459 However, if foo wants just 0 arguments, treat this as 0. */
2461 while (bp != lim && is_space[*bp]) bp++;
2466 /* Don't output an error message if we have already output one for
2467 a parse error above. */
2469 if (nargs == 0 && i > 0)
2471 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
2475 /* traditional C allows foo() if foo wants one argument. */
2476 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2478 /* the rest args token is allowed to absorb 0 tokens */
2479 else if (i == nargs - 1 && defn->rest_args)
2482 cpp_error (pfile, "macro `%s' used without args", hp->name);
2484 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2486 cpp_error (pfile, "macro `%s' used with only %d args",
2492 "macro `%s' used with too many (%d) args", hp->name, i);
2496 /* If macro wants zero args, we parsed the arglist for checking only.
2497 Read directly from the macro definition. */
2500 xbuf = defn->expansion;
2501 xbuf_len = defn->length;
2505 register U_CHAR *exp = defn->expansion;
2506 register int offset; /* offset in expansion,
2507 copied a piece at a time */
2508 register int totlen; /* total amount of exp buffer filled so far */
2510 register struct reflist *ap, *last_ap;
2512 /* Macro really takes args. Compute the expansion of this call. */
2514 /* Compute length in characters of the macro's expansion.
2515 Also count number of times each arg is used. */
2516 xbuf_len = defn->length;
2517 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2521 register struct argdata *arg = &args[ap->argno];
2522 /* Stringify if it hasn't already been */
2523 if (arg->stringified_length < 0)
2525 int arglen = arg->raw_length;
2529 /* Initially need_space is -1. Otherwise, 1 means the
2530 previous character was a space, but we suppressed it;
2531 0 means the previous character was a non-space. */
2532 int need_space = -1;
2534 arg->stringified = CPP_WRITTEN (pfile);
2535 if (!CPP_TRADITIONAL (pfile))
2536 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2537 for (; i < arglen; i++)
2539 c = (ARG_BASE + arg->raw)[i];
2543 /* Internal sequences of whitespace are replaced by
2544 one space except within an string or char token.*/
2547 if (CPP_WRITTEN (pfile) > (unsigned)arg->stringified
2548 && (CPP_PWRITTEN (pfile))[-1] == '@')
2550 /* "@ " escape markers are removed */
2551 CPP_ADJUST_WRITTEN (pfile, -1);
2554 if (need_space == 0)
2558 else if (need_space > 0)
2559 CPP_PUTC (pfile, ' ');
2574 else if (c == '\"' || c == '\'')
2578 /* Escape these chars */
2579 if (c == '\"' || (in_string && c == '\\'))
2580 CPP_PUTC (pfile, '\\');
2582 CPP_PUTC (pfile, c);
2585 CPP_RESERVE (pfile, 4);
2586 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o",
2588 CPP_ADJUST_WRITTEN (pfile, 4);
2591 if (!CPP_TRADITIONAL (pfile))
2592 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2593 arg->stringified_length
2594 = CPP_WRITTEN (pfile) - arg->stringified;
2596 xbuf_len += args[ap->argno].stringified_length;
2598 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2599 /* Add 4 for two newline-space markers to prevent
2600 token concatenation. */
2601 xbuf_len += args[ap->argno].raw_length + 4;
2604 /* We have an ordinary (expanded) occurrence of the arg.
2605 So compute its expansion, if we have not already. */
2606 if (args[ap->argno].expand_length < 0)
2608 args[ap->argno].expanded = CPP_WRITTEN (pfile);
2609 cpp_expand_to_buffer (pfile,
2610 ARG_BASE + args[ap->argno].raw,
2611 args[ap->argno].raw_length);
2613 args[ap->argno].expand_length
2614 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2617 /* Add 4 for two newline-space markers to prevent
2618 token concatenation. */
2619 xbuf_len += args[ap->argno].expand_length + 4;
2621 if (args[ap->argno].use_count < 10)
2622 args[ap->argno].use_count++;
2625 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2627 /* Generate in XBUF the complete expansion
2628 with arguments substituted in.
2629 TOTLEN is the total size generated so far.
2630 OFFSET is the index in the definition
2631 of where we are copying from. */
2632 offset = totlen = 0;
2633 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2634 last_ap = ap, ap = ap->next)
2636 register struct argdata *arg = &args[ap->argno];
2637 int count_before = totlen;
2639 /* Add chars to XBUF. */
2640 for (i = 0; i < ap->nchars; i++, offset++)
2641 xbuf[totlen++] = exp[offset];
2643 /* If followed by an empty rest arg with concatenation,
2644 delete the last run of nonwhite chars. */
2645 if (rest_zero && totlen > count_before
2646 && ((ap->rest_args && ap->raw_before)
2647 || (last_ap != NULL && last_ap->rest_args
2648 && last_ap->raw_after)))
2650 /* Delete final whitespace. */
2651 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2654 /* Delete the nonwhites before them. */
2655 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
2659 if (ap->stringify != 0)
2661 bcopy (ARG_BASE + arg->stringified,
2662 xbuf + totlen, arg->stringified_length);
2663 totlen += arg->stringified_length;
2665 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2667 U_CHAR *p1 = ARG_BASE + arg->raw;
2668 U_CHAR *l1 = p1 + arg->raw_length;
2671 while (p1 != l1 && is_space[*p1]) p1++;
2672 while (p1 != l1 && is_idchar[*p1])
2673 xbuf[totlen++] = *p1++;
2677 /* Arg is concatenated after: delete trailing whitespace,
2678 whitespace markers, and no-reexpansion markers. */
2681 if (is_space[l1[-1]]) l1--;
2682 else if (l1[-1] == '@')
2684 U_CHAR *p2 = l1 - 1;
2685 /* If whitespace is preceded by an odd number
2686 of `@' signs, the last `@' was a whitespace
2687 marker; drop it too. */
2688 while (p2 != p1 && p2[0] == '@') p2--;
2693 else if (l1[-1] == '-')
2695 U_CHAR *p2 = l1 - 1;
2696 /* If a `-' is preceded by an odd number of
2697 `@' signs then it and the last `@' are
2698 a no-reexpansion marker. */
2699 while (p2 != p1 && p2[0] == '@') p2--;
2709 /* Delete any no-reexpansion marker that precedes
2710 an identifier at the beginning of the argument. */
2711 if (p1[0] == '@' && p1[1] == '-')
2714 bcopy (p1, xbuf + totlen, l1 - p1);
2719 U_CHAR *expanded = ARG_BASE + arg->expanded;
2720 if (!ap->raw_before && totlen > 0 && arg->expand_length
2721 && !CPP_TRADITIONAL(pfile)
2722 && unsafe_chars (xbuf[totlen-1], expanded[0]))
2724 xbuf[totlen++] = '@';
2725 xbuf[totlen++] = ' ';
2728 bcopy (expanded, xbuf + totlen, arg->expand_length);
2729 totlen += arg->expand_length;
2731 if (!ap->raw_after && totlen > 0 && offset < defn->length
2732 && !CPP_TRADITIONAL(pfile)
2733 && unsafe_chars (xbuf[totlen-1], exp[offset]))
2735 xbuf[totlen++] = '@';
2736 xbuf[totlen++] = ' ';
2739 /* If a macro argument with newlines is used multiple times,
2740 then only expand the newlines once. This avoids creating
2741 output lines which don't correspond to any input line,
2742 which confuses gdb and gcov. */
2743 if (arg->use_count > 1 && arg->newlines > 0)
2745 /* Don't bother doing change_newlines for subsequent
2749 = change_newlines (expanded, arg->expand_length);
2753 if (totlen > xbuf_len)
2757 /* if there is anything left of the definition
2758 after handling the arg list, copy that in too. */
2760 for (i = offset; i < defn->length; i++)
2762 /* if we've reached the end of the macro */
2765 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
2766 && last_ap->raw_after))
2767 xbuf[totlen++] = exp[i];
2775 pfile->output_escapes--;
2777 /* Now put the expansion on the input stack
2778 so our caller will commence reading from it. */
2779 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
2780 CPP_BUFFER (pfile)->has_escapes = 1;
2782 /* Pop the space we've used in the token_buffer for argument expansion. */
2783 CPP_SET_WRITTEN (pfile, old_written);
2785 /* Recursive macro use sometimes works traditionally.
2786 #define foo(x,y) bar (x (y,0), y)
2789 if (!CPP_TRADITIONAL (pfile))
2790 hp->type = T_DISABLED;
2794 push_macro_expansion (pfile, xbuf, xbuf_len, hp)
2796 register U_CHAR *xbuf;
2800 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
2803 mbuf->cleanup = macro_cleanup;
2806 /* The first chars of the expansion should be a "@ " added by
2807 collect_expansion. This is to prevent accidental token-pasting
2808 between the text preceding the macro invocation, and the macro
2811 We would like to avoid adding unneeded spaces (for the sake of
2812 tools that use cpp, such as imake). In some common cases we can
2813 tell that it is safe to omit the space.
2815 The character before the macro invocation cannot have been an
2816 idchar (or else it would have been pasted with the idchars of
2817 the macro name). Therefore, if the first non-space character
2818 of the expansion is an idchar, we do not need the extra space
2819 to prevent token pasting.
2821 Also, we don't need the extra space if the first char is '(',
2822 or some other (less common) characters. */
2824 if (xbuf[0] == '@' && xbuf[1] == ' '
2825 && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\''
2826 || xbuf[2] == '\"'))
2830 /* Like cpp_get_token, except that it does not read past end-of-line.
2831 Also, horizontal space is skipped, and macros are popped. */
2833 static enum cpp_token
2834 get_directive_token (pfile)
2839 long old_written = CPP_WRITTEN (pfile);
2840 enum cpp_token token;
2841 cpp_skip_hspace (pfile);
2842 if (PEEKC () == '\n')
2844 token = cpp_get_token (pfile);
2848 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2850 /* ... else fall though ... */
2851 case CPP_HSPACE: case CPP_COMMENT:
2852 CPP_SET_WRITTEN (pfile, old_written);
2860 /* Handle #include and #import.
2861 This function expects to see "fname" or <fname> on the input.
2863 The input is normally in part of the output_buffer following
2864 CPP_WRITTEN, and will get overwritten by output_line_command.
2865 I.e. in input file specification has been popped by handle_directive.
2869 do_include (pfile, keyword)
2871 struct directive *keyword;
2873 int importing = (keyword->type == T_IMPORT);
2874 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
2875 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
2876 int before; /* included before? */
2881 enum cpp_token token;
2883 /* Chain of dirs to search */
2884 struct include_hash *ihash;
2885 struct file_name_list *search_start;
2887 long old_written = CPP_WRITTEN (pfile);
2891 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
2894 cpp_pedwarn (pfile, "ANSI C does not allow `#import'");
2896 cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'");
2899 if (importing && CPP_OPTIONS (pfile)->warn_import
2900 && !CPP_OPTIONS (pfile)->inhibit_warnings
2901 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
2903 pfile->import_warning = 1;
2904 cpp_warning (pfile, "`#import' is obsolete, use an #ifdef wrapper in the header file");
2907 pfile->parsing_include_directive++;
2908 token = get_directive_token (pfile);
2909 pfile->parsing_include_directive--;
2911 if (token == CPP_STRING)
2913 fbeg = pfile->token_buffer + old_written + 1;
2914 fend = CPP_PWRITTEN (pfile) - 1;
2916 if (fbeg[-1] == '<')
2920 else if (token == CPP_NAME)
2922 /* Support '#include xyz' like VAX-C to allow for easy use of
2923 * all the decwindow include files. It defaults to '#include
2924 * <xyz.h>' and generates a warning. */
2926 "VAX-C-style include specification found, use '#include <filename.h>' !");
2929 /* Append the missing `.h' to the name. */
2930 CPP_PUTS (pfile, ".h", 3)
2931 CPP_NUL_TERMINATE_Q (pfile);
2933 fbeg = pfile->token_buffer + old_written;
2934 fend = CPP_PWRITTEN (pfile);
2940 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
2941 CPP_SET_WRITTEN (pfile, old_written);
2942 skip_rest_of_line (pfile);
2946 token = get_directive_token (pfile);
2947 if (token != CPP_VSPACE)
2949 cpp_error (pfile, "junk at end of `#include'");
2950 skip_rest_of_line (pfile);
2953 CPP_SET_WRITTEN (pfile, old_written);
2959 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
2965 for (fp = CPP_BUFFER (pfile);
2966 fp != CPP_NULL_BUFFER (pfile);
2967 fp = CPP_PREV_BUFFER (fp))
2968 if (fp->fname != NULL)
2971 if (fp == CPP_NULL_BUFFER (pfile))
2973 cpp_fatal (pfile, "cpp internal error: fp == NULL_BUFFER in do_include");
2977 /* For #include_next, skip in the search path past the dir in which the
2978 containing file was found. Treat files specified using an absolute path
2979 as if there are no more directories to search. Treat the primary source
2980 file like any other included source, but generate a warning. */
2981 if (skip_dirs && CPP_PREV_BUFFER(fp) != CPP_NULL_BUFFER (pfile))
2983 if (fp->ihash->foundhere != ABSOLUTE_PATH)
2984 search_start = fp->ihash->foundhere->next;
2989 cpp_warning (pfile, "#include_next in primary source file");
2992 search_start = CPP_OPTIONS (pfile)->bracket_include;
2995 if (!CPP_OPTIONS (pfile)->ignore_srcdir)
2998 search_start = fp->actual_dir;
3001 search_start = CPP_OPTIONS (pfile)->quote_include;
3007 cpp_error (pfile, "No include path in which to find %s", fbeg);
3011 fd = find_include_file (pfile, fbeg, search_start, &ihash, &before);
3018 if (CPP_OPTIONS (pfile)->print_deps_missing_files
3019 && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
3020 (pfile->system_include_depth > 0)))
3022 if (!angle_brackets)
3023 deps_output (pfile, fbeg, ' ');
3027 struct file_name_list *ptr;
3028 /* If requested as a system header, assume it belongs in
3029 the first system header directory. */
3030 if (CPP_OPTIONS (pfile)->bracket_include)
3031 ptr = CPP_OPTIONS (pfile)->bracket_include;
3033 ptr = CPP_OPTIONS (pfile)->quote_include;
3035 p = (char *) alloca (strlen (ptr->name)
3036 + strlen (fbeg) + 2);
3037 if (*ptr->name != '\0')
3039 strcpy (p, ptr->name);
3043 deps_output (pfile, p, ' ');
3046 /* If -M was specified, and this header file won't be added to
3047 the dependency list, then don't count this as an error,
3048 because we can still produce correct output. Otherwise, we
3049 can't produce correct output, because there may be
3050 dependencies we need inside the missing file, and we don't
3051 know what directory this missing file exists in. */
3052 else if (CPP_PRINT_DEPS (pfile)
3053 && (CPP_PRINT_DEPS (pfile)
3054 <= (angle_brackets || (pfile->system_include_depth > 0))))
3055 cpp_warning (pfile, "No include path in which to find %s", fbeg);
3057 cpp_error_from_errno (pfile, fbeg);
3062 /* For -M, add the file to the dependencies on its first inclusion. */
3063 if (!before && (CPP_PRINT_DEPS (pfile)
3064 > (angle_brackets || (pfile->system_include_depth > 0))))
3065 deps_output (pfile, ihash->name, ' ');
3067 /* Handle -H option. */
3068 if (CPP_OPTIONS(pfile)->print_include_names)
3070 fp = CPP_BUFFER (pfile);
3071 while ((fp = CPP_PREV_BUFFER (fp)) != CPP_NULL_BUFFER (pfile))
3073 fprintf (stderr, " %s\n", ihash->name);
3076 /* Actually process the file */
3079 ihash->control_macro = "";
3081 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
3088 pfile->system_include_depth++; /* Decremented in file_cleanup. */
3090 if (finclude (pfile, fd, ihash))
3092 output_line_command (pfile, 0, enter_file);
3093 pfile->only_seen_white = 2;
3100 /* Convert a character string literal into a nul-terminated string.
3101 The input string is [IN ... LIMIT).
3102 The result is placed in RESULT. RESULT can be the same as IN.
3103 The value returned in the end of the string written to RESULT,
3104 or NULL on error. */
3107 convert_string (pfile, result, in, limit, handle_escapes)
3109 register U_CHAR *result, *in, *limit;
3129 char *bpc = (char *) in;
3130 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc, 0x00ff);
3131 in = (U_CHAR *) bpc;
3133 *result++ = (U_CHAR)c;
3136 /* else fall through */
3146 * interpret #line command. Remembers previously seen fnames
3147 * in its very own hash table.
3149 #define FNAME_HASHSIZE 37
3152 do_line (pfile, keyword)
3154 struct directive *keyword ATTRIBUTE_UNUSED;
3156 cpp_buffer *ip = CPP_BUFFER (pfile);
3158 long old_written = CPP_WRITTEN (pfile);
3159 enum file_change_code file_change = same_file;
3160 enum cpp_token token;
3162 token = get_directive_token (pfile);
3164 if (token != CPP_NUMBER
3165 || !ISDIGIT(pfile->token_buffer[old_written]))
3167 cpp_error (pfile, "invalid format `#line' command");
3168 goto bad_line_directive;
3171 /* The Newline at the end of this line remains to be processed.
3172 To put the next line at the specified line number,
3173 we must store a line number now that is one less. */
3174 new_lineno = atoi ((char *)(pfile->token_buffer + old_written)) - 1;
3175 CPP_SET_WRITTEN (pfile, old_written);
3177 /* NEW_LINENO is one less than the actual line number here. */
3178 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3179 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3181 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3182 if (PEEKC() && !is_space[PEEKC()]) {
3183 cpp_error (pfile, "invalid format `#line' command");
3184 goto bad_line_directive;
3188 token = get_directive_token (pfile);
3190 if (token == CPP_STRING) {
3191 U_CHAR *fname = pfile->token_buffer + old_written;
3193 static HASHNODE *fname_table[FNAME_HASHSIZE];
3194 HASHNODE *hp, **hash_bucket;
3199 /* Turn the file name, which is a character string literal,
3200 into a null-terminated string. Do this in place. */
3201 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3202 if (end_name == NULL)
3204 cpp_error (pfile, "invalid format `#line' command");
3205 goto bad_line_directive;
3208 fname_length = end_name - fname;
3210 num_start = CPP_WRITTEN (pfile);
3211 token = get_directive_token (pfile);
3212 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3213 p = pfile->token_buffer + num_start;
3214 if (CPP_PEDANTIC (pfile))
3215 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3217 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3219 cpp_error (pfile, "invalid format `#line' command");
3220 goto bad_line_directive;
3223 file_change = enter_file;
3225 file_change = leave_file;
3227 ip->system_header_p = 1;
3228 else /* if (*p == '4') */
3229 ip->system_header_p = 2;
3231 CPP_SET_WRITTEN (pfile, num_start);
3232 token = get_directive_token (pfile);
3233 p = pfile->token_buffer + num_start;
3234 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3235 ip->system_header_p = *p == '3' ? 1 : 2;
3236 token = get_directive_token (pfile);
3238 if (token != CPP_VSPACE) {
3239 cpp_error (pfile, "invalid format `#line' command");
3240 goto bad_line_directive;
3244 hash_bucket = &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3245 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3246 if (hp->length == fname_length
3247 && strncmp (hp->value.cpval, fname, fname_length) == 0) {
3248 ip->nominal_fname = hp->value.cpval;
3252 /* Didn't find it; cons up a new one. */
3253 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3254 hp->next = *hash_bucket;
3257 hp->length = fname_length;
3258 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3259 bcopy (fname, hp->value.cpval, fname_length);
3262 else if (token != CPP_VSPACE && token != CPP_EOF) {
3263 cpp_error (pfile, "invalid format `#line' command");
3264 goto bad_line_directive;
3267 ip->lineno = new_lineno;
3269 skip_rest_of_line (pfile);
3270 CPP_SET_WRITTEN (pfile, old_written);
3271 output_line_command (pfile, 0, file_change);
3276 * remove the definition of a symbol from the symbol table.
3277 * according to un*x /lib/cpp, it is not an error to undef
3278 * something that has no definitions, so it isn't one here either.
3282 do_undef (pfile, keyword)
3284 struct directive *keyword;
3288 U_CHAR *buf, *name, *limit;
3290 long here = CPP_WRITTEN (pfile);
3291 enum cpp_token token;
3293 cpp_skip_hspace (pfile);
3295 if (! is_idstart[c])
3297 cpp_error (pfile, "token after #undef is not an identifier");
3298 skip_rest_of_line (pfile);
3302 parse_name (pfile, c);
3303 buf = pfile->token_buffer + here;
3304 limit = CPP_PWRITTEN(pfile);
3306 /* Copy out the token so we can pop the token buffer. */
3307 name = alloca (limit - buf + 1);
3308 bcopy(buf, name, limit - buf);
3309 name[limit - buf] = '\0';
3311 token = get_directive_token (pfile);
3312 if (token != CPP_VSPACE && token != CPP_POP)
3314 cpp_pedwarn (pfile, "junk on line after #undef");
3315 skip_rest_of_line (pfile);
3318 CPP_SET_WRITTEN (pfile, here);
3321 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3322 if (pcp_outfile && keyword)
3323 pass_thru_directive (buf, limit, pfile, keyword);
3326 sym_length = check_macro_name (pfile, name, "macro");
3328 while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
3330 /* If we are generating additional info for debugging (with -g) we
3331 need to pass through all effective #undef commands. */
3332 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3333 pass_thru_directive (name, name+sym_length, pfile, keyword);
3334 if (hp->type != T_MACRO)
3335 cpp_warning (pfile, "undefining `%s'", hp->name);
3342 /* Wrap do_undef for -U processing. */
3344 cpp_undef (pfile, macro)
3348 if (cpp_push_buffer (pfile, macro, strlen(macro)))
3350 do_undef (pfile, NULL);
3351 cpp_pop_buffer (pfile);
3357 * Report an error detected by the program we are processing.
3358 * Use the text of the line in the error message.
3359 * (We use error because it prints the filename & line#.)
3363 do_error (pfile, keyword)
3365 struct directive *keyword ATTRIBUTE_UNUSED;
3367 long here = CPP_WRITTEN (pfile);
3369 copy_rest_of_line (pfile);
3370 text = pfile->token_buffer + here;
3371 SKIP_WHITE_SPACE(text);
3373 cpp_error (pfile, "#error %s", text);
3374 CPP_SET_WRITTEN (pfile, here);
3379 * Report a warning detected by the program we are processing.
3380 * Use the text of the line in the warning message, then continue.
3384 do_warning (pfile, keyword)
3386 struct directive *keyword ATTRIBUTE_UNUSED;
3389 long here = CPP_WRITTEN(pfile);
3390 copy_rest_of_line (pfile);
3391 text = pfile->token_buffer + here;
3392 SKIP_WHITE_SPACE(text);
3394 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3395 cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
3397 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
3398 if -pedantic-errors is given, #warning should cause an error. */
3399 cpp_pedwarn (pfile, "#warning %s", text);
3400 CPP_SET_WRITTEN (pfile, here);
3404 /* Report program identification. */
3407 do_ident (pfile, keyword)
3409 struct directive *keyword ATTRIBUTE_UNUSED;
3411 /* Allow #ident in system headers, since that's not user's fault. */
3412 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3413 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
3415 skip_rest_of_line (pfile); /* Correct? Appears to match cccp. */
3420 /* Just check for some recognized pragmas that need validation here,
3421 and leave the text in the token buffer to be output. */
3424 do_pragma (pfile, keyword)
3426 struct directive *keyword ATTRIBUTE_UNUSED;
3428 long here = CPP_WRITTEN (pfile);
3431 copy_rest_of_line (pfile);
3432 buf = pfile->token_buffer + here;
3433 SKIP_WHITE_SPACE (buf);
3435 if (!strncmp (buf, "once", 4))
3437 cpp_buffer *ip = NULL;
3439 /* Allow #pragma once in system headers, since that's not the user's
3441 if (!CPP_BUFFER (pfile)->system_header_p)
3442 cpp_warning (pfile, "`#pragma once' is obsolete");
3444 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3446 if (ip == CPP_NULL_BUFFER (pfile))
3448 if (ip->fname != NULL)
3452 if (CPP_PREV_BUFFER (ip) == CPP_NULL_BUFFER (pfile))
3453 cpp_warning (pfile, "`#pragma once' outside include file");
3455 ip->ihash->control_macro = ""; /* never repeat */
3458 if (!strncmp (buf, "implementation", 14))
3460 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3461 been included yet. */
3462 struct include_hash *ptr;
3463 U_CHAR *p = buf + 14, *fname, *fcopy;
3464 SKIP_WHITE_SPACE (p);
3465 if (*p == '\n' || *p != '\"')
3469 p = (U_CHAR *) index (fname, '\"');
3471 fcopy = alloca (p - fname + 1);
3472 bcopy (fname, fcopy, p - fname);
3473 fcopy[p-fname] = '\0';
3475 ptr = include_hash (pfile, fcopy, 0);
3478 "`#pragma implementation' for `%s' appears after file is included",
3485 #ifdef SCCS_DIRECTIVE
3486 /* Just ignore #sccs, on systems where we define it at all. */
3489 do_sccs (pfile, keyword)
3491 struct directive *keyword ATTRIBUTE_UNUSED;
3493 if (CPP_PEDANTIC (pfile))
3494 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
3495 skip_rest_of_line (pfile);
3501 * handle #if command by
3502 * 1) inserting special `defined' keyword into the hash table
3503 * that gets turned into 0 or 1 by special_symbol (thus,
3504 * if the luser has a symbol called `defined' already, it won't
3505 * work inside the #if command)
3506 * 2) rescan the input into a temporary output buffer
3507 * 3) pass the output buffer to the yacc parser and collect a value
3508 * 4) clean up the mess left from steps 1 and 2.
3509 * 5) call conditional_skip to skip til the next #endif (etc.),
3510 * or not, depending on the value from step 3.
3514 do_if (pfile, keyword)
3516 struct directive *keyword ATTRIBUTE_UNUSED;
3518 HOST_WIDE_INT value = eval_if_expression (pfile);
3519 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
3524 * handle a #elif directive by not changing if_stack either.
3525 * see the comment above do_else.
3529 do_elif (pfile, keyword)
3531 struct directive *keyword ATTRIBUTE_UNUSED;
3533 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
3534 cpp_error (pfile, "`#elif' not within a conditional");
3537 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
3538 cpp_error (pfile, "`#elif' after `#else'");
3540 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
3542 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
3543 && strcmp (pfile->if_stack->fname,
3544 CPP_BUFFER (pfile)->nominal_fname) != 0)
3545 fprintf (stderr, ", file %s", pfile->if_stack->fname);
3546 fprintf (stderr, ")\n");
3548 pfile->if_stack->type = T_ELIF;
3551 if (pfile->if_stack->if_succeeded)
3552 skip_if_group (pfile);
3554 HOST_WIDE_INT value = eval_if_expression (pfile);
3556 skip_if_group (pfile);
3558 ++pfile->if_stack->if_succeeded; /* continue processing input */
3559 output_line_command (pfile, 1, same_file);
3566 * evaluate a #if expression in BUF, of length LENGTH,
3567 * then parse the result as a C expression and return the value as an int.
3570 static HOST_WIDE_INT
3571 eval_if_expression (pfile)
3574 HASHNODE *save_defined;
3575 HOST_WIDE_INT value;
3576 long old_written = CPP_WRITTEN (pfile);
3578 save_defined = install ((U_CHAR *)"defined", -1, T_SPEC_DEFINED, 0, 0, -1);
3579 pfile->pcp_inside_if = 1;
3581 value = cpp_parse_expr (pfile);
3582 pfile->pcp_inside_if = 0;
3583 delete_macro (save_defined); /* clean up special symbol */
3585 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
3591 * routine to handle ifdef/ifndef. Try to look up the symbol,
3592 * then do or don't skip to the #endif/#else/#elif depending
3593 * on what directive is actually being processed.
3597 do_xifdef (pfile, keyword)
3599 struct directive *keyword;
3602 cpp_buffer *ip = CPP_BUFFER (pfile);
3605 enum cpp_token token;
3606 int start_of_file = 0;
3607 U_CHAR *control_macro = 0;
3608 int old_written = CPP_WRITTEN (pfile);
3610 /* Detect a #ifndef at start of file (not counting comments). */
3611 if (ip->fname != 0 && keyword->type == T_IFNDEF)
3612 start_of_file = pfile->only_seen_white == 2;
3614 pfile->no_macro_expand++;
3615 token = get_directive_token (pfile);
3616 pfile->no_macro_expand--;
3618 ident = pfile->token_buffer + old_written;
3619 ident_length = CPP_WRITTEN (pfile) - old_written;
3620 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
3622 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
3624 skip = (keyword->type == T_IFDEF);
3625 if (! CPP_TRADITIONAL (pfile))
3626 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
3628 else if (token == CPP_NAME)
3630 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
3631 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
3632 if (start_of_file && !skip)
3634 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
3635 bcopy (ident, control_macro, ident_length + 1);
3640 skip = (keyword->type == T_IFDEF);
3641 if (! CPP_TRADITIONAL (pfile))
3642 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
3645 if (!CPP_TRADITIONAL (pfile))
3647 cpp_skip_hspace (pfile);
3649 if (c != EOF && c != '\n')
3650 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
3652 skip_rest_of_line (pfile);
3656 /* Output a precondition for this macro. */
3657 if (hp && hp->value.defn->predefined)
3658 fprintf (pcp_outfile, "#define %s\n", hp->name);
3661 fprintf (pcp_outfile, "#undef ");
3662 while (is_idchar[*cp]) /* Ick! */
3663 fputc (*cp++, pcp_outfile);
3664 putc ('\n', pcp_outfile);
3668 conditional_skip (pfile, skip, T_IF, control_macro);
3672 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
3673 If this is a #ifndef starting at the beginning of a file,
3674 CONTROL_MACRO is the macro name tested by the #ifndef.
3675 Otherwise, CONTROL_MACRO is 0. */
3678 conditional_skip (pfile, skip, type, control_macro)
3681 enum node_type type;
3682 U_CHAR *control_macro;
3684 IF_STACK_FRAME *temp;
3686 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
3687 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
3689 temp->lineno = CPP_BUFFER (pfile)->lineno;
3691 temp->next = pfile->if_stack;
3692 temp->control_macro = control_macro;
3693 pfile->if_stack = temp;
3695 pfile->if_stack->type = type;
3698 skip_if_group (pfile);
3701 ++pfile->if_stack->if_succeeded;
3702 output_line_command (pfile, 1, same_file);
3706 /* Subroutine of skip_if_group. Examine one preprocessing directive and
3707 return 0 if skipping should continue, 1 if it should halt. Also
3708 adjusts the if_stack as appropriate.
3709 The `#' has been read, but not the identifier. */
3712 consider_directive_while_skipping (pfile, stack)
3714 IF_STACK_FRAME *stack;
3716 long ident_len, ident;
3717 struct directive *kt;
3718 IF_STACK_FRAME *temp;
3720 cpp_skip_hspace (pfile);
3722 ident = CPP_WRITTEN (pfile);
3723 parse_name (pfile, GETC());
3724 ident_len = CPP_WRITTEN (pfile) - ident;
3726 CPP_SET_WRITTEN (pfile, ident);
3728 for (kt = directive_table; kt->length >= 0; kt++)
3729 if (kt->length == ident_len
3730 && strncmp (pfile->token_buffer + ident, kt->name, kt->length) == 0)
3736 temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
3737 temp->next = pfile->if_stack;
3738 pfile->if_stack = temp;
3739 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
3740 temp->type = kt->type;
3744 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
3745 validate_else (pfile, "#else");
3748 if (pfile->if_stack->type == T_ELSE)
3749 cpp_error (pfile, "`%s' after `#else'", kt->name);
3751 if (pfile->if_stack == stack)
3755 pfile->if_stack->type = kt->type;
3760 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
3761 validate_else (pfile, "#endif");
3763 if (pfile->if_stack == stack)
3766 temp = pfile->if_stack;
3767 pfile->if_stack = temp->next;
3775 /* Don't let erroneous code go by. */
3776 if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile))
3777 cpp_pedwarn (pfile, "invalid preprocessor directive name");
3781 /* skip to #endif, #else, or #elif. adjust line numbers, etc.
3782 * leaves input ptr at the sharp sign found.
3785 skip_if_group (pfile)
3789 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
3790 U_CHAR *beg_of_line;
3793 if (CPP_OPTIONS (pfile)->output_conditionals)
3795 CPP_PUTS (pfile, "#failed\n", 8);
3797 output_line_command (pfile, 1, same_file);
3800 old_written = CPP_WRITTEN (pfile);
3804 beg_of_line = CPP_BUFFER (pfile)->cur;
3806 if (! CPP_TRADITIONAL (pfile))
3807 cpp_skip_hspace (pfile);
3811 if (CPP_OPTIONS (pfile)->output_conditionals)
3812 CPP_PUTC (pfile, c);
3817 if (consider_directive_while_skipping (pfile, save_if_stack))
3821 return; /* Caller will issue error. */
3824 if (CPP_OPTIONS (pfile)->output_conditionals)
3826 CPP_PUTS (pfile, beg_of_line, CPP_BUFFER (pfile)->cur - beg_of_line);
3827 copy_rest_of_line (pfile);
3831 copy_rest_of_line (pfile);
3832 CPP_SET_WRITTEN (pfile, old_written); /* discard it */
3837 return; /* Caller will issue error. */
3841 if (CPP_OPTIONS (pfile)->output_conditionals)
3842 CPP_PUTC (pfile, c);
3846 /* Back up to the beginning of this line. Caller will process the
3848 CPP_BUFFER (pfile)->cur = beg_of_line;
3849 pfile->only_seen_white = 1;
3850 if (CPP_OPTIONS (pfile)->output_conditionals)
3852 CPP_PUTS (pfile, "#endfailed\n", 11);
3858 * handle a #else directive. Do this by just continuing processing
3859 * without changing if_stack ; this is so that the error message
3860 * for missing #endif's etc. will point to the original #if. It
3861 * is possible that something different would be better.
3865 do_else (pfile, keyword)
3867 struct directive *keyword ATTRIBUTE_UNUSED;
3869 cpp_buffer *ip = CPP_BUFFER (pfile);
3871 if (CPP_PEDANTIC (pfile))
3872 validate_else (pfile, "#else");
3873 skip_rest_of_line (pfile);
3875 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
3876 cpp_error (pfile, "`#else' not within a conditional");
3879 /* #ifndef can't have its special treatment for containing the whole file
3880 if it has a #else clause. */
3881 pfile->if_stack->control_macro = 0;
3883 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
3884 cpp_error (pfile, "`#else' after `#else'");
3885 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
3886 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
3887 fprintf (stderr, ", file %s", pfile->if_stack->fname);
3888 fprintf (stderr, ")\n");
3890 pfile->if_stack->type = T_ELSE;
3893 if (pfile->if_stack->if_succeeded)
3894 skip_if_group (pfile);
3896 ++pfile->if_stack->if_succeeded; /* continue processing input */
3897 output_line_command (pfile, 1, same_file);
3903 * unstack after #endif command
3907 do_endif (pfile, keyword)
3909 struct directive *keyword ATTRIBUTE_UNUSED;
3911 if (CPP_PEDANTIC (pfile))
3912 validate_else (pfile, "#endif");
3913 skip_rest_of_line (pfile);
3915 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
3916 cpp_error (pfile, "unbalanced `#endif'");
3919 IF_STACK_FRAME *temp = pfile->if_stack;
3920 pfile->if_stack = temp->next;
3921 if (temp->control_macro != 0)
3923 /* This #endif matched a #ifndef at the start of the file.
3924 See if it is at the end of the file. */
3925 struct parse_marker start_mark;
3928 parse_set_mark (&start_mark, pfile);
3932 cpp_skip_hspace (pfile);
3937 parse_goto_mark (&start_mark, pfile);
3938 parse_clear_mark (&start_mark);
3942 /* This #endif ends a #ifndef
3943 that contains all of the file (aside from whitespace).
3944 Arrange not to include the file again
3945 if the macro that was tested is defined. */
3946 struct cpp_buffer *ip;
3947 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3948 if (ip->fname != NULL)
3950 ip->ihash->control_macro = temp->control_macro;
3954 output_line_command (pfile, 1, same_file);
3959 /* When an #else or #endif is found while skipping failed conditional,
3960 if -pedantic was specified, this is called to warn about text after
3961 the command name. P points to the first char after the command name. */
3964 validate_else (pfile, directive)
3969 cpp_skip_hspace (pfile);
3971 if (c != EOF && c != '\n')
3973 "text following `%s' violates ANSI standard", directive);
3976 /* Get the next token, and add it to the text in pfile->token_buffer.
3977 Return the kind of token we got. */
3980 cpp_get_token (pfile)
3983 register int c, c2, c3;
3985 long start_line, start_column;
3986 enum cpp_token token;
3987 struct cpp_options *opts = CPP_OPTIONS (pfile);
3988 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
3994 if (CPP_BUFFER (pfile)->seen_eof)
3996 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4003 cpp_buffer *next_buf
4004 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4005 CPP_BUFFER (pfile)->seen_eof = 1;
4006 if (CPP_BUFFER (pfile)->nominal_fname
4007 && next_buf != CPP_NULL_BUFFER (pfile))
4009 /* We're about to return from an #include file.
4010 Emit #line information now (as part of the CPP_POP) result.
4011 But the #line refers to the file we will pop to. */
4012 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4013 CPP_BUFFER (pfile) = next_buf;
4014 pfile->input_stack_listing_current = 0;
4015 output_line_command (pfile, 0, leave_file);
4016 CPP_BUFFER (pfile) = cur_buffer;
4026 struct parse_marker start_mark;
4028 if (PEEKC () == '=')
4030 if (opts->put_out_comments)
4031 parse_set_mark (&start_mark, pfile);
4033 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4034 &start_line, &start_column);
4035 c = skip_comment (pfile, &newlines);
4036 if (opts->put_out_comments && (c == '/' || c == EOF))
4037 parse_clear_mark (&start_mark);
4042 cpp_error_with_line (pfile, start_line, start_column,
4043 "unterminated comment");
4046 c = '/'; /* Initial letter of comment. */
4048 /* Comments are equivalent to spaces.
4049 For -traditional, a comment is equivalent to nothing. */
4050 if (opts->put_out_comments)
4052 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4053 U_CHAR *start = pbuf->buf + start_mark.position;
4054 int len = pbuf->cur - start;
4055 CPP_RESERVE(pfile, 1 + len);
4056 CPP_PUTC_Q (pfile, c);
4057 CPP_PUTS_Q (pfile, start, len);
4058 pfile->lineno += newlines;
4059 parse_clear_mark (&start_mark);
4062 else if (CPP_TRADITIONAL (pfile))
4069 /* This may not work if cpp_get_token is called recursively,
4070 since many places look for horizontal space. */
4073 /* Copy the newlines into the output buffer, in order to
4074 avoid the pain of a #line every time a multiline comment
4076 CPP_RESERVE(pfile, newlines);
4077 while (--newlines >= 0)
4079 CPP_PUTC_Q (pfile, '\n');
4085 CPP_RESERVE(pfile, 1);
4086 CPP_PUTC_Q (pfile, ' ');
4090 if (opts->for_lint) {
4093 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4095 if (lintcmd != NULL) {
4096 /* I believe it is always safe to emit this newline: */
4098 bcopy ("#pragma lint ", (char *) obp, 13);
4100 bcopy (lintcmd, (char *) obp, cmdlen);
4105 bcopy (argbp, (char *) obp, arglen);
4109 /* OK, now bring us back to the state we were in before we entered
4110 this branch. We need #line because the newline for the pragma
4111 could mess things up. */
4112 output_line_command (pfile, 0, same_file);
4113 *(obp++) = ' '; /* just in case, if comments are copied thru */
4121 /* If this is expanding a macro definition, don't recognize
4122 preprocessor directives. */
4125 /* If this is expand_into_temp_buffer, recognize them
4126 only after an actual newline at this level,
4127 not at the beginning of the input level. */
4128 if (ip->fname == 0 && beg_of_line == ip->buf)
4134 if (!pfile->only_seen_white)
4136 if (handle_directive (pfile))
4137 return CPP_DIRECTIVE;
4138 pfile->only_seen_white = 0;
4143 /* A single quoted string is treated like a double -- some
4144 programs (e.g., troff) are perverse this way */
4145 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4146 &start_line, &start_column);
4147 old_written = CPP_WRITTEN (pfile);
4149 CPP_PUTC (pfile, c);
4155 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4157 /* try harder: this string crosses a macro expansion
4158 boundary. This can happen naturally if -traditional.
4159 Otherwise, only -D can make a macro with an unmatched
4161 cpp_buffer *next_buf
4162 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4163 (*CPP_BUFFER (pfile)->cleanup)
4164 (CPP_BUFFER (pfile), pfile);
4165 CPP_BUFFER (pfile) = next_buf;
4168 if (!CPP_TRADITIONAL (pfile))
4170 cpp_error_with_line (pfile, start_line, start_column,
4171 "unterminated string or character constant");
4172 if (pfile->multiline_string_line != start_line
4173 && pfile->multiline_string_line != 0)
4174 cpp_error_with_line (pfile,
4175 pfile->multiline_string_line, -1,
4176 "possible real start of unterminated constant");
4177 pfile->multiline_string_line = 0;
4181 CPP_PUTC (pfile, cc);
4185 /* Traditionally, end of line ends a string constant with
4186 no error. So exit the loop and record the new line. */
4187 if (CPP_TRADITIONAL (pfile))
4191 cpp_error_with_line (pfile, start_line, start_column,
4192 "unterminated character constant");
4195 if (CPP_PEDANTIC (pfile)
4196 && pfile->multiline_string_line == 0)
4198 cpp_pedwarn_with_line (pfile, start_line, start_column,
4199 "string constant runs past end of line");
4201 if (pfile->multiline_string_line == 0)
4202 pfile->multiline_string_line = start_line;
4209 /* Backslash newline is replaced by nothing at all. */
4210 CPP_ADJUST_WRITTEN (pfile, -1);
4215 /* ANSI stupidly requires that in \\ the second \
4216 is *not* prevented from combining with a newline. */
4219 CPP_PUTC (pfile, cc);
4231 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4232 CPP_PWRITTEN (pfile));
4233 pfile->only_seen_white = 0;
4234 return c == '\'' ? CPP_CHAR : CPP_STRING;
4237 if (!opts->dollars_in_ident)
4242 if (opts->cplusplus && PEEKC () == ':')
4251 if (c2 == c || c2 == '=')
4261 if (PEEKC () == '=')
4268 if (c2 == '-' && opts->chill)
4270 /* Chill style comment */
4271 if (opts->put_out_comments)
4272 parse_set_mark (&start_mark, pfile);
4273 FORWARD(1); /* Skip second '-'. */
4281 /* Don't consider final '\n' to be part of comment. */
4287 goto return_comment;
4289 if (c2 == '-' || c2 == '=' || c2 == '>')
4294 if (pfile->parsing_include_directive)
4298 CPP_PUTC (pfile, c);
4303 if (c == '\n' || c == EOF)
4306 "missing '>' in `#include <FILENAME>'");
4312 /* else fall through */
4321 CPP_RESERVE (pfile, 4);
4322 CPP_PUTC (pfile, c);
4323 CPP_PUTC (pfile, c2);
4327 CPP_PUTC_Q (pfile, GETC ());
4328 CPP_NUL_TERMINATE_Q (pfile);
4329 pfile->only_seen_white = 0;
4333 if (CPP_BUFFER (pfile)->has_escapes)
4338 if (pfile->output_escapes)
4339 CPP_PUTS (pfile, "@-", 2);
4340 parse_name (pfile, GETC ());
4343 else if (is_space [c])
4345 CPP_RESERVE (pfile, 2);
4346 if (pfile->output_escapes)
4347 CPP_PUTC_Q (pfile, '@');
4348 CPP_PUTC_Q (pfile, c);
4352 if (pfile->output_escapes)
4354 CPP_PUTS (pfile, "@@", 2);
4364 CPP_RESERVE(pfile, 2);
4365 CPP_PUTC_Q (pfile, '.');
4369 /* FIXME - misses the case "..\\\n." */
4370 if (c2 == '.' && PEEKN(1) == '.')
4372 CPP_RESERVE(pfile, 4);
4373 CPP_PUTC_Q (pfile, '.');
4374 CPP_PUTC_Q (pfile, '.');
4375 CPP_PUTC_Q (pfile, '.');
4377 CPP_NUL_TERMINATE_Q (pfile);
4378 pfile->only_seen_white = 0;
4385 pfile->only_seen_white = 0;
4387 CPP_RESERVE(pfile, 3);
4388 CPP_PUTC_Q (pfile, c);
4389 CPP_PUTC_Q (pfile, GETC ());
4390 CPP_NUL_TERMINATE_Q (pfile);
4396 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
4398 CPP_PUTC (pfile, c);
4404 case '0': case '1': case '2': case '3': case '4':
4405 case '5': case '6': case '7': case '8': case '9':
4410 CPP_RESERVE (pfile, 2);
4411 CPP_PUTC_Q (pfile, c);
4416 if (!is_idchar[c] && c != '.'
4417 && ((c2 != 'e' && c2 != 'E'
4418 && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
4419 || (c != '+' && c != '-')))
4424 CPP_NUL_TERMINATE_Q (pfile);
4425 pfile->only_seen_white = 0;
4427 case 'b': case 'c': case 'd': case 'h': case 'o':
4428 case 'B': case 'C': case 'D': case 'H': case 'O':
4429 if (opts->chill && PEEKC () == '\'')
4431 pfile->only_seen_white = 0;
4432 CPP_RESERVE (pfile, 2);
4433 CPP_PUTC_Q (pfile, c);
4434 CPP_PUTC_Q (pfile, '\'');
4440 goto chill_number_eof;
4443 if (c == '\\' && PEEKC() == '\n')
4450 CPP_PUTC (pfile, c);
4454 CPP_RESERVE (pfile, 2);
4455 CPP_PUTC_Q (pfile, c);
4456 CPP_NUL_TERMINATE_Q (pfile);
4463 CPP_NUL_TERMINATE (pfile);
4470 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
4471 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
4472 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
4473 case 'x': case 'y': case 'z':
4474 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
4475 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
4476 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
4481 unsigned char *ident;
4482 int before_name_written = CPP_WRITTEN (pfile);
4484 parse_name (pfile, c);
4485 pfile->only_seen_white = 0;
4486 if (pfile->no_macro_expand)
4488 ident = pfile->token_buffer + before_name_written;
4489 ident_len = CPP_PWRITTEN (pfile) - ident;
4490 hp = cpp_lookup (pfile, ident, ident_len, -1);
4493 if (hp->type == T_DISABLED)
4495 if (pfile->output_escapes)
4496 { /* Return "@-IDENT", followed by '\0'. */
4498 CPP_RESERVE (pfile, 3);
4499 ident = pfile->token_buffer + before_name_written;
4500 CPP_ADJUST_WRITTEN (pfile, 2);
4501 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
4508 /* If macro wants an arglist, verify that a '(' follows.
4509 first skip all whitespace, copying it to the output
4510 after the macro name. Then, if there is no '(',
4511 decide this is not a macro call and leave things that way. */
4512 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
4514 struct parse_marker macro_mark;
4515 int is_macro_call, macbuf_whitespace = 0;
4517 parse_set_mark (¯o_mark, pfile);
4520 cpp_skip_hspace (pfile);
4522 is_macro_call = c == '(';
4531 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4533 if (macro_mark.position !=
4534 (CPP_BUFFER (pfile)->cur
4535 - CPP_BUFFER (pfile)->buf))
4536 macbuf_whitespace = 1;
4538 parse_clear_mark (¯o_mark);
4539 cpp_pop_buffer (pfile);
4540 parse_set_mark (¯o_mark, pfile);
4548 parse_goto_mark (¯o_mark, pfile);
4549 if (macbuf_whitespace)
4550 CPP_PUTC (pfile, ' ');
4552 parse_clear_mark (¯o_mark);
4556 /* This is now known to be a macro call. */
4558 /* it might not actually be a macro. */
4559 if (hp->type != T_MACRO) {
4560 int xbuf_len; U_CHAR *xbuf;
4561 CPP_SET_WRITTEN (pfile, before_name_written);
4562 special_symbol (hp, pfile);
4563 xbuf_len = CPP_WRITTEN (pfile) - before_name_written;
4564 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
4565 CPP_SET_WRITTEN (pfile, before_name_written);
4566 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
4567 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
4571 /* Expand the macro, reading arguments as needed,
4572 and push the expansion on the input stack. */
4573 macroexpand (pfile, hp);
4574 CPP_SET_WRITTEN (pfile, before_name_written);
4577 /* An extra "@ " is added to the end of a macro expansion
4578 to prevent accidental token pasting. We prefer to avoid
4579 unneeded extra spaces (for the sake of cpp-using tools like
4580 imake). Here we remove the space if it is safe to do so. */
4581 if (pfile->buffer->rlimit - pfile->buffer->cur >= 3
4582 && pfile->buffer->rlimit[-2] == '@'
4583 && pfile->buffer->rlimit[-1] == ' ')
4585 int c1 = pfile->buffer->rlimit[-3];
4586 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
4587 if (c2 == EOF || ! unsafe_chars (c1, c2))
4588 pfile->buffer->rlimit -= 2;
4593 case ' ': case '\t': case '\v': case '\r':
4596 CPP_PUTC (pfile, c);
4598 if (c == EOF || !is_hor_space[c])
4612 CPP_PUTC (pfile, c);
4613 if (pfile->only_seen_white == 0)
4614 pfile->only_seen_white = 1;
4616 output_line_command (pfile, 1, same_file);
4619 case '(': token = CPP_LPAREN; goto char1;
4620 case ')': token = CPP_RPAREN; goto char1;
4621 case '{': token = CPP_LBRACE; goto char1;
4622 case '}': token = CPP_RBRACE; goto char1;
4623 case ',': token = CPP_COMMA; goto char1;
4624 case ';': token = CPP_SEMICOLON; goto char1;
4630 pfile->only_seen_white = 0;
4631 CPP_PUTC (pfile, c);
4637 /* Like cpp_get_token, but skip spaces and comments. */
4640 cpp_get_non_space_token (pfile)
4643 int old_written = CPP_WRITTEN (pfile);
4646 enum cpp_token token = cpp_get_token (pfile);
4647 if (token != CPP_COMMENT && token != CPP_POP
4648 && token != CPP_HSPACE && token != CPP_VSPACE)
4650 CPP_SET_WRITTEN (pfile, old_written);
4654 /* Parse an identifier starting with C. */
4657 parse_name (pfile, c)
4658 cpp_reader *pfile; int c;
4664 if (c == '\\' && PEEKC() == '\n')
4673 if (c == '$' && CPP_PEDANTIC (pfile))
4674 cpp_pedwarn (pfile, "`$' in identifier");
4676 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
4677 CPP_PUTC_Q (pfile, c);
4682 CPP_NUL_TERMINATE_Q (pfile);
4686 /* This is called after options have been processed.
4687 * Check options for consistency, and setup for processing input
4688 * from the file named FNAME. (Use standard input if FNAME==NULL.)
4689 * Return 1 on success, 0 on failure.
4693 cpp_start_read (pfile, fname)
4697 struct cpp_options *opts = CPP_OPTIONS (pfile);
4698 struct cpp_pending *pend;
4702 struct include_hash *ih_fake;
4704 /* The code looks at the defaults through this pointer, rather than through
4705 the constant structure above. This pointer gets changed if an environment
4706 variable specifies other defaults. */
4707 struct default_include *include_defaults = include_defaults_array;
4709 /* Now that we know dollars_in_ident for real,
4710 reset is_idchar/is_idstart. */
4711 is_idchar['$'] = opts->dollars_in_ident;
4712 is_idstart['$'] = opts->dollars_in_ident;
4714 /* Add dirs from CPATH after dirs from -I. */
4715 /* There seems to be confusion about what CPATH should do,
4716 so for the moment it is not documented. */
4717 /* Some people say that CPATH should replace the standard include dirs,
4718 but that seems pointless: it comes before them, so it overrides them
4720 GET_ENV_PATH_LIST (p, "CPATH");
4721 if (p != 0 && ! opts->no_standard_includes)
4722 path_include (pfile, p);
4724 /* Do partial setup of input buffer for the sake of generating
4725 early #line directives (when -g is in effect). */
4726 fp = cpp_push_buffer (pfile, NULL, 0);
4729 if (opts->in_fname == NULL || *opts->in_fname == 0)
4731 opts->in_fname = fname;
4732 if (opts->in_fname == NULL)
4733 opts->in_fname = "";
4735 fp->nominal_fname = fp->fname = opts->in_fname;
4738 /* Install __LINE__, etc. Must follow initialize_char_syntax
4739 and option processing. */
4740 initialize_builtins (pfile);
4742 /* Do standard #defines and assertions
4743 that identify system and machine type. */
4745 if (!opts->inhibit_predefs) {
4746 char *p = (char *) alloca (strlen (predefs) + 1);
4747 strcpy (p, predefs);
4750 while (*p == ' ' || *p == '\t')
4752 /* Handle -D options. */
4753 if (p[0] == '-' && p[1] == 'D') {
4755 while (*p && *p != ' ' && *p != '\t')
4759 if (opts->debug_output)
4760 output_line_command (pfile, 0, same_file);
4761 cpp_define (pfile, q);
4762 while (*p == ' ' || *p == '\t')
4764 } else if (p[0] == '-' && p[1] == 'A') {
4765 /* Handle -A options (assertions). */
4774 past_name = assertion;
4775 /* Locate end of name. */
4776 while (*past_name && *past_name != ' '
4777 && *past_name != '\t' && *past_name != '(')
4779 /* Locate `(' at start of value. */
4781 while (*value && (*value == ' ' || *value == '\t'))
4783 if (*value++ != '(')
4785 while (*value && (*value == ' ' || *value == '\t'))
4788 /* Locate end of value. */
4789 while (*past_value && *past_value != ' '
4790 && *past_value != '\t' && *past_value != ')')
4792 termination = past_value;
4793 while (*termination && (*termination == ' ' || *termination == '\t'))
4795 if (*termination++ != ')')
4797 if (*termination && *termination != ' ' && *termination != '\t')
4799 /* Temporarily null-terminate the value. */
4800 save_char = *termination;
4801 *termination = '\0';
4802 /* Install the assertion. */
4803 make_assertion (pfile, "-A", assertion);
4804 *termination = (char) save_char;
4806 while (*p == ' ' || *p == '\t')
4814 /* Now handle the command line options. */
4816 /* Do -U's, -D's and -A's in the order they were seen. */
4817 /* First reverse the list. */
4818 opts->pending = nreverse_pending (opts->pending);
4820 for (pend = opts->pending; pend; pend = pend->next)
4822 if (pend->cmd != NULL && pend->cmd[0] == '-')
4824 switch (pend->cmd[1])
4827 if (opts->debug_output)
4828 output_line_command (pfile, 0, same_file);
4829 cpp_undef (pfile, pend->arg);
4832 if (opts->debug_output)
4833 output_line_command (pfile, 0, same_file);
4834 cpp_define (pfile, pend->arg);
4837 make_assertion (pfile, "-A", pend->arg);
4843 opts->done_initializing = 1;
4845 { /* Read the appropriate environment variable and if it exists
4846 replace include_defaults with the listed path. */
4848 switch ((opts->objc << 1) + opts->cplusplus)
4851 GET_ENV_PATH_LIST (epath, "C_INCLUDE_PATH");
4854 GET_ENV_PATH_LIST (epath, "CPLUS_INCLUDE_PATH");
4857 GET_ENV_PATH_LIST (epath, "OBJC_INCLUDE_PATH");
4860 GET_ENV_PATH_LIST (epath, "OBJCPLUS_INCLUDE_PATH");
4863 /* If the environment var for this language is set,
4864 add to the default list of include directories. */
4866 char *nstore = (char *) alloca (strlen (epath) + 2);
4868 char *startp, *endp;
4870 for (num_dirs = 1, startp = epath; *startp; startp++)
4871 if (*startp == PATH_SEPARATOR)
4874 = (struct default_include *) xmalloc ((num_dirs
4875 * sizeof (struct default_include))
4876 + sizeof (include_defaults_array));
4877 startp = endp = epath;
4880 /* Handle cases like c:/usr/lib:d:/gcc/lib */
4881 if ((*endp == PATH_SEPARATOR)
4883 strncpy (nstore, startp, endp-startp);
4885 strcpy (nstore, ".");
4887 nstore[endp-startp] = '\0';
4889 include_defaults[num_dirs].fname = xstrdup (nstore);
4890 include_defaults[num_dirs].component = 0;
4891 include_defaults[num_dirs].cplusplus = opts->cplusplus;
4892 include_defaults[num_dirs].cxx_aware = 1;
4896 endp = startp = endp + 1;
4900 /* Put the usual defaults back in at the end. */
4901 bcopy ((char *) include_defaults_array,
4902 (char *) &include_defaults[num_dirs],
4903 sizeof (include_defaults_array));
4907 /* Unless -fnostdinc,
4908 tack on the standard include file dirs to the specified list */
4909 if (!opts->no_standard_includes) {
4910 struct default_include *p = include_defaults;
4911 char *specd_prefix = opts->include_prefix;
4912 char *default_prefix = xstrdup (GCC_INCLUDE_DIR);
4913 int default_len = 0;
4914 /* Remove the `include' from /usr/local/lib/gcc.../include. */
4915 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
4916 default_len = strlen (default_prefix) - 7;
4917 default_prefix[default_len] = 0;
4919 /* Search "translated" versions of GNU directories.
4920 These have /usr/local/lib/gcc... replaced by specd_prefix. */
4921 if (specd_prefix != 0 && default_len != 0)
4922 for (p = include_defaults; p->fname; p++) {
4923 /* Some standard dirs are only for C++. */
4925 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
4926 /* Does this dir start with the prefix? */
4927 if (!strncmp (p->fname, default_prefix, default_len)) {
4928 /* Yes; change prefix and add to search list. */
4929 int this_len = strlen (specd_prefix)
4930 + strlen (p->fname) - default_len;
4931 char *str = (char *) xmalloc (this_len + 1);
4932 strcpy (str, specd_prefix);
4933 strcat (str, p->fname + default_len);
4935 append_include_chain (pfile, &opts->system_include,
4936 str, !p->cxx_aware);
4940 /* Search ordinary names for GNU include directories. */
4941 for (p = include_defaults; p->fname; p++) {
4942 /* Some standard dirs are only for C++. */
4944 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
4945 char *str = update_path (p->fname, p->component);
4946 append_include_chain (pfile, &opts->system_include,
4947 str, !p->cxx_aware);
4952 merge_include_chains (opts);
4954 /* With -v, print the list of dirs to search. */
4955 if (opts->verbose) {
4956 struct file_name_list *p;
4957 fprintf (stderr, "#include \"...\" search starts here:\n");
4958 for (p = opts->quote_include; p; p = p->next) {
4959 if (p == opts->bracket_include)
4960 fprintf (stderr, "#include <...> search starts here:\n");
4961 fprintf (stderr, " %s\n", p->name);
4963 fprintf (stderr, "End of search list.\n");
4966 /* Copy the entire contents of the main input file into
4967 the stacked input buffer previously allocated for it. */
4968 if (fname == NULL || *fname == 0) {
4971 } else if ((f = open (fname, O_RDONLY, 0666)) < 0)
4972 cpp_pfatal_with_name (pfile, fname);
4974 /* -MG doesn't select the form of output and must be specified with one of
4975 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
4976 inhibit compilation. */
4977 if (opts->print_deps_missing_files
4978 && (opts->print_deps == 0 || !opts->no_output))
4980 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
4984 /* Either of two environment variables can specify output of deps.
4985 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
4986 where OUTPUT_FILE is the file to write deps info to
4987 and DEPS_TARGET is the target to mention in the deps. */
4989 if (opts->print_deps == 0
4990 && (getenv ("SUNPRO_DEPENDENCIES") != 0
4991 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
4992 char *spec = getenv ("DEPENDENCIES_OUTPUT");
4998 spec = getenv ("SUNPRO_DEPENDENCIES");
4999 opts->print_deps = 2;
5002 opts->print_deps = 1;
5005 /* Find the space before the DEPS_TARGET, if there is one. */
5006 /* This should use index. (mrs) */
5007 while (*s != 0 && *s != ' ') s++;
5010 opts->deps_target = s + 1;
5011 output_file = (char *) xmalloc (s - spec + 1);
5012 bcopy (spec, output_file, s - spec);
5013 output_file[s - spec] = 0;
5017 opts->deps_target = 0;
5021 opts->deps_file = output_file;
5022 opts->print_deps_append = 1;
5025 /* For -M, print the expected object file name
5026 as the target of this Make-rule. */
5027 if (opts->print_deps)
5029 pfile->deps_allocated_size = 200;
5030 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
5031 pfile->deps_buffer[0] = 0;
5032 pfile->deps_size = 0;
5033 pfile->deps_column = 0;
5035 if (opts->deps_target)
5036 deps_output (pfile, opts->deps_target, ':');
5037 else if (*opts->in_fname == 0)
5038 deps_output (pfile, "-", ':');
5043 static char *known_suffixes[] = { ".c", ".C", ".s", ".S", ".m",
5044 ".cc", ".cxx", ".cpp", ".cp",
5048 /* Discard all directory prefixes from filename. */
5049 if ((q = rindex (opts->in_fname, '/')) != NULL
5050 #ifdef DIR_SEPARATOR
5051 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
5058 /* Copy remainder to mungable area. */
5059 p = (char *) alloca (strlen(q) + 8);
5062 /* Output P, but remove known suffixes. */
5065 /* Point to the filename suffix. */
5066 r = rindex (p, '.');
5067 /* Compare against the known suffixes. */
5069 while (known_suffixes[x] != 0)
5071 if (strncmp (known_suffixes[x], r, q - r) == 0)
5073 /* Make q point to the bit we're going to overwrite
5074 with an object suffix. */
5081 /* Supply our own suffix. */
5088 deps_output (pfile, p, ':');
5089 deps_output (pfile, opts->in_fname, ' ');
5094 /* Make sure data ends with a newline. And put a null after it. */
5096 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
5097 /* Backslash-newline at end is not good enough. */
5098 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
5099 fp->buf[fp->length++] = '\n';
5100 missing_newline = 1;
5102 fp->buf[fp->length] = '\0';
5104 /* Unless inhibited, convert trigraphs in the input. */
5110 /* Must call finclude() on the main input before processing
5111 -include switches; otherwise the -included text winds up
5112 after the main input. */
5113 ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
5115 ih_fake->next_this_file = 0;
5116 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5117 ih_fake->name = fname;
5118 ih_fake->control_macro = 0;
5119 ih_fake->buf = (char *)-1;
5121 if (!finclude (pfile, f, ih_fake))
5123 output_line_command (pfile, 0, same_file);
5124 pfile->only_seen_white = 2;
5126 /* The -imacros files can be scanned now, but the -include files
5127 have to be pushed onto the include stack and processed later,
5128 in the main loop calling cpp_get_token. That means the -include
5129 files have to be processed in reverse order of the pending list,
5130 which means the pending list has to be reversed again, which
5131 means the -imacros files have to be done separately and first. */
5133 pfile->no_record_file++;
5135 for (pend = opts->pending; pend; pend = pend->next)
5137 if (pend->cmd != NULL)
5139 if (strcmp (pend->cmd, "-imacros") == 0)
5141 int fd = open (pend->arg, O_RDONLY, 0666);
5144 cpp_perror_with_name (pfile, pend->arg);
5147 if (!cpp_push_buffer (pfile, NULL, 0))
5150 ih_fake = (struct include_hash *)
5151 xmalloc (sizeof (struct include_hash));
5153 ih_fake->next_this_file = 0;
5154 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5155 ih_fake->name = pend->arg;
5156 ih_fake->control_macro = 0;
5157 ih_fake->buf = (char *)-1;
5159 if (!finclude (pfile, fd, ih_fake))
5160 cpp_scan_buffer (pfile);
5166 opts->pending = nreverse_pending (opts->pending);
5167 for (pend = opts->pending; pend; pend = pend->next)
5169 if (pend->cmd != NULL)
5171 if (strcmp (pend->cmd, "-include") == 0)
5173 int fd = open (pend->arg, O_RDONLY, 0666);
5176 cpp_perror_with_name (pfile, pend->arg);
5179 if (!cpp_push_buffer (pfile, NULL, 0))
5182 ih_fake = (struct include_hash *)
5183 xmalloc (sizeof (struct include_hash));
5185 ih_fake->next_this_file = 0;
5186 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5187 ih_fake->name = pend->arg;
5188 ih_fake->control_macro = 0;
5189 ih_fake->buf = (char *)-1;
5191 if (finclude (pfile, fd, ih_fake))
5192 output_line_command (pfile, 0, enter_file);
5196 pfile->no_record_file--;
5198 /* Free the pending list. */
5199 for (pend = opts->pending; pend; )
5201 struct cpp_pending *next = pend->next;
5205 opts->pending = NULL;
5211 cpp_reader_init (pfile)
5214 bzero ((char *) pfile, sizeof (cpp_reader));
5215 pfile->get_token = cpp_get_token;
5217 pfile->token_buffer_size = 200;
5218 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
5219 CPP_SET_WRITTEN (pfile, 0);
5221 pfile->timebuf = NULL;
5222 pfile->only_seen_white = 1;
5223 pfile->buffer = CPP_NULL_BUFFER(pfile);
5224 pfile->actual_dirs = NULL;
5227 static struct cpp_pending *
5228 nreverse_pending (list)
5229 struct cpp_pending *list;
5232 register struct cpp_pending *prev = 0, *next, *pend;
5233 for (pend = list; pend; pend = next)
5243 push_pending (pfile, cmd, arg)
5248 struct cpp_pending *pend
5249 = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
5252 pend->next = CPP_OPTIONS (pfile)->pending;
5253 CPP_OPTIONS (pfile)->pending = pend;
5260 printf ("Usage: %s [switches] input output\n", progname);
5261 printf ("Switches:\n");
5262 printf (" -include <file> Include the contents of <file> before other files\n");
5263 printf (" -imacros <file> Accept definition of marcos in <file>\n");
5264 printf (" -iprefix <path> Specify <path> as a prefix for next two options\n");
5265 printf (" -iwithprefix <dir> Add <dir> to the end of the system include paths\n");
5266 printf (" -iwithprefixbefore <dir> Add <dir> to the end of the main include paths\n");
5267 printf (" -isystem <dir> Add <dir> to the start of the system include paths\n");
5268 printf (" -idirafter <dir> Add <dir> to the end of the system include paths\n");
5269 printf (" -I <dir> Add <dir> to the end of the main include paths\n");
5270 printf (" -nostdinc Do not search the system include directories\n");
5271 printf (" -nostdinc++ Do not search the system include directories for C++\n");
5272 printf (" -o <file> Put output into <file>\n");
5273 printf (" -pedantic Issue all warnings demanded by strict ANSI C\n");
5274 printf (" -traditional Follow K&R pre-processor behaviour\n");
5275 printf (" -trigraphs Support ANSI C trigraphs\n");
5276 printf (" -lang-c Assume that the input sources are in C\n");
5277 printf (" -lang-c89 Assume that the input sources are in C89\n");
5278 printf (" -lang-c++ Assume that the input sources are in C++\n");
5279 printf (" -lang-objc Assume that the input sources are in ObjectiveC\n");
5280 printf (" -lang-objc++ Assume that the input sources are in ObjectiveC++\n");
5281 printf (" -lang-asm Assume that the input sources are in assembler\n");
5282 printf (" -lang-chill Assume that the input sources are in Chill\n");
5283 printf (" -+ Allow parsing of C++ style features\n");
5284 printf (" -w Inhibit warning messages\n");
5285 printf (" -Wtrigraphs Warn if trigraphs are encountered\n");
5286 printf (" -Wno-trigraphs Do not warn about trigraphs\n");
5287 printf (" -Wcomment{s} Warn if one comment starts inside another\n");
5288 printf (" -Wno-comment{s} Do not warn about comments\n");
5289 printf (" -Wtraditional Warn if a macro argument is/would be turned into\n");
5290 printf (" a string if -tradtional is specified\n");
5291 printf (" -Wno-traditional Do not warn about stringification\n");
5292 printf (" -Wundef Warn if an undefined macro is used by #if\n");
5293 printf (" -Wno-undef Do not warn about testing udefined macros\n");
5294 printf (" -Wimport Warn about the use of the #import directive\n");
5295 printf (" -Wno-import Do not warn about the use of #import\n");
5296 printf (" -Werror Treat all warnings as errors\n");
5297 printf (" -Wno-error Do not treat warnings as errors\n");
5298 printf (" -Wall Enable all preprocessor warnings\n");
5299 printf (" -M Generate make dependencies\n");
5300 printf (" -MM As -M, but ignore system header files\n");
5301 printf (" -MD As -M, but put output in a .d file\n");
5302 printf (" -MMD As -MD, but ignore system header files\n");
5303 printf (" -MG Treat missing header file as generated files\n");
5304 printf (" -g Include #define and #undef directives in the output\n");
5305 printf (" -D<macro> Define a <macro> with string '1' as its value\n");
5306 printf (" -D<macro>=<val> Define a <macro> with <val> as its value\n");
5307 printf (" -A<question> (<answer>) Assert the <answer> to <question>\n");
5308 printf (" -U<macro> Undefine <macro> \n");
5309 printf (" -u or -undef Do not predefine any macros\n");
5310 printf (" -v Display the version number\n");
5311 printf (" -H Print the name of header files as they are used\n");
5312 printf (" -C Do not discard comments\n");
5313 printf (" -dM Display a list of macro definitions active at end\n");
5314 printf (" -dD Preserve macro definitions in output\n");
5315 printf (" -dN As -dD except that only the names are preserved\n");
5316 printf (" -dI Include #include directives in the output\n");
5317 printf (" -ifoutput Describe skipped code blocks in output \n");
5318 printf (" -P Do not generate #line directives\n");
5319 printf (" -$ Do not include '$' in identifiers\n");
5320 printf (" -remap Remap file names when including files.\n");
5321 printf (" -h or --help Display this information\n");
5325 /* Handle one command-line option in (argc, argv).
5326 Can be called multiple times, to handle multiple sets of options.
5327 Returns number of strings consumed. */
5329 cpp_handle_option (pfile, argc, argv)
5334 struct cpp_options *opts = CPP_OPTIONS (pfile);
5337 if (user_label_prefix == NULL)
5338 user_label_prefix = USER_LABEL_PREFIX;
5340 if (argv[i][0] != '-') {
5341 if (opts->out_fname != NULL)
5344 cpp_fatal (pfile, "Too many arguments");
5346 else if (opts->in_fname != NULL)
5347 opts->out_fname = argv[i];
5349 opts->in_fname = argv[i];
5351 switch (argv[i][1]) {
5354 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
5357 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
5361 if (!strcmp (argv[i], "-fleading-underscore"))
5362 user_label_prefix = "_";
5363 else if (!strcmp (argv[i], "-fno-leading-underscore"))
5364 user_label_prefix = "";
5367 case 'I': /* Add directory to path for includes. */
5368 if (!strcmp (argv[i] + 2, "-"))
5370 if (! opts->ignore_srcdir)
5372 opts->ignore_srcdir = 1;
5373 /* Don't use any preceding -I directories for #include <...>. */
5374 opts->quote_include = opts->bracket_include;
5375 opts->bracket_include = 0;
5381 if (argv[i][2] != 0)
5382 fname = argv[i] + 2;
5383 else if (i + 1 == argc)
5384 goto missing_dirname;
5387 append_include_chain (pfile, &opts->bracket_include, fname, 0);
5392 /* Add directory to beginning of system include path, as a system
5393 include directory. */
5394 if (!strcmp (argv[i], "-isystem"))
5397 goto missing_filename;
5398 append_include_chain (pfile, &opts->system_include, argv[++i], 1);
5400 /* Add directory to end of path for includes,
5401 with the default prefix at the front of its name. */
5402 else if (!strcmp (argv[i], "-iwithprefix"))
5406 goto missing_dirname;
5409 if (opts->include_prefix != 0)
5411 fname = xmalloc (strlen (opts->include_prefix)
5412 + strlen (argv[i]) + 1);
5413 strcpy (fname, opts->include_prefix);
5414 strcat (fname, argv[i]);
5418 fname = xmalloc (strlen (GCC_INCLUDE_DIR)
5419 + strlen (argv[i]) + 1);
5420 strcpy (fname, GCC_INCLUDE_DIR);
5421 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5422 if (!strcmp (fname + strlen (fname) - 8, "/include"))
5423 fname[strlen (fname) - 7] = 0;
5424 strcat (fname, argv[i]);
5427 append_include_chain (pfile, &opts->system_include, fname, 0);
5429 /* Add directory to main path for includes,
5430 with the default prefix at the front of its name. */
5431 else if (!strcmp (argv[i], "-iwithprefix"))
5435 goto missing_dirname;
5438 if (opts->include_prefix != 0)
5440 fname = xmalloc (strlen (opts->include_prefix)
5441 + strlen (argv[i]) + 1);
5442 strcpy (fname, opts->include_prefix);
5443 strcat (fname, argv[i]);
5447 fname = xmalloc (strlen (GCC_INCLUDE_DIR)
5448 + strlen (argv[i]) + 1);
5449 strcpy (fname, GCC_INCLUDE_DIR);
5450 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5451 if (!strcmp (fname + strlen (fname) - 8, "/include"))
5452 fname[strlen (fname) - 7] = 0;
5453 strcat (fname, argv[i]);
5456 append_include_chain (pfile, &opts->bracket_include, fname, 0);
5458 /* Add directory to end of path for includes. */
5459 else if (!strcmp (argv[i], "-idirafter"))
5462 goto missing_dirname;
5463 append_include_chain (pfile, &opts->after_include, argv[++i], 0);
5465 else if (!strcmp (argv[i], "-include") || !strcmp (argv[i], "-imacros"))
5468 goto missing_filename;
5470 push_pending (pfile, argv[i], argv[i+1]), i++;
5472 else if (!strcmp (argv[i], "-iprefix"))
5475 goto missing_filename;
5477 opts->include_prefix = argv[++i];
5479 else if (!strcmp (argv[i], "-ifoutput"))
5480 opts->output_conditionals = 1;
5485 if (opts->out_fname != NULL)
5487 cpp_fatal (pfile, "Output filename specified twice");
5491 goto missing_filename;
5492 opts->out_fname = argv[++i];
5493 if (!strcmp (opts->out_fname, "-"))
5494 opts->out_fname = "";
5498 if (!strcmp (argv[i], "-pedantic"))
5499 CPP_PEDANTIC (pfile) = 1;
5500 else if (!strcmp (argv[i], "-pedantic-errors")) {
5501 CPP_PEDANTIC (pfile) = 1;
5502 opts->pedantic_errors = 1;
5505 else if (!strcmp (argv[i], "-pcp")) {
5506 char *pcp_fname = argv[++i];
5507 pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
5508 ? fopen (pcp_fname, "w")
5509 : fdopen (dup (fileno (stdout)), "w"));
5510 if (pcp_outfile == 0)
5511 cpp_pfatal_with_name (pfile, pcp_fname);
5518 if (!strcmp (argv[i], "-traditional")) {
5519 opts->traditional = 1;
5520 opts->cplusplus_comments = 0;
5521 } else if (!strcmp (argv[i], "-trigraphs")) {
5523 opts->no_trigraphs = 0;
5528 if (! strcmp (argv[i], "-lang-c"))
5529 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
5531 if (! strcmp (argv[i], "-lang-c89"))
5532 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1,
5534 if (! strcmp (argv[i], "-lang-c++"))
5535 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
5537 if (! strcmp (argv[i], "-lang-objc"))
5538 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
5540 if (! strcmp (argv[i], "-lang-objc++"))
5541 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
5543 if (! strcmp (argv[i], "-lang-asm"))
5545 if (! strcmp (argv[i], "-lint"))
5547 if (! strcmp (argv[i], "-lang-chill"))
5548 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
5549 opts->traditional = 1, opts->no_trigraphs = 1;
5553 opts->cplusplus = 1, opts->cplusplus_comments = 1;
5557 opts->inhibit_warnings = 1;
5561 if (!strcmp (argv[i], "-Wtrigraphs"))
5562 opts->warn_trigraphs = 1;
5563 else if (!strcmp (argv[i], "-Wno-trigraphs"))
5564 opts->warn_trigraphs = 0;
5565 else if (!strcmp (argv[i], "-Wcomment"))
5566 opts->warn_comments = 1;
5567 else if (!strcmp (argv[i], "-Wno-comment"))
5568 opts->warn_comments = 0;
5569 else if (!strcmp (argv[i], "-Wcomments"))
5570 opts->warn_comments = 1;
5571 else if (!strcmp (argv[i], "-Wno-comments"))
5572 opts->warn_comments = 0;
5573 else if (!strcmp (argv[i], "-Wtraditional"))
5574 opts->warn_stringify = 1;
5575 else if (!strcmp (argv[i], "-Wno-traditional"))
5576 opts->warn_stringify = 0;
5577 else if (!strcmp (argv[i], "-Wundef"))
5578 opts->warn_undef = 1;
5579 else if (!strcmp (argv[i], "-Wno-undef"))
5580 opts->warn_undef = 0;
5581 else if (!strcmp (argv[i], "-Wimport"))
5582 opts->warn_import = 1;
5583 else if (!strcmp (argv[i], "-Wno-import"))
5584 opts->warn_import = 0;
5585 else if (!strcmp (argv[i], "-Werror"))
5586 opts->warnings_are_errors = 1;
5587 else if (!strcmp (argv[i], "-Wno-error"))
5588 opts->warnings_are_errors = 0;
5589 else if (!strcmp (argv[i], "-Wall"))
5591 opts->warn_trigraphs = 1;
5592 opts->warn_comments = 1;
5597 /* The style of the choices here is a bit mixed.
5598 The chosen scheme is a hybrid of keeping all options in one string
5599 and specifying each option in a separate argument:
5600 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
5601 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
5602 -M[M][G][D file]. This is awkward to handle in specs, and is not
5604 /* ??? -MG must be specified in addition to one of -M or -MM.
5605 This can be relaxed in the future without breaking anything.
5606 The converse isn't true. */
5608 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
5609 if (!strcmp (argv[i], "-MG"))
5611 opts->print_deps_missing_files = 1;
5614 if (!strcmp (argv[i], "-M"))
5615 opts->print_deps = 2;
5616 else if (!strcmp (argv[i], "-MM"))
5617 opts->print_deps = 1;
5618 else if (!strcmp (argv[i], "-MD"))
5619 opts->print_deps = 2;
5620 else if (!strcmp (argv[i], "-MMD"))
5621 opts->print_deps = 1;
5622 /* For -MD and -MMD options, write deps on file named by next arg. */
5623 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
5626 goto missing_filename;
5627 opts->deps_file = argv[++i];
5631 /* For -M and -MM, write deps on standard output
5632 and suppress the usual output. */
5633 opts->no_output = 1;
5639 char *p = argv[i] + 2;
5641 while ((c = *p++) != 0) {
5642 /* Arg to -d specifies what parts of macros to dump */
5645 opts->dump_macros = dump_only;
5646 opts->no_output = 1;
5649 opts->dump_macros = dump_names;
5652 opts->dump_macros = dump_definitions;
5655 opts->dump_includes = 1;
5663 if (argv[i][2] == '3')
5664 opts->debug_output = 1;
5668 if (strcmp (argv[i], "--help") != 0)
5674 fprintf (stderr, "GNU CPP version %s", version_string);
5675 #ifdef TARGET_VERSION
5678 fprintf (stderr, "\n");
5683 opts->print_include_names = 1;
5687 if (argv[i][2] != 0)
5688 push_pending (pfile, "-D", argv[i] + 2);
5689 else if (i + 1 == argc)
5691 cpp_fatal (pfile, "Macro name missing after -D option");
5695 i++, push_pending (pfile, "-D", argv[i]);
5702 if (argv[i][2] != 0)
5704 else if (i + 1 == argc)
5706 cpp_fatal (pfile, "Assertion missing after -A option");
5712 if (!strcmp (p, "-")) {
5713 struct cpp_pending **ptr;
5714 /* -A- eliminates all predefined macros and assertions.
5715 Let's include also any that were specified earlier
5716 on the command line. That way we can get rid of any
5717 that were passed automatically in from GCC. */
5718 opts->inhibit_predefs = 1;
5719 for (ptr = &opts->pending; *ptr != NULL; )
5721 struct cpp_pending *pend = *ptr;
5722 if (pend->cmd && pend->cmd[0] == '-'
5723 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
5732 push_pending (pfile, "-A", p);
5737 case 'U': /* JF #undef something */
5738 if (argv[i][2] != 0)
5739 push_pending (pfile, "-U", argv[i] + 2);
5740 else if (i + 1 == argc)
5742 cpp_fatal (pfile, "Macro name missing after -U option");
5746 push_pending (pfile, "-U", argv[i+1]), i++;
5750 opts->put_out_comments = 1;
5753 case 'E': /* -E comes from cc -E; ignore it. */
5757 opts->no_line_commands = 1;
5760 case '$': /* Don't include $ in identifiers. */
5761 opts->dollars_in_ident = 0;
5765 if (!strcmp (argv[i], "-nostdinc"))
5766 /* -nostdinc causes no default include directories.
5767 You must specify all include-file directories with -I. */
5768 opts->no_standard_includes = 1;
5769 else if (!strcmp (argv[i], "-nostdinc++"))
5770 /* -nostdinc++ causes no default C++-specific include directories. */
5771 opts->no_standard_cplusplus_includes = 1;
5773 else if (!strcmp (argv[i], "-noprecomp"))
5779 if (!strcmp (argv[i], "-remap"))
5784 /* Sun compiler passes undocumented switch "-undef".
5785 Let's assume it means to inhibit the predefined symbols. */
5786 opts->inhibit_predefs = 1;
5789 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
5790 if (opts->in_fname == NULL) {
5791 opts->in_fname = "";
5793 } else if (opts->out_fname == NULL) {
5794 opts->out_fname = "";
5796 } /* else fall through into error */
5806 /* Handle command-line options in (argc, argv).
5807 Can be called multiple times, to handle multiple sets of options.
5808 Returns if an unrecognized option is seen.
5809 Returns number of strings consumed. */
5812 cpp_handle_options (pfile, argc, argv)
5818 int strings_processed;
5819 for (i = 0; i < argc; i += strings_processed)
5821 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
5822 if (strings_processed == 0)
5832 struct cpp_options *opts = CPP_OPTIONS (pfile);
5834 if (opts->print_deps)
5836 /* Stream on which to print the dependency information. */
5839 /* Don't actually write the deps file if compilation has failed. */
5840 if (pfile->errors == 0)
5842 char *deps_mode = opts->print_deps_append ? "a" : "w";
5843 if (opts->deps_file == 0)
5844 deps_stream = stdout;
5845 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
5846 cpp_pfatal_with_name (pfile, opts->deps_file);
5847 fputs (pfile->deps_buffer, deps_stream);
5848 putc ('\n', deps_stream);
5849 if (opts->deps_file)
5851 if (ferror (deps_stream) || fclose (deps_stream) != 0)
5852 cpp_fatal (pfile, "I/O error on output");
5858 /* Debugging: dump statistics on the include hash table. */
5860 struct include_hash *x;
5863 for(i = 0; i < ALL_INCLUDE_HASHSIZE; i++)
5865 x = pfile->all_include_files[i];
5872 fprintf(stderr, "%d/%d ", i, j);
5874 fputc('\n', stderr);
5880 /* Free resources used by PFILE.
5881 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
5888 while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
5889 cpp_pop_buffer (pfile);
5891 if (pfile->token_buffer)
5893 free (pfile->token_buffer);
5894 pfile->token_buffer = NULL;
5897 if (pfile->deps_buffer)
5899 free (pfile->deps_buffer);
5900 pfile->deps_buffer = NULL;
5901 pfile->deps_allocated_size = 0;
5904 while (pfile->if_stack)
5906 IF_STACK_FRAME *temp = pfile->if_stack;
5907 pfile->if_stack = temp->next;
5911 for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; )
5913 struct include_hash *imp = pfile->all_include_files[i];
5916 struct include_hash *next = imp->next;
5918 /* This gets freed elsewhere - I think. */
5924 pfile->all_include_files[i] = 0;
5927 cpp_hash_cleanup (pfile);
5930 /* Read an assertion into the token buffer, converting to
5931 canonical form: `#predicate(a n swe r)' The next non-whitespace
5932 character to read should be the first letter of the predicate.
5933 Returns 0 for syntax error, 1 for bare predicate, 2 for predicate
5934 with answer (see callers for why). In case of 0, an error has been
5937 parse_assertion (pfile)
5941 cpp_skip_hspace (pfile);
5943 if (! is_idstart[c])
5945 cpp_error (pfile, "assertion predicate is not an identifier");
5948 CPP_PUTC(pfile, '#');
5950 parse_name(pfile, c);
5955 if (is_hor_space[c])
5956 cpp_skip_hspace (pfile);
5962 CPP_PUTC(pfile, '(');
5965 while ((c = GETC()) != ')')
5967 if (is_hor_space[c])
5971 CPP_PUTC(pfile, ' ');
5975 else if (c == '\\' && PEEKC() == '\n')
5977 else if (c == '\n' || c == EOF)
5979 if (c == '\n') FORWARD(-1);
5980 cpp_error (pfile, "un-terminated assertion answer");
5990 if (pfile->limit[-1] == ' ')
5991 pfile->limit[-1] = ')';
5992 else if (pfile->limit[-1] == '(')
5994 cpp_error (pfile, "empty token sequence in assertion");
5998 CPP_PUTC(pfile, ')');
6000 CPP_NUL_TERMINATE(pfile);
6005 do_assert (pfile, keyword)
6007 struct directive *keyword ATTRIBUTE_UNUSED;
6011 HASHNODE *base, *this;
6012 int baselen, thislen;
6014 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6015 && !CPP_BUFFER (pfile)->system_header_p)
6016 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6018 cpp_skip_hspace (pfile);
6019 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
6020 ret = parse_assertion (pfile);
6025 cpp_error (pfile, "missing token-sequence in `#assert'");
6029 cpp_skip_hspace (pfile);
6031 if (c != EOF && c != '\n')
6033 cpp_error (pfile, "junk at end of `#assert'");
6037 thislen = strlen (sym);
6038 baselen = index (sym, '(') - sym;
6039 this = cpp_lookup (pfile, sym, thislen, -1);
6042 cpp_warning (pfile, "`%s' re-asserted", sym);
6046 base = cpp_lookup (pfile, sym, baselen, -1);
6048 base = install (sym, baselen, T_ASSERT, 0, 0, -1);
6049 else if (base->type != T_ASSERT)
6051 /* Token clash - but with what?! */
6053 "cpp internal error: base->type != T_ASSERT in do_assert");
6057 this = install (sym, thislen, T_ASSERT, 0,
6058 (char *)base->value.aschain, -1);
6059 base->value.aschain = this;
6061 pfile->limit = sym; /* Pop */
6065 pfile->limit = sym; /* Pop */
6066 skip_rest_of_line (pfile);
6071 do_unassert (pfile, keyword)
6073 struct directive *keyword ATTRIBUTE_UNUSED;
6077 long baselen, thislen;
6078 HASHNODE *base, *this, *next;
6080 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6081 && !CPP_BUFFER (pfile)->system_header_p)
6082 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6084 cpp_skip_hspace (pfile);
6086 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
6087 ret = parse_assertion (pfile);
6091 cpp_skip_hspace (pfile);
6093 if (c != EOF && c != '\n')
6094 cpp_error (pfile, "junk at end of `#unassert'");
6096 thislen = strlen (sym);
6099 base = cpp_lookup (pfile, sym, thislen, -1);
6101 goto error; /* It isn't an error to #undef what isn't #defined,
6102 so it isn't an error to #unassert what isn't
6103 #asserted either. */
6105 for (this = base->value.aschain; this; this = next)
6107 next = this->value.aschain;
6108 delete_macro (this);
6110 delete_macro (base);
6114 baselen = index (sym, '(') - sym;
6115 base = cpp_lookup (pfile, sym, baselen, -1);
6116 if (! base) goto error;
6117 this = cpp_lookup (pfile, sym, thislen, -1);
6118 if (! this) goto error;
6121 while (next->value.aschain != this)
6122 next = next->value.aschain;
6124 next->value.aschain = this->value.aschain;
6125 delete_macro (this);
6127 if (base->value.aschain == NULL)
6128 delete_macro (base); /* Last answer for this predicate deleted. */
6131 pfile->limit = sym; /* Pop */
6134 pfile->limit = sym; /* Pop */
6135 skip_rest_of_line (pfile);
6140 cpp_read_check_assertion (pfile)
6143 char *name = CPP_PWRITTEN (pfile);
6147 FORWARD (1); /* Skip '#' */
6148 cpp_skip_hspace (pfile);
6149 if (! parse_assertion (pfile))
6153 hp = cpp_lookup (pfile, name, (char *)CPP_PWRITTEN (pfile) - name, -1);
6157 pfile->limit = name;
6161 /* Initialize PMARK to remember the current position of PFILE. */
6164 parse_set_mark (pmark, pfile)
6165 struct parse_marker *pmark;
6168 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6169 pmark->next = pbuf->marks;
6170 pbuf->marks = pmark;
6172 pmark->position = pbuf->cur - pbuf->buf;
6175 /* Cleanup PMARK - we no longer need it. */
6178 parse_clear_mark (pmark)
6179 struct parse_marker *pmark;
6181 struct parse_marker **pp = &pmark->buf->marks;
6182 for (; ; pp = &(*pp)->next) {
6183 if (*pp == NULL) abort ();
6184 if (*pp == pmark) break;
6189 /* Backup the current position of PFILE to that saved in PMARK. */
6192 parse_goto_mark (pmark, pfile)
6193 struct parse_marker *pmark;
6196 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6197 if (pbuf != pmark->buf)
6198 cpp_fatal (pfile, "internal error %s", "parse_goto_mark");
6199 pbuf->cur = pbuf->buf + pmark->position;
6202 /* Reset PMARK to point to the current position of PFILE. (Same
6203 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
6206 parse_move_mark (pmark, pfile)
6207 struct parse_marker *pmark;
6210 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6211 if (pbuf != pmark->buf)
6212 cpp_fatal (pfile, "internal error %s", "parse_move_mark");
6213 pmark->position = pbuf->cur - pbuf->buf;
6218 cpp_print_file_and_line (pfile)
6221 cpp_buffer *ip = cpp_file_buffer (pfile);
6226 cpp_buf_line_and_col (ip, &line, &col);
6227 cpp_file_line_for_message (pfile, ip->nominal_fname,
6228 line, pfile->show_column ? col : -1);
6233 v_cpp_error (pfile, msg, ap)
6238 cpp_print_containing_files (pfile);
6239 cpp_print_file_and_line (pfile);
6240 v_cpp_message (pfile, 1, msg, ap);
6244 cpp_error VPROTO ((cpp_reader * pfile, const char *msg, ...))
6246 #ifndef ANSI_PROTOTYPES
6254 #ifndef ANSI_PROTOTYPES
6255 pfile = va_arg (ap, cpp_reader *);
6256 msg = va_arg (ap, const char *);
6259 v_cpp_error (pfile, msg, ap);
6263 /* Print error message but don't count it. */
6266 v_cpp_warning (pfile, msg, ap)
6271 if (CPP_OPTIONS (pfile)->inhibit_warnings)
6274 if (CPP_OPTIONS (pfile)->warnings_are_errors)
6277 cpp_print_containing_files (pfile);
6278 cpp_print_file_and_line (pfile);
6279 v_cpp_message (pfile, 0, msg, ap);
6283 cpp_warning VPROTO ((cpp_reader * pfile, const char *msg, ...))
6285 #ifndef ANSI_PROTOTYPES
6293 #ifndef ANSI_PROTOTYPES
6294 pfile = va_arg (ap, cpp_reader *);
6295 msg = va_arg (ap, const char *);
6298 v_cpp_warning (pfile, msg, ap);
6302 /* Print an error message and maybe count it. */
6305 cpp_pedwarn VPROTO ((cpp_reader * pfile, const char *msg, ...))
6307 #ifndef ANSI_PROTOTYPES
6315 #ifndef ANSI_PROTOTYPES
6316 pfile = va_arg (ap, cpp_reader *);
6317 msg = va_arg (ap, const char *);
6320 if (CPP_OPTIONS (pfile)->pedantic_errors)
6321 v_cpp_error (pfile, msg, ap);
6323 v_cpp_warning (pfile, msg, ap);
6328 v_cpp_error_with_line (pfile, line, column, msg, ap)
6335 cpp_buffer *ip = cpp_file_buffer (pfile);
6337 cpp_print_containing_files (pfile);
6340 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
6342 v_cpp_message (pfile, 1, msg, ap);
6346 cpp_error_with_line VPROTO ((cpp_reader * pfile, int line, int column, const char *msg, ...))
6348 #ifndef ANSI_PROTOTYPES
6358 #ifndef ANSI_PROTOTYPES
6359 pfile = va_arg (ap, cpp_reader *);
6360 line = va_arg (ap, int);
6361 column = va_arg (ap, int);
6362 msg = va_arg (ap, const char *);
6365 v_cpp_error_with_line(pfile, line, column, msg, ap);
6370 v_cpp_warning_with_line (pfile, line, column, msg, ap)
6379 if (CPP_OPTIONS (pfile)->inhibit_warnings)
6382 if (CPP_OPTIONS (pfile)->warnings_are_errors)
6385 cpp_print_containing_files (pfile);
6387 ip = cpp_file_buffer (pfile);
6390 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
6392 v_cpp_message (pfile, 0, msg, ap);
6397 cpp_warning_with_line VPROTO ((cpp_reader * pfile, int line, int column, const char *msg, ...))
6399 #ifndef ANSI_PROTOTYPES
6409 #ifndef ANSI_PROTOTYPES
6410 pfile = va_arg (ap, cpp_reader *);
6411 line = va_arg (ap, int);
6412 column = va_arg (ap, int);
6413 msg = va_arg (ap, const char *);
6416 v_cpp_warning_with_line (pfile, line, column, msg, ap);
6422 cpp_pedwarn_with_line VPROTO ((cpp_reader * pfile, int line, int column, const char *msg, ...))
6424 #ifndef ANSI_PROTOTYPES
6434 #ifndef ANSI_PROTOTYPES
6435 pfile = va_arg (ap, cpp_reader *);
6436 line = va_arg (ap, int);
6437 column = va_arg (ap, int);
6438 msg = va_arg (ap, const char *);
6441 if (CPP_OPTIONS (pfile)->pedantic_errors)
6442 v_cpp_error_with_line (pfile, column, line, msg, ap);
6444 v_cpp_warning_with_line (pfile, line, column, msg, ap);
6448 /* Report a warning (or an error if pedantic_errors)
6449 giving specified file name and line number, not current. */
6452 cpp_pedwarn_with_file_and_line VPROTO ((cpp_reader *pfile, char *file, int line, const char *msg, ...))
6454 #ifndef ANSI_PROTOTYPES
6464 #ifndef ANSI_PROTOTYPES
6465 pfile = va_arg (ap, cpp_reader *);
6466 file = va_arg (ap, char *);
6467 line = va_arg (ap, int);
6468 msg = va_arg (ap, const char *);
6471 if (!CPP_OPTIONS (pfile)->pedantic_errors
6472 && CPP_OPTIONS (pfile)->inhibit_warnings)
6475 cpp_file_line_for_message (pfile, file, line, -1);
6476 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msg, ap);
6480 /* my_strerror - return the descriptive text associated with an
6484 my_strerror (errnum)
6490 #ifndef HAVE_STRERROR
6491 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
6493 result = strerror (errnum);
6496 /* VAXCRTL's strerror() takes an optional second argument, which only
6497 matters when the first argument is EVMSERR. However, it's simplest
6498 just to pass it unconditionally. `vaxc$errno' is declared in
6499 <errno.h>, and maintained by the library in parallel with `errno'.
6500 We assume that caller's `errnum' either matches the last setting of
6501 `errno' by the library or else does not have the value `EVMSERR'. */
6503 result = strerror (errnum, vaxc$errno);
6507 result = "undocumented I/O error";
6512 /* Error including a message from `errno'. */
6515 cpp_error_from_errno (pfile, name)
6519 cpp_message_from_errno (pfile, 1, name);
6523 cpp_message_from_errno (pfile, is_error, name)
6529 cpp_buffer *ip = cpp_file_buffer (pfile);
6531 cpp_print_containing_files (pfile);
6534 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
6536 cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
6540 cpp_perror_with_name (pfile, name)
6544 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
6548 * No pre-compiled header file support.
6550 * Possibly different enum token codes for each C/C++ token.
6552 * Find and cleanup remaining uses of static variables,
6554 * Support for trigraphs.
6556 * Support -dM flag (dump_all_macros).
6558 * Support for_lint flag.