2 Copyright (C) 1986, 87, 89, 92-97, 1998 Free Software Foundation, Inc.
3 Contributed by Per Bothner, 1994-95.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #ifdef HAVE_SYS_TIMES_H
31 #include <sys/times.h>
34 #ifdef HAVE_SYS_RESOURCE_H
35 # include <sys/resource.h>
38 #include "gansidecl.h"
42 #ifndef GET_ENV_PATH_LIST
43 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
46 extern char *update_path
PARAMS ((char *, char *));
50 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
51 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
53 /* Find the largest host integer type and set its size and type.
54 Watch out: on some crazy hosts `long' is shorter than `int'. */
58 # include <inttypes.h>
59 # define HOST_WIDE_INT intmax_t
61 # if (HOST_BITS_PER_LONG <= HOST_BITS_PER_INT \
62 && HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_INT)
63 # define HOST_WIDE_INT int
65 # if (HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_LONG \
66 || ! (defined LONG_LONG_MAX || defined LLONG_MAX))
67 # define HOST_WIDE_INT long
69 # define HOST_WIDE_INT long long
76 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
80 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
83 /* By default, colon separates directories in a path. */
84 #ifndef PATH_SEPARATOR
85 #define PATH_SEPARATOR ':'
88 #ifndef STANDARD_INCLUDE_DIR
89 #define STANDARD_INCLUDE_DIR "/usr/include"
91 #ifndef INCLUDE_LEN_FUDGE
92 #define INCLUDE_LEN_FUDGE 0
95 /* Symbols to predefine. */
98 static char *predefs
= CPP_PREDEFINES
;
100 static char *predefs
= "";
103 /* We let tm.h override the types used here, to handle trivial differences
104 such as the choice of unsigned int or long unsigned int for size_t.
105 When machines start needing nontrivial differences in the size type,
106 it would be best to do something here to figure out automatically
107 from other information what type to use. */
109 /* The string value for __SIZE_TYPE__. */
112 #define SIZE_TYPE "long unsigned int"
115 /* The string value for __PTRDIFF_TYPE__. */
118 #define PTRDIFF_TYPE "long int"
121 /* The string value for __WCHAR_TYPE__. */
124 #define WCHAR_TYPE "int"
126 #define CPP_WCHAR_TYPE(PFILE) \
127 (CPP_OPTIONS (PFILE)->cplusplus ? "__wchar_t" : WCHAR_TYPE)
129 /* The string value for __USER_LABEL_PREFIX__ */
131 #ifndef USER_LABEL_PREFIX
132 #define USER_LABEL_PREFIX ""
135 /* The string value for __REGISTER_PREFIX__ */
137 #ifndef REGISTER_PREFIX
138 #define REGISTER_PREFIX ""
141 /* In the definition of a #assert name, this structure forms
142 a list of the individual values asserted.
143 Each value is itself a list of "tokens".
144 These are strings that are compared by name. */
146 struct tokenlist_list
{
147 struct tokenlist_list
*next
;
148 struct arglist
*tokens
;
151 struct assertion_hashnode
{
152 struct assertion_hashnode
*next
; /* double links for easy deletion */
153 struct assertion_hashnode
*prev
;
154 /* also, a back pointer to this node's hash
155 chain is kept, in case the node is the head
156 of the chain and gets deleted. */
157 struct assertion_hashnode
**bucket_hdr
;
158 int length
; /* length of token, for quick comparison */
159 U_CHAR
*name
; /* the actual name */
160 /* List of token-sequences. */
161 struct tokenlist_list
*value
;
164 #define SKIP_WHITE_SPACE(p) do { while (is_hor_space[*p]) p++; } while (0)
165 #define SKIP_ALL_WHITE_SPACE(p) do { while (is_space[*p]) p++; } while (0)
167 #define PEEKN(N) (CPP_BUFFER (pfile)->rlimit - CPP_BUFFER (pfile)->cur >= (N) ? CPP_BUFFER (pfile)->cur[N] : EOF)
168 #define FORWARD(N) CPP_FORWARD (CPP_BUFFER (pfile), (N))
169 #define GETC() CPP_BUF_GET (CPP_BUFFER (pfile))
170 #define PEEKC() CPP_BUF_PEEK (CPP_BUFFER (pfile))
171 /* CPP_IS_MACRO_BUFFER is true if the buffer contains macro expansion.
172 (Note that it is false while we're expanding marco *arguments*.) */
173 #define CPP_IS_MACRO_BUFFER(PBUF) ((PBUF)->cleanup == macro_cleanup)
175 /* Move all backslash-newline pairs out of embarrassing places.
176 Exchange all such pairs following BP
177 with any potentially-embarrassing characters that follow them.
178 Potentially-embarrassing characters are / and *
179 (because a backslash-newline inside a comment delimiter
180 would cause it not to be recognized). */
182 #define NEWLINE_FIX \
183 do {while (PEEKC() == '\\' && PEEKN(1) == '\n') FORWARD(2); } while(0)
185 /* Same, but assume we've already read the potential '\\' into C. */
186 #define NEWLINE_FIX1(C) do { \
187 while ((C) == '\\' && PEEKC() == '\n') { FORWARD(1); (C) = GETC(); }\
191 struct cpp_pending
*next
;
196 /* Forward declarations. */
199 extern void cpp_hash_cleanup
PARAMS ((cpp_reader
*));
201 static char *my_strerror
PROTO ((int));
202 static void add_import
PROTO ((cpp_reader
*, int, char *));
203 static void append_include_chain
PROTO ((cpp_reader
*,
204 struct file_name_list
*,
205 struct file_name_list
*));
206 static void make_assertion
PROTO ((cpp_reader
*, char *, U_CHAR
*));
207 static void path_include
PROTO ((cpp_reader
*, char *));
208 static void initialize_builtins
PROTO ((cpp_reader
*));
209 static void initialize_char_syntax
PROTO ((struct cpp_options
*));
211 static void trigraph_pcp ();
213 static int finclude
PROTO ((cpp_reader
*, int, char *,
214 int, struct file_name_list
*));
215 static void validate_else
PROTO ((cpp_reader
*, char *));
216 static int comp_def_part
PROTO ((int, U_CHAR
*, int, U_CHAR
*,
219 extern void fancy_abort ();
221 static int lookup_import
PROTO ((cpp_reader
*, char *,
222 struct file_name_list
*));
223 static int redundant_include_p
PROTO ((cpp_reader
*, char *));
224 static int is_system_include
PROTO ((cpp_reader
*, char *));
225 static struct file_name_map
*read_name_map
PROTO ((cpp_reader
*, char *));
226 static char *read_filename_string
PROTO ((int, FILE *));
227 static int open_include_file
PROTO ((cpp_reader
*, char *,
228 struct file_name_list
*));
229 static int check_macro_name
PROTO ((cpp_reader
*, U_CHAR
*, char *));
230 static int compare_defs
PROTO ((cpp_reader
*,
231 DEFINITION
*, DEFINITION
*));
232 static int compare_token_lists
PROTO ((struct arglist
*,
234 static HOST_WIDE_INT eval_if_expression
PROTO ((cpp_reader
*, U_CHAR
*, int));
235 static int change_newlines
PROTO ((U_CHAR
*, int));
236 static struct arglist
*read_token_list
PROTO ((cpp_reader
*, int *));
237 static void free_token_list
PROTO ((struct arglist
*));
238 static int safe_read
PROTO ((int, char *, int));
239 static void push_macro_expansion
PARAMS ((cpp_reader
*,
240 U_CHAR
*, int, HASHNODE
*));
241 static struct cpp_pending
*nreverse_pending
PARAMS ((struct cpp_pending
*));
242 extern char *xrealloc ();
243 static char *xcalloc
PROTO ((unsigned, unsigned));
244 static char *savestring
PROTO ((char *));
246 static void conditional_skip
PROTO ((cpp_reader
*, int,
247 enum node_type
, U_CHAR
*));
248 static void skip_if_group
PROTO ((cpp_reader
*, int));
249 static int parse_name
PARAMS ((cpp_reader
*, int));
250 static void print_help
PROTO ((void));
252 /* Last arg to output_line_command. */
253 enum file_change_code
{same_file
, enter_file
, leave_file
};
255 /* External declarations. */
257 extern HOST_WIDE_INT cpp_parse_expr
PARAMS ((cpp_reader
*));
259 extern char *version_string
;
260 extern struct tm
*localtime ();
262 struct file_name_list
264 struct file_name_list
*next
;
266 /* If the following is nonzero, it is a macro name.
267 Don't include the file again if that macro is defined. */
268 U_CHAR
*control_macro
;
269 /* If the following is nonzero, it is a C-language system include
271 int c_system_include_path
;
272 /* Mapping of file names for this directory. */
273 struct file_name_map
*name_map
;
274 /* Non-zero if name_map is valid. */
278 /* If a buffer's dir field is SELF_DIR_DUMMY, it means the file was found
279 via the same directory as the file that #included it. */
280 #define SELF_DIR_DUMMY ((struct file_name_list *) (~0))
282 /* #include "file" looks in source file dir, then stack. */
283 /* #include <file> just looks in the stack. */
284 /* -I directories are added to the end, then the defaults are added. */
286 static struct default_include
{
287 char *fname
; /* The name of the directory. */
288 char *component
; /* The component containing the directory */
289 int cplusplus
; /* Only look here if we're compiling C++. */
290 int cxx_aware
; /* Includes in this directory don't need to
291 be wrapped in extern "C" when compiling
293 } include_defaults_array
[]
294 #ifdef INCLUDE_DEFAULTS
298 /* Pick up GNU C++ specific include files. */
299 { GPLUSPLUS_INCLUDE_DIR
, "G++", 1, 1 },
301 /* This is the dir for fixincludes. Put it just before
302 the files that we fix. */
303 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
304 /* For cross-compilation, this dir name is generated
305 automatically in Makefile.in. */
306 { CROSS_INCLUDE_DIR
, "GCC",0, 0 },
307 #ifdef TOOL_INCLUDE_DIR
308 /* This is another place that the target system's headers might be. */
309 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
311 #else /* not CROSS_COMPILE */
312 #ifdef LOCAL_INCLUDE_DIR
313 /* This should be /usr/local/include and should come before
314 the fixincludes-fixed header files. */
315 { LOCAL_INCLUDE_DIR
, 0, 0, 1 },
317 #ifdef TOOL_INCLUDE_DIR
318 /* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
319 Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
320 { TOOL_INCLUDE_DIR
, "BINUTILS", 0, 1 },
322 /* This is the dir for fixincludes. Put it just before
323 the files that we fix. */
324 { GCC_INCLUDE_DIR
, "GCC", 0, 0 },
325 /* Some systems have an extra dir of include files. */
326 #ifdef SYSTEM_INCLUDE_DIR
327 { SYSTEM_INCLUDE_DIR
, 0, 0, 0 },
329 #ifndef STANDARD_INCLUDE_COMPONENT
330 #define STANDARD_INCLUDE_COMPONENT 0
332 { STANDARD_INCLUDE_DIR
, STANDARD_INCLUDE_COMPONENT
, 0, 0 },
333 #endif /* not CROSS_COMPILE */
336 #endif /* no INCLUDE_DEFAULTS */
338 /* `struct directive' defines one #-directive, including how to handle it. */
341 int length
; /* Length of name */
342 int (*func
) /* Function to handle directive */
343 PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
344 char *name
; /* Name of directive */
345 enum node_type type
; /* Code which describes which directive. */
346 char command_reads_line
; /* One if rest of line is read by func. */
349 /* These functions are declared to return int instead of void since they
350 are going to be placed in a table and some old compilers have trouble with
351 pointers to functions returning void. */
353 static int do_define
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
354 static int do_line
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
355 static int do_include
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
356 static int do_undef
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
357 static int do_error
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
358 static int do_pragma
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
359 static int do_ident
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
360 static int do_if
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
361 static int do_xifdef
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
362 static int do_else
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
363 static int do_elif
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
364 static int do_endif
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
365 #ifdef SCCS_DIRECTIVE
366 static int do_sccs
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
368 static int do_once
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
369 static int do_assert
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
370 static int do_unassert
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
371 static int do_warning
PARAMS ((cpp_reader
*, struct directive
*, U_CHAR
*, U_CHAR
*));
373 #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
374 ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
376 /* Here is the actual list of #-directives, most-often-used first.
377 The initialize_builtins function assumes #define is the very first. */
379 static struct directive directive_table
[] = {
380 { 6, do_define
, "define", T_DEFINE
},
381 { 5, do_xifdef
, "ifdef", T_IFDEF
, 1},
382 { 6, do_xifdef
, "ifndef", T_IFNDEF
, 1},
383 { 7, do_include
, "include", T_INCLUDE
, 1},
384 { 12, do_include
, "include_next", T_INCLUDE_NEXT
, 1},
385 { 6, do_include
, "import", T_IMPORT
, 1},
386 { 5, do_endif
, "endif", T_ENDIF
, 1},
387 { 4, do_else
, "else", T_ELSE
, 1},
388 { 2, do_if
, "if", T_IF
, 1},
389 { 4, do_elif
, "elif", T_ELIF
, 1},
390 { 5, do_undef
, "undef", T_UNDEF
},
391 { 5, do_error
, "error", T_ERROR
},
392 { 7, do_warning
, "warning", T_WARNING
},
393 { 6, do_pragma
, "pragma", T_PRAGMA
},
394 { 4, do_line
, "line", T_LINE
, 1},
395 { 5, do_ident
, "ident", T_IDENT
, 1},
396 #ifdef SCCS_DIRECTIVE
397 { 4, do_sccs
, "sccs", T_SCCS
},
399 { 6, do_assert
, "assert", T_ASSERT
, 1},
400 { 8, do_unassert
, "unassert", T_UNASSERT
, 1},
401 { -1, 0, "", T_UNUSED
},
404 /* table to tell if char can be part of a C identifier. */
405 U_CHAR is_idchar
[256];
406 /* table to tell if char can be first char of a c identifier. */
407 U_CHAR is_idstart
[256];
408 /* table to tell if c is horizontal space. */
409 U_CHAR is_hor_space
[256];
410 /* table to tell if c is horizontal or vertical space. */
411 static U_CHAR is_space
[256];
413 /* Initialize syntactic classifications of characters. */
416 initialize_char_syntax (opts
)
417 struct cpp_options
*opts
;
422 * Set up is_idchar and is_idstart tables. These should be
423 * faster than saying (is_alpha (c) || c == '_'), etc.
424 * Set up these things before calling any routines tthat
427 for (i
= 'a'; i
<= 'z'; i
++) {
428 is_idchar
[i
- 'a' + 'A'] = 1;
430 is_idstart
[i
- 'a' + 'A'] = 1;
433 for (i
= '0'; i
<= '9'; i
++)
437 is_idchar
['$'] = opts
->dollars_in_ident
;
438 is_idstart
['$'] = opts
->dollars_in_ident
;
440 /* horizontal space table */
441 is_hor_space
[' '] = 1;
442 is_hor_space
['\t'] = 1;
443 is_hor_space
['\v'] = 1;
444 is_hor_space
['\f'] = 1;
445 is_hor_space
['\r'] = 1;
456 /* Place into PFILE a quoted string representing the string SRC.
457 Caller must reserve enough space in pfile->token_buffer. */
460 quote_string (pfile
, src
)
466 CPP_PUTC_Q (pfile
, '\"');
468 switch ((c
= *src
++))
472 CPP_PUTC_Q (pfile
, c
);
475 sprintf ((char *)CPP_PWRITTEN (pfile
), "\\%03o", c
);
476 CPP_ADJUST_WRITTEN (pfile
, 4);
482 CPP_PUTC_Q (pfile
, '\\');
483 CPP_PUTC_Q (pfile
, c
);
487 CPP_PUTC_Q (pfile
, '\"');
488 CPP_NUL_TERMINATE_Q (pfile
);
493 /* Re-allocates PFILE->token_buffer so it will hold at least N more chars. */
496 cpp_grow_buffer (pfile
, n
)
500 long old_written
= CPP_WRITTEN (pfile
);
501 pfile
->token_buffer_size
= n
+ 2 * pfile
->token_buffer_size
;
502 pfile
->token_buffer
= (U_CHAR
*)
503 xrealloc(pfile
->token_buffer
, pfile
->token_buffer_size
);
504 CPP_SET_WRITTEN (pfile
, old_written
);
509 * process a given definition string, for initialization
510 * If STR is just an identifier, define it with value 1.
511 * If STR has anything after the identifier, then it should
512 * be identifier=definition.
516 cpp_define (pfile
, str
)
526 cpp_error (pfile
, "malformed option `-D %s'", str
);
529 while (is_idchar
[*++p
])
532 while (is_idchar
[*++p
] || *p
== ',' || is_hor_space
[*p
])
535 p
= (U_CHAR
*) str
; /* Error */
539 buf
= (U_CHAR
*) alloca (p
- buf
+ 4);
540 strcpy ((char *)buf
, str
);
541 strcat ((char *)buf
, " 1");
545 cpp_error (pfile
, "malformed option `-D %s'", str
);
551 /* Copy the entire option so we can modify it. */
552 buf
= (U_CHAR
*) alloca (2 * strlen (str
) + 1);
553 strncpy (buf
, str
, p
- str
);
554 /* Change the = to a space. */
556 /* Scan for any backslash-newline and remove it. */
561 if (*p
== '\\' && p
[1] == '\n')
569 do_define (pfile
, NULL
, buf
, buf
+ strlen (buf
));
572 /* Process the string STR as if it appeared as the body of a #assert.
573 OPTION is the option name for which STR was the argument. */
576 make_assertion (pfile
, option
, str
)
583 /* Copy the entire option so we can modify it. */
584 buf
= (U_CHAR
*) alloca (strlen (str
) + 1);
585 strcpy ((char *) buf
, str
);
586 /* Scan for any backslash-newline and remove it. */
590 if (*p
== '\\' && p
[1] == '\n')
599 if (!is_idstart
[*p
]) {
600 cpp_error (pfile
, "malformed option `%s %s'", option
, str
);
603 while (is_idchar
[*++p
])
605 while (*p
== ' ' || *p
== '\t') p
++;
606 if (! (*p
== 0 || *p
== '(')) {
607 cpp_error (pfile
, "malformed option `%s %s'", option
, str
);
611 if (cpp_push_buffer (pfile
, buf
, strlen (buf
)) != NULL
)
613 do_assert (pfile
, NULL
, NULL
, NULL
);
614 cpp_pop_buffer (pfile
);
618 /* Append a chain of `struct file_name_list's
619 to the end of the main include chain.
620 FIRST is the beginning of the chain to append, and LAST is the end. */
623 append_include_chain (pfile
, first
, last
)
625 struct file_name_list
*first
, *last
;
627 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
628 struct file_name_list
*dir
;
633 if (opts
->include
== 0)
634 opts
->include
= first
;
636 opts
->last_include
->next
= first
;
638 if (opts
->first_bracket_include
== 0)
639 opts
->first_bracket_include
= first
;
641 for (dir
= first
; ; dir
= dir
->next
) {
642 int len
= strlen (dir
->fname
) + INCLUDE_LEN_FUDGE
;
643 if (len
> pfile
->max_include_len
)
644 pfile
->max_include_len
= len
;
650 opts
->last_include
= last
;
653 /* Add output to `deps_buffer' for the -M switch.
654 STRING points to the text to be output.
655 SPACER is ':' for targets, ' ' for dependencies, zero for text
656 to be inserted literally. */
659 deps_output (pfile
, string
, spacer
)
664 int size
= strlen (string
);
669 #ifndef MAX_OUTPUT_COLUMNS
670 #define MAX_OUTPUT_COLUMNS 72
673 && pfile
->deps_column
> 0
674 && (pfile
->deps_column
+ size
) > MAX_OUTPUT_COLUMNS
)
676 deps_output (pfile
, " \\\n ", 0);
677 pfile
->deps_column
= 0;
680 if (pfile
->deps_size
+ size
+ 8 > pfile
->deps_allocated_size
)
682 pfile
->deps_allocated_size
= (pfile
->deps_size
+ size
+ 50) * 2;
683 pfile
->deps_buffer
= (char *) xrealloc (pfile
->deps_buffer
,
684 pfile
->deps_allocated_size
);
686 if (spacer
== ' ' && pfile
->deps_column
> 0)
687 pfile
->deps_buffer
[pfile
->deps_size
++] = ' ';
688 bcopy (string
, &pfile
->deps_buffer
[pfile
->deps_size
], size
);
689 pfile
->deps_size
+= size
;
690 pfile
->deps_column
+= size
;
692 pfile
->deps_buffer
[pfile
->deps_size
++] = ':';
693 pfile
->deps_buffer
[pfile
->deps_size
] = 0;
696 /* Given a colon-separated list of file names PATH,
697 add all the names to the search path for include files. */
700 path_include (pfile
, path
)
712 struct file_name_list
*dirtmp
;
714 /* Find the end of this name. */
715 while (*q
!= 0 && *q
!= PATH_SEPARATOR
) q
++;
717 /* An empty name in the path stands for the current directory. */
718 name
= (char *) xmalloc (2);
722 /* Otherwise use the directory that is named. */
723 name
= (char *) xmalloc (q
- p
+ 1);
724 bcopy (p
, name
, q
- p
);
728 dirtmp
= (struct file_name_list
*)
729 xmalloc (sizeof (struct file_name_list
));
730 dirtmp
->next
= 0; /* New one goes on the end */
731 dirtmp
->control_macro
= 0;
732 dirtmp
->c_system_include_path
= 0;
733 dirtmp
->fname
= name
;
734 dirtmp
->got_name_map
= 0;
735 append_include_chain (pfile
, dirtmp
, dirtmp
);
737 /* Advance past this name. */
741 /* Skip the colon. */
747 cpp_options_init (opts
)
750 bzero ((char *) opts
, sizeof *opts
);
751 opts
->in_fname
= NULL
;
752 opts
->out_fname
= NULL
;
754 /* Initialize is_idchar to allow $. */
755 opts
->dollars_in_ident
= 1;
756 initialize_char_syntax (opts
);
758 opts
->no_line_commands
= 0;
759 opts
->no_trigraphs
= 1;
760 opts
->put_out_comments
= 0;
761 opts
->print_include_names
= 0;
762 opts
->dump_macros
= dump_none
;
766 opts
->cplusplus_comments
= 1;
773 opts
->pedantic_errors
= 0;
774 opts
->inhibit_warnings
= 0;
775 opts
->warn_comments
= 0;
776 opts
->warn_import
= 1;
777 opts
->warnings_are_errors
= 0;
781 null_underflow (pfile
)
782 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
788 null_cleanup (pbuf
, pfile
)
789 cpp_buffer
*pbuf ATTRIBUTE_UNUSED
;
790 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
796 macro_cleanup (pbuf
, pfile
)
798 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
800 HASHNODE
*macro
= (HASHNODE
*) pbuf
->data
;
801 if (macro
->type
== T_DISABLED
)
802 macro
->type
= T_MACRO
;
803 if (macro
->type
!= T_MACRO
|| pbuf
->buf
!= macro
->value
.defn
->expansion
)
809 file_cleanup (pbuf
, pfile
)
811 cpp_reader
*pfile ATTRIBUTE_UNUSED
;
821 /* Assuming we have read '/'.
822 If this is the start of a comment (followed by '*' or '/'),
823 skip to the end of the comment, and return ' '.
824 Return EOF if we reached the end of file before the end of the comment.
825 If not the start of a comment, return '/'. */
828 skip_comment (pfile
, linep
)
833 while (PEEKC() == '\\' && PEEKN(1) == '\n')
848 while (c
== '\\' && PEEKC() == '\n')
852 FORWARD(1), c
= GETC();
854 if (prev_c
== '*' && c
== '/')
856 if (c
== '\n' && linep
)
860 else if (PEEKC() == '/' && CPP_OPTIONS (pfile
)->cplusplus_comments
)
867 return ' '; /* Allow // to be terminated by EOF. */
868 while (c
== '\\' && PEEKC() == '\n')
877 /* Don't consider final '\n' to be part of comment. */
887 /* Skip whitespace \-newline and comments. Does not macro-expand. */
890 cpp_skip_hspace (pfile
)
900 if ((c
== '\f' || c
== '\v') && CPP_PEDANTIC (pfile
))
901 cpp_pedwarn (pfile
, "%s in preprocessing directive",
902 c
== '\f' ? "formfeed" : "vertical tab");
908 c
= skip_comment (pfile
, NULL
);
911 if (c
== EOF
|| c
== '/')
914 else if (c
== '\\' && PEEKN(1) == '\n') {
917 else if (c
== '@' && CPP_BUFFER (pfile
)->has_escapes
918 && is_hor_space
[PEEKN(1)])
924 /* Read the rest of the current line.
925 The line is appended to PFILE's output buffer. */
928 copy_rest_of_line (pfile
)
931 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
948 goto scan_directive_token
;
952 if (nextc
== '*' || (opts
->cplusplus_comments
&& nextc
== '/'))
953 goto scan_directive_token
;
957 if (CPP_PEDANTIC (pfile
))
958 cpp_pedwarn (pfile
, "%s in preprocessing directive",
959 c
== '\f' ? "formfeed" : "vertical tab");
965 scan_directive_token
:
967 cpp_get_token (pfile
);
973 CPP_NUL_TERMINATE (pfile
);
977 skip_rest_of_line (pfile
)
980 long old
= CPP_WRITTEN (pfile
);
981 copy_rest_of_line (pfile
);
982 CPP_SET_WRITTEN (pfile
, old
);
985 /* Handle a possible # directive.
986 '#' has already been read. */
989 handle_directive (pfile
)
992 register struct directive
*kt
;
995 U_CHAR
*ident
, *line_end
;
996 long old_written
= CPP_WRITTEN (pfile
);
998 cpp_skip_hspace (pfile
);
1001 if (c
>= '0' && c
<= '9')
1003 /* Handle # followed by a line number. */
1004 if (CPP_PEDANTIC (pfile
))
1005 cpp_pedwarn (pfile
, "`#' followed by integer");
1006 do_line (pfile
, NULL
, NULL
, NULL
);
1007 goto done_a_directive
;
1010 /* Now find the directive name. */
1011 CPP_PUTC (pfile
, '#');
1012 parse_name (pfile
, GETC());
1013 ident
= pfile
->token_buffer
+ old_written
+ 1;
1014 ident_length
= CPP_PWRITTEN (pfile
) - ident
;
1015 if (ident_length
== 0 && PEEKC() == '\n')
1017 /* A line of just `#' becomes blank. */
1018 goto done_a_directive
;
1022 if (ident_length
== 0 || !is_idstart
[*ident
]) {
1024 while (is_idchar
[*p
]) {
1025 if (*p
< '0' || *p
> '9')
1029 /* Avoid error for `###' and similar cases unless -pedantic. */
1031 while (*p
== '#' || is_hor_space
[*p
]) p
++;
1033 if (pedantic
&& !lang_asm
)
1034 cpp_warning (pfile
, "invalid preprocessor directive");
1040 cpp_error (pfile
, "invalid preprocessor directive name");
1046 * Decode the keyword and call the appropriate expansion
1047 * routine, after moving the input pointer up to the next line.
1049 for (kt
= directive_table
; ; kt
++) {
1050 if (kt
->length
<= 0)
1051 goto not_a_directive
;
1052 if (kt
->length
== ident_length
&& !strncmp (kt
->name
, ident
, ident_length
))
1056 if (kt
->command_reads_line
)
1060 /* Nonzero means do not delete comments within the directive.
1061 #define needs this when -traditional. */
1062 int comments
= CPP_TRADITIONAL (pfile
) && kt
->type
== T_DEFINE
;
1063 int save_put_out_comments
= CPP_OPTIONS (pfile
)->put_out_comments
;
1064 CPP_OPTIONS (pfile
)->put_out_comments
= comments
;
1065 after_ident
= CPP_WRITTEN (pfile
);
1066 copy_rest_of_line (pfile
);
1067 CPP_OPTIONS (pfile
)->put_out_comments
= save_put_out_comments
;
1070 /* We may want to pass through #define, #pragma, and #include.
1071 Other directives may create output, but we don't want the directive
1072 itself out, so we pop it now. For example conditionals may emit
1073 #failed ... #endfailed stuff. But note that popping the buffer
1074 means the parameters to kt->func may point after pfile->limit
1075 so these parameters are invalid as soon as something gets appended
1076 to the token_buffer. */
1078 line_end
= CPP_PWRITTEN (pfile
);
1079 if (! (kt
->type
== T_DEFINE
1080 || kt
->type
== T_PRAGMA
1081 || (IS_INCLUDE_DIRECTIVE_TYPE (kt
->type
)
1082 && CPP_OPTIONS (pfile
)->dump_includes
)))
1083 CPP_SET_WRITTEN (pfile
, old_written
);
1085 (*kt
->func
) (pfile
, kt
, pfile
->token_buffer
+ after_ident
, line_end
);
1087 if (kt
->type
== T_DEFINE
)
1089 if (CPP_OPTIONS (pfile
)->dump_macros
== dump_names
)
1091 /* Skip "#define". */
1092 U_CHAR
*p
= pfile
->token_buffer
+ old_written
+ 7;
1094 SKIP_WHITE_SPACE (p
);
1095 while (is_idchar
[*p
]) p
++;
1097 CPP_PUTC (pfile
, '\n');
1099 else if (CPP_OPTIONS (pfile
)->dump_macros
!= dump_definitions
)
1100 CPP_SET_WRITTEN (pfile
, old_written
);
1110 /* Pass a directive through to the output file.
1111 BUF points to the contents of the directive, as a contiguous string.
1112 LIMIT points to the first character past the end of the directive.
1113 KEYWORD is the keyword-table entry for the directive. */
1116 pass_thru_directive (buf
, limit
, pfile
, keyword
)
1117 U_CHAR
*buf
, *limit
;
1119 struct directive
*keyword
;
1121 register unsigned keyword_length
= keyword
->length
;
1123 CPP_RESERVE (pfile
, 1 + keyword_length
+ (limit
- buf
));
1124 CPP_PUTC_Q (pfile
, '#');
1125 CPP_PUTS_Q (pfile
, keyword
->name
, keyword_length
);
1126 if (limit
!= buf
&& buf
[0] != ' ')
1127 CPP_PUTC_Q (pfile
, ' ');
1128 CPP_PUTS_Q (pfile
, buf
, limit
- buf
);
1130 CPP_PUTS_Q (pfile
, '\n');
1131 /* Count the line we have just made in the output,
1132 to get in sync properly. */
1137 /* The arglist structure is built by do_define to tell
1138 collect_definition where the argument names begin. That
1139 is, for a define like "#define f(x,y,z) foo+x-bar*y", the arglist
1140 would contain pointers to the strings x, y, and z.
1141 Collect_definition would then build a DEFINITION node,
1142 with reflist nodes pointing to the places x, y, and z had
1143 appeared. So the arglist is just convenience data passed
1144 between these two routines. It is not kept around after
1145 the current #define has been processed and entered into the
1149 struct arglist
*next
;
1156 /* Read a replacement list for a macro with parameters.
1157 Build the DEFINITION structure.
1158 Reads characters of text starting at BUF until END.
1159 ARGLIST specifies the formal parameters to look for
1160 in the text of the definition; NARGS is the number of args
1161 in that list, or -1 for a macro name that wants no argument list.
1162 MACRONAME is the macro name itself (so we can avoid recursive expansion)
1163 and NAMELEN is its length in characters.
1165 Note that comments, backslash-newlines, and leading white space
1166 have already been deleted from the argument. */
1169 collect_expansion (pfile
, buf
, limit
, nargs
, arglist
)
1171 U_CHAR
*buf
, *limit
;
1173 struct arglist
*arglist
;
1176 register U_CHAR
*p
, *lastp
, *exp_p
;
1177 struct reflist
*endpat
= NULL
;
1178 /* Pointer to first nonspace after last ## seen. */
1180 /* Pointer to first nonspace after last single-# seen. */
1181 U_CHAR
*stringify
= 0;
1183 int expected_delimiter
= '\0';
1185 /* Scan thru the replacement list, ignoring comments and quoted
1186 strings, picking up on the macro calls. It does a linear search
1187 thru the arg list on every potential symbol. Profiling might say
1188 that something smarter should happen. */
1193 /* Find the beginning of the trailing whitespace. */
1195 while (p
< limit
&& is_space
[limit
[-1]]) limit
--;
1197 /* Allocate space for the text in the macro definition.
1198 Leading and trailing whitespace chars need 2 bytes each.
1199 Each other input char may or may not need 1 byte,
1200 so this is an upper bound. The extra 5 are for invented
1201 leading and trailing newline-marker and final null. */
1202 maxsize
= (sizeof (DEFINITION
)
1204 /* Occurrences of '@' get doubled, so allocate extra space for them. */
1208 defn
= (DEFINITION
*) xcalloc (1, maxsize
);
1210 defn
->nargs
= nargs
;
1211 exp_p
= defn
->expansion
= (U_CHAR
*) defn
+ sizeof (DEFINITION
);
1216 /* Add one initial space escape-marker to prevent accidental
1217 token-pasting (often removed by macroexpand). */
1221 if (limit
- p
>= 2 && p
[0] == '#' && p
[1] == '#') {
1222 cpp_error (pfile
, "`##' at start of macro definition");
1226 /* Process the main body of the definition. */
1228 int skipped_arg
= 0;
1229 register U_CHAR c
= *p
++;
1233 if (!CPP_TRADITIONAL (pfile
)) {
1237 if (expected_delimiter
!= '\0') {
1238 if (c
== expected_delimiter
)
1239 expected_delimiter
= '\0';
1241 expected_delimiter
= c
;
1245 if (p
< limit
&& expected_delimiter
) {
1246 /* In a string, backslash goes through
1247 and makes next char ordinary. */
1253 /* An '@' in a string or character constant stands for itself,
1254 and does not need to be escaped. */
1255 if (!expected_delimiter
)
1260 /* # is ordinary inside a string. */
1261 if (expected_delimiter
)
1263 if (p
< limit
&& *p
== '#') {
1264 /* ##: concatenate preceding and following tokens. */
1265 /* Take out the first #, discard preceding whitespace. */
1267 while (exp_p
> lastp
&& is_hor_space
[exp_p
[-1]])
1269 /* Skip the second #. */
1271 /* Discard following whitespace. */
1272 SKIP_WHITE_SPACE (p
);
1275 cpp_error (pfile
, "`##' at end of macro definition");
1276 } else if (nargs
>= 0) {
1277 /* Single #: stringify following argument ref.
1278 Don't leave the # in the expansion. */
1280 SKIP_WHITE_SPACE (p
);
1281 if (p
== limit
|| ! is_idstart
[*p
]
1282 || (*p
== 'L' && p
+ 1 < limit
&& (p
[1] == '\'' || p
[1] == '"')))
1284 "`#' operator is not followed by a macro argument name");
1291 /* In -traditional mode, recognize arguments inside strings and
1292 character constants, and ignore special properties of #.
1293 Arguments inside strings are considered "stringified", but no
1294 extra quote marks are supplied. */
1298 if (expected_delimiter
!= '\0') {
1299 if (c
== expected_delimiter
)
1300 expected_delimiter
= '\0';
1302 expected_delimiter
= c
;
1306 /* Backslash quotes delimiters and itself, but not macro args. */
1307 if (expected_delimiter
!= 0 && p
< limit
1308 && (*p
== expected_delimiter
|| *p
== '\\')) {
1315 if (expected_delimiter
!= '\0') /* No comments inside strings. */
1318 /* If we find a comment that wasn't removed by handle_directive,
1319 this must be -traditional. So replace the comment with
1323 while (p
< limit
&& !(p
[-2] == '*' && p
[-1] == '/'))
1326 /* Mark this as a concatenation-point, as if it had been ##. */
1334 /* Handle the start of a symbol. */
1335 if (is_idchar
[c
] && nargs
> 0) {
1336 U_CHAR
*id_beg
= p
- 1;
1340 while (p
!= limit
&& is_idchar
[*p
]) p
++;
1341 id_len
= p
- id_beg
;
1344 && ! (id_len
== 1 && c
== 'L' && (*p
== '\'' || *p
== '"'))) {
1345 register struct arglist
*arg
;
1347 for (arg
= arglist
; arg
!= NULL
; arg
= arg
->next
) {
1348 struct reflist
*tpat
;
1350 if (arg
->name
[0] == c
1351 && arg
->length
== id_len
1352 && strncmp (arg
->name
, id_beg
, id_len
) == 0) {
1353 if (expected_delimiter
&& CPP_OPTIONS (pfile
)->warn_stringify
) {
1354 if (CPP_TRADITIONAL (pfile
)) {
1355 cpp_warning (pfile
, "macro argument `%.*s' is stringified.",
1359 "macro arg `%.*s' would be stringified with -traditional.",
1363 /* If ANSI, don't actually substitute inside a string. */
1364 if (!CPP_TRADITIONAL (pfile
) && expected_delimiter
)
1366 /* make a pat node for this arg and append it to the end of
1368 tpat
= (struct reflist
*) xmalloc (sizeof (struct reflist
));
1370 tpat
->raw_before
= concat
== id_beg
;
1371 tpat
->raw_after
= 0;
1372 tpat
->rest_args
= arg
->rest_args
;
1373 tpat
->stringify
= (CPP_TRADITIONAL (pfile
)
1374 ? expected_delimiter
!= '\0'
1375 : stringify
== id_beg
);
1378 defn
->pattern
= tpat
;
1380 endpat
->next
= tpat
;
1383 tpat
->argno
= arg
->argno
;
1384 tpat
->nchars
= exp_p
- lastp
;
1386 register U_CHAR
*p1
= p
;
1387 SKIP_WHITE_SPACE (p1
);
1388 if (p1
+ 2 <= limit
&& p1
[0] == '#' && p1
[1] == '#')
1389 tpat
->raw_after
= 1;
1391 lastp
= exp_p
; /* place to start copying from next time */
1398 /* If this was not a macro arg, copy it into the expansion. */
1399 if (! skipped_arg
) {
1400 register U_CHAR
*lim1
= p
;
1404 if (stringify
== id_beg
)
1406 "`#' operator should be followed by a macro argument name");
1411 if (!CPP_TRADITIONAL (pfile
) && expected_delimiter
== 0)
1413 /* If ANSI, put in a "@ " marker to prevent token pasting.
1414 But not if "inside a string" (which in ANSI mode
1415 happens only for -D option). */
1422 defn
->length
= exp_p
- defn
->expansion
;
1424 /* Crash now if we overrun the allocated size. */
1425 if (defn
->length
+ 1 > maxsize
)
1429 /* This isn't worth the time it takes. */
1430 /* give back excess storage */
1431 defn
->expansion
= (U_CHAR
*) xrealloc (defn
->expansion
, defn
->length
+ 1);
1438 * special extension string that can be added to the last macro argument to
1439 * allow it to absorb the "rest" of the arguments when expanded. Ex:
1440 * #define wow(a, b...) process (b, a, b)
1441 * { wow (1, 2, 3); } -> { process (2, 3, 1, 2, 3); }
1442 * { wow (one, two); } -> { process (two, one, two); }
1443 * if this "rest_arg" is used with the concat token '##' and if it is not
1444 * supplied then the token attached to with ## will not be outputted. Ex:
1445 * #define wow (a, b...) process (b ## , a, ## b)
1446 * { wow (1, 2); } -> { process (2, 1, 2); }
1447 * { wow (one); } -> { process (one); {
1449 static char rest_extension
[] = "...";
1450 #define REST_EXTENSION_LENGTH (sizeof (rest_extension) - 1)
1452 /* Create a DEFINITION node from a #define directive. Arguments are
1453 as for do_define. */
1456 create_definition (buf
, limit
, pfile
, predefinition
)
1457 U_CHAR
*buf
, *limit
;
1461 U_CHAR
*bp
; /* temp ptr into input buffer */
1462 U_CHAR
*symname
; /* remember where symbol name starts */
1463 int sym_length
; /* and how long it is */
1466 char *file
= CPP_BUFFER (pfile
) ? CPP_BUFFER (pfile
)->nominal_fname
: "";
1468 int arglengths
= 0; /* Accumulate lengths of arg names
1469 plus number of args. */
1471 cpp_buf_line_and_col (CPP_BUFFER (pfile
), &line
, &col
);
1475 while (is_hor_space
[*bp
])
1478 symname
= bp
; /* remember where it starts */
1480 sym_length
= check_macro_name (pfile
, bp
, "macro");
1483 /* Lossage will occur if identifiers or control keywords are broken
1484 across lines using backslash. This is not the right place to take
1488 struct arglist
*arg_ptrs
= NULL
;
1491 bp
++; /* skip '(' */
1492 SKIP_WHITE_SPACE (bp
);
1494 /* Loop over macro argument names. */
1495 while (*bp
!= ')') {
1496 struct arglist
*temp
;
1498 temp
= (struct arglist
*) alloca (sizeof (struct arglist
));
1500 temp
->next
= arg_ptrs
;
1501 temp
->argno
= argno
++;
1502 temp
->rest_args
= 0;
1506 cpp_pedwarn (pfile
, "another parameter follows `%s'", rest_extension
);
1508 if (!is_idstart
[*bp
])
1509 cpp_pedwarn (pfile
, "invalid character in macro parameter name");
1511 /* Find the end of the arg name. */
1512 while (is_idchar
[*bp
]) {
1514 /* do we have a "special" rest-args extension here? */
1515 if (limit
- bp
> REST_EXTENSION_LENGTH
1516 && strncmp (rest_extension
, bp
, REST_EXTENSION_LENGTH
) == 0) {
1518 temp
->rest_args
= 1;
1522 temp
->length
= bp
- temp
->name
;
1524 bp
+= REST_EXTENSION_LENGTH
;
1525 arglengths
+= temp
->length
+ 2;
1526 SKIP_WHITE_SPACE (bp
);
1527 if (temp
->length
== 0 || (*bp
!= ',' && *bp
!= ')')) {
1528 cpp_error (pfile
, "badly punctuated parameter list in `#define'");
1533 SKIP_WHITE_SPACE (bp
);
1536 cpp_error (pfile
, "unterminated parameter list in `#define'");
1540 struct arglist
*otemp
;
1542 for (otemp
= temp
->next
; otemp
!= NULL
; otemp
= otemp
->next
)
1543 if (temp
->length
== otemp
->length
1544 && strncmp (temp
->name
, otemp
->name
, temp
->length
) == 0) {
1547 name
= (U_CHAR
*) alloca (temp
->length
+ 1);
1548 (void) strncpy (name
, temp
->name
, temp
->length
);
1549 name
[temp
->length
] = '\0';
1551 "duplicate argument name `%s' in `#define'", name
);
1557 ++bp
; /* skip paren */
1558 SKIP_WHITE_SPACE (bp
);
1559 /* now everything from bp before limit is the definition. */
1560 defn
= collect_expansion (pfile
, bp
, limit
, argno
, arg_ptrs
);
1561 defn
->rest_args
= rest_args
;
1563 /* Now set defn->args.argnames to the result of concatenating
1564 the argument names in reverse order
1565 with comma-space between them. */
1566 defn
->args
.argnames
= (U_CHAR
*) xmalloc (arglengths
+ 1);
1568 struct arglist
*temp
;
1570 for (temp
= arg_ptrs
; temp
; temp
= temp
->next
) {
1571 bcopy (temp
->name
, &defn
->args
.argnames
[i
], temp
->length
);
1573 if (temp
->next
!= 0) {
1574 defn
->args
.argnames
[i
++] = ',';
1575 defn
->args
.argnames
[i
++] = ' ';
1578 defn
->args
.argnames
[i
] = 0;
1581 /* Simple expansion or empty definition. */
1585 if (is_hor_space
[*bp
]) {
1587 SKIP_WHITE_SPACE (bp
);
1590 case '!': case '"': case '#': case '%': case '&': case '\'':
1591 case ')': case '*': case '+': case ',': case '-': case '.':
1592 case '/': case ':': case ';': case '<': case '=': case '>':
1593 case '?': case '[': case '\\': case ']': case '^': case '{':
1594 case '|': case '}': case '~':
1595 cpp_warning (pfile
, "missing white space after `#define %.*s'",
1596 sym_length
, symname
);
1600 cpp_pedwarn (pfile
, "missing white space after `#define %.*s'",
1601 sym_length
, symname
);
1606 /* now everything from bp before limit is the definition. */
1607 defn
= collect_expansion (pfile
, bp
, limit
, -1, NULL_PTR
);
1608 defn
->args
.argnames
= (U_CHAR
*) "";
1614 /* OP is null if this is a predefinition */
1615 defn
->predefined
= predefinition
;
1617 mdef
.symnam
= symname
;
1618 mdef
.symlen
= sym_length
;
1627 /* Check a purported macro name SYMNAME, and yield its length.
1628 USAGE is the kind of name this is intended for. */
1631 check_macro_name (pfile
, symname
, usage
)
1639 for (p
= symname
; is_idchar
[*p
]; p
++)
1641 sym_length
= p
- symname
;
1643 || (sym_length
== 1 && *symname
== 'L' && (*p
== '\'' || *p
== '"')))
1644 cpp_error (pfile
, "invalid %s name", usage
);
1645 else if (!is_idstart
[*symname
]) {
1646 U_CHAR
*msg
; /* what pain... */
1647 msg
= (U_CHAR
*) alloca (sym_length
+ 1);
1648 bcopy (symname
, msg
, sym_length
);
1649 msg
[sym_length
] = 0;
1650 cpp_error (pfile
, "invalid %s name `%s'", usage
, msg
);
1652 if (! strncmp (symname
, "defined", 7) && sym_length
== 7)
1653 cpp_error (pfile
, "invalid %s name `defined'", usage
);
1658 /* Return zero if two DEFINITIONs are isomorphic. */
1661 compare_defs (pfile
, d1
, d2
)
1663 DEFINITION
*d1
, *d2
;
1665 register struct reflist
*a1
, *a2
;
1666 register U_CHAR
*p1
= d1
->expansion
;
1667 register U_CHAR
*p2
= d2
->expansion
;
1670 if (d1
->nargs
!= d2
->nargs
)
1672 if (CPP_PEDANTIC (pfile
)
1673 && strcmp ((char *)d1
->args
.argnames
, (char *)d2
->args
.argnames
))
1675 for (a1
= d1
->pattern
, a2
= d2
->pattern
; a1
&& a2
;
1676 a1
= a1
->next
, a2
= a2
->next
) {
1677 if (!((a1
->nchars
== a2
->nchars
&& ! strncmp (p1
, p2
, a1
->nchars
))
1678 || ! comp_def_part (first
, p1
, a1
->nchars
, p2
, a2
->nchars
, 0))
1679 || a1
->argno
!= a2
->argno
1680 || a1
->stringify
!= a2
->stringify
1681 || a1
->raw_before
!= a2
->raw_before
1682 || a1
->raw_after
!= a2
->raw_after
)
1690 if (comp_def_part (first
, p1
, d1
->length
- (p1
- d1
->expansion
),
1691 p2
, d2
->length
- (p2
- d2
->expansion
), 1))
1696 /* Return 1 if two parts of two macro definitions are effectively different.
1697 One of the parts starts at BEG1 and has LEN1 chars;
1698 the other has LEN2 chars at BEG2.
1699 Any sequence of whitespace matches any other sequence of whitespace.
1700 FIRST means these parts are the first of a macro definition;
1701 so ignore leading whitespace entirely.
1702 LAST means these parts are the last of a macro definition;
1703 so ignore trailing whitespace entirely. */
1706 comp_def_part (first
, beg1
, len1
, beg2
, len2
, last
)
1708 U_CHAR
*beg1
, *beg2
;
1712 register U_CHAR
*end1
= beg1
+ len1
;
1713 register U_CHAR
*end2
= beg2
+ len2
;
1715 while (beg1
!= end1
&& is_space
[*beg1
]) beg1
++;
1716 while (beg2
!= end2
&& is_space
[*beg2
]) beg2
++;
1719 while (beg1
!= end1
&& is_space
[end1
[-1]]) end1
--;
1720 while (beg2
!= end2
&& is_space
[end2
[-1]]) end2
--;
1722 while (beg1
!= end1
&& beg2
!= end2
) {
1723 if (is_space
[*beg1
] && is_space
[*beg2
]) {
1724 while (beg1
!= end1
&& is_space
[*beg1
]) beg1
++;
1725 while (beg2
!= end2
&& is_space
[*beg2
]) beg2
++;
1726 } else if (*beg1
== *beg2
) {
1730 return (beg1
!= end1
) || (beg2
!= end2
);
1733 /* Process a #define command.
1734 BUF points to the contents of the #define command, as a contiguous string.
1735 LIMIT points to the first character past the end of the definition.
1736 KEYWORD is the keyword-table entry for #define,
1737 or NULL for a "predefined" macro. */
1740 do_define (pfile
, keyword
, buf
, limit
)
1742 struct directive
*keyword
;
1743 U_CHAR
*buf
, *limit
;
1750 /* If this is a precompiler run (with -pcp) pass thru #define commands. */
1751 if (pcp_outfile
&& keyword
)
1752 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1755 mdef
= create_definition (buf
, limit
, pfile
, keyword
== NULL
);
1759 hashcode
= hashf (mdef
.symnam
, mdef
.symlen
, HASHSIZE
);
1761 if ((hp
= cpp_lookup (pfile
, mdef
.symnam
, mdef
.symlen
, hashcode
)) != NULL
)
1764 /* Redefining a precompiled key is ok. */
1765 if (hp
->type
== T_PCSTRING
)
1767 /* Redefining a macro is ok if the definitions are the same. */
1768 else if (hp
->type
== T_MACRO
)
1769 ok
= ! compare_defs (pfile
, mdef
.defn
, hp
->value
.defn
);
1770 /* Redefining a constant is ok with -D. */
1771 else if (hp
->type
== T_CONST
)
1772 ok
= ! CPP_OPTIONS (pfile
)->done_initializing
;
1773 /* Print the warning if it's not ok. */
1776 U_CHAR
*msg
; /* what pain... */
1778 /* If we are passing through #define and #undef directives, do
1779 that for this re-definition now. */
1780 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
1781 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1783 msg
= (U_CHAR
*) alloca (mdef
.symlen
+ 22);
1785 bcopy (mdef
.symnam
, msg
+ 1, mdef
.symlen
);
1786 strcpy ((char *) (msg
+ mdef
.symlen
+ 1), "' redefined");
1787 cpp_pedwarn (pfile
, msg
);
1788 if (hp
->type
== T_MACRO
)
1789 cpp_pedwarn_with_file_and_line (pfile
, hp
->value
.defn
->file
, hp
->value
.defn
->line
,
1790 "this is the location of the previous definition");
1792 /* Replace the old definition. */
1794 hp
->value
.defn
= mdef
.defn
;
1798 /* If we are passing through #define and #undef directives, do
1799 that for this new definition now. */
1800 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
1801 pass_thru_directive (buf
, limit
, pfile
, keyword
);
1802 install (mdef
.symnam
, mdef
.symlen
, T_MACRO
, 0,
1803 (char *) mdef
.defn
, hashcode
);
1813 /* This structure represents one parsed argument in a macro call.
1814 `raw' points to the argument text as written (`raw_length' is its length).
1815 `expanded' points to the argument's macro-expansion
1816 (its length is `expand_length').
1817 `stringified_length' is the length the argument would have
1819 `use_count' is the number of times this macro arg is substituted
1820 into the macro. If the actual use count exceeds 10,
1821 the value stored is 10. */
1823 /* raw and expanded are relative to ARG_BASE */
1824 #define ARG_BASE ((pfile)->token_buffer)
1827 /* Strings relative to pfile->token_buffer */
1828 long raw
, expanded
, stringified
;
1829 int raw_length
, expand_length
;
1830 int stringified_length
;
1835 /* Allocate a new cpp_buffer for PFILE, and push it on the input buffer stack.
1836 If BUFFER != NULL, then use the LENGTH characters in BUFFER
1837 as the new input buffer.
1838 Return the new buffer, or NULL on failure. */
1841 cpp_push_buffer (pfile
, buffer
, length
)
1846 register cpp_buffer
*buf
= CPP_BUFFER (pfile
);
1847 if (buf
== pfile
->buffer_stack
)
1849 cpp_fatal (pfile
, "%s: macro or `#include' recursion too deep",
1854 bzero ((char *) buf
, sizeof (cpp_buffer
));
1855 CPP_BUFFER (pfile
) = buf
;
1856 buf
->if_stack
= pfile
->if_stack
;
1857 buf
->cleanup
= null_cleanup
;
1858 buf
->underflow
= null_underflow
;
1859 buf
->buf
= buf
->cur
= buffer
;
1860 buf
->alimit
= buf
->rlimit
= buffer
+ length
;
1866 cpp_pop_buffer (pfile
)
1869 cpp_buffer
*buf
= CPP_BUFFER (pfile
);
1870 (*buf
->cleanup
) (buf
, pfile
);
1871 return ++CPP_BUFFER (pfile
);
1874 /* Scan until CPP_BUFFER (PFILE) is exhausted into PFILE->token_buffer.
1875 Pop the buffer when done. */
1878 cpp_scan_buffer (pfile
)
1881 cpp_buffer
*buffer
= CPP_BUFFER (pfile
);
1884 enum cpp_token token
= cpp_get_token (pfile
);
1885 if (token
== CPP_EOF
) /* Should not happen ... */
1887 if (token
== CPP_POP
&& CPP_BUFFER (pfile
) == buffer
)
1889 cpp_pop_buffer (pfile
);
1896 * Rescan a string (which may have escape marks) into pfile's buffer.
1897 * Place the result in pfile->token_buffer.
1899 * The input is copied before it is scanned, so it is safe to pass
1900 * it something from the token_buffer that will get overwritten
1901 * (because it follows CPP_WRITTEN). This is used by do_include.
1905 cpp_expand_to_buffer (pfile
, buf
, length
)
1910 register cpp_buffer
*ip
;
1914 U_CHAR
*limit
= buf
+ length
;
1917 int odepth
= indepth
;
1923 /* Set up the input on the input stack. */
1925 buf1
= (U_CHAR
*) alloca (length
+ 1);
1927 register U_CHAR
*p1
= buf
;
1928 register U_CHAR
*p2
= buf1
;
1935 ip
= cpp_push_buffer (pfile
, buf1
, length
);
1938 ip
->has_escapes
= 1;
1940 ip
->lineno
= obuf
.lineno
= 1;
1943 /* Scan the input, create the output. */
1944 cpp_scan_buffer (pfile
);
1947 if (indepth
!= odepth
)
1951 CPP_NUL_TERMINATE (pfile
);
1956 adjust_position (buf
, limit
, linep
, colp
)
1966 (*linep
)++, (*colp
) = 1;
1972 /* Move line_base forward, updating lineno and colno. */
1975 update_position (pbuf
)
1976 register cpp_buffer
*pbuf
;
1978 unsigned char *old_pos
= pbuf
->buf
+ pbuf
->line_base
;
1979 unsigned char *new_pos
= pbuf
->cur
;
1980 register struct parse_marker
*mark
;
1981 for (mark
= pbuf
->marks
; mark
!= NULL
; mark
= mark
->next
)
1983 if (pbuf
->buf
+ mark
->position
< new_pos
)
1984 new_pos
= pbuf
->buf
+ mark
->position
;
1986 pbuf
->line_base
+= new_pos
- old_pos
;
1987 adjust_position (old_pos
, new_pos
, &pbuf
->lineno
, &pbuf
->colno
);
1991 cpp_buf_line_and_col (pbuf
, linep
, colp
)
1992 register cpp_buffer
*pbuf
;
2000 *linep
= pbuf
->lineno
;
2001 *colp
= pbuf
->colno
;
2002 adjust_position (pbuf
->buf
+ pbuf
->line_base
, pbuf
->cur
, linep
, colp
);
2011 /* Return the cpp_buffer that corresponds to a file (not a macro). */
2014 cpp_file_buffer (pfile
)
2017 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
2019 for ( ; ip
!= CPP_NULL_BUFFER (pfile
); ip
= CPP_PREV_BUFFER (ip
))
2020 if (ip
->fname
!= NULL
)
2026 count_newlines (buf
, limit
)
2027 register U_CHAR
*buf
;
2028 register U_CHAR
*limit
;
2030 register long count
= 0;
2041 * write out a #line command, for instance, after an #include file.
2042 * If CONDITIONAL is nonzero, we can omit the #line if it would
2043 * appear to be a no-op, and we can output a few newlines instead
2044 * if we want to increase the line number by a small amount.
2045 * FILE_CHANGE says whether we are entering a file, leaving, or neither.
2049 output_line_command (pfile
, conditional
, file_change
)
2052 enum file_change_code file_change
;
2055 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
2057 if (ip
->fname
== NULL
)
2060 update_position (ip
);
2062 if (CPP_OPTIONS (pfile
)->no_line_commands
2063 || CPP_OPTIONS (pfile
)->no_output
)
2066 line
= CPP_BUFFER (pfile
)->lineno
;
2067 col
= CPP_BUFFER (pfile
)->colno
;
2068 adjust_position (CPP_LINE_BASE (ip
), ip
->cur
, &line
, &col
);
2070 if (CPP_OPTIONS (pfile
)->no_line_commands
)
2074 if (line
== pfile
->lineno
)
2077 /* If the inherited line number is a little too small,
2078 output some newlines instead of a #line command. */
2079 if (line
> pfile
->lineno
&& line
< pfile
->lineno
+ 8) {
2080 CPP_RESERVE (pfile
, 20);
2081 while (line
> pfile
->lineno
) {
2082 CPP_PUTC_Q (pfile
, '\n');
2090 /* Don't output a line number of 0 if we can help it. */
2091 if (ip
->lineno
== 0 && ip
->bufp
- ip
->buf
< ip
->length
2092 && *ip
->bufp
== '\n') {
2098 CPP_RESERVE (pfile
, 4 * strlen (ip
->nominal_fname
) + 50);
2100 #ifdef OUTPUT_LINE_COMMANDS
2101 static char sharp_line
[] = "#line ";
2103 static char sharp_line
[] = "# ";
2105 CPP_PUTS_Q (pfile
, sharp_line
, sizeof(sharp_line
)-1);
2108 sprintf ((char *) CPP_PWRITTEN (pfile
), "%ld ", line
);
2109 CPP_ADJUST_WRITTEN (pfile
, strlen (CPP_PWRITTEN (pfile
)));
2111 quote_string (pfile
, ip
->nominal_fname
);
2112 if (file_change
!= same_file
) {
2113 CPP_PUTC_Q (pfile
, ' ');
2114 CPP_PUTC_Q (pfile
, file_change
== enter_file
? '1' : '2');
2116 /* Tell cc1 if following text comes from a system header file. */
2117 if (ip
->system_header_p
) {
2118 CPP_PUTC_Q (pfile
, ' ');
2119 CPP_PUTC_Q (pfile
, '3');
2121 #ifndef NO_IMPLICIT_EXTERN_C
2122 /* Tell cc1plus if following text should be treated as C. */
2123 if (ip
->system_header_p
== 2 && CPP_OPTIONS (pfile
)->cplusplus
) {
2124 CPP_PUTC_Q (pfile
, ' ');
2125 CPP_PUTC_Q (pfile
, '4');
2128 CPP_PUTC_Q (pfile
, '\n');
2129 pfile
->lineno
= line
;
2133 * Parse a macro argument and append the info on PFILE's token_buffer.
2134 * REST_ARGS means to absorb the rest of the args.
2135 * Return nonzero to indicate a syntax error.
2138 static enum cpp_token
2139 macarg (pfile
, rest_args
)
2144 enum cpp_token token
;
2145 char save_put_out_comments
= CPP_OPTIONS (pfile
)->put_out_comments
;
2146 CPP_OPTIONS (pfile
)->put_out_comments
= 0;
2148 /* Try to parse as much of the argument as exists at this
2149 input stack level. */
2150 pfile
->no_macro_expand
++;
2153 token
= cpp_get_token (pfile
);
2159 /* If we've hit end of file, it's an error (reported by caller).
2160 Ditto if it's the end of cpp_expand_to_buffer text.
2161 If we've hit end of macro, just continue. */
2162 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
2173 /* if we've returned to lowest level and
2174 we aren't absorbing all args */
2175 if (paren
== 0 && rest_args
== 0)
2179 /* Remove ',' or ')' from argument buffer. */
2180 CPP_ADJUST_WRITTEN (pfile
, -1);
2187 CPP_OPTIONS (pfile
)->put_out_comments
= save_put_out_comments
;
2188 pfile
->no_macro_expand
--;
2193 /* Turn newlines to spaces in the string of length LENGTH at START,
2194 except inside of string constants.
2195 The string is copied into itself with its beginning staying fixed. */
2198 change_newlines (start
, length
)
2202 register U_CHAR
*ibp
;
2203 register U_CHAR
*obp
;
2204 register U_CHAR
*limit
;
2208 limit
= start
+ length
;
2211 while (ibp
< limit
) {
2212 *obp
++ = c
= *ibp
++;
2217 /* Notice and skip strings, so that we don't delete newlines in them. */
2220 while (ibp
< limit
) {
2221 *obp
++ = c
= *ibp
++;
2224 if (c
== '\n' && quotec
== '\'')
2240 if (!pfile
->timebuf
) {
2241 time_t t
= time ((time_t *) 0);
2242 pfile
->timebuf
= localtime (&t
);
2244 return pfile
->timebuf
;
2247 static char *monthnames
[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
2248 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
2252 * expand things like __FILE__. Place the expansion into the output
2253 * buffer *without* rescanning.
2257 special_symbol (hp
, pfile
)
2264 cpp_buffer
*ip
= NULL
;
2267 int paren
= 0; /* For special `defined' keyword */
2270 if (pcp_outfile
&& pcp_inside_if
2271 && hp
->type
!= T_SPEC_DEFINED
&& hp
->type
!= T_CONST
)
2273 "Predefined macro `%s' used inside `#if' during precompilation",
2277 for (ip
= CPP_BUFFER (pfile
); ; ip
= CPP_PREV_BUFFER (ip
))
2279 if (ip
== CPP_NULL_BUFFER (pfile
))
2281 cpp_error (pfile
, "cccp error: not in any file?!");
2282 return; /* the show must go on */
2284 if (ip
->fname
!= NULL
)
2294 if (hp
->type
== T_BASE_FILE
)
2296 while (CPP_PREV_BUFFER (ip
) != CPP_NULL_BUFFER (pfile
))
2297 ip
= CPP_PREV_BUFFER (ip
);
2299 string
= ip
->nominal_fname
;
2303 CPP_RESERVE (pfile
, 3 + 4 * strlen (string
));
2304 quote_string (pfile
, string
);
2308 case T_INCLUDE_LEVEL
:
2310 ip
= CPP_BUFFER (pfile
);
2311 for (; ip
!= CPP_NULL_BUFFER (pfile
); ip
= CPP_PREV_BUFFER (ip
))
2312 if (ip
->fname
!= NULL
)
2315 buf
= (char *) alloca (8); /* Eight bytes ought to be more than enough */
2316 sprintf (buf
, "%d", true_indepth
- 1);
2320 buf
= (char *) alloca (3 + strlen (version_string
));
2321 sprintf (buf
, "\"%s\"", version_string
);
2324 #ifndef NO_BUILTIN_SIZE_TYPE
2330 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2331 case T_PTRDIFF_TYPE
:
2337 buf
= CPP_WCHAR_TYPE (pfile
);
2340 case T_USER_LABEL_PREFIX_TYPE
:
2341 buf
= USER_LABEL_PREFIX
;
2344 case T_REGISTER_PREFIX_TYPE
:
2345 buf
= REGISTER_PREFIX
;
2349 buf
= (char *) alloca (4 * sizeof (int));
2350 sprintf (buf
, "%d", hp
->value
.ival
);
2351 #ifdef STDC_0_IN_SYSTEM_HEADERS
2352 if (ip
->system_header_p
2353 && hp
->length
== 8 && bcmp (hp
->name
, "__STDC__", 8) == 0
2354 && ! cpp_lookup (pfile
, (U_CHAR
*) "__STRICT_ANSI__", -1, -1))
2358 if (pcp_inside_if
&& pcp_outfile
)
2359 /* Output a precondition for this macro use */
2360 fprintf (pcp_outfile
, "#define %s %d\n", hp
->name
, hp
->value
.ival
);
2366 long line
= ip
->lineno
;
2367 long col
= ip
->colno
;
2368 adjust_position (CPP_LINE_BASE (ip
), ip
->cur
, &line
, &col
);
2370 buf
= (char *) alloca (10);
2371 sprintf (buf
, "%ld", line
);
2377 buf
= (char *) alloca (20);
2378 timebuf
= timestamp (pfile
);
2379 if (hp
->type
== T_DATE
)
2380 sprintf (buf
, "\"%s %2d %4d\"", monthnames
[timebuf
->tm_mon
],
2381 timebuf
->tm_mday
, timebuf
->tm_year
+ 1900);
2383 sprintf (buf
, "\"%02d:%02d:%02d\"", timebuf
->tm_hour
, timebuf
->tm_min
,
2387 case T_SPEC_DEFINED
:
2388 buf
= " 0 "; /* Assume symbol is not defined */
2389 ip
= CPP_BUFFER (pfile
);
2390 SKIP_WHITE_SPACE (ip
->cur
);
2391 if (*ip
->cur
== '(')
2394 ip
->cur
++; /* Skip over the paren */
2395 SKIP_WHITE_SPACE (ip
->cur
);
2398 if (!is_idstart
[*ip
->cur
])
2400 if (ip
->cur
[0] == 'L' && (ip
->cur
[1] == '\'' || ip
->cur
[1] == '"'))
2402 if ((hp
= cpp_lookup (pfile
, ip
->cur
, -1, -1)))
2405 if (pcp_outfile
&& pcp_inside_if
2406 && (hp
->type
== T_CONST
2407 || (hp
->type
== T_MACRO
&& hp
->value
.defn
->predefined
)))
2408 /* Output a precondition for this macro use. */
2409 fprintf (pcp_outfile
, "#define %s\n", hp
->name
);
2415 if (pcp_outfile
&& pcp_inside_if
)
2417 /* Output a precondition for this macro use */
2418 U_CHAR
*cp
= ip
->bufp
;
2419 fprintf (pcp_outfile
, "#undef ");
2420 while (is_idchar
[*cp
]) /* Ick! */
2421 fputc (*cp
++, pcp_outfile
);
2422 putc ('\n', pcp_outfile
);
2425 while (is_idchar
[*ip
->cur
])
2427 SKIP_WHITE_SPACE (ip
->cur
);
2430 if (*ip
->cur
!= ')')
2438 cpp_error (pfile
, "`defined' without an identifier");
2442 cpp_error (pfile
, "cccp error: invalid special hash type"); /* time for gdb */
2446 CPP_RESERVE (pfile
, len
+ 1);
2447 CPP_PUTS_Q (pfile
, buf
, len
);
2448 CPP_NUL_TERMINATE_Q (pfile
);
2453 /* Write out a #define command for the special named MACRO_NAME
2454 to PFILE's token_buffer. */
2457 dump_special_to_buffer (pfile
, macro_name
)
2461 static char define_directive
[] = "#define ";
2462 int macro_name_length
= strlen (macro_name
);
2463 output_line_command (pfile
, 0, same_file
);
2464 CPP_RESERVE (pfile
, sizeof(define_directive
) + macro_name_length
);
2465 CPP_PUTS_Q (pfile
, define_directive
, sizeof(define_directive
)-1);
2466 CPP_PUTS_Q (pfile
, macro_name
, macro_name_length
);
2467 CPP_PUTC_Q (pfile
, ' ');
2468 cpp_expand_to_buffer (pfile
, macro_name
, macro_name_length
);
2469 CPP_PUTC (pfile
, '\n');
2472 /* Initialize the built-in macros. */
2475 initialize_builtins (pfile
)
2478 install ((U_CHAR
*)"__LINE__", -1, T_SPECLINE
, 0, 0, -1);
2479 install ((U_CHAR
*)"__DATE__", -1, T_DATE
, 0, 0, -1);
2480 install ((U_CHAR
*)"__FILE__", -1, T_FILE
, 0, 0, -1);
2481 install ((U_CHAR
*)"__BASE_FILE__", -1, T_BASE_FILE
, 0, 0, -1);
2482 install ((U_CHAR
*)"__INCLUDE_LEVEL__", -1, T_INCLUDE_LEVEL
, 0, 0, -1);
2483 install ((U_CHAR
*)"__VERSION__", -1, T_VERSION
, 0, 0, -1);
2484 #ifndef NO_BUILTIN_SIZE_TYPE
2485 install ((U_CHAR
*)"__SIZE_TYPE__", -1, T_SIZE_TYPE
, 0, 0, -1);
2487 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2488 install ((U_CHAR
*)"__PTRDIFF_TYPE__ ", -1, T_PTRDIFF_TYPE
, 0, 0, -1);
2490 install ((U_CHAR
*)"__WCHAR_TYPE__", -1, T_WCHAR_TYPE
, 0, 0, -1);
2491 install ((U_CHAR
*)"__USER_LABEL_PREFIX__", -1, T_USER_LABEL_PREFIX_TYPE
, 0, 0, -1);
2492 install ((U_CHAR
*)"__REGISTER_PREFIX__", -1, T_REGISTER_PREFIX_TYPE
, 0, 0, -1);
2493 install ((U_CHAR
*)"__TIME__", -1, T_TIME
, 0, 0, -1);
2494 if (!CPP_TRADITIONAL (pfile
))
2495 install ((U_CHAR
*)"__STDC__", -1, T_CONST
, STDC_VALUE
, 0, -1);
2496 if (CPP_OPTIONS (pfile
)->objc
)
2497 install ((U_CHAR
*)"__OBJC__", -1, T_CONST
, 1, 0, -1);
2498 /* This is supplied using a -D by the compiler driver
2499 so that it is present only when truly compiling with GNU C. */
2500 /* install ("__GNUC__", -1, T_CONST, 2, 0, -1); */
2502 if (CPP_OPTIONS (pfile
)->debug_output
)
2504 dump_special_to_buffer (pfile
, "__BASE_FILE__");
2505 dump_special_to_buffer (pfile
, "__VERSION__");
2506 #ifndef NO_BUILTIN_SIZE_TYPE
2507 dump_special_to_buffer (pfile
, "__SIZE_TYPE__");
2509 #ifndef NO_BUILTIN_PTRDIFF_TYPE
2510 dump_special_to_buffer (pfile
, "__PTRDIFF_TYPE__");
2512 dump_special_to_buffer (pfile
, "__WCHAR_TYPE__");
2513 dump_special_to_buffer (pfile
, "__DATE__");
2514 dump_special_to_buffer (pfile
, "__TIME__");
2515 if (!CPP_TRADITIONAL (pfile
))
2516 dump_special_to_buffer (pfile
, "__STDC__");
2517 if (CPP_OPTIONS (pfile
)->objc
)
2518 dump_special_to_buffer (pfile
, "__OBJC__");
2522 /* Return 1 iff a token ending in C1 followed directly by a token C2
2523 could cause mis-tokenization. */
2526 unsafe_chars (c1
, c2
)
2532 if (c2
== c1
|| c2
== '=')
2536 case '0': case '1': case '2': case '3': case '4':
2537 case '5': case '6': case '7': case '8': case '9':
2538 case 'e': case 'E': case 'p': case 'P':
2539 if (c2
== '-' || c2
== '+')
2540 return 1; /* could extend a pre-processing number */
2543 if (c2
== '\'' || c2
== '\"')
2544 return 1; /* Could turn into L"xxx" or L'xxx'. */
2548 case 'a': case 'b': case 'c': case 'd': case 'f':
2549 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
2550 case 'm': case 'n': case 'o': case 'q': case 'r':
2551 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
2553 case 'A': case 'B': case 'C': case 'D': case 'F':
2554 case 'G': case 'H': case 'I': case 'J': case 'K':
2555 case 'M': case 'N': case 'O': case 'Q': case 'R':
2556 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
2558 /* We're in the middle of either a name or a pre-processing number. */
2559 return (is_idchar
[c2
] || c2
== '.');
2560 case '<': case '>': case '!': case '%': case '#': case ':':
2561 case '^': case '&': case '|': case '*': case '/': case '=':
2562 return (c2
== c1
|| c2
== '=');
2567 /* Expand a macro call.
2568 HP points to the symbol that is the macro being called.
2569 Put the result of expansion onto the input stack
2570 so that subsequent input by our caller will use it.
2572 If macro wants arguments, caller has already verified that
2573 an argument list follows; arguments come from the input stack. */
2576 macroexpand (pfile
, hp
)
2581 DEFINITION
*defn
= hp
->value
.defn
;
2582 register U_CHAR
*xbuf
;
2583 long start_line
, start_column
;
2585 struct argdata
*args
;
2586 long old_written
= CPP_WRITTEN (pfile
);
2588 int start_line
= instack
[indepth
].lineno
;
2590 int rest_args
, rest_zero
;
2594 CHECK_DEPTH (return;);
2598 /* This macro is being used inside a #if, which means it must be */
2599 /* recorded as a precondition. */
2600 if (pcp_inside_if
&& pcp_outfile
&& defn
->predefined
)
2601 dump_single_macro (hp
, pcp_outfile
);
2604 pfile
->output_escapes
++;
2605 cpp_buf_line_and_col (cpp_file_buffer (pfile
), &start_line
, &start_column
);
2607 nargs
= defn
->nargs
;
2611 enum cpp_token token
;
2613 args
= (struct argdata
*) alloca ((nargs
+ 1) * sizeof (struct argdata
));
2615 for (i
= 0; i
< nargs
; i
++)
2617 args
[i
].raw
= args
[i
].expanded
= 0;
2618 args
[i
].raw_length
= 0;
2619 args
[i
].expand_length
= args
[i
].stringified_length
= -1;
2620 args
[i
].use_count
= 0;
2623 /* Parse all the macro args that are supplied. I counts them.
2624 The first NARGS args are stored in ARGS.
2625 The rest are discarded. If rest_args is set then we assume
2626 macarg absorbed the rest of the args. */
2630 FORWARD(1); /* Discard the open-parenthesis before the first arg. */
2635 if (i
< nargs
|| (nargs
== 0 && i
== 0))
2637 /* if we are working on last arg which absorbs rest of args... */
2638 if (i
== nargs
- 1 && defn
->rest_args
)
2640 args
[i
].raw
= CPP_WRITTEN (pfile
);
2641 token
= macarg (pfile
, rest_args
);
2642 args
[i
].raw_length
= CPP_WRITTEN (pfile
) - args
[i
].raw
;
2643 args
[i
].newlines
= 0; /* FIXME */
2646 token
= macarg (pfile
, 0);
2647 if (token
== CPP_EOF
|| token
== CPP_POP
)
2649 cpp_error_with_line (pfile
, start_line
, start_column
,
2650 "unterminated macro call");
2654 } while (token
== CPP_COMMA
);
2656 /* If we got one arg but it was just whitespace, call that 0 args. */
2659 register U_CHAR
*bp
= ARG_BASE
+ args
[0].raw
;
2660 register U_CHAR
*lim
= bp
+ args
[0].raw_length
;
2661 /* cpp.texi says for foo ( ) we provide one argument.
2662 However, if foo wants just 0 arguments, treat this as 0. */
2664 while (bp
!= lim
&& is_space
[*bp
]) bp
++;
2669 /* Don't output an error message if we have already output one for
2670 a parse error above. */
2672 if (nargs
== 0 && i
> 0)
2674 cpp_error (pfile
, "arguments given to macro `%s'", hp
->name
);
2678 /* traditional C allows foo() if foo wants one argument. */
2679 if (nargs
== 1 && i
== 0 && CPP_TRADITIONAL (pfile
))
2681 /* the rest args token is allowed to absorb 0 tokens */
2682 else if (i
== nargs
- 1 && defn
->rest_args
)
2685 cpp_error (pfile
, "macro `%s' used without args", hp
->name
);
2687 cpp_error (pfile
, "macro `%s' used with just one arg", hp
->name
);
2689 cpp_error (pfile
, "macro `%s' used with only %d args",
2695 "macro `%s' used with too many (%d) args", hp
->name
, i
);
2699 /* If macro wants zero args, we parsed the arglist for checking only.
2700 Read directly from the macro definition. */
2703 xbuf
= defn
->expansion
;
2704 xbuf_len
= defn
->length
;
2708 register U_CHAR
*exp
= defn
->expansion
;
2709 register int offset
; /* offset in expansion,
2710 copied a piece at a time */
2711 register int totlen
; /* total amount of exp buffer filled so far */
2713 register struct reflist
*ap
, *last_ap
;
2715 /* Macro really takes args. Compute the expansion of this call. */
2717 /* Compute length in characters of the macro's expansion.
2718 Also count number of times each arg is used. */
2719 xbuf_len
= defn
->length
;
2720 for (ap
= defn
->pattern
; ap
!= NULL
; ap
= ap
->next
)
2724 register struct argdata
*arg
= &args
[ap
->argno
];
2725 /* Stringify if it hasn't already been */
2726 if (arg
->stringified_length
< 0)
2728 int arglen
= arg
->raw_length
;
2732 /* Initially need_space is -1. Otherwise, 1 means the
2733 previous character was a space, but we suppressed it;
2734 0 means the previous character was a non-space. */
2735 int need_space
= -1;
2737 arg
->stringified
= CPP_WRITTEN (pfile
);
2738 if (!CPP_TRADITIONAL (pfile
))
2739 CPP_PUTC (pfile
, '\"'); /* insert beginning quote */
2740 for (; i
< arglen
; i
++)
2742 c
= (ARG_BASE
+ arg
->raw
)[i
];
2746 /* Internal sequences of whitespace are replaced by
2747 one space except within an string or char token.*/
2750 if (CPP_WRITTEN (pfile
) > arg
->stringified
2751 && (CPP_PWRITTEN (pfile
))[-1] == '@')
2753 /* "@ " escape markers are removed */
2754 CPP_ADJUST_WRITTEN (pfile
, -1);
2757 if (need_space
== 0)
2761 else if (need_space
> 0)
2762 CPP_PUTC (pfile
, ' ');
2777 else if (c
== '\"' || c
== '\'')
2781 /* Escape these chars */
2782 if (c
== '\"' || (in_string
&& c
== '\\'))
2783 CPP_PUTC (pfile
, '\\');
2785 CPP_PUTC (pfile
, c
);
2788 CPP_RESERVE (pfile
, 4);
2789 sprintf ((char *)CPP_PWRITTEN (pfile
), "\\%03o",
2791 CPP_ADJUST_WRITTEN (pfile
, 4);
2794 if (!CPP_TRADITIONAL (pfile
))
2795 CPP_PUTC (pfile
, '\"'); /* insert ending quote */
2796 arg
->stringified_length
2797 = CPP_WRITTEN (pfile
) - arg
->stringified
;
2799 xbuf_len
+= args
[ap
->argno
].stringified_length
;
2801 else if (ap
->raw_before
|| ap
->raw_after
|| CPP_TRADITIONAL (pfile
))
2802 /* Add 4 for two newline-space markers to prevent
2803 token concatenation. */
2804 xbuf_len
+= args
[ap
->argno
].raw_length
+ 4;
2807 /* We have an ordinary (expanded) occurrence of the arg.
2808 So compute its expansion, if we have not already. */
2809 if (args
[ap
->argno
].expand_length
< 0)
2811 args
[ap
->argno
].expanded
= CPP_WRITTEN (pfile
);
2812 cpp_expand_to_buffer (pfile
,
2813 ARG_BASE
+ args
[ap
->argno
].raw
,
2814 args
[ap
->argno
].raw_length
);
2816 args
[ap
->argno
].expand_length
2817 = CPP_WRITTEN (pfile
) - args
[ap
->argno
].expanded
;
2820 /* Add 4 for two newline-space markers to prevent
2821 token concatenation. */
2822 xbuf_len
+= args
[ap
->argno
].expand_length
+ 4;
2824 if (args
[ap
->argno
].use_count
< 10)
2825 args
[ap
->argno
].use_count
++;
2828 xbuf
= (U_CHAR
*) xmalloc (xbuf_len
+ 1);
2830 /* Generate in XBUF the complete expansion
2831 with arguments substituted in.
2832 TOTLEN is the total size generated so far.
2833 OFFSET is the index in the definition
2834 of where we are copying from. */
2835 offset
= totlen
= 0;
2836 for (last_ap
= NULL
, ap
= defn
->pattern
; ap
!= NULL
;
2837 last_ap
= ap
, ap
= ap
->next
)
2839 register struct argdata
*arg
= &args
[ap
->argno
];
2840 int count_before
= totlen
;
2842 /* Add chars to XBUF. */
2843 for (i
= 0; i
< ap
->nchars
; i
++, offset
++)
2844 xbuf
[totlen
++] = exp
[offset
];
2846 /* If followed by an empty rest arg with concatenation,
2847 delete the last run of nonwhite chars. */
2848 if (rest_zero
&& totlen
> count_before
2849 && ((ap
->rest_args
&& ap
->raw_before
)
2850 || (last_ap
!= NULL
&& last_ap
->rest_args
2851 && last_ap
->raw_after
)))
2853 /* Delete final whitespace. */
2854 while (totlen
> count_before
&& is_space
[xbuf
[totlen
- 1]])
2857 /* Delete the nonwhites before them. */
2858 while (totlen
> count_before
&& ! is_space
[xbuf
[totlen
- 1]])
2862 if (ap
->stringify
!= 0)
2864 bcopy (ARG_BASE
+ arg
->stringified
,
2865 xbuf
+ totlen
, arg
->stringified_length
);
2866 totlen
+= arg
->stringified_length
;
2868 else if (ap
->raw_before
|| ap
->raw_after
|| CPP_TRADITIONAL (pfile
))
2870 U_CHAR
*p1
= ARG_BASE
+ arg
->raw
;
2871 U_CHAR
*l1
= p1
+ arg
->raw_length
;
2874 while (p1
!= l1
&& is_space
[*p1
]) p1
++;
2875 while (p1
!= l1
&& is_idchar
[*p1
])
2876 xbuf
[totlen
++] = *p1
++;
2877 /* Delete any no-reexpansion marker that follows
2878 an identifier at the beginning of the argument
2879 if the argument is concatenated with what precedes it. */
2880 if (p1
[0] == '@' && p1
[1] == '-')
2885 /* Arg is concatenated after: delete trailing whitespace,
2886 whitespace markers, and no-reexpansion markers. */
2889 if (is_space
[l1
[-1]]) l1
--;
2890 else if (l1
[-1] == '-')
2892 U_CHAR
*p2
= l1
- 1;
2893 /* If a `-' is preceded by an odd number of newlines then it
2894 and the last newline are a no-reexpansion marker. */
2895 while (p2
!= p1
&& p2
[-1] == '\n') p2
--;
2896 if ((l1
- 1 - p2
) & 1) {
2905 bcopy (p1
, xbuf
+ totlen
, l1
- p1
);
2910 U_CHAR
*expanded
= ARG_BASE
+ arg
->expanded
;
2911 if (!ap
->raw_before
&& totlen
> 0 && arg
->expand_length
2912 && !CPP_TRADITIONAL(pfile
)
2913 && unsafe_chars (xbuf
[totlen
-1], expanded
[0]))
2915 xbuf
[totlen
++] = '@';
2916 xbuf
[totlen
++] = ' ';
2919 bcopy (expanded
, xbuf
+ totlen
, arg
->expand_length
);
2920 totlen
+= arg
->expand_length
;
2922 if (!ap
->raw_after
&& totlen
> 0 && offset
< defn
->length
2923 && !CPP_TRADITIONAL(pfile
)
2924 && unsafe_chars (xbuf
[totlen
-1], exp
[offset
]))
2926 xbuf
[totlen
++] = '@';
2927 xbuf
[totlen
++] = ' ';
2930 /* If a macro argument with newlines is used multiple times,
2931 then only expand the newlines once. This avoids creating
2932 output lines which don't correspond to any input line,
2933 which confuses gdb and gcov. */
2934 if (arg
->use_count
> 1 && arg
->newlines
> 0)
2936 /* Don't bother doing change_newlines for subsequent
2940 = change_newlines (expanded
, arg
->expand_length
);
2944 if (totlen
> xbuf_len
)
2948 /* if there is anything left of the definition
2949 after handling the arg list, copy that in too. */
2951 for (i
= offset
; i
< defn
->length
; i
++)
2953 /* if we've reached the end of the macro */
2956 if (! (rest_zero
&& last_ap
!= NULL
&& last_ap
->rest_args
2957 && last_ap
->raw_after
))
2958 xbuf
[totlen
++] = exp
[i
];
2966 pfile
->output_escapes
--;
2968 /* Now put the expansion on the input stack
2969 so our caller will commence reading from it. */
2970 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
);
2971 CPP_BUFFER (pfile
)->has_escapes
= 1;
2973 /* Pop the space we've used in the token_buffer for argument expansion. */
2974 CPP_SET_WRITTEN (pfile
, old_written
);
2976 /* Recursive macro use sometimes works traditionally.
2977 #define foo(x,y) bar (x (y,0), y)
2980 if (!CPP_TRADITIONAL (pfile
))
2981 hp
->type
= T_DISABLED
;
2985 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
)
2987 register U_CHAR
*xbuf
;
2991 register cpp_buffer
*mbuf
= cpp_push_buffer (pfile
, xbuf
, xbuf_len
);
2994 mbuf
->cleanup
= macro_cleanup
;
2997 /* The first chars of the expansion should be a "@ " added by
2998 collect_expansion. This is to prevent accidental token-pasting
2999 between the text preceding the macro invocation, and the macro
3002 We would like to avoid adding unneeded spaces (for the sake of
3003 tools that use cpp, such as imake). In some common cases we can
3004 tell that it is safe to omit the space.
3006 The character before the macro invocation cannot have been an
3007 idchar (or else it would have been pasted with the idchars of
3008 the macro name). Therefore, if the first non-space character
3009 of the expansion is an idchar, we do not need the extra space
3010 to prevent token pasting.
3012 Also, we don't need the extra space if the first char is '(',
3013 or some other (less common) characters. */
3015 if (xbuf
[0] == '@' && xbuf
[1] == ' '
3016 && (is_idchar
[xbuf
[2]] || xbuf
[2] == '(' || xbuf
[2] == '\''
3017 || xbuf
[2] == '\"'))
3021 /* Like cpp_get_token, except that it does not read past end-of-line.
3022 Also, horizontal space is skipped, and macros are popped. */
3024 static enum cpp_token
3025 get_directive_token (pfile
)
3030 long old_written
= CPP_WRITTEN (pfile
);
3031 enum cpp_token token
;
3032 cpp_skip_hspace (pfile
);
3033 if (PEEKC () == '\n')
3035 token
= cpp_get_token (pfile
);
3039 if (! CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
3041 /* ... else fall though ... */
3042 case CPP_HSPACE
: case CPP_COMMENT
:
3043 CPP_SET_WRITTEN (pfile
, old_written
);
3051 /* Handle #include and #import.
3052 This function expects to see "fname" or <fname> on the input.
3054 The input is normally in part of the output_buffer following
3055 CPP_WRITTEN, and will get overwritten by output_line_command.
3056 I.e. in input file specification has been popped by handle_directive.
3060 do_include (pfile
, keyword
, unused1
, unused2
)
3062 struct directive
*keyword
;
3063 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3065 int importing
= (keyword
->type
== T_IMPORT
);
3066 int skip_dirs
= (keyword
->type
== T_INCLUDE_NEXT
);
3067 char *fname
; /* Dynamically allocated fname buffer */
3069 U_CHAR
*fbeg
, *fend
; /* Beginning and end of fname */
3070 enum cpp_token token
;
3072 /* Chain of dirs to search */
3073 struct file_name_list
*search_start
= CPP_OPTIONS (pfile
)->include
;
3074 struct file_name_list dsp
[1]; /* First in chain, if #include "..." */
3075 struct file_name_list
*searchptr
= 0;
3076 long old_written
= CPP_WRITTEN (pfile
);
3080 int f
; /* file number */
3082 int angle_brackets
= 0; /* 0 for "...", 1 for <...> */
3089 f
= -1; /* JF we iz paranoid! */
3091 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3094 cpp_pedwarn (pfile
, "ANSI C does not allow `#import'");
3096 cpp_pedwarn (pfile
, "ANSI C does not allow `#include_next'");
3099 if (importing
&& CPP_OPTIONS (pfile
)->warn_import
3100 && !CPP_OPTIONS (pfile
)->inhibit_warnings
3101 && !CPP_BUFFER (pfile
)->system_header_p
&& !pfile
->import_warning
)
3103 pfile
->import_warning
= 1;
3104 cpp_warning (pfile
, "using `#import' is not recommended");
3105 fprintf (stderr
, "The fact that a certain header file need not be processed more than once\n");
3106 fprintf (stderr
, "should be indicated in the header file, not where it is used.\n");
3107 fprintf (stderr
, "The best way to do this is with a conditional of this form:\n\n");
3108 fprintf (stderr
, " #ifndef _FOO_H_INCLUDED\n");
3109 fprintf (stderr
, " #define _FOO_H_INCLUDED\n");
3110 fprintf (stderr
, " ... <real contents of file> ...\n");
3111 fprintf (stderr
, " #endif /* Not _FOO_H_INCLUDED */\n\n");
3112 fprintf (stderr
, "Then users can use `#include' any number of times.\n");
3113 fprintf (stderr
, "GNU C automatically avoids processing the file more than once\n");
3114 fprintf (stderr
, "when it is equipped with such a conditional.\n");
3117 pfile
->parsing_include_directive
++;
3118 token
= get_directive_token (pfile
);
3119 pfile
->parsing_include_directive
--;
3121 if (token
== CPP_STRING
)
3123 /* FIXME - check no trailing garbage */
3124 fbeg
= pfile
->token_buffer
+ old_written
+ 1;
3125 fend
= CPP_PWRITTEN (pfile
) - 1;
3126 if (fbeg
[-1] == '<')
3129 /* If -I-, start with the first -I dir after the -I-. */
3130 if (CPP_OPTIONS (pfile
)->first_bracket_include
)
3131 search_start
= CPP_OPTIONS (pfile
)->first_bracket_include
;
3133 /* If -I- was specified, don't search current dir, only spec'd ones. */
3134 else if (! CPP_OPTIONS (pfile
)->ignore_srcdir
)
3136 cpp_buffer
*fp
= CPP_BUFFER (pfile
);
3137 /* We have "filename". Figure out directory this source
3138 file is coming from and put it on the front of the list. */
3140 for ( ; fp
!= CPP_NULL_BUFFER (pfile
); fp
= CPP_PREV_BUFFER (fp
))
3145 if ((nam
= fp
->nominal_fname
) != NULL
)
3147 /* Found a named file. Figure out dir of the file,
3148 and put it in front of the search list. */
3149 dsp
[0].next
= search_start
;
3152 ep
= rindex (nam
, '/');
3154 ep
= rindex (nam
, ']');
3155 if (ep
== NULL
) ep
= rindex (nam
, '>');
3156 if (ep
== NULL
) ep
= rindex (nam
, ':');
3157 if (ep
!= NULL
) ep
++;
3162 dsp
[0].fname
= (char *) alloca (n
+ 1);
3163 strncpy (dsp
[0].fname
, nam
, n
);
3164 dsp
[0].fname
[n
] = '\0';
3165 if (n
+ INCLUDE_LEN_FUDGE
> pfile
->max_include_len
)
3166 pfile
->max_include_len
= n
+ INCLUDE_LEN_FUDGE
;
3170 dsp
[0].fname
= 0; /* Current directory */
3172 dsp
[0].got_name_map
= 0;
3179 else if (token
== CPP_NAME
)
3182 * Support '#include xyz' like VAX-C to allow for easy use of all the
3183 * decwindow include files. It defaults to '#include <xyz.h>' (so the
3184 * code from case '<' is repeated here) and generates a warning.
3187 "VAX-C-style include specification found, use '#include <filename.h>' !");
3189 /* If -I-, start with the first -I dir after the -I-. */
3190 if (CPP_OPTIONS (pfile
)->first_bracket_include
)
3191 search_start
= CPP_OPTIONS (pfile
)->first_bracket_include
;
3192 fbeg
= pfile
->token_buffer
+ old_written
;
3193 fend
= CPP_PWRITTEN (pfile
);
3199 "`#%s' expects \"FILENAME\" or <FILENAME>", keyword
->name
);
3200 CPP_SET_WRITTEN (pfile
, old_written
);
3201 skip_rest_of_line (pfile
);
3207 token
= get_directive_token (pfile
);
3208 if (token
!= CPP_VSPACE
)
3210 cpp_error (pfile
, "junk at end of `#include'");
3211 while (token
!= CPP_VSPACE
&& token
!= CPP_EOF
&& token
!= CPP_POP
)
3212 token
= get_directive_token (pfile
);
3215 /* For #include_next, skip in the search path
3216 past the dir in which the containing file was found. */
3219 cpp_buffer
*fp
= CPP_BUFFER (pfile
);
3220 for (; fp
!= CPP_NULL_BUFFER (pfile
); fp
= CPP_PREV_BUFFER (fp
))
3221 if (fp
->fname
!= NULL
)
3223 /* fp->dir is null if the containing file was specified with
3224 an absolute file name. In that case, don't skip anything. */
3225 if (fp
->dir
== SELF_DIR_DUMMY
)
3226 search_start
= CPP_OPTIONS (pfile
)->include
;
3228 search_start
= fp
->dir
->next
;
3233 CPP_SET_WRITTEN (pfile
, old_written
);
3239 cpp_error (pfile
, "empty file name in `#%s'", keyword
->name
);
3243 /* Allocate this permanently, because it gets stored in the definitions
3245 fname
= (char *) xmalloc (pfile
->max_include_len
+ flen
+ 4);
3246 /* + 2 above for slash and terminating null. */
3247 /* + 2 added for '.h' on VMS (to support '#include filename') */
3249 /* If specified file name is absolute, just open it. */
3252 strncpy (fname
, fbeg
, flen
);
3254 if (redundant_include_p (pfile
, fname
))
3257 f
= lookup_import (pfile
, fname
, NULL_PTR
);
3259 f
= open_include_file (pfile
, fname
, NULL_PTR
);
3261 return 0; /* Already included this file */
3263 /* Search directory path, trying to open the file.
3264 Copy each filename tried into FNAME. */
3266 for (searchptr
= search_start
; searchptr
; searchptr
= searchptr
->next
) {
3267 if (searchptr
->fname
) {
3268 /* The empty string in a search path is ignored.
3269 This makes it possible to turn off entirely
3270 a standard piece of the list. */
3271 if (searchptr
->fname
[0] == 0)
3273 strcpy (fname
, searchptr
->fname
);
3274 strcat (fname
, "/");
3275 fname
[strlen (fname
) + flen
] = 0;
3279 strncat (fname
, fbeg
, flen
);
3281 /* Change this 1/2 Unix 1/2 VMS file specification into a
3282 full VMS file specification */
3283 if (searchptr
->fname
&& (searchptr
->fname
[0] != 0)) {
3284 /* Fix up the filename */
3285 hack_vms_include_specification (fname
);
3287 /* This is a normal VMS filespec, so use it unchanged. */
3288 strncpy (fname
, fbeg
, flen
);
3290 /* if it's '#include filename', add the missing .h */
3291 if (index(fname
,'.')==NULL
) {
3292 strcat (fname
, ".h");
3296 /* ??? There are currently 3 separate mechanisms for avoiding processing
3297 of redundant include files: #import, #pragma once, and
3298 redundant_include_p. It would be nice if they were unified. */
3299 if (redundant_include_p (pfile
, fname
))
3302 f
= lookup_import (pfile
, fname
, searchptr
);
3304 f
= open_include_file (pfile
, fname
, searchptr
);
3306 return 0; /* Already included this file */
3308 else if (f
== -1 && errno
== EACCES
)
3309 cpp_warning (pfile
, "Header file %s exists, but is not readable",
3319 /* A file that was not found. */
3320 strncpy (fname
, fbeg
, flen
);
3322 /* If generating dependencies and -MG was specified, we assume missing
3323 files are leaf files, living in the same directory as the source file
3324 or other similar place; these missing files may be generated from
3325 other files and may not exist yet (eg: y.tab.h). */
3327 if (CPP_OPTIONS(pfile
)->print_deps_missing_files
3328 && CPP_PRINT_DEPS (pfile
)
3329 > (angle_brackets
|| (pfile
->system_include_depth
> 0)))
3331 /* If it was requested as a system header file,
3332 then assume it belongs in the first place to look for such. */
3335 for (searchptr
= search_start
; searchptr
;
3336 searchptr
= searchptr
->next
)
3338 if (searchptr
->fname
)
3342 if (searchptr
->fname
[0] == 0)
3344 p
= (char *) alloca (strlen (searchptr
->fname
)
3345 + strlen (fname
) + 2);
3346 strcpy (p
, searchptr
->fname
);
3349 deps_output (pfile
, p
, ' ');
3356 /* Otherwise, omit the directory, as if the file existed
3357 in the directory with the source. */
3358 deps_output (pfile
, fname
, ' ');
3361 /* If -M was specified, and this header file won't be added to the
3362 dependency list, then don't count this as an error, because we can
3363 still produce correct output. Otherwise, we can't produce correct
3364 output, because there may be dependencies we need inside the missing
3365 file, and we don't know what directory this missing file exists in.*/
3366 else if (CPP_PRINT_DEPS (pfile
)
3367 && (CPP_PRINT_DEPS (pfile
)
3368 <= (angle_brackets
|| (pfile
->system_include_depth
> 0))))
3369 cpp_warning (pfile
, "No include path in which to find %s", fname
);
3370 else if (search_start
)
3371 cpp_error_from_errno (pfile
, fname
);
3373 cpp_error (pfile
, "No include path in which to find %s", fname
);
3376 /* Check to see if this include file is a once-only include file.
3379 struct file_name_list
*ptr
;
3381 for (ptr
= pfile
->dont_repeat_files
; ptr
; ptr
= ptr
->next
) {
3382 if (!strcmp (ptr
->fname
, fname
)) {
3384 return 0; /* This file was once'd. */
3388 for (ptr
= pfile
->all_include_files
; ptr
; ptr
= ptr
->next
) {
3389 if (!strcmp (ptr
->fname
, fname
))
3390 break; /* This file was included before. */
3394 /* This is the first time for this file. */
3395 /* Add it to list of files included. */
3397 ptr
= (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
3398 ptr
->control_macro
= 0;
3399 ptr
->c_system_include_path
= 0;
3400 ptr
->next
= pfile
->all_include_files
;
3401 pfile
->all_include_files
= ptr
;
3402 ptr
->fname
= savestring (fname
);
3403 ptr
->got_name_map
= 0;
3405 /* For -M, add this file to the dependencies. */
3406 if (CPP_PRINT_DEPS (pfile
)
3407 > (angle_brackets
|| (pfile
->system_include_depth
> 0)))
3408 deps_output (pfile
, fname
, ' ');
3411 /* Handle -H option. */
3412 if (CPP_OPTIONS(pfile
)->print_include_names
)
3414 cpp_buffer
*buf
= CPP_BUFFER (pfile
);
3415 while ((buf
= CPP_PREV_BUFFER (buf
)) != CPP_NULL_BUFFER (pfile
))
3417 fprintf (stderr
, "%s\n", fname
);
3421 pfile
->system_include_depth
++;
3423 /* Actually process the file. */
3425 /* Record file on "seen" list for #import. */
3426 add_import (pfile
, f
, fname
);
3428 pcftry
= (char *) alloca (strlen (fname
) + 30);
3440 sprintf (pcftry
, "%s%d", fname
, pcfnum
++);
3442 pcf
= open (pcftry
, O_RDONLY
, 0666);
3448 if (bcmp ((char *) &stat_f
.st_ino
, (char *) &s
.st_ino
,
3450 || stat_f
.st_dev
!= s
.st_dev
)
3452 pcfbuf
= check_precompiled (pcf
, fname
, &pcfbuflimit
);
3453 /* Don't need it any more. */
3458 /* Don't need it at all. */
3463 } while (pcf
!= -1 && !pcfbuf
);
3467 /* Actually process the file */
3468 if (cpp_push_buffer (pfile
, NULL
, 0) == NULL
)
3470 if (finclude (pfile
, f
, fname
, is_system_include (pfile
, fname
),
3471 searchptr
!= dsp
? searchptr
: SELF_DIR_DUMMY
))
3473 output_line_command (pfile
, 0, enter_file
);
3474 pfile
->only_seen_white
= 2;
3478 pfile
->system_include_depth
--;
3483 /* Return nonzero if there is no need to include file NAME
3484 because it has already been included and it contains a conditional
3485 to make a repeated include do nothing. */
3488 redundant_include_p (pfile
, name
)
3492 struct file_name_list
*l
= pfile
->all_include_files
;
3493 for (; l
; l
= l
->next
)
3494 if (! strcmp (name
, l
->fname
)
3496 && cpp_lookup (pfile
, l
->control_macro
, -1, -1))
3501 /* Return nonzero if the given FILENAME is an absolute pathname which
3502 designates a file within one of the known "system" include file
3503 directories. We assume here that if the given FILENAME looks like
3504 it is the name of a file which resides either directly in a "system"
3505 include file directory, or within any subdirectory thereof, then the
3506 given file must be a "system" include file. This function tells us
3507 if we should suppress pedantic errors/warnings for the given FILENAME.
3509 The value is 2 if the file is a C-language system header file
3510 for which C++ should (on most systems) assume `extern "C"'. */
3513 is_system_include (pfile
, filename
)
3515 register char *filename
;
3517 struct file_name_list
*searchptr
;
3519 for (searchptr
= CPP_OPTIONS (pfile
)->first_system_include
; searchptr
;
3520 searchptr
= searchptr
->next
)
3521 if (searchptr
->fname
) {
3522 register char *sys_dir
= searchptr
->fname
;
3523 register unsigned length
= strlen (sys_dir
);
3525 if (! strncmp (sys_dir
, filename
, length
) && filename
[length
] == '/')
3527 if (searchptr
->c_system_include_path
)
3538 * Install a name in the assertion hash table.
3540 * If LEN is >= 0, it is the length of the name.
3541 * Otherwise, compute the length by scanning the entire name.
3543 * If HASH is >= 0, it is the precomputed hash code.
3544 * Otherwise, compute the hash code.
3547 static ASSERTION_HASHNODE
*
3548 assertion_install (pfile
, name
, len
, hash
)
3554 register ASSERTION_HASHNODE
*hp
;
3555 register int i
, bucket
;
3556 register U_CHAR
*p
, *q
;
3558 i
= sizeof (ASSERTION_HASHNODE
) + len
+ 1;
3559 hp
= (ASSERTION_HASHNODE
*) xmalloc (i
);
3561 hp
->bucket_hdr
= &pfile
->assertion_hashtab
[bucket
];
3562 hp
->next
= pfile
->assertion_hashtab
[bucket
];
3563 pfile
->assertion_hashtab
[bucket
] = hp
;
3565 if (hp
->next
!= NULL
)
3566 hp
->next
->prev
= hp
;
3569 hp
->name
= ((U_CHAR
*) hp
) + sizeof (ASSERTION_HASHNODE
);
3572 for (i
= 0; i
< len
; i
++)
3578 * find the most recent hash node for name "name" (ending with first
3579 * non-identifier char) installed by install
3581 * If LEN is >= 0, it is the length of the name.
3582 * Otherwise, compute the length by scanning the entire name.
3584 * If HASH is >= 0, it is the precomputed hash code.
3585 * Otherwise, compute the hash code.
3588 static ASSERTION_HASHNODE
*
3589 assertion_lookup (pfile
, name
, len
, hash
)
3595 register ASSERTION_HASHNODE
*bucket
;
3597 bucket
= pfile
->assertion_hashtab
[hash
];
3599 if (bucket
->length
== len
&& strncmp (bucket
->name
, name
, len
) == 0)
3601 bucket
= bucket
->next
;
3607 delete_assertion (hp
)
3608 ASSERTION_HASHNODE
*hp
;
3610 struct tokenlist_list
*tail
;
3611 if (hp
->prev
!= NULL
)
3612 hp
->prev
->next
= hp
->next
;
3613 if (hp
->next
!= NULL
)
3614 hp
->next
->prev
= hp
->prev
;
3616 for (tail
= hp
->value
; tail
; )
3618 struct tokenlist_list
*next
= tail
->next
;
3619 free_token_list (tail
->tokens
);
3624 /* Make sure that the bucket chain header that
3625 the deleted guy was on points to the right thing afterwards. */
3626 if (hp
== *hp
->bucket_hdr
)
3627 *hp
->bucket_hdr
= hp
->next
;
3632 /* Convert a character string literal into a nul-terminated string.
3633 The input string is [IN ... LIMIT).
3634 The result is placed in RESULT. RESULT can be the same as IN.
3635 The value returned in the end of the string written to RESULT,
3636 or NULL on error. */
3639 convert_string (pfile
, result
, in
, limit
, handle_escapes
)
3641 register U_CHAR
*result
, *in
, *limit
;
3661 char *bpc
= (char *) in
;
3662 int i
= (U_CHAR
) cpp_parse_escape (pfile
, &bpc
);
3663 in
= (U_CHAR
*) bpc
;
3665 *result
++ = (U_CHAR
)c
;
3668 /* else fall through */
3678 * interpret #line command. Remembers previously seen fnames
3679 * in its very own hash table.
3681 #define FNAME_HASHSIZE 37
3684 do_line (pfile
, keyword
, unused1
, unused2
)
3686 struct directive
*keyword ATTRIBUTE_UNUSED
;
3687 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3689 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
3691 long old_written
= CPP_WRITTEN (pfile
);
3692 enum file_change_code file_change
= same_file
;
3693 enum cpp_token token
;
3695 token
= get_directive_token (pfile
);
3697 if (token
!= CPP_NUMBER
3698 || !ISDIGIT(pfile
->token_buffer
[old_written
]))
3700 cpp_error (pfile
, "invalid format `#line' command");
3701 goto bad_line_directive
;
3704 /* The Newline at the end of this line remains to be processed.
3705 To put the next line at the specified line number,
3706 we must store a line number now that is one less. */
3707 new_lineno
= atoi ((char *)(pfile
->token_buffer
+ old_written
)) - 1;
3708 CPP_SET_WRITTEN (pfile
, old_written
);
3710 /* NEW_LINENO is one less than the actual line number here. */
3711 if (CPP_PEDANTIC (pfile
) && new_lineno
< 0)
3712 cpp_pedwarn (pfile
, "line number out of range in `#line' command");
3714 #if 0 /* #line 10"foo.c" is supposed to be allowed. */
3715 if (PEEKC() && !is_space
[PEEKC()]) {
3716 cpp_error (pfile
, "invalid format `#line' command");
3717 goto bad_line_directive
;
3721 token
= get_directive_token (pfile
);
3723 if (token
== CPP_STRING
) {
3724 U_CHAR
*fname
= pfile
->token_buffer
+ old_written
;
3726 static HASHNODE
*fname_table
[FNAME_HASHSIZE
];
3727 HASHNODE
*hp
, **hash_bucket
;
3732 /* Turn the file name, which is a character string literal,
3733 into a null-terminated string. Do this in place. */
3734 end_name
= convert_string (pfile
, fname
, fname
, CPP_PWRITTEN (pfile
), 1);
3735 if (end_name
== NULL
)
3737 cpp_error (pfile
, "invalid format `#line' command");
3738 goto bad_line_directive
;
3741 fname_length
= end_name
- fname
;
3743 num_start
= CPP_WRITTEN (pfile
);
3744 token
= get_directive_token (pfile
);
3745 if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
&& token
!= CPP_POP
) {
3746 p
= pfile
->token_buffer
+ num_start
;
3747 if (CPP_PEDANTIC (pfile
))
3748 cpp_pedwarn (pfile
, "garbage at end of `#line' command");
3750 if (token
!= CPP_NUMBER
|| *p
< '0' || *p
> '4' || p
[1] != '\0')
3752 cpp_error (pfile
, "invalid format `#line' command");
3753 goto bad_line_directive
;
3756 file_change
= enter_file
;
3758 file_change
= leave_file
;
3760 ip
->system_header_p
= 1;
3761 else /* if (*p == '4') */
3762 ip
->system_header_p
= 2;
3764 CPP_SET_WRITTEN (pfile
, num_start
);
3765 token
= get_directive_token (pfile
);
3766 p
= pfile
->token_buffer
+ num_start
;
3767 if (token
== CPP_NUMBER
&& p
[1] == '\0' && (*p
== '3' || *p
== '4')) {
3768 ip
->system_header_p
= *p
== '3' ? 1 : 2;
3769 token
= get_directive_token (pfile
);
3771 if (token
!= CPP_VSPACE
) {
3772 cpp_error (pfile
, "invalid format `#line' command");
3773 goto bad_line_directive
;
3777 hash_bucket
= &fname_table
[hashf (fname
, fname_length
, FNAME_HASHSIZE
)];
3778 for (hp
= *hash_bucket
; hp
!= NULL
; hp
= hp
->next
)
3779 if (hp
->length
== fname_length
3780 && strncmp (hp
->value
.cpval
, fname
, fname_length
) == 0) {
3781 ip
->nominal_fname
= hp
->value
.cpval
;
3785 /* Didn't find it; cons up a new one. */
3786 hp
= (HASHNODE
*) xcalloc (1, sizeof (HASHNODE
) + fname_length
+ 1);
3787 hp
->next
= *hash_bucket
;
3790 hp
->length
= fname_length
;
3791 ip
->nominal_fname
= hp
->value
.cpval
= ((char *) hp
) + sizeof (HASHNODE
);
3792 bcopy (fname
, hp
->value
.cpval
, fname_length
);
3795 else if (token
!= CPP_VSPACE
&& token
!= CPP_EOF
) {
3796 cpp_error (pfile
, "invalid format `#line' command");
3797 goto bad_line_directive
;
3800 ip
->lineno
= new_lineno
;
3802 skip_rest_of_line (pfile
);
3803 CPP_SET_WRITTEN (pfile
, old_written
);
3804 output_line_command (pfile
, 0, file_change
);
3809 * remove the definition of a symbol from the symbol table.
3810 * according to un*x /lib/cpp, it is not an error to undef
3811 * something that has no definitions, so it isn't one here either.
3815 do_undef (pfile
, keyword
, buf
, limit
)
3817 struct directive
*keyword
;
3818 U_CHAR
*buf
, *limit
;
3822 U_CHAR
*orig_buf
= buf
;
3825 /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
3826 if (pcp_outfile
&& keyword
)
3827 pass_thru_directive (buf
, limit
, pfile
, keyword
);
3830 SKIP_WHITE_SPACE (buf
);
3831 sym_length
= check_macro_name (pfile
, buf
, "macro");
3833 while ((hp
= cpp_lookup (pfile
, buf
, sym_length
, -1)) != NULL
)
3835 /* If we are generating additional info for debugging (with -g) we
3836 need to pass through all effective #undef commands. */
3837 if (CPP_OPTIONS (pfile
)->debug_output
&& keyword
)
3838 pass_thru_directive (orig_buf
, limit
, pfile
, keyword
);
3839 if (hp
->type
!= T_MACRO
)
3840 cpp_warning (pfile
, "undefining `%s'", hp
->name
);
3844 if (CPP_PEDANTIC (pfile
)) {
3846 SKIP_WHITE_SPACE (buf
);
3848 cpp_pedwarn (pfile
, "garbage after `#undef' directive");
3854 * Report an error detected by the program we are processing.
3855 * Use the text of the line in the error message.
3856 * (We use error because it prints the filename & line#.)
3860 do_error (pfile
, keyword
, buf
, limit
)
3862 struct directive
*keyword ATTRIBUTE_UNUSED
;
3863 U_CHAR
*buf
, *limit
;
3865 int length
= limit
- buf
;
3866 U_CHAR
*copy
= (U_CHAR
*) alloca (length
+ 1);
3867 bcopy (buf
, copy
, length
);
3869 SKIP_WHITE_SPACE (copy
);
3870 cpp_error (pfile
, "#error %s", copy
);
3875 * Report a warning detected by the program we are processing.
3876 * Use the text of the line in the warning message, then continue.
3877 * (We use error because it prints the filename & line#.)
3881 do_warning (pfile
, keyword
, buf
, limit
)
3883 struct directive
*keyword ATTRIBUTE_UNUSED
;
3884 U_CHAR
*buf
, *limit
;
3886 int length
= limit
- buf
;
3887 U_CHAR
*copy
= (U_CHAR
*) alloca (length
+ 1);
3888 bcopy (buf
, copy
, length
);
3890 SKIP_WHITE_SPACE (copy
);
3892 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3893 cpp_pedwarn (pfile
, "ANSI C does not allow `#warning'");
3895 /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
3896 if -pedantic-errors is given, #warning should cause an error. */
3897 cpp_pedwarn (pfile
, "#warning %s", copy
);
3901 /* Remember the name of the current file being read from so that we can
3902 avoid ever including it again. */
3905 do_once (pfile
, keyword
, unused1
, unused2
)
3907 struct directive
*keyword ATTRIBUTE_UNUSED
;
3908 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
3910 cpp_buffer
*ip
= NULL
;
3911 struct file_name_list
*new;
3913 for (ip
= CPP_BUFFER (pfile
); ; ip
= CPP_PREV_BUFFER (ip
))
3915 if (ip
== CPP_NULL_BUFFER (pfile
))
3917 if (ip
->fname
!= NULL
)
3922 new = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
3923 new->next
= pfile
->dont_repeat_files
;
3924 pfile
->dont_repeat_files
= new;
3925 new->fname
= savestring (ip
->fname
);
3926 new->control_macro
= 0;
3927 new->got_name_map
= 0;
3928 new->c_system_include_path
= 0;
3933 /* Report program identification. */
3936 do_ident (pfile
, keyword
, buf
, limit
)
3938 struct directive
*keyword ATTRIBUTE_UNUSED
;
3939 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
3941 /* long old_written = CPP_WRITTEN (pfile);*/
3943 /* Allow #ident in system headers, since that's not user's fault. */
3944 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
3945 cpp_pedwarn (pfile
, "ANSI C does not allow `#ident'");
3947 /* Leave rest of line to be read by later calls to cpp_get_token. */
3952 /* #pragma and its argument line have already been copied to the output file.
3953 Just check for some recognized pragmas that need validation here. */
3956 do_pragma (pfile
, keyword
, buf
, limit
)
3958 struct directive
*keyword ATTRIBUTE_UNUSED
;
3959 U_CHAR
*buf
, *limit ATTRIBUTE_UNUSED
;
3961 while (*buf
== ' ' || *buf
== '\t')
3963 if (!strncmp (buf
, "once", 4)) {
3964 /* Allow #pragma once in system headers, since that's not the user's
3966 if (!CPP_BUFFER (pfile
)->system_header_p
)
3967 cpp_warning (pfile
, "`#pragma once' is obsolete");
3968 do_once (pfile
, NULL
, NULL
, NULL
);
3971 if (!strncmp (buf
, "implementation", 14)) {
3972 /* Be quiet about `#pragma implementation' for a file only if it hasn't
3973 been included yet. */
3974 struct file_name_list
*ptr
;
3975 U_CHAR
*p
= buf
+ 14, *fname
, *inc_fname
;
3977 SKIP_WHITE_SPACE (p
);
3978 if (*p
== '\n' || *p
!= '\"')
3982 p
= (U_CHAR
*) index (fname
, '\"');
3983 fname_len
= p
!= NULL
? p
- fname
: strlen (fname
);
3985 for (ptr
= pfile
->all_include_files
; ptr
; ptr
= ptr
->next
) {
3986 inc_fname
= (U_CHAR
*) rindex (ptr
->fname
, '/');
3987 inc_fname
= inc_fname
? inc_fname
+ 1 : (U_CHAR
*) ptr
->fname
;
3988 if (inc_fname
&& !strncmp (inc_fname
, fname
, fname_len
))
3990 "`#pragma implementation' for `%s' appears after file is included",
3999 /* This was a fun hack, but #pragma seems to start to be useful.
4000 By failing to recognize it, we pass it through unchanged to cc1. */
4003 * the behavior of the #pragma directive is implementation defined.
4004 * this implementation defines it as follows.
4011 if (open ("/dev/tty", O_RDONLY
, 0666) != 0)
4014 if (open ("/dev/tty", O_WRONLY
, 0666) != 1)
4016 execl ("/usr/games/hack", "#pragma", 0);
4017 execl ("/usr/games/rogue", "#pragma", 0);
4018 execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
4019 execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
4021 fatal ("You are in a maze of twisty compiler features, all different");
4025 #ifdef SCCS_DIRECTIVE
4026 /* Just ignore #sccs, on systems where we define it at all. */
4029 do_sccs (pfile
, keyword
, buf
, limit
)
4031 struct directive
*keyword ATTRIBUTE_UNUSED
;
4032 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4034 if (CPP_PEDANTIC (pfile
))
4035 cpp_pedwarn (pfile
, "ANSI C does not allow `#sccs'");
4041 * handle #if command by
4042 * 1) inserting special `defined' keyword into the hash table
4043 * that gets turned into 0 or 1 by special_symbol (thus,
4044 * if the luser has a symbol called `defined' already, it won't
4045 * work inside the #if command)
4046 * 2) rescan the input into a temporary output buffer
4047 * 3) pass the output buffer to the yacc parser and collect a value
4048 * 4) clean up the mess left from steps 1 and 2.
4049 * 5) call conditional_skip to skip til the next #endif (etc.),
4050 * or not, depending on the value from step 3.
4054 do_if (pfile
, keyword
, buf
, limit
)
4056 struct directive
*keyword ATTRIBUTE_UNUSED
;
4057 U_CHAR
*buf
, *limit
;
4059 HOST_WIDE_INT value
= eval_if_expression (pfile
, buf
, limit
- buf
);
4060 conditional_skip (pfile
, value
== 0, T_IF
, NULL_PTR
);
4065 * handle a #elif directive by not changing if_stack either.
4066 * see the comment above do_else.
4070 do_elif (pfile
, keyword
, buf
, limit
)
4072 struct directive
*keyword ATTRIBUTE_UNUSED
;
4073 U_CHAR
*buf
, *limit
;
4075 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
) {
4076 cpp_error (pfile
, "`#elif' not within a conditional");
4079 if (pfile
->if_stack
->type
!= T_IF
&& pfile
->if_stack
->type
!= T_ELIF
) {
4080 cpp_error (pfile
, "`#elif' after `#else'");
4082 fprintf (stderr
, " (matches line %d", pfile
->if_stack
->lineno
);
4084 if (pfile
->if_stack
->fname
!= NULL
&& CPP_BUFFER (pfile
)->fname
!= NULL
4085 && strcmp (pfile
->if_stack
->fname
,
4086 CPP_BUFFER (pfile
)->nominal_fname
) != 0)
4087 fprintf (stderr
, ", file %s", pfile
->if_stack
->fname
);
4088 fprintf (stderr
, ")\n");
4090 pfile
->if_stack
->type
= T_ELIF
;
4093 if (pfile
->if_stack
->if_succeeded
)
4094 skip_if_group (pfile
, 0);
4096 HOST_WIDE_INT value
= eval_if_expression (pfile
, buf
, limit
- buf
);
4098 skip_if_group (pfile
, 0);
4100 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
4101 output_line_command (pfile
, 1, same_file
);
4108 * evaluate a #if expression in BUF, of length LENGTH,
4109 * then parse the result as a C expression and return the value as an int.
4112 static HOST_WIDE_INT
4113 eval_if_expression (pfile
, buf
, length
)
4115 U_CHAR
*buf ATTRIBUTE_UNUSED
;
4116 int length ATTRIBUTE_UNUSED
;
4118 HASHNODE
*save_defined
;
4119 HOST_WIDE_INT value
;
4120 long old_written
= CPP_WRITTEN (pfile
);
4122 save_defined
= install ((U_CHAR
*)"defined", -1, T_SPEC_DEFINED
, 0, 0, -1);
4123 pfile
->pcp_inside_if
= 1;
4125 value
= cpp_parse_expr (pfile
);
4126 pfile
->pcp_inside_if
= 0;
4127 delete_macro (save_defined
); /* clean up special symbol */
4129 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
4135 * routine to handle ifdef/ifndef. Try to look up the symbol,
4136 * then do or don't skip to the #endif/#else/#elif depending
4137 * on what directive is actually being processed.
4141 do_xifdef (pfile
, keyword
, unused1
, unused2
)
4143 struct directive
*keyword
;
4144 U_CHAR
*unused1 ATTRIBUTE_UNUSED
, *unused2 ATTRIBUTE_UNUSED
;
4147 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
4150 enum cpp_token token
;
4151 int start_of_file
= 0;
4152 U_CHAR
*control_macro
= 0;
4153 int old_written
= CPP_WRITTEN (pfile
);
4155 /* Detect a #ifndef at start of file (not counting comments). */
4156 if (ip
->fname
!= 0 && keyword
->type
== T_IFNDEF
)
4157 start_of_file
= pfile
->only_seen_white
== 2;
4159 pfile
->no_macro_expand
++;
4160 token
= get_directive_token (pfile
);
4161 pfile
->no_macro_expand
--;
4163 ident
= pfile
->token_buffer
+ old_written
;
4164 ident_length
= CPP_WRITTEN (pfile
) - old_written
;
4165 CPP_SET_WRITTEN (pfile
, old_written
); /* Pop */
4167 if (token
== CPP_VSPACE
|| token
== CPP_POP
|| token
== CPP_EOF
)
4169 skip
= (keyword
->type
== T_IFDEF
);
4170 if (! CPP_TRADITIONAL (pfile
))
4171 cpp_pedwarn (pfile
, "`#%s' with no argument", keyword
->name
);
4173 else if (token
== CPP_NAME
)
4175 HASHNODE
*hp
= cpp_lookup (pfile
, ident
, ident_length
, -1);
4176 skip
= (hp
== NULL
) ^ (keyword
->type
== T_IFNDEF
);
4177 if (start_of_file
&& !skip
)
4179 control_macro
= (U_CHAR
*) xmalloc (ident_length
+ 1);
4180 bcopy (ident
, control_macro
, ident_length
+ 1);
4185 skip
= (keyword
->type
== T_IFDEF
);
4186 if (! CPP_TRADITIONAL (pfile
))
4187 cpp_error (pfile
, "`#%s' with invalid argument", keyword
->name
);
4190 if (!CPP_TRADITIONAL (pfile
))
4192 cpp_skip_hspace (pfile
);
4194 if (c
!= EOF
&& c
!= '\n')
4195 cpp_pedwarn (pfile
, "garbage at end of `#%s' argument", keyword
->name
);
4197 skip_rest_of_line (pfile
);
4201 /* Output a precondition for this macro. */
4202 if (hp
&& hp
->value
.defn
->predefined
)
4203 fprintf (pcp_outfile
, "#define %s\n", hp
->name
);
4206 fprintf (pcp_outfile
, "#undef ");
4207 while (is_idchar
[*cp
]) /* Ick! */
4208 fputc (*cp
++, pcp_outfile
);
4209 putc ('\n', pcp_outfile
);
4213 conditional_skip (pfile
, skip
, T_IF
, control_macro
);
4217 /* Push TYPE on stack; then, if SKIP is nonzero, skip ahead.
4218 If this is a #ifndef starting at the beginning of a file,
4219 CONTROL_MACRO is the macro name tested by the #ifndef.
4220 Otherwise, CONTROL_MACRO is 0. */
4223 conditional_skip (pfile
, skip
, type
, control_macro
)
4226 enum node_type type
;
4227 U_CHAR
*control_macro
;
4229 IF_STACK_FRAME
*temp
;
4231 temp
= (IF_STACK_FRAME
*) xcalloc (1, sizeof (IF_STACK_FRAME
));
4232 temp
->fname
= CPP_BUFFER (pfile
)->nominal_fname
;
4234 temp
->lineno
= CPP_BUFFER (pfile
)->lineno
;
4236 temp
->next
= pfile
->if_stack
;
4237 temp
->control_macro
= control_macro
;
4238 pfile
->if_stack
= temp
;
4240 pfile
->if_stack
->type
= type
;
4243 skip_if_group (pfile
, 0);
4246 ++pfile
->if_stack
->if_succeeded
;
4247 output_line_command (pfile
, 1, same_file
);
4252 * skip to #endif, #else, or #elif. adjust line numbers, etc.
4253 * leaves input ptr at the sharp sign found.
4254 * If ANY is nonzero, return at next directive of any sort.
4258 skip_if_group (pfile
, any
)
4263 struct directive
*kt
;
4264 IF_STACK_FRAME
*save_if_stack
= pfile
->if_stack
; /* don't pop past here */
4266 U_CHAR
*beg_of_line
= bp
;
4268 register int ident_length
;
4270 struct parse_marker line_start_mark
;
4272 parse_set_mark (&line_start_mark
, pfile
);
4274 if (CPP_OPTIONS (pfile
)->output_conditionals
) {
4275 static char failed
[] = "#failed\n";
4276 CPP_PUTS (pfile
, failed
, sizeof(failed
)-1);
4278 output_line_command (pfile
, 1, same_file
);
4282 if (CPP_OPTIONS (pfile
)->output_conditionals
)
4284 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
4285 U_CHAR
*start_line
= pbuf
->buf
+ line_start_mark
.position
;
4286 CPP_PUTS (pfile
, start_line
, pbuf
->cur
- start_line
);
4288 parse_move_mark (&line_start_mark
, pfile
);
4289 if (!CPP_TRADITIONAL (pfile
))
4290 cpp_skip_hspace (pfile
);
4294 int old_written
= CPP_WRITTEN (pfile
);
4295 cpp_skip_hspace (pfile
);
4297 parse_name (pfile
, GETC());
4298 ident_length
= CPP_WRITTEN (pfile
) - old_written
;
4299 ident
= pfile
->token_buffer
+ old_written
;
4300 pfile
->limit
= ident
;
4302 if (ident_length
== 0)
4303 goto not_a_directive
;
4305 /* Handle # followed by a line number. */
4307 /* Avoid error for `###' and similar cases unless -pedantic. */
4310 for (kt
= directive_table
; kt
->length
>= 0; kt
++)
4312 IF_STACK_FRAME
*temp
;
4313 if (ident_length
== kt
->length
4314 && strncmp (ident
, kt
->name
, kt
->length
) == 0)
4316 /* If we are asked to return on next directive, do so now. */
4326 = (IF_STACK_FRAME
*) xcalloc (1, sizeof (IF_STACK_FRAME
));
4327 temp
->next
= pfile
->if_stack
;
4328 pfile
->if_stack
= temp
;
4330 temp
->lineno
= CPP_BUFFER(pfile
)->lineno
;
4332 temp
->fname
= CPP_BUFFER(pfile
)->nominal_fname
;
4333 temp
->type
= kt
->type
;
4337 if (CPP_PEDANTIC (pfile
) && pfile
->if_stack
!= save_if_stack
)
4338 validate_else (pfile
,
4339 kt
->type
== T_ELSE
? "#else" : "#endif");
4341 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
4344 "`#%s' not within a conditional", kt
->name
);
4347 else if (pfile
->if_stack
== save_if_stack
)
4348 goto done
; /* found what we came for */
4350 if (kt
->type
!= T_ENDIF
)
4352 if (pfile
->if_stack
->type
== T_ELSE
)
4353 cpp_error (pfile
, "`#else' or `#elif' after `#else'");
4354 pfile
->if_stack
->type
= kt
->type
;
4358 temp
= pfile
->if_stack
;
4359 pfile
->if_stack
= temp
->next
;
4366 /* Don't let erroneous code go by. */
4367 if (kt
->length
< 0 && !CPP_OPTIONS (pfile
)->lang_asm
4368 && CPP_PEDANTIC (pfile
))
4369 cpp_pedwarn (pfile
, "invalid preprocessor directive name");
4373 /* We're in the middle of a line. Skip the rest of it. */
4380 case '/': /* possible comment */
4381 c
= skip_comment (pfile
, NULL
);
4388 old
= CPP_WRITTEN (pfile
);
4389 cpp_get_token (pfile
);
4390 CPP_SET_WRITTEN (pfile
, old
);
4393 /* Char after backslash loses its special meaning. */
4394 if (PEEKC() == '\n')
4404 if (CPP_OPTIONS (pfile
)->output_conditionals
) {
4405 static char end_failed
[] = "#endfailed\n";
4406 CPP_PUTS (pfile
, end_failed
, sizeof(end_failed
)-1);
4409 pfile
->only_seen_white
= 1;
4410 parse_goto_mark (&line_start_mark
, pfile
);
4411 parse_clear_mark (&line_start_mark
);
4415 * handle a #else directive. Do this by just continuing processing
4416 * without changing if_stack ; this is so that the error message
4417 * for missing #endif's etc. will point to the original #if. It
4418 * is possible that something different would be better.
4422 do_else (pfile
, keyword
, buf
, limit
)
4424 struct directive
*keyword ATTRIBUTE_UNUSED
;
4425 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4427 cpp_buffer
*ip
= CPP_BUFFER (pfile
);
4429 if (CPP_PEDANTIC (pfile
))
4430 validate_else (pfile
, "#else");
4431 skip_rest_of_line (pfile
);
4433 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
) {
4434 cpp_error (pfile
, "`#else' not within a conditional");
4437 /* #ifndef can't have its special treatment for containing the whole file
4438 if it has a #else clause. */
4439 pfile
->if_stack
->control_macro
= 0;
4441 if (pfile
->if_stack
->type
!= T_IF
&& pfile
->if_stack
->type
!= T_ELIF
) {
4442 cpp_error (pfile
, "`#else' after `#else'");
4443 fprintf (stderr
, " (matches line %d", pfile
->if_stack
->lineno
);
4444 if (strcmp (pfile
->if_stack
->fname
, ip
->nominal_fname
) != 0)
4445 fprintf (stderr
, ", file %s", pfile
->if_stack
->fname
);
4446 fprintf (stderr
, ")\n");
4448 pfile
->if_stack
->type
= T_ELSE
;
4451 if (pfile
->if_stack
->if_succeeded
)
4452 skip_if_group (pfile
, 0);
4454 ++pfile
->if_stack
->if_succeeded
; /* continue processing input */
4455 output_line_command (pfile
, 1, same_file
);
4461 * unstack after #endif command
4465 do_endif (pfile
, keyword
, buf
, limit
)
4467 struct directive
*keyword ATTRIBUTE_UNUSED
;
4468 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
4470 if (CPP_PEDANTIC (pfile
))
4471 validate_else (pfile
, "#endif");
4472 skip_rest_of_line (pfile
);
4474 if (pfile
->if_stack
== CPP_BUFFER (pfile
)->if_stack
)
4475 cpp_error (pfile
, "unbalanced `#endif'");
4478 IF_STACK_FRAME
*temp
= pfile
->if_stack
;
4479 pfile
->if_stack
= temp
->next
;
4480 if (temp
->control_macro
!= 0)
4482 /* This #endif matched a #ifndef at the start of the file.
4483 See if it is at the end of the file. */
4484 struct parse_marker start_mark
;
4487 parse_set_mark (&start_mark
, pfile
);
4491 cpp_skip_hspace (pfile
);
4496 parse_goto_mark (&start_mark
, pfile
);
4497 parse_clear_mark (&start_mark
);
4501 /* If we get here, this #endif ends a #ifndef
4502 that contains all of the file (aside from whitespace).
4503 Arrange not to include the file again
4504 if the macro that was tested is defined.
4506 Do not do this for the top-level file in a -include or any
4507 file in a -imacros. */
4511 && ! (indepth
== 1 && pfile
->no_record_file
)
4512 && ! (pfile
->no_record_file
&& no_output
))
4515 struct file_name_list
*ifile
= pfile
->all_include_files
;
4517 for ( ; ifile
!= NULL
; ifile
= ifile
->next
)
4519 if (!strcmp (ifile
->fname
, CPP_BUFFER (pfile
)->fname
))
4521 ifile
->control_macro
= temp
->control_macro
;
4529 output_line_command (pfile
, 1, same_file
);
4534 /* When an #else or #endif is found while skipping failed conditional,
4535 if -pedantic was specified, this is called to warn about text after
4536 the command name. P points to the first char after the command name. */
4539 validate_else (pfile
, directive
)
4544 cpp_skip_hspace (pfile
);
4546 if (c
!= EOF
&& c
!= '\n')
4548 "text following `%s' violates ANSI standard", directive
);
4551 /* Get the next token, and add it to the text in pfile->token_buffer.
4552 Return the kind of token we got. */
4555 cpp_get_token (pfile
)
4558 register int c
, c2
, c3
;
4560 long start_line
, start_column
;
4561 enum cpp_token token
;
4562 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
4563 CPP_BUFFER (pfile
)->prev
= CPP_BUFFER (pfile
)->cur
;
4569 if (CPP_BUFFER (pfile
)->seen_eof
)
4571 if (cpp_pop_buffer (pfile
) != CPP_NULL_BUFFER (pfile
))
4578 cpp_buffer
*next_buf
4579 = CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
4580 CPP_BUFFER (pfile
)->seen_eof
= 1;
4581 if (CPP_BUFFER (pfile
)->nominal_fname
4582 && next_buf
!= CPP_NULL_BUFFER (pfile
))
4584 /* We're about to return from an #include file.
4585 Emit #line information now (as part of the CPP_POP) result.
4586 But the #line refers to the file we will pop to. */
4587 cpp_buffer
*cur_buffer
= CPP_BUFFER (pfile
);
4588 CPP_BUFFER (pfile
) = next_buf
;
4589 pfile
->input_stack_listing_current
= 0;
4590 output_line_command (pfile
, 0, leave_file
);
4591 CPP_BUFFER (pfile
) = cur_buffer
;
4601 struct parse_marker start_mark
;
4603 if (PEEKC () == '=')
4605 if (opts
->put_out_comments
)
4606 parse_set_mark (&start_mark
, pfile
);
4608 cpp_buf_line_and_col (cpp_file_buffer (pfile
),
4609 &start_line
, &start_column
);
4610 c
= skip_comment (pfile
, &newlines
);
4611 if (opts
->put_out_comments
&& (c
== '/' || c
== EOF
))
4612 parse_clear_mark (&start_mark
);
4617 cpp_error_with_line (pfile
, start_line
, start_column
,
4618 "unterminated comment");
4621 c
= '/'; /* Initial letter of comment. */
4623 /* Comments are equivalent to spaces.
4624 For -traditional, a comment is equivalent to nothing. */
4625 if (opts
->put_out_comments
)
4627 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
4628 U_CHAR
*start
= pbuf
->buf
+ start_mark
.position
;
4629 int len
= pbuf
->cur
- start
;
4630 CPP_RESERVE(pfile
, 1 + len
);
4631 CPP_PUTC_Q (pfile
, c
);
4632 CPP_PUTS_Q (pfile
, start
, len
);
4633 pfile
->lineno
+= newlines
;
4634 parse_clear_mark (&start_mark
);
4637 else if (CPP_TRADITIONAL (pfile
))
4644 /* This may not work if cpp_get_token is called recursively,
4645 since many places look for horizontal space. */
4648 /* Copy the newlines into the output buffer, in order to
4649 avoid the pain of a #line every time a multiline comment
4651 CPP_RESERVE(pfile
, newlines
);
4652 while (--newlines
>= 0)
4654 CPP_PUTC_Q (pfile
, '\n');
4660 CPP_RESERVE(pfile
, 1);
4661 CPP_PUTC_Q (pfile
, ' ');
4665 if (opts
->for_lint
) {
4668 char *lintcmd
= get_lintcmd (ibp
, limit
, &argbp
, &arglen
, &cmdlen
);
4670 if (lintcmd
!= NULL
) {
4671 /* I believe it is always safe to emit this newline: */
4673 bcopy ("#pragma lint ", (char *) obp
, 13);
4675 bcopy (lintcmd
, (char *) obp
, cmdlen
);
4680 bcopy (argbp
, (char *) obp
, arglen
);
4684 /* OK, now bring us back to the state we were in before we entered
4685 this branch. We need #line because the newline for the pragma
4686 could mess things up. */
4687 output_line_command (pfile
, 0, same_file
);
4688 *(obp
++) = ' '; /* just in case, if comments are copied thru */
4696 /* If this is expanding a macro definition, don't recognize
4697 preprocessor directives. */
4700 /* If this is expand_into_temp_buffer, recognize them
4701 only after an actual newline at this level,
4702 not at the beginning of the input level. */
4703 if (ip
->fname
== 0 && beg_of_line
== ip
->buf
)
4709 if (!pfile
->only_seen_white
)
4711 if (handle_directive (pfile
))
4712 return CPP_DIRECTIVE
;
4713 pfile
->only_seen_white
= 0;
4718 /* A single quoted string is treated like a double -- some
4719 programs (e.g., troff) are perverse this way */
4720 cpp_buf_line_and_col (cpp_file_buffer (pfile
),
4721 &start_line
, &start_column
);
4722 old_written
= CPP_WRITTEN (pfile
);
4724 CPP_PUTC (pfile
, c
);
4730 if (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
4732 /* try harder: this string crosses a macro expansion
4733 boundary. This can happen naturally if -traditional.
4734 Otherwise, only -D can make a macro with an unmatched
4736 cpp_buffer
*next_buf
4737 = CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
4738 (*CPP_BUFFER (pfile
)->cleanup
)
4739 (CPP_BUFFER (pfile
), pfile
);
4740 CPP_BUFFER (pfile
) = next_buf
;
4743 if (!CPP_TRADITIONAL (pfile
))
4745 cpp_error_with_line (pfile
, start_line
, start_column
,
4746 "unterminated string or character constant");
4747 if (pfile
->multiline_string_line
!= start_line
4748 && pfile
->multiline_string_line
!= 0)
4749 cpp_error_with_line (pfile
,
4750 pfile
->multiline_string_line
, -1,
4751 "possible real start of unterminated constant");
4752 pfile
->multiline_string_line
= 0;
4756 CPP_PUTC (pfile
, cc
);
4760 /* Traditionally, end of line ends a string constant with
4761 no error. So exit the loop and record the new line. */
4762 if (CPP_TRADITIONAL (pfile
))
4766 cpp_error_with_line (pfile
, start_line
, start_column
,
4767 "unterminated character constant");
4770 if (CPP_PEDANTIC (pfile
)
4771 && pfile
->multiline_string_line
== 0)
4773 cpp_pedwarn_with_line (pfile
, start_line
, start_column
,
4774 "string constant runs past end of line");
4776 if (pfile
->multiline_string_line
== 0)
4777 pfile
->multiline_string_line
= start_line
;
4784 /* Backslash newline is replaced by nothing at all. */
4785 CPP_ADJUST_WRITTEN (pfile
, -1);
4790 /* ANSI stupidly requires that in \\ the second \
4791 is *not* prevented from combining with a newline. */
4794 CPP_PUTC (pfile
, cc
);
4806 pfile
->lineno
+= count_newlines (pfile
->token_buffer
+ old_written
,
4807 CPP_PWRITTEN (pfile
));
4808 pfile
->only_seen_white
= 0;
4809 return c
== '\'' ? CPP_CHAR
: CPP_STRING
;
4812 if (!opts
->dollars_in_ident
)
4817 if (opts
->cplusplus
&& PEEKC () == ':')
4826 if (c2
== c
|| c2
== '=')
4836 if (PEEKC () == '=')
4843 if (c2
== '-' && opts
->chill
)
4845 /* Chill style comment */
4846 if (opts
->put_out_comments
)
4847 parse_set_mark (&start_mark
, pfile
);
4848 FORWARD(1); /* Skip second '-'. */
4856 /* Don't consider final '\n' to be part of comment. */
4862 goto return_comment
;
4864 if (c2
== '-' || c2
== '=' || c2
== '>')
4869 if (pfile
->parsing_include_directive
)
4873 CPP_PUTC (pfile
, c
);
4878 if (c
== '\n' || c
== EOF
)
4881 "missing '>' in `#include <FILENAME>'");
4887 /* else fall through */
4896 CPP_RESERVE (pfile
, 4);
4897 CPP_PUTC (pfile
, c
);
4898 CPP_PUTC (pfile
, c2
);
4902 CPP_PUTC_Q (pfile
, GETC ());
4903 CPP_NUL_TERMINATE_Q (pfile
);
4904 pfile
->only_seen_white
= 0;
4908 if (CPP_BUFFER (pfile
)->has_escapes
)
4913 if (pfile
->output_escapes
)
4914 CPP_PUTS (pfile
, "@-", 2);
4915 parse_name (pfile
, GETC ());
4918 else if (is_space
[c
])
4920 CPP_RESERVE (pfile
, 2);
4921 if (pfile
->output_escapes
)
4922 CPP_PUTC_Q (pfile
, '@');
4923 CPP_PUTC_Q (pfile
, c
);
4927 if (pfile
->output_escapes
)
4929 CPP_PUTS (pfile
, "@@", 2);
4939 CPP_RESERVE(pfile
, 2);
4940 CPP_PUTC_Q (pfile
, '.');
4944 /* FIXME - misses the case "..\\\n." */
4945 if (c2
== '.' && PEEKN(1) == '.')
4947 CPP_RESERVE(pfile
, 4);
4948 CPP_PUTC_Q (pfile
, '.');
4949 CPP_PUTC_Q (pfile
, '.');
4950 CPP_PUTC_Q (pfile
, '.');
4952 CPP_NUL_TERMINATE_Q (pfile
);
4953 pfile
->only_seen_white
= 0;
4960 pfile
->only_seen_white
= 0;
4962 CPP_RESERVE(pfile
, 3);
4963 CPP_PUTC_Q (pfile
, c
);
4964 CPP_PUTC_Q (pfile
, GETC ());
4965 CPP_NUL_TERMINATE_Q (pfile
);
4971 if ((c2
== '\'' || c2
== '\"') && !CPP_TRADITIONAL (pfile
))
4973 CPP_PUTC (pfile
, c
);
4979 case '0': case '1': case '2': case '3': case '4':
4980 case '5': case '6': case '7': case '8': case '9':
4985 CPP_RESERVE (pfile
, 2);
4986 CPP_PUTC_Q (pfile
, c
);
4991 if (!is_idchar
[c
] && c
!= '.'
4992 && ((c2
!= 'e' && c2
!= 'E'
4993 && ((c2
!= 'p' && c2
!= 'P') || CPP_C89 (pfile
)))
4994 || (c
!= '+' && c
!= '-')))
4999 CPP_NUL_TERMINATE_Q (pfile
);
5000 pfile
->only_seen_white
= 0;
5002 case 'b': case 'c': case 'd': case 'h': case 'o':
5003 case 'B': case 'C': case 'D': case 'H': case 'O':
5004 if (opts
->chill
&& PEEKC () == '\'')
5006 pfile
->only_seen_white
= 0;
5007 CPP_RESERVE (pfile
, 2);
5008 CPP_PUTC_Q (pfile
, c
);
5009 CPP_PUTC_Q (pfile
, '\'');
5015 goto chill_number_eof
;
5018 if (c
== '\\' && PEEKC() == '\n')
5025 CPP_PUTC (pfile
, c
);
5029 CPP_RESERVE (pfile
, 2);
5030 CPP_PUTC_Q (pfile
, c
);
5031 CPP_NUL_TERMINATE_Q (pfile
);
5038 CPP_NUL_TERMINATE (pfile
);
5045 case 'a': case 'e': case 'f': case 'g': case 'i': case 'j':
5046 case 'k': case 'l': case 'm': case 'n': case 'p': case 'q':
5047 case 'r': case 's': case 't': case 'u': case 'v': case 'w':
5048 case 'x': case 'y': case 'z':
5049 case 'A': case 'E': case 'F': case 'G': case 'I': case 'J':
5050 case 'K': case 'M': case 'N': case 'P': case 'Q': case 'R':
5051 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
5056 unsigned char *ident
;
5057 int before_name_written
= CPP_WRITTEN (pfile
);
5059 parse_name (pfile
, c
);
5060 pfile
->only_seen_white
= 0;
5061 if (pfile
->no_macro_expand
)
5063 ident
= pfile
->token_buffer
+ before_name_written
;
5064 ident_len
= CPP_PWRITTEN (pfile
) - ident
;
5065 hp
= cpp_lookup (pfile
, ident
, ident_len
, -1);
5068 if (hp
->type
== T_DISABLED
)
5070 if (pfile
->output_escapes
)
5071 { /* Return "@-IDENT", followed by '\0'. */
5073 CPP_RESERVE (pfile
, 3);
5074 ident
= pfile
->token_buffer
+ before_name_written
;
5075 CPP_ADJUST_WRITTEN (pfile
, 2);
5076 for (i
= ident_len
; i
>= 0; i
--) ident
[i
+2] = ident
[i
];
5083 /* If macro wants an arglist, verify that a '(' follows.
5084 first skip all whitespace, copying it to the output
5085 after the macro name. Then, if there is no '(',
5086 decide this is not a macro call and leave things that way. */
5087 if (hp
->type
== T_MACRO
&& hp
->value
.defn
->nargs
>= 0)
5089 struct parse_marker macro_mark
;
5091 while (CPP_IS_MACRO_BUFFER (CPP_BUFFER (pfile
)))
5093 cpp_buffer
*next_buf
;
5094 cpp_skip_hspace (pfile
);
5095 if (PEEKC () != EOF
)
5097 next_buf
= CPP_PREV_BUFFER (CPP_BUFFER (pfile
));
5098 (*CPP_BUFFER (pfile
)->cleanup
) (CPP_BUFFER (pfile
), pfile
);
5099 CPP_BUFFER (pfile
) = next_buf
;
5101 parse_set_mark (¯o_mark
, pfile
);
5104 cpp_skip_hspace (pfile
);
5106 is_macro_call
= c
== '(';
5112 parse_goto_mark (¯o_mark
, pfile
);
5113 parse_clear_mark (¯o_mark
);
5117 /* This is now known to be a macro call. */
5119 /* it might not actually be a macro. */
5120 if (hp
->type
!= T_MACRO
) {
5121 int xbuf_len
; U_CHAR
*xbuf
;
5122 CPP_SET_WRITTEN (pfile
, before_name_written
);
5123 special_symbol (hp
, pfile
);
5124 xbuf_len
= CPP_WRITTEN (pfile
) - before_name_written
;
5125 xbuf
= (U_CHAR
*) xmalloc (xbuf_len
+ 1);
5126 CPP_SET_WRITTEN (pfile
, before_name_written
);
5127 bcopy (CPP_PWRITTEN (pfile
), xbuf
, xbuf_len
+ 1);
5128 push_macro_expansion (pfile
, xbuf
, xbuf_len
, hp
);
5132 /* Expand the macro, reading arguments as needed,
5133 and push the expansion on the input stack. */
5134 macroexpand (pfile
, hp
);
5135 CPP_SET_WRITTEN (pfile
, before_name_written
);
5138 /* An extra "@ " is added to the end of a macro expansion
5139 to prevent accidental token pasting. We prefer to avoid
5140 unneeded extra spaces (for the sake of cpp-using tools like
5141 imake). Here we remove the space if it is safe to do so. */
5142 if (pfile
->buffer
->rlimit
- pfile
->buffer
->cur
>= 3
5143 && pfile
->buffer
->rlimit
[-2] == '@'
5144 && pfile
->buffer
->rlimit
[-1] == ' ')
5146 int c1
= pfile
->buffer
->rlimit
[-3];
5147 int c2
= CPP_BUF_PEEK (CPP_PREV_BUFFER (CPP_BUFFER (pfile
)));
5148 if (c2
== EOF
|| ! unsafe_chars (c1
, c2
))
5149 pfile
->buffer
->rlimit
-= 2;
5154 case ' ': case '\t': case '\v': case '\r':
5157 CPP_PUTC (pfile
, c
);
5159 if (c
== EOF
|| !is_hor_space
[c
])
5173 CPP_PUTC (pfile
, c
);
5174 if (pfile
->only_seen_white
== 0)
5175 pfile
->only_seen_white
= 1;
5177 output_line_command (pfile
, 1, same_file
);
5180 case '(': token
= CPP_LPAREN
; goto char1
;
5181 case ')': token
= CPP_RPAREN
; goto char1
;
5182 case '{': token
= CPP_LBRACE
; goto char1
;
5183 case '}': token
= CPP_RBRACE
; goto char1
;
5184 case ',': token
= CPP_COMMA
; goto char1
;
5185 case ';': token
= CPP_SEMICOLON
; goto char1
;
5191 pfile
->only_seen_white
= 0;
5192 CPP_PUTC (pfile
, c
);
5198 /* Like cpp_get_token, but skip spaces and comments. */
5201 cpp_get_non_space_token (pfile
)
5204 int old_written
= CPP_WRITTEN (pfile
);
5207 enum cpp_token token
= cpp_get_token (pfile
);
5208 if (token
!= CPP_COMMENT
&& token
!= CPP_POP
5209 && token
!= CPP_HSPACE
&& token
!= CPP_VSPACE
)
5211 CPP_SET_WRITTEN (pfile
, old_written
);
5215 /* Parse an identifier starting with C. */
5218 parse_name (pfile
, c
)
5219 cpp_reader
*pfile
; int c
;
5225 if (c
== '\\' && PEEKC() == '\n')
5234 if (c
== '$' && CPP_PEDANTIC (pfile
))
5235 cpp_pedwarn (pfile
, "`$' in identifier");
5237 CPP_RESERVE(pfile
, 2); /* One more for final NUL. */
5238 CPP_PUTC_Q (pfile
, c
);
5243 CPP_NUL_TERMINATE_Q (pfile
);
5248 /* Maintain and search list of included files, for #import. */
5250 /* Hash a file name for import_hash_table. */
5258 while (*f
) val
+= *f
++;
5259 return (val
%IMPORT_HASH_SIZE
);
5262 /* Search for file FILENAME in import_hash_table.
5263 Return -2 if found, either a matching name or a matching inode.
5264 Otherwise, open the file and return a file descriptor if successful
5265 or -1 if unsuccessful. */
5268 lookup_import (pfile
, filename
, searchptr
)
5271 struct file_name_list
*searchptr
;
5273 struct import_file
*i
;
5279 hashval
= import_hash (filename
);
5281 /* Attempt to find file in list of already included files */
5282 i
= pfile
->import_hash_table
[hashval
];
5285 if (!strcmp (filename
, i
->name
))
5286 return -2; /* return found */
5289 /* Open it and try a match on inode/dev */
5290 fd
= open_include_file (pfile
, filename
, searchptr
);
5294 for (h
= 0; h
< IMPORT_HASH_SIZE
; h
++) {
5295 i
= pfile
->import_hash_table
[h
];
5297 /* Compare the inode and the device.
5298 Supposedly on some systems the inode is not a scalar. */
5299 if (!bcmp ((char *) &i
->inode
, (char *) &sb
.st_ino
, sizeof (sb
.st_ino
))
5300 && i
->dev
== sb
.st_dev
) {
5302 return -2; /* return found */
5307 return fd
; /* Not found, return open file */
5310 /* Add the file FNAME, open on descriptor FD, to import_hash_table. */
5313 add_import (pfile
, fd
, fname
)
5318 struct import_file
*i
;
5322 hashval
= import_hash (fname
);
5324 i
= (struct import_file
*)xmalloc (sizeof (struct import_file
));
5325 i
->name
= (char *)xmalloc (strlen (fname
)+1);
5326 strcpy (i
->name
, fname
);
5327 bcopy ((char *) &sb
.st_ino
, (char *) &i
->inode
, sizeof (sb
.st_ino
));
5329 i
->next
= pfile
->import_hash_table
[hashval
];
5330 pfile
->import_hash_table
[hashval
] = i
;
5333 /* The file_name_map structure holds a mapping of file names for a
5334 particular directory. This mapping is read from the file named
5335 FILE_NAME_MAP_FILE in that directory. Such a file can be used to
5336 map filenames on a file system with severe filename restrictions,
5337 such as DOS. The format of the file name map file is just a series
5338 of lines with two tokens on each line. The first token is the name
5339 to map, and the second token is the actual name to use. */
5341 struct file_name_map
5343 struct file_name_map
*map_next
;
5348 #define FILE_NAME_MAP_FILE "header.gcc"
5350 /* Read a space delimited string of unlimited length from a stdio
5354 read_filename_string (ch
, f
)
5362 set
= alloc
= xmalloc (len
+ 1);
5366 while ((ch
= getc (f
)) != EOF
&& ! is_space
[ch
])
5368 if (set
- alloc
== len
)
5371 alloc
= xrealloc (alloc
, len
+ 1);
5372 set
= alloc
+ len
/ 2;
5382 /* This structure holds a linked list of file name maps, one per directory. */
5384 struct file_name_map_list
5386 struct file_name_map_list
*map_list_next
;
5387 char *map_list_name
;
5388 struct file_name_map
*map_list_map
;
5391 /* Read the file name map file for DIRNAME. */
5393 static struct file_name_map
*
5394 read_name_map (pfile
, dirname
)
5398 register struct file_name_map_list
*map_list_ptr
;
5402 for (map_list_ptr
= CPP_OPTIONS (pfile
)->map_list
; map_list_ptr
;
5403 map_list_ptr
= map_list_ptr
->map_list_next
)
5404 if (! strcmp (map_list_ptr
->map_list_name
, dirname
))
5405 return map_list_ptr
->map_list_map
;
5407 map_list_ptr
= ((struct file_name_map_list
*)
5408 xmalloc (sizeof (struct file_name_map_list
)));
5409 map_list_ptr
->map_list_name
= savestring (dirname
);
5410 map_list_ptr
->map_list_map
= NULL
;
5412 name
= (char *) alloca (strlen (dirname
) + strlen (FILE_NAME_MAP_FILE
) + 2);
5413 strcpy (name
, dirname
);
5416 strcat (name
, FILE_NAME_MAP_FILE
);
5417 f
= fopen (name
, "r");
5419 map_list_ptr
->map_list_map
= NULL
;
5423 int dirlen
= strlen (dirname
);
5425 while ((ch
= getc (f
)) != EOF
)
5428 struct file_name_map
*ptr
;
5432 from
= read_filename_string (ch
, f
);
5433 while ((ch
= getc (f
)) != EOF
&& is_hor_space
[ch
])
5435 to
= read_filename_string (ch
, f
);
5437 ptr
= ((struct file_name_map
*)
5438 xmalloc (sizeof (struct file_name_map
)));
5439 ptr
->map_from
= from
;
5441 /* Make the real filename absolute. */
5446 ptr
->map_to
= xmalloc (dirlen
+ strlen (to
) + 2);
5447 strcpy (ptr
->map_to
, dirname
);
5448 ptr
->map_to
[dirlen
] = '/';
5449 strcpy (ptr
->map_to
+ dirlen
+ 1, to
);
5453 ptr
->map_next
= map_list_ptr
->map_list_map
;
5454 map_list_ptr
->map_list_map
= ptr
;
5456 while ((ch
= getc (f
)) != '\n')
5463 map_list_ptr
->map_list_next
= CPP_OPTIONS (pfile
)->map_list
;
5464 CPP_OPTIONS (pfile
)->map_list
= map_list_ptr
;
5466 return map_list_ptr
->map_list_map
;
5469 /* Try to open include file FILENAME. SEARCHPTR is the directory
5470 being tried from the include file search path. This function maps
5471 filenames on file systems based on information read by
5475 open_include_file (pfile
, filename
, searchptr
)
5478 struct file_name_list
*searchptr
;
5480 if (CPP_OPTIONS (pfile
)->remap
)
5482 register struct file_name_map
*map
;
5483 register char *from
;
5486 if (searchptr
&& ! searchptr
->got_name_map
)
5488 searchptr
->name_map
= read_name_map (pfile
,
5490 ? searchptr
->fname
: ".");
5491 searchptr
->got_name_map
= 1;
5494 /* First check the mapping for the directory we are using. */
5495 if (searchptr
&& searchptr
->name_map
)
5498 if (searchptr
->fname
)
5499 from
+= strlen (searchptr
->fname
) + 1;
5500 for (map
= searchptr
->name_map
; map
; map
= map
->map_next
)
5502 if (! strcmp (map
->map_from
, from
))
5504 /* Found a match. */
5505 return open (map
->map_to
, O_RDONLY
, 0666);
5510 /* Try to find a mapping file for the particular directory we are
5511 looking in. Thus #include <sys/types.h> will look up sys/types.h
5512 in /usr/include/header.gcc and look up types.h in
5513 /usr/include/sys/header.gcc. */
5514 p
= rindex (filename
, '/');
5519 && strlen (searchptr
->fname
) == p
- filename
5520 && ! strncmp (searchptr
->fname
, filename
, p
- filename
))
5522 /* FILENAME is in SEARCHPTR, which we've already checked. */
5523 return open (filename
, O_RDONLY
, 0666);
5533 dir
= (char *) alloca (p
- filename
+ 1);
5534 bcopy (filename
, dir
, p
- filename
);
5535 dir
[p
- filename
] = '\0';
5538 for (map
= read_name_map (pfile
, dir
); map
; map
= map
->map_next
)
5539 if (! strcmp (map
->map_from
, from
))
5540 return open (map
->map_to
, O_RDONLY
, 0666);
5543 return open (filename
, O_RDONLY
, 0666);
5546 /* Process the contents of include file FNAME, already open on descriptor F,
5548 SYSTEM_HEADER_P is 1 if this file resides in any one of the known
5549 "system" include directories (as decided by the `is_system_include'
5551 DIRPTR is the link in the dir path through which this file was found,
5552 or 0 if the file name was absolute or via the current directory.
5553 Return 1 on success, 0 on failure.
5555 The caller is responsible for the cpp_push_buffer. */
5558 finclude (pfile
, f
, fname
, system_header_p
, dirptr
)
5562 int system_header_p
;
5563 struct file_name_list
*dirptr
;
5569 cpp_buffer
*fp
; /* For input stack frame */
5571 int missing_newline
= 0;
5574 if (fstat (f
, &st
) < 0)
5576 cpp_perror_with_name (pfile
, fname
);
5578 cpp_pop_buffer (pfile
);
5582 fp
= CPP_BUFFER (pfile
);
5583 fp
->nominal_fname
= fp
->fname
= fname
;
5588 fp
->system_header_p
= system_header_p
;
5591 fp
->cleanup
= file_cleanup
;
5593 if (S_ISREG (st
.st_mode
)) {
5594 st_size
= (size_t) st
.st_size
;
5595 if (st_size
!= st
.st_size
|| st_size
+ 2 < st_size
) {
5596 cpp_error (pfile
, "file `%s' too large", fname
);
5600 fp
->buf
= (U_CHAR
*) xmalloc (st_size
+ 2);
5601 fp
->alimit
= fp
->buf
+ st_size
+ 2;
5604 /* Read the file contents, knowing that st_size is an upper bound
5605 on the number of bytes we can read. */
5606 length
= safe_read (f
, fp
->buf
, st_size
);
5607 fp
->rlimit
= fp
->buf
+ length
;
5608 if (length
< 0) goto nope
;
5610 else if (S_ISDIR (st
.st_mode
)) {
5611 cpp_error (pfile
, "directory `%s' specified in #include", fname
);
5615 /* Cannot count its file size before reading.
5616 First read the entire file into heap and
5617 copy them into buffer on stack. */
5622 fp
->buf
= (U_CHAR
*) xmalloc (bsize
+ 2);
5625 i
= safe_read (f
, fp
->buf
+ st_size
, bsize
- st_size
);
5627 goto nope
; /* error! */
5629 if (st_size
!= bsize
)
5630 break; /* End of file */
5632 fp
->buf
= (U_CHAR
*) xrealloc (fp
->buf
, bsize
+ 2);
5638 if ((length
> 0 && fp
->buf
[length
- 1] != '\n')
5639 /* Backslash-newline at end is not good enough. */
5640 || (length
> 1 && fp
->buf
[length
- 2] == '\\')) {
5641 fp
->buf
[length
++] = '\n';
5643 missing_newline
= 1;
5646 fp
->buf
[length
] = '\0';
5647 fp
->rlimit
= fp
->buf
+ length
;
5649 /* Close descriptor now, so nesting does not use lots of descriptors. */
5652 /* Must do this before calling trigraph_pcp, so that the correct file name
5653 will be printed in warning messages. */
5655 pfile
->input_stack_listing_current
= 0;
5665 if (missing_newline
)
5668 if (CPP_PEDANTIC (pfile
) && missing_newline
)
5669 pedwarn ("file does not end in newline");
5672 input_file_stack_tick
++;
5679 cpp_perror_with_name (pfile
, fname
);
5685 /* This is called after options have been processed.
5686 * Check options for consistency, and setup for processing input
5687 * from the file named FNAME. (Use standard input if FNAME==NULL.)
5688 * Return 1 on success, 0 on failure.
5692 cpp_start_read (pfile
, fname
)
5696 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
5697 struct cpp_pending
*pend
;
5702 /* The code looks at the defaults through this pointer, rather than through
5703 the constant structure above. This pointer gets changed if an environment
5704 variable specifies other defaults. */
5705 struct default_include
*include_defaults
= include_defaults_array
;
5707 /* Add dirs from CPATH after dirs from -I. */
5708 /* There seems to be confusion about what CPATH should do,
5709 so for the moment it is not documented. */
5710 /* Some people say that CPATH should replace the standard include dirs,
5711 but that seems pointless: it comes before them, so it overrides them
5713 GET_ENV_PATH_LIST (p
, "CPATH");
5714 if (p
!= 0 && ! opts
->no_standard_includes
)
5715 path_include (pfile
, p
);
5717 /* Now that dollars_in_ident is known, initialize is_idchar. */
5718 initialize_char_syntax (opts
);
5720 /* Do partial setup of input buffer for the sake of generating
5721 early #line directives (when -g is in effect). */
5722 fp
= cpp_push_buffer (pfile
, NULL
, 0);
5725 if (opts
->in_fname
== NULL
)
5726 opts
->in_fname
= "";
5727 fp
->nominal_fname
= fp
->fname
= opts
->in_fname
;
5730 /* Install __LINE__, etc. Must follow initialize_char_syntax
5731 and option processing. */
5732 initialize_builtins (pfile
);
5734 /* Do standard #defines and assertions
5735 that identify system and machine type. */
5737 if (!opts
->inhibit_predefs
) {
5738 char *p
= (char *) alloca (strlen (predefs
) + 1);
5739 strcpy (p
, predefs
);
5742 while (*p
== ' ' || *p
== '\t')
5744 /* Handle -D options. */
5745 if (p
[0] == '-' && p
[1] == 'D') {
5747 while (*p
&& *p
!= ' ' && *p
!= '\t')
5751 if (opts
->debug_output
)
5752 output_line_command (pfile
, 0, same_file
);
5753 cpp_define (pfile
, q
);
5754 while (*p
== ' ' || *p
== '\t')
5756 } else if (p
[0] == '-' && p
[1] == 'A') {
5757 /* Handle -A options (assertions). */
5766 past_name
= assertion
;
5767 /* Locate end of name. */
5768 while (*past_name
&& *past_name
!= ' '
5769 && *past_name
!= '\t' && *past_name
!= '(')
5771 /* Locate `(' at start of value. */
5773 while (*value
&& (*value
== ' ' || *value
== '\t'))
5775 if (*value
++ != '(')
5777 while (*value
&& (*value
== ' ' || *value
== '\t'))
5780 /* Locate end of value. */
5781 while (*past_value
&& *past_value
!= ' '
5782 && *past_value
!= '\t' && *past_value
!= ')')
5784 termination
= past_value
;
5785 while (*termination
&& (*termination
== ' ' || *termination
== '\t'))
5787 if (*termination
++ != ')')
5789 if (*termination
&& *termination
!= ' ' && *termination
!= '\t')
5791 /* Temporarily null-terminate the value. */
5792 save_char
= *termination
;
5793 *termination
= '\0';
5794 /* Install the assertion. */
5795 make_assertion (pfile
, "-A", assertion
);
5796 *termination
= (char) save_char
;
5798 while (*p
== ' ' || *p
== '\t')
5806 /* Now handle the command line options. */
5808 /* Do -U's, -D's and -A's in the order they were seen. */
5809 /* First reverse the list. */
5810 opts
->pending
= nreverse_pending (opts
->pending
);
5812 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
5814 if (pend
->cmd
!= NULL
&& pend
->cmd
[0] == '-')
5816 switch (pend
->cmd
[1])
5819 if (opts
->debug_output
)
5820 output_line_command (pfile
, 0, same_file
);
5821 do_undef (pfile
, NULL
, pend
->arg
, pend
->arg
+ strlen (pend
->arg
));
5824 if (opts
->debug_output
)
5825 output_line_command (pfile
, 0, same_file
);
5826 cpp_define (pfile
, pend
->arg
);
5829 make_assertion (pfile
, "-A", pend
->arg
);
5835 opts
->done_initializing
= 1;
5837 { /* Read the appropriate environment variable and if it exists
5838 replace include_defaults with the listed path. */
5840 switch ((opts
->objc
<< 1) + opts
->cplusplus
)
5843 GET_ENV_PATH_LIST (epath
, "C_INCLUDE_PATH");
5846 GET_ENV_PATH_LIST (epath
, "CPLUS_INCLUDE_PATH");
5849 GET_ENV_PATH_LIST (epath
, "OBJC_INCLUDE_PATH");
5852 GET_ENV_PATH_LIST (epath
, "OBJCPLUS_INCLUDE_PATH");
5855 /* If the environment var for this language is set,
5856 add to the default list of include directories. */
5858 char *nstore
= (char *) alloca (strlen (epath
) + 2);
5860 char *startp
, *endp
;
5862 for (num_dirs
= 1, startp
= epath
; *startp
; startp
++)
5863 if (*startp
== PATH_SEPARATOR
)
5866 = (struct default_include
*) xmalloc ((num_dirs
5867 * sizeof (struct default_include
))
5868 + sizeof (include_defaults_array
));
5869 startp
= endp
= epath
;
5872 /* Handle cases like c:/usr/lib:d:/gcc/lib */
5873 if ((*endp
== PATH_SEPARATOR
)
5875 strncpy (nstore
, startp
, endp
-startp
);
5877 strcpy (nstore
, ".");
5879 nstore
[endp
-startp
] = '\0';
5881 include_defaults
[num_dirs
].fname
= savestring (nstore
);
5882 include_defaults
[num_dirs
].component
= 0;
5883 include_defaults
[num_dirs
].cplusplus
= opts
->cplusplus
;
5884 include_defaults
[num_dirs
].cxx_aware
= 1;
5888 endp
= startp
= endp
+ 1;
5892 /* Put the usual defaults back in at the end. */
5893 bcopy ((char *) include_defaults_array
,
5894 (char *) &include_defaults
[num_dirs
],
5895 sizeof (include_defaults_array
));
5899 append_include_chain (pfile
, opts
->before_system
, opts
->last_before_system
);
5900 opts
->first_system_include
= opts
->before_system
;
5902 /* Unless -fnostdinc,
5903 tack on the standard include file dirs to the specified list */
5904 if (!opts
->no_standard_includes
) {
5905 struct default_include
*p
= include_defaults
;
5906 char *specd_prefix
= opts
->include_prefix
;
5907 char *default_prefix
= savestring (GCC_INCLUDE_DIR
);
5908 int default_len
= 0;
5909 /* Remove the `include' from /usr/local/lib/gcc.../include. */
5910 if (!strcmp (default_prefix
+ strlen (default_prefix
) - 8, "/include")) {
5911 default_len
= strlen (default_prefix
) - 7;
5912 default_prefix
[default_len
] = 0;
5914 /* Search "translated" versions of GNU directories.
5915 These have /usr/local/lib/gcc... replaced by specd_prefix. */
5916 if (specd_prefix
!= 0 && default_len
!= 0)
5917 for (p
= include_defaults
; p
->fname
; p
++) {
5918 /* Some standard dirs are only for C++. */
5920 || (opts
->cplusplus
&& !opts
->no_standard_cplusplus_includes
)) {
5921 /* Does this dir start with the prefix? */
5922 if (!strncmp (p
->fname
, default_prefix
, default_len
)) {
5923 /* Yes; change prefix and add to search list. */
5924 struct file_name_list
*new
5925 = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
5926 int this_len
= strlen (specd_prefix
) + strlen (p
->fname
) - default_len
;
5927 char *str
= (char *) xmalloc (this_len
+ 1);
5928 strcpy (str
, specd_prefix
);
5929 strcat (str
, p
->fname
+ default_len
);
5931 new->control_macro
= 0;
5932 new->c_system_include_path
= !p
->cxx_aware
;
5933 new->got_name_map
= 0;
5934 append_include_chain (pfile
, new, new);
5935 if (opts
->first_system_include
== 0)
5936 opts
->first_system_include
= new;
5940 /* Search ordinary names for GNU include directories. */
5941 for (p
= include_defaults
; p
->fname
; p
++) {
5942 /* Some standard dirs are only for C++. */
5944 || (opts
->cplusplus
&& !opts
->no_standard_cplusplus_includes
)) {
5945 struct file_name_list
*new
5946 = (struct file_name_list
*) xmalloc (sizeof (struct file_name_list
));
5947 new->control_macro
= 0;
5948 new->c_system_include_path
= !p
->cxx_aware
;
5949 new->fname
= update_path (p
->fname
, p
->component
);
5950 new->got_name_map
= 0;
5951 append_include_chain (pfile
, new, new);
5952 if (opts
->first_system_include
== 0)
5953 opts
->first_system_include
= new;
5958 /* Tack the after_include chain at the end of the include chain. */
5959 append_include_chain (pfile
, opts
->after_include
, opts
->last_after_include
);
5960 if (opts
->first_system_include
== 0)
5961 opts
->first_system_include
= opts
->after_include
;
5963 /* With -v, print the list of dirs to search. */
5964 if (opts
->verbose
) {
5965 struct file_name_list
*p
;
5966 fprintf (stderr
, "#include \"...\" search starts here:\n");
5967 for (p
= opts
->include
; p
; p
= p
->next
) {
5968 if (p
== opts
->first_bracket_include
)
5969 fprintf (stderr
, "#include <...> search starts here:\n");
5970 fprintf (stderr
, " %s\n", p
->fname
);
5972 fprintf (stderr
, "End of search list.\n");
5975 /* Scan the -imacros files before the main input.
5976 Much like #including them, but with no_output set
5977 so that only their macro definitions matter. */
5979 opts
->no_output
++; pfile
->no_record_file
++;
5980 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
5982 if (pend
->cmd
!= NULL
&& strcmp (pend
->cmd
, "-imacros") == 0)
5984 int fd
= open (pend
->arg
, O_RDONLY
, 0666);
5987 cpp_perror_with_name (pfile
, pend
->arg
);
5990 if (!cpp_push_buffer (pfile
, NULL
, 0))
5992 finclude (pfile
, fd
, pend
->arg
, 0, NULL_PTR
);
5993 cpp_scan_buffer (pfile
);
5996 opts
->no_output
--; pfile
->no_record_file
--;
5998 /* Copy the entire contents of the main input file into
5999 the stacked input buffer previously allocated for it. */
6000 if (fname
== NULL
|| *fname
== 0) {
6003 } else if ((f
= open (fname
, O_RDONLY
, 0666)) < 0)
6004 cpp_pfatal_with_name (pfile
, fname
);
6006 /* -MG doesn't select the form of output and must be specified with one of
6007 -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
6008 inhibit compilation. */
6009 if (opts
->print_deps_missing_files
6010 && (opts
->print_deps
== 0 || !opts
->no_output
))
6012 cpp_fatal (pfile
, "-MG must be specified with one of -M or -MM");
6016 /* Either of two environment variables can specify output of deps.
6017 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
6018 where OUTPUT_FILE is the file to write deps info to
6019 and DEPS_TARGET is the target to mention in the deps. */
6021 if (opts
->print_deps
== 0
6022 && (getenv ("SUNPRO_DEPENDENCIES") != 0
6023 || getenv ("DEPENDENCIES_OUTPUT") != 0)) {
6024 char *spec
= getenv ("DEPENDENCIES_OUTPUT");
6030 spec
= getenv ("SUNPRO_DEPENDENCIES");
6031 opts
->print_deps
= 2;
6034 opts
->print_deps
= 1;
6037 /* Find the space before the DEPS_TARGET, if there is one. */
6038 /* This should use index. (mrs) */
6039 while (*s
!= 0 && *s
!= ' ') s
++;
6042 opts
->deps_target
= s
+ 1;
6043 output_file
= (char *) xmalloc (s
- spec
+ 1);
6044 bcopy (spec
, output_file
, s
- spec
);
6045 output_file
[s
- spec
] = 0;
6049 opts
->deps_target
= 0;
6053 opts
->deps_file
= output_file
;
6054 opts
->print_deps_append
= 1;
6057 /* For -M, print the expected object file name
6058 as the target of this Make-rule. */
6059 if (opts
->print_deps
)
6061 pfile
->deps_allocated_size
= 200;
6062 pfile
->deps_buffer
= (char *) xmalloc (pfile
->deps_allocated_size
);
6063 pfile
->deps_buffer
[0] = 0;
6064 pfile
->deps_size
= 0;
6065 pfile
->deps_column
= 0;
6067 if (opts
->deps_target
)
6068 deps_output (pfile
, opts
->deps_target
, ':');
6069 else if (*opts
->in_fname
== 0)
6070 deps_output (pfile
, "-", ':');
6075 static char *known_suffixes
[] = { ".c", ".C", ".s", ".S", ".m",
6076 ".cc", ".cxx", ".cpp", ".cp",
6080 /* Discard all directory prefixes from filename. */
6081 if ((q
= rindex (opts
->in_fname
, '/')) != NULL
6082 #ifdef DIR_SEPARATOR
6083 && (q
= rindex (opts
->in_fname
, DIR_SEPARATOR
)) != NULL
6090 /* Copy remainder to mungable area. */
6091 p
= (char *) alloca (strlen(q
) + 8);
6094 /* Output P, but remove known suffixes. */
6097 /* Point to the filename suffix. */
6098 r
= rindex (p
, '.');
6099 /* Compare against the known suffixes. */
6101 while (known_suffixes
[x
] != 0)
6103 if (strncmp (known_suffixes
[x
], r
, q
- r
) == 0)
6105 /* Make q point to the bit we're going to overwrite
6106 with an object suffix. */
6113 /* Supply our own suffix. */
6120 deps_output (pfile
, p
, ':');
6121 deps_output (pfile
, opts
->in_fname
, ' ');
6126 /* Make sure data ends with a newline. And put a null after it. */
6128 if ((fp
->length
> 0 && fp
->buf
[fp
->length
- 1] != '\n')
6129 /* Backslash-newline at end is not good enough. */
6130 || (fp
->length
> 1 && fp
->buf
[fp
->length
- 2] == '\\')) {
6131 fp
->buf
[fp
->length
++] = '\n';
6132 missing_newline
= 1;
6134 fp
->buf
[fp
->length
] = '\0';
6136 /* Unless inhibited, convert trigraphs in the input. */
6142 /* Scan the -include files before the main input.
6143 We push these in reverse order, so that the first one is handled first. */
6145 pfile
->no_record_file
++;
6146 opts
->pending
= nreverse_pending (opts
->pending
);
6147 for (pend
= opts
->pending
; pend
; pend
= pend
->next
)
6149 if (pend
->cmd
!= NULL
&& strcmp (pend
->cmd
, "-include") == 0)
6151 int fd
= open (pend
->arg
, O_RDONLY
, 0666);
6154 cpp_perror_with_name (pfile
, pend
->arg
);
6157 if (!cpp_push_buffer (pfile
, NULL
, 0))
6159 finclude (pfile
, fd
, pend
->arg
, 0, NULL_PTR
);
6162 pfile
->no_record_file
--;
6164 /* Free the pending list. */
6165 for (pend
= opts
->pending
; pend
; )
6167 struct cpp_pending
*next
= pend
->next
;
6171 opts
->pending
= NULL
;
6174 /* Scan the input, processing macros and directives. */
6176 rescan (&outbuf
, 0);
6178 if (missing_newline
)
6181 if (CPP_PEDANTIC (pfile
) && missing_newline
)
6182 pedwarn ("file does not end in newline");
6185 if (finclude (pfile
, f
, fname
, 0, NULL_PTR
))
6186 output_line_command (pfile
, 0, same_file
);
6191 cpp_reader_init (pfile
)
6194 bzero ((char *) pfile
, sizeof (cpp_reader
));
6195 pfile
->get_token
= cpp_get_token
;
6197 pfile
->token_buffer_size
= 200;
6198 pfile
->token_buffer
= (U_CHAR
*) xmalloc (pfile
->token_buffer_size
);
6199 CPP_SET_WRITTEN (pfile
, 0);
6201 pfile
->system_include_depth
= 0;
6202 pfile
->dont_repeat_files
= 0;
6203 pfile
->all_include_files
= 0;
6204 pfile
->max_include_len
= 0;
6205 pfile
->timebuf
= NULL
;
6206 pfile
->only_seen_white
= 1;
6207 pfile
->buffer
= CPP_NULL_BUFFER(pfile
);
6210 static struct cpp_pending
*
6211 nreverse_pending (list
)
6212 struct cpp_pending
*list
;
6215 register struct cpp_pending
*prev
= 0, *next
, *pend
;
6216 for (pend
= list
; pend
; pend
= next
)
6226 push_pending (pfile
, cmd
, arg
)
6231 struct cpp_pending
*pend
6232 = (struct cpp_pending
*) xmalloc (sizeof (struct cpp_pending
));
6235 pend
->next
= CPP_OPTIONS (pfile
)->pending
;
6236 CPP_OPTIONS (pfile
)->pending
= pend
;
6243 printf ("Usage: %s [switches] input output\n", progname
);
6244 printf ("Switches:\n");
6245 printf (" -include <file> Include the contents of <file> before other files\n");
6246 printf (" -imacros <file> Accept definition of marcos in <file>\n");
6247 printf (" -iprefix <path> Specify <path> as a prefix for next two options\n");
6248 printf (" -iwithprefix <dir> Add <dir> to the end of the system include paths\n");
6249 printf (" -iwithprefixbefore <dir> Add <dir> to the end of the main include paths\n");
6250 printf (" -isystem <dir> Add <dir> to the start of the system include paths\n");
6251 printf (" -idirafter <dir> Add <dir> to the end of the system include paths\n");
6252 printf (" -I <dir> Add <dir> to the end of the main include paths\n");
6253 printf (" -nostdinc Do not search the system include directories\n");
6254 printf (" -nostdinc++ Do not search the system include directories for C++\n");
6255 printf (" -o <file> Put output into <file>\n");
6256 printf (" -pedantic Issue all warnings demanded by strict ANSI C\n");
6257 printf (" -traditional Follow K&R pre-processor behaviour\n");
6258 printf (" -trigraphs Support ANSI C trigraphs\n");
6259 printf (" -lang-c Assume that the input sources are in C\n");
6260 printf (" -lang-c89 Assume that the input sources are in C89\n");
6261 printf (" -lang-c++ Assume that the input sources are in C++\n");
6262 printf (" -lang-objc Assume that the input sources are in ObjectiveC\n");
6263 printf (" -lang-objc++ Assume that the input sources are in ObjectiveC++\n");
6264 printf (" -lang-asm Assume that the input sources are in assembler\n");
6265 printf (" -lang-chill Assume that the input sources are in Chill\n");
6266 printf (" -+ Allow parsing of C++ style features\n");
6267 printf (" -w Inhibit warning messages\n");
6268 printf (" -Wtrigraphs Warn if trigraphs are encountered\n");
6269 printf (" -Wno-trigraphs Do not warn about trigraphs\n");
6270 printf (" -Wcomment{s} Warn if one comment starts inside another\n");
6271 printf (" -Wno-comment{s} Do not warn about comments\n");
6272 printf (" -Wtraditional Warn if a macro argument is/would be turned into\n");
6273 printf (" a string if -tradtional is specified\n");
6274 printf (" -Wno-traditional Do not warn about stringification\n");
6275 printf (" -Wundef Warn if an undefined macro is used by #if\n");
6276 printf (" -Wno-undef Do not warn about testing udefined macros\n");
6277 printf (" -Wimport Warn about the use of the #import directive\n");
6278 printf (" -Wno-import Do not warn about the use of #import\n");
6279 printf (" -Werror Treat all warnings as errors\n");
6280 printf (" -Wno-error Do not treat warnings as errors\n");
6281 printf (" -Wall Enable all preprocessor warnings\n");
6282 printf (" -M Generate make dependencies\n");
6283 printf (" -MM As -M, but ignore system header files\n");
6284 printf (" -MD As -M, but put output in a .d file\n");
6285 printf (" -MMD As -MD, but ignore system header files\n");
6286 printf (" -MG Treat missing header file as generated files\n");
6287 printf (" -g Include #define and #undef directives in the output\n");
6288 printf (" -D<macro> Define a <macro> with string '1' as its value\n");
6289 printf (" -D<macro>=<val> Define a <macro> with <val> as its value\n");
6290 printf (" -A<question> (<answer>) Assert the <answer> to <question>\n");
6291 printf (" -U<macro> Undefine <macro> \n");
6292 printf (" -u or -undef Do not predefine any macros\n");
6293 printf (" -v Display the version number\n");
6294 printf (" -H Print the name of header files as they are used\n");
6295 printf (" -C Do not discard comments\n");
6296 printf (" -dM Display a list of macro definitions active at end\n");
6297 printf (" -dD Preserve macro definitions in output\n");
6298 printf (" -dN As -dD except that only the names are preserved\n");
6299 printf (" -dI Include #include directives in the output\n");
6300 printf (" -ifoutput Describe skipped code blocks in output \n");
6301 printf (" -P Do not generate #line directives\n");
6302 printf (" -$ Do not include '$' in identifiers\n");
6303 printf (" -remap Remap file names when including files.\n");
6304 printf (" -h or --help Display this information\n");
6308 /* Handle one command-line option in (argc, argv).
6309 Can be called multiple times, to handle multiple sets of options.
6310 Returns number of strings consumed. */
6312 cpp_handle_option (pfile
, argc
, argv
)
6317 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
6319 if (argv
[i
][0] != '-') {
6320 if (opts
->out_fname
!= NULL
)
6323 cpp_fatal (pfile
, "Too many arguments");
6325 else if (opts
->in_fname
!= NULL
)
6326 opts
->out_fname
= argv
[i
];
6328 opts
->in_fname
= argv
[i
];
6330 switch (argv
[i
][1]) {
6333 cpp_fatal (pfile
, "Filename missing after `%s' option", argv
[i
]);
6336 cpp_fatal (pfile
, "Directory name missing after `%s' option", argv
[i
]);
6340 if (!strcmp (argv
[i
], "-include")
6341 || !strcmp (argv
[i
], "-imacros")) {
6343 goto missing_filename
;
6345 push_pending (pfile
, argv
[i
], argv
[i
+1]), i
++;
6347 if (!strcmp (argv
[i
], "-iprefix")) {
6349 goto missing_filename
;
6351 opts
->include_prefix
= argv
[++i
];
6353 if (!strcmp (argv
[i
], "-ifoutput")) {
6354 opts
->output_conditionals
= 1;
6356 if (!strcmp (argv
[i
], "-isystem")) {
6357 struct file_name_list
*dirtmp
;
6360 goto missing_filename
;
6362 dirtmp
= (struct file_name_list
*)
6363 xmalloc (sizeof (struct file_name_list
));
6365 dirtmp
->control_macro
= 0;
6366 dirtmp
->c_system_include_path
= 1;
6367 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1]) + 1);
6368 strcpy (dirtmp
->fname
, argv
[++i
]);
6369 dirtmp
->got_name_map
= 0;
6371 if (opts
->before_system
== 0)
6372 opts
->before_system
= dirtmp
;
6374 opts
->last_before_system
->next
= dirtmp
;
6375 opts
->last_before_system
= dirtmp
; /* Tail follows the last one */
6377 /* Add directory to end of path for includes,
6378 with the default prefix at the front of its name. */
6379 if (!strcmp (argv
[i
], "-iwithprefix")) {
6380 struct file_name_list
*dirtmp
;
6383 if (opts
->include_prefix
!= 0)
6384 prefix
= opts
->include_prefix
;
6386 prefix
= savestring (GCC_INCLUDE_DIR
);
6387 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6388 if (!strcmp (prefix
+ strlen (prefix
) - 8, "/include"))
6389 prefix
[strlen (prefix
) - 7] = 0;
6392 dirtmp
= (struct file_name_list
*)
6393 xmalloc (sizeof (struct file_name_list
));
6394 dirtmp
->next
= 0; /* New one goes on the end */
6395 dirtmp
->control_macro
= 0;
6396 dirtmp
->c_system_include_path
= 0;
6398 goto missing_dirname
;
6400 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1])
6401 + strlen (prefix
) + 1);
6402 strcpy (dirtmp
->fname
, prefix
);
6403 strcat (dirtmp
->fname
, argv
[++i
]);
6404 dirtmp
->got_name_map
= 0;
6406 if (opts
->after_include
== 0)
6407 opts
->after_include
= dirtmp
;
6409 opts
->last_after_include
->next
= dirtmp
;
6410 opts
->last_after_include
= dirtmp
; /* Tail follows the last one */
6412 /* Add directory to main path for includes,
6413 with the default prefix at the front of its name. */
6414 if (!strcmp (argv
[i
], "-iwithprefixbefore")) {
6415 struct file_name_list
*dirtmp
;
6418 if (opts
->include_prefix
!= 0)
6419 prefix
= opts
->include_prefix
;
6421 prefix
= savestring (GCC_INCLUDE_DIR
);
6422 /* Remove the `include' from /usr/local/lib/gcc.../include. */
6423 if (!strcmp (prefix
+ strlen (prefix
) - 8, "/include"))
6424 prefix
[strlen (prefix
) - 7] = 0;
6427 dirtmp
= (struct file_name_list
*)
6428 xmalloc (sizeof (struct file_name_list
));
6429 dirtmp
->next
= 0; /* New one goes on the end */
6430 dirtmp
->control_macro
= 0;
6431 dirtmp
->c_system_include_path
= 0;
6433 goto missing_dirname
;
6435 dirtmp
->fname
= (char *) xmalloc (strlen (argv
[i
+1])
6436 + strlen (prefix
) + 1);
6437 strcpy (dirtmp
->fname
, prefix
);
6438 strcat (dirtmp
->fname
, argv
[++i
]);
6439 dirtmp
->got_name_map
= 0;
6441 append_include_chain (pfile
, dirtmp
, dirtmp
);
6443 /* Add directory to end of path for includes. */
6444 if (!strcmp (argv
[i
], "-idirafter")) {
6445 struct file_name_list
*dirtmp
;
6447 dirtmp
= (struct file_name_list
*)
6448 xmalloc (sizeof (struct file_name_list
));
6449 dirtmp
->next
= 0; /* New one goes on the end */
6450 dirtmp
->control_macro
= 0;
6451 dirtmp
->c_system_include_path
= 0;
6453 goto missing_dirname
;
6455 dirtmp
->fname
= argv
[++i
];
6456 dirtmp
->got_name_map
= 0;
6458 if (opts
->after_include
== 0)
6459 opts
->after_include
= dirtmp
;
6461 opts
->last_after_include
->next
= dirtmp
;
6462 opts
->last_after_include
= dirtmp
; /* Tail follows the last one */
6467 if (opts
->out_fname
!= NULL
)
6469 cpp_fatal (pfile
, "Output filename specified twice");
6473 goto missing_filename
;
6474 opts
->out_fname
= argv
[++i
];
6475 if (!strcmp (opts
->out_fname
, "-"))
6476 opts
->out_fname
= "";
6480 if (!strcmp (argv
[i
], "-pedantic"))
6481 CPP_PEDANTIC (pfile
) = 1;
6482 else if (!strcmp (argv
[i
], "-pedantic-errors")) {
6483 CPP_PEDANTIC (pfile
) = 1;
6484 opts
->pedantic_errors
= 1;
6487 else if (!strcmp (argv
[i
], "-pcp")) {
6488 char *pcp_fname
= argv
[++i
];
6489 pcp_outfile
= ((pcp_fname
[0] != '-' || pcp_fname
[1] != '\0')
6490 ? fopen (pcp_fname
, "w")
6491 : fdopen (dup (fileno (stdout
)), "w"));
6492 if (pcp_outfile
== 0)
6493 cpp_pfatal_with_name (pfile
, pcp_fname
);
6500 if (!strcmp (argv
[i
], "-traditional")) {
6501 opts
->traditional
= 1;
6502 opts
->cplusplus_comments
= 0;
6503 } else if (!strcmp (argv
[i
], "-trigraphs")) {
6505 opts
->no_trigraphs
= 0;
6510 if (! strcmp (argv
[i
], "-lang-c"))
6511 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6513 if (! strcmp (argv
[i
], "-lang-c89"))
6514 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 0, opts
->c89
= 1,
6516 if (! strcmp (argv
[i
], "-lang-c++"))
6517 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6519 if (! strcmp (argv
[i
], "-lang-objc"))
6520 opts
->cplusplus
= 0, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6522 if (! strcmp (argv
[i
], "-lang-objc++"))
6523 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1, opts
->c89
= 0,
6525 if (! strcmp (argv
[i
], "-lang-asm"))
6527 if (! strcmp (argv
[i
], "-lint"))
6529 if (! strcmp (argv
[i
], "-lang-chill"))
6530 opts
->objc
= 0, opts
->cplusplus
= 0, opts
->chill
= 1,
6531 opts
->traditional
= 1, opts
->no_trigraphs
= 1;
6535 opts
->cplusplus
= 1, opts
->cplusplus_comments
= 1;
6539 opts
->inhibit_warnings
= 1;
6543 if (!strcmp (argv
[i
], "-Wtrigraphs"))
6544 opts
->warn_trigraphs
= 1;
6545 else if (!strcmp (argv
[i
], "-Wno-trigraphs"))
6546 opts
->warn_trigraphs
= 0;
6547 else if (!strcmp (argv
[i
], "-Wcomment"))
6548 opts
->warn_comments
= 1;
6549 else if (!strcmp (argv
[i
], "-Wno-comment"))
6550 opts
->warn_comments
= 0;
6551 else if (!strcmp (argv
[i
], "-Wcomments"))
6552 opts
->warn_comments
= 1;
6553 else if (!strcmp (argv
[i
], "-Wno-comments"))
6554 opts
->warn_comments
= 0;
6555 else if (!strcmp (argv
[i
], "-Wtraditional"))
6556 opts
->warn_stringify
= 1;
6557 else if (!strcmp (argv
[i
], "-Wno-traditional"))
6558 opts
->warn_stringify
= 0;
6559 else if (!strcmp (argv
[i
], "-Wundef"))
6560 opts
->warn_undef
= 1;
6561 else if (!strcmp (argv
[i
], "-Wno-undef"))
6562 opts
->warn_undef
= 0;
6563 else if (!strcmp (argv
[i
], "-Wimport"))
6564 opts
->warn_import
= 1;
6565 else if (!strcmp (argv
[i
], "-Wno-import"))
6566 opts
->warn_import
= 0;
6567 else if (!strcmp (argv
[i
], "-Werror"))
6568 opts
->warnings_are_errors
= 1;
6569 else if (!strcmp (argv
[i
], "-Wno-error"))
6570 opts
->warnings_are_errors
= 0;
6571 else if (!strcmp (argv
[i
], "-Wall"))
6573 opts
->warn_trigraphs
= 1;
6574 opts
->warn_comments
= 1;
6579 /* The style of the choices here is a bit mixed.
6580 The chosen scheme is a hybrid of keeping all options in one string
6581 and specifying each option in a separate argument:
6582 -M|-MM|-MD file|-MMD file [-MG]. An alternative is:
6583 -M|-MM|-MD file|-MMD file|-MG|-MMG; or more concisely:
6584 -M[M][G][D file]. This is awkward to handle in specs, and is not
6586 /* ??? -MG must be specified in addition to one of -M or -MM.
6587 This can be relaxed in the future without breaking anything.
6588 The converse isn't true. */
6590 /* -MG isn't valid with -MD or -MMD. This is checked for later. */
6591 if (!strcmp (argv
[i
], "-MG"))
6593 opts
->print_deps_missing_files
= 1;
6596 if (!strcmp (argv
[i
], "-M"))
6597 opts
->print_deps
= 2;
6598 else if (!strcmp (argv
[i
], "-MM"))
6599 opts
->print_deps
= 1;
6600 else if (!strcmp (argv
[i
], "-MD"))
6601 opts
->print_deps
= 2;
6602 else if (!strcmp (argv
[i
], "-MMD"))
6603 opts
->print_deps
= 1;
6604 /* For -MD and -MMD options, write deps on file named by next arg. */
6605 if (!strcmp (argv
[i
], "-MD") || !strcmp (argv
[i
], "-MMD"))
6608 goto missing_filename
;
6609 opts
->deps_file
= argv
[++i
];
6613 /* For -M and -MM, write deps on standard output
6614 and suppress the usual output. */
6615 opts
->no_output
= 1;
6621 char *p
= argv
[i
] + 2;
6623 while ((c
= *p
++) != 0) {
6624 /* Arg to -d specifies what parts of macros to dump */
6627 opts
->dump_macros
= dump_only
;
6628 opts
->no_output
= 1;
6631 opts
->dump_macros
= dump_names
;
6634 opts
->dump_macros
= dump_definitions
;
6637 opts
->dump_includes
= 1;
6645 if (argv
[i
][2] == '3')
6646 opts
->debug_output
= 1;
6650 if (strcmp (argv
[i
], "--help") != 0)
6656 fprintf (stderr
, "GNU CPP version %s", version_string
);
6657 #ifdef TARGET_VERSION
6660 fprintf (stderr
, "\n");
6665 opts
->print_include_names
= 1;
6669 if (argv
[i
][2] != 0)
6670 push_pending (pfile
, "-D", argv
[i
] + 2);
6671 else if (i
+ 1 == argc
)
6673 cpp_fatal (pfile
, "Macro name missing after -D option");
6677 i
++, push_pending (pfile
, "-D", argv
[i
]);
6684 if (argv
[i
][2] != 0)
6686 else if (i
+ 1 == argc
)
6688 cpp_fatal (pfile
, "Assertion missing after -A option");
6694 if (!strcmp (p
, "-")) {
6695 struct cpp_pending
**ptr
;
6696 /* -A- eliminates all predefined macros and assertions.
6697 Let's include also any that were specified earlier
6698 on the command line. That way we can get rid of any
6699 that were passed automatically in from GCC. */
6700 opts
->inhibit_predefs
= 1;
6701 for (ptr
= &opts
->pending
; *ptr
!= NULL
; )
6703 struct cpp_pending
*pend
= *ptr
;
6704 if (pend
->cmd
&& pend
->cmd
[0] == '-'
6705 && (pend
->cmd
[1] == 'D' || pend
->cmd
[1] == 'A'))
6714 push_pending (pfile
, "-A", p
);
6719 case 'U': /* JF #undef something */
6720 if (argv
[i
][2] != 0)
6721 push_pending (pfile
, "-U", argv
[i
] + 2);
6722 else if (i
+ 1 == argc
)
6724 cpp_fatal (pfile
, "Macro name missing after -U option");
6728 push_pending (pfile
, "-U", argv
[i
+1]), i
++;
6732 opts
->put_out_comments
= 1;
6735 case 'E': /* -E comes from cc -E; ignore it. */
6739 opts
->no_line_commands
= 1;
6742 case '$': /* Don't include $ in identifiers. */
6743 opts
->dollars_in_ident
= 0;
6746 case 'I': /* Add directory to path for includes. */
6748 struct file_name_list
*dirtmp
;
6750 if (! CPP_OPTIONS(pfile
)->ignore_srcdir
6751 && !strcmp (argv
[i
] + 2, "-")) {
6752 CPP_OPTIONS (pfile
)->ignore_srcdir
= 1;
6753 /* Don't use any preceding -I directories for #include <...>. */
6754 CPP_OPTIONS (pfile
)->first_bracket_include
= 0;
6757 dirtmp
= (struct file_name_list
*)
6758 xmalloc (sizeof (struct file_name_list
));
6759 dirtmp
->next
= 0; /* New one goes on the end */
6760 dirtmp
->control_macro
= 0;
6761 dirtmp
->c_system_include_path
= 0;
6762 if (argv
[i
][2] != 0)
6763 dirtmp
->fname
= argv
[i
] + 2;
6764 else if (i
+ 1 == argc
)
6765 goto missing_dirname
;
6767 dirtmp
->fname
= argv
[++i
];
6768 dirtmp
->got_name_map
= 0;
6769 append_include_chain (pfile
, dirtmp
, dirtmp
);
6775 if (!strcmp (argv
[i
], "-nostdinc"))
6776 /* -nostdinc causes no default include directories.
6777 You must specify all include-file directories with -I. */
6778 opts
->no_standard_includes
= 1;
6779 else if (!strcmp (argv
[i
], "-nostdinc++"))
6780 /* -nostdinc++ causes no default C++-specific include directories. */
6781 opts
->no_standard_cplusplus_includes
= 1;
6783 else if (!strcmp (argv
[i
], "-noprecomp"))
6789 if (!strcmp (argv
[i
], "-remap"))
6794 /* Sun compiler passes undocumented switch "-undef".
6795 Let's assume it means to inhibit the predefined symbols. */
6796 opts
->inhibit_predefs
= 1;
6799 case '\0': /* JF handle '-' as file name meaning stdin or stdout */
6800 if (opts
->in_fname
== NULL
) {
6801 opts
->in_fname
= "";
6803 } else if (opts
->out_fname
== NULL
) {
6804 opts
->out_fname
= "";
6806 } /* else fall through into error */
6816 /* Handle command-line options in (argc, argv).
6817 Can be called multiple times, to handle multiple sets of options.
6818 Returns if an unrecognized option is seen.
6819 Returns number of strings consumed. */
6822 cpp_handle_options (pfile
, argc
, argv
)
6828 int strings_processed
;
6829 for (i
= 0; i
< argc
; i
+= strings_processed
)
6831 strings_processed
= cpp_handle_option (pfile
, argc
- i
, argv
+ i
);
6832 if (strings_processed
== 0)
6842 struct cpp_options
*opts
= CPP_OPTIONS (pfile
);
6844 if (opts
->print_deps
)
6846 /* Stream on which to print the dependency information. */
6849 /* Don't actually write the deps file if compilation has failed. */
6850 if (pfile
->errors
== 0)
6852 char *deps_mode
= opts
->print_deps_append
? "a" : "w";
6853 if (opts
->deps_file
== 0)
6854 deps_stream
= stdout
;
6855 else if ((deps_stream
= fopen (opts
->deps_file
, deps_mode
)) == 0)
6856 cpp_pfatal_with_name (pfile
, opts
->deps_file
);
6857 fputs (pfile
->deps_buffer
, deps_stream
);
6858 putc ('\n', deps_stream
);
6859 if (opts
->deps_file
)
6861 if (ferror (deps_stream
) || fclose (deps_stream
) != 0)
6862 cpp_fatal (pfile
, "I/O error on output");
6868 /* Free resources used by PFILE.
6869 This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */
6876 while ( CPP_BUFFER (pfile
) != CPP_NULL_BUFFER (pfile
))
6877 cpp_pop_buffer (pfile
);
6879 if (pfile
->token_buffer
)
6881 free (pfile
->token_buffer
);
6882 pfile
->token_buffer
= NULL
;
6885 if (pfile
->deps_buffer
)
6887 free (pfile
->deps_buffer
);
6888 pfile
->deps_buffer
= NULL
;
6889 pfile
->deps_allocated_size
= 0;
6892 while (pfile
->if_stack
)
6894 IF_STACK_FRAME
*temp
= pfile
->if_stack
;
6895 pfile
->if_stack
= temp
->next
;
6899 while (pfile
->dont_repeat_files
)
6901 struct file_name_list
*temp
= pfile
->dont_repeat_files
;
6902 pfile
->dont_repeat_files
= temp
->next
;
6907 while (pfile
->all_include_files
)
6909 struct file_name_list
*temp
= pfile
->all_include_files
;
6910 pfile
->all_include_files
= temp
->next
;
6915 for (i
= IMPORT_HASH_SIZE
; --i
>= 0; )
6917 register struct import_file
*imp
= pfile
->import_hash_table
[i
];
6920 struct import_file
*next
= imp
->next
;
6925 pfile
->import_hash_table
[i
] = 0;
6928 for (i
= ASSERTION_HASHSIZE
; --i
>= 0; )
6930 while (pfile
->assertion_hashtab
[i
])
6931 delete_assertion (pfile
->assertion_hashtab
[i
]);
6934 cpp_hash_cleanup (pfile
);
6938 do_assert (pfile
, keyword
, buf
, limit
)
6940 struct directive
*keyword ATTRIBUTE_UNUSED
;
6941 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
6943 long symstart
; /* remember where symbol name starts */
6945 int sym_length
; /* and how long it is */
6946 struct arglist
*tokens
= NULL
;
6948 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
6949 && !CPP_BUFFER (pfile
)->system_header_p
)
6950 cpp_pedwarn (pfile
, "ANSI C does not allow `#assert'");
6952 cpp_skip_hspace (pfile
);
6953 symstart
= CPP_WRITTEN (pfile
); /* remember where it starts */
6954 parse_name (pfile
, GETC());
6955 sym_length
= check_macro_name (pfile
, pfile
->token_buffer
+ symstart
,
6958 cpp_skip_hspace (pfile
);
6959 if (PEEKC() != '(') {
6960 cpp_error (pfile
, "missing token-sequence in `#assert'");
6966 tokens
= read_token_list (pfile
, &error_flag
);
6970 cpp_error (pfile
, "empty token-sequence in `#assert'");
6973 cpp_skip_hspace (pfile
);
6975 if (c
!= EOF
&& c
!= '\n')
6976 cpp_pedwarn (pfile
, "junk at end of `#assert'");
6977 skip_rest_of_line (pfile
);
6980 /* If this name isn't already an assertion name, make it one.
6981 Error if it was already in use in some other way. */
6984 ASSERTION_HASHNODE
*hp
;
6985 U_CHAR
*symname
= pfile
->token_buffer
+ symstart
;
6986 int hashcode
= hashf (symname
, sym_length
, ASSERTION_HASHSIZE
);
6987 struct tokenlist_list
*value
6988 = (struct tokenlist_list
*) xmalloc (sizeof (struct tokenlist_list
));
6990 hp
= assertion_lookup (pfile
, symname
, sym_length
, hashcode
);
6992 if (sym_length
== 7 && ! strncmp (symname
, "defined", sym_length
))
6993 cpp_error (pfile
, "`defined' redefined as assertion");
6994 hp
= assertion_install (pfile
, symname
, sym_length
, hashcode
);
6997 /* Add the spec'd token-sequence to the list of such. */
6998 value
->tokens
= tokens
;
6999 value
->next
= hp
->value
;
7002 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
7005 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
7006 skip_rest_of_line (pfile
);
7011 do_unassert (pfile
, keyword
, buf
, limit
)
7013 struct directive
*keyword ATTRIBUTE_UNUSED
;
7014 U_CHAR
*buf ATTRIBUTE_UNUSED
, *limit ATTRIBUTE_UNUSED
;
7016 long symstart
; /* remember where symbol name starts */
7017 int sym_length
; /* and how long it is */
7020 struct arglist
*tokens
= NULL
;
7021 int tokens_specified
= 0;
7023 if (CPP_PEDANTIC (pfile
) && CPP_OPTIONS (pfile
)->done_initializing
7024 && !CPP_BUFFER (pfile
)->system_header_p
)
7025 cpp_pedwarn (pfile
, "ANSI C does not allow `#unassert'");
7027 cpp_skip_hspace (pfile
);
7029 symstart
= CPP_WRITTEN (pfile
); /* remember where it starts */
7030 parse_name (pfile
, GETC());
7031 sym_length
= check_macro_name (pfile
, pfile
->token_buffer
+ symstart
,
7034 cpp_skip_hspace (pfile
);
7035 if (PEEKC() == '(') {
7038 tokens
= read_token_list (pfile
, &error_flag
);
7042 cpp_error (pfile
, "empty token list in `#unassert'");
7046 tokens_specified
= 1;
7049 cpp_skip_hspace (pfile
);
7051 if (c
!= EOF
&& c
!= '\n')
7052 cpp_error (pfile
, "junk at end of `#unassert'");
7053 skip_rest_of_line (pfile
);
7056 ASSERTION_HASHNODE
*hp
;
7057 U_CHAR
*symname
= pfile
->token_buffer
+ symstart
;
7058 int hashcode
= hashf (symname
, sym_length
, ASSERTION_HASHSIZE
);
7059 struct tokenlist_list
*tail
, *prev
;
7061 hp
= assertion_lookup (pfile
, symname
, sym_length
, hashcode
);
7065 /* If no token list was specified, then eliminate this assertion
7067 if (! tokens_specified
)
7068 delete_assertion (hp
);
7070 /* If a list of tokens was given, then delete any matching list. */
7075 struct tokenlist_list
*next
= tail
->next
;
7076 if (compare_token_lists (tail
->tokens
, tokens
)) {
7080 hp
->value
= tail
->next
;
7081 free_token_list (tail
->tokens
);
7091 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
7094 CPP_SET_WRITTEN (pfile
, symstart
); /* Pop */
7095 skip_rest_of_line (pfile
);
7099 /* Test whether there is an assertion named NAME
7100 and optionally whether it has an asserted token list TOKENS.
7101 NAME is not null terminated; its length is SYM_LENGTH.
7102 If TOKENS_SPECIFIED is 0, then don't check for any token list. */
7105 check_assertion (pfile
, name
, sym_length
, tokens_specified
, tokens
)
7109 int tokens_specified
;
7110 struct arglist
*tokens
;
7112 ASSERTION_HASHNODE
*hp
;
7113 int hashcode
= hashf (name
, sym_length
, ASSERTION_HASHSIZE
);
7115 if (CPP_PEDANTIC (pfile
) && !CPP_BUFFER (pfile
)->system_header_p
)
7116 cpp_pedwarn (pfile
, "ANSI C does not allow testing assertions");
7118 hp
= assertion_lookup (pfile
, name
, sym_length
, hashcode
);
7120 /* It is not an assertion; just return false. */
7123 /* If no token list was specified, then value is 1. */
7124 if (! tokens_specified
)
7128 struct tokenlist_list
*tail
;
7132 /* If a list of tokens was given,
7133 then succeed if the assertion records a matching list. */
7136 if (compare_token_lists (tail
->tokens
, tokens
))
7141 /* Fail if the assertion has no matching list. */
7146 /* Compare two lists of tokens for equality including order of tokens. */
7149 compare_token_lists (l1
, l2
)
7150 struct arglist
*l1
, *l2
;
7153 if (l1
->length
!= l2
->length
)
7155 if (strncmp (l1
->name
, l2
->name
, l1
->length
))
7161 /* Succeed if both lists end at the same time. */
7166 reverse_token_list (tokens
)
7167 struct arglist
*tokens
;
7169 register struct arglist
*prev
= 0, *this, *next
;
7170 for (this = tokens
; this; this = next
)
7179 /* Read a space-separated list of tokens ending in a close parenthesis.
7180 Return a list of strings, in the order they were written.
7181 (In case of error, return 0 and store -1 in *ERROR_FLAG.) */
7183 static struct arglist
*
7184 read_token_list (pfile
, error_flag
)
7188 struct arglist
*token_ptrs
= 0;
7193 FORWARD (1); /* Skip '(' */
7195 /* Loop over the assertion value tokens. */
7198 struct arglist
*temp
;
7199 long name_written
= CPP_WRITTEN (pfile
);
7202 cpp_skip_hspace (pfile
);
7206 /* Find the end of the token. */
7209 CPP_PUTC (pfile
, c
);
7217 CPP_PUTC (pfile
, c
);
7219 else if (c
== '"' || c
== '\'')
7222 cpp_get_token (pfile
);
7228 while (c
!= EOF
&& ! is_space
[c
] && c
!= '(' && c
!= ')'
7229 && c
!= '"' && c
!= '\'')
7231 CPP_PUTC (pfile
, c
);
7234 if (c
!= EOF
) FORWARD(-1);
7237 length
= CPP_WRITTEN (pfile
) - name_written
;
7238 temp
= (struct arglist
*)
7239 xmalloc (sizeof (struct arglist
) + length
+ 1);
7240 temp
->name
= (U_CHAR
*) (temp
+ 1);
7241 bcopy ((char *) (pfile
->token_buffer
+ name_written
),
7242 (char *) temp
->name
, length
);
7243 temp
->name
[length
] = 0;
7244 temp
->next
= token_ptrs
;
7246 temp
->length
= length
;
7248 CPP_ADJUST_WRITTEN (pfile
, -length
); /* pop */
7250 if (c
== EOF
|| c
== '\n')
7253 "unterminated token sequence following `#' operator");
7258 /* We accumulated the names in reverse order.
7259 Now reverse them to get the proper order. */
7260 return reverse_token_list (token_ptrs
);
7264 free_token_list (tokens
)
7265 struct arglist
*tokens
;
7268 struct arglist
*next
= tokens
->next
;
7269 free (tokens
->name
);
7275 /* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
7276 retrying if necessary. If MAX_READ_LEN is defined, read at most
7277 that bytes at a time. Return a negative value if an error occurs,
7278 otherwise return the actual number of bytes read,
7279 which must be LEN unless end-of-file was reached. */
7282 safe_read (desc
, ptr
, len
)
7287 int left
, rcount
, nchars
;
7293 if (rcount
> MAX_READ_LEN
)
7294 rcount
= MAX_READ_LEN
;
7296 nchars
= read (desc
, ptr
, rcount
);
7314 xcalloc (number
, size
)
7315 unsigned number
, size
;
7317 register unsigned total
= number
* size
;
7318 register char *ptr
= (char *) xmalloc (total
);
7327 unsigned size
= strlen (input
);
7328 char *output
= xmalloc (size
+ 1);
7329 strcpy (output
, input
);
7333 /* Initialize PMARK to remember the current position of PFILE. */
7336 parse_set_mark (pmark
, pfile
)
7337 struct parse_marker
*pmark
;
7340 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7341 pmark
->next
= pbuf
->marks
;
7342 pbuf
->marks
= pmark
;
7344 pmark
->position
= pbuf
->cur
- pbuf
->buf
;
7347 /* Cleanup PMARK - we no longer need it. */
7350 parse_clear_mark (pmark
)
7351 struct parse_marker
*pmark
;
7353 struct parse_marker
**pp
= &pmark
->buf
->marks
;
7354 for (; ; pp
= &(*pp
)->next
) {
7355 if (*pp
== NULL
) abort ();
7356 if (*pp
== pmark
) break;
7361 /* Backup the current position of PFILE to that saved in PMARK. */
7364 parse_goto_mark (pmark
, pfile
)
7365 struct parse_marker
*pmark
;
7368 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7369 if (pbuf
!= pmark
->buf
)
7370 cpp_fatal (pfile
, "internal error %s", "parse_goto_mark");
7371 pbuf
->cur
= pbuf
->buf
+ pmark
->position
;
7374 /* Reset PMARK to point to the current position of PFILE. (Same
7375 as parse_clear_mark (PMARK), parse_set_mark (PMARK, PFILE) but faster. */
7378 parse_move_mark (pmark
, pfile
)
7379 struct parse_marker
*pmark
;
7382 cpp_buffer
*pbuf
= CPP_BUFFER (pfile
);
7383 if (pbuf
!= pmark
->buf
)
7384 cpp_fatal (pfile
, "internal error %s", "parse_move_mark");
7385 pmark
->position
= pbuf
->cur
- pbuf
->buf
;
7389 cpp_read_check_assertion (pfile
)
7392 int name_start
= CPP_WRITTEN (pfile
);
7393 int name_length
, name_written
;
7395 FORWARD (1); /* Skip '#' */
7396 cpp_skip_hspace (pfile
);
7397 parse_name (pfile
, GETC ());
7398 name_written
= CPP_WRITTEN (pfile
);
7399 name_length
= name_written
- name_start
;
7400 cpp_skip_hspace (pfile
);
7401 if (CPP_BUF_PEEK (CPP_BUFFER (pfile
)) == '(')
7404 struct arglist
*token_ptrs
= read_token_list (pfile
, &error_flag
);
7405 result
= check_assertion (pfile
,
7406 pfile
->token_buffer
+ name_start
, name_length
,
7410 result
= check_assertion (pfile
,
7411 pfile
->token_buffer
+ name_start
, name_length
,
7413 CPP_ADJUST_WRITTEN (pfile
, - name_length
); /* pop */
7418 cpp_print_file_and_line (pfile
)
7421 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7426 cpp_buf_line_and_col (ip
, &line
, &col
);
7427 cpp_file_line_for_message (pfile
, ip
->nominal_fname
,
7428 line
, pfile
->show_column
? col
: -1);
7433 v_cpp_error (pfile
, msg
, ap
)
7438 cpp_print_containing_files (pfile
);
7439 cpp_print_file_and_line (pfile
);
7440 v_cpp_message (pfile
, 1, msg
, ap
);
7444 cpp_error
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7455 pfile
= va_arg (ap
, cpp_reader
*);
7456 msg
= va_arg (ap
, const char *);
7459 v_cpp_error (pfile
, msg
, ap
);
7463 /* Print error message but don't count it. */
7466 v_cpp_warning (pfile
, msg
, ap
)
7471 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
7474 if (CPP_OPTIONS (pfile
)->warnings_are_errors
)
7477 cpp_print_containing_files (pfile
);
7478 cpp_print_file_and_line (pfile
);
7479 v_cpp_message (pfile
, 0, msg
, ap
);
7483 cpp_warning
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7494 pfile
= va_arg (ap
, cpp_reader
*);
7495 msg
= va_arg (ap
, const char *);
7498 v_cpp_warning (pfile
, msg
, ap
);
7502 /* Print an error message and maybe count it. */
7505 cpp_pedwarn
VPROTO ((cpp_reader
* pfile
, const char *msg
, ...))
7516 pfile
= va_arg (ap
, cpp_reader
*);
7517 msg
= va_arg (ap
, const char *);
7520 if (CPP_OPTIONS (pfile
)->pedantic_errors
)
7521 v_cpp_error (pfile
, msg
, ap
);
7523 v_cpp_warning (pfile
, msg
, ap
);
7528 v_cpp_error_with_line (pfile
, line
, column
, msg
, ap
)
7535 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7537 cpp_print_containing_files (pfile
);
7540 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, line
, column
);
7542 v_cpp_message (pfile
, 1, msg
, ap
);
7546 cpp_error_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7559 pfile
= va_arg (ap
, cpp_reader
*);
7560 line
= va_arg (ap
, int);
7561 column
= va_arg (ap
, int);
7562 msg
= va_arg (ap
, const char *);
7565 v_cpp_error_with_line(pfile
, line
, column
, msg
, ap
);
7570 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
)
7579 if (CPP_OPTIONS (pfile
)->inhibit_warnings
)
7582 if (CPP_OPTIONS (pfile
)->warnings_are_errors
)
7585 cpp_print_containing_files (pfile
);
7587 ip
= cpp_file_buffer (pfile
);
7590 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, line
, column
);
7592 v_cpp_message (pfile
, 0, msg
, ap
);
7597 cpp_warning_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7610 pfile
= va_arg (ap
, cpp_reader
*);
7611 line
= va_arg (ap
, int);
7612 column
= va_arg (ap
, int);
7613 msg
= va_arg (ap
, const char *);
7616 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
);
7622 cpp_pedwarn_with_line
VPROTO ((cpp_reader
* pfile
, int line
, int column
, const char *msg
, ...))
7635 pfile
= va_arg (ap
, cpp_reader
*);
7636 line
= va_arg (ap
, int);
7637 column
= va_arg (ap
, int);
7638 msg
= va_arg (ap
, const char *);
7641 if (CPP_OPTIONS (pfile
)->pedantic_errors
)
7642 v_cpp_error_with_line (pfile
, column
, line
, msg
, ap
);
7644 v_cpp_warning_with_line (pfile
, line
, column
, msg
, ap
);
7648 /* Report a warning (or an error if pedantic_errors)
7649 giving specified file name and line number, not current. */
7652 cpp_pedwarn_with_file_and_line
VPROTO ((cpp_reader
*pfile
, char *file
, int line
, const char *msg
, ...))
7665 pfile
= va_arg (ap
, cpp_reader
*);
7666 file
= va_arg (ap
, char *);
7667 line
= va_arg (ap
, int);
7668 msg
= va_arg (ap
, const char *);
7671 if (!CPP_OPTIONS (pfile
)->pedantic_errors
7672 && CPP_OPTIONS (pfile
)->inhibit_warnings
)
7675 cpp_file_line_for_message (pfile
, file
, line
, -1);
7676 v_cpp_message (pfile
, CPP_OPTIONS (pfile
)->pedantic_errors
, msg
, ap
);
7680 /* my_strerror - return the descriptive text associated with an
7684 my_strerror (errnum
)
7690 #ifndef HAVE_STRERROR
7691 result
= (char *) ((errnum
< sys_nerr
) ? sys_errlist
[errnum
] : 0);
7693 result
= strerror (errnum
);
7696 /* VAXCRTL's strerror() takes an optional second argument, which only
7697 matters when the first argument is EVMSERR. However, it's simplest
7698 just to pass it unconditionally. `vaxc$errno' is declared in
7699 <errno.h>, and maintained by the library in parallel with `errno'.
7700 We assume that caller's `errnum' either matches the last setting of
7701 `errno' by the library or else does not have the value `EVMSERR'. */
7703 result
= strerror (errnum
, vaxc$errno
);
7707 result
= "undocumented I/O error";
7712 /* Error including a message from `errno'. */
7715 cpp_error_from_errno (pfile
, name
)
7719 cpp_message_from_errno (pfile
, 1, name
);
7723 cpp_message_from_errno (pfile
, is_error
, name
)
7729 cpp_buffer
*ip
= cpp_file_buffer (pfile
);
7731 cpp_print_containing_files (pfile
);
7734 cpp_file_line_for_message (pfile
, ip
->nominal_fname
, ip
->lineno
, -1);
7736 cpp_message (pfile
, is_error
, "%s: %s", name
, my_strerror (e
));
7740 cpp_perror_with_name (pfile
, name
)
7744 cpp_message (pfile
, 1, "%s: %s: %s", progname
, name
, my_strerror (errno
));
7748 * No pre-compiled header file support.
7750 * Possibly different enum token codes for each C/C++ token.
7752 * Should clean up remaining directives to that do_XXX functions
7753 * only take two arguments and all have command_reads_line.
7755 * Find and cleanup remaining uses of static variables,
7757 * Support for trigraphs.
7759 * Support -dM flag (dump_all_macros).
7761 * Support for_lint flag.