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 *));
50 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
51 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
54 /* By default, colon separates directories in a path. */
55 #ifndef PATH_SEPARATOR
56 #define PATH_SEPARATOR ':'
59 #ifndef STANDARD_INCLUDE_DIR
60 #define STANDARD_INCLUDE_DIR "/usr/include"
63 /* Symbols to predefine. */
66 static char *predefs = CPP_PREDEFINES;
68 static char *predefs = "";
71 /* We let tm.h override the types used here, to handle trivial differences
72 such as the choice of unsigned int or long unsigned int for size_t.
73 When machines start needing nontrivial differences in the size type,
74 it would be best to do something here to figure out automatically
75 from other information what type to use. */
77 /* The string value for __SIZE_TYPE__. */
80 #define SIZE_TYPE "long unsigned int"
83 /* The string value for __PTRDIFF_TYPE__. */
86 #define PTRDIFF_TYPE "long int"
89 /* The string value for __WCHAR_TYPE__. */
92 #define WCHAR_TYPE "int"
94 #define CPP_WCHAR_TYPE(PFILE) \
95 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
97 /* The string value for __USER_LABEL_PREFIX__ */
99 #ifndef USER_LABEL_PREFIX
100 #define USER_LABEL_PREFIX ""
103 /* The string value for __REGISTER_PREFIX__ */
105 #ifndef REGISTER_PREFIX
106 #define REGISTER_PREFIX ""
109 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
110 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
112 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
113 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
114 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
115 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
116 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
117 (Note that it is false while we're expanding marco *arguments*.) */
118 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
120 /* Move all backslash-newline pairs out of embarrassing places.
121 Exchange all such pairs following BP
122 with any potentially-embarrassing characters that follow them.
123 Potentially-embarrassing characters are / and *
124 (because a backslash-newline inside a comment delimiter
125 would cause it not to be recognized). */
127 #define NEWLINE_FIX \
128 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
130 /* Same, but assume we've already read the potential '\\' into C. */
131 #define NEWLINE_FIX1(C) do { \
132 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
136 struct cpp_pending *next;
141 /* Forward declarations. */
143 extern void cpp_hash_cleanup PARAMS ((cpp_reader *));
145 static char *my_strerror PROTO ((int));
146 static void make_assertion PROTO ((cpp_reader *, char *, U_CHAR *));
147 static void path_include PROTO ((cpp_reader *, char *));
148 static void initialize_builtins PROTO ((cpp_reader *));
149 static void initialize_char_syntax PROTO ((void));
151 static void trigraph_pcp ();
153 static void validate_else PROTO ((cpp_reader *, char *));
154 static int comp_def_part PROTO ((int, U_CHAR *, int, U_CHAR *,
157 extern void fancy_abort ();
159 static int check_macro_name PROTO ((cpp_reader *, U_CHAR *, char *));
160 static int compare_defs PROTO ((cpp_reader *,
161 DEFINITION *, DEFINITION *));
162 static HOST_WIDE_INT eval_if_expression PROTO ((cpp_reader *, U_CHAR *, int));
163 static int change_newlines PROTO ((U_CHAR *, int));
164 static void push_macro_expansion PARAMS ((cpp_reader *,
165 U_CHAR *, int, HASHNODE *));
166 static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
168 static void conditional_skip PROTO ((cpp_reader *, int,
169 enum node_type, U_CHAR *));
170 static void skip_if_group PROTO ((cpp_reader *, int));
171 static int parse_name PARAMS ((cpp_reader *, int));
172 static void print_help PROTO ((void));
174 /* Last arg to output_line_command. */
175 enum file_change_code {same_file, enter_file, leave_file};
177 /* External declarations. */
179 extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader *));
181 extern char *version_string;
182 extern struct tm *localtime ();
185 /* #include "file" looks in source file dir, then stack. */
186 /* #include <file> just looks in the stack. */
187 /* -I directories are added to the end, then the defaults are added. */
189 static struct default_include {
190 char *fname; /* The name of the directory. */
191 char *component; /* The component containing the directory */
192 int cplusplus; /* Only look here if we're compiling C++. */
193 int cxx_aware; /* Includes in this directory don't need to
194 be wrapped in extern "C" when compiling
196 } include_defaults_array[]
197 #ifdef INCLUDE_DEFAULTS
201 /* Pick up GNU C++ specific include files. */
202 { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
204 /* This is the dir for fixincludes. Put it just before
205 the files that we fix. */
206 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
207 /* For cross-compilation, this dir name is generated
208 automatically in Makefile.in. */
209 { CROSS_INCLUDE_DIR, "GCC",0, 0 },
210 #ifdef TOOL_INCLUDE_DIR
211 /* This is another place that the target system's headers might be. */
212 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
214 #else /* not CROSS_COMPILE */
215 #ifdef LOCAL_INCLUDE_DIR
216 /* This should be /usr/local/include and should come before
217 the fixincludes-fixed header files. */
218 { LOCAL_INCLUDE_DIR, 0, 0, 1 },
220 #ifdef TOOL_INCLUDE_DIR
221 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
222 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
223 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
225 /* This is the dir for fixincludes. Put it just before
226 the files that we fix. */
227 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
228 /* Some systems have an extra dir of include files. */
229 #ifdef SYSTEM_INCLUDE_DIR
230 { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
232 #ifndef STANDARD_INCLUDE_COMPONENT
233 #define STANDARD_INCLUDE_COMPONENT 0
235 { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
236 #endif /* not CROSS_COMPILE */
239 #endif /* no INCLUDE_DEFAULTS */
241 /* `struct directive' defines one #-directive, including how to handle it. */
244 int length; /* Length of name */
245 int (*func) /* Function to handle directive */
246 PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
247 char *name; /* Name of directive */
248 enum node_type type; /* Code which describes which directive. */
249 char command_reads_line; /* One if rest of line is read by func. */
252 /* These functions are declared to return int instead of void since they
253 are going to be placed in a table and some old compilers have trouble with
254 pointers to functions returning void. */
256 static int do_define PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
257 static int do_line PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
258 static int do_include PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
259 static int do_undef PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
260 static int do_error PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
261 static int do_pragma PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
262 static int do_ident PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
263 static int do_if PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
264 static int do_xifdef PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
265 static int do_else PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
266 static int do_elif PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
267 static int do_endif PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
268 #ifdef SCCS_DIRECTIVE
269 static int do_sccs PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
271 static int do_assert PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
272 static int do_unassert PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
273 static int do_warning PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *));
275 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
276 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
278 /* Here is the actual list of #-directives, most-often-used first.
279 The initialize_builtins function assumes #define is the very first. */
281 static struct directive directive_table[] = {
282 { 6, do_define, "define", T_DEFINE, 0},
283 { 5, do_xifdef, "ifdef", T_IFDEF, 1},
284 { 6, do_xifdef, "ifndef", T_IFNDEF, 1},
285 { 7, do_include, "include", T_INCLUDE, 1},
286 { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
287 { 6, do_include, "import", T_IMPORT, 1},
288 { 5, do_endif, "endif", T_ENDIF, 1},
289 { 4, do_else, "else", T_ELSE, 1},
290 { 2, do_if, "if", T_IF, 1},
291 { 4, do_elif, "elif", T_ELIF, 1},
292 { 5, do_undef, "undef", T_UNDEF, 0},
293 { 5, do_error, "error", T_ERROR, 0},
294 { 7, do_warning, "warning", T_WARNING, 0},
295 { 6, do_pragma, "pragma", T_PRAGMA, 0},
296 { 4, do_line, "line", T_LINE, 1},
297 { 5, do_ident, "ident", T_IDENT, 1},
298 #ifdef SCCS_DIRECTIVE
299 { 4, do_sccs, "sccs", T_SCCS, 0},
301 { 6, do_assert, "assert", T_ASSERT, 1},
302 { 8, do_unassert, "unassert", T_UNASSERT, 1},
303 { -1, 0, "", T_UNUSED, 0},
306 /* table to tell if char can be part of a C identifier. */
307 U_CHAR is_idchar[256] = { 0 };
308 /* table to tell if char can be first char of a c identifier. */
309 U_CHAR is_idstart[256] = { 0 };
310 /* table to tell if c is horizontal space. */
311 U_CHAR is_hor_space[256] = { 0 };
312 /* table to tell if c is horizontal or vertical space. */
313 U_CHAR is_space[256] = { 0 };
315 /* Initialize syntactic classifications of characters. */
317 initialize_char_syntax ()
322 * Set up is_idchar and is_idstart tables. These should be
323 * faster than saying (is_alpha (c) || c == '_'), etc.
324 * Set up these things before calling any routines tthat
326 * XXX We should setlocale(LC_CTYPE, "C") here for safety.
328 for (i = 0; i < 256; i++)
330 is_idchar[i] = ISALNUM (i);
331 is_idstart[i] = ISALPHA (i);
337 /* These will be reset later if -$ is in effect. */
341 /* horizontal space table */
342 is_hor_space[' '] = 1;
343 is_hor_space['\t'] = 1;
344 is_hor_space['\v'] = 1;
345 is_hor_space['\f'] = 1;
346 is_hor_space['\r'] = 1;
357 /* Place into PFILE a quoted string representing the string SRC.
358 Caller must reserve enough space in pfile->token_buffer. */
361 quote_string (pfile, src)
367 CPP_PUTC_Q (pfile, '\"');
369 switch ((c = *src++))
373 CPP_PUTC_Q (pfile, c);
376 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
377 CPP_ADJUST_WRITTEN (pfile, 4);
383 CPP_PUTC_Q (pfile, '\\');
384 CPP_PUTC_Q (pfile, c);
388 CPP_PUTC_Q (pfile, '\"');
389 CPP_NUL_TERMINATE_Q (pfile);
394 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
397 cpp_grow_buffer (pfile, n)
401 long old_written = CPP_WRITTEN (pfile);
402 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
403 pfile->token_buffer = (U_CHAR *)
404 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
405 CPP_SET_WRITTEN (pfile, old_written);
410 * process a given definition string, for initialization
411 * If STR is just an identifier, define it with value 1.
412 * If STR has anything after the identifier, then it should
413 * be identifier=definition.
417 cpp_define (pfile, str)
427 cpp_error (pfile, "malformed option `-D %s'", str);
430 while (is_idchar[*++p])
433 while (is_idchar[*++p] || *p == ',' || is_hor_space[*p])
436 p = (U_CHAR *) str; /* Error */
440 buf = (U_CHAR *) alloca (p - buf + 4);
441 strcpy ((char *)buf, str);
442 strcat ((char *)buf, " 1");
446 cpp_error (pfile, "malformed option `-D %s'", str);
452 /* Copy the entire option so we can modify it. */
453 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
454 strncpy (buf, str, p - str);
455 /* Change the = to a space. */
457 /* Scan for any backslash-newline and remove it. */
462 if (*p == '\\' && p[1] == '\n')
470 do_define (pfile, NULL, buf, buf + strlen (buf));
473 /* Process the string STR as if it appeared as the body of a #assert.
474 OPTION is the option name for which STR was the argument. */
477 make_assertion (pfile, option, str)
484 /* Copy the entire option so we can modify it. */
485 buf = (U_CHAR *) alloca (strlen (str) + 1);
486 strcpy ((char *) buf, str);
487 /* Scan for any backslash-newline and remove it. */
491 if (*p == '\\' && p[1] == '\n')
500 if (!is_idstart[*p]) {
501 cpp_error (pfile, "malformed option `%s %s'", option, str);
504 while (is_idchar[*++p])
506 while (*p == ' ' || *p == '\t') p++;
507 if (! (*p == 0 || *p == '(')) {
508 cpp_error (pfile, "malformed option `%s %s'", option, str);
512 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
514 do_assert (pfile, NULL, NULL, NULL);
515 cpp_pop_buffer (pfile);
519 /* Given a colon-separated list of file names PATH,
520 add all the names to the search path for include files. */
523 path_include (pfile, path)
536 /* Find the end of this name. */
537 while (*q != 0 && *q != PATH_SEPARATOR) q++;
539 /* An empty name in the path stands for the current directory. */
540 name = (char *) xmalloc (2);
544 /* Otherwise use the directory that is named. */
545 name = (char *) xmalloc (q - p + 1);
546 bcopy (p, name, q - p);
550 append_include_chain (pfile,
551 &(CPP_OPTIONS (pfile)->bracket_include), name, 0);
553 /* Advance past this name. */
557 /* Skip the colon. */
563 cpp_options_init (opts)
566 bzero ((char *) opts, sizeof *opts);
567 opts->in_fname = NULL;
568 opts->out_fname = NULL;
570 opts->dollars_in_ident = 1;
571 initialize_char_syntax ();
573 opts->no_line_commands = 0;
574 opts->no_trigraphs = 1;
575 opts->put_out_comments = 0;
576 opts->print_include_names = 0;
577 opts->dump_macros = dump_none;
581 opts->cplusplus_comments = 1;
588 opts->pedantic_errors = 0;
589 opts->inhibit_warnings = 0;
590 opts->warn_comments = 0;
591 opts->warn_import = 1;
592 opts->warnings_are_errors = 0;
596 null_underflow (pfile)
597 cpp_reader *pfile ATTRIBUTE_UNUSED;
603 null_cleanup (pbuf, pfile)
604 cpp_buffer *pbuf ATTRIBUTE_UNUSED;
605 cpp_reader *pfile ATTRIBUTE_UNUSED;
611 macro_cleanup (pbuf, pfile)
613 cpp_reader *pfile ATTRIBUTE_UNUSED;
615 HASHNODE *macro = (HASHNODE *) pbuf->data;
616 if (macro->type == T_DISABLED)
617 macro->type = T_MACRO;
618 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
623 /* Assuming we have read '/'.
624 If this is the start of a comment (followed by '*' or '/'),
625 skip to the end of the comment, and return ' '.
626 Return EOF if we reached the end of file before the end of the comment.
627 If not the start of a comment, return '/'. */
630 skip_comment (pfile, linep)
635 while (PEEKC() == '\\' && PEEKN(1) == '\n')
650 while (c == '\\' && PEEKC() == '\n')
654 FORWARD(1), c = GETC();
656 if (prev_c == '*' && c == '/')
658 if (c == '\n' && linep)
662 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
669 return ' '; /* Allow // to be terminated by EOF. */
670 while (c == '\\' && PEEKC() == '\n')
679 /* Don't consider final '\n' to be part of comment. */
689 /* Skip whitespace \-newline and comments. Does not macro-expand. */
692 cpp_skip_hspace (pfile)
702 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
703 cpp_pedwarn (pfile, "%s in preprocessing directive",
704 c == '\f' ? "formfeed" : "vertical tab");
710 c = skip_comment (pfile, NULL);
713 if (c == EOF || c == '/')
716 else if (c == '\\' && PEEKN(1) == '\n') {
719 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
720 && is_hor_space[PEEKN(1)])
726 /* Read the rest of the current line.
727 The line is appended to PFILE's output buffer. */
730 copy_rest_of_line (pfile)
733 struct cpp_options *opts = CPP_OPTIONS (pfile);
750 goto scan_directive_token;
754 if (nextc == '*' || (opts->cplusplus_comments && nextc == '/'))
755 goto scan_directive_token;
759 if (CPP_PEDANTIC (pfile))
760 cpp_pedwarn (pfile, "%s in preprocessing directive",
761 c == '\f' ? "formfeed" : "vertical tab");
767 scan_directive_token:
769 cpp_get_token (pfile);
775 CPP_NUL_TERMINATE (pfile);
779 skip_rest_of_line (pfile)
782 long old = CPP_WRITTEN (pfile);
783 copy_rest_of_line (pfile);
784 CPP_SET_WRITTEN (pfile, old);
787 /* Handle a possible # directive.
788 '#' has already been read. */
791 handle_directive (pfile)
794 register struct directive *kt;
797 U_CHAR *ident, *line_end;
798 long old_written = CPP_WRITTEN (pfile);
800 cpp_skip_hspace (pfile);
803 if (c >= '0' && c <= '9')
805 /* Handle # followed by a line number. */
806 if (CPP_PEDANTIC (pfile))
807 cpp_pedwarn (pfile, "`#' followed by integer");
808 do_line (pfile, NULL, NULL, NULL);
809 goto done_a_directive;
812 /* Now find the directive name. */
813 CPP_PUTC (pfile, '#');
814 parse_name (pfile, GETC());
815 ident = pfile->token_buffer + old_written + 1;
816 ident_length = CPP_PWRITTEN (pfile) - ident;
817 if (ident_length == 0 && PEEKC() == '\n')
819 /* A line of just `#' becomes blank. */
820 goto done_a_directive;
824 if (ident_length == 0 || !is_idstart[*ident]) {
826 while (is_idchar[*p]) {
827 if (*p < '0' || *p > '9')
831 /* Avoid error for `###' and similar cases unless -pedantic. */
833 while (*p == '#' || is_hor_space[*p]) p++;
835 if (pedantic && !lang_asm)
836 cpp_warning (pfile, "invalid preprocessor directive");
842 cpp_error (pfile, "invalid preprocessor directive name");
848 * Decode the keyword and call the appropriate expansion
849 * routine, after moving the input pointer up to the next line.
851 for (kt = directive_table; ; kt++) {
853 goto not_a_directive;
854 if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length))
858 if (kt->command_reads_line)
862 /* Nonzero means do not delete comments within the directive.
863 #define needs this when -traditional. */
864 int comments = CPP_TRADITIONAL (pfile) && kt->type == T_DEFINE;
865 int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
866 CPP_OPTIONS (pfile)->put_out_comments = comments;
867 after_ident = CPP_WRITTEN (pfile);
868 copy_rest_of_line (pfile);
869 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
872 /* We may want to pass through #define, #pragma, and #include.
873 Other directives may create output, but we don't want the directive
874 itself out, so we pop it now. For example conditionals may emit
875 #failed ... #endfailed stuff. But note that popping the buffer
876 means the parameters to kt->func may point after pfile->limit
877 so these parameters are invalid as soon as something gets appended
878 to the token_buffer. */
880 line_end = CPP_PWRITTEN (pfile);
881 if (! (kt->type == T_DEFINE
882 || kt->type == T_PRAGMA
883 || (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)
884 && CPP_OPTIONS (pfile)->dump_includes)))
885 CPP_SET_WRITTEN (pfile, old_written);
887 (*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end);
889 if (kt->type == T_DEFINE)
891 if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
893 /* Skip "#define". */
894 U_CHAR *p = pfile->token_buffer + old_written + 7;
896 SKIP_WHITE_SPACE (p);
897 while (is_idchar[*p]) p++;
899 CPP_PUTC (pfile, '\n');
901 else if (CPP_OPTIONS (pfile)->dump_macros != dump_definitions)
902 CPP_SET_WRITTEN (pfile, old_written);
912 /* Pass a directive through to the output file.
913 BUF points to the contents of the directive, as a contiguous string.
914 LIMIT points to the first character past the end of the directive.
915 KEYWORD is the keyword-table entry for the directive. */
918 pass_thru_directive (buf, limit, pfile, keyword)
921 struct directive *keyword;
923 register unsigned keyword_length = keyword->length;
925 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
926 CPP_PUTC_Q (pfile, '#');
927 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
928 if (limit != buf && buf[0] != ' ')
929 CPP_PUTC_Q (pfile, ' ');
930 CPP_PUTS_Q (pfile, buf, limit - buf);
932 CPP_PUTS_Q (pfile, '\n');
933 /* Count the line we have just made in the output,
934 to get in sync properly. */
939 /* The arglist structure is built by do_define to tell
940 collect_definition where the argument names begin. That
941 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
942 would contain pointers to the strings x, y, and z.
943 Collect_definition would then build a DEFINITION node,
944 with reflist nodes pointing to the places x, y, and z had
945 appeared. So the arglist is just convenience data passed
946 between these two routines. It is not kept around after
947 the current #define has been processed and entered into the
951 struct arglist *next;
958 /* Read a replacement list for a macro with parameters.
959 Build the DEFINITION structure.
960 Reads characters of text starting at BUF until END.
961 ARGLIST specifies the formal parameters to look for
962 in the text of the definition; NARGS is the number of args
963 in that list, or -1 for a macro name that wants no argument list.
964 MACRONAME is the macro name itself (so we can avoid recursive expansion)
965 and NAMELEN is its length in characters.
967 Note that comments, backslash-newlines, and leading white space
968 have already been deleted from the argument. */
971 collect_expansion (pfile, buf, limit, nargs, arglist)
975 struct arglist *arglist;
978 register U_CHAR *p, *lastp, *exp_p;
979 struct reflist *endpat = NULL;
980 /* Pointer to first nonspace after last ## seen. */
982 /* Pointer to first nonspace after last single-# seen. */
983 U_CHAR *stringify = 0;
985 int expected_delimiter = '\0';
987 /* Scan thru the replacement list, ignoring comments and quoted
988 strings, picking up on the macro calls. It does a linear search
989 thru the arg list on every potential symbol. Profiling might say
990 that something smarter should happen. */
995 /* Find the beginning of the trailing whitespace. */
997 while (p < limit && is_space[limit[-1]]) limit--;
999 /* Allocate space for the text in the macro definition.
1000 Leading and trailing whitespace chars need 2 bytes each.
1001 Each other input char may or may not need 1 byte,
1002 so this is an upper bound. The extra 5 are for invented
1003 leading and trailing newline-marker and final null. */
1004 maxsize = (sizeof (DEFINITION)
1006 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1010 defn = (DEFINITION *) xcalloc (1, maxsize);
1012 defn->nargs = nargs;
1013 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
1018 /* Add one initial space escape-marker to prevent accidental
1019 token-pasting (often removed by macroexpand). */
1023 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1024 cpp_error (pfile, "`##' at start of macro definition");
1028 /* Process the main body of the definition. */
1030 int skipped_arg = 0;
1031 register U_CHAR c = *p++;
1035 if (!CPP_TRADITIONAL (pfile)) {
1039 if (expected_delimiter != '\0') {
1040 if (c == expected_delimiter)
1041 expected_delimiter = '\0';
1043 expected_delimiter = c;
1047 if (p < limit && expected_delimiter) {
1048 /* In a string, backslash goes through
1049 and makes next char ordinary. */
1055 /* An '@' in a string or character constant stands for itself,
1056 and does not need to be escaped. */
1057 if (!expected_delimiter)
1062 /* # is ordinary inside a string. */
1063 if (expected_delimiter)
1065 if (p < limit && *p == '#') {
1066 /* ##: concatenate preceding and following tokens. */
1067 /* Take out the first #, discard preceding whitespace. */
1069 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1071 /* Skip the second #. */
1073 /* Discard following whitespace. */
1074 SKIP_WHITE_SPACE (p);
1077 cpp_error (pfile, "`##' at end of macro definition");
1078 } else if (nargs >= 0) {
1079 /* Single #: stringify following argument ref.
1080 Don't leave the # in the expansion. */
1082 SKIP_WHITE_SPACE (p);
1083 if (p == limit || ! is_idstart[*p]
1084 || (*p == 'L' && p + 1 < limit && (p[1] == '\'' || p[1] == '"')))
1086 "`#' operator is not followed by a macro argument name");
1093 /* In -traditional mode, recognize arguments inside strings and
1094 character constants, and ignore special properties of #.
1095 Arguments inside strings are considered "stringified", but no
1096 extra quote marks are supplied. */
1100 if (expected_delimiter != '\0') {
1101 if (c == expected_delimiter)
1102 expected_delimiter = '\0';
1104 expected_delimiter = c;
1108 /* Backslash quotes delimiters and itself, but not macro args. */
1109 if (expected_delimiter != 0 && p < limit
1110 && (*p == expected_delimiter || *p == '\\')) {
1117 if (expected_delimiter != '\0') /* No comments inside strings. */
1120 /* If we find a comment that wasn't removed by handle_directive,
1121 this must be -traditional. So replace the comment with
1125 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1128 /* Mark this as a concatenation-point, as if it had been ##. */
1136 /* Handle the start of a symbol. */
1137 if (is_idchar[c] && nargs > 0) {
1138 U_CHAR *id_beg = p - 1;
1142 while (p != limit && is_idchar[*p]) p++;
1143 id_len = p - id_beg;
1146 && ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '"'))) {
1147 register struct arglist *arg;
1149 for (arg = arglist; arg != NULL; arg = arg->next) {
1150 struct reflist *tpat;
1152 if (arg->name[0] == c
1153 && arg->length == id_len
1154 && strncmp (arg->name, id_beg, id_len) == 0) {
1155 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1156 if (CPP_TRADITIONAL (pfile)) {
1157 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1161 "macro arg `%.*s' would be stringified with -traditional.",
1165 /* If ANSI, don't actually substitute inside a string. */
1166 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1168 /* make a pat node for this arg and append it to the end of
1170 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1172 tpat->raw_before = concat == id_beg;
1173 tpat->raw_after = 0;
1174 tpat->rest_args = arg->rest_args;
1175 tpat->stringify = (CPP_TRADITIONAL (pfile)
1176 ? expected_delimiter != '\0'
1177 : stringify == id_beg);
1180 defn->pattern = tpat;
1182 endpat->next = tpat;
1185 tpat->argno = arg->argno;
1186 tpat->nchars = exp_p - lastp;
1188 register U_CHAR *p1 = p;
1189 SKIP_WHITE_SPACE (p1);
1190 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1191 tpat->raw_after = 1;
1193 lastp = exp_p; /* place to start copying from next time */
1200 /* If this was not a macro arg, copy it into the expansion. */
1201 if (! skipped_arg) {
1202 register U_CHAR *lim1 = p;
1206 if (stringify == id_beg)
1208 "`#' operator should be followed by a macro argument name");
1213 if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0)
1215 /* If ANSI, put in a "@ " marker to prevent token pasting.
1216 But not if "inside a string" (which in ANSI mode
1217 happens only for -D option). */
1224 defn->length = exp_p - defn->expansion;
1226 /* Crash now if we overrun the allocated size. */
1227 if (defn->length + 1 > maxsize)
1231 /* This isn't worth the time it takes. */
1232 /* give back excess storage */
1233 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1240 * special extension string that can be added to the last macro argument to
1241 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1242 * #define wow(a, b...) process (b, a, b)
1243 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1244 * { wow (one, two); } -> { process (two, one, two); }
1245 * if this "rest_arg" is used with the concat token '##' and if it is not
1246 * supplied then the token attached to with ## will not be outputted. Ex:
1247 * #define wow (a, b...) process (b ## , a, ## b)
1248 * { wow (1, 2); } -> { process (2, 1, 2); }
1249 * { wow (one); } -> { process (one); {
1251 static char rest_extension[] = "...";
1252 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1254 /* Create a DEFINITION node from a #define directive. Arguments are
1255 as for do_define. */
1258 create_definition (buf, limit, pfile, predefinition)
1259 U_CHAR *buf, *limit;
1263 U_CHAR *bp; /* temp ptr into input buffer */
1264 U_CHAR *symname; /* remember where symbol name starts */
1265 int sym_length; /* and how long it is */
1268 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1270 int arglengths = 0; /* Accumulate lengths of arg names
1271 plus number of args. */
1273 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1277 while (is_hor_space[*bp])
1280 symname = bp; /* remember where it starts */
1282 sym_length = check_macro_name (pfile, bp, "macro");
1285 /* Lossage will occur if identifiers or control keywords are broken
1286 across lines using backslash. This is not the right place to take
1290 struct arglist *arg_ptrs = NULL;
1293 bp++; /* skip '(' */
1294 SKIP_WHITE_SPACE (bp);
1296 /* Loop over macro argument names. */
1297 while (*bp != ')') {
1298 struct arglist *temp;
1300 temp = (struct arglist *) alloca (sizeof (struct arglist));
1302 temp->next = arg_ptrs;
1303 temp->argno = argno++;
1304 temp->rest_args = 0;
1308 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1310 if (!is_idstart[*bp])
1311 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1313 /* Find the end of the arg name. */
1314 while (is_idchar[*bp]) {
1316 /* do we have a "special" rest-args extension here? */
1317 if ((size_t)(limit - bp) > REST_EXTENSION_LENGTH
1318 && strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1320 temp->rest_args = 1;
1324 temp->length = bp - temp->name;
1326 bp += REST_EXTENSION_LENGTH;
1327 arglengths += temp->length + 2;
1328 SKIP_WHITE_SPACE (bp);
1329 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1330 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1335 SKIP_WHITE_SPACE (bp);
1338 cpp_error (pfile, "unterminated parameter list in `#define'");
1342 struct arglist *otemp;
1344 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1345 if (temp->length == otemp->length
1346 && strncmp (temp->name, otemp->name, temp->length) == 0) {
1349 name = (U_CHAR *) alloca (temp->length + 1);
1350 (void) strncpy (name, temp->name, temp->length);
1351 name[temp->length] = '\0';
1353 "duplicate argument name `%s' in `#define'", name);
1359 ++bp; /* skip paren */
1360 SKIP_WHITE_SPACE (bp);
1361 /* now everything from bp before limit is the definition. */
1362 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1363 defn->rest_args = rest_args;
1365 /* Now set defn->args.argnames to the result of concatenating
1366 the argument names in reverse order
1367 with comma-space between them. */
1368 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1370 struct arglist *temp;
1372 for (temp = arg_ptrs; temp; temp = temp->next) {
1373 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1375 if (temp->next != 0) {
1376 defn->args.argnames[i++] = ',';
1377 defn->args.argnames[i++] = ' ';
1380 defn->args.argnames[i] = 0;
1383 /* Simple expansion or empty definition. */
1387 if (is_hor_space[*bp]) {
1389 SKIP_WHITE_SPACE (bp);
1392 case '!': case '"': case '#': case '%': case '&': case '\'':
1393 case ')': case '*': case '+': case ',': case '-': case '.':
1394 case '/': case ':': case ';': case '<': case '=': case '>':
1395 case '?': case '[': case '\\': case ']': case '^': case '{':
1396 case '|': case '}': case '~':
1397 cpp_warning (pfile, "missing white space after `#define %.*s'",
1398 sym_length, symname);
1402 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1403 sym_length, symname);
1408 /* now everything from bp before limit is the definition. */
1409 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1410 defn->args.argnames = (U_CHAR *) "";
1416 /* OP is null if this is a predefinition */
1417 defn->predefined = predefinition;
1419 mdef.symnam = symname;
1420 mdef.symlen = sym_length;
1429 /* Check a purported macro name SYMNAME, and yield its length.
1430 USAGE is the kind of name this is intended for. */
1433 check_macro_name (pfile, symname, usage)
1441 for (p = symname; is_idchar[*p]; p++)
1443 sym_length = p - symname;
1445 || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
1446 cpp_error (pfile, "invalid %s name", usage);
1447 else if (!is_idstart[*symname]) {
1448 U_CHAR *msg; /* what pain... */
1449 msg = (U_CHAR *) alloca (sym_length + 1);
1450 bcopy (symname, msg, sym_length);
1451 msg[sym_length] = 0;
1452 cpp_error (pfile, "invalid %s name `%s'", usage, msg);
1454 if (! strncmp (symname, "defined", 7) && sym_length == 7)
1455 cpp_error (pfile, "invalid %s name `defined'", usage);
1460 /* Return zero if two DEFINITIONs are isomorphic. */
1463 compare_defs (pfile, d1, d2)
1465 DEFINITION *d1, *d2;
1467 register struct reflist *a1, *a2;
1468 register U_CHAR *p1 = d1->expansion;
1469 register U_CHAR *p2 = d2->expansion;
1472 if (d1->nargs != d2->nargs)
1474 if (CPP_PEDANTIC (pfile)
1475 && strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1477 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1478 a1 = a1->next, a2 = a2->next) {
1479 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1480 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1481 || a1->argno != a2->argno
1482 || a1->stringify != a2->stringify
1483 || a1->raw_before != a2->raw_before
1484 || a1->raw_after != a2->raw_after)
1492 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1493 p2, d2->length - (p2 - d2->expansion), 1))
1498 /* Return 1 if two parts of two macro definitions are effectively different.
1499 One of the parts starts at BEG1 and has LEN1 chars;
1500 the other has LEN2 chars at BEG2.
1501 Any sequence of whitespace matches any other sequence of whitespace.
1502 FIRST means these parts are the first of a macro definition;
1503 so ignore leading whitespace entirely.
1504 LAST means these parts are the last of a macro definition;
1505 so ignore trailing whitespace entirely. */
1508 comp_def_part (first, beg1, len1, beg2, len2, last)
1510 U_CHAR *beg1, *beg2;
1514 register U_CHAR *end1 = beg1 + len1;
1515 register U_CHAR *end2 = beg2 + len2;
1517 while (beg1 != end1 && is_space[*beg1]) beg1++;
1518 while (beg2 != end2 && is_space[*beg2]) beg2++;
1521 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1522 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1524 while (beg1 != end1 && beg2 != end2) {
1525 if (is_space[*beg1] && is_space[*beg2]) {
1526 while (beg1 != end1 && is_space[*beg1]) beg1++;
1527 while (beg2 != end2 && is_space[*beg2]) beg2++;
1528 } else if (*beg1 == *beg2) {
1532 return (beg1 != end1) || (beg2 != end2);
1535 /* Process a #define command.
1536 BUF points to the contents of the #define command, as a contiguous string.
1537 LIMIT points to the first character past the end of the definition.
1538 KEYWORD is the keyword-table entry for #define,
1539 or NULL for a "predefined" macro. */
1542 do_define (pfile, keyword, buf, limit)
1544 struct directive *keyword;
1545 U_CHAR *buf, *limit;
1552 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1553 if (pcp_outfile && keyword)
1554 pass_thru_directive (buf, limit, pfile, keyword);
1557 mdef = create_definition (buf, limit, pfile, keyword == NULL);
1561 hashcode = hashf (mdef.symnam, mdef.symlen, HASHSIZE);
1563 if ((hp = cpp_lookup (pfile, mdef.symnam, mdef.symlen, hashcode)) != NULL)
1566 /* Redefining a precompiled key is ok. */
1567 if (hp->type == T_PCSTRING)
1569 /* Redefining a macro is ok if the definitions are the same. */
1570 else if (hp->type == T_MACRO)
1571 ok = ! compare_defs (pfile, mdef.defn, hp->value.defn);
1572 /* Redefining a constant is ok with -D. */
1573 else if (hp->type == T_CONST)
1574 ok = ! CPP_OPTIONS (pfile)->done_initializing;
1575 /* Print the warning if it's not ok. */
1578 U_CHAR *msg; /* what pain... */
1580 /* If we are passing through #define and #undef directives, do
1581 that for this re-definition now. */
1582 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1583 pass_thru_directive (buf, limit, pfile, keyword);
1585 msg = (U_CHAR *) alloca (mdef.symlen + 22);
1587 bcopy (mdef.symnam, msg + 1, mdef.symlen);
1588 strcpy ((char *) (msg + mdef.symlen + 1), "' redefined");
1589 cpp_pedwarn (pfile, msg);
1590 if (hp->type == T_MACRO)
1591 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1592 "this is the location of the previous definition");
1594 /* Replace the old definition. */
1596 hp->value.defn = mdef.defn;
1600 /* If we are passing through #define and #undef directives, do
1601 that for this new definition now. */
1602 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1603 pass_thru_directive (buf, limit, pfile, keyword);
1604 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1605 (char *) mdef.defn, hashcode);
1615 /* This structure represents one parsed argument in a macro call.
1616 `raw' points to the argument text as written (`raw_length' is its length).
1617 `expanded' points to the argument's macro-expansion
1618 (its length is `expand_length').
1619 `stringified_length' is the length the argument would have
1621 `use_count' is the number of times this macro arg is substituted
1622 into the macro. If the actual use count exceeds 10,
1623 the value stored is 10. */
1625 /* raw and expanded are relative to ARG_BASE */
1626 #define ARG_BASE ((pfile)->token_buffer)
1629 /* Strings relative to pfile->token_buffer */
1630 long raw, expanded, stringified;
1631 int raw_length, expand_length;
1632 int stringified_length;
1637 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1638 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1639 as the new input buffer.
1640 Return the new buffer, or NULL on failure. */
1643 cpp_push_buffer (pfile, buffer, length)
1648 register cpp_buffer *buf = CPP_BUFFER (pfile);
1649 if (buf == pfile->buffer_stack)
1651 cpp_fatal (pfile, "%s: macro or `#include' recursion too deep",
1656 bzero ((char *) buf, sizeof (cpp_buffer));
1657 CPP_BUFFER (pfile) = buf;
1658 buf->if_stack = pfile->if_stack;
1659 buf->cleanup = null_cleanup;
1660 buf->underflow = null_underflow;
1661 buf->buf = buf->cur = buffer;
1662 buf->alimit = buf->rlimit = buffer + length;
1668 cpp_pop_buffer (pfile)
1671 cpp_buffer *buf = CPP_BUFFER (pfile);
1672 (*buf->cleanup) (buf, pfile);
1673 return ++CPP_BUFFER (pfile);
1676 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1677 Pop the buffer when done. */
1680 cpp_scan_buffer (pfile)
1683 cpp_buffer *buffer = CPP_BUFFER (pfile);
1686 enum cpp_token token = cpp_get_token (pfile);
1687 if (token == CPP_EOF) /* Should not happen ... */
1689 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
1691 cpp_pop_buffer (pfile);
1698 * Rescan a string (which may have escape marks) into pfile's buffer.
1699 * Place the result in pfile->token_buffer.
1701 * The input is copied before it is scanned, so it is safe to pass
1702 * it something from the token_buffer that will get overwritten
1703 * (because it follows CPP_WRITTEN). This is used by do_include.
1707 cpp_expand_to_buffer (pfile, buf, length)
1712 register cpp_buffer *ip;
1716 U_CHAR *limit = buf + length;
1719 int odepth = indepth;
1725 /* Set up the input on the input stack. */
1727 buf1 = (U_CHAR *) alloca (length + 1);
1729 register U_CHAR *p1 = buf;
1730 register U_CHAR *p2 = buf1;
1737 ip = cpp_push_buffer (pfile, buf1, length);
1740 ip->has_escapes = 1;
1742 ip->lineno = obuf.lineno = 1;
1745 /* Scan the input, create the output. */
1746 cpp_scan_buffer (pfile);
1749 if (indepth != odepth)
1753 CPP_NUL_TERMINATE (pfile);
1758 adjust_position (buf, limit, linep, colp)
1768 (*linep)++, (*colp) = 1;
1774 /* Move line_base forward, updating lineno and colno. */
1777 update_position (pbuf)
1778 register cpp_buffer *pbuf;
1780 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
1781 unsigned char *new_pos = pbuf->cur;
1782 register struct parse_marker *mark;
1783 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
1785 if (pbuf->buf + mark->position < new_pos)
1786 new_pos = pbuf->buf + mark->position;
1788 pbuf->line_base += new_pos - old_pos;
1789 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
1793 cpp_buf_line_and_col (pbuf, linep, colp)
1794 register cpp_buffer *pbuf;
1802 *linep = pbuf->lineno;
1803 *colp = pbuf->colno;
1804 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
1813 /* Return the cpp_buffer that corresponds to a file (not a macro). */
1816 cpp_file_buffer (pfile)
1819 cpp_buffer *ip = CPP_BUFFER (pfile);
1821 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
1822 if (ip->fname != NULL)
1828 count_newlines (buf, limit)
1829 register U_CHAR *buf;
1830 register U_CHAR *limit;
1832 register long count = 0;
1843 * write out a #line command, for instance, after an #include file.
1844 * If CONDITIONAL is nonzero, we can omit the #line if it would
1845 * appear to be a no-op, and we can output a few newlines instead
1846 * if we want to increase the line number by a small amount.
1847 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
1851 output_line_command (pfile, conditional, file_change)
1854 enum file_change_code file_change;
1857 cpp_buffer *ip = CPP_BUFFER (pfile);
1859 if (ip->fname == NULL)
1862 update_position (ip);
1864 if (CPP_OPTIONS (pfile)->no_line_commands
1865 || CPP_OPTIONS (pfile)->no_output)
1868 line = CPP_BUFFER (pfile)->lineno;
1869 col = CPP_BUFFER (pfile)->colno;
1870 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
1872 if (CPP_OPTIONS (pfile)->no_line_commands)
1876 if (line == pfile->lineno)
1879 /* If the inherited line number is a little too small,
1880 output some newlines instead of a #line command. */
1881 if (line > pfile->lineno && line < pfile->lineno + 8) {
1882 CPP_RESERVE (pfile, 20);
1883 while (line > pfile->lineno) {
1884 CPP_PUTC_Q (pfile, '\n');
1892 /* Don't output a line number of 0 if we can help it. */
1893 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
1894 && *ip->bufp == '\n') {
1900 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
1902 #ifdef OUTPUT_LINE_COMMANDS
1903 static char sharp_line[] = "#line ";
1905 static char sharp_line[] = "# ";
1907 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
1910 sprintf ((char *) CPP_PWRITTEN (pfile), "%ld ", line);
1911 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
1913 quote_string (pfile, ip->nominal_fname);
1914 if (file_change != same_file) {
1915 CPP_PUTC_Q (pfile, ' ');
1916 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
1918 /* Tell cc1 if following text comes from a system header file. */
1919 if (ip->system_header_p) {
1920 CPP_PUTC_Q (pfile, ' ');
1921 CPP_PUTC_Q (pfile, '3');
1923 #ifndef NO_IMPLICIT_EXTERN_C
1924 /* Tell cc1plus if following text should be treated as C. */
1925 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
1926 CPP_PUTC_Q (pfile, ' ');
1927 CPP_PUTC_Q (pfile, '4');
1930 CPP_PUTC_Q (pfile, '\n');
1931 pfile->lineno = line;
1935 * Parse a macro argument and append the info on PFILE's token_buffer.
1936 * REST_ARGS means to absorb the rest of the args.
1937 * Return nonzero to indicate a syntax error.
1940 static enum cpp_token
1941 macarg (pfile, rest_args)
1946 enum cpp_token token;
1947 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1948 CPP_OPTIONS (pfile)->put_out_comments = 0;
1950 /* Try to parse as much of the argument as exists at this
1951 input stack level. */
1952 pfile->no_macro_expand++;
1955 token = cpp_get_token (pfile);
1961 /* If we've hit end of file, it's an error (reported by caller).
1962 Ditto if it's the end of cpp_expand_to_buffer text.
1963 If we've hit end of macro, just continue. */
1964 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
1975 /* if we've returned to lowest level and
1976 we aren't absorbing all args */
1977 if (paren == 0 && rest_args == 0)
1981 /* Remove ',' or ')' from argument buffer. */
1982 CPP_ADJUST_WRITTEN (pfile, -1);
1989 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1990 pfile->no_macro_expand--;
1995 /* Turn newlines to spaces in the string of length LENGTH at START,
1996 except inside of string constants.
1997 The string is copied into itself with its beginning staying fixed. */
2000 change_newlines (start, length)
2004 register U_CHAR *ibp;
2005 register U_CHAR *obp;
2006 register U_CHAR *limit;
2010 limit = start + length;
2013 while (ibp < limit) {
2014 *obp++ = c = *ibp++;
2019 /* Notice and skip strings, so that we don't delete newlines in them. */
2022 while (ibp < limit) {
2023 *obp++ = c = *ibp++;
2026 if (c == '\n' && quotec == '\'')
2042 if (!pfile->timebuf) {
2043 time_t t = time ((time_t *) 0);
2044 pfile->timebuf = localtime (&t);
2046 return pfile->timebuf;
2049 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2050 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2054 * expand things like __FILE__. Place the expansion into the output
2055 * buffer *without* rescanning.
2059 special_symbol (hp, pfile)
2066 cpp_buffer *ip = NULL;
2069 int paren = 0; /* For special `defined' keyword */
2072 if (pcp_outfile && pcp_inside_if
2073 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2075 "Predefined macro `%s' used inside `#if' during precompilation",
2079 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2081 if (ip == CPP_NULL_BUFFER (pfile))
2083 cpp_error (pfile, "cccp error: not in any file?!");
2084 return; /* the show must go on */
2086 if (ip->fname != NULL)
2096 if (hp->type == T_BASE_FILE)
2098 while (CPP_PREV_BUFFER (ip) != CPP_NULL_BUFFER (pfile))
2099 ip = CPP_PREV_BUFFER (ip);
2101 string = ip->nominal_fname;
2105 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2106 quote_string (pfile, string);
2110 case T_INCLUDE_LEVEL:
2112 ip = CPP_BUFFER (pfile);
2113 for (; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
2114 if (ip->fname != NULL)
2117 buf = (char *) alloca (8); /* Eight bytes ought to be more than enough */
2118 sprintf (buf, "%d", true_indepth - 1);
2122 buf = (char *) alloca (3 + strlen (version_string));
2123 sprintf (buf, "\"%s\"", version_string);
2126 #ifndef NO_BUILTIN_SIZE_TYPE
2132 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2133 case T_PTRDIFF_TYPE:
2139 buf = CPP_WCHAR_TYPE (pfile);
2142 case T_USER_LABEL_PREFIX_TYPE:
2143 buf = user_label_prefix;
2146 case T_REGISTER_PREFIX_TYPE:
2147 buf = REGISTER_PREFIX;
2151 buf = (char *) alloca (4 * sizeof (int));
2152 sprintf (buf, "%d", hp->value.ival);
2153 #ifdef STDC_0_IN_SYSTEM_HEADERS
2154 if (ip->system_header_p
2155 && hp->length == 8 && bcmp (hp->name, "__STDC__", 8) == 0
2156 && ! cpp_lookup (pfile, (U_CHAR *) "__STRICT_ANSI__", -1, -1))
2160 if (pcp_inside_if && pcp_outfile)
2161 /* Output a precondition for this macro use */
2162 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2168 long line = ip->lineno;
2169 long col = ip->colno;
2170 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2172 buf = (char *) alloca (10);
2173 sprintf (buf, "%ld", line);
2179 buf = (char *) alloca (20);
2180 timebuf = timestamp (pfile);
2181 if (hp->type == T_DATE)
2182 sprintf (buf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2183 timebuf->tm_mday, timebuf->tm_year + 1900);
2185 sprintf (buf, "\"%02d:%02d:%02d\"", timebuf->tm_hour, timebuf->tm_min,
2189 case T_SPEC_DEFINED:
2190 buf = " 0 "; /* Assume symbol is not defined */
2191 ip = CPP_BUFFER (pfile);
2192 SKIP_WHITE_SPACE (ip->cur);
2193 if (*ip->cur == '(')
2196 ip->cur++; /* Skip over the paren */
2197 SKIP_WHITE_SPACE (ip->cur);
2200 if (!is_idstart[*ip->cur])
2202 if (ip->cur[0] == 'L' && (ip->cur[1] == '\'' || ip->cur[1] == '"'))
2204 if ((hp = cpp_lookup (pfile, ip->cur, -1, -1)))
2207 if (pcp_outfile && pcp_inside_if
2208 && (hp->type == T_CONST
2209 || (hp->type == T_MACRO && hp->value.defn->predefined)))
2210 /* Output a precondition for this macro use. */
2211 fprintf (pcp_outfile, "#define %s\n", hp->name);
2217 if (pcp_outfile && pcp_inside_if)
2219 /* Output a precondition for this macro use */
2220 U_CHAR *cp = ip->bufp;
2221 fprintf (pcp_outfile, "#undef ");
2222 while (is_idchar[*cp]) /* Ick! */
2223 fputc (*cp++, pcp_outfile);
2224 putc ('\n', pcp_outfile);
2227 while (is_idchar[*ip->cur])
2229 SKIP_WHITE_SPACE (ip->cur);
2232 if (*ip->cur != ')')
2240 cpp_error (pfile, "`defined' without an identifier");
2244 cpp_error (pfile, "cccp error: invalid special hash type"); /* time for gdb */
2248 CPP_RESERVE (pfile, len + 1);
2249 CPP_PUTS_Q (pfile, buf, len);
2250 CPP_NUL_TERMINATE_Q (pfile);
2255 /* Write out a #define command for the special named MACRO_NAME
2256 to PFILE's token_buffer. */
2259 dump_special_to_buffer (pfile, macro_name)
2263 static char define_directive[] = "#define ";
2264 int macro_name_length = strlen (macro_name);
2265 output_line_command (pfile, 0, same_file);
2266 CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
2267 CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1);
2268 CPP_PUTS_Q (pfile, macro_name, macro_name_length);
2269 CPP_PUTC_Q (pfile, ' ');
2270 cpp_expand_to_buffer (pfile, macro_name, macro_name_length);
2271 CPP_PUTC (pfile, '\n');
2274 /* Initialize the built-in macros. */
2277 initialize_builtins (pfile)
2280 install ((U_CHAR *)"__LINE__", -1, T_SPECLINE, 0, 0, -1);
2281 install ((U_CHAR *)"__DATE__", -1, T_DATE, 0, 0, -1);
2282 install ((U_CHAR *)"__FILE__", -1, T_FILE, 0, 0, -1);
2283 install ((U_CHAR *)"__BASE_FILE__", -1, T_BASE_FILE, 0, 0, -1);
2284 install ((U_CHAR *)"__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL, 0, 0, -1);
2285 install ((U_CHAR *)"__VERSION__", -1, T_VERSION, 0, 0, -1);
2286 #ifndef NO_BUILTIN_SIZE_TYPE
2287 install ((U_CHAR *)"__SIZE_TYPE__", -1, T_SIZE_TYPE, 0, 0, -1);
2289 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2290 install ((U_CHAR *)"__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE, 0, 0, -1);
2292 install ((U_CHAR *)"__WCHAR_TYPE__", -1, T_WCHAR_TYPE, 0, 0, -1);
2293 install ((U_CHAR *)"__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE, 0, 0, -1);
2294 install ((U_CHAR *)"__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE, 0, 0, -1);
2295 install ((U_CHAR *)"__TIME__", -1, T_TIME, 0, 0, -1);
2296 if (!CPP_TRADITIONAL (pfile))
2297 install ((U_CHAR *)"__STDC__", -1, T_CONST, STDC_VALUE, 0, -1);
2298 if (CPP_OPTIONS (pfile)->objc)
2299 install ((U_CHAR *)"__OBJC__", -1, T_CONST, 1, 0, -1);
2300 /* This is supplied using a -D by the compiler driver
2301 so that it is present only when truly compiling with GNU C. */
2302 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2304 if (CPP_OPTIONS (pfile)->debug_output)
2306 dump_special_to_buffer (pfile, "__BASE_FILE__");
2307 dump_special_to_buffer (pfile, "__VERSION__");
2308 #ifndef NO_BUILTIN_SIZE_TYPE
2309 dump_special_to_buffer (pfile, "__SIZE_TYPE__");
2311 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2312 dump_special_to_buffer (pfile, "__PTRDIFF_TYPE__");
2314 dump_special_to_buffer (pfile, "__WCHAR_TYPE__");
2315 dump_special_to_buffer (pfile, "__DATE__");
2316 dump_special_to_buffer (pfile, "__TIME__");
2317 if (!CPP_TRADITIONAL (pfile))
2318 dump_special_to_buffer (pfile, "__STDC__");
2319 if (CPP_OPTIONS (pfile)->objc)
2320 dump_special_to_buffer (pfile, "__OBJC__");
2324 /* Return 1 iff a token ending in C1 followed directly by a token C2
2325 could cause mis-tokenization. */
2328 unsafe_chars (c1, c2)
2334 if (c2 == c1 || c2 == '=')
2338 case '0': case '1': case '2': case '3': case '4':
2339 case '5': case '6': case '7': case '8': case '9':
2340 case 'e': case 'E': case 'p': case 'P':
2341 if (c2 == '-' || c2 == '+')
2342 return 1; /* could extend a pre-processing number */
2345 if (c2 == '\'' || c2 == '\"')
2346 return 1; /* Could turn into L"xxx" or L'xxx'. */
2350 case 'a': case 'b': case 'c': case 'd': case 'f':
2351 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
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 case 'A': case 'B': case 'C': case 'D': case 'F':
2356 case 'G': case 'H': case 'I': case 'J': case 'K':
2357 case 'M': case 'N': case 'O': case 'Q': case 'R':
2358 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2360 /* We're in the middle of either a name or a pre-processing number. */
2361 return (is_idchar[c2] || c2 == '.');
2362 case '<': case '>': case '!': case '%': case '#': case ':':
2363 case '^': case '&': case '|': case '*': case '/': case '=':
2364 return (c2 == c1 || c2 == '=');
2369 /* Expand a macro call.
2370 HP points to the symbol that is the macro being called.
2371 Put the result of expansion onto the input stack
2372 so that subsequent input by our caller will use it.
2374 If macro wants arguments, caller has already verified that
2375 an argument list follows; arguments come from the input stack. */
2378 macroexpand (pfile, hp)
2383 DEFINITION *defn = hp->value.defn;
2384 register U_CHAR *xbuf;
2385 long start_line, start_column;
2387 struct argdata *args;
2388 long old_written = CPP_WRITTEN (pfile);
2390 int start_line = instack[indepth].lineno;
2392 int rest_args, rest_zero;
2396 CHECK_DEPTH (return;);
2400 /* This macro is being used inside a #if, which means it must be */
2401 /* recorded as a precondition. */
2402 if (pcp_inside_if && pcp_outfile && defn->predefined)
2403 dump_single_macro (hp, pcp_outfile);
2406 pfile->output_escapes++;
2407 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2409 nargs = defn->nargs;
2413 enum cpp_token token;
2415 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2417 for (i = 0; i < nargs; i++)
2419 args[i].raw = args[i].expanded = 0;
2420 args[i].raw_length = 0;
2421 args[i].expand_length = args[i].stringified_length = -1;
2422 args[i].use_count = 0;
2425 /* Parse all the macro args that are supplied. I counts them.
2426 The first NARGS args are stored in ARGS.
2427 The rest are discarded. If rest_args is set then we assume
2428 macarg absorbed the rest of the args. */
2432 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2437 if (i < nargs || (nargs == 0 && i == 0))
2439 /* if we are working on last arg which absorbs rest of args... */
2440 if (i == nargs - 1 && defn->rest_args)
2442 args[i].raw = CPP_WRITTEN (pfile);
2443 token = macarg (pfile, rest_args);
2444 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2445 args[i].newlines = 0; /* FIXME */
2448 token = macarg (pfile, 0);
2449 if (token == CPP_EOF || token == CPP_POP)
2451 cpp_error_with_line (pfile, start_line, start_column,
2452 "unterminated macro call");
2456 } while (token == CPP_COMMA);
2458 /* If we got one arg but it was just whitespace, call that 0 args. */
2461 register U_CHAR *bp = ARG_BASE + args[0].raw;
2462 register U_CHAR *lim = bp + args[0].raw_length;
2463 /* cpp.texi says for foo ( ) we provide one argument.
2464 However, if foo wants just 0 arguments, treat this as 0. */
2466 while (bp != lim && is_space[*bp]) bp++;
2471 /* Don't output an error message if we have already output one for
2472 a parse error above. */
2474 if (nargs == 0 && i > 0)
2476 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
2480 /* traditional C allows foo() if foo wants one argument. */
2481 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2483 /* the rest args token is allowed to absorb 0 tokens */
2484 else if (i == nargs - 1 && defn->rest_args)
2487 cpp_error (pfile, "macro `%s' used without args", hp->name);
2489 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2491 cpp_error (pfile, "macro `%s' used with only %d args",
2497 "macro `%s' used with too many (%d) args", hp->name, i);
2501 /* If macro wants zero args, we parsed the arglist for checking only.
2502 Read directly from the macro definition. */
2505 xbuf = defn->expansion;
2506 xbuf_len = defn->length;
2510 register U_CHAR *exp = defn->expansion;
2511 register int offset; /* offset in expansion,
2512 copied a piece at a time */
2513 register int totlen; /* total amount of exp buffer filled so far */
2515 register struct reflist *ap, *last_ap;
2517 /* Macro really takes args. Compute the expansion of this call. */
2519 /* Compute length in characters of the macro's expansion.
2520 Also count number of times each arg is used. */
2521 xbuf_len = defn->length;
2522 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2526 register struct argdata *arg = &args[ap->argno];
2527 /* Stringify if it hasn't already been */
2528 if (arg->stringified_length < 0)
2530 int arglen = arg->raw_length;
2534 /* Initially need_space is -1. Otherwise, 1 means the
2535 previous character was a space, but we suppressed it;
2536 0 means the previous character was a non-space. */
2537 int need_space = -1;
2539 arg->stringified = CPP_WRITTEN (pfile);
2540 if (!CPP_TRADITIONAL (pfile))
2541 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2542 for (; i < arglen; i++)
2544 c = (ARG_BASE + arg->raw)[i];
2548 /* Internal sequences of whitespace are replaced by
2549 one space except within an string or char token.*/
2552 if (CPP_WRITTEN (pfile) > (unsigned)arg->stringified
2553 && (CPP_PWRITTEN (pfile))[-1] == '@')
2555 /* "@ " escape markers are removed */
2556 CPP_ADJUST_WRITTEN (pfile, -1);
2559 if (need_space == 0)
2563 else if (need_space > 0)
2564 CPP_PUTC (pfile, ' ');
2579 else if (c == '\"' || c == '\'')
2583 /* Escape these chars */
2584 if (c == '\"' || (in_string && c == '\\'))
2585 CPP_PUTC (pfile, '\\');
2587 CPP_PUTC (pfile, c);
2590 CPP_RESERVE (pfile, 4);
2591 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o",
2593 CPP_ADJUST_WRITTEN (pfile, 4);
2596 if (!CPP_TRADITIONAL (pfile))
2597 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2598 arg->stringified_length
2599 = CPP_WRITTEN (pfile) - arg->stringified;
2601 xbuf_len += args[ap->argno].stringified_length;
2603 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2604 /* Add 4 for two newline-space markers to prevent
2605 token concatenation. */
2606 xbuf_len += args[ap->argno].raw_length + 4;
2609 /* We have an ordinary (expanded) occurrence of the arg.
2610 So compute its expansion, if we have not already. */
2611 if (args[ap->argno].expand_length < 0)
2613 args[ap->argno].expanded = CPP_WRITTEN (pfile);
2614 cpp_expand_to_buffer (pfile,
2615 ARG_BASE + args[ap->argno].raw,
2616 args[ap->argno].raw_length);
2618 args[ap->argno].expand_length
2619 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2622 /* Add 4 for two newline-space markers to prevent
2623 token concatenation. */
2624 xbuf_len += args[ap->argno].expand_length + 4;
2626 if (args[ap->argno].use_count < 10)
2627 args[ap->argno].use_count++;
2630 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2632 /* Generate in XBUF the complete expansion
2633 with arguments substituted in.
2634 TOTLEN is the total size generated so far.
2635 OFFSET is the index in the definition
2636 of where we are copying from. */
2637 offset = totlen = 0;
2638 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2639 last_ap = ap, ap = ap->next)
2641 register struct argdata *arg = &args[ap->argno];
2642 int count_before = totlen;
2644 /* Add chars to XBUF. */
2645 for (i = 0; i < ap->nchars; i++, offset++)
2646 xbuf[totlen++] = exp[offset];
2648 /* If followed by an empty rest arg with concatenation,
2649 delete the last run of nonwhite chars. */
2650 if (rest_zero && totlen > count_before
2651 && ((ap->rest_args && ap->raw_before)
2652 || (last_ap != NULL && last_ap->rest_args
2653 && last_ap->raw_after)))
2655 /* Delete final whitespace. */
2656 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2659 /* Delete the nonwhites before them. */
2660 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
2664 if (ap->stringify != 0)
2666 bcopy (ARG_BASE + arg->stringified,
2667 xbuf + totlen, arg->stringified_length);
2668 totlen += arg->stringified_length;
2670 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2672 U_CHAR *p1 = ARG_BASE + arg->raw;
2673 U_CHAR *l1 = p1 + arg->raw_length;
2676 while (p1 != l1 && is_space[*p1]) p1++;
2677 while (p1 != l1 && is_idchar[*p1])
2678 xbuf[totlen++] = *p1++;
2682 /* Arg is concatenated after: delete trailing whitespace,
2683 whitespace markers, and no-reexpansion markers. */
2686 if (is_space[l1[-1]]) l1--;
2687 else if (l1[-1] == '@')
2689 U_CHAR *p2 = l1 - 1;
2690 /* If whitespace is preceded by an odd number
2691 of `@' signs, the last `@' was a whitespace
2692 marker; drop it too. */
2693 while (p2 != p1 && p2[0] == '@') p2--;
2698 else if (l1[-1] == '-')
2700 U_CHAR *p2 = l1 - 1;
2701 /* If a `-' is preceded by an odd number of
2702 `@' signs then it and the last `@' are
2703 a no-reexpansion marker. */
2704 while (p2 != p1 && p2[0] == '@') p2--;
2714 /* Delete any no-reexpansion marker that precedes
2715 an identifier at the beginning of the argument. */
2716 if (p1[0] == '@' && p1[1] == '-')
2719 bcopy (p1, xbuf + totlen, l1 - p1);
2724 U_CHAR *expanded = ARG_BASE + arg->expanded;
2725 if (!ap->raw_before && totlen > 0 && arg->expand_length
2726 && !CPP_TRADITIONAL(pfile)
2727 && unsafe_chars (xbuf[totlen-1], expanded[0]))
2729 xbuf[totlen++] = '@';
2730 xbuf[totlen++] = ' ';
2733 bcopy (expanded, xbuf + totlen, arg->expand_length);
2734 totlen += arg->expand_length;
2736 if (!ap->raw_after && totlen > 0 && offset < defn->length
2737 && !CPP_TRADITIONAL(pfile)
2738 && unsafe_chars (xbuf[totlen-1], exp[offset]))
2740 xbuf[totlen++] = '@';
2741 xbuf[totlen++] = ' ';
2744 /* If a macro argument with newlines is used multiple times,
2745 then only expand the newlines once. This avoids creating
2746 output lines which don't correspond to any input line,
2747 which confuses gdb and gcov. */
2748 if (arg->use_count > 1 && arg->newlines > 0)
2750 /* Don't bother doing change_newlines for subsequent
2754 = change_newlines (expanded, arg->expand_length);
2758 if (totlen > xbuf_len)
2762 /* if there is anything left of the definition
2763 after handling the arg list, copy that in too. */
2765 for (i = offset; i < defn->length; i++)
2767 /* if we've reached the end of the macro */
2770 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
2771 && last_ap->raw_after))
2772 xbuf[totlen++] = exp[i];
2780 pfile->output_escapes--;
2782 /* Now put the expansion on the input stack
2783 so our caller will commence reading from it. */
2784 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
2785 CPP_BUFFER (pfile)->has_escapes = 1;
2787 /* Pop the space we've used in the token_buffer for argument expansion. */
2788 CPP_SET_WRITTEN (pfile, old_written);
2790 /* Recursive macro use sometimes works traditionally.
2791 #define foo(x,y) bar (x (y,0), y)
2794 if (!CPP_TRADITIONAL (pfile))
2795 hp->type = T_DISABLED;
2799 push_macro_expansion (pfile, xbuf, xbuf_len, hp)
2801 register U_CHAR *xbuf;
2805 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
2808 mbuf->cleanup = macro_cleanup;
2811 /* The first chars of the expansion should be a "@ " added by
2812 collect_expansion. This is to prevent accidental token-pasting
2813 between the text preceding the macro invocation, and the macro
2816 We would like to avoid adding unneeded spaces (for the sake of
2817 tools that use cpp, such as imake). In some common cases we can
2818 tell that it is safe to omit the space.
2820 The character before the macro invocation cannot have been an
2821 idchar (or else it would have been pasted with the idchars of
2822 the macro name). Therefore, if the first non-space character
2823 of the expansion is an idchar, we do not need the extra space
2824 to prevent token pasting.
2826 Also, we don't need the extra space if the first char is '(',
2827 or some other (less common) characters. */
2829 if (xbuf[0] == '@' && xbuf[1] == ' '
2830 && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\''
2831 || xbuf[2] == '\"'))
2835 /* Like cpp_get_token, except that it does not read past end-of-line.
2836 Also, horizontal space is skipped, and macros are popped. */
2838 static enum cpp_token
2839 get_directive_token (pfile)
2844 long old_written = CPP_WRITTEN (pfile);
2845 enum cpp_token token;
2846 cpp_skip_hspace (pfile);
2847 if (PEEKC () == '\n')
2849 token = cpp_get_token (pfile);
2853 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2855 /* ... else fall though ... */
2856 case CPP_HSPACE: case CPP_COMMENT:
2857 CPP_SET_WRITTEN (pfile, old_written);
2865 /* Handle #include and #import.
2866 This function expects to see "fname" or <fname> on the input.
2868 The input is normally in part of the output_buffer following
2869 CPP_WRITTEN, and will get overwritten by output_line_command.
2870 I.e. in input file specification has been popped by handle_directive.
2874 do_include (pfile, keyword, unused1, unused2)
2876 struct directive *keyword;
2877 U_CHAR *unused1 ATTRIBUTE_UNUSED, *unused2 ATTRIBUTE_UNUSED;
2879 int importing = (keyword->type == T_IMPORT);
2880 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
2881 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
2882 int before; /* included before? */
2887 enum cpp_token token;
2889 /* Chain of dirs to search */
2890 struct include_hash *ihash;
2891 struct file_name_list *search_start;
2893 long old_written = CPP_WRITTEN (pfile);
2897 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
2900 cpp_pedwarn (pfile, "ANSI C does not allow `#import'");
2902 cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'");
2905 if (importing && CPP_OPTIONS (pfile)->warn_import
2906 && !CPP_OPTIONS (pfile)->inhibit_warnings
2907 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
2909 pfile->import_warning = 1;
2910 cpp_warning (pfile, "`#import' is obsolete, use an #ifdef wrapper in the header file");
2913 pfile->parsing_include_directive++;
2914 token = get_directive_token (pfile);
2915 pfile->parsing_include_directive--;
2917 if (token == CPP_STRING)
2919 fbeg = pfile->token_buffer + old_written + 1;
2920 fend = CPP_PWRITTEN (pfile) - 1;
2922 if (fbeg[-1] == '<')
2926 else if (token == CPP_NAME)
2928 /* Support '#include xyz' like VAX-C to allow for easy use of
2929 * all the decwindow include files. It defaults to '#include
2930 * <xyz.h>' and generates a warning. */
2932 "VAX-C-style include specification found, use '#include <filename.h>' !");
2935 /* Append the missing `.h' to the name. */
2936 CPP_PUTS (pfile, ".h", 3)
2937 CPP_NUL_TERMINATE_Q (pfile);
2939 fbeg = pfile->token_buffer + old_written;
2940 fend = CPP_PWRITTEN (pfile);
2946 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
2947 CPP_SET_WRITTEN (pfile, old_written);
2948 skip_rest_of_line (pfile);
2952 token = get_directive_token (pfile);
2953 if (token != CPP_VSPACE)
2955 cpp_error (pfile, "junk at end of `#include'");
2956 skip_rest_of_line (pfile);
2959 CPP_SET_WRITTEN (pfile, old_written);
2965 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
2971 for (fp = CPP_BUFFER (pfile);
2972 fp != CPP_NULL_BUFFER (pfile);
2973 fp = CPP_PREV_BUFFER (fp))
2974 if (fp->fname != NULL)
2977 if (fp == CPP_NULL_BUFFER (pfile))
2980 /* For #include_next, skip in the search path
2981 past the dir in which the containing file was found. */
2985 search_start = fp->ihash->foundhere->next;
2990 search_start = CPP_OPTIONS (pfile)->bracket_include;
2993 if (!CPP_OPTIONS (pfile)->ignore_srcdir)
2996 search_start = fp->actual_dir;
2999 search_start = CPP_OPTIONS (pfile)->quote_include;
3005 cpp_error (pfile, "No include path in which to find %s", fbeg);
3009 fd = find_include_file (pfile, fbeg, search_start, &ihash, &before);
3016 if (CPP_OPTIONS (pfile)->print_deps_missing_files
3017 && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
3018 (pfile->system_include_depth > 0)))
3020 if (!angle_brackets)
3021 deps_output (pfile, fbeg, ' ');
3025 struct file_name_list *ptr;
3026 /* If requested as a system header, assume it belongs in
3027 the first system header directory. */
3028 if (CPP_OPTIONS (pfile)->bracket_include)
3029 ptr = CPP_OPTIONS (pfile)->bracket_include;
3031 ptr = CPP_OPTIONS (pfile)->quote_include;
3033 p = (char *) alloca (strlen (ptr->name)
3034 + strlen (fbeg) + 2);
3035 if (*ptr->name != '\0')
3037 strcpy (p, ptr->name);
3041 deps_output (pfile, p, ' ');
3044 /* If -M was specified, and this header file won't be added to
3045 the dependency list, then don't count this as an error,
3046 because we can still produce correct output. Otherwise, we
3047 can't produce correct output, because there may be
3048 dependencies we need inside the missing file, and we don't
3049 know what directory this missing file exists in. */
3050 else if (CPP_PRINT_DEPS (pfile)
3051 && (CPP_PRINT_DEPS (pfile)
3052 <= (angle_brackets || (pfile->system_include_depth > 0))))
3053 cpp_warning (pfile, "No include path in which to find %s", fbeg);
3055 cpp_error_from_errno (pfile, fbeg);
3060 /* For -M, add the file to the dependencies on its first inclusion. */
3061 if (!before && (CPP_PRINT_DEPS (pfile)
3062 > (angle_brackets || (pfile->system_include_depth > 0))))
3063 deps_output (pfile, ihash->name, ' ');
3065 /* Handle -H option. */
3066 if (CPP_OPTIONS(pfile)->print_include_names)
3068 fp = CPP_BUFFER (pfile);
3069 while ((fp = CPP_PREV_BUFFER (fp)) != CPP_NULL_BUFFER (pfile))
3071 fprintf (stderr, " %s\n", ihash->name);
3074 /* Actually process the file */
3077 ihash->control_macro = "";
3079 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
3086 pfile->system_include_depth++; /* Decremented in file_cleanup. */
3088 if (finclude (pfile, fd, ihash))
3090 output_line_command (pfile, 0, enter_file);
3091 pfile->only_seen_white = 2;
3098 /* Convert a character string literal into a nul-terminated string.
3099 The input string is [IN ... LIMIT).
3100 The result is placed in RESULT. RESULT can be the same as IN.
3101 The value returned in the end of the string written to RESULT,
3102 or NULL on error. */
3105 convert_string (pfile, result, in, limit, handle_escapes)
3107 register U_CHAR *result, *in, *limit;
3127 char *bpc = (char *) in;
3128 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc, 0x00ff);
3129 in = (U_CHAR *) bpc;
3131 *result++ = (U_CHAR)c;
3134 /* else fall through */
3144 * interpret #line command. Remembers previously seen fnames
3145 * in its very own hash table.
3147 #define FNAME_HASHSIZE 37
3150 do_line (pfile, keyword, unused1, unused2)
3152 struct directive *keyword ATTRIBUTE_UNUSED;
3153 U_CHAR *unused1 ATTRIBUTE_UNUSED, *unused2 ATTRIBUTE_UNUSED;
3155 cpp_buffer *ip = CPP_BUFFER (pfile);
3157 long old_written = CPP_WRITTEN (pfile);
3158 enum file_change_code file_change = same_file;
3159 enum cpp_token token;
3161 token = get_directive_token (pfile);
3163 if (token != CPP_NUMBER
3164 || !ISDIGIT(pfile->token_buffer[old_written]))
3166 cpp_error (pfile, "invalid format `#line' command");
3167 goto bad_line_directive;
3170 /* The Newline at the end of this line remains to be processed.
3171 To put the next line at the specified line number,
3172 we must store a line number now that is one less. */
3173 new_lineno = atoi ((char *)(pfile->token_buffer + old_written)) - 1;
3174 CPP_SET_WRITTEN (pfile, old_written);
3176 /* NEW_LINENO is one less than the actual line number here. */
3177 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3178 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3180 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3181 if (PEEKC() && !is_space[PEEKC()]) {
3182 cpp_error (pfile, "invalid format `#line' command");
3183 goto bad_line_directive;
3187 token = get_directive_token (pfile);
3189 if (token == CPP_STRING) {
3190 U_CHAR *fname = pfile->token_buffer + old_written;
3192 static HASHNODE *fname_table[FNAME_HASHSIZE];
3193 HASHNODE *hp, **hash_bucket;
3198 /* Turn the file name, which is a character string literal,
3199 into a null-terminated string. Do this in place. */
3200 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3201 if (end_name == NULL)
3203 cpp_error (pfile, "invalid format `#line' command");
3204 goto bad_line_directive;
3207 fname_length = end_name - fname;
3209 num_start = CPP_WRITTEN (pfile);
3210 token = get_directive_token (pfile);
3211 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3212 p = pfile->token_buffer + num_start;
3213 if (CPP_PEDANTIC (pfile))
3214 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3216 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3218 cpp_error (pfile, "invalid format `#line' command");
3219 goto bad_line_directive;
3222 file_change = enter_file;
3224 file_change = leave_file;
3226 ip->system_header_p = 1;
3227 else /* if (*p == '4') */
3228 ip->system_header_p = 2;
3230 CPP_SET_WRITTEN (pfile, num_start);
3231 token = get_directive_token (pfile);
3232 p = pfile->token_buffer + num_start;
3233 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3234 ip->system_header_p = *p == '3' ? 1 : 2;
3235 token = get_directive_token (pfile);
3237 if (token != CPP_VSPACE) {
3238 cpp_error (pfile, "invalid format `#line' command");
3239 goto bad_line_directive;
3243 hash_bucket = &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3244 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3245 if (hp->length == fname_length
3246 && strncmp (hp->value.cpval, fname, fname_length) == 0) {
3247 ip->nominal_fname = hp->value.cpval;
3251 /* Didn't find it; cons up a new one. */
3252 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3253 hp->next = *hash_bucket;
3256 hp->length = fname_length;
3257 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3258 bcopy (fname, hp->value.cpval, fname_length);
3261 else if (token != CPP_VSPACE && token != CPP_EOF) {
3262 cpp_error (pfile, "invalid format `#line' command");
3263 goto bad_line_directive;
3266 ip->lineno = new_lineno;
3268 skip_rest_of_line (pfile);
3269 CPP_SET_WRITTEN (pfile, old_written);
3270 output_line_command (pfile, 0, file_change);
3275 * remove the definition of a symbol from the symbol table.
3276 * according to un*x /lib/cpp, it is not an error to undef
3277 * something that has no definitions, so it isn't one here either.
3281 do_undef (pfile, keyword, buf, limit)
3283 struct directive *keyword;
3284 U_CHAR *buf, *limit;
3288 U_CHAR *orig_buf = buf;
3291 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3292 if (pcp_outfile && keyword)
3293 pass_thru_directive (buf, limit, pfile, keyword);
3296 SKIP_WHITE_SPACE (buf);
3297 sym_length = check_macro_name (pfile, buf, "macro");
3299 while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL)
3301 /* If we are generating additional info for debugging (with -g) we
3302 need to pass through all effective #undef commands. */
3303 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3304 pass_thru_directive (orig_buf, limit, pfile, keyword);
3305 if (hp->type != T_MACRO)
3306 cpp_warning (pfile, "undefining `%s'", hp->name);
3310 if (CPP_PEDANTIC (pfile)) {
3312 SKIP_WHITE_SPACE (buf);
3314 cpp_pedwarn (pfile, "garbage after `#undef' directive");
3320 * Report an error detected by the program we are processing.
3321 * Use the text of the line in the error message.
3322 * (We use error because it prints the filename & line#.)
3326 do_error (pfile, keyword, buf, limit)
3328 struct directive *keyword ATTRIBUTE_UNUSED;
3329 U_CHAR *buf, *limit;
3331 int length = limit - buf;
3332 U_CHAR *copy = (U_CHAR *) alloca (length + 1);
3333 bcopy (buf, copy, length);
3335 SKIP_WHITE_SPACE (copy);
3336 cpp_error (pfile, "#error %s", copy);
3341 * Report a warning detected by the program we are processing.
3342 * Use the text of the line in the warning message, then continue.
3343 * (We use error because it prints the filename & line#.)
3347 do_warning (pfile, keyword, buf, limit)
3349 struct directive *keyword ATTRIBUTE_UNUSED;
3350 U_CHAR *buf, *limit;
3352 int length = limit - buf;
3353 U_CHAR *copy = (U_CHAR *) alloca (length + 1);
3354 bcopy (buf, copy, length);
3356 SKIP_WHITE_SPACE (copy);
3358 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3359 cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
3361 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
3362 if -pedantic-errors is given, #warning should cause an error. */
3363 cpp_pedwarn (pfile, "#warning %s", copy);
3367 /* Report program identification. */
3370 do_ident (pfile, keyword, buf, limit)
3372 struct directive *keyword ATTRIBUTE_UNUSED;
3373 U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
3375 /* long old_written = CPP_WRITTEN (pfile);*/
3377 /* Allow #ident in system headers, since that's not user's fault. */
3378 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3379 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
3381 /* Leave rest of line to be read by later calls to cpp_get_token. */
3386 /* #pragma and its argument line have already been copied to the output file.
3387 Just check for some recognized pragmas that need validation here. */
3390 do_pragma (pfile, keyword, buf, limit)
3392 struct directive *keyword ATTRIBUTE_UNUSED;
3393 U_CHAR *buf, *limit ATTRIBUTE_UNUSED;
3395 while (*buf == ' ' || *buf == '\t')
3397 if (!strncmp (buf, "once", 4))
3399 cpp_buffer *ip = NULL;
3401 /* Allow #pragma once in system headers, since that's not the user's
3403 if (!CPP_BUFFER (pfile)->system_header_p)
3404 cpp_warning (pfile, "`#pragma once' is obsolete");
3406 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3408 if (ip == CPP_NULL_BUFFER (pfile))
3410 if (ip->fname != NULL)
3414 if (CPP_PREV_BUFFER (ip) == CPP_NULL_BUFFER (pfile))
3415 cpp_warning (pfile, "`#pragma once' outside include file");
3417 ip->ihash->control_macro = ""; /* never repeat */
3420 if (!strncmp (buf, "implementation", 14))
3422 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3423 been included yet. */
3424 struct include_hash *ptr;
3425 U_CHAR *p = buf + 14, *fname, *fcopy;
3426 SKIP_WHITE_SPACE (p);
3427 if (*p == '\n' || *p != '\"')
3431 p = (U_CHAR *) index (fname, '\"');
3433 fcopy = alloca (p - fname + 1);
3434 bcopy (fname, fcopy, p - fname);
3435 fcopy[p-fname] = '\0';
3437 ptr = include_hash (pfile, fcopy, 0);
3440 "`#pragma implementation' for `%s' appears after file is included",
3448 /* This was a fun hack, but #pragma seems to start to be useful.
3449 By failing to recognize it, we pass it through unchanged to cc1. */
3452 * the behavior of the #pragma directive is implementation defined.
3453 * this implementation defines it as follows.
3460 if (open ("/dev/tty", O_RDONLY, 0666) != 0)
3463 if (open ("/dev/tty", O_WRONLY, 0666) != 1)
3465 execl ("/usr/games/hack", "#pragma", 0);
3466 execl ("/usr/games/rogue", "#pragma", 0);
3467 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
3468 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
3470 fatal ("You are in a maze of twisty compiler features, all different");
3474 #ifdef SCCS_DIRECTIVE
3475 /* Just ignore #sccs, on systems where we define it at all. */
3478 do_sccs (pfile, keyword, buf, limit)
3480 struct directive *keyword ATTRIBUTE_UNUSED;
3481 U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
3483 if (CPP_PEDANTIC (pfile))
3484 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
3490 * handle #if command by
3491 * 1) inserting special `defined' keyword into the hash table
3492 * that gets turned into 0 or 1 by special_symbol (thus,
3493 * if the luser has a symbol called `defined' already, it won't
3494 * work inside the #if command)
3495 * 2) rescan the input into a temporary output buffer
3496 * 3) pass the output buffer to the yacc parser and collect a value
3497 * 4) clean up the mess left from steps 1 and 2.
3498 * 5) call conditional_skip to skip til the next #endif (etc.),
3499 * or not, depending on the value from step 3.
3503 do_if (pfile, keyword, buf, limit)
3505 struct directive *keyword ATTRIBUTE_UNUSED;
3506 U_CHAR *buf, *limit;
3508 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
3509 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
3514 * handle a #elif directive by not changing if_stack either.
3515 * see the comment above do_else.
3519 do_elif (pfile, keyword, buf, limit)
3521 struct directive *keyword ATTRIBUTE_UNUSED;
3522 U_CHAR *buf, *limit;
3524 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
3525 cpp_error (pfile, "`#elif' not within a conditional");
3528 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
3529 cpp_error (pfile, "`#elif' after `#else'");
3531 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
3533 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
3534 && strcmp (pfile->if_stack->fname,
3535 CPP_BUFFER (pfile)->nominal_fname) != 0)
3536 fprintf (stderr, ", file %s", pfile->if_stack->fname);
3537 fprintf (stderr, ")\n");
3539 pfile->if_stack->type = T_ELIF;
3542 if (pfile->if_stack->if_succeeded)
3543 skip_if_group (pfile, 0);
3545 HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf);
3547 skip_if_group (pfile, 0);
3549 ++pfile->if_stack->if_succeeded; /* continue processing input */
3550 output_line_command (pfile, 1, same_file);
3557 * evaluate a #if expression in BUF, of length LENGTH,
3558 * then parse the result as a C expression and return the value as an int.
3561 static HOST_WIDE_INT
3562 eval_if_expression (pfile, buf, length)
3564 U_CHAR *buf ATTRIBUTE_UNUSED;
3565 int length ATTRIBUTE_UNUSED;
3567 HASHNODE *save_defined;
3568 HOST_WIDE_INT value;
3569 long old_written = CPP_WRITTEN (pfile);
3571 save_defined = install ((U_CHAR *)"defined", -1, T_SPEC_DEFINED, 0, 0, -1);
3572 pfile->pcp_inside_if = 1;
3574 value = cpp_parse_expr (pfile);
3575 pfile->pcp_inside_if = 0;
3576 delete_macro (save_defined); /* clean up special symbol */
3578 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
3584 * routine to handle ifdef/ifndef. Try to look up the symbol,
3585 * then do or don't skip to the #endif/#else/#elif depending
3586 * on what directive is actually being processed.
3590 do_xifdef (pfile, keyword, unused1, unused2)
3592 struct directive *keyword;
3593 U_CHAR *unused1 ATTRIBUTE_UNUSED, *unused2 ATTRIBUTE_UNUSED;
3596 cpp_buffer *ip = CPP_BUFFER (pfile);
3599 enum cpp_token token;
3600 int start_of_file = 0;
3601 U_CHAR *control_macro = 0;
3602 int old_written = CPP_WRITTEN (pfile);
3604 /* Detect a #ifndef at start of file (not counting comments). */
3605 if (ip->fname != 0 && keyword->type == T_IFNDEF)
3606 start_of_file = pfile->only_seen_white == 2;
3608 pfile->no_macro_expand++;
3609 token = get_directive_token (pfile);
3610 pfile->no_macro_expand--;
3612 ident = pfile->token_buffer + old_written;
3613 ident_length = CPP_WRITTEN (pfile) - old_written;
3614 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
3616 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
3618 skip = (keyword->type == T_IFDEF);
3619 if (! CPP_TRADITIONAL (pfile))
3620 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
3622 else if (token == CPP_NAME)
3624 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
3625 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
3626 if (start_of_file && !skip)
3628 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
3629 bcopy (ident, control_macro, ident_length + 1);
3634 skip = (keyword->type == T_IFDEF);
3635 if (! CPP_TRADITIONAL (pfile))
3636 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
3639 if (!CPP_TRADITIONAL (pfile))
3641 cpp_skip_hspace (pfile);
3643 if (c != EOF && c != '\n')
3644 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
3646 skip_rest_of_line (pfile);
3650 /* Output a precondition for this macro. */
3651 if (hp && hp->value.defn->predefined)
3652 fprintf (pcp_outfile, "#define %s\n", hp->name);
3655 fprintf (pcp_outfile, "#undef ");
3656 while (is_idchar[*cp]) /* Ick! */
3657 fputc (*cp++, pcp_outfile);
3658 putc ('\n', pcp_outfile);
3662 conditional_skip (pfile, skip, T_IF, control_macro);
3666 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
3667 If this is a #ifndef starting at the beginning of a file,
3668 CONTROL_MACRO is the macro name tested by the #ifndef.
3669 Otherwise, CONTROL_MACRO is 0. */
3672 conditional_skip (pfile, skip, type, control_macro)
3675 enum node_type type;
3676 U_CHAR *control_macro;
3678 IF_STACK_FRAME *temp;
3680 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
3681 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
3683 temp->lineno = CPP_BUFFER (pfile)->lineno;
3685 temp->next = pfile->if_stack;
3686 temp->control_macro = control_macro;
3687 pfile->if_stack = temp;
3689 pfile->if_stack->type = type;
3692 skip_if_group (pfile, 0);
3695 ++pfile->if_stack->if_succeeded;
3696 output_line_command (pfile, 1, same_file);
3701 * skip to #endif, #else, or #elif. adjust line numbers, etc.
3702 * leaves input ptr at the sharp sign found.
3703 * If ANY is nonzero, return at next directive of any sort.
3707 skip_if_group (pfile, any)
3712 struct directive *kt;
3713 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
3715 U_CHAR *beg_of_line = bp;
3717 register int ident_length;
3719 struct parse_marker line_start_mark;
3721 parse_set_mark (&line_start_mark, pfile);
3723 if (CPP_OPTIONS (pfile)->output_conditionals) {
3724 static char failed[] = "#failed\n";
3725 CPP_PUTS (pfile, failed, sizeof(failed)-1);
3727 output_line_command (pfile, 1, same_file);
3731 if (CPP_OPTIONS (pfile)->output_conditionals)
3733 cpp_buffer *pbuf = CPP_BUFFER (pfile);
3734 U_CHAR *start_line = pbuf->buf + line_start_mark.position;
3735 CPP_PUTS (pfile, start_line, pbuf->cur - start_line);
3737 parse_move_mark (&line_start_mark, pfile);
3738 if (!CPP_TRADITIONAL (pfile))
3739 cpp_skip_hspace (pfile);
3743 int old_written = CPP_WRITTEN (pfile);
3744 cpp_skip_hspace (pfile);
3746 parse_name (pfile, GETC());
3747 ident_length = CPP_WRITTEN (pfile) - old_written;
3748 ident = pfile->token_buffer + old_written;
3749 pfile->limit = ident;
3751 if (ident_length == 0)
3752 goto not_a_directive;
3754 /* Handle # followed by a line number. */
3756 /* Avoid error for `###' and similar cases unless -pedantic. */
3759 for (kt = directive_table; kt->length >= 0; kt++)
3761 IF_STACK_FRAME *temp;
3762 if (ident_length == kt->length
3763 && strncmp (ident, kt->name, kt->length) == 0)
3765 /* If we are asked to return on next directive, do so now. */
3775 = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
3776 temp->next = pfile->if_stack;
3777 pfile->if_stack = temp;
3779 temp->lineno = CPP_BUFFER(pfile)->lineno;
3781 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
3782 temp->type = kt->type;
3786 if (CPP_PEDANTIC (pfile) && pfile->if_stack != save_if_stack)
3787 validate_else (pfile,
3788 kt->type == T_ELSE ? "#else" : "#endif");
3790 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
3793 "`#%s' not within a conditional", kt->name);
3796 else if (pfile->if_stack == save_if_stack)
3797 goto done; /* found what we came for */
3799 if (kt->type != T_ENDIF)
3801 if (pfile->if_stack->type == T_ELSE)
3802 cpp_error (pfile, "`#else' or `#elif' after `#else'");
3803 pfile->if_stack->type = kt->type;
3807 temp = pfile->if_stack;
3808 pfile->if_stack = temp->next;
3815 /* Don't let erroneous code go by. */
3816 if (kt->length < 0 && !CPP_OPTIONS (pfile)->lang_asm
3817 && CPP_PEDANTIC (pfile))
3818 cpp_pedwarn (pfile, "invalid preprocessor directive name");
3822 /* We're in the middle of a line. Skip the rest of it. */
3829 case '/': /* possible comment */
3830 c = skip_comment (pfile, NULL);
3837 old = CPP_WRITTEN (pfile);
3838 cpp_get_token (pfile);
3839 CPP_SET_WRITTEN (pfile, old);
3842 /* Char after backslash loses its special meaning. */
3843 if (PEEKC() == '\n')
3853 if (CPP_OPTIONS (pfile)->output_conditionals) {
3854 static char end_failed[] = "#endfailed\n";
3855 CPP_PUTS (pfile, end_failed, sizeof(end_failed)-1);
3858 pfile->only_seen_white = 1;
3859 parse_goto_mark (&line_start_mark, pfile);
3860 parse_clear_mark (&line_start_mark);
3864 * handle a #else directive. Do this by just continuing processing
3865 * without changing if_stack ; this is so that the error message
3866 * for missing #endif's etc. will point to the original #if. It
3867 * is possible that something different would be better.
3871 do_else (pfile, keyword, buf, limit)
3873 struct directive *keyword ATTRIBUTE_UNUSED;
3874 U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
3876 cpp_buffer *ip = CPP_BUFFER (pfile);
3878 if (CPP_PEDANTIC (pfile))
3879 validate_else (pfile, "#else");
3880 skip_rest_of_line (pfile);
3882 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
3883 cpp_error (pfile, "`#else' not within a conditional");
3886 /* #ifndef can't have its special treatment for containing the whole file
3887 if it has a #else clause. */
3888 pfile->if_stack->control_macro = 0;
3890 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
3891 cpp_error (pfile, "`#else' after `#else'");
3892 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
3893 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
3894 fprintf (stderr, ", file %s", pfile->if_stack->fname);
3895 fprintf (stderr, ")\n");
3897 pfile->if_stack->type = T_ELSE;
3900 if (pfile->if_stack->if_succeeded)
3901 skip_if_group (pfile, 0);
3903 ++pfile->if_stack->if_succeeded; /* continue processing input */
3904 output_line_command (pfile, 1, same_file);
3910 * unstack after #endif command
3914 do_endif (pfile, keyword, buf, limit)
3916 struct directive *keyword ATTRIBUTE_UNUSED;
3917 U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
3919 if (CPP_PEDANTIC (pfile))
3920 validate_else (pfile, "#endif");
3921 skip_rest_of_line (pfile);
3923 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
3924 cpp_error (pfile, "unbalanced `#endif'");
3927 IF_STACK_FRAME *temp = pfile->if_stack;
3928 pfile->if_stack = temp->next;
3929 if (temp->control_macro != 0)
3931 /* This #endif matched a #ifndef at the start of the file.
3932 See if it is at the end of the file. */
3933 struct parse_marker start_mark;
3936 parse_set_mark (&start_mark, pfile);
3940 cpp_skip_hspace (pfile);
3945 parse_goto_mark (&start_mark, pfile);
3946 parse_clear_mark (&start_mark);
3950 /* This #endif ends a #ifndef
3951 that contains all of the file (aside from whitespace).
3952 Arrange not to include the file again
3953 if the macro that was tested is defined. */
3954 struct cpp_buffer *ip;
3955 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3956 if (ip->fname != NULL)
3958 ip->ihash->control_macro = temp->control_macro;
3962 output_line_command (pfile, 1, same_file);
3967 /* When an #else or #endif is found while skipping failed conditional,
3968 if -pedantic was specified, this is called to warn about text after
3969 the command name. P points to the first char after the command name. */
3972 validate_else (pfile, directive)
3977 cpp_skip_hspace (pfile);
3979 if (c != EOF && c != '\n')
3981 "text following `%s' violates ANSI standard", directive);
3984 /* Get the next token, and add it to the text in pfile->token_buffer.
3985 Return the kind of token we got. */
3988 cpp_get_token (pfile)
3991 register int c, c2, c3;
3993 long start_line, start_column;
3994 enum cpp_token token;
3995 struct cpp_options *opts = CPP_OPTIONS (pfile);
3996 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
4002 if (CPP_BUFFER (pfile)->seen_eof)
4004 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4011 cpp_buffer *next_buf
4012 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4013 CPP_BUFFER (pfile)->seen_eof = 1;
4014 if (CPP_BUFFER (pfile)->nominal_fname
4015 && next_buf != CPP_NULL_BUFFER (pfile))
4017 /* We're about to return from an #include file.
4018 Emit #line information now (as part of the CPP_POP) result.
4019 But the #line refers to the file we will pop to. */
4020 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4021 CPP_BUFFER (pfile) = next_buf;
4022 pfile->input_stack_listing_current = 0;
4023 output_line_command (pfile, 0, leave_file);
4024 CPP_BUFFER (pfile) = cur_buffer;
4034 struct parse_marker start_mark;
4036 if (PEEKC () == '=')
4038 if (opts->put_out_comments)
4039 parse_set_mark (&start_mark, pfile);
4041 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4042 &start_line, &start_column);
4043 c = skip_comment (pfile, &newlines);
4044 if (opts->put_out_comments && (c == '/' || c == EOF))
4045 parse_clear_mark (&start_mark);
4050 cpp_error_with_line (pfile, start_line, start_column,
4051 "unterminated comment");
4054 c = '/'; /* Initial letter of comment. */
4056 /* Comments are equivalent to spaces.
4057 For -traditional, a comment is equivalent to nothing. */
4058 if (opts->put_out_comments)
4060 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4061 U_CHAR *start = pbuf->buf + start_mark.position;
4062 int len = pbuf->cur - start;
4063 CPP_RESERVE(pfile, 1 + len);
4064 CPP_PUTC_Q (pfile, c);
4065 CPP_PUTS_Q (pfile, start, len);
4066 pfile->lineno += newlines;
4067 parse_clear_mark (&start_mark);
4070 else if (CPP_TRADITIONAL (pfile))
4077 /* This may not work if cpp_get_token is called recursively,
4078 since many places look for horizontal space. */
4081 /* Copy the newlines into the output buffer, in order to
4082 avoid the pain of a #line every time a multiline comment
4084 CPP_RESERVE(pfile, newlines);
4085 while (--newlines >= 0)
4087 CPP_PUTC_Q (pfile, '\n');
4093 CPP_RESERVE(pfile, 1);
4094 CPP_PUTC_Q (pfile, ' ');
4098 if (opts->for_lint) {
4101 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4103 if (lintcmd != NULL) {
4104 /* I believe it is always safe to emit this newline: */
4106 bcopy ("#pragma lint ", (char *) obp, 13);
4108 bcopy (lintcmd, (char *) obp, cmdlen);
4113 bcopy (argbp, (char *) obp, arglen);
4117 /* OK, now bring us back to the state we were in before we entered
4118 this branch. We need #line because the newline for the pragma
4119 could mess things up. */
4120 output_line_command (pfile, 0, same_file);
4121 *(obp++) = ' '; /* just in case, if comments are copied thru */
4129 /* If this is expanding a macro definition, don't recognize
4130 preprocessor directives. */
4133 /* If this is expand_into_temp_buffer, recognize them
4134 only after an actual newline at this level,
4135 not at the beginning of the input level. */
4136 if (ip->fname == 0 && beg_of_line == ip->buf)
4142 if (!pfile->only_seen_white)
4144 if (handle_directive (pfile))
4145 return CPP_DIRECTIVE;
4146 pfile->only_seen_white = 0;
4151 /* A single quoted string is treated like a double -- some
4152 programs (e.g., troff) are perverse this way */
4153 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4154 &start_line, &start_column);
4155 old_written = CPP_WRITTEN (pfile);
4157 CPP_PUTC (pfile, c);
4163 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4165 /* try harder: this string crosses a macro expansion
4166 boundary. This can happen naturally if -traditional.
4167 Otherwise, only -D can make a macro with an unmatched
4169 cpp_buffer *next_buf
4170 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4171 (*CPP_BUFFER (pfile)->cleanup)
4172 (CPP_BUFFER (pfile), pfile);
4173 CPP_BUFFER (pfile) = next_buf;
4176 if (!CPP_TRADITIONAL (pfile))
4178 cpp_error_with_line (pfile, start_line, start_column,
4179 "unterminated string or character constant");
4180 if (pfile->multiline_string_line != start_line
4181 && pfile->multiline_string_line != 0)
4182 cpp_error_with_line (pfile,
4183 pfile->multiline_string_line, -1,
4184 "possible real start of unterminated constant");
4185 pfile->multiline_string_line = 0;
4189 CPP_PUTC (pfile, cc);
4193 /* Traditionally, end of line ends a string constant with
4194 no error. So exit the loop and record the new line. */
4195 if (CPP_TRADITIONAL (pfile))
4199 cpp_error_with_line (pfile, start_line, start_column,
4200 "unterminated character constant");
4203 if (CPP_PEDANTIC (pfile)
4204 && pfile->multiline_string_line == 0)
4206 cpp_pedwarn_with_line (pfile, start_line, start_column,
4207 "string constant runs past end of line");
4209 if (pfile->multiline_string_line == 0)
4210 pfile->multiline_string_line = start_line;
4217 /* Backslash newline is replaced by nothing at all. */
4218 CPP_ADJUST_WRITTEN (pfile, -1);
4223 /* ANSI stupidly requires that in \\ the second \
4224 is *not* prevented from combining with a newline. */
4227 CPP_PUTC (pfile, cc);
4239 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4240 CPP_PWRITTEN (pfile));
4241 pfile->only_seen_white = 0;
4242 return c == '\'' ? CPP_CHAR : CPP_STRING;
4245 if (!opts->dollars_in_ident)
4250 if (opts->cplusplus && PEEKC () == ':')
4259 if (c2 == c || c2 == '=')
4269 if (PEEKC () == '=')
4276 if (c2 == '-' && opts->chill)
4278 /* Chill style comment */
4279 if (opts->put_out_comments)
4280 parse_set_mark (&start_mark, pfile);
4281 FORWARD(1); /* Skip second '-'. */
4289 /* Don't consider final '\n' to be part of comment. */
4295 goto return_comment;
4297 if (c2 == '-' || c2 == '=' || c2 == '>')
4302 if (pfile->parsing_include_directive)
4306 CPP_PUTC (pfile, c);
4311 if (c == '\n' || c == EOF)
4314 "missing '>' in `#include <FILENAME>'");
4320 /* else fall through */
4329 CPP_RESERVE (pfile, 4);
4330 CPP_PUTC (pfile, c);
4331 CPP_PUTC (pfile, c2);
4335 CPP_PUTC_Q (pfile, GETC ());
4336 CPP_NUL_TERMINATE_Q (pfile);
4337 pfile->only_seen_white = 0;
4341 if (CPP_BUFFER (pfile)->has_escapes)
4346 if (pfile->output_escapes)
4347 CPP_PUTS (pfile, "@-", 2);
4348 parse_name (pfile, GETC ());
4351 else if (is_space [c])
4353 CPP_RESERVE (pfile, 2);
4354 if (pfile->output_escapes)
4355 CPP_PUTC_Q (pfile, '@');
4356 CPP_PUTC_Q (pfile, c);
4360 if (pfile->output_escapes)
4362 CPP_PUTS (pfile, "@@", 2);
4372 CPP_RESERVE(pfile, 2);
4373 CPP_PUTC_Q (pfile, '.');
4377 /* FIXME - misses the case "..\\\n." */
4378 if (c2 == '.' && PEEKN(1) == '.')
4380 CPP_RESERVE(pfile, 4);
4381 CPP_PUTC_Q (pfile, '.');
4382 CPP_PUTC_Q (pfile, '.');
4383 CPP_PUTC_Q (pfile, '.');
4385 CPP_NUL_TERMINATE_Q (pfile);
4386 pfile->only_seen_white = 0;
4393 pfile->only_seen_white = 0;
4395 CPP_RESERVE(pfile, 3);
4396 CPP_PUTC_Q (pfile, c);
4397 CPP_PUTC_Q (pfile, GETC ());
4398 CPP_NUL_TERMINATE_Q (pfile);
4404 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
4406 CPP_PUTC (pfile, c);
4412 case '0': case '1': case '2': case '3': case '4':
4413 case '5': case '6': case '7': case '8': case '9':
4418 CPP_RESERVE (pfile, 2);
4419 CPP_PUTC_Q (pfile, c);
4424 if (!is_idchar[c] && c != '.'
4425 && ((c2 != 'e' && c2 != 'E'
4426 && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
4427 || (c != '+' && c != '-')))
4432 CPP_NUL_TERMINATE_Q (pfile);
4433 pfile->only_seen_white = 0;
4435 case 'b': case 'c': case 'd': case 'h': case 'o':
4436 case 'B': case 'C': case 'D': case 'H': case 'O':
4437 if (opts->chill && PEEKC () == '\'')
4439 pfile->only_seen_white = 0;
4440 CPP_RESERVE (pfile, 2);
4441 CPP_PUTC_Q (pfile, c);
4442 CPP_PUTC_Q (pfile, '\'');
4448 goto chill_number_eof;
4451 if (c == '\\' && PEEKC() == '\n')
4458 CPP_PUTC (pfile, c);
4462 CPP_RESERVE (pfile, 2);
4463 CPP_PUTC_Q (pfile, c);
4464 CPP_NUL_TERMINATE_Q (pfile);
4471 CPP_NUL_TERMINATE (pfile);
4478 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
4479 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
4480 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
4481 case 'x': case 'y': case 'z':
4482 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
4483 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
4484 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
4489 unsigned char *ident;
4490 int before_name_written = CPP_WRITTEN (pfile);
4492 parse_name (pfile, c);
4493 pfile->only_seen_white = 0;
4494 if (pfile->no_macro_expand)
4496 ident = pfile->token_buffer + before_name_written;
4497 ident_len = CPP_PWRITTEN (pfile) - ident;
4498 hp = cpp_lookup (pfile, ident, ident_len, -1);
4501 if (hp->type == T_DISABLED)
4503 if (pfile->output_escapes)
4504 { /* Return "@-IDENT", followed by '\0'. */
4506 CPP_RESERVE (pfile, 3);
4507 ident = pfile->token_buffer + before_name_written;
4508 CPP_ADJUST_WRITTEN (pfile, 2);
4509 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
4516 /* If macro wants an arglist, verify that a '(' follows.
4517 first skip all whitespace, copying it to the output
4518 after the macro name. Then, if there is no '(',
4519 decide this is not a macro call and leave things that way. */
4520 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
4522 struct parse_marker macro_mark;
4523 int is_macro_call, macbuf_whitespace = 0;
4525 parse_set_mark (¯o_mark, pfile);
4528 cpp_skip_hspace (pfile);
4530 is_macro_call = c == '(';
4539 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4541 if (macro_mark.position !=
4542 (CPP_BUFFER (pfile)->cur
4543 - CPP_BUFFER (pfile)->buf))
4544 macbuf_whitespace = 1;
4546 parse_clear_mark (¯o_mark);
4547 cpp_pop_buffer (pfile);
4548 parse_set_mark (¯o_mark, pfile);
4556 parse_goto_mark (¯o_mark, pfile);
4557 if (macbuf_whitespace)
4558 CPP_PUTC (pfile, ' ');
4560 parse_clear_mark (¯o_mark);
4564 /* This is now known to be a macro call. */
4566 /* it might not actually be a macro. */
4567 if (hp->type != T_MACRO) {
4568 int xbuf_len; U_CHAR *xbuf;
4569 CPP_SET_WRITTEN (pfile, before_name_written);
4570 special_symbol (hp, pfile);
4571 xbuf_len = CPP_WRITTEN (pfile) - before_name_written;
4572 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
4573 CPP_SET_WRITTEN (pfile, before_name_written);
4574 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
4575 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
4579 /* Expand the macro, reading arguments as needed,
4580 and push the expansion on the input stack. */
4581 macroexpand (pfile, hp);
4582 CPP_SET_WRITTEN (pfile, before_name_written);
4585 /* An extra "@ " is added to the end of a macro expansion
4586 to prevent accidental token pasting. We prefer to avoid
4587 unneeded extra spaces (for the sake of cpp-using tools like
4588 imake). Here we remove the space if it is safe to do so. */
4589 if (pfile->buffer->rlimit - pfile->buffer->cur >= 3
4590 && pfile->buffer->rlimit[-2] == '@'
4591 && pfile->buffer->rlimit[-1] == ' ')
4593 int c1 = pfile->buffer->rlimit[-3];
4594 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
4595 if (c2 == EOF || ! unsafe_chars (c1, c2))
4596 pfile->buffer->rlimit -= 2;
4601 case ' ': case '\t': case '\v': case '\r':
4604 CPP_PUTC (pfile, c);
4606 if (c == EOF || !is_hor_space[c])
4620 CPP_PUTC (pfile, c);
4621 if (pfile->only_seen_white == 0)
4622 pfile->only_seen_white = 1;
4624 output_line_command (pfile, 1, same_file);
4627 case '(': token = CPP_LPAREN; goto char1;
4628 case ')': token = CPP_RPAREN; goto char1;
4629 case '{': token = CPP_LBRACE; goto char1;
4630 case '}': token = CPP_RBRACE; goto char1;
4631 case ',': token = CPP_COMMA; goto char1;
4632 case ';': token = CPP_SEMICOLON; goto char1;
4638 pfile->only_seen_white = 0;
4639 CPP_PUTC (pfile, c);
4645 /* Like cpp_get_token, but skip spaces and comments. */
4648 cpp_get_non_space_token (pfile)
4651 int old_written = CPP_WRITTEN (pfile);
4654 enum cpp_token token = cpp_get_token (pfile);
4655 if (token != CPP_COMMENT && token != CPP_POP
4656 && token != CPP_HSPACE && token != CPP_VSPACE)
4658 CPP_SET_WRITTEN (pfile, old_written);
4662 /* Parse an identifier starting with C. */
4665 parse_name (pfile, c)
4666 cpp_reader *pfile; int c;
4672 if (c == '\\' && PEEKC() == '\n')
4681 if (c == '$' && CPP_PEDANTIC (pfile))
4682 cpp_pedwarn (pfile, "`$' in identifier");
4684 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
4685 CPP_PUTC_Q (pfile, c);
4690 CPP_NUL_TERMINATE_Q (pfile);
4694 /* This is called after options have been processed.
4695 * Check options for consistency, and setup for processing input
4696 * from the file named FNAME. (Use standard input if FNAME==NULL.)
4697 * Return 1 on success, 0 on failure.
4701 cpp_start_read (pfile, fname)
4705 struct cpp_options *opts = CPP_OPTIONS (pfile);
4706 struct cpp_pending *pend;
4710 struct include_hash *ih_fake;
4712 /* The code looks at the defaults through this pointer, rather than through
4713 the constant structure above. This pointer gets changed if an environment
4714 variable specifies other defaults. */
4715 struct default_include *include_defaults = include_defaults_array;
4717 /* Now that we know dollars_in_ident for real,
4718 reset is_idchar/is_idstart. */
4719 is_idchar['$'] = opts->dollars_in_ident;
4720 is_idstart['$'] = opts->dollars_in_ident;
4722 /* Add dirs from CPATH after dirs from -I. */
4723 /* There seems to be confusion about what CPATH should do,
4724 so for the moment it is not documented. */
4725 /* Some people say that CPATH should replace the standard include dirs,
4726 but that seems pointless: it comes before them, so it overrides them
4728 GET_ENV_PATH_LIST (p, "CPATH");
4729 if (p != 0 && ! opts->no_standard_includes)
4730 path_include (pfile, p);
4732 /* Do partial setup of input buffer for the sake of generating
4733 early #line directives (when -g is in effect). */
4734 fp = cpp_push_buffer (pfile, NULL, 0);
4737 if (opts->in_fname == NULL)
4738 opts->in_fname = "";
4739 fp->nominal_fname = fp->fname = opts->in_fname;
4742 /* Install __LINE__, etc. Must follow initialize_char_syntax
4743 and option processing. */
4744 initialize_builtins (pfile);
4746 /* Do standard #defines and assertions
4747 that identify system and machine type. */
4749 if (!opts->inhibit_predefs) {
4750 char *p = (char *) alloca (strlen (predefs) + 1);
4751 strcpy (p, predefs);
4754 while (*p == ' ' || *p == '\t')
4756 /* Handle -D options. */
4757 if (p[0] == '-' && p[1] == 'D') {
4759 while (*p && *p != ' ' && *p != '\t')
4763 if (opts->debug_output)
4764 output_line_command (pfile, 0, same_file);
4765 cpp_define (pfile, q);
4766 while (*p == ' ' || *p == '\t')
4768 } else if (p[0] == '-' && p[1] == 'A') {
4769 /* Handle -A options (assertions). */
4778 past_name = assertion;
4779 /* Locate end of name. */
4780 while (*past_name && *past_name != ' '
4781 && *past_name != '\t' && *past_name != '(')
4783 /* Locate `(' at start of value. */
4785 while (*value && (*value == ' ' || *value == '\t'))
4787 if (*value++ != '(')
4789 while (*value && (*value == ' ' || *value == '\t'))
4792 /* Locate end of value. */
4793 while (*past_value && *past_value != ' '
4794 && *past_value != '\t' && *past_value != ')')
4796 termination = past_value;
4797 while (*termination && (*termination == ' ' || *termination == '\t'))
4799 if (*termination++ != ')')
4801 if (*termination && *termination != ' ' && *termination != '\t')
4803 /* Temporarily null-terminate the value. */
4804 save_char = *termination;
4805 *termination = '\0';
4806 /* Install the assertion. */
4807 make_assertion (pfile, "-A", assertion);
4808 *termination = (char) save_char;
4810 while (*p == ' ' || *p == '\t')
4818 /* Now handle the command line options. */
4820 /* Do -U's, -D's and -A's in the order they were seen. */
4821 /* First reverse the list. */
4822 opts->pending = nreverse_pending (opts->pending);
4824 for (pend = opts->pending; pend; pend = pend->next)
4826 if (pend->cmd != NULL && pend->cmd[0] == '-')
4828 switch (pend->cmd[1])
4831 if (opts->debug_output)
4832 output_line_command (pfile, 0, same_file);
4833 do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg));
4836 if (opts->debug_output)
4837 output_line_command (pfile, 0, same_file);
4838 cpp_define (pfile, pend->arg);
4841 make_assertion (pfile, "-A", pend->arg);
4847 opts->done_initializing = 1;
4849 { /* Read the appropriate environment variable and if it exists
4850 replace include_defaults with the listed path. */
4852 switch ((opts->objc << 1) + opts->cplusplus)
4855 GET_ENV_PATH_LIST (epath, "C_INCLUDE_PATH");
4858 GET_ENV_PATH_LIST (epath, "CPLUS_INCLUDE_PATH");
4861 GET_ENV_PATH_LIST (epath, "OBJC_INCLUDE_PATH");
4864 GET_ENV_PATH_LIST (epath, "OBJCPLUS_INCLUDE_PATH");
4867 /* If the environment var for this language is set,
4868 add to the default list of include directories. */
4870 char *nstore = (char *) alloca (strlen (epath) + 2);
4872 char *startp, *endp;
4874 for (num_dirs = 1, startp = epath; *startp; startp++)
4875 if (*startp == PATH_SEPARATOR)
4878 = (struct default_include *) xmalloc ((num_dirs
4879 * sizeof (struct default_include))
4880 + sizeof (include_defaults_array));
4881 startp = endp = epath;
4884 /* Handle cases like c:/usr/lib:d:/gcc/lib */
4885 if ((*endp == PATH_SEPARATOR)
4887 strncpy (nstore, startp, endp-startp);
4889 strcpy (nstore, ".");
4891 nstore[endp-startp] = '\0';
4893 include_defaults[num_dirs].fname = savestring (nstore);
4894 include_defaults[num_dirs].component = 0;
4895 include_defaults[num_dirs].cplusplus = opts->cplusplus;
4896 include_defaults[num_dirs].cxx_aware = 1;
4900 endp = startp = endp + 1;
4904 /* Put the usual defaults back in at the end. */
4905 bcopy ((char *) include_defaults_array,
4906 (char *) &include_defaults[num_dirs],
4907 sizeof (include_defaults_array));
4911 /* Unless -fnostdinc,
4912 tack on the standard include file dirs to the specified list */
4913 if (!opts->no_standard_includes) {
4914 struct default_include *p = include_defaults;
4915 char *specd_prefix = opts->include_prefix;
4916 char *default_prefix = savestring (GCC_INCLUDE_DIR);
4917 int default_len = 0;
4918 /* Remove the `include' from /usr/local/lib/gcc.../include. */
4919 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
4920 default_len = strlen (default_prefix) - 7;
4921 default_prefix[default_len] = 0;
4923 /* Search "translated" versions of GNU directories.
4924 These have /usr/local/lib/gcc... replaced by specd_prefix. */
4925 if (specd_prefix != 0 && default_len != 0)
4926 for (p = include_defaults; p->fname; p++) {
4927 /* Some standard dirs are only for C++. */
4929 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
4930 /* Does this dir start with the prefix? */
4931 if (!strncmp (p->fname, default_prefix, default_len)) {
4932 /* Yes; change prefix and add to search list. */
4933 int this_len = strlen (specd_prefix)
4934 + strlen (p->fname) - default_len;
4935 char *str = (char *) xmalloc (this_len + 1);
4936 strcpy (str, specd_prefix);
4937 strcat (str, p->fname + default_len);
4939 append_include_chain (pfile, &opts->system_include,
4940 str, !p->cxx_aware);
4944 /* Search ordinary names for GNU include directories. */
4945 for (p = include_defaults; p->fname; p++) {
4946 /* Some standard dirs are only for C++. */
4948 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
4949 char *str = update_path (p->fname, p->component);
4950 append_include_chain (pfile, &opts->system_include,
4951 str, !p->cxx_aware);
4956 merge_include_chains (opts);
4958 /* With -v, print the list of dirs to search. */
4959 if (opts->verbose) {
4960 struct file_name_list *p;
4961 fprintf (stderr, "#include \"...\" search starts here:\n");
4962 for (p = opts->quote_include; p; p = p->next) {
4963 if (p == opts->bracket_include)
4964 fprintf (stderr, "#include <...> search starts here:\n");
4965 fprintf (stderr, " %s\n", p->name);
4967 fprintf (stderr, "End of search list.\n");
4970 /* Copy the entire contents of the main input file into
4971 the stacked input buffer previously allocated for it. */
4972 if (fname == NULL || *fname == 0) {
4975 } else if ((f = open (fname, O_RDONLY, 0666)) < 0)
4976 cpp_pfatal_with_name (pfile, fname);
4978 /* -MG doesn't select the form of output and must be specified with one of
4979 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
4980 inhibit compilation. */
4981 if (opts->print_deps_missing_files
4982 && (opts->print_deps == 0 || !opts->no_output))
4984 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
4988 /* Either of two environment variables can specify output of deps.
4989 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
4990 where OUTPUT_FILE is the file to write deps info to
4991 and DEPS_TARGET is the target to mention in the deps. */
4993 if (opts->print_deps == 0
4994 && (getenv ("SUNPRO_DEPENDENCIES") != 0
4995 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
4996 char *spec = getenv ("DEPENDENCIES_OUTPUT");
5002 spec = getenv ("SUNPRO_DEPENDENCIES");
5003 opts->print_deps = 2;
5006 opts->print_deps = 1;
5009 /* Find the space before the DEPS_TARGET, if there is one. */
5010 /* This should use index. (mrs) */
5011 while (*s != 0 && *s != ' ') s++;
5014 opts->deps_target = s + 1;
5015 output_file = (char *) xmalloc (s - spec + 1);
5016 bcopy (spec, output_file, s - spec);
5017 output_file[s - spec] = 0;
5021 opts->deps_target = 0;
5025 opts->deps_file = output_file;
5026 opts->print_deps_append = 1;
5029 /* For -M, print the expected object file name
5030 as the target of this Make-rule. */
5031 if (opts->print_deps)
5033 pfile->deps_allocated_size = 200;
5034 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
5035 pfile->deps_buffer[0] = 0;
5036 pfile->deps_size = 0;
5037 pfile->deps_column = 0;
5039 if (opts->deps_target)
5040 deps_output (pfile, opts->deps_target, ':');
5041 else if (*opts->in_fname == 0)
5042 deps_output (pfile, "-", ':');
5047 static char *known_suffixes[] = { ".c", ".C", ".s", ".S", ".m",
5048 ".cc", ".cxx", ".cpp", ".cp",
5052 /* Discard all directory prefixes from filename. */
5053 if ((q = rindex (opts->in_fname, '/')) != NULL
5054 #ifdef DIR_SEPARATOR
5055 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
5062 /* Copy remainder to mungable area. */
5063 p = (char *) alloca (strlen(q) + 8);
5066 /* Output P, but remove known suffixes. */
5069 /* Point to the filename suffix. */
5070 r = rindex (p, '.');
5071 /* Compare against the known suffixes. */
5073 while (known_suffixes[x] != 0)
5075 if (strncmp (known_suffixes[x], r, q - r) == 0)
5077 /* Make q point to the bit we're going to overwrite
5078 with an object suffix. */
5085 /* Supply our own suffix. */
5092 deps_output (pfile, p, ':');
5093 deps_output (pfile, opts->in_fname, ' ');
5098 /* Make sure data ends with a newline. And put a null after it. */
5100 if ((fp->length > 0 && fp->buf[fp->length - 1] != '\n')
5101 /* Backslash-newline at end is not good enough. */
5102 || (fp->length > 1 && fp->buf[fp->length - 2] == '\\')) {
5103 fp->buf[fp->length++] = '\n';
5104 missing_newline = 1;
5106 fp->buf[fp->length] = '\0';
5108 /* Unless inhibited, convert trigraphs in the input. */
5114 /* Must call finclude() on the main input before processing
5115 -include switches; otherwise the -included text winds up
5116 after the main input. */
5117 ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
5119 ih_fake->next_this_file = 0;
5120 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5121 ih_fake->name = fname;
5122 ih_fake->control_macro = 0;
5123 ih_fake->buf = (char *)-1;
5125 if (!finclude (pfile, f, ih_fake))
5127 output_line_command (pfile, 0, same_file);
5128 pfile->only_seen_white = 2;
5130 /* The -imacros files can be scanned now, but the -include files
5131 have to be pushed onto the include stack and processed later,
5132 in the main loop calling cpp_get_token. That means the -include
5133 files have to be processed in reverse order of the pending list,
5134 which means the pending list has to be reversed again, which
5135 means the -imacros files have to be done separately and first. */
5137 pfile->no_record_file++;
5139 for (pend = opts->pending; pend; pend = pend->next)
5141 if (pend->cmd != NULL)
5143 if (strcmp (pend->cmd, "-imacros") == 0)
5145 int fd = open (pend->arg, O_RDONLY, 0666);
5148 cpp_perror_with_name (pfile, pend->arg);
5151 if (!cpp_push_buffer (pfile, NULL, 0))
5154 ih_fake = (struct include_hash *)
5155 xmalloc (sizeof (struct include_hash));
5157 ih_fake->next_this_file = 0;
5158 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5159 ih_fake->name = pend->arg;
5160 ih_fake->control_macro = 0;
5161 ih_fake->buf = (char *)-1;
5163 if (!finclude (pfile, fd, ih_fake))
5164 cpp_scan_buffer (pfile);
5170 opts->pending = nreverse_pending (opts->pending);
5171 for (pend = opts->pending; pend; pend = pend->next)
5173 if (pend->cmd != NULL)
5175 if (strcmp (pend->cmd, "-include") == 0)
5177 int fd = open (pend->arg, O_RDONLY, 0666);
5180 cpp_perror_with_name (pfile, pend->arg);
5183 if (!cpp_push_buffer (pfile, NULL, 0))
5186 ih_fake = (struct include_hash *)
5187 xmalloc (sizeof (struct include_hash));
5189 ih_fake->next_this_file = 0;
5190 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5191 ih_fake->name = pend->arg;
5192 ih_fake->control_macro = 0;
5193 ih_fake->buf = (char *)-1;
5195 if (finclude (pfile, fd, ih_fake))
5196 output_line_command (pfile, 0, enter_file);
5200 pfile->no_record_file--;
5202 /* Free the pending list. */
5203 for (pend = opts->pending; pend; )
5205 struct cpp_pending *next = pend->next;
5209 opts->pending = NULL;
5215 cpp_reader_init (pfile)
5218 bzero ((char *) pfile, sizeof (cpp_reader));
5219 pfile->get_token = cpp_get_token;
5221 pfile->token_buffer_size = 200;
5222 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
5223 CPP_SET_WRITTEN (pfile, 0);
5225 pfile->timebuf = NULL;
5226 pfile->only_seen_white = 1;
5227 pfile->buffer = CPP_NULL_BUFFER(pfile);
5228 pfile->actual_dirs = NULL;
5231 static struct cpp_pending *
5232 nreverse_pending (list)
5233 struct cpp_pending *list;
5236 register struct cpp_pending *prev = 0, *next, *pend;
5237 for (pend = list; pend; pend = next)
5247 push_pending (pfile, cmd, arg)
5252 struct cpp_pending *pend
5253 = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
5256 pend->next = CPP_OPTIONS (pfile)->pending;
5257 CPP_OPTIONS (pfile)->pending = pend;
5264 printf ("Usage: %s [switches] input output\n", progname);
5265 printf ("Switches:\n");
5266 printf (" -include <file> Include the contents of <file> before other files\n");
5267 printf (" -imacros <file> Accept definition of marcos in <file>\n");
5268 printf (" -iprefix <path> Specify <path> as a prefix for next two options\n");
5269 printf (" -iwithprefix <dir> Add <dir> to the end of the system include paths\n");
5270 printf (" -iwithprefixbefore <dir> Add <dir> to the end of the main include paths\n");
5271 printf (" -isystem <dir> Add <dir> to the start of the system include paths\n");
5272 printf (" -idirafter <dir> Add <dir> to the end of the system include paths\n");
5273 printf (" -I <dir> Add <dir> to the end of the main include paths\n");
5274 printf (" -nostdinc Do not search the system include directories\n");
5275 printf (" -nostdinc++ Do not search the system include directories for C++\n");
5276 printf (" -o <file> Put output into <file>\n");
5277 printf (" -pedantic Issue all warnings demanded by strict ANSI C\n");
5278 printf (" -traditional Follow K&R pre-processor behaviour\n");
5279 printf (" -trigraphs Support ANSI C trigraphs\n");
5280 printf (" -lang-c Assume that the input sources are in C\n");
5281 printf (" -lang-c89 Assume that the input sources are in C89\n");
5282 printf (" -lang-c++ Assume that the input sources are in C++\n");
5283 printf (" -lang-objc Assume that the input sources are in ObjectiveC\n");
5284 printf (" -lang-objc++ Assume that the input sources are in ObjectiveC++\n");
5285 printf (" -lang-asm Assume that the input sources are in assembler\n");
5286 printf (" -lang-chill Assume that the input sources are in Chill\n");
5287 printf (" -+ Allow parsing of C++ style features\n");
5288 printf (" -w Inhibit warning messages\n");
5289 printf (" -Wtrigraphs Warn if trigraphs are encountered\n");
5290 printf (" -Wno-trigraphs Do not warn about trigraphs\n");
5291 printf (" -Wcomment{s} Warn if one comment starts inside another\n");
5292 printf (" -Wno-comment{s} Do not warn about comments\n");
5293 printf (" -Wtraditional Warn if a macro argument is/would be turned into\n");
5294 printf (" a string if -tradtional is specified\n");
5295 printf (" -Wno-traditional Do not warn about stringification\n");
5296 printf (" -Wundef Warn if an undefined macro is used by #if\n");
5297 printf (" -Wno-undef Do not warn about testing udefined macros\n");
5298 printf (" -Wimport Warn about the use of the #import directive\n");
5299 printf (" -Wno-import Do not warn about the use of #import\n");
5300 printf (" -Werror Treat all warnings as errors\n");
5301 printf (" -Wno-error Do not treat warnings as errors\n");
5302 printf (" -Wall Enable all preprocessor warnings\n");
5303 printf (" -M Generate make dependencies\n");
5304 printf (" -MM As -M, but ignore system header files\n");
5305 printf (" -MD As -M, but put output in a .d file\n");
5306 printf (" -MMD As -MD, but ignore system header files\n");
5307 printf (" -MG Treat missing header file as generated files\n");
5308 printf (" -g Include #define and #undef directives in the output\n");
5309 printf (" -D<macro> Define a <macro> with string '1' as its value\n");
5310 printf (" -D<macro>=<val> Define a <macro> with <val> as its value\n");
5311 printf (" -A<question> (<answer>) Assert the <answer> to <question>\n");
5312 printf (" -U<macro> Undefine <macro> \n");
5313 printf (" -u or -undef Do not predefine any macros\n");
5314 printf (" -v Display the version number\n");
5315 printf (" -H Print the name of header files as they are used\n");
5316 printf (" -C Do not discard comments\n");
5317 printf (" -dM Display a list of macro definitions active at end\n");
5318 printf (" -dD Preserve macro definitions in output\n");
5319 printf (" -dN As -dD except that only the names are preserved\n");
5320 printf (" -dI Include #include directives in the output\n");
5321 printf (" -ifoutput Describe skipped code blocks in output \n");
5322 printf (" -P Do not generate #line directives\n");
5323 printf (" -$ Do not include '$' in identifiers\n");
5324 printf (" -remap Remap file names when including files.\n");
5325 printf (" -h or --help Display this information\n");
5329 /* Handle one command-line option in (argc, argv).
5330 Can be called multiple times, to handle multiple sets of options.
5331 Returns number of strings consumed. */
5333 cpp_handle_option (pfile, argc, argv)
5338 struct cpp_options *opts = CPP_OPTIONS (pfile);
5341 if (user_label_prefix == NULL)
5342 user_label_prefix = USER_LABEL_PREFIX;
5344 if (argv[i][0] != '-') {
5345 if (opts->out_fname != NULL)
5348 cpp_fatal (pfile, "Too many arguments");
5350 else if (opts->in_fname != NULL)
5351 opts->out_fname = argv[i];
5353 opts->in_fname = argv[i];
5355 switch (argv[i][1]) {
5358 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
5361 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
5365 if (!strcmp (argv[i], "-fleading-underscore"))
5366 user_label_prefix = "_";
5367 else if (!strcmp (argv[i], "-fno-leading-underscore"))
5368 user_label_prefix = "";
5371 case 'I': /* Add directory to path for includes. */
5372 if (!strcmp (argv[i] + 2, "-"))
5374 if (! opts->ignore_srcdir)
5376 opts->ignore_srcdir = 1;
5377 /* Don't use any preceding -I directories for #include <...>. */
5378 opts->quote_include = opts->bracket_include;
5379 opts->bracket_include = 0;
5385 if (argv[i][2] != 0)
5386 fname = argv[i] + 2;
5387 else if (i + 1 == argc)
5388 goto missing_dirname;
5391 append_include_chain (pfile, &opts->bracket_include, fname, 0);
5396 /* Add directory to beginning of system include path, as a system
5397 include directory. */
5398 if (!strcmp (argv[i], "-isystem"))
5401 goto missing_filename;
5402 append_include_chain (pfile, &opts->system_include, argv[++i], 1);
5404 /* Add directory to end of path for includes,
5405 with the default prefix at the front of its name. */
5406 else if (!strcmp (argv[i], "-iwithprefix"))
5410 goto missing_dirname;
5413 if (opts->include_prefix != 0)
5415 fname = xmalloc (strlen (opts->include_prefix)
5416 + strlen (argv[i]) + 1);
5417 strcpy (fname, opts->include_prefix);
5418 strcat (fname, argv[i]);
5422 fname = xmalloc (strlen (GCC_INCLUDE_DIR)
5423 + strlen (argv[i]) + 1);
5424 strcpy (fname, GCC_INCLUDE_DIR);
5425 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5426 if (!strcmp (fname + strlen (fname) - 8, "/include"))
5427 fname[strlen (fname) - 7] = 0;
5428 strcat (fname, argv[i]);
5431 append_include_chain (pfile, &opts->system_include, fname, 0);
5433 /* Add directory to main path for includes,
5434 with the default prefix at the front of its name. */
5435 else if (!strcmp (argv[i], "-iwithprefix"))
5439 goto missing_dirname;
5442 if (opts->include_prefix != 0)
5444 fname = xmalloc (strlen (opts->include_prefix)
5445 + strlen (argv[i]) + 1);
5446 strcpy (fname, opts->include_prefix);
5447 strcat (fname, argv[i]);
5451 fname = xmalloc (strlen (GCC_INCLUDE_DIR)
5452 + strlen (argv[i]) + 1);
5453 strcpy (fname, GCC_INCLUDE_DIR);
5454 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5455 if (!strcmp (fname + strlen (fname) - 8, "/include"))
5456 fname[strlen (fname) - 7] = 0;
5457 strcat (fname, argv[i]);
5460 append_include_chain (pfile, &opts->bracket_include, fname, 0);
5462 /* Add directory to end of path for includes. */
5463 else if (!strcmp (argv[i], "-idirafter"))
5466 goto missing_dirname;
5467 append_include_chain (pfile, &opts->after_include, argv[++i], 0);
5469 else if (!strcmp (argv[i], "-include") || !strcmp (argv[i], "-imacros"))
5472 goto missing_filename;
5474 push_pending (pfile, argv[i], argv[i+1]), i++;
5476 else if (!strcmp (argv[i], "-iprefix"))
5479 goto missing_filename;
5481 opts->include_prefix = argv[++i];
5483 else if (!strcmp (argv[i], "-ifoutput"))
5484 opts->output_conditionals = 1;
5489 if (opts->out_fname != NULL)
5491 cpp_fatal (pfile, "Output filename specified twice");
5495 goto missing_filename;
5496 opts->out_fname = argv[++i];
5497 if (!strcmp (opts->out_fname, "-"))
5498 opts->out_fname = "";
5502 if (!strcmp (argv[i], "-pedantic"))
5503 CPP_PEDANTIC (pfile) = 1;
5504 else if (!strcmp (argv[i], "-pedantic-errors")) {
5505 CPP_PEDANTIC (pfile) = 1;
5506 opts->pedantic_errors = 1;
5509 else if (!strcmp (argv[i], "-pcp")) {
5510 char *pcp_fname = argv[++i];
5511 pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
5512 ? fopen (pcp_fname, "w")
5513 : fdopen (dup (fileno (stdout)), "w"));
5514 if (pcp_outfile == 0)
5515 cpp_pfatal_with_name (pfile, pcp_fname);
5522 if (!strcmp (argv[i], "-traditional")) {
5523 opts->traditional = 1;
5524 opts->cplusplus_comments = 0;
5525 } else if (!strcmp (argv[i], "-trigraphs")) {
5527 opts->no_trigraphs = 0;
5532 if (! strcmp (argv[i], "-lang-c"))
5533 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
5535 if (! strcmp (argv[i], "-lang-c89"))
5536 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1,
5538 if (! strcmp (argv[i], "-lang-c++"))
5539 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
5541 if (! strcmp (argv[i], "-lang-objc"))
5542 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
5544 if (! strcmp (argv[i], "-lang-objc++"))
5545 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
5547 if (! strcmp (argv[i], "-lang-asm"))
5549 if (! strcmp (argv[i], "-lint"))
5551 if (! strcmp (argv[i], "-lang-chill"))
5552 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
5553 opts->traditional = 1, opts->no_trigraphs = 1;
5557 opts->cplusplus = 1, opts->cplusplus_comments = 1;
5561 opts->inhibit_warnings = 1;
5565 if (!strcmp (argv[i], "-Wtrigraphs"))
5566 opts->warn_trigraphs = 1;
5567 else if (!strcmp (argv[i], "-Wno-trigraphs"))
5568 opts->warn_trigraphs = 0;
5569 else if (!strcmp (argv[i], "-Wcomment"))
5570 opts->warn_comments = 1;
5571 else if (!strcmp (argv[i], "-Wno-comment"))
5572 opts->warn_comments = 0;
5573 else if (!strcmp (argv[i], "-Wcomments"))
5574 opts->warn_comments = 1;
5575 else if (!strcmp (argv[i], "-Wno-comments"))
5576 opts->warn_comments = 0;
5577 else if (!strcmp (argv[i], "-Wtraditional"))
5578 opts->warn_stringify = 1;
5579 else if (!strcmp (argv[i], "-Wno-traditional"))
5580 opts->warn_stringify = 0;
5581 else if (!strcmp (argv[i], "-Wundef"))
5582 opts->warn_undef = 1;
5583 else if (!strcmp (argv[i], "-Wno-undef"))
5584 opts->warn_undef = 0;
5585 else if (!strcmp (argv[i], "-Wimport"))
5586 opts->warn_import = 1;
5587 else if (!strcmp (argv[i], "-Wno-import"))
5588 opts->warn_import = 0;
5589 else if (!strcmp (argv[i], "-Werror"))
5590 opts->warnings_are_errors = 1;
5591 else if (!strcmp (argv[i], "-Wno-error"))
5592 opts->warnings_are_errors = 0;
5593 else if (!strcmp (argv[i], "-Wall"))
5595 opts->warn_trigraphs = 1;
5596 opts->warn_comments = 1;
5601 /* The style of the choices here is a bit mixed.
5602 The chosen scheme is a hybrid of keeping all options in one string
5603 and specifying each option in a separate argument:
5604 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
5605 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
5606 -M[M][G][D file]. This is awkward to handle in specs, and is not
5608 /* ??? -MG must be specified in addition to one of -M or -MM.
5609 This can be relaxed in the future without breaking anything.
5610 The converse isn't true. */
5612 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
5613 if (!strcmp (argv[i], "-MG"))
5615 opts->print_deps_missing_files = 1;
5618 if (!strcmp (argv[i], "-M"))
5619 opts->print_deps = 2;
5620 else if (!strcmp (argv[i], "-MM"))
5621 opts->print_deps = 1;
5622 else if (!strcmp (argv[i], "-MD"))
5623 opts->print_deps = 2;
5624 else if (!strcmp (argv[i], "-MMD"))
5625 opts->print_deps = 1;
5626 /* For -MD and -MMD options, write deps on file named by next arg. */
5627 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
5630 goto missing_filename;
5631 opts->deps_file = argv[++i];
5635 /* For -M and -MM, write deps on standard output
5636 and suppress the usual output. */
5637 opts->no_output = 1;
5643 char *p = argv[i] + 2;
5645 while ((c = *p++) != 0) {
5646 /* Arg to -d specifies what parts of macros to dump */
5649 opts->dump_macros = dump_only;
5650 opts->no_output = 1;
5653 opts->dump_macros = dump_names;
5656 opts->dump_macros = dump_definitions;
5659 opts->dump_includes = 1;
5667 if (argv[i][2] == '3')
5668 opts->debug_output = 1;
5672 if (strcmp (argv[i], "--help") != 0)
5678 fprintf (stderr, "GNU CPP version %s", version_string);
5679 #ifdef TARGET_VERSION
5682 fprintf (stderr, "\n");
5687 opts->print_include_names = 1;
5691 if (argv[i][2] != 0)
5692 push_pending (pfile, "-D", argv[i] + 2);
5693 else if (i + 1 == argc)
5695 cpp_fatal (pfile, "Macro name missing after -D option");
5699 i++, push_pending (pfile, "-D", argv[i]);
5706 if (argv[i][2] != 0)
5708 else if (i + 1 == argc)
5710 cpp_fatal (pfile, "Assertion missing after -A option");
5716 if (!strcmp (p, "-")) {
5717 struct cpp_pending **ptr;
5718 /* -A- eliminates all predefined macros and assertions.
5719 Let's include also any that were specified earlier
5720 on the command line. That way we can get rid of any
5721 that were passed automatically in from GCC. */
5722 opts->inhibit_predefs = 1;
5723 for (ptr = &opts->pending; *ptr != NULL; )
5725 struct cpp_pending *pend = *ptr;
5726 if (pend->cmd && pend->cmd[0] == '-'
5727 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
5736 push_pending (pfile, "-A", p);
5741 case 'U': /* JF #undef something */
5742 if (argv[i][2] != 0)
5743 push_pending (pfile, "-U", argv[i] + 2);
5744 else if (i + 1 == argc)
5746 cpp_fatal (pfile, "Macro name missing after -U option");
5750 push_pending (pfile, "-U", argv[i+1]), i++;
5754 opts->put_out_comments = 1;
5757 case 'E': /* -E comes from cc -E; ignore it. */
5761 opts->no_line_commands = 1;
5764 case '$': /* Don't include $ in identifiers. */
5765 opts->dollars_in_ident = 0;
5769 if (!strcmp (argv[i], "-nostdinc"))
5770 /* -nostdinc causes no default include directories.
5771 You must specify all include-file directories with -I. */
5772 opts->no_standard_includes = 1;
5773 else if (!strcmp (argv[i], "-nostdinc++"))
5774 /* -nostdinc++ causes no default C++-specific include directories. */
5775 opts->no_standard_cplusplus_includes = 1;
5777 else if (!strcmp (argv[i], "-noprecomp"))
5783 if (!strcmp (argv[i], "-remap"))
5788 /* Sun compiler passes undocumented switch "-undef".
5789 Let's assume it means to inhibit the predefined symbols. */
5790 opts->inhibit_predefs = 1;
5793 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
5794 if (opts->in_fname == NULL) {
5795 opts->in_fname = "";
5797 } else if (opts->out_fname == NULL) {
5798 opts->out_fname = "";
5800 } /* else fall through into error */
5810 /* Handle command-line options in (argc, argv).
5811 Can be called multiple times, to handle multiple sets of options.
5812 Returns if an unrecognized option is seen.
5813 Returns number of strings consumed. */
5816 cpp_handle_options (pfile, argc, argv)
5822 int strings_processed;
5823 for (i = 0; i < argc; i += strings_processed)
5825 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
5826 if (strings_processed == 0)
5836 struct cpp_options *opts = CPP_OPTIONS (pfile);
5838 if (opts->print_deps)
5840 /* Stream on which to print the dependency information. */
5843 /* Don't actually write the deps file if compilation has failed. */
5844 if (pfile->errors == 0)
5846 char *deps_mode = opts->print_deps_append ? "a" : "w";
5847 if (opts->deps_file == 0)
5848 deps_stream = stdout;
5849 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
5850 cpp_pfatal_with_name (pfile, opts->deps_file);
5851 fputs (pfile->deps_buffer, deps_stream);
5852 putc ('\n', deps_stream);
5853 if (opts->deps_file)
5855 if (ferror (deps_stream) || fclose (deps_stream) != 0)
5856 cpp_fatal (pfile, "I/O error on output");
5862 /* Debugging: dump statistics on the include hash table. */
5864 struct include_hash *x;
5867 for(i = 0; i < ALL_INCLUDE_HASHSIZE; i++)
5869 x = pfile->all_include_files[i];
5876 fprintf(stderr, "%d/%d ", i, j);
5878 fputc('\n', stderr);
5884 /* Free resources used by PFILE.
5885 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
5892 while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
5893 cpp_pop_buffer (pfile);
5895 if (pfile->token_buffer)
5897 free (pfile->token_buffer);
5898 pfile->token_buffer = NULL;
5901 if (pfile->deps_buffer)
5903 free (pfile->deps_buffer);
5904 pfile->deps_buffer = NULL;
5905 pfile->deps_allocated_size = 0;
5908 while (pfile->if_stack)
5910 IF_STACK_FRAME *temp = pfile->if_stack;
5911 pfile->if_stack = temp->next;
5915 for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; )
5917 struct include_hash *imp = pfile->all_include_files[i];
5920 struct include_hash *next = imp->next;
5922 /* This gets freed elsewhere - I think. */
5928 pfile->all_include_files[i] = 0;
5931 cpp_hash_cleanup (pfile);
5934 /* Read an assertion into the token buffer, converting to
5935 canonical form: `#predicate(a n swe r)' The next non-whitespace
5936 character to read should be the first letter of the predicate.
5937 Returns 0 for syntax error, 1 for bare predicate, 2 for predicate
5938 with answer (see callers for why). In case of 0, an error has been
5941 parse_assertion (pfile)
5945 cpp_skip_hspace (pfile);
5947 if (! is_idstart[c])
5949 cpp_error (pfile, "assertion predicate is not an identifier");
5952 CPP_PUTC(pfile, '#');
5954 parse_name(pfile, c);
5959 if (is_hor_space[c])
5960 cpp_skip_hspace (pfile);
5966 CPP_PUTC(pfile, '(');
5969 while ((c = GETC()) != ')')
5971 if (is_hor_space[c])
5975 CPP_PUTC(pfile, ' ');
5979 else if (c == '\\' && PEEKC() == '\n')
5981 else if (c == '\n' || c == EOF)
5983 if (c == '\n') FORWARD(-1);
5984 cpp_error (pfile, "un-terminated assertion answer");
5994 if (pfile->limit[-1] == ' ')
5995 pfile->limit[-1] = ')';
5996 else if (pfile->limit[-1] == '(')
5998 cpp_error (pfile, "empty token sequence in assertion");
6002 CPP_PUTC(pfile, ')');
6004 CPP_NUL_TERMINATE(pfile);
6009 do_assert (pfile, keyword, buf, limit)
6011 struct directive *keyword ATTRIBUTE_UNUSED;
6012 U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
6016 HASHNODE *base, *this;
6017 int baselen, thislen;
6019 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6020 && !CPP_BUFFER (pfile)->system_header_p)
6021 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6023 cpp_skip_hspace (pfile);
6024 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
6025 ret = parse_assertion (pfile);
6030 cpp_error (pfile, "missing token-sequence in `#assert'");
6034 cpp_skip_hspace (pfile);
6036 if (c != EOF && c != '\n')
6038 cpp_error (pfile, "junk at end of `#assert'");
6042 thislen = strlen (sym);
6043 baselen = index (sym, '(') - sym;
6044 this = cpp_lookup (pfile, sym, thislen, -1);
6047 cpp_warning (pfile, "`%s' re-asserted", sym);
6051 base = cpp_lookup (pfile, sym, baselen, -1);
6053 base = install (sym, baselen, T_ASSERT, 0, 0, -1);
6054 else if (base->type != T_ASSERT)
6056 /* Token clash - but with what?! */
6058 "cpp internal error: base->type != T_ASSERT in do_assert");
6062 this = install (sym, thislen, T_ASSERT, 0,
6063 (char *)base->value.aschain, -1);
6064 base->value.aschain = this;
6066 pfile->limit = sym; /* Pop */
6070 pfile->limit = sym; /* Pop */
6071 skip_rest_of_line (pfile);
6076 do_unassert (pfile, keyword, buf, limit)
6078 struct directive *keyword ATTRIBUTE_UNUSED;
6079 U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
6083 long baselen, thislen;
6084 HASHNODE *base, *this, *next;
6086 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6087 && !CPP_BUFFER (pfile)->system_header_p)
6088 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6090 cpp_skip_hspace (pfile);
6092 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
6093 ret = parse_assertion (pfile);
6097 cpp_skip_hspace (pfile);
6099 if (c != EOF && c != '\n')
6100 cpp_error (pfile, "junk at end of `#unassert'");
6102 thislen = strlen (sym);
6105 base = cpp_lookup (pfile, sym, thislen, -1);
6107 goto error; /* It isn't an error to #undef what isn't #defined,
6108 so it isn't an error to #unassert what isn't
6109 #asserted either. */
6111 for (this = base->value.aschain; this; this = next)
6113 next = this->value.aschain;
6114 delete_macro (this);
6116 delete_macro (base);
6120 baselen = index (sym, '(') - sym;
6121 base = cpp_lookup (pfile, sym, baselen, -1);
6122 if (! base) goto error;
6123 this = cpp_lookup (pfile, sym, thislen, -1);
6124 if (! this) goto error;
6127 while (next->value.aschain != this)
6128 next = next->value.aschain;
6130 next->value.aschain = this->value.aschain;
6131 delete_macro (this);
6133 if (base->value.aschain == NULL)
6134 delete_macro (base); /* Last answer for this predicate deleted. */
6137 pfile->limit = sym; /* Pop */
6140 pfile->limit = sym; /* Pop */
6141 skip_rest_of_line (pfile);
6146 cpp_read_check_assertion (pfile)
6149 char *name = CPP_PWRITTEN (pfile);
6153 FORWARD (1); /* Skip '#' */
6154 cpp_skip_hspace (pfile);
6155 if (! parse_assertion (pfile))
6159 hp = cpp_lookup (pfile, name, (char *)CPP_PWRITTEN (pfile) - name, -1);
6163 pfile->limit = name;
6167 /* FIXME: savestring() should be renamed strdup() and should
6168 be moved into cppalloc.c. We can't do that right now because
6169 then we'd get multiple-symbol clashes with toplev.c and several
6175 unsigned size = strlen (input);
6176 char *output = xmalloc (size + 1);
6177 strcpy (output, input);
6181 /* Initialize PMARK to remember the current position of PFILE. */
6184 parse_set_mark (pmark, pfile)
6185 struct parse_marker *pmark;
6188 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6189 pmark->next = pbuf->marks;
6190 pbuf->marks = pmark;
6192 pmark->position = pbuf->cur - pbuf->buf;
6195 /* Cleanup PMARK - we no longer need it. */
6198 parse_clear_mark (pmark)
6199 struct parse_marker *pmark;
6201 struct parse_marker **pp = &pmark->buf->marks;
6202 for (; ; pp = &(*pp)->next) {
6203 if (*pp == NULL) abort ();
6204 if (*pp == pmark) break;
6209 /* Backup the current position of PFILE to that saved in PMARK. */
6212 parse_goto_mark (pmark, pfile)
6213 struct parse_marker *pmark;
6216 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6217 if (pbuf != pmark->buf)
6218 cpp_fatal (pfile, "internal error %s", "parse_goto_mark");
6219 pbuf->cur = pbuf->buf + pmark->position;
6222 /* Reset PMARK to point to the current position of PFILE. (Same
6223 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
6226 parse_move_mark (pmark, pfile)
6227 struct parse_marker *pmark;
6230 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6231 if (pbuf != pmark->buf)
6232 cpp_fatal (pfile, "internal error %s", "parse_move_mark");
6233 pmark->position = pbuf->cur - pbuf->buf;
6238 cpp_print_file_and_line (pfile)
6241 cpp_buffer *ip = cpp_file_buffer (pfile);
6246 cpp_buf_line_and_col (ip, &line, &col);
6247 cpp_file_line_for_message (pfile, ip->nominal_fname,
6248 line, pfile->show_column ? col : -1);
6253 v_cpp_error (pfile, msg, ap)
6258 cpp_print_containing_files (pfile);
6259 cpp_print_file_and_line (pfile);
6260 v_cpp_message (pfile, 1, msg, ap);
6264 cpp_error VPROTO ((cpp_reader * pfile, const char *msg, ...))
6266 #ifndef ANSI_PROTOTYPES
6274 #ifndef ANSI_PROTOTYPES
6275 pfile = va_arg (ap, cpp_reader *);
6276 msg = va_arg (ap, const char *);
6279 v_cpp_error (pfile, msg, ap);
6283 /* Print error message but don't count it. */
6286 v_cpp_warning (pfile, msg, ap)
6291 if (CPP_OPTIONS (pfile)->inhibit_warnings)
6294 if (CPP_OPTIONS (pfile)->warnings_are_errors)
6297 cpp_print_containing_files (pfile);
6298 cpp_print_file_and_line (pfile);
6299 v_cpp_message (pfile, 0, msg, ap);
6303 cpp_warning VPROTO ((cpp_reader * pfile, const char *msg, ...))
6305 #ifndef ANSI_PROTOTYPES
6313 #ifndef ANSI_PROTOTYPES
6314 pfile = va_arg (ap, cpp_reader *);
6315 msg = va_arg (ap, const char *);
6318 v_cpp_warning (pfile, msg, ap);
6322 /* Print an error message and maybe count it. */
6325 cpp_pedwarn VPROTO ((cpp_reader * pfile, const char *msg, ...))
6327 #ifndef ANSI_PROTOTYPES
6335 #ifndef ANSI_PROTOTYPES
6336 pfile = va_arg (ap, cpp_reader *);
6337 msg = va_arg (ap, const char *);
6340 if (CPP_OPTIONS (pfile)->pedantic_errors)
6341 v_cpp_error (pfile, msg, ap);
6343 v_cpp_warning (pfile, msg, ap);
6348 v_cpp_error_with_line (pfile, line, column, msg, ap)
6355 cpp_buffer *ip = cpp_file_buffer (pfile);
6357 cpp_print_containing_files (pfile);
6360 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
6362 v_cpp_message (pfile, 1, msg, ap);
6366 cpp_error_with_line VPROTO ((cpp_reader * pfile, int line, int column, const char *msg, ...))
6368 #ifndef ANSI_PROTOTYPES
6378 #ifndef ANSI_PROTOTYPES
6379 pfile = va_arg (ap, cpp_reader *);
6380 line = va_arg (ap, int);
6381 column = va_arg (ap, int);
6382 msg = va_arg (ap, const char *);
6385 v_cpp_error_with_line(pfile, line, column, msg, ap);
6390 v_cpp_warning_with_line (pfile, line, column, msg, ap)
6399 if (CPP_OPTIONS (pfile)->inhibit_warnings)
6402 if (CPP_OPTIONS (pfile)->warnings_are_errors)
6405 cpp_print_containing_files (pfile);
6407 ip = cpp_file_buffer (pfile);
6410 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
6412 v_cpp_message (pfile, 0, msg, ap);
6417 cpp_warning_with_line VPROTO ((cpp_reader * pfile, int line, int column, const char *msg, ...))
6419 #ifndef ANSI_PROTOTYPES
6429 #ifndef ANSI_PROTOTYPES
6430 pfile = va_arg (ap, cpp_reader *);
6431 line = va_arg (ap, int);
6432 column = va_arg (ap, int);
6433 msg = va_arg (ap, const char *);
6436 v_cpp_warning_with_line (pfile, line, column, msg, ap);
6442 cpp_pedwarn_with_line VPROTO ((cpp_reader * pfile, int line, int column, const char *msg, ...))
6444 #ifndef ANSI_PROTOTYPES
6454 #ifndef ANSI_PROTOTYPES
6455 pfile = va_arg (ap, cpp_reader *);
6456 line = va_arg (ap, int);
6457 column = va_arg (ap, int);
6458 msg = va_arg (ap, const char *);
6461 if (CPP_OPTIONS (pfile)->pedantic_errors)
6462 v_cpp_error_with_line (pfile, column, line, msg, ap);
6464 v_cpp_warning_with_line (pfile, line, column, msg, ap);
6468 /* Report a warning (or an error if pedantic_errors)
6469 giving specified file name and line number, not current. */
6472 cpp_pedwarn_with_file_and_line VPROTO ((cpp_reader *pfile, char *file, int line, const char *msg, ...))
6474 #ifndef ANSI_PROTOTYPES
6484 #ifndef ANSI_PROTOTYPES
6485 pfile = va_arg (ap, cpp_reader *);
6486 file = va_arg (ap, char *);
6487 line = va_arg (ap, int);
6488 msg = va_arg (ap, const char *);
6491 if (!CPP_OPTIONS (pfile)->pedantic_errors
6492 && CPP_OPTIONS (pfile)->inhibit_warnings)
6495 cpp_file_line_for_message (pfile, file, line, -1);
6496 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msg, ap);
6500 /* my_strerror - return the descriptive text associated with an
6504 my_strerror (errnum)
6510 #ifndef HAVE_STRERROR
6511 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
6513 result = strerror (errnum);
6516 /* VAXCRTL's strerror() takes an optional second argument, which only
6517 matters when the first argument is EVMSERR. However, it's simplest
6518 just to pass it unconditionally. `vaxc$errno' is declared in
6519 <errno.h>, and maintained by the library in parallel with `errno'.
6520 We assume that caller's `errnum' either matches the last setting of
6521 `errno' by the library or else does not have the value `EVMSERR'. */
6523 result = strerror (errnum, vaxc$errno);
6527 result = "undocumented I/O error";
6532 /* Error including a message from `errno'. */
6535 cpp_error_from_errno (pfile, name)
6539 cpp_message_from_errno (pfile, 1, name);
6543 cpp_message_from_errno (pfile, is_error, name)
6549 cpp_buffer *ip = cpp_file_buffer (pfile);
6551 cpp_print_containing_files (pfile);
6554 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
6556 cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
6560 cpp_perror_with_name (pfile, name)
6564 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
6568 * No pre-compiled header file support.
6570 * Possibly different enum token codes for each C/C++ token.
6572 * Should clean up remaining directives to that do_XXX functions
6573 * only take two arguments and all have command_reads_line.
6575 * Find and cleanup remaining uses of static variables,
6577 * Support for trigraphs.
6579 * Support -dM flag (dump_all_macros).
6581 * Support for_lint flag.