2 Copyright (C) 1986, 87, 89, 92-98, 1999 Free Software Foundation, Inc.
3 Contributed by Per Bothner, 1994-95.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 #ifndef GET_ENV_PATH_LIST
35 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
38 /* By default, colon separates directories in a path. */
39 #ifndef PATH_SEPARATOR
40 #define PATH_SEPARATOR ':'
43 #ifndef STANDARD_INCLUDE_DIR
44 #define STANDARD_INCLUDE_DIR "/usr/include"
47 /* Symbols to predefine. */
50 static char *predefs = CPP_PREDEFINES;
52 static char *predefs = "";
55 /* We let tm.h override the types used here, to handle trivial differences
56 such as the choice of unsigned int or long unsigned int for size_t.
57 When machines start needing nontrivial differences in the size type,
58 it would be best to do something here to figure out automatically
59 from other information what type to use. */
61 /* The string value for __SIZE_TYPE__. */
64 #define SIZE_TYPE "long unsigned int"
67 /* The string value for __PTRDIFF_TYPE__. */
70 #define PTRDIFF_TYPE "long int"
73 /* The string value for __WCHAR_TYPE__. */
76 #define WCHAR_TYPE "int"
78 #define CPP_WCHAR_TYPE(PFILE) \
79 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
81 /* The string value for __USER_LABEL_PREFIX__ */
83 #ifndef USER_LABEL_PREFIX
84 #define USER_LABEL_PREFIX ""
87 /* The string value for __REGISTER_PREFIX__ */
89 #ifndef REGISTER_PREFIX
90 #define REGISTER_PREFIX ""
93 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
94 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
96 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
97 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
98 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
99 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
100 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
101 (Note that it is false while we're expanding marco *arguments*.) */
102 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
104 /* Move all backslash-newline pairs out of embarrassing places.
105 Exchange all such pairs following BP
106 with any potentially-embarrassing characters that follow them.
107 Potentially-embarrassing characters are / and *
108 (because a backslash-newline inside a comment delimiter
109 would cause it not to be recognized). */
111 #define NEWLINE_FIX \
112 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
114 /* Same, but assume we've already read the potential '\\' into C. */
115 #define NEWLINE_FIX1(C) do { \
116 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
120 struct cpp_pending *next;
125 /* Forward declarations. */
127 extern void cpp_hash_cleanup PARAMS ((cpp_reader *));
129 static char *my_strerror PROTO ((int));
130 static void make_assertion PROTO ((cpp_reader *, char *, U_CHAR *));
131 static void path_include PROTO ((cpp_reader *, char *));
132 static void initialize_builtins PROTO ((cpp_reader *));
133 static void initialize_char_syntax PROTO ((void));
134 static void validate_else PROTO ((cpp_reader *, char *));
135 static int comp_def_part PROTO ((int, U_CHAR *, int, U_CHAR *,
138 extern void fancy_abort ();
140 static int check_macro_name PROTO ((cpp_reader *, U_CHAR *, int));
141 static int compare_defs PROTO ((cpp_reader *,
142 DEFINITION *, DEFINITION *));
143 static HOST_WIDE_INT eval_if_expression PROTO ((cpp_reader *));
144 static int change_newlines PROTO ((U_CHAR *, int));
145 static void push_macro_expansion PARAMS ((cpp_reader *,
146 U_CHAR *, int, HASHNODE *));
147 static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending *));
149 static void conditional_skip PROTO ((cpp_reader *, int,
150 enum node_type, U_CHAR *));
151 static void skip_if_group PROTO ((cpp_reader *));
152 static int parse_name PARAMS ((cpp_reader *, int));
153 static void print_help PROTO ((void));
155 /* Last arg to output_line_command. */
156 enum file_change_code {same_file, enter_file, leave_file};
158 /* External declarations. */
160 extern HOST_WIDE_INT cpp_parse_expr PARAMS ((cpp_reader *));
161 extern char *version_string;
163 /* #include "file" looks in source file dir, then stack. */
164 /* #include <file> just looks in the stack. */
165 /* -I directories are added to the end, then the defaults are added. */
167 static struct default_include {
168 char *fname; /* The name of the directory. */
169 char *component; /* The component containing the directory */
170 int cplusplus; /* Only look here if we're compiling C++. */
171 int cxx_aware; /* Includes in this directory don't need to
172 be wrapped in extern "C" when compiling
174 } include_defaults_array[]
175 #ifdef INCLUDE_DEFAULTS
179 /* Pick up GNU C++ specific include files. */
180 { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
182 /* This is the dir for fixincludes. Put it just before
183 the files that we fix. */
184 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
185 /* For cross-compilation, this dir name is generated
186 automatically in Makefile.in. */
187 { CROSS_INCLUDE_DIR, "GCC",0, 0 },
188 #ifdef TOOL_INCLUDE_DIR
189 /* This is another place that the target system's headers might be. */
190 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
192 #else /* not CROSS_COMPILE */
193 #ifdef LOCAL_INCLUDE_DIR
194 /* This should be /usr/local/include and should come before
195 the fixincludes-fixed header files. */
196 { LOCAL_INCLUDE_DIR, 0, 0, 1 },
198 #ifdef TOOL_INCLUDE_DIR
199 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
200 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
201 { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1 },
203 /* This is the dir for fixincludes. Put it just before
204 the files that we fix. */
205 { GCC_INCLUDE_DIR, "GCC", 0, 0 },
206 /* Some systems have an extra dir of include files. */
207 #ifdef SYSTEM_INCLUDE_DIR
208 { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
210 #ifndef STANDARD_INCLUDE_COMPONENT
211 #define STANDARD_INCLUDE_COMPONENT 0
213 { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
214 #endif /* not CROSS_COMPILE */
217 #endif /* no INCLUDE_DEFAULTS */
219 /* `struct directive' defines one #-directive, including how to handle it. */
222 int length; /* Length of name */
223 int (*func) /* Function to handle directive */
224 PARAMS ((cpp_reader *, struct directive *));
225 char *name; /* Name of directive */
226 enum node_type type; /* Code which describes which directive. */
229 /* These functions are declared to return int instead of void since they
230 are going to be placed in a table and some old compilers have trouble with
231 pointers to functions returning void. */
233 static int do_define PARAMS ((cpp_reader *, struct directive *));
234 static int do_line PARAMS ((cpp_reader *, struct directive *));
235 static int do_include PARAMS ((cpp_reader *, struct directive *));
236 static int do_undef PARAMS ((cpp_reader *, struct directive *));
237 static int do_error PARAMS ((cpp_reader *, struct directive *));
238 static int do_pragma PARAMS ((cpp_reader *, struct directive *));
239 static int do_ident PARAMS ((cpp_reader *, struct directive *));
240 static int do_if PARAMS ((cpp_reader *, struct directive *));
241 static int do_xifdef PARAMS ((cpp_reader *, struct directive *));
242 static int do_else PARAMS ((cpp_reader *, struct directive *));
243 static int do_elif PARAMS ((cpp_reader *, struct directive *));
244 static int do_endif PARAMS ((cpp_reader *, struct directive *));
245 #ifdef SCCS_DIRECTIVE
246 static int do_sccs PARAMS ((cpp_reader *, struct directive *));
248 static int do_assert PARAMS ((cpp_reader *, struct directive *));
249 static int do_unassert PARAMS ((cpp_reader *, struct directive *));
250 static int do_warning PARAMS ((cpp_reader *, struct directive *));
252 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
253 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
255 /* Here is the actual list of #-directives, most-often-used first.
256 The initialize_builtins function assumes #define is the very first. */
258 static struct directive directive_table[] = {
259 { 6, do_define, "define", T_DEFINE },
260 { 5, do_xifdef, "ifdef", T_IFDEF },
261 { 6, do_xifdef, "ifndef", T_IFNDEF },
262 { 7, do_include, "include", T_INCLUDE },
263 { 12, do_include, "include_next", T_INCLUDE_NEXT },
264 { 6, do_include, "import", T_IMPORT },
265 { 5, do_endif, "endif", T_ENDIF },
266 { 4, do_else, "else", T_ELSE },
267 { 2, do_if, "if", T_IF },
268 { 4, do_elif, "elif", T_ELIF },
269 { 5, do_undef, "undef", T_UNDEF },
270 { 5, do_error, "error", T_ERROR },
271 { 7, do_warning, "warning", T_WARNING },
272 { 6, do_pragma, "pragma", T_PRAGMA },
273 { 4, do_line, "line", T_LINE },
274 { 5, do_ident, "ident", T_IDENT },
275 #ifdef SCCS_DIRECTIVE
276 { 4, do_sccs, "sccs", T_SCCS },
278 { 6, do_assert, "assert", T_ASSERT },
279 { 8, do_unassert, "unassert", T_UNASSERT },
280 { -1, 0, "", T_UNUSED }
283 /* table to tell if char can be part of a C identifier. */
284 U_CHAR is_idchar[256] = { 0 };
285 /* table to tell if char can be first char of a c identifier. */
286 U_CHAR is_idstart[256] = { 0 };
287 /* table to tell if c is horizontal space. */
288 U_CHAR is_hor_space[256] = { 0 };
289 /* table to tell if c is horizontal or vertical space. */
290 U_CHAR is_space[256] = { 0 };
291 /* Table to handle trigraph conversion, which occurs before all other
292 processing, everywhere in the file. (This is necessary since one
293 of the trigraphs encodes backslash.) Note it's off by default.
295 from to from to from to
300 There is not a space between the ?? and the third char. I put spaces
301 there to avoid warnings when compiling this file. */
302 U_CHAR trigraph_table[256] = { 0 };
304 /* Initialize syntactic classifications of characters. */
306 initialize_char_syntax ()
311 * Set up is_idchar and is_idstart tables. These should be
312 * faster than saying (is_alpha (c) || c == '_'), etc.
313 * Set up these things before calling any routines tthat
315 * XXX We should setlocale(LC_CTYPE, "C") here for safety.
317 for (i = 0; i < 256; i++)
319 is_idchar[i] = ISALNUM (i);
320 is_idstart[i] = ISALPHA (i);
326 /* These will be reset later if -$ is in effect. */
330 /* horizontal space table */
331 is_hor_space[' '] = 1;
332 is_hor_space['\t'] = 1;
333 is_hor_space['\v'] = 1;
334 is_hor_space['\f'] = 1;
335 is_hor_space['\r'] = 1;
344 /* trigraph conversion */
345 trigraph_table['='] = '#'; trigraph_table[')'] = ']';
346 trigraph_table['!'] = '|'; trigraph_table['('] = '[';
347 trigraph_table['\''] = '^'; trigraph_table['>'] = '}';
348 trigraph_table['/'] = '\\'; trigraph_table['<'] = '{';
349 trigraph_table['-'] = '~';
352 /* Place into PFILE a quoted string representing the string SRC.
353 Caller must reserve enough space in pfile->token_buffer. */
356 quote_string (pfile, src)
362 CPP_PUTC_Q (pfile, '\"');
364 switch ((c = *src++))
368 CPP_PUTC_Q (pfile, c);
371 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o", c);
372 CPP_ADJUST_WRITTEN (pfile, 4);
378 CPP_PUTC_Q (pfile, '\\');
379 CPP_PUTC_Q (pfile, c);
383 CPP_PUTC_Q (pfile, '\"');
384 CPP_NUL_TERMINATE_Q (pfile);
389 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
392 cpp_grow_buffer (pfile, n)
396 long old_written = CPP_WRITTEN (pfile);
397 pfile->token_buffer_size = n + 2 * pfile->token_buffer_size;
398 pfile->token_buffer = (U_CHAR *)
399 xrealloc(pfile->token_buffer, pfile->token_buffer_size);
400 CPP_SET_WRITTEN (pfile, old_written);
405 * process a given definition string, for initialization
406 * If STR is just an identifier, define it with value 1.
407 * If STR has anything after the identifier, then it should
408 * be identifier=definition.
412 cpp_define (pfile, str)
422 cpp_error (pfile, "malformed option `-D %s'", str);
425 while (is_idchar[*++p])
428 while (is_idchar[*++p] || *p == ',' || is_hor_space[*p])
431 p = (U_CHAR *) str; /* Error */
435 buf = (U_CHAR *) alloca (p - buf + 4);
436 strcpy ((char *)buf, str);
437 strcat ((char *)buf, " 1");
441 cpp_error (pfile, "malformed option `-D %s'", str);
447 /* Copy the entire option so we can modify it. */
448 buf = (U_CHAR *) alloca (2 * strlen (str) + 1);
449 strncpy (buf, str, p - str);
450 /* Change the = to a space. */
452 /* Scan for any backslash-newline and remove it. */
457 if (*p == '\\' && p[1] == '\n')
465 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
467 do_define (pfile, NULL);
468 cpp_pop_buffer (pfile);
472 /* Process the string STR as if it appeared as the body of a #assert.
473 OPTION is the option name for which STR was the argument. */
476 make_assertion (pfile, option, str)
483 /* Copy the entire option so we can modify it. */
484 buf = (U_CHAR *) alloca (strlen (str) + 1);
485 strcpy ((char *) buf, str);
486 /* Scan for any backslash-newline and remove it. */
490 if (*p == '\\' && p[1] == '\n')
499 if (!is_idstart[*p]) {
500 cpp_error (pfile, "malformed option `%s %s'", option, str);
503 while (is_idchar[*++p])
505 while (*p == ' ' || *p == '\t') p++;
506 if (! (*p == 0 || *p == '(')) {
507 cpp_error (pfile, "malformed option `%s %s'", option, str);
511 if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
513 do_assert (pfile, NULL);
514 cpp_pop_buffer (pfile);
518 /* Given a colon-separated list of file names PATH,
519 add all the names to the search path for include files. */
522 path_include (pfile, path)
535 /* Find the end of this name. */
536 while (*q != 0 && *q != PATH_SEPARATOR) q++;
538 /* An empty name in the path stands for the current directory. */
539 name = (char *) xmalloc (2);
543 /* Otherwise use the directory that is named. */
544 name = (char *) xmalloc (q - p + 1);
545 bcopy (p, name, q - p);
549 append_include_chain (pfile,
550 &(CPP_OPTIONS (pfile)->bracket_include), name, 0);
552 /* Advance past this name. */
556 /* Skip the colon. */
562 cpp_options_init (opts)
565 bzero ((char *) opts, sizeof *opts);
566 opts->in_fname = NULL;
567 opts->out_fname = NULL;
569 opts->dollars_in_ident = 1;
570 initialize_char_syntax ();
572 opts->no_line_commands = 0;
574 opts->put_out_comments = 0;
575 opts->print_include_names = 0;
576 opts->dump_macros = dump_none;
580 opts->cplusplus_comments = 1;
587 opts->pedantic_errors = 0;
588 opts->inhibit_warnings = 0;
589 opts->warn_comments = 0;
590 opts->warn_import = 1;
591 opts->warnings_are_errors = 0;
595 null_underflow (pfile)
596 cpp_reader *pfile ATTRIBUTE_UNUSED;
602 null_cleanup (pbuf, pfile)
603 cpp_buffer *pbuf ATTRIBUTE_UNUSED;
604 cpp_reader *pfile ATTRIBUTE_UNUSED;
610 macro_cleanup (pbuf, pfile)
612 cpp_reader *pfile ATTRIBUTE_UNUSED;
614 HASHNODE *macro = (HASHNODE *) pbuf->data;
615 if (macro->type == T_DISABLED)
616 macro->type = T_MACRO;
617 if (macro->type != T_MACRO || pbuf->buf != macro->value.defn->expansion)
622 /* Assuming we have read '/'.
623 If this is the start of a comment (followed by '*' or '/'),
624 skip to the end of the comment, and return ' '.
625 Return EOF if we reached the end of file before the end of the comment.
626 If not the start of a comment, return '/'. */
629 skip_comment (pfile, linep)
634 while (PEEKC() == '\\' && PEEKN(1) == '\n')
649 while (c == '\\' && PEEKC() == '\n')
653 FORWARD(1), c = GETC();
655 if (prev_c == '*' && c == '/')
657 if (c == '\n' && linep)
661 else if (PEEKC() == '/' && CPP_OPTIONS (pfile)->cplusplus_comments)
668 return ' '; /* Allow // to be terminated by EOF. */
669 while (c == '\\' && PEEKC() == '\n')
678 /* Don't consider final '\n' to be part of comment. */
688 /* Skip whitespace \-newline and comments. Does not macro-expand. */
691 cpp_skip_hspace (pfile)
701 if ((c == '\f' || c == '\v') && CPP_PEDANTIC (pfile))
702 cpp_pedwarn (pfile, "%s in preprocessing directive",
703 c == '\f' ? "formfeed" : "vertical tab");
709 c = skip_comment (pfile, NULL);
712 if (c == EOF || c == '/')
715 else if (c == '\\' && PEEKN(1) == '\n') {
718 else if (c == '@' && CPP_BUFFER (pfile)->has_escapes
719 && is_hor_space[PEEKN(1)])
725 /* Read the rest of the current line.
726 The line is appended to PFILE's output buffer. */
729 copy_rest_of_line (pfile)
732 struct cpp_options *opts = CPP_OPTIONS (pfile);
749 goto scan_directive_token;
753 if (nextc == '*' || (opts->cplusplus_comments && nextc == '/'))
754 goto scan_directive_token;
758 if (CPP_PEDANTIC (pfile))
759 cpp_pedwarn (pfile, "%s in preprocessing directive",
760 c == '\f' ? "formfeed" : "vertical tab");
766 scan_directive_token:
768 cpp_get_token (pfile);
774 CPP_NUL_TERMINATE (pfile);
778 skip_rest_of_line (pfile)
781 long old = CPP_WRITTEN (pfile);
782 copy_rest_of_line (pfile);
783 CPP_SET_WRITTEN (pfile, old);
786 /* Handle a possible # directive.
787 '#' has already been read. */
790 handle_directive (pfile)
793 register struct directive *kt;
796 long old_written = CPP_WRITTEN (pfile);
798 cpp_skip_hspace (pfile);
801 if (c >= '0' && c <= '9')
803 /* Handle # followed by a line number. */
804 if (CPP_PEDANTIC (pfile))
805 cpp_pedwarn (pfile, "`#' followed by integer");
806 do_line (pfile, NULL);
807 goto done_a_directive;
810 /* Now find the directive name. */
811 CPP_PUTC (pfile, '#');
812 parse_name (pfile, GETC());
813 ident = pfile->token_buffer + old_written + 1;
814 ident_length = CPP_PWRITTEN (pfile) - ident;
815 if (ident_length == 0 && PEEKC() == '\n')
817 /* A line of just `#' becomes blank. */
818 goto done_a_directive;
822 if (ident_length == 0 || !is_idstart[*ident]) {
824 while (is_idchar[*p]) {
825 if (*p < '0' || *p > '9')
829 /* Avoid error for `###' and similar cases unless -pedantic. */
831 while (*p == '#' || is_hor_space[*p]) p++;
833 if (pedantic && !lang_asm)
834 cpp_warning (pfile, "invalid preprocessor directive");
840 cpp_error (pfile, "invalid preprocessor directive name");
846 * Decode the keyword and call the appropriate expansion
847 * routine, after moving the input pointer up to the next line.
849 for (kt = directive_table; ; kt++) {
851 goto not_a_directive;
852 if (kt->length == ident_length
853 && !strncmp (kt->name, ident, ident_length))
857 /* We may want to pass through #define, #undef, #pragma, and #include.
858 Other directives may create output, but we don't want the directive
859 itself out, so we pop it now. For example conditionals may emit
860 #failed ... #endfailed stuff. */
862 if (! (kt->type == T_DEFINE
863 || kt->type == T_PRAGMA
864 || (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)
865 && CPP_OPTIONS (pfile)->dump_includes)))
866 CPP_SET_WRITTEN (pfile, old_written);
868 (*kt->func) (pfile, kt);
870 if (kt->type == T_DEFINE)
872 if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
874 /* Skip "#define". */
875 U_CHAR *p = pfile->token_buffer + old_written + 7;
877 SKIP_WHITE_SPACE (p);
878 while (is_idchar[*p]) p++;
880 CPP_PUTC (pfile, '\n');
882 else if (CPP_OPTIONS (pfile)->dump_macros != dump_definitions)
883 CPP_SET_WRITTEN (pfile, old_written);
893 /* Pass a directive through to the output file.
894 BUF points to the contents of the directive, as a contiguous string.
895 m LIMIT points to the first character past the end of the directive.
896 KEYWORD is the keyword-table entry for the directive. */
899 pass_thru_directive (buf, limit, pfile, keyword)
902 struct directive *keyword;
904 register unsigned keyword_length = keyword->length;
906 CPP_RESERVE (pfile, 1 + keyword_length + (limit - buf));
907 CPP_PUTC_Q (pfile, '#');
908 CPP_PUTS_Q (pfile, keyword->name, keyword_length);
909 if (limit != buf && buf[0] != ' ')
910 CPP_PUTC_Q (pfile, ' ');
911 CPP_PUTS_Q (pfile, buf, limit - buf);
913 CPP_PUTS_Q (pfile, '\n');
914 /* Count the line we have just made in the output,
915 to get in sync properly. */
920 /* The arglist structure is built by do_define to tell
921 collect_definition where the argument names begin. That
922 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
923 would contain pointers to the strings x, y, and z.
924 Collect_definition would then build a DEFINITION node,
925 with reflist nodes pointing to the places x, y, and z had
926 appeared. So the arglist is just convenience data passed
927 between these two routines. It is not kept around after
928 the current #define has been processed and entered into the
932 struct arglist *next;
939 /* Read a replacement list for a macro with parameters.
940 Build the DEFINITION structure.
941 Reads characters of text starting at BUF until END.
942 ARGLIST specifies the formal parameters to look for
943 in the text of the definition; NARGS is the number of args
944 in that list, or -1 for a macro name that wants no argument list.
945 MACRONAME is the macro name itself (so we can avoid recursive expansion)
946 and NAMELEN is its length in characters.
948 Note that comments, backslash-newlines, and leading white space
949 have already been deleted from the argument. */
952 collect_expansion (pfile, buf, limit, nargs, arglist)
956 struct arglist *arglist;
959 register U_CHAR *p, *lastp, *exp_p;
960 struct reflist *endpat = NULL;
961 /* Pointer to first nonspace after last ## seen. */
963 /* Pointer to first nonspace after last single-# seen. */
964 U_CHAR *stringify = 0;
966 int expected_delimiter = '\0';
968 /* Scan thru the replacement list, ignoring comments and quoted
969 strings, picking up on the macro calls. It does a linear search
970 thru the arg list on every potential symbol. Profiling might say
971 that something smarter should happen. */
976 /* Find the beginning of the trailing whitespace. */
978 while (p < limit && is_space[limit[-1]]) limit--;
980 /* Allocate space for the text in the macro definition.
981 Leading and trailing whitespace chars need 2 bytes each.
982 Each other input char may or may not need 1 byte,
983 so this is an upper bound. The extra 5 are for invented
984 leading and trailing newline-marker and final null. */
985 maxsize = (sizeof (DEFINITION)
987 /* Occurrences of '@' get doubled, so allocate extra space for them. */
991 defn = (DEFINITION *) xcalloc (1, maxsize);
994 exp_p = defn->expansion = (U_CHAR *) defn + sizeof (DEFINITION);
999 /* Add one initial space escape-marker to prevent accidental
1000 token-pasting (often removed by macroexpand). */
1004 if (limit - p >= 2 && p[0] == '#' && p[1] == '#') {
1005 cpp_error (pfile, "`##' at start of macro definition");
1009 /* Process the main body of the definition. */
1011 int skipped_arg = 0;
1012 register U_CHAR c = *p++;
1016 if (!CPP_TRADITIONAL (pfile)) {
1020 if (expected_delimiter != '\0') {
1021 if (c == expected_delimiter)
1022 expected_delimiter = '\0';
1024 expected_delimiter = c;
1028 if (p < limit && expected_delimiter) {
1029 /* In a string, backslash goes through
1030 and makes next char ordinary. */
1036 /* An '@' in a string or character constant stands for itself,
1037 and does not need to be escaped. */
1038 if (!expected_delimiter)
1043 /* # is ordinary inside a string. */
1044 if (expected_delimiter)
1046 if (p < limit && *p == '#') {
1047 /* ##: concatenate preceding and following tokens. */
1048 /* Take out the first #, discard preceding whitespace. */
1050 while (exp_p > lastp && is_hor_space[exp_p[-1]])
1052 /* Skip the second #. */
1054 /* Discard following whitespace. */
1055 SKIP_WHITE_SPACE (p);
1058 cpp_error (pfile, "`##' at end of macro definition");
1059 } else if (nargs >= 0) {
1060 /* Single #: stringify following argument ref.
1061 Don't leave the # in the expansion. */
1063 SKIP_WHITE_SPACE (p);
1064 if (p == limit || ! is_idstart[*p]
1065 || (*p == 'L' && p + 1 < limit && (p[1] == '\'' || p[1] == '"')))
1067 "`#' operator is not followed by a macro argument name");
1074 /* In -traditional mode, recognize arguments inside strings and
1075 character constants, and ignore special properties of #.
1076 Arguments inside strings are considered "stringified", but no
1077 extra quote marks are supplied. */
1081 if (expected_delimiter != '\0') {
1082 if (c == expected_delimiter)
1083 expected_delimiter = '\0';
1085 expected_delimiter = c;
1089 /* Backslash quotes delimiters and itself, but not macro args. */
1090 if (expected_delimiter != 0 && p < limit
1091 && (*p == expected_delimiter || *p == '\\')) {
1098 if (expected_delimiter != '\0') /* No comments inside strings. */
1101 /* If we find a comment that wasn't removed by handle_directive,
1102 this must be -traditional. So replace the comment with
1106 while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
1109 /* Mark this as a concatenation-point, as if it had been ##. */
1117 /* Handle the start of a symbol. */
1118 if (is_idchar[c] && nargs > 0) {
1119 U_CHAR *id_beg = p - 1;
1123 while (p != limit && is_idchar[*p]) p++;
1124 id_len = p - id_beg;
1127 && ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '"'))) {
1128 register struct arglist *arg;
1130 for (arg = arglist; arg != NULL; arg = arg->next) {
1131 struct reflist *tpat;
1133 if (arg->name[0] == c
1134 && arg->length == id_len
1135 && strncmp (arg->name, id_beg, id_len) == 0) {
1136 if (expected_delimiter && CPP_OPTIONS (pfile)->warn_stringify) {
1137 if (CPP_TRADITIONAL (pfile)) {
1138 cpp_warning (pfile, "macro argument `%.*s' is stringified.",
1142 "macro arg `%.*s' would be stringified with -traditional.",
1146 /* If ANSI, don't actually substitute inside a string. */
1147 if (!CPP_TRADITIONAL (pfile) && expected_delimiter)
1149 /* make a pat node for this arg and append it to the end of
1151 tpat = (struct reflist *) xmalloc (sizeof (struct reflist));
1153 tpat->raw_before = concat == id_beg;
1154 tpat->raw_after = 0;
1155 tpat->rest_args = arg->rest_args;
1156 tpat->stringify = (CPP_TRADITIONAL (pfile)
1157 ? expected_delimiter != '\0'
1158 : stringify == id_beg);
1161 defn->pattern = tpat;
1163 endpat->next = tpat;
1166 tpat->argno = arg->argno;
1167 tpat->nchars = exp_p - lastp;
1169 register U_CHAR *p1 = p;
1170 SKIP_WHITE_SPACE (p1);
1171 if (p1 + 2 <= limit && p1[0] == '#' && p1[1] == '#')
1172 tpat->raw_after = 1;
1174 lastp = exp_p; /* place to start copying from next time */
1181 /* If this was not a macro arg, copy it into the expansion. */
1182 if (! skipped_arg) {
1183 register U_CHAR *lim1 = p;
1187 if (stringify == id_beg)
1189 "`#' operator should be followed by a macro argument name");
1194 if (!CPP_TRADITIONAL (pfile) && expected_delimiter == 0)
1196 /* If ANSI, put in a "@ " marker to prevent token pasting.
1197 But not if "inside a string" (which in ANSI mode
1198 happens only for -D option). */
1205 defn->length = exp_p - defn->expansion;
1207 /* Crash now if we overrun the allocated size. */
1208 if (defn->length + 1 > maxsize)
1212 /* This isn't worth the time it takes. */
1213 /* give back excess storage */
1214 defn->expansion = (U_CHAR *) xrealloc (defn->expansion, defn->length + 1);
1221 * special extension string that can be added to the last macro argument to
1222 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1223 * #define wow(a, b...) process (b, a, b)
1224 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1225 * { wow (one, two); } -> { process (two, one, two); }
1226 * if this "rest_arg" is used with the concat token '##' and if it is not
1227 * supplied then the token attached to with ## will not be outputted. Ex:
1228 * #define wow (a, b...) process (b ## , a, ## b)
1229 * { wow (1, 2); } -> { process (2, 1, 2); }
1230 * { wow (one); } -> { process (one); {
1232 static char rest_extension[] = "...";
1233 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1235 /* Create a DEFINITION node from a #define directive. Arguments are
1236 as for do_define. */
1239 create_definition (buf, limit, pfile, predefinition)
1240 U_CHAR *buf, *limit;
1244 U_CHAR *bp; /* temp ptr into input buffer */
1245 U_CHAR *symname; /* remember where symbol name starts */
1246 int sym_length; /* and how long it is */
1249 char *file = CPP_BUFFER (pfile) ? CPP_BUFFER (pfile)->nominal_fname : "";
1251 int arglengths = 0; /* Accumulate lengths of arg names
1252 plus number of args. */
1254 cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, &col);
1258 while (is_hor_space[*bp])
1261 symname = bp; /* remember where it starts */
1263 sym_length = check_macro_name (pfile, bp, 0);
1266 /* Lossage will occur if identifiers or control keywords are broken
1267 across lines using backslash. This is not the right place to take
1271 struct arglist *arg_ptrs = NULL;
1274 bp++; /* skip '(' */
1275 SKIP_WHITE_SPACE (bp);
1277 /* Loop over macro argument names. */
1278 while (*bp != ')') {
1279 struct arglist *temp;
1281 temp = (struct arglist *) alloca (sizeof (struct arglist));
1283 temp->next = arg_ptrs;
1284 temp->argno = argno++;
1285 temp->rest_args = 0;
1289 cpp_pedwarn (pfile, "another parameter follows `%s'", rest_extension);
1291 if (!is_idstart[*bp])
1292 cpp_pedwarn (pfile, "invalid character in macro parameter name");
1294 /* Find the end of the arg name. */
1295 while (is_idchar[*bp]) {
1297 /* do we have a "special" rest-args extension here? */
1298 if ((size_t)(limit - bp) > REST_EXTENSION_LENGTH
1299 && strncmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
1301 temp->rest_args = 1;
1305 temp->length = bp - temp->name;
1307 bp += REST_EXTENSION_LENGTH;
1308 arglengths += temp->length + 2;
1309 SKIP_WHITE_SPACE (bp);
1310 if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
1311 cpp_error (pfile, "badly punctuated parameter list in `#define'");
1316 SKIP_WHITE_SPACE (bp);
1319 cpp_error (pfile, "unterminated parameter list in `#define'");
1323 struct arglist *otemp;
1325 for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
1326 if (temp->length == otemp->length
1327 && strncmp (temp->name, otemp->name, temp->length) == 0) {
1330 name = (U_CHAR *) alloca (temp->length + 1);
1331 (void) strncpy (name, temp->name, temp->length);
1332 name[temp->length] = '\0';
1334 "duplicate argument name `%s' in `#define'", name);
1340 ++bp; /* skip paren */
1341 SKIP_WHITE_SPACE (bp);
1342 /* now everything from bp before limit is the definition. */
1343 defn = collect_expansion (pfile, bp, limit, argno, arg_ptrs);
1344 defn->rest_args = rest_args;
1346 /* Now set defn->args.argnames to the result of concatenating
1347 the argument names in reverse order
1348 with comma-space between them. */
1349 defn->args.argnames = (U_CHAR *) xmalloc (arglengths + 1);
1351 struct arglist *temp;
1353 for (temp = arg_ptrs; temp; temp = temp->next) {
1354 bcopy (temp->name, &defn->args.argnames[i], temp->length);
1356 if (temp->next != 0) {
1357 defn->args.argnames[i++] = ',';
1358 defn->args.argnames[i++] = ' ';
1361 defn->args.argnames[i] = 0;
1364 /* Simple expansion or empty definition. */
1368 if (is_hor_space[*bp]) {
1370 SKIP_WHITE_SPACE (bp);
1373 case '!': case '"': case '#': case '%': case '&': case '\'':
1374 case ')': case '*': case '+': case ',': case '-': case '.':
1375 case '/': case ':': case ';': case '<': case '=': case '>':
1376 case '?': case '[': case '\\': case ']': case '^': case '{':
1377 case '|': case '}': case '~':
1378 cpp_warning (pfile, "missing white space after `#define %.*s'",
1379 sym_length, symname);
1383 cpp_pedwarn (pfile, "missing white space after `#define %.*s'",
1384 sym_length, symname);
1389 /* now everything from bp before limit is the definition. */
1390 defn = collect_expansion (pfile, bp, limit, -1, NULL_PTR);
1391 defn->args.argnames = (U_CHAR *) "";
1397 /* OP is null if this is a predefinition */
1398 defn->predefined = predefinition;
1400 mdef.symnam = symname;
1401 mdef.symlen = sym_length;
1410 /* Check a purported macro name SYMNAME, and yield its length.
1411 ASSERTION is nonzero if this is really for an assertion name. */
1414 check_macro_name (pfile, symname, assertion)
1422 for (p = symname; is_idchar[*p]; p++)
1424 sym_length = p - symname;
1426 || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
1428 assertion ? "invalid assertion name" : "invalid macro name");
1429 else if (!is_idstart[*symname]
1430 || (! strncmp (symname, "defined", 7) && sym_length == 7)) {
1431 U_CHAR *msg; /* what pain... */
1432 msg = (U_CHAR *) alloca (sym_length + 1);
1433 bcopy (symname, msg, sym_length);
1434 msg[sym_length] = 0;
1437 ? "invalid assertion name `%s'"
1438 : "invalid macro name `%s'"),
1444 /* Return zero if two DEFINITIONs are isomorphic. */
1447 compare_defs (pfile, d1, d2)
1449 DEFINITION *d1, *d2;
1451 register struct reflist *a1, *a2;
1452 register U_CHAR *p1 = d1->expansion;
1453 register U_CHAR *p2 = d2->expansion;
1456 if (d1->nargs != d2->nargs)
1458 if (CPP_PEDANTIC (pfile)
1459 && strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
1461 for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
1462 a1 = a1->next, a2 = a2->next) {
1463 if (!((a1->nchars == a2->nchars && ! strncmp (p1, p2, a1->nchars))
1464 || ! comp_def_part (first, p1, a1->nchars, p2, a2->nchars, 0))
1465 || a1->argno != a2->argno
1466 || a1->stringify != a2->stringify
1467 || a1->raw_before != a2->raw_before
1468 || a1->raw_after != a2->raw_after)
1476 if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
1477 p2, d2->length - (p2 - d2->expansion), 1))
1482 /* Return 1 if two parts of two macro definitions are effectively different.
1483 One of the parts starts at BEG1 and has LEN1 chars;
1484 the other has LEN2 chars at BEG2.
1485 Any sequence of whitespace matches any other sequence of whitespace.
1486 FIRST means these parts are the first of a macro definition;
1487 so ignore leading whitespace entirely.
1488 LAST means these parts are the last of a macro definition;
1489 so ignore trailing whitespace entirely. */
1492 comp_def_part (first, beg1, len1, beg2, len2, last)
1494 U_CHAR *beg1, *beg2;
1498 register U_CHAR *end1 = beg1 + len1;
1499 register U_CHAR *end2 = beg2 + len2;
1501 while (beg1 != end1 && is_space[*beg1]) beg1++;
1502 while (beg2 != end2 && is_space[*beg2]) beg2++;
1505 while (beg1 != end1 && is_space[end1[-1]]) end1--;
1506 while (beg2 != end2 && is_space[end2[-1]]) end2--;
1508 while (beg1 != end1 && beg2 != end2) {
1509 if (is_space[*beg1] && is_space[*beg2]) {
1510 while (beg1 != end1 && is_space[*beg1]) beg1++;
1511 while (beg2 != end2 && is_space[*beg2]) beg2++;
1512 } else if (*beg1 == *beg2) {
1516 return (beg1 != end1) || (beg2 != end2);
1519 /* Process a #define command.
1520 KEYWORD is the keyword-table entry for #define,
1521 or NULL for a "predefined" macro. */
1524 do_define (pfile, keyword)
1526 struct directive *keyword;
1531 int save_put_out_comments;
1533 U_CHAR *macro, *buf, *end;
1535 here = CPP_WRITTEN (pfile);
1537 save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1538 CPP_OPTIONS (pfile)->put_out_comments = CPP_TRADITIONAL (pfile);
1539 copy_rest_of_line (pfile);
1540 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1542 /* Copy out the line so we can pop the token buffer. */
1543 buf = pfile->token_buffer + here;
1544 end = CPP_PWRITTEN (pfile);
1545 macro = alloca (end - buf + 1);
1546 bcopy (buf, macro, end - buf + 1);
1547 end = macro + (end - buf);
1549 CPP_SET_WRITTEN (pfile, here);
1552 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1553 if (pcp_outfile && keyword)
1554 pass_thru_directive (macro, end, pfile, keyword);
1557 mdef = create_definition (macro, end, 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 /* If we are passing through #define and #undef directives, do
1579 that for this re-definition now. */
1580 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1581 pass_thru_directive (macro, end, pfile, keyword);
1583 cpp_pedwarn (pfile, "`%.*s' redefined", mdef.symlen, mdef.symnam);
1584 if (hp->type == T_MACRO)
1585 cpp_pedwarn_with_file_and_line (pfile, hp->value.defn->file, hp->value.defn->line,
1586 "this is the location of the previous definition");
1588 /* Replace the old definition. */
1590 hp->value.defn = mdef.defn;
1594 /* If we are passing through #define and #undef directives, do
1595 that for this new definition now. */
1596 if (CPP_OPTIONS (pfile)->debug_output && keyword)
1597 pass_thru_directive (macro, end, pfile, keyword);
1598 install (mdef.symnam, mdef.symlen, T_MACRO, 0,
1599 (char *) mdef.defn, hashcode);
1609 /* This structure represents one parsed argument in a macro call.
1610 `raw' points to the argument text as written (`raw_length' is its length).
1611 `expanded' points to the argument's macro-expansion
1612 (its length is `expand_length').
1613 `stringified_length' is the length the argument would have
1615 `use_count' is the number of times this macro arg is substituted
1616 into the macro. If the actual use count exceeds 10,
1617 the value stored is 10. */
1619 /* raw and expanded are relative to ARG_BASE */
1620 #define ARG_BASE ((pfile)->token_buffer)
1623 /* Strings relative to pfile->token_buffer */
1624 long raw, expanded, stringified;
1625 int raw_length, expand_length;
1626 int stringified_length;
1631 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1632 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1633 as the new input buffer.
1634 Return the new buffer, or NULL on failure. */
1637 cpp_push_buffer (pfile, buffer, length)
1642 register cpp_buffer *buf = CPP_BUFFER (pfile);
1643 if (buf == pfile->buffer_stack)
1645 cpp_fatal (pfile, "%s: macro or `#include' recursion too deep",
1650 bzero ((char *) buf, sizeof (cpp_buffer));
1651 CPP_BUFFER (pfile) = buf;
1652 buf->if_stack = pfile->if_stack;
1653 buf->cleanup = null_cleanup;
1654 buf->underflow = null_underflow;
1655 buf->buf = buf->cur = buffer;
1656 buf->alimit = buf->rlimit = buffer + length;
1662 cpp_pop_buffer (pfile)
1665 cpp_buffer *buf = CPP_BUFFER (pfile);
1666 (*buf->cleanup) (buf, pfile);
1667 return ++CPP_BUFFER (pfile);
1670 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1671 Pop the buffer when done. */
1674 cpp_scan_buffer (pfile)
1677 cpp_buffer *buffer = CPP_BUFFER (pfile);
1680 enum cpp_token token = cpp_get_token (pfile);
1681 if (token == CPP_EOF) /* Should not happen ... */
1683 if (token == CPP_POP && CPP_BUFFER (pfile) == buffer)
1685 cpp_pop_buffer (pfile);
1692 * Rescan a string (which may have escape marks) into pfile's buffer.
1693 * Place the result in pfile->token_buffer.
1695 * The input is copied before it is scanned, so it is safe to pass
1696 * it something from the token_buffer that will get overwritten
1697 * (because it follows CPP_WRITTEN). This is used by do_include.
1701 cpp_expand_to_buffer (pfile, buf, length)
1706 register cpp_buffer *ip;
1710 U_CHAR *limit = buf + length;
1713 int odepth = indepth;
1719 /* Set up the input on the input stack. */
1721 buf1 = (U_CHAR *) alloca (length + 1);
1723 register U_CHAR *p1 = buf;
1724 register U_CHAR *p2 = buf1;
1731 ip = cpp_push_buffer (pfile, buf1, length);
1734 ip->has_escapes = 1;
1736 ip->lineno = obuf.lineno = 1;
1739 /* Scan the input, create the output. */
1740 cpp_scan_buffer (pfile);
1743 if (indepth != odepth)
1747 CPP_NUL_TERMINATE (pfile);
1752 adjust_position (buf, limit, linep, colp)
1762 (*linep)++, (*colp) = 1;
1768 /* Move line_base forward, updating lineno and colno. */
1771 update_position (pbuf)
1772 register cpp_buffer *pbuf;
1774 unsigned char *old_pos = pbuf->buf + pbuf->line_base;
1775 unsigned char *new_pos = pbuf->cur;
1776 register struct parse_marker *mark;
1777 for (mark = pbuf->marks; mark != NULL; mark = mark->next)
1779 if (pbuf->buf + mark->position < new_pos)
1780 new_pos = pbuf->buf + mark->position;
1782 pbuf->line_base += new_pos - old_pos;
1783 adjust_position (old_pos, new_pos, &pbuf->lineno, &pbuf->colno);
1787 cpp_buf_line_and_col (pbuf, linep, colp)
1788 register cpp_buffer *pbuf;
1796 *linep = pbuf->lineno;
1797 *colp = pbuf->colno;
1798 adjust_position (pbuf->buf + pbuf->line_base, pbuf->cur, linep, colp);
1807 /* Return the cpp_buffer that corresponds to a file (not a macro). */
1810 cpp_file_buffer (pfile)
1813 cpp_buffer *ip = CPP_BUFFER (pfile);
1815 for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
1816 if (ip->fname != NULL)
1822 count_newlines (buf, limit)
1823 register U_CHAR *buf;
1824 register U_CHAR *limit;
1826 register long count = 0;
1837 * write out a #line command, for instance, after an #include file.
1838 * If CONDITIONAL is nonzero, we can omit the #line if it would
1839 * appear to be a no-op, and we can output a few newlines instead
1840 * if we want to increase the line number by a small amount.
1841 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
1845 output_line_command (pfile, conditional, file_change)
1848 enum file_change_code file_change;
1851 cpp_buffer *ip = CPP_BUFFER (pfile);
1853 if (ip->fname == NULL)
1856 update_position (ip);
1858 if (CPP_OPTIONS (pfile)->no_line_commands
1859 || CPP_OPTIONS (pfile)->no_output)
1862 line = CPP_BUFFER (pfile)->lineno;
1863 col = CPP_BUFFER (pfile)->colno;
1864 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
1866 if (CPP_OPTIONS (pfile)->no_line_commands)
1870 if (line == pfile->lineno)
1873 /* If the inherited line number is a little too small,
1874 output some newlines instead of a #line command. */
1875 if (line > pfile->lineno && line < pfile->lineno + 8) {
1876 CPP_RESERVE (pfile, 20);
1877 while (line > pfile->lineno) {
1878 CPP_PUTC_Q (pfile, '\n');
1886 /* Don't output a line number of 0 if we can help it. */
1887 if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
1888 && *ip->bufp == '\n') {
1894 CPP_RESERVE (pfile, 4 * strlen (ip->nominal_fname) + 50);
1896 #ifdef OUTPUT_LINE_COMMANDS
1897 static char sharp_line[] = "#line ";
1899 static char sharp_line[] = "# ";
1901 CPP_PUTS_Q (pfile, sharp_line, sizeof(sharp_line)-1);
1904 sprintf ((char *) CPP_PWRITTEN (pfile), "%ld ", line);
1905 CPP_ADJUST_WRITTEN (pfile, strlen (CPP_PWRITTEN (pfile)));
1907 quote_string (pfile, ip->nominal_fname);
1908 if (file_change != same_file) {
1909 CPP_PUTC_Q (pfile, ' ');
1910 CPP_PUTC_Q (pfile, file_change == enter_file ? '1' : '2');
1912 /* Tell cc1 if following text comes from a system header file. */
1913 if (ip->system_header_p) {
1914 CPP_PUTC_Q (pfile, ' ');
1915 CPP_PUTC_Q (pfile, '3');
1917 #ifndef NO_IMPLICIT_EXTERN_C
1918 /* Tell cc1plus if following text should be treated as C. */
1919 if (ip->system_header_p == 2 && CPP_OPTIONS (pfile)->cplusplus) {
1920 CPP_PUTC_Q (pfile, ' ');
1921 CPP_PUTC_Q (pfile, '4');
1924 CPP_PUTC_Q (pfile, '\n');
1925 pfile->lineno = line;
1929 * Parse a macro argument and append the info on PFILE's token_buffer.
1930 * REST_ARGS means to absorb the rest of the args.
1931 * Return nonzero to indicate a syntax error.
1934 static enum cpp_token
1935 macarg (pfile, rest_args)
1940 enum cpp_token token;
1941 char save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
1942 CPP_OPTIONS (pfile)->put_out_comments = 0;
1944 /* Try to parse as much of the argument as exists at this
1945 input stack level. */
1946 pfile->no_macro_expand++;
1949 token = cpp_get_token (pfile);
1955 /* If we've hit end of file, it's an error (reported by caller).
1956 Ditto if it's the end of cpp_expand_to_buffer text.
1957 If we've hit end of macro, just continue. */
1958 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
1969 /* if we've returned to lowest level and
1970 we aren't absorbing all args */
1971 if (paren == 0 && rest_args == 0)
1975 /* Remove ',' or ')' from argument buffer. */
1976 CPP_ADJUST_WRITTEN (pfile, -1);
1983 CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
1984 pfile->no_macro_expand--;
1989 /* Turn newlines to spaces in the string of length LENGTH at START,
1990 except inside of string constants.
1991 The string is copied into itself with its beginning staying fixed. */
1994 change_newlines (start, length)
1998 register U_CHAR *ibp;
1999 register U_CHAR *obp;
2000 register U_CHAR *limit;
2004 limit = start + length;
2007 while (ibp < limit) {
2008 *obp++ = c = *ibp++;
2013 /* Notice and skip strings, so that we don't delete newlines in them. */
2016 while (ibp < limit) {
2017 *obp++ = c = *ibp++;
2020 if (c == '\n' && quotec == '\'')
2036 if (!pfile->timebuf) {
2037 time_t t = time ((time_t *) 0);
2038 pfile->timebuf = localtime (&t);
2040 return pfile->timebuf;
2043 static char *monthnames[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2044 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2048 * expand things like __FILE__. Place the expansion into the output
2049 * buffer *without* rescanning.
2053 special_symbol (hp, pfile)
2061 cpp_buffer *ip = NULL;
2064 int paren = 0; /* For special `defined' keyword */
2067 if (pcp_outfile && pcp_inside_if
2068 && hp->type != T_SPEC_DEFINED && hp->type != T_CONST)
2070 "Predefined macro `%s' used inside `#if' during precompilation",
2074 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
2076 if (ip == CPP_NULL_BUFFER (pfile))
2078 cpp_error (pfile, "cccp error: not in any file?!");
2079 return; /* the show must go on */
2081 if (ip->fname != NULL)
2091 if (hp->type == T_BASE_FILE)
2093 while (CPP_PREV_BUFFER (ip) != CPP_NULL_BUFFER (pfile))
2094 ip = CPP_PREV_BUFFER (ip);
2096 string = ip->nominal_fname;
2100 CPP_RESERVE (pfile, 3 + 4 * strlen (string));
2101 quote_string (pfile, string);
2105 case T_INCLUDE_LEVEL:
2107 ip = CPP_BUFFER (pfile);
2108 for (; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
2109 if (ip->fname != NULL)
2112 wbuf = (char *) alloca (8); /* Eight bytes ought to be more than enough*/
2113 sprintf (wbuf, "%d", true_indepth - 1);
2118 wbuf = (char *) alloca (3 + strlen (version_string));
2119 sprintf (wbuf, "\"%s\"", version_string);
2123 #ifndef NO_BUILTIN_SIZE_TYPE
2129 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2130 case T_PTRDIFF_TYPE:
2136 buf = CPP_WCHAR_TYPE (pfile);
2139 case T_USER_LABEL_PREFIX_TYPE:
2140 buf = user_label_prefix;
2143 case T_REGISTER_PREFIX_TYPE:
2144 buf = REGISTER_PREFIX;
2148 wbuf = (char *) alloca (4 * sizeof (int));
2149 sprintf (wbuf, "%d", hp->value.ival);
2150 #ifdef STDC_0_IN_SYSTEM_HEADERS
2151 if (ip->system_header_p
2152 && hp->length == 8 && bcmp (hp->name, "__STDC__", 8) == 0
2153 && ! cpp_lookup (pfile, (U_CHAR *) "__STRICT_ANSI__", -1, -1))
2157 if (pcp_inside_if && pcp_outfile)
2158 /* Output a precondition for this macro use */
2159 fprintf (pcp_outfile, "#define %s %d\n", hp->name, hp->value.ival);
2166 long line = ip->lineno;
2167 long col = ip->colno;
2168 adjust_position (CPP_LINE_BASE (ip), ip->cur, &line, &col);
2170 wbuf = (char *) alloca (10);
2171 sprintf (wbuf, "%ld", line);
2178 wbuf = (char *) alloca (20);
2179 timebuf = timestamp (pfile);
2180 if (hp->type == T_DATE)
2181 sprintf (wbuf, "\"%s %2d %4d\"", monthnames[timebuf->tm_mon],
2182 timebuf->tm_mday, timebuf->tm_year + 1900);
2184 sprintf (wbuf, "\"%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)
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 cpp_buf_line_and_col (cpp_file_buffer (pfile), &start_line, &start_column);
2408 /* Check for and handle special symbols. */
2409 if (hp->type != T_MACRO)
2411 special_symbol (hp, pfile);
2412 xbuf_len = CPP_WRITTEN (pfile) - old_written;
2413 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2414 CPP_SET_WRITTEN (pfile, old_written);
2415 bcopy (CPP_PWRITTEN (pfile), xbuf, xbuf_len + 1);
2416 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
2420 defn = hp->value.defn;
2421 nargs = defn->nargs;
2422 pfile->output_escapes++;
2426 enum cpp_token token;
2428 args = (struct argdata *) alloca ((nargs + 1) * sizeof (struct argdata));
2430 for (i = 0; i < nargs; i++)
2432 args[i].raw = args[i].expanded = 0;
2433 args[i].raw_length = 0;
2434 args[i].expand_length = args[i].stringified_length = -1;
2435 args[i].use_count = 0;
2438 /* Parse all the macro args that are supplied. I counts them.
2439 The first NARGS args are stored in ARGS.
2440 The rest are discarded. If rest_args is set then we assume
2441 macarg absorbed the rest of the args. */
2445 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2450 if (i < nargs || (nargs == 0 && i == 0))
2452 /* if we are working on last arg which absorbs rest of args... */
2453 if (i == nargs - 1 && defn->rest_args)
2455 args[i].raw = CPP_WRITTEN (pfile);
2456 token = macarg (pfile, rest_args);
2457 args[i].raw_length = CPP_WRITTEN (pfile) - args[i].raw;
2458 args[i].newlines = 0; /* FIXME */
2461 token = macarg (pfile, 0);
2462 if (token == CPP_EOF || token == CPP_POP)
2464 cpp_error_with_line (pfile, start_line, start_column,
2465 "unterminated macro call");
2469 } while (token == CPP_COMMA);
2471 /* If we got one arg but it was just whitespace, call that 0 args. */
2474 register U_CHAR *bp = ARG_BASE + args[0].raw;
2475 register U_CHAR *lim = bp + args[0].raw_length;
2476 /* cpp.texi says for foo ( ) we provide one argument.
2477 However, if foo wants just 0 arguments, treat this as 0. */
2479 while (bp != lim && is_space[*bp]) bp++;
2484 /* Don't output an error message if we have already output one for
2485 a parse error above. */
2487 if (nargs == 0 && i > 0)
2489 cpp_error (pfile, "arguments given to macro `%s'", hp->name);
2493 /* traditional C allows foo() if foo wants one argument. */
2494 if (nargs == 1 && i == 0 && CPP_TRADITIONAL (pfile))
2496 /* the rest args token is allowed to absorb 0 tokens */
2497 else if (i == nargs - 1 && defn->rest_args)
2500 cpp_error (pfile, "macro `%s' used without args", hp->name);
2502 cpp_error (pfile, "macro `%s' used with just one arg", hp->name);
2504 cpp_error (pfile, "macro `%s' used with only %d args",
2510 "macro `%s' used with too many (%d) args", hp->name, i);
2514 /* If macro wants zero args, we parsed the arglist for checking only.
2515 Read directly from the macro definition. */
2518 xbuf = defn->expansion;
2519 xbuf_len = defn->length;
2523 register U_CHAR *exp = defn->expansion;
2524 register int offset; /* offset in expansion,
2525 copied a piece at a time */
2526 register int totlen; /* total amount of exp buffer filled so far */
2528 register struct reflist *ap, *last_ap;
2530 /* Macro really takes args. Compute the expansion of this call. */
2532 /* Compute length in characters of the macro's expansion.
2533 Also count number of times each arg is used. */
2534 xbuf_len = defn->length;
2535 for (ap = defn->pattern; ap != NULL; ap = ap->next)
2539 register struct argdata *arg = &args[ap->argno];
2540 /* Stringify if it hasn't already been */
2541 if (arg->stringified_length < 0)
2543 int arglen = arg->raw_length;
2547 /* Initially need_space is -1. Otherwise, 1 means the
2548 previous character was a space, but we suppressed it;
2549 0 means the previous character was a non-space. */
2550 int need_space = -1;
2552 arg->stringified = CPP_WRITTEN (pfile);
2553 if (!CPP_TRADITIONAL (pfile))
2554 CPP_PUTC (pfile, '\"'); /* insert beginning quote */
2555 for (; i < arglen; i++)
2557 c = (ARG_BASE + arg->raw)[i];
2561 /* Internal sequences of whitespace are replaced by
2562 one space except within an string or char token.*/
2565 if (CPP_WRITTEN (pfile) > (unsigned)arg->stringified
2566 && (CPP_PWRITTEN (pfile))[-1] == '@')
2568 /* "@ " escape markers are removed */
2569 CPP_ADJUST_WRITTEN (pfile, -1);
2572 if (need_space == 0)
2576 else if (need_space > 0)
2577 CPP_PUTC (pfile, ' ');
2592 else if (c == '\"' || c == '\'')
2596 /* Escape these chars */
2597 if (c == '\"' || (in_string && c == '\\'))
2598 CPP_PUTC (pfile, '\\');
2600 CPP_PUTC (pfile, c);
2603 CPP_RESERVE (pfile, 4);
2604 sprintf ((char *)CPP_PWRITTEN (pfile), "\\%03o",
2606 CPP_ADJUST_WRITTEN (pfile, 4);
2609 if (!CPP_TRADITIONAL (pfile))
2610 CPP_PUTC (pfile, '\"'); /* insert ending quote */
2611 arg->stringified_length
2612 = CPP_WRITTEN (pfile) - arg->stringified;
2614 xbuf_len += args[ap->argno].stringified_length;
2616 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2617 /* Add 4 for two newline-space markers to prevent
2618 token concatenation. */
2619 xbuf_len += args[ap->argno].raw_length + 4;
2622 /* We have an ordinary (expanded) occurrence of the arg.
2623 So compute its expansion, if we have not already. */
2624 if (args[ap->argno].expand_length < 0)
2626 args[ap->argno].expanded = CPP_WRITTEN (pfile);
2627 cpp_expand_to_buffer (pfile,
2628 ARG_BASE + args[ap->argno].raw,
2629 args[ap->argno].raw_length);
2631 args[ap->argno].expand_length
2632 = CPP_WRITTEN (pfile) - args[ap->argno].expanded;
2635 /* Add 4 for two newline-space markers to prevent
2636 token concatenation. */
2637 xbuf_len += args[ap->argno].expand_length + 4;
2639 if (args[ap->argno].use_count < 10)
2640 args[ap->argno].use_count++;
2643 xbuf = (U_CHAR *) xmalloc (xbuf_len + 1);
2645 /* Generate in XBUF the complete expansion
2646 with arguments substituted in.
2647 TOTLEN is the total size generated so far.
2648 OFFSET is the index in the definition
2649 of where we are copying from. */
2650 offset = totlen = 0;
2651 for (last_ap = NULL, ap = defn->pattern; ap != NULL;
2652 last_ap = ap, ap = ap->next)
2654 register struct argdata *arg = &args[ap->argno];
2655 int count_before = totlen;
2657 /* Add chars to XBUF. */
2658 for (i = 0; i < ap->nchars; i++, offset++)
2659 xbuf[totlen++] = exp[offset];
2661 /* If followed by an empty rest arg with concatenation,
2662 delete the last run of nonwhite chars. */
2663 if (rest_zero && totlen > count_before
2664 && ((ap->rest_args && ap->raw_before)
2665 || (last_ap != NULL && last_ap->rest_args
2666 && last_ap->raw_after)))
2668 /* Delete final whitespace. */
2669 while (totlen > count_before && is_space[xbuf[totlen - 1]])
2672 /* Delete the nonwhites before them. */
2673 while (totlen > count_before && ! is_space[xbuf[totlen - 1]])
2677 if (ap->stringify != 0)
2679 bcopy (ARG_BASE + arg->stringified,
2680 xbuf + totlen, arg->stringified_length);
2681 totlen += arg->stringified_length;
2683 else if (ap->raw_before || ap->raw_after || CPP_TRADITIONAL (pfile))
2685 U_CHAR *p1 = ARG_BASE + arg->raw;
2686 U_CHAR *l1 = p1 + arg->raw_length;
2689 while (p1 != l1 && is_space[*p1]) p1++;
2690 while (p1 != l1 && is_idchar[*p1])
2691 xbuf[totlen++] = *p1++;
2695 /* Arg is concatenated after: delete trailing whitespace,
2696 whitespace markers, and no-reexpansion markers. */
2699 if (is_space[l1[-1]]) l1--;
2700 else if (l1[-1] == '@')
2702 U_CHAR *p2 = l1 - 1;
2703 /* If whitespace is preceded by an odd number
2704 of `@' signs, the last `@' was a whitespace
2705 marker; drop it too. */
2706 while (p2 != p1 && p2[0] == '@') p2--;
2711 else if (l1[-1] == '-')
2713 U_CHAR *p2 = l1 - 1;
2714 /* If a `-' is preceded by an odd number of
2715 `@' signs then it and the last `@' are
2716 a no-reexpansion marker. */
2717 while (p2 != p1 && p2[0] == '@') p2--;
2727 /* Delete any no-reexpansion marker that precedes
2728 an identifier at the beginning of the argument. */
2729 if (p1[0] == '@' && p1[1] == '-')
2732 bcopy (p1, xbuf + totlen, l1 - p1);
2737 U_CHAR *expanded = ARG_BASE + arg->expanded;
2738 if (!ap->raw_before && totlen > 0 && arg->expand_length
2739 && !CPP_TRADITIONAL(pfile)
2740 && unsafe_chars (xbuf[totlen-1], expanded[0]))
2742 xbuf[totlen++] = '@';
2743 xbuf[totlen++] = ' ';
2746 bcopy (expanded, xbuf + totlen, arg->expand_length);
2747 totlen += arg->expand_length;
2749 if (!ap->raw_after && totlen > 0 && offset < defn->length
2750 && !CPP_TRADITIONAL(pfile)
2751 && unsafe_chars (xbuf[totlen-1], exp[offset]))
2753 xbuf[totlen++] = '@';
2754 xbuf[totlen++] = ' ';
2757 /* If a macro argument with newlines is used multiple times,
2758 then only expand the newlines once. This avoids creating
2759 output lines which don't correspond to any input line,
2760 which confuses gdb and gcov. */
2761 if (arg->use_count > 1 && arg->newlines > 0)
2763 /* Don't bother doing change_newlines for subsequent
2767 = change_newlines (expanded, arg->expand_length);
2771 if (totlen > xbuf_len)
2775 /* if there is anything left of the definition
2776 after handling the arg list, copy that in too. */
2778 for (i = offset; i < defn->length; i++)
2780 /* if we've reached the end of the macro */
2783 if (! (rest_zero && last_ap != NULL && last_ap->rest_args
2784 && last_ap->raw_after))
2785 xbuf[totlen++] = exp[i];
2793 pfile->output_escapes--;
2795 /* Now put the expansion on the input stack
2796 so our caller will commence reading from it. */
2797 push_macro_expansion (pfile, xbuf, xbuf_len, hp);
2798 CPP_BUFFER (pfile)->has_escapes = 1;
2800 /* Pop the space we've used in the token_buffer for argument expansion. */
2801 CPP_SET_WRITTEN (pfile, old_written);
2803 /* Recursive macro use sometimes works traditionally.
2804 #define foo(x,y) bar (x (y,0), y)
2807 if (!CPP_TRADITIONAL (pfile))
2808 hp->type = T_DISABLED;
2812 push_macro_expansion (pfile, xbuf, xbuf_len, hp)
2814 register U_CHAR *xbuf;
2818 register cpp_buffer *mbuf = cpp_push_buffer (pfile, xbuf, xbuf_len);
2821 mbuf->cleanup = macro_cleanup;
2824 /* The first chars of the expansion should be a "@ " added by
2825 collect_expansion. This is to prevent accidental token-pasting
2826 between the text preceding the macro invocation, and the macro
2829 We would like to avoid adding unneeded spaces (for the sake of
2830 tools that use cpp, such as imake). In some common cases we can
2831 tell that it is safe to omit the space.
2833 The character before the macro invocation cannot have been an
2834 idchar (or else it would have been pasted with the idchars of
2835 the macro name). Therefore, if the first non-space character
2836 of the expansion is an idchar, we do not need the extra space
2837 to prevent token pasting.
2839 Also, we don't need the extra space if the first char is '(',
2840 or some other (less common) characters. */
2842 if (xbuf[0] == '@' && xbuf[1] == ' '
2843 && (is_idchar[xbuf[2]] || xbuf[2] == '(' || xbuf[2] == '\''
2844 || xbuf[2] == '\"'))
2847 /* Likewise, avoid the extra space at the end of the macro expansion
2848 if this is safe. (We can do a better job here since we can know
2849 what the next char will be.) */
2851 && mbuf->rlimit[-2] == '@'
2852 && mbuf->rlimit[-1] == ' ')
2854 int c1 = mbuf->rlimit[-3];
2855 int c2 = CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile)));
2856 if (c2 == EOF || ! unsafe_chars (c1, c2))
2861 /* Like cpp_get_token, except that it does not read past end-of-line.
2862 Also, horizontal space is skipped, and macros are popped. */
2864 static enum cpp_token
2865 get_directive_token (pfile)
2870 long old_written = CPP_WRITTEN (pfile);
2871 enum cpp_token token;
2872 cpp_skip_hspace (pfile);
2873 if (PEEKC () == '\n')
2875 token = cpp_get_token (pfile);
2879 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
2881 /* ... else fall though ... */
2882 case CPP_HSPACE: case CPP_COMMENT:
2883 CPP_SET_WRITTEN (pfile, old_written);
2891 /* Handle #include and #import.
2892 This function expects to see "fname" or <fname> on the input.
2894 The input is normally in part of the output_buffer following
2895 CPP_WRITTEN, and will get overwritten by output_line_command.
2896 I.e. in input file specification has been popped by handle_directive.
2900 do_include (pfile, keyword)
2902 struct directive *keyword;
2904 int importing = (keyword->type == T_IMPORT);
2905 int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
2906 int angle_brackets = 0; /* 0 for "...", 1 for <...> */
2907 int before; /* included before? */
2912 enum cpp_token token;
2914 /* Chain of dirs to search */
2915 struct include_hash *ihash;
2916 struct file_name_list *search_start;
2918 long old_written = CPP_WRITTEN (pfile);
2922 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
2925 cpp_pedwarn (pfile, "ANSI C does not allow `#import'");
2927 cpp_pedwarn (pfile, "ANSI C does not allow `#include_next'");
2930 if (importing && CPP_OPTIONS (pfile)->warn_import
2931 && !CPP_OPTIONS (pfile)->inhibit_warnings
2932 && !CPP_BUFFER (pfile)->system_header_p && !pfile->import_warning)
2934 pfile->import_warning = 1;
2935 cpp_warning (pfile, "using `#import' is not recommended");
2936 cpp_notice ("The fact that a certain header file need not be processed more than once\n\
2937 should be indicated in the header file, not where it is used.\n\
2938 The best way to do this is with a conditional of this form:\n\
2940 #ifndef _FOO_H_INCLUDED\n\
2941 #define _FOO_H_INCLUDED\n\
2942 ... <real contents of file> ...\n\
2943 #endif /* Not _FOO_H_INCLUDED */\n\
2945 Then users can use `#include' any number of times.\n\
2946 GNU C automatically avoids processing the file more than once\n\
2947 when it is equipped with such a conditional.\n");
2950 pfile->parsing_include_directive++;
2951 token = get_directive_token (pfile);
2952 pfile->parsing_include_directive--;
2954 if (token == CPP_STRING)
2956 fbeg = pfile->token_buffer + old_written + 1;
2957 fend = CPP_PWRITTEN (pfile) - 1;
2959 if (fbeg[-1] == '<')
2963 else if (token == CPP_NAME)
2965 /* Support '#include xyz' like VAX-C to allow for easy use of
2966 * all the decwindow include files. It defaults to '#include
2967 * <xyz.h>' and generates a warning. */
2969 "VAX-C-style include specification found, use '#include <filename.h>' !");
2972 /* Append the missing `.h' to the name. */
2973 CPP_PUTS (pfile, ".h", 3)
2974 CPP_NUL_TERMINATE_Q (pfile);
2976 fbeg = pfile->token_buffer + old_written;
2977 fend = CPP_PWRITTEN (pfile);
2983 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
2984 CPP_SET_WRITTEN (pfile, old_written);
2985 skip_rest_of_line (pfile);
2989 token = get_directive_token (pfile);
2990 if (token != CPP_VSPACE)
2992 cpp_error (pfile, "junk at end of `#include'");
2993 skip_rest_of_line (pfile);
2996 CPP_SET_WRITTEN (pfile, old_written);
3002 cpp_error (pfile, "empty file name in `#%s'", keyword->name);
3008 for (fp = CPP_BUFFER (pfile);
3009 fp != CPP_NULL_BUFFER (pfile);
3010 fp = CPP_PREV_BUFFER (fp))
3011 if (fp->fname != NULL)
3014 if (fp == CPP_NULL_BUFFER (pfile))
3016 cpp_fatal (pfile, "cpp internal error: fp == NULL_BUFFER in do_include");
3020 /* For #include_next, skip in the search path past the dir in which the
3021 containing file was found. Treat files specified using an absolute path
3022 as if there are no more directories to search. Treat the primary source
3023 file like any other included source, but generate a warning. */
3024 if (skip_dirs && CPP_PREV_BUFFER(fp) != CPP_NULL_BUFFER (pfile))
3026 if (fp->ihash->foundhere != ABSOLUTE_PATH)
3027 search_start = fp->ihash->foundhere->next;
3032 cpp_warning (pfile, "#include_next in primary source file");
3035 search_start = CPP_OPTIONS (pfile)->bracket_include;
3038 if (!CPP_OPTIONS (pfile)->ignore_srcdir)
3041 search_start = fp->actual_dir;
3044 search_start = CPP_OPTIONS (pfile)->quote_include;
3050 cpp_error (pfile, "No include path in which to find %s", fbeg);
3054 fd = find_include_file (pfile, fbeg, search_start, &ihash, &before);
3061 if (CPP_OPTIONS (pfile)->print_deps_missing_files
3062 && CPP_PRINT_DEPS (pfile) > (angle_brackets ||
3063 (pfile->system_include_depth > 0)))
3065 if (!angle_brackets)
3066 deps_output (pfile, fbeg, ' ');
3070 struct file_name_list *ptr;
3071 /* If requested as a system header, assume it belongs in
3072 the first system header directory. */
3073 if (CPP_OPTIONS (pfile)->bracket_include)
3074 ptr = CPP_OPTIONS (pfile)->bracket_include;
3076 ptr = CPP_OPTIONS (pfile)->quote_include;
3078 p = (char *) alloca (strlen (ptr->name)
3079 + strlen (fbeg) + 2);
3080 if (*ptr->name != '\0')
3082 strcpy (p, ptr->name);
3086 deps_output (pfile, p, ' ');
3089 /* If -M was specified, and this header file won't be added to
3090 the dependency list, then don't count this as an error,
3091 because we can still produce correct output. Otherwise, we
3092 can't produce correct output, because there may be
3093 dependencies we need inside the missing file, and we don't
3094 know what directory this missing file exists in. */
3095 else if (CPP_PRINT_DEPS (pfile)
3096 && (CPP_PRINT_DEPS (pfile)
3097 <= (angle_brackets || (pfile->system_include_depth > 0))))
3098 cpp_warning (pfile, "No include path in which to find %s", fbeg);
3100 cpp_error_from_errno (pfile, fbeg);
3105 /* For -M, add the file to the dependencies on its first inclusion. */
3106 if (!before && (CPP_PRINT_DEPS (pfile)
3107 > (angle_brackets || (pfile->system_include_depth > 0))))
3108 deps_output (pfile, ihash->name, ' ');
3110 /* Handle -H option. */
3111 if (CPP_OPTIONS(pfile)->print_include_names)
3113 fp = CPP_BUFFER (pfile);
3114 while ((fp = CPP_PREV_BUFFER (fp)) != CPP_NULL_BUFFER (pfile))
3116 fprintf (stderr, " %s\n", ihash->name);
3119 /* Actually process the file */
3122 ihash->control_macro = "";
3124 if (cpp_push_buffer (pfile, NULL, 0) == NULL)
3131 pfile->system_include_depth++; /* Decremented in file_cleanup. */
3133 if (finclude (pfile, fd, ihash))
3135 output_line_command (pfile, 0, enter_file);
3136 pfile->only_seen_white = 2;
3143 /* Convert a character string literal into a nul-terminated string.
3144 The input string is [IN ... LIMIT).
3145 The result is placed in RESULT. RESULT can be the same as IN.
3146 The value returned in the end of the string written to RESULT,
3147 or NULL on error. */
3150 convert_string (pfile, result, in, limit, handle_escapes)
3152 register U_CHAR *result, *in, *limit;
3172 char *bpc = (char *) in;
3173 int i = (U_CHAR) cpp_parse_escape (pfile, &bpc, 0x00ff);
3174 in = (U_CHAR *) bpc;
3176 *result++ = (U_CHAR)c;
3179 /* else fall through */
3189 * interpret #line command. Remembers previously seen fnames
3190 * in its very own hash table.
3192 #define FNAME_HASHSIZE 37
3195 do_line (pfile, keyword)
3197 struct directive *keyword ATTRIBUTE_UNUSED;
3199 cpp_buffer *ip = CPP_BUFFER (pfile);
3201 long old_written = CPP_WRITTEN (pfile);
3202 enum file_change_code file_change = same_file;
3203 enum cpp_token token;
3205 token = get_directive_token (pfile);
3207 if (token != CPP_NUMBER
3208 || !ISDIGIT(pfile->token_buffer[old_written]))
3210 cpp_error (pfile, "invalid format `#line' command");
3211 goto bad_line_directive;
3214 /* The Newline at the end of this line remains to be processed.
3215 To put the next line at the specified line number,
3216 we must store a line number now that is one less. */
3217 new_lineno = atoi ((char *)(pfile->token_buffer + old_written)) - 1;
3218 CPP_SET_WRITTEN (pfile, old_written);
3220 /* NEW_LINENO is one less than the actual line number here. */
3221 if (CPP_PEDANTIC (pfile) && new_lineno < 0)
3222 cpp_pedwarn (pfile, "line number out of range in `#line' command");
3224 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3225 if (PEEKC() && !is_space[PEEKC()]) {
3226 cpp_error (pfile, "invalid format `#line' command");
3227 goto bad_line_directive;
3231 token = get_directive_token (pfile);
3233 if (token == CPP_STRING) {
3234 U_CHAR *fname = pfile->token_buffer + old_written;
3236 static HASHNODE *fname_table[FNAME_HASHSIZE];
3237 HASHNODE *hp, **hash_bucket;
3242 /* Turn the file name, which is a character string literal,
3243 into a null-terminated string. Do this in place. */
3244 end_name = convert_string (pfile, fname, fname, CPP_PWRITTEN (pfile), 1);
3245 if (end_name == NULL)
3247 cpp_error (pfile, "invalid format `#line' command");
3248 goto bad_line_directive;
3251 fname_length = end_name - fname;
3253 num_start = CPP_WRITTEN (pfile);
3254 token = get_directive_token (pfile);
3255 if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP) {
3256 p = pfile->token_buffer + num_start;
3257 if (CPP_PEDANTIC (pfile))
3258 cpp_pedwarn (pfile, "garbage at end of `#line' command");
3260 if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
3262 cpp_error (pfile, "invalid format `#line' command");
3263 goto bad_line_directive;
3266 file_change = enter_file;
3268 file_change = leave_file;
3270 ip->system_header_p = 1;
3271 else /* if (*p == '4') */
3272 ip->system_header_p = 2;
3274 CPP_SET_WRITTEN (pfile, num_start);
3275 token = get_directive_token (pfile);
3276 p = pfile->token_buffer + num_start;
3277 if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4')) {
3278 ip->system_header_p = *p == '3' ? 1 : 2;
3279 token = get_directive_token (pfile);
3281 if (token != CPP_VSPACE) {
3282 cpp_error (pfile, "invalid format `#line' command");
3283 goto bad_line_directive;
3287 hash_bucket = &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
3288 for (hp = *hash_bucket; hp != NULL; hp = hp->next)
3289 if (hp->length == fname_length
3290 && strncmp (hp->value.cpval, fname, fname_length) == 0) {
3291 ip->nominal_fname = hp->value.cpval;
3295 /* Didn't find it; cons up a new one. */
3296 hp = (HASHNODE *) xcalloc (1, sizeof (HASHNODE) + fname_length + 1);
3297 hp->next = *hash_bucket;
3300 hp->length = fname_length;
3301 ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
3302 bcopy (fname, hp->value.cpval, fname_length);
3305 else if (token != CPP_VSPACE && token != CPP_EOF) {
3306 cpp_error (pfile, "invalid format `#line' command");
3307 goto bad_line_directive;
3310 ip->lineno = new_lineno;
3312 skip_rest_of_line (pfile);
3313 CPP_SET_WRITTEN (pfile, old_written);
3314 output_line_command (pfile, 0, file_change);
3319 * remove the definition of a symbol from the symbol table.
3320 * according to un*x /lib/cpp, it is not an error to undef
3321 * something that has no definitions, so it isn't one here either.
3325 do_undef (pfile, keyword)
3327 struct directive *keyword;
3331 U_CHAR *buf, *name, *limit;
3333 long here = CPP_WRITTEN (pfile);
3334 enum cpp_token token;
3336 cpp_skip_hspace (pfile);
3338 if (! is_idstart[c])
3340 cpp_error (pfile, "token after #undef is not an identifier");
3341 skip_rest_of_line (pfile);
3345 parse_name (pfile, c);
3346 buf = pfile->token_buffer + here;
3347 limit = CPP_PWRITTEN(pfile);
3349 /* Copy out the token so we can pop the token buffer. */
3350 name = alloca (limit - buf + 1);
3351 bcopy(buf, name, limit - buf);
3352 name[limit - buf] = '\0';
3354 token = get_directive_token (pfile);
3355 if (token != CPP_VSPACE && token != CPP_POP)
3357 cpp_pedwarn (pfile, "junk on line after #undef");
3358 skip_rest_of_line (pfile);
3361 CPP_SET_WRITTEN (pfile, here);
3364 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3365 if (pcp_outfile && keyword)
3366 pass_thru_directive (buf, limit, pfile, keyword);
3369 sym_length = check_macro_name (pfile, buf, 0);
3371 while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
3373 /* If we are generating additional info for debugging (with -g) we
3374 need to pass through all effective #undef commands. */
3375 if (CPP_OPTIONS (pfile)->debug_output && keyword)
3376 pass_thru_directive (name, name+sym_length, pfile, keyword);
3377 if (hp->type != T_MACRO)
3378 cpp_warning (pfile, "undefining `%s'", hp->name);
3385 /* Wrap do_undef for -U processing. */
3387 cpp_undef (pfile, macro)
3391 if (cpp_push_buffer (pfile, macro, strlen(macro)))
3393 do_undef (pfile, NULL);
3394 cpp_pop_buffer (pfile);
3400 * Report an error detected by the program we are processing.
3401 * Use the text of the line in the error message.
3402 * (We use error because it prints the filename & line#.)
3406 do_error (pfile, keyword)
3408 struct directive *keyword ATTRIBUTE_UNUSED;
3410 long here = CPP_WRITTEN (pfile);
3412 copy_rest_of_line (pfile);
3413 text = pfile->token_buffer + here;
3414 SKIP_WHITE_SPACE(text);
3416 cpp_error (pfile, "#error %s", text);
3417 CPP_SET_WRITTEN (pfile, here);
3422 * Report a warning detected by the program we are processing.
3423 * Use the text of the line in the warning message, then continue.
3427 do_warning (pfile, keyword)
3429 struct directive *keyword ATTRIBUTE_UNUSED;
3432 long here = CPP_WRITTEN(pfile);
3433 copy_rest_of_line (pfile);
3434 text = pfile->token_buffer + here;
3435 SKIP_WHITE_SPACE(text);
3437 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3438 cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
3440 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
3441 if -pedantic-errors is given, #warning should cause an error. */
3442 cpp_pedwarn (pfile, "#warning %s", text);
3443 CPP_SET_WRITTEN (pfile, here);
3447 /* Report program identification. */
3450 do_ident (pfile, keyword)
3452 struct directive *keyword ATTRIBUTE_UNUSED;
3454 /* Allow #ident in system headers, since that's not user's fault. */
3455 if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
3456 cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
3458 skip_rest_of_line (pfile); /* Correct? Appears to match cccp. */
3463 /* Just check for some recognized pragmas that need validation here,
3464 and leave the text in the token buffer to be output. */
3467 do_pragma (pfile, keyword)
3469 struct directive *keyword ATTRIBUTE_UNUSED;
3471 long here = CPP_WRITTEN (pfile);
3474 copy_rest_of_line (pfile);
3475 buf = pfile->token_buffer + here;
3476 SKIP_WHITE_SPACE (buf);
3478 if (!strncmp (buf, "once", 4))
3480 cpp_buffer *ip = NULL;
3482 /* Allow #pragma once in system headers, since that's not the user's
3484 if (!CPP_BUFFER (pfile)->system_header_p)
3485 cpp_warning (pfile, "`#pragma once' is obsolete");
3487 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3489 if (ip == CPP_NULL_BUFFER (pfile))
3491 if (ip->fname != NULL)
3495 if (CPP_PREV_BUFFER (ip) == CPP_NULL_BUFFER (pfile))
3496 cpp_warning (pfile, "`#pragma once' outside include file");
3498 ip->ihash->control_macro = ""; /* never repeat */
3501 if (!strncmp (buf, "implementation", 14))
3503 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3504 been included yet. */
3505 struct include_hash *ptr;
3506 U_CHAR *p = buf + 14, *fname, *fcopy;
3507 SKIP_WHITE_SPACE (p);
3508 if (*p == '\n' || *p != '\"')
3512 p = (U_CHAR *) index (fname, '\"');
3514 fcopy = alloca (p - fname + 1);
3515 bcopy (fname, fcopy, p - fname);
3516 fcopy[p-fname] = '\0';
3518 ptr = include_hash (pfile, fcopy, 0);
3521 "`#pragma implementation' for `%s' appears after file is included",
3528 #ifdef SCCS_DIRECTIVE
3529 /* Just ignore #sccs, on systems where we define it at all. */
3532 do_sccs (pfile, keyword)
3534 struct directive *keyword ATTRIBUTE_UNUSED;
3536 if (CPP_PEDANTIC (pfile))
3537 cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
3538 skip_rest_of_line (pfile);
3544 * handle #if command by
3545 * 1) inserting special `defined' keyword into the hash table
3546 * that gets turned into 0 or 1 by special_symbol (thus,
3547 * if the luser has a symbol called `defined' already, it won't
3548 * work inside the #if command)
3549 * 2) rescan the input into a temporary output buffer
3550 * 3) pass the output buffer to the yacc parser and collect a value
3551 * 4) clean up the mess left from steps 1 and 2.
3552 * 5) call conditional_skip to skip til the next #endif (etc.),
3553 * or not, depending on the value from step 3.
3557 do_if (pfile, keyword)
3559 struct directive *keyword ATTRIBUTE_UNUSED;
3561 HOST_WIDE_INT value = eval_if_expression (pfile);
3562 conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
3567 * handle a #elif directive by not changing if_stack either.
3568 * see the comment above do_else.
3572 do_elif (pfile, keyword)
3574 struct directive *keyword ATTRIBUTE_UNUSED;
3576 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
3577 cpp_error (pfile, "`#elif' not within a conditional");
3580 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
3581 cpp_error (pfile, "`#elif' after `#else'");
3583 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
3585 if (pfile->if_stack->fname != NULL && CPP_BUFFER (pfile)->fname != NULL
3586 && strcmp (pfile->if_stack->fname,
3587 CPP_BUFFER (pfile)->nominal_fname) != 0)
3588 fprintf (stderr, ", file %s", pfile->if_stack->fname);
3589 fprintf (stderr, ")\n");
3591 pfile->if_stack->type = T_ELIF;
3594 if (pfile->if_stack->if_succeeded)
3595 skip_if_group (pfile);
3597 HOST_WIDE_INT value = eval_if_expression (pfile);
3599 skip_if_group (pfile);
3601 ++pfile->if_stack->if_succeeded; /* continue processing input */
3602 output_line_command (pfile, 1, same_file);
3609 * evaluate a #if expression in BUF, of length LENGTH,
3610 * then parse the result as a C expression and return the value as an int.
3613 static HOST_WIDE_INT
3614 eval_if_expression (pfile)
3617 HASHNODE *save_defined;
3618 HOST_WIDE_INT value;
3619 long old_written = CPP_WRITTEN (pfile);
3621 save_defined = install ((U_CHAR *)"defined", -1, T_SPEC_DEFINED, 0, 0, -1);
3622 pfile->pcp_inside_if = 1;
3624 value = cpp_parse_expr (pfile);
3625 pfile->pcp_inside_if = 0;
3626 delete_macro (save_defined); /* clean up special symbol */
3628 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
3634 * routine to handle ifdef/ifndef. Try to look up the symbol,
3635 * then do or don't skip to the #endif/#else/#elif depending
3636 * on what directive is actually being processed.
3640 do_xifdef (pfile, keyword)
3642 struct directive *keyword;
3645 cpp_buffer *ip = CPP_BUFFER (pfile);
3648 enum cpp_token token;
3649 int start_of_file = 0;
3650 U_CHAR *control_macro = 0;
3651 int old_written = CPP_WRITTEN (pfile);
3653 /* Detect a #ifndef at start of file (not counting comments). */
3654 if (ip->fname != 0 && keyword->type == T_IFNDEF)
3655 start_of_file = pfile->only_seen_white == 2;
3657 pfile->no_macro_expand++;
3658 token = get_directive_token (pfile);
3659 pfile->no_macro_expand--;
3661 ident = pfile->token_buffer + old_written;
3662 ident_length = CPP_WRITTEN (pfile) - old_written;
3663 CPP_SET_WRITTEN (pfile, old_written); /* Pop */
3665 if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
3667 skip = (keyword->type == T_IFDEF);
3668 if (! CPP_TRADITIONAL (pfile))
3669 cpp_pedwarn (pfile, "`#%s' with no argument", keyword->name);
3671 else if (token == CPP_NAME)
3673 HASHNODE *hp = cpp_lookup (pfile, ident, ident_length, -1);
3674 skip = (hp == NULL) ^ (keyword->type == T_IFNDEF);
3675 if (start_of_file && !skip)
3677 control_macro = (U_CHAR *) xmalloc (ident_length + 1);
3678 bcopy (ident, control_macro, ident_length + 1);
3683 skip = (keyword->type == T_IFDEF);
3684 if (! CPP_TRADITIONAL (pfile))
3685 cpp_error (pfile, "`#%s' with invalid argument", keyword->name);
3688 if (!CPP_TRADITIONAL (pfile))
3690 cpp_skip_hspace (pfile);
3692 if (c != EOF && c != '\n')
3693 cpp_pedwarn (pfile, "garbage at end of `#%s' argument", keyword->name);
3695 skip_rest_of_line (pfile);
3699 /* Output a precondition for this macro. */
3700 if (hp && hp->value.defn->predefined)
3701 fprintf (pcp_outfile, "#define %s\n", hp->name);
3704 fprintf (pcp_outfile, "#undef ");
3705 while (is_idchar[*cp]) /* Ick! */
3706 fputc (*cp++, pcp_outfile);
3707 putc ('\n', pcp_outfile);
3711 conditional_skip (pfile, skip, T_IF, control_macro);
3715 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
3716 If this is a #ifndef starting at the beginning of a file,
3717 CONTROL_MACRO is the macro name tested by the #ifndef.
3718 Otherwise, CONTROL_MACRO is 0. */
3721 conditional_skip (pfile, skip, type, control_macro)
3724 enum node_type type;
3725 U_CHAR *control_macro;
3727 IF_STACK_FRAME *temp;
3729 temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
3730 temp->fname = CPP_BUFFER (pfile)->nominal_fname;
3732 temp->lineno = CPP_BUFFER (pfile)->lineno;
3734 temp->next = pfile->if_stack;
3735 temp->control_macro = control_macro;
3736 pfile->if_stack = temp;
3738 pfile->if_stack->type = type;
3741 skip_if_group (pfile);
3744 ++pfile->if_stack->if_succeeded;
3745 output_line_command (pfile, 1, same_file);
3749 /* Subroutine of skip_if_group. Examine one preprocessing directive and
3750 return 0 if skipping should continue, 1 if it should halt. Also
3751 adjusts the if_stack as appropriate.
3752 The `#' has been read, but not the identifier. */
3755 consider_directive_while_skipping (pfile, stack)
3757 IF_STACK_FRAME *stack;
3759 long ident_len, ident;
3760 struct directive *kt;
3761 IF_STACK_FRAME *temp;
3763 cpp_skip_hspace (pfile);
3765 ident = CPP_WRITTEN (pfile);
3766 parse_name (pfile, GETC());
3767 ident_len = CPP_WRITTEN (pfile) - ident;
3769 CPP_SET_WRITTEN (pfile, ident);
3771 for (kt = directive_table; kt->length >= 0; kt++)
3772 if (kt->length == ident_len
3773 && strncmp (pfile->token_buffer + ident, kt->name, kt->length) == 0)
3779 temp = (IF_STACK_FRAME *) xmalloc (sizeof (IF_STACK_FRAME));
3780 temp->next = pfile->if_stack;
3781 pfile->if_stack = temp;
3782 temp->fname = CPP_BUFFER(pfile)->nominal_fname;
3783 temp->type = kt->type;
3787 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
3788 validate_else (pfile, "#else");
3791 if (pfile->if_stack->type == T_ELSE)
3792 cpp_error (pfile, "`%s' after `#else'", kt->name);
3794 if (pfile->if_stack == stack)
3798 pfile->if_stack->type = kt->type;
3803 if (CPP_PEDANTIC (pfile) && pfile->if_stack != stack)
3804 validate_else (pfile, "#endif");
3806 if (pfile->if_stack == stack)
3809 temp = pfile->if_stack;
3810 pfile->if_stack = temp->next;
3818 /* Don't let erroneous code go by. */
3819 if (!CPP_OPTIONS (pfile)->lang_asm && CPP_PEDANTIC (pfile))
3820 cpp_pedwarn (pfile, "invalid preprocessor directive name");
3824 /* skip to #endif, #else, or #elif. adjust line numbers, etc.
3825 * leaves input ptr at the sharp sign found.
3828 skip_if_group (pfile)
3832 IF_STACK_FRAME *save_if_stack = pfile->if_stack; /* don't pop past here */
3833 U_CHAR *beg_of_line;
3836 if (CPP_OPTIONS (pfile)->output_conditionals)
3838 CPP_PUTS (pfile, "#failed\n", 8);
3840 output_line_command (pfile, 1, same_file);
3843 old_written = CPP_WRITTEN (pfile);
3847 beg_of_line = CPP_BUFFER (pfile)->cur;
3849 if (! CPP_TRADITIONAL (pfile))
3850 cpp_skip_hspace (pfile);
3854 if (CPP_OPTIONS (pfile)->output_conditionals)
3855 CPP_PUTC (pfile, c);
3860 if (consider_directive_while_skipping (pfile, save_if_stack))
3864 return; /* Caller will issue error. */
3867 if (CPP_OPTIONS (pfile)->output_conditionals)
3869 CPP_PUTS (pfile, beg_of_line, CPP_BUFFER (pfile)->cur - beg_of_line);
3870 copy_rest_of_line (pfile);
3874 copy_rest_of_line (pfile);
3875 CPP_SET_WRITTEN (pfile, old_written); /* discard it */
3880 return; /* Caller will issue error. */
3884 if (CPP_OPTIONS (pfile)->output_conditionals)
3885 CPP_PUTC (pfile, c);
3889 /* Back up to the beginning of this line. Caller will process the
3891 CPP_BUFFER (pfile)->cur = beg_of_line;
3892 pfile->only_seen_white = 1;
3893 if (CPP_OPTIONS (pfile)->output_conditionals)
3895 CPP_PUTS (pfile, "#endfailed\n", 11);
3901 * handle a #else directive. Do this by just continuing processing
3902 * without changing if_stack ; this is so that the error message
3903 * for missing #endif's etc. will point to the original #if. It
3904 * is possible that something different would be better.
3908 do_else (pfile, keyword)
3910 struct directive *keyword ATTRIBUTE_UNUSED;
3912 cpp_buffer *ip = CPP_BUFFER (pfile);
3914 if (CPP_PEDANTIC (pfile))
3915 validate_else (pfile, "#else");
3916 skip_rest_of_line (pfile);
3918 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
3919 cpp_error (pfile, "`#else' not within a conditional");
3922 /* #ifndef can't have its special treatment for containing the whole file
3923 if it has a #else clause. */
3924 pfile->if_stack->control_macro = 0;
3926 if (pfile->if_stack->type != T_IF && pfile->if_stack->type != T_ELIF) {
3927 cpp_error (pfile, "`#else' after `#else'");
3928 fprintf (stderr, " (matches line %d", pfile->if_stack->lineno);
3929 if (strcmp (pfile->if_stack->fname, ip->nominal_fname) != 0)
3930 fprintf (stderr, ", file %s", pfile->if_stack->fname);
3931 fprintf (stderr, ")\n");
3933 pfile->if_stack->type = T_ELSE;
3936 if (pfile->if_stack->if_succeeded)
3937 skip_if_group (pfile);
3939 ++pfile->if_stack->if_succeeded; /* continue processing input */
3940 output_line_command (pfile, 1, same_file);
3946 * unstack after #endif command
3950 do_endif (pfile, keyword)
3952 struct directive *keyword ATTRIBUTE_UNUSED;
3954 if (CPP_PEDANTIC (pfile))
3955 validate_else (pfile, "#endif");
3956 skip_rest_of_line (pfile);
3958 if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
3959 cpp_error (pfile, "unbalanced `#endif'");
3962 IF_STACK_FRAME *temp = pfile->if_stack;
3963 pfile->if_stack = temp->next;
3964 if (temp->control_macro != 0)
3966 /* This #endif matched a #ifndef at the start of the file.
3967 See if it is at the end of the file. */
3968 struct parse_marker start_mark;
3971 parse_set_mark (&start_mark, pfile);
3975 cpp_skip_hspace (pfile);
3980 parse_goto_mark (&start_mark, pfile);
3981 parse_clear_mark (&start_mark);
3985 /* This #endif ends a #ifndef
3986 that contains all of the file (aside from whitespace).
3987 Arrange not to include the file again
3988 if the macro that was tested is defined. */
3989 struct cpp_buffer *ip;
3990 for (ip = CPP_BUFFER (pfile); ; ip = CPP_PREV_BUFFER (ip))
3991 if (ip->fname != NULL)
3993 ip->ihash->control_macro = temp->control_macro;
3997 output_line_command (pfile, 1, same_file);
4002 /* When an #else or #endif is found while skipping failed conditional,
4003 if -pedantic was specified, this is called to warn about text after
4004 the command name. P points to the first char after the command name. */
4007 validate_else (pfile, directive)
4012 cpp_skip_hspace (pfile);
4014 if (c != EOF && c != '\n')
4016 "text following `%s' violates ANSI standard", directive);
4019 /* Get the next token, and add it to the text in pfile->token_buffer.
4020 Return the kind of token we got. */
4023 cpp_get_token (pfile)
4026 register int c, c2, c3;
4028 long start_line, start_column;
4029 enum cpp_token token;
4030 struct cpp_options *opts = CPP_OPTIONS (pfile);
4031 CPP_BUFFER (pfile)->prev = CPP_BUFFER (pfile)->cur;
4037 if (CPP_BUFFER (pfile)->seen_eof)
4039 if (cpp_pop_buffer (pfile) != CPP_NULL_BUFFER (pfile))
4046 cpp_buffer *next_buf
4047 = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
4048 CPP_BUFFER (pfile)->seen_eof = 1;
4049 if (CPP_BUFFER (pfile)->nominal_fname
4050 && next_buf != CPP_NULL_BUFFER (pfile))
4052 /* We're about to return from an #include file.
4053 Emit #line information now (as part of the CPP_POP) result.
4054 But the #line refers to the file we will pop to. */
4055 cpp_buffer *cur_buffer = CPP_BUFFER (pfile);
4056 CPP_BUFFER (pfile) = next_buf;
4057 pfile->input_stack_listing_current = 0;
4058 output_line_command (pfile, 0, leave_file);
4059 CPP_BUFFER (pfile) = cur_buffer;
4069 struct parse_marker start_mark;
4071 if (PEEKC () == '=')
4073 if (opts->put_out_comments)
4074 parse_set_mark (&start_mark, pfile);
4076 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4077 &start_line, &start_column);
4078 c = skip_comment (pfile, &newlines);
4079 if (opts->put_out_comments && (c == '/' || c == EOF))
4080 parse_clear_mark (&start_mark);
4085 cpp_error_with_line (pfile, start_line, start_column,
4086 "unterminated comment");
4089 c = '/'; /* Initial letter of comment. */
4091 /* Comments are equivalent to spaces.
4092 For -traditional, a comment is equivalent to nothing. */
4093 if (opts->put_out_comments)
4095 cpp_buffer *pbuf = CPP_BUFFER (pfile);
4096 U_CHAR *start = pbuf->buf + start_mark.position;
4097 int len = pbuf->cur - start;
4098 CPP_RESERVE(pfile, 1 + len);
4099 CPP_PUTC_Q (pfile, c);
4100 CPP_PUTS_Q (pfile, start, len);
4101 pfile->lineno += newlines;
4102 parse_clear_mark (&start_mark);
4105 else if (CPP_TRADITIONAL (pfile))
4112 /* This may not work if cpp_get_token is called recursively,
4113 since many places look for horizontal space. */
4116 /* Copy the newlines into the output buffer, in order to
4117 avoid the pain of a #line every time a multiline comment
4119 CPP_RESERVE(pfile, newlines);
4120 while (--newlines >= 0)
4122 CPP_PUTC_Q (pfile, '\n');
4128 CPP_RESERVE(pfile, 1);
4129 CPP_PUTC_Q (pfile, ' ');
4133 if (opts->for_lint) {
4136 char *lintcmd = get_lintcmd (ibp, limit, &argbp, &arglen, &cmdlen);
4138 if (lintcmd != NULL) {
4139 /* I believe it is always safe to emit this newline: */
4141 bcopy ("#pragma lint ", (char *) obp, 13);
4143 bcopy (lintcmd, (char *) obp, cmdlen);
4148 bcopy (argbp, (char *) obp, arglen);
4152 /* OK, now bring us back to the state we were in before we entered
4153 this branch. We need #line because the newline for the pragma
4154 could mess things up. */
4155 output_line_command (pfile, 0, same_file);
4156 *(obp++) = ' '; /* just in case, if comments are copied thru */
4164 /* If this is expanding a macro definition, don't recognize
4165 preprocessor directives. */
4168 /* If this is expand_into_temp_buffer, recognize them
4169 only after an actual newline at this level,
4170 not at the beginning of the input level. */
4171 if (ip->fname == 0 && beg_of_line == ip->buf)
4177 if (!pfile->only_seen_white)
4179 if (handle_directive (pfile))
4180 return CPP_DIRECTIVE;
4181 pfile->only_seen_white = 0;
4187 /* A single quoted string is treated like a double -- some
4188 programs (e.g., troff) are perverse this way */
4189 cpp_buf_line_and_col (cpp_file_buffer (pfile),
4190 &start_line, &start_column);
4191 old_written = CPP_WRITTEN (pfile);
4192 CPP_PUTC (pfile, c);
4198 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4200 /* try harder: this string crosses a macro expansion
4201 boundary. This can happen naturally if -traditional.
4202 Otherwise, only -D can make a macro with an unmatched
4204 cpp_pop_buffer (pfile);
4207 if (!CPP_TRADITIONAL (pfile))
4209 cpp_error_with_line (pfile, start_line, start_column,
4210 "unterminated string or character constant");
4211 if (pfile->multiline_string_line != start_line
4212 && pfile->multiline_string_line != 0)
4213 cpp_error_with_line (pfile,
4214 pfile->multiline_string_line, -1,
4215 "possible real start of unterminated constant");
4216 pfile->multiline_string_line = 0;
4220 CPP_PUTC (pfile, cc);
4224 /* Traditionally, end of line ends a string constant with
4225 no error. So exit the loop and record the new line. */
4226 if (CPP_TRADITIONAL (pfile))
4230 cpp_error_with_line (pfile, start_line, start_column,
4231 "unterminated character constant");
4234 if (CPP_PEDANTIC (pfile)
4235 && pfile->multiline_string_line == 0)
4237 cpp_pedwarn_with_line (pfile, start_line, start_column,
4238 "string constant runs past end of line");
4240 if (pfile->multiline_string_line == 0)
4241 pfile->multiline_string_line = start_line;
4248 /* Backslash newline is replaced by nothing at all. */
4249 CPP_ADJUST_WRITTEN (pfile, -1);
4254 /* ANSI stupidly requires that in \\ the second \
4255 is *not* prevented from combining with a newline. */
4258 CPP_PUTC (pfile, cc);
4270 pfile->lineno += count_newlines (pfile->token_buffer + old_written,
4271 CPP_PWRITTEN (pfile));
4272 pfile->only_seen_white = 0;
4273 return c == '\'' ? CPP_CHAR : CPP_STRING;
4276 if (!opts->dollars_in_ident)
4281 if (opts->cplusplus && PEEKC () == ':')
4290 if (c2 == c || c2 == '=')
4300 if (PEEKC () == '=')
4307 if (c2 == '-' && opts->chill)
4309 /* Chill style comment */
4310 if (opts->put_out_comments)
4311 parse_set_mark (&start_mark, pfile);
4312 FORWARD(1); /* Skip second '-'. */
4320 /* Don't consider final '\n' to be part of comment. */
4326 goto return_comment;
4328 if (c2 == '-' || c2 == '=' || c2 == '>')
4333 if (pfile->parsing_include_directive)
4337 CPP_PUTC (pfile, c);
4342 if (c == '\n' || c == EOF)
4345 "missing '>' in `#include <FILENAME>'");
4351 /* else fall through */
4360 CPP_RESERVE (pfile, 4);
4361 CPP_PUTC (pfile, c);
4362 CPP_PUTC (pfile, c2);
4366 CPP_PUTC_Q (pfile, GETC ());
4367 CPP_NUL_TERMINATE_Q (pfile);
4368 pfile->only_seen_white = 0;
4372 if (CPP_BUFFER (pfile)->has_escapes)
4377 if (pfile->output_escapes)
4378 CPP_PUTS (pfile, "@-", 2);
4379 parse_name (pfile, GETC ());
4382 else if (is_space [c])
4384 CPP_RESERVE (pfile, 2);
4385 if (pfile->output_escapes)
4386 CPP_PUTC_Q (pfile, '@');
4387 CPP_PUTC_Q (pfile, c);
4391 if (pfile->output_escapes)
4393 CPP_PUTS (pfile, "@@", 2);
4403 CPP_RESERVE(pfile, 2);
4404 CPP_PUTC_Q (pfile, '.');
4408 /* FIXME - misses the case "..\\\n." */
4409 if (c2 == '.' && PEEKN(1) == '.')
4411 CPP_RESERVE(pfile, 4);
4412 CPP_PUTC_Q (pfile, '.');
4413 CPP_PUTC_Q (pfile, '.');
4414 CPP_PUTC_Q (pfile, '.');
4416 CPP_NUL_TERMINATE_Q (pfile);
4417 pfile->only_seen_white = 0;
4424 pfile->only_seen_white = 0;
4426 CPP_RESERVE(pfile, 3);
4427 CPP_PUTC_Q (pfile, c);
4428 CPP_PUTC_Q (pfile, GETC ());
4429 CPP_NUL_TERMINATE_Q (pfile);
4435 if ((c2 == '\'' || c2 == '\"') && !CPP_TRADITIONAL (pfile))
4437 CPP_PUTC (pfile, c);
4443 case '0': case '1': case '2': case '3': case '4':
4444 case '5': case '6': case '7': case '8': case '9':
4449 CPP_RESERVE (pfile, 2);
4450 CPP_PUTC_Q (pfile, c);
4455 if (!is_idchar[c] && c != '.'
4456 && ((c2 != 'e' && c2 != 'E'
4457 && ((c2 != 'p' && c2 != 'P') || CPP_C89 (pfile)))
4458 || (c != '+' && c != '-')))
4463 CPP_NUL_TERMINATE_Q (pfile);
4464 pfile->only_seen_white = 0;
4466 case 'b': case 'c': case 'd': case 'h': case 'o':
4467 case 'B': case 'C': case 'D': case 'H': case 'O':
4468 if (opts->chill && PEEKC () == '\'')
4470 pfile->only_seen_white = 0;
4471 CPP_RESERVE (pfile, 2);
4472 CPP_PUTC_Q (pfile, c);
4473 CPP_PUTC_Q (pfile, '\'');
4479 goto chill_number_eof;
4482 if (c == '\\' && PEEKC() == '\n')
4489 CPP_PUTC (pfile, c);
4493 CPP_RESERVE (pfile, 2);
4494 CPP_PUTC_Q (pfile, c);
4495 CPP_NUL_TERMINATE_Q (pfile);
4502 CPP_NUL_TERMINATE (pfile);
4509 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
4510 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
4511 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
4512 case 'x': case 'y': case 'z':
4513 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
4514 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
4515 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
4520 unsigned char *ident;
4521 int before_name_written = CPP_WRITTEN (pfile);
4523 parse_name (pfile, c);
4524 pfile->only_seen_white = 0;
4525 if (pfile->no_macro_expand)
4527 ident = pfile->token_buffer + before_name_written;
4528 ident_len = CPP_PWRITTEN (pfile) - ident;
4529 hp = cpp_lookup (pfile, ident, ident_len, -1);
4532 if (hp->type == T_DISABLED)
4534 if (pfile->output_escapes)
4535 { /* Return "@-IDENT", followed by '\0'. */
4537 CPP_RESERVE (pfile, 3);
4538 ident = pfile->token_buffer + before_name_written;
4539 CPP_ADJUST_WRITTEN (pfile, 2);
4540 for (i = ident_len; i >= 0; i--) ident[i+2] = ident[i];
4547 /* If macro wants an arglist, verify that a '(' follows.
4548 first skip all whitespace, copying it to the output
4549 after the macro name. Then, if there is no '(',
4550 decide this is not a macro call and leave things that way. */
4551 if (hp->type == T_MACRO && hp->value.defn->nargs >= 0)
4553 struct parse_marker macro_mark;
4554 int is_macro_call, macbuf_whitespace = 0;
4556 parse_set_mark (¯o_mark, pfile);
4559 cpp_skip_hspace (pfile);
4561 is_macro_call = c == '(';
4570 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile)))
4572 if (macro_mark.position !=
4573 (CPP_BUFFER (pfile)->cur
4574 - CPP_BUFFER (pfile)->buf))
4575 macbuf_whitespace = 1;
4577 parse_clear_mark (¯o_mark);
4578 cpp_pop_buffer (pfile);
4579 parse_set_mark (¯o_mark, pfile);
4587 parse_goto_mark (¯o_mark, pfile);
4588 if (macbuf_whitespace)
4589 CPP_PUTC (pfile, ' ');
4591 parse_clear_mark (¯o_mark);
4595 /* This is now known to be a macro call.
4596 Expand the macro, reading arguments as needed,
4597 and push the expansion on the input stack. */
4598 macroexpand (pfile, hp);
4599 CPP_SET_WRITTEN (pfile, before_name_written);
4603 case ' ': case '\t': case '\v': case '\r':
4606 CPP_PUTC (pfile, c);
4608 if (c == EOF || !is_hor_space[c])
4622 CPP_PUTC (pfile, c);
4623 if (pfile->only_seen_white == 0)
4624 pfile->only_seen_white = 1;
4626 output_line_command (pfile, 1, same_file);
4629 case '(': token = CPP_LPAREN; goto char1;
4630 case ')': token = CPP_RPAREN; goto char1;
4631 case '{': token = CPP_LBRACE; goto char1;
4632 case '}': token = CPP_RBRACE; goto char1;
4633 case ',': token = CPP_COMMA; goto char1;
4634 case ';': token = CPP_SEMICOLON; goto char1;
4640 pfile->only_seen_white = 0;
4641 CPP_PUTC (pfile, c);
4647 /* Like cpp_get_token, but skip spaces and comments. */
4650 cpp_get_non_space_token (pfile)
4653 int old_written = CPP_WRITTEN (pfile);
4656 enum cpp_token token = cpp_get_token (pfile);
4657 if (token != CPP_COMMENT && token != CPP_POP
4658 && token != CPP_HSPACE && token != CPP_VSPACE)
4660 CPP_SET_WRITTEN (pfile, old_written);
4664 /* Parse an identifier starting with C. */
4667 parse_name (pfile, c)
4668 cpp_reader *pfile; int c;
4674 if (c == '\\' && PEEKC() == '\n')
4683 if (c == '$' && CPP_PEDANTIC (pfile))
4684 cpp_pedwarn (pfile, "`$' in identifier");
4686 CPP_RESERVE(pfile, 2); /* One more for final NUL. */
4687 CPP_PUTC_Q (pfile, c);
4692 CPP_NUL_TERMINATE_Q (pfile);
4696 /* This is called after options have been processed.
4697 * Check options for consistency, and setup for processing input
4698 * from the file named FNAME. (Use standard input if FNAME==NULL.)
4699 * Return 1 on success, 0 on failure.
4703 cpp_start_read (pfile, fname)
4707 struct cpp_options *opts = CPP_OPTIONS (pfile);
4708 struct cpp_pending *pend;
4712 struct include_hash *ih_fake;
4714 /* The code looks at the defaults through this pointer, rather than through
4715 the constant structure above. This pointer gets changed if an environment
4716 variable specifies other defaults. */
4717 struct default_include *include_defaults = include_defaults_array;
4719 /* Now that we know dollars_in_ident for real,
4720 reset is_idchar/is_idstart. */
4721 is_idchar['$'] = opts->dollars_in_ident;
4722 is_idstart['$'] = opts->dollars_in_ident;
4724 /* Add dirs from CPATH after dirs from -I. */
4725 /* There seems to be confusion about what CPATH should do,
4726 so for the moment it is not documented. */
4727 /* Some people say that CPATH should replace the standard include dirs,
4728 but that seems pointless: it comes before them, so it overrides them
4730 GET_ENV_PATH_LIST (p, "CPATH");
4731 if (p != 0 && ! opts->no_standard_includes)
4732 path_include (pfile, p);
4734 /* Do partial setup of input buffer for the sake of generating
4735 early #line directives (when -g is in effect). */
4736 fp = cpp_push_buffer (pfile, NULL, 0);
4739 if (opts->in_fname == NULL || *opts->in_fname == 0)
4741 opts->in_fname = fname;
4742 if (opts->in_fname == NULL)
4743 opts->in_fname = "";
4745 fp->nominal_fname = fp->fname = opts->in_fname;
4748 /* Install __LINE__, etc. Must follow initialize_char_syntax
4749 and option processing. */
4750 initialize_builtins (pfile);
4752 /* Do standard #defines and assertions
4753 that identify system and machine type. */
4755 if (!opts->inhibit_predefs) {
4756 char *p = (char *) alloca (strlen (predefs) + 1);
4757 strcpy (p, predefs);
4760 while (*p == ' ' || *p == '\t')
4762 /* Handle -D options. */
4763 if (p[0] == '-' && p[1] == 'D') {
4765 while (*p && *p != ' ' && *p != '\t')
4769 if (opts->debug_output)
4770 output_line_command (pfile, 0, same_file);
4771 cpp_define (pfile, q);
4772 while (*p == ' ' || *p == '\t')
4774 } else if (p[0] == '-' && p[1] == 'A') {
4775 /* Handle -A options (assertions). */
4784 past_name = assertion;
4785 /* Locate end of name. */
4786 while (*past_name && *past_name != ' '
4787 && *past_name != '\t' && *past_name != '(')
4789 /* Locate `(' at start of value. */
4791 while (*value && (*value == ' ' || *value == '\t'))
4793 if (*value++ != '(')
4795 while (*value && (*value == ' ' || *value == '\t'))
4798 /* Locate end of value. */
4799 while (*past_value && *past_value != ' '
4800 && *past_value != '\t' && *past_value != ')')
4802 termination = past_value;
4803 while (*termination && (*termination == ' ' || *termination == '\t'))
4805 if (*termination++ != ')')
4807 if (*termination && *termination != ' ' && *termination != '\t')
4809 /* Temporarily null-terminate the value. */
4810 save_char = *termination;
4811 *termination = '\0';
4812 /* Install the assertion. */
4813 make_assertion (pfile, "-A", assertion);
4814 *termination = (char) save_char;
4816 while (*p == ' ' || *p == '\t')
4824 /* Now handle the command line options. */
4826 /* Do -U's, -D's and -A's in the order they were seen. */
4827 /* First reverse the list. */
4828 opts->pending = nreverse_pending (opts->pending);
4830 for (pend = opts->pending; pend; pend = pend->next)
4832 if (pend->cmd != NULL && pend->cmd[0] == '-')
4834 switch (pend->cmd[1])
4837 if (opts->debug_output)
4838 output_line_command (pfile, 0, same_file);
4839 cpp_undef (pfile, pend->arg);
4842 if (opts->debug_output)
4843 output_line_command (pfile, 0, same_file);
4844 cpp_define (pfile, pend->arg);
4847 make_assertion (pfile, "-A", pend->arg);
4853 opts->done_initializing = 1;
4855 { /* Read the appropriate environment variable and if it exists
4856 replace include_defaults with the listed path. */
4858 switch ((opts->objc << 1) + opts->cplusplus)
4861 GET_ENV_PATH_LIST (epath, "C_INCLUDE_PATH");
4864 GET_ENV_PATH_LIST (epath, "CPLUS_INCLUDE_PATH");
4867 GET_ENV_PATH_LIST (epath, "OBJC_INCLUDE_PATH");
4870 GET_ENV_PATH_LIST (epath, "OBJCPLUS_INCLUDE_PATH");
4873 /* If the environment var for this language is set,
4874 add to the default list of include directories. */
4876 char *nstore = (char *) alloca (strlen (epath) + 2);
4878 char *startp, *endp;
4880 for (num_dirs = 1, startp = epath; *startp; startp++)
4881 if (*startp == PATH_SEPARATOR)
4884 = (struct default_include *) xmalloc ((num_dirs
4885 * sizeof (struct default_include))
4886 + sizeof (include_defaults_array));
4887 startp = endp = epath;
4890 /* Handle cases like c:/usr/lib:d:/gcc/lib */
4891 if ((*endp == PATH_SEPARATOR)
4893 strncpy (nstore, startp, endp-startp);
4895 strcpy (nstore, ".");
4897 nstore[endp-startp] = '\0';
4899 include_defaults[num_dirs].fname = xstrdup (nstore);
4900 include_defaults[num_dirs].component = 0;
4901 include_defaults[num_dirs].cplusplus = opts->cplusplus;
4902 include_defaults[num_dirs].cxx_aware = 1;
4906 endp = startp = endp + 1;
4910 /* Put the usual defaults back in at the end. */
4911 bcopy ((char *) include_defaults_array,
4912 (char *) &include_defaults[num_dirs],
4913 sizeof (include_defaults_array));
4917 /* Unless -fnostdinc,
4918 tack on the standard include file dirs to the specified list */
4919 if (!opts->no_standard_includes) {
4920 struct default_include *p = include_defaults;
4921 char *specd_prefix = opts->include_prefix;
4922 char *default_prefix = xstrdup (GCC_INCLUDE_DIR);
4923 int default_len = 0;
4924 /* Remove the `include' from /usr/local/lib/gcc.../include. */
4925 if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
4926 default_len = strlen (default_prefix) - 7;
4927 default_prefix[default_len] = 0;
4929 /* Search "translated" versions of GNU directories.
4930 These have /usr/local/lib/gcc... replaced by specd_prefix. */
4931 if (specd_prefix != 0 && default_len != 0)
4932 for (p = include_defaults; p->fname; p++) {
4933 /* Some standard dirs are only for C++. */
4935 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
4936 /* Does this dir start with the prefix? */
4937 if (!strncmp (p->fname, default_prefix, default_len)) {
4938 /* Yes; change prefix and add to search list. */
4939 int this_len = strlen (specd_prefix)
4940 + strlen (p->fname) - default_len;
4941 char *str = (char *) xmalloc (this_len + 1);
4942 strcpy (str, specd_prefix);
4943 strcat (str, p->fname + default_len);
4945 append_include_chain (pfile, &opts->system_include,
4946 str, !p->cxx_aware);
4950 /* Search ordinary names for GNU include directories. */
4951 for (p = include_defaults; p->fname; p++) {
4952 /* Some standard dirs are only for C++. */
4954 || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
4955 const char *str = update_path (p->fname, p->component);
4956 append_include_chain (pfile, &opts->system_include,
4957 str, !p->cxx_aware);
4962 merge_include_chains (opts);
4964 /* With -v, print the list of dirs to search. */
4965 if (opts->verbose) {
4966 struct file_name_list *p;
4967 cpp_notice ("#include \"...\" search starts here:\n");
4968 for (p = opts->quote_include; p; p = p->next) {
4969 if (p == opts->bracket_include)
4970 cpp_notice ("#include <...> search starts here:\n");
4971 fprintf (stderr, " %s\n", p->name);
4973 cpp_notice ("End of search list.\n");
4976 /* Copy the entire contents of the main input file into
4977 the stacked input buffer previously allocated for it. */
4978 if (fname == NULL || *fname == 0) {
4981 } else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
4982 cpp_pfatal_with_name (pfile, fname);
4984 /* -MG doesn't select the form of output and must be specified with one of
4985 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
4986 inhibit compilation. */
4987 if (opts->print_deps_missing_files
4988 && (opts->print_deps == 0 || !opts->no_output))
4990 cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
4994 /* Either of two environment variables can specify output of deps.
4995 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
4996 where OUTPUT_FILE is the file to write deps info to
4997 and DEPS_TARGET is the target to mention in the deps. */
4999 if (opts->print_deps == 0
5000 && (getenv ("SUNPRO_DEPENDENCIES") != 0
5001 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
5002 char *spec = getenv ("DEPENDENCIES_OUTPUT");
5008 spec = getenv ("SUNPRO_DEPENDENCIES");
5009 opts->print_deps = 2;
5012 opts->print_deps = 1;
5015 /* Find the space before the DEPS_TARGET, if there is one. */
5016 /* This should use index. (mrs) */
5017 while (*s != 0 && *s != ' ') s++;
5020 opts->deps_target = s + 1;
5021 output_file = (char *) xmalloc (s - spec + 1);
5022 bcopy (spec, output_file, s - spec);
5023 output_file[s - spec] = 0;
5027 opts->deps_target = 0;
5031 opts->deps_file = output_file;
5032 opts->print_deps_append = 1;
5035 /* For -M, print the expected object file name
5036 as the target of this Make-rule. */
5037 if (opts->print_deps)
5039 pfile->deps_allocated_size = 200;
5040 pfile->deps_buffer = (char *) xmalloc (pfile->deps_allocated_size);
5041 pfile->deps_buffer[0] = 0;
5042 pfile->deps_size = 0;
5043 pfile->deps_column = 0;
5045 if (opts->deps_target)
5046 deps_output (pfile, opts->deps_target, ':');
5047 else if (*opts->in_fname == 0)
5048 deps_output (pfile, "-", ':');
5053 static char *known_suffixes[] = { ".c", ".C", ".s", ".S", ".m",
5054 ".cc", ".cxx", ".cpp", ".cp",
5058 /* Discard all directory prefixes from filename. */
5059 if ((q = rindex (opts->in_fname, '/')) != NULL
5060 #ifdef DIR_SEPARATOR
5061 && (q = rindex (opts->in_fname, DIR_SEPARATOR)) != NULL
5068 /* Copy remainder to mungable area. */
5069 p = (char *) alloca (strlen(q) + 8);
5072 /* Output P, but remove known suffixes. */
5075 /* Point to the filename suffix. */
5076 r = rindex (p, '.');
5077 /* Compare against the known suffixes. */
5079 while (known_suffixes[x] != 0)
5081 if (strncmp (known_suffixes[x], r, q - r) == 0)
5083 /* Make q point to the bit we're going to overwrite
5084 with an object suffix. */
5091 /* Supply our own suffix. */
5098 deps_output (pfile, p, ':');
5099 deps_output (pfile, opts->in_fname, ' ');
5103 /* Must call finclude() on the main input before processing
5104 -include switches; otherwise the -included text winds up
5105 after the main input. */
5106 ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
5108 ih_fake->next_this_file = 0;
5109 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5110 ih_fake->name = fname;
5111 ih_fake->control_macro = 0;
5112 ih_fake->buf = (char *)-1;
5114 if (!finclude (pfile, f, ih_fake))
5116 output_line_command (pfile, 0, same_file);
5117 pfile->only_seen_white = 2;
5119 /* The -imacros files can be scanned now, but the -include files
5120 have to be pushed onto the include stack and processed later,
5121 in the main loop calling cpp_get_token. That means the -include
5122 files have to be processed in reverse order of the pending list,
5123 which means the pending list has to be reversed again, which
5124 means the -imacros files have to be done separately and first. */
5126 pfile->no_record_file++;
5128 for (pend = opts->pending; pend; pend = pend->next)
5130 if (pend->cmd != NULL)
5132 if (strcmp (pend->cmd, "-imacros") == 0)
5134 int fd = open (pend->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
5137 cpp_perror_with_name (pfile, pend->arg);
5140 if (!cpp_push_buffer (pfile, NULL, 0))
5143 ih_fake = (struct include_hash *)
5144 xmalloc (sizeof (struct include_hash));
5146 ih_fake->next_this_file = 0;
5147 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5148 ih_fake->name = pend->arg;
5149 ih_fake->control_macro = 0;
5150 ih_fake->buf = (char *)-1;
5152 if (!finclude (pfile, fd, ih_fake))
5153 cpp_scan_buffer (pfile);
5159 opts->pending = nreverse_pending (opts->pending);
5160 for (pend = opts->pending; pend; pend = pend->next)
5162 if (pend->cmd != NULL)
5164 if (strcmp (pend->cmd, "-include") == 0)
5166 int fd = open (pend->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666);
5169 cpp_perror_with_name (pfile, pend->arg);
5172 if (!cpp_push_buffer (pfile, NULL, 0))
5175 ih_fake = (struct include_hash *)
5176 xmalloc (sizeof (struct include_hash));
5178 ih_fake->next_this_file = 0;
5179 ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
5180 ih_fake->name = pend->arg;
5181 ih_fake->control_macro = 0;
5182 ih_fake->buf = (char *)-1;
5184 if (finclude (pfile, fd, ih_fake))
5185 output_line_command (pfile, 0, enter_file);
5189 pfile->no_record_file--;
5191 /* Free the pending list. */
5192 for (pend = opts->pending; pend; )
5194 struct cpp_pending *next = pend->next;
5198 opts->pending = NULL;
5204 cpp_reader_init (pfile)
5207 bzero ((char *) pfile, sizeof (cpp_reader));
5208 pfile->get_token = cpp_get_token;
5210 pfile->token_buffer_size = 200;
5211 pfile->token_buffer = (U_CHAR *) xmalloc (pfile->token_buffer_size);
5212 CPP_SET_WRITTEN (pfile, 0);
5214 pfile->timebuf = NULL;
5215 pfile->only_seen_white = 1;
5216 pfile->buffer = CPP_NULL_BUFFER(pfile);
5217 pfile->actual_dirs = NULL;
5220 static struct cpp_pending *
5221 nreverse_pending (list)
5222 struct cpp_pending *list;
5225 register struct cpp_pending *prev = 0, *next, *pend;
5226 for (pend = list; pend; pend = next)
5236 push_pending (pfile, cmd, arg)
5241 struct cpp_pending *pend
5242 = (struct cpp_pending *) xmalloc (sizeof (struct cpp_pending));
5245 pend->next = CPP_OPTIONS (pfile)->pending;
5246 CPP_OPTIONS (pfile)->pending = pend;
5253 printf ("Usage: %s [switches] input output\n", progname);
5254 printf ("Switches:\n");
5255 printf (" -include <file> Include the contents of <file> before other files\n");
5256 printf (" -imacros <file> Accept definition of marcos in <file>\n");
5257 printf (" -iprefix <path> Specify <path> as a prefix for next two options\n");
5258 printf (" -iwithprefix <dir> Add <dir> to the end of the system include paths\n");
5259 printf (" -iwithprefixbefore <dir> Add <dir> to the end of the main include paths\n");
5260 printf (" -isystem <dir> Add <dir> to the start of the system include paths\n");
5261 printf (" -idirafter <dir> Add <dir> to the end of the system include paths\n");
5262 printf (" -I <dir> Add <dir> to the end of the main include paths\n");
5263 printf (" -nostdinc Do not search the system include directories\n");
5264 printf (" -nostdinc++ Do not search the system include directories for C++\n");
5265 printf (" -o <file> Put output into <file>\n");
5266 printf (" -pedantic Issue all warnings demanded by strict ANSI C\n");
5267 printf (" -traditional Follow K&R pre-processor behaviour\n");
5268 printf (" -trigraphs Support ANSI C trigraphs\n");
5269 printf (" -lang-c Assume that the input sources are in C\n");
5270 printf (" -lang-c89 Assume that the input sources are in C89\n");
5271 printf (" -lang-c++ Assume that the input sources are in C++\n");
5272 printf (" -lang-objc Assume that the input sources are in ObjectiveC\n");
5273 printf (" -lang-objc++ Assume that the input sources are in ObjectiveC++\n");
5274 printf (" -lang-asm Assume that the input sources are in assembler\n");
5275 printf (" -lang-chill Assume that the input sources are in Chill\n");
5276 printf (" -+ Allow parsing of C++ style features\n");
5277 printf (" -w Inhibit warning messages\n");
5278 printf (" -Wtrigraphs Warn if trigraphs are encountered\n");
5279 printf (" -Wno-trigraphs Do not warn about trigraphs\n");
5280 printf (" -Wcomment{s} Warn if one comment starts inside another\n");
5281 printf (" -Wno-comment{s} Do not warn about comments\n");
5282 printf (" -Wtraditional Warn if a macro argument is/would be turned into\n");
5283 printf (" a string if -traditional is specified\n");
5284 printf (" -Wno-traditional Do not warn about stringification\n");
5285 printf (" -Wundef Warn if an undefined macro is used by #if\n");
5286 printf (" -Wno-undef Do not warn about testing undefined macros\n");
5287 printf (" -Wimport Warn about the use of the #import directive\n");
5288 printf (" -Wno-import Do not warn about the use of #import\n");
5289 printf (" -Werror Treat all warnings as errors\n");
5290 printf (" -Wno-error Do not treat warnings as errors\n");
5291 printf (" -Wall Enable all preprocessor warnings\n");
5292 printf (" -M Generate make dependencies\n");
5293 printf (" -MM As -M, but ignore system header files\n");
5294 printf (" -MD As -M, but put output in a .d file\n");
5295 printf (" -MMD As -MD, but ignore system header files\n");
5296 printf (" -MG Treat missing header file as generated files\n");
5297 printf (" -g Include #define and #undef directives in the output\n");
5298 printf (" -D<macro> Define a <macro> with string '1' as its value\n");
5299 printf (" -D<macro>=<val> Define a <macro> with <val> as its value\n");
5300 printf (" -A<question> (<answer>) Assert the <answer> to <question>\n");
5301 printf (" -U<macro> Undefine <macro> \n");
5302 printf (" -u or -undef Do not predefine any macros\n");
5303 printf (" -v Display the version number\n");
5304 printf (" -H Print the name of header files as they are used\n");
5305 printf (" -C Do not discard comments\n");
5306 printf (" -dM Display a list of macro definitions active at end\n");
5307 printf (" -dD Preserve macro definitions in output\n");
5308 printf (" -dN As -dD except that only the names are preserved\n");
5309 printf (" -dI Include #include directives in the output\n");
5310 printf (" -ifoutput Describe skipped code blocks in output \n");
5311 printf (" -P Do not generate #line directives\n");
5312 printf (" -$ Do not include '$' in identifiers\n");
5313 printf (" -remap Remap file names when including files.\n");
5314 printf (" -h or --help Display this information\n");
5318 /* Handle one command-line option in (argc, argv).
5319 Can be called multiple times, to handle multiple sets of options.
5320 Returns number of strings consumed. */
5322 cpp_handle_option (pfile, argc, argv)
5327 struct cpp_options *opts = CPP_OPTIONS (pfile);
5330 if (user_label_prefix == NULL)
5331 user_label_prefix = USER_LABEL_PREFIX;
5333 if (argv[i][0] != '-') {
5334 if (opts->out_fname != NULL)
5337 cpp_fatal (pfile, "Too many arguments");
5339 else if (opts->in_fname != NULL)
5340 opts->out_fname = argv[i];
5342 opts->in_fname = argv[i];
5344 switch (argv[i][1]) {
5347 cpp_fatal (pfile, "Filename missing after `%s' option", argv[i]);
5350 cpp_fatal (pfile, "Directory name missing after `%s' option", argv[i]);
5354 if (!strcmp (argv[i], "-fleading-underscore"))
5355 user_label_prefix = "_";
5356 else if (!strcmp (argv[i], "-fno-leading-underscore"))
5357 user_label_prefix = "";
5360 case 'I': /* Add directory to path for includes. */
5361 if (!strcmp (argv[i] + 2, "-"))
5363 if (! opts->ignore_srcdir)
5365 opts->ignore_srcdir = 1;
5366 /* Don't use any preceding -I directories for #include <...>. */
5367 opts->quote_include = opts->bracket_include;
5368 opts->bracket_include = 0;
5374 if (argv[i][2] != 0)
5375 fname = argv[i] + 2;
5376 else if (i + 1 == argc)
5377 goto missing_dirname;
5380 append_include_chain (pfile, &opts->bracket_include, fname, 0);
5385 /* Add directory to beginning of system include path, as a system
5386 include directory. */
5387 if (!strcmp (argv[i], "-isystem"))
5390 goto missing_filename;
5391 append_include_chain (pfile, &opts->system_include, argv[++i], 1);
5393 /* Add directory to end of path for includes,
5394 with the default prefix at the front of its name. */
5395 else if (!strcmp (argv[i], "-iwithprefix"))
5399 goto missing_dirname;
5402 if (opts->include_prefix != 0)
5404 fname = xmalloc (strlen (opts->include_prefix)
5405 + strlen (argv[i]) + 1);
5406 strcpy (fname, opts->include_prefix);
5407 strcat (fname, argv[i]);
5411 fname = xmalloc (strlen (GCC_INCLUDE_DIR)
5412 + strlen (argv[i]) + 1);
5413 strcpy (fname, GCC_INCLUDE_DIR);
5414 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5415 if (!strcmp (fname + strlen (fname) - 8, "/include"))
5416 fname[strlen (fname) - 7] = 0;
5417 strcat (fname, argv[i]);
5420 append_include_chain (pfile, &opts->system_include, fname, 0);
5422 /* Add directory to main path for includes,
5423 with the default prefix at the front of its name. */
5424 else if (!strcmp (argv[i], "-iwithprefix"))
5428 goto missing_dirname;
5431 if (opts->include_prefix != 0)
5433 fname = xmalloc (strlen (opts->include_prefix)
5434 + strlen (argv[i]) + 1);
5435 strcpy (fname, opts->include_prefix);
5436 strcat (fname, argv[i]);
5440 fname = xmalloc (strlen (GCC_INCLUDE_DIR)
5441 + strlen (argv[i]) + 1);
5442 strcpy (fname, GCC_INCLUDE_DIR);
5443 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5444 if (!strcmp (fname + strlen (fname) - 8, "/include"))
5445 fname[strlen (fname) - 7] = 0;
5446 strcat (fname, argv[i]);
5449 append_include_chain (pfile, &opts->bracket_include, fname, 0);
5451 /* Add directory to end of path for includes. */
5452 else if (!strcmp (argv[i], "-idirafter"))
5455 goto missing_dirname;
5456 append_include_chain (pfile, &opts->after_include, argv[++i], 0);
5458 else if (!strcmp (argv[i], "-include") || !strcmp (argv[i], "-imacros"))
5461 goto missing_filename;
5463 push_pending (pfile, argv[i], argv[i+1]), i++;
5465 else if (!strcmp (argv[i], "-iprefix"))
5468 goto missing_filename;
5470 opts->include_prefix = argv[++i];
5472 else if (!strcmp (argv[i], "-ifoutput"))
5473 opts->output_conditionals = 1;
5478 if (opts->out_fname != NULL)
5480 cpp_fatal (pfile, "Output filename specified twice");
5484 goto missing_filename;
5485 opts->out_fname = argv[++i];
5486 if (!strcmp (opts->out_fname, "-"))
5487 opts->out_fname = "";
5491 if (!strcmp (argv[i], "-pedantic"))
5492 CPP_PEDANTIC (pfile) = 1;
5493 else if (!strcmp (argv[i], "-pedantic-errors")) {
5494 CPP_PEDANTIC (pfile) = 1;
5495 opts->pedantic_errors = 1;
5498 else if (!strcmp (argv[i], "-pcp")) {
5499 char *pcp_fname = argv[++i];
5500 pcp_outfile = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
5501 ? fopen (pcp_fname, "w")
5502 : fdopen (dup (fileno (stdout)), "w"));
5503 if (pcp_outfile == 0)
5504 cpp_pfatal_with_name (pfile, pcp_fname);
5511 if (!strcmp (argv[i], "-traditional")) {
5512 opts->traditional = 1;
5513 opts->cplusplus_comments = 0;
5514 } else if (!strcmp (argv[i], "-trigraphs")) {
5516 opts->trigraphs = 1;
5521 if (! strcmp (argv[i], "-lang-c"))
5522 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
5524 if (! strcmp (argv[i], "-lang-c89"))
5525 opts->cplusplus = 0, opts->cplusplus_comments = 0, opts->c89 = 1,
5527 if (! strcmp (argv[i], "-lang-c++"))
5528 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
5530 if (! strcmp (argv[i], "-lang-objc"))
5531 opts->cplusplus = 0, opts->cplusplus_comments = 1, opts->c89 = 0,
5533 if (! strcmp (argv[i], "-lang-objc++"))
5534 opts->cplusplus = 1, opts->cplusplus_comments = 1, opts->c89 = 0,
5536 if (! strcmp (argv[i], "-lang-asm"))
5538 if (! strcmp (argv[i], "-lint"))
5540 if (! strcmp (argv[i], "-lang-chill"))
5541 opts->objc = 0, opts->cplusplus = 0, opts->chill = 1,
5542 opts->traditional = 1, opts->trigraphs = 0;
5546 opts->cplusplus = 1, opts->cplusplus_comments = 1;
5550 opts->inhibit_warnings = 1;
5554 if (!strcmp (argv[i], "-Wtrigraphs"))
5555 opts->warn_trigraphs = 1;
5556 else if (!strcmp (argv[i], "-Wno-trigraphs"))
5557 opts->warn_trigraphs = 0;
5558 else if (!strcmp (argv[i], "-Wcomment"))
5559 opts->warn_comments = 1;
5560 else if (!strcmp (argv[i], "-Wno-comment"))
5561 opts->warn_comments = 0;
5562 else if (!strcmp (argv[i], "-Wcomments"))
5563 opts->warn_comments = 1;
5564 else if (!strcmp (argv[i], "-Wno-comments"))
5565 opts->warn_comments = 0;
5566 else if (!strcmp (argv[i], "-Wtraditional"))
5567 opts->warn_stringify = 1;
5568 else if (!strcmp (argv[i], "-Wno-traditional"))
5569 opts->warn_stringify = 0;
5570 else if (!strcmp (argv[i], "-Wundef"))
5571 opts->warn_undef = 1;
5572 else if (!strcmp (argv[i], "-Wno-undef"))
5573 opts->warn_undef = 0;
5574 else if (!strcmp (argv[i], "-Wimport"))
5575 opts->warn_import = 1;
5576 else if (!strcmp (argv[i], "-Wno-import"))
5577 opts->warn_import = 0;
5578 else if (!strcmp (argv[i], "-Werror"))
5579 opts->warnings_are_errors = 1;
5580 else if (!strcmp (argv[i], "-Wno-error"))
5581 opts->warnings_are_errors = 0;
5582 else if (!strcmp (argv[i], "-Wall"))
5584 opts->warn_trigraphs = 1;
5585 opts->warn_comments = 1;
5590 /* The style of the choices here is a bit mixed.
5591 The chosen scheme is a hybrid of keeping all options in one string
5592 and specifying each option in a separate argument:
5593 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
5594 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
5595 -M[M][G][D file]. This is awkward to handle in specs, and is not
5597 /* ??? -MG must be specified in addition to one of -M or -MM.
5598 This can be relaxed in the future without breaking anything.
5599 The converse isn't true. */
5601 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
5602 if (!strcmp (argv[i], "-MG"))
5604 opts->print_deps_missing_files = 1;
5607 if (!strcmp (argv[i], "-M"))
5608 opts->print_deps = 2;
5609 else if (!strcmp (argv[i], "-MM"))
5610 opts->print_deps = 1;
5611 else if (!strcmp (argv[i], "-MD"))
5612 opts->print_deps = 2;
5613 else if (!strcmp (argv[i], "-MMD"))
5614 opts->print_deps = 1;
5615 /* For -MD and -MMD options, write deps on file named by next arg. */
5616 if (!strcmp (argv[i], "-MD") || !strcmp (argv[i], "-MMD"))
5619 goto missing_filename;
5620 opts->deps_file = argv[++i];
5624 /* For -M and -MM, write deps on standard output
5625 and suppress the usual output. */
5626 opts->no_output = 1;
5632 char *p = argv[i] + 2;
5634 while ((c = *p++) != 0) {
5635 /* Arg to -d specifies what parts of macros to dump */
5638 opts->dump_macros = dump_only;
5639 opts->no_output = 1;
5642 opts->dump_macros = dump_names;
5645 opts->dump_macros = dump_definitions;
5648 opts->dump_includes = 1;
5656 if (argv[i][2] == '3')
5657 opts->debug_output = 1;
5661 if (strcmp (argv[i], "--help") != 0)
5667 cpp_notice ("GNU CPP version %s", version_string);
5668 #ifdef TARGET_VERSION
5671 fprintf (stderr, "\n");
5676 opts->print_include_names = 1;
5680 if (argv[i][2] != 0)
5681 push_pending (pfile, "-D", argv[i] + 2);
5682 else if (i + 1 == argc)
5684 cpp_fatal (pfile, "Macro name missing after -D option");
5688 i++, push_pending (pfile, "-D", argv[i]);
5695 if (argv[i][2] != 0)
5697 else if (i + 1 == argc)
5699 cpp_fatal (pfile, "Assertion missing after -A option");
5705 if (!strcmp (p, "-")) {
5706 struct cpp_pending **ptr;
5707 /* -A- eliminates all predefined macros and assertions.
5708 Let's include also any that were specified earlier
5709 on the command line. That way we can get rid of any
5710 that were passed automatically in from GCC. */
5711 opts->inhibit_predefs = 1;
5712 for (ptr = &opts->pending; *ptr != NULL; )
5714 struct cpp_pending *pend = *ptr;
5715 if (pend->cmd && pend->cmd[0] == '-'
5716 && (pend->cmd[1] == 'D' || pend->cmd[1] == 'A'))
5725 push_pending (pfile, "-A", p);
5730 case 'U': /* JF #undef something */
5731 if (argv[i][2] != 0)
5732 push_pending (pfile, "-U", argv[i] + 2);
5733 else if (i + 1 == argc)
5735 cpp_fatal (pfile, "Macro name missing after -U option");
5739 push_pending (pfile, "-U", argv[i+1]), i++;
5743 opts->put_out_comments = 1;
5746 case 'E': /* -E comes from cc -E; ignore it. */
5750 opts->no_line_commands = 1;
5753 case '$': /* Don't include $ in identifiers. */
5754 opts->dollars_in_ident = 0;
5758 if (!strcmp (argv[i], "-nostdinc"))
5759 /* -nostdinc causes no default include directories.
5760 You must specify all include-file directories with -I. */
5761 opts->no_standard_includes = 1;
5762 else if (!strcmp (argv[i], "-nostdinc++"))
5763 /* -nostdinc++ causes no default C++-specific include directories. */
5764 opts->no_standard_cplusplus_includes = 1;
5766 else if (!strcmp (argv[i], "-noprecomp"))
5772 if (!strcmp (argv[i], "-remap"))
5777 /* Sun compiler passes undocumented switch "-undef".
5778 Let's assume it means to inhibit the predefined symbols. */
5779 opts->inhibit_predefs = 1;
5782 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
5783 if (opts->in_fname == NULL) {
5784 opts->in_fname = "";
5786 } else if (opts->out_fname == NULL) {
5787 opts->out_fname = "";
5789 } /* else fall through into error */
5799 /* Handle command-line options in (argc, argv).
5800 Can be called multiple times, to handle multiple sets of options.
5801 Returns if an unrecognized option is seen.
5802 Returns number of strings consumed. */
5805 cpp_handle_options (pfile, argc, argv)
5811 int strings_processed;
5812 for (i = 0; i < argc; i += strings_processed)
5814 strings_processed = cpp_handle_option (pfile, argc - i, argv + i);
5815 if (strings_processed == 0)
5825 struct cpp_options *opts = CPP_OPTIONS (pfile);
5827 if (opts->print_deps)
5829 /* Stream on which to print the dependency information. */
5832 /* Don't actually write the deps file if compilation has failed. */
5833 if (pfile->errors == 0)
5835 char *deps_mode = opts->print_deps_append ? "a" : "w";
5836 if (opts->deps_file == 0)
5837 deps_stream = stdout;
5838 else if ((deps_stream = fopen (opts->deps_file, deps_mode)) == 0)
5839 cpp_pfatal_with_name (pfile, opts->deps_file);
5840 fputs (pfile->deps_buffer, deps_stream);
5841 putc ('\n', deps_stream);
5842 if (opts->deps_file)
5844 if (ferror (deps_stream) || fclose (deps_stream) != 0)
5845 cpp_fatal (pfile, "I/O error on output");
5851 /* Debugging: dump statistics on the include hash table. */
5853 struct include_hash *x;
5856 for(i = 0; i < ALL_INCLUDE_HASHSIZE; i++)
5858 x = pfile->all_include_files[i];
5865 fprintf(stderr, "%d/%d ", i, j);
5867 fputc('\n', stderr);
5873 /* Free resources used by PFILE.
5874 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
5881 while ( CPP_BUFFER (pfile) != CPP_NULL_BUFFER (pfile))
5882 cpp_pop_buffer (pfile);
5884 if (pfile->token_buffer)
5886 free (pfile->token_buffer);
5887 pfile->token_buffer = NULL;
5890 if (pfile->deps_buffer)
5892 free (pfile->deps_buffer);
5893 pfile->deps_buffer = NULL;
5894 pfile->deps_allocated_size = 0;
5897 while (pfile->if_stack)
5899 IF_STACK_FRAME *temp = pfile->if_stack;
5900 pfile->if_stack = temp->next;
5904 for (i = ALL_INCLUDE_HASHSIZE; --i >= 0; )
5906 struct include_hash *imp = pfile->all_include_files[i];
5909 struct include_hash *next = imp->next;
5911 /* This gets freed elsewhere - I think. */
5917 pfile->all_include_files[i] = 0;
5920 cpp_hash_cleanup (pfile);
5923 /* Read an assertion into the token buffer, converting to
5924 canonical form: `#predicate(a n swe r)' The next non-whitespace
5925 character to read should be the first letter of the predicate.
5926 Returns 0 for syntax error, 1 for bare predicate, 2 for predicate
5927 with answer (see callers for why). In case of 0, an error has been
5930 parse_assertion (pfile)
5934 cpp_skip_hspace (pfile);
5936 if (! is_idstart[c])
5938 cpp_error (pfile, "assertion predicate is not an identifier");
5941 CPP_PUTC(pfile, '#');
5943 parse_name(pfile, c);
5948 if (is_hor_space[c])
5949 cpp_skip_hspace (pfile);
5955 CPP_PUTC(pfile, '(');
5958 while ((c = GETC()) != ')')
5960 if (is_hor_space[c])
5964 CPP_PUTC(pfile, ' ');
5968 else if (c == '\\' && PEEKC() == '\n')
5970 else if (c == '\n' || c == EOF)
5972 if (c == '\n') FORWARD(-1);
5973 cpp_error (pfile, "un-terminated assertion answer");
5983 if (pfile->limit[-1] == ' ')
5984 pfile->limit[-1] = ')';
5985 else if (pfile->limit[-1] == '(')
5987 cpp_error (pfile, "empty token sequence in assertion");
5991 CPP_PUTC(pfile, ')');
5993 CPP_NUL_TERMINATE(pfile);
5998 do_assert (pfile, keyword)
6000 struct directive *keyword ATTRIBUTE_UNUSED;
6004 HASHNODE *base, *this;
6005 int baselen, thislen;
6007 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6008 && !CPP_BUFFER (pfile)->system_header_p)
6009 cpp_pedwarn (pfile, "ANSI C does not allow `#assert'");
6011 cpp_skip_hspace (pfile);
6012 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
6013 ret = parse_assertion (pfile);
6018 cpp_error (pfile, "missing token-sequence in `#assert'");
6022 cpp_skip_hspace (pfile);
6024 if (c != EOF && c != '\n')
6026 cpp_error (pfile, "junk at end of `#assert'");
6030 thislen = strlen (sym);
6031 baselen = index (sym, '(') - sym;
6032 this = cpp_lookup (pfile, sym, thislen, -1);
6035 cpp_warning (pfile, "`%s' re-asserted", sym);
6039 base = cpp_lookup (pfile, sym, baselen, -1);
6041 base = install (sym, baselen, T_ASSERT, 0, 0, -1);
6042 else if (base->type != T_ASSERT)
6044 /* Token clash - but with what?! */
6046 "cpp internal error: base->type != T_ASSERT in do_assert");
6050 this = install (sym, thislen, T_ASSERT, 0,
6051 (char *)base->value.aschain, -1);
6052 base->value.aschain = this;
6054 pfile->limit = sym; /* Pop */
6058 pfile->limit = sym; /* Pop */
6059 skip_rest_of_line (pfile);
6064 do_unassert (pfile, keyword)
6066 struct directive *keyword ATTRIBUTE_UNUSED;
6070 long baselen, thislen;
6071 HASHNODE *base, *this, *next;
6073 if (CPP_PEDANTIC (pfile) && CPP_OPTIONS (pfile)->done_initializing
6074 && !CPP_BUFFER (pfile)->system_header_p)
6075 cpp_pedwarn (pfile, "ANSI C does not allow `#unassert'");
6077 cpp_skip_hspace (pfile);
6079 sym = CPP_PWRITTEN (pfile); /* remember where it starts */
6080 ret = parse_assertion (pfile);
6084 cpp_skip_hspace (pfile);
6086 if (c != EOF && c != '\n')
6087 cpp_error (pfile, "junk at end of `#unassert'");
6089 thislen = strlen (sym);
6092 base = cpp_lookup (pfile, sym, thislen, -1);
6094 goto error; /* It isn't an error to #undef what isn't #defined,
6095 so it isn't an error to #unassert what isn't
6096 #asserted either. */
6098 for (this = base->value.aschain; this; this = next)
6100 next = this->value.aschain;
6101 delete_macro (this);
6103 delete_macro (base);
6107 baselen = index (sym, '(') - sym;
6108 base = cpp_lookup (pfile, sym, baselen, -1);
6109 if (! base) goto error;
6110 this = cpp_lookup (pfile, sym, thislen, -1);
6111 if (! this) goto error;
6114 while (next->value.aschain != this)
6115 next = next->value.aschain;
6117 next->value.aschain = this->value.aschain;
6118 delete_macro (this);
6120 if (base->value.aschain == NULL)
6121 delete_macro (base); /* Last answer for this predicate deleted. */
6124 pfile->limit = sym; /* Pop */
6127 pfile->limit = sym; /* Pop */
6128 skip_rest_of_line (pfile);
6133 cpp_read_check_assertion (pfile)
6136 char *name = CPP_PWRITTEN (pfile);
6140 FORWARD (1); /* Skip '#' */
6141 cpp_skip_hspace (pfile);
6142 if (! parse_assertion (pfile))
6146 hp = cpp_lookup (pfile, name, (char *)CPP_PWRITTEN (pfile) - name, -1);
6150 pfile->limit = name;
6154 /* Initialize PMARK to remember the current position of PFILE. */
6157 parse_set_mark (pmark, pfile)
6158 struct parse_marker *pmark;
6161 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6162 pmark->next = pbuf->marks;
6163 pbuf->marks = pmark;
6165 pmark->position = pbuf->cur - pbuf->buf;
6168 /* Cleanup PMARK - we no longer need it. */
6171 parse_clear_mark (pmark)
6172 struct parse_marker *pmark;
6174 struct parse_marker **pp = &pmark->buf->marks;
6175 for (; ; pp = &(*pp)->next) {
6176 if (*pp == NULL) abort ();
6177 if (*pp == pmark) break;
6182 /* Backup the current position of PFILE to that saved in PMARK. */
6185 parse_goto_mark (pmark, pfile)
6186 struct parse_marker *pmark;
6189 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6190 if (pbuf != pmark->buf)
6191 cpp_fatal (pfile, "internal error %s", "parse_goto_mark");
6192 pbuf->cur = pbuf->buf + pmark->position;
6195 /* Reset PMARK to point to the current position of PFILE. (Same
6196 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
6199 parse_move_mark (pmark, pfile)
6200 struct parse_marker *pmark;
6203 cpp_buffer *pbuf = CPP_BUFFER (pfile);
6204 if (pbuf != pmark->buf)
6205 cpp_fatal (pfile, "internal error %s", "parse_move_mark");
6206 pmark->position = pbuf->cur - pbuf->buf;
6211 cpp_print_file_and_line (pfile)
6214 cpp_buffer *ip = cpp_file_buffer (pfile);
6219 cpp_buf_line_and_col (ip, &line, &col);
6220 cpp_file_line_for_message (pfile, ip->nominal_fname,
6221 line, pfile->show_column ? col : -1);
6226 v_cpp_error (pfile, msgid, ap)
6231 cpp_print_containing_files (pfile);
6232 cpp_print_file_and_line (pfile);
6233 v_cpp_message (pfile, 1, msgid, ap);
6237 cpp_error VPROTO ((cpp_reader * pfile, const char *msgid, ...))
6239 #ifndef ANSI_PROTOTYPES
6245 VA_START(ap, msgid);
6247 #ifndef ANSI_PROTOTYPES
6248 pfile = va_arg (ap, cpp_reader *);
6249 msgid = va_arg (ap, const char *);
6252 v_cpp_error (pfile, msgid, ap);
6256 /* Print error message but don't count it. */
6259 v_cpp_warning (pfile, msgid, ap)
6264 if (CPP_OPTIONS (pfile)->inhibit_warnings)
6267 if (CPP_OPTIONS (pfile)->warnings_are_errors)
6270 cpp_print_containing_files (pfile);
6271 cpp_print_file_and_line (pfile);
6272 v_cpp_message (pfile, 0, msgid, ap);
6276 cpp_warning VPROTO ((cpp_reader * pfile, const char *msgid, ...))
6278 #ifndef ANSI_PROTOTYPES
6284 VA_START (ap, msgid);
6286 #ifndef ANSI_PROTOTYPES
6287 pfile = va_arg (ap, cpp_reader *);
6288 msgid = va_arg (ap, const char *);
6291 v_cpp_warning (pfile, msgid, ap);
6295 /* Print an error message and maybe count it. */
6298 cpp_pedwarn VPROTO ((cpp_reader * pfile, const char *msgid, ...))
6300 #ifndef ANSI_PROTOTYPES
6306 VA_START (ap, msgid);
6308 #ifndef ANSI_PROTOTYPES
6309 pfile = va_arg (ap, cpp_reader *);
6310 msgid = va_arg (ap, const char *);
6313 if (CPP_OPTIONS (pfile)->pedantic_errors)
6314 v_cpp_error (pfile, msgid, ap);
6316 v_cpp_warning (pfile, msgid, ap);
6321 v_cpp_error_with_line (pfile, line, column, msgid, ap)
6328 cpp_buffer *ip = cpp_file_buffer (pfile);
6330 cpp_print_containing_files (pfile);
6333 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
6335 v_cpp_message (pfile, 1, msgid, ap);
6339 cpp_error_with_line VPROTO ((cpp_reader * pfile, int line, int column,
6340 const char *msgid, ...))
6342 #ifndef ANSI_PROTOTYPES
6350 VA_START (ap, msgid);
6352 #ifndef ANSI_PROTOTYPES
6353 pfile = va_arg (ap, cpp_reader *);
6354 line = va_arg (ap, int);
6355 column = va_arg (ap, int);
6356 msgid = va_arg (ap, const char *);
6359 v_cpp_error_with_line(pfile, line, column, msgid, ap);
6364 v_cpp_warning_with_line (pfile, line, column, msgid, ap)
6373 if (CPP_OPTIONS (pfile)->inhibit_warnings)
6376 if (CPP_OPTIONS (pfile)->warnings_are_errors)
6379 cpp_print_containing_files (pfile);
6381 ip = cpp_file_buffer (pfile);
6384 cpp_file_line_for_message (pfile, ip->nominal_fname, line, column);
6386 v_cpp_message (pfile, 0, msgid, ap);
6390 cpp_warning_with_line VPROTO ((cpp_reader * pfile, int line, int column,
6391 const char *msgid, ...))
6393 #ifndef ANSI_PROTOTYPES
6401 VA_START (ap, msgid);
6403 #ifndef ANSI_PROTOTYPES
6404 pfile = va_arg (ap, cpp_reader *);
6405 line = va_arg (ap, int);
6406 column = va_arg (ap, int);
6407 msgid = va_arg (ap, const char *);
6410 v_cpp_warning_with_line (pfile, line, column, msgid, ap);
6415 cpp_pedwarn_with_line VPROTO ((cpp_reader * pfile, int line, int column,
6416 const char *msgid, ...))
6418 #ifndef ANSI_PROTOTYPES
6426 VA_START (ap, msgid);
6428 #ifndef ANSI_PROTOTYPES
6429 pfile = va_arg (ap, cpp_reader *);
6430 line = va_arg (ap, int);
6431 column = va_arg (ap, int);
6432 msgid = va_arg (ap, const char *);
6435 if (CPP_OPTIONS (pfile)->pedantic_errors)
6436 v_cpp_error_with_line (pfile, column, line, msgid, ap);
6438 v_cpp_warning_with_line (pfile, line, column, msgid, ap);
6442 /* Report a warning (or an error if pedantic_errors)
6443 giving specified file name and line number, not current. */
6446 cpp_pedwarn_with_file_and_line VPROTO ((cpp_reader *pfile, char *file, int line,
6447 const char *msgid, ...))
6449 #ifndef ANSI_PROTOTYPES
6457 VA_START (ap, msgid);
6459 #ifndef ANSI_PROTOTYPES
6460 pfile = va_arg (ap, cpp_reader *);
6461 file = va_arg (ap, char *);
6462 line = va_arg (ap, int);
6463 msgid = va_arg (ap, const char *);
6466 if (!CPP_OPTIONS (pfile)->pedantic_errors
6467 && CPP_OPTIONS (pfile)->inhibit_warnings)
6470 cpp_file_line_for_message (pfile, file, line, -1);
6471 v_cpp_message (pfile, CPP_OPTIONS (pfile)->pedantic_errors, msgid, ap);
6475 /* my_strerror - return the descriptive text associated with an
6479 my_strerror (errnum)
6485 #ifndef HAVE_STRERROR
6486 result = (char *) ((errnum < sys_nerr) ? sys_errlist[errnum] : 0);
6488 result = strerror (errnum);
6491 /* VAXCRTL's strerror() takes an optional second argument, which only
6492 matters when the first argument is EVMSERR. However, it's simplest
6493 just to pass it unconditionally. `vaxc$errno' is declared in
6494 <errno.h>, and maintained by the library in parallel with `errno'.
6495 We assume that caller's `errnum' either matches the last setting of
6496 `errno' by the library or else does not have the value `EVMSERR'. */
6498 result = strerror (errnum, vaxc$errno);
6502 result = "errno = ?";
6507 /* Error including a message from `errno'. */
6510 cpp_error_from_errno (pfile, name)
6514 cpp_message_from_errno (pfile, 1, name);
6518 cpp_message_from_errno (pfile, is_error, name)
6524 cpp_buffer *ip = cpp_file_buffer (pfile);
6526 cpp_print_containing_files (pfile);
6529 cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
6531 cpp_message (pfile, is_error, "%s: %s", name, my_strerror (e));
6535 cpp_perror_with_name (pfile, name)
6539 cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
6543 * No pre-compiled header file support.
6545 * Possibly different enum token codes for each C/C++ token.
6547 * Find and cleanup remaining uses of static variables,
6549 * Support -dM flag (dump_all_macros).
6551 * Support for_lint flag.