2 Copyright (C) 1986, 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 Contributed by Per Bothner, 1994-95.
5 Based on CCCP program by Paul Rubin, June 1986
6 Adapted to ANSI C, Richard Stallman, Jan 1987
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "cppdefault.h"
31 #include "except.h" /* for USING_SJLJ_EXCEPTIONS */
33 /* Predefined symbols, built-in macros, and the default include path. */
35 #ifndef GET_ENV_PATH_LIST
36 #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
39 /* Windows does not natively support inodes, and neither does MSDOS.
40 Cygwin's emulation can generate non-unique inodes, so don't use it.
41 VMS has non-numeric inodes. */
43 # define INO_T_EQ(A, B) (!memcmp (&(A), &(B), sizeof (A)))
44 # define INO_T_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof (SRC))
46 # if (defined _WIN32 && ! defined (_UWIN)) || defined __MSDOS__
47 # define INO_T_EQ(A, B) 0
49 # define INO_T_EQ(A, B) ((A) == (B))
51 # define INO_T_COPY(DEST, SRC) (DEST) = (SRC)
54 /* Internal structures and prototypes. */
56 /* A `struct pending_option' remembers one -D, -A, -U, -include, or
58 typedef void (* cl_directive_handler
) PARAMS ((cpp_reader
*, const char *));
61 struct pending_option
*next
;
63 cl_directive_handler handler
;
66 /* The `pending' structure accumulates all the options that are not
67 actually processed until we hit cpp_read_main_file. It consists of
68 several lists, one for each type of option. We keep both head and
69 tail pointers for quick insertion. */
72 struct pending_option
*directive_head
, *directive_tail
;
74 struct search_path
*quote_head
, *quote_tail
;
75 struct search_path
*brack_head
, *brack_tail
;
76 struct search_path
*systm_head
, *systm_tail
;
77 struct search_path
*after_head
, *after_tail
;
79 struct pending_option
*imacros_head
, *imacros_tail
;
80 struct pending_option
*include_head
, *include_tail
;
84 #define APPEND(pend, list, elt) \
85 do { if (!(pend)->list##_head) (pend)->list##_head = (elt); \
86 else (pend)->list##_tail->next = (elt); \
87 (pend)->list##_tail = (elt); \
90 #define APPEND(pend, list, elt) \
91 do { if (!(pend)->list/**/_head) (pend)->list/**/_head = (elt); \
92 else (pend)->list/**/_tail->next = (elt); \
93 (pend)->list/**/_tail = (elt); \
97 static void print_help
PARAMS ((void));
98 static void path_include
PARAMS ((cpp_reader
*,
100 static void init_library
PARAMS ((void));
101 static void init_builtins
PARAMS ((cpp_reader
*));
102 static void append_include_chain
PARAMS ((cpp_reader
*,
104 static struct search_path
* remove_dup_dir
PARAMS ((cpp_reader
*,
105 struct search_path
*));
106 static struct search_path
* remove_dup_dirs
PARAMS ((cpp_reader
*,
107 struct search_path
*));
108 static void merge_include_chains
PARAMS ((cpp_reader
*));
109 static bool push_include
PARAMS ((cpp_reader
*,
110 struct pending_option
*));
111 static void free_chain
PARAMS ((struct pending_option
*));
112 static void set_lang
PARAMS ((cpp_reader
*, enum c_lang
));
113 static void init_dependency_output
PARAMS ((cpp_reader
*));
114 static void init_standard_includes
PARAMS ((cpp_reader
*));
115 static void read_original_filename
PARAMS ((cpp_reader
*));
116 static void new_pending_directive
PARAMS ((struct cpp_pending
*,
118 cl_directive_handler
));
119 static void output_deps
PARAMS ((cpp_reader
*));
120 static int parse_option
PARAMS ((const char *));
122 /* Fourth argument to append_include_chain: chain to use.
123 Note it's never asked to append to the quote chain. */
124 enum { BRACKET
= 0, SYSTEM
, AFTER
};
126 /* If we have designated initializers (GCC >2.7) these tables can be
127 initialized, constant data. Otherwise, they have to be filled in at
129 #if HAVE_DESIGNATED_INITIALIZERS
131 #define init_trigraph_map() /* Nothing. */
132 #define TRIGRAPH_MAP \
133 __extension__ const uchar _cpp_trigraph_map[UCHAR_MAX + 1] = {
136 #define s(p, v) [p] = v,
140 #define TRIGRAPH_MAP uchar _cpp_trigraph_map[UCHAR_MAX + 1] = { 0 }; \
141 static void init_trigraph_map PARAMS ((void)) { \
142 unsigned char *x = _cpp_trigraph_map;
145 #define s(p, v) x[p] = v;
150 s('=', '#') s(')', ']') s('!', '|')
151 s('(', '[') s('\'', '^') s('>', '}')
152 s('/', '\\') s('<', '{') s('-', '~')
159 /* Given a colon-separated list of file names PATH,
160 add all the names to the search path for include files. */
162 path_include (pfile
, list
, path
)
173 /* Find the end of this name. */
175 while (*q
!= 0 && *q
!= PATH_SEPARATOR
) q
++;
178 /* An empty name in the path stands for the current directory. */
179 name
= (char *) xmalloc (2);
185 /* Otherwise use the directory that is named. */
186 name
= (char *) xmalloc (q
- p
+ 1);
187 memcpy (name
, p
, q
- p
);
191 append_include_chain (pfile
, name
, path
, 0);
193 /* Advance past this name. */
201 /* Append DIR to include path PATH. DIR must be allocated on the
202 heap; this routine takes responsibility for freeing it. CXX_AWARE
203 is non-zero if the header contains extern "C" guards for C++,
204 otherwise it is zero. */
206 append_include_chain (pfile
, dir
, path
, cxx_aware
)
210 int cxx_aware ATTRIBUTE_UNUSED
;
212 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
213 struct search_path
*new;
222 _cpp_simplify_pathname (dir
);
226 /* Dirs that don't exist are silently ignored. */
228 cpp_errno (pfile
, DL_ERROR
, dir
);
229 else if (CPP_OPTION (pfile
, verbose
))
230 fprintf (stderr
, _("ignoring nonexistent directory \"%s\"\n"), dir
);
235 if (!S_ISDIR (st
.st_mode
))
237 cpp_error_with_line (pfile
, DL_ERROR
, 0, 0, "%s: Not a directory", dir
);
243 if (len
> pfile
->max_include_len
)
244 pfile
->max_include_len
= len
;
246 new = (struct search_path
*) xmalloc (sizeof (struct search_path
));
249 INO_T_COPY (new->ino
, st
.st_ino
);
250 new->dev
= st
.st_dev
;
251 /* Both systm and after include file lists should be treated as system
252 include files since these two lists are really just a concatenation
253 of one "system" list. */
254 if (path
== SYSTEM
|| path
== AFTER
)
255 #ifdef NO_IMPLICIT_EXTERN_C
258 new->sysp
= cxx_aware
? 1 : 2;
262 new->name_map
= NULL
;
267 case BRACKET
: APPEND (pend
, brack
, new); break;
268 case SYSTEM
: APPEND (pend
, systm
, new); break;
269 case AFTER
: APPEND (pend
, after
, new); break;
273 /* Handle a duplicated include path. PREV is the link in the chain
274 before the duplicate. The duplicate is removed from the chain and
275 freed. Returns PREV. */
276 static struct search_path
*
277 remove_dup_dir (pfile
, prev
)
279 struct search_path
*prev
;
281 struct search_path
*cur
= prev
->next
;
283 if (CPP_OPTION (pfile
, verbose
))
284 fprintf (stderr
, _("ignoring duplicate directory \"%s\"\n"), cur
->name
);
286 prev
->next
= cur
->next
;
287 free ((PTR
) cur
->name
);
293 /* Remove duplicate directories from a chain. Returns the tail of the
294 chain, or NULL if the chain is empty. This algorithm is quadratic
295 in the number of -I switches, which is acceptable since there
296 aren't usually that many of them. */
297 static struct search_path
*
298 remove_dup_dirs (pfile
, head
)
300 struct search_path
*head
;
302 struct search_path
*prev
= NULL
, *cur
, *other
;
304 for (cur
= head
; cur
; cur
= cur
->next
)
306 for (other
= head
; other
!= cur
; other
= other
->next
)
307 if (INO_T_EQ (cur
->ino
, other
->ino
) && cur
->dev
== other
->dev
)
309 if (cur
->sysp
&& !other
->sysp
)
311 cpp_error (pfile
, DL_WARNING
,
312 "changing search order for system directory \"%s\"",
314 if (strcmp (cur
->name
, other
->name
))
315 cpp_error (pfile
, DL_WARNING
,
316 " as it is the same as non-system directory \"%s\"",
319 cpp_error (pfile
, DL_WARNING
,
320 " as it has already been specified as a non-system directory");
322 cur
= remove_dup_dir (pfile
, prev
);
331 /* Merge the four include chains together in the order quote, bracket,
332 system, after. Remove duplicate dirs (as determined by
333 INO_T_EQ()). The system_include and after_include chains are never
334 referred to again after this function; all access is through the
335 bracket_include path. */
337 merge_include_chains (pfile
)
340 struct search_path
*quote
, *brack
, *systm
, *qtail
;
342 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
344 quote
= pend
->quote_head
;
345 brack
= pend
->brack_head
;
346 systm
= pend
->systm_head
;
347 qtail
= pend
->quote_tail
;
349 /* Paste together bracket, system, and after include chains. */
351 pend
->systm_tail
->next
= pend
->after_head
;
353 systm
= pend
->after_head
;
356 pend
->brack_tail
->next
= systm
;
360 /* This is a bit tricky. First we drop dupes from the quote-include
361 list. Then we drop dupes from the bracket-include list.
362 Finally, if qtail and brack are the same directory, we cut out
363 brack and move brack up to point to qtail.
365 We can't just merge the lists and then uniquify them because
366 then we may lose directories from the <> search path that should
367 be there; consider -Ifoo -Ibar -I- -Ifoo -Iquux. It is however
368 safe to treat -Ibar -Ifoo -I- -Ifoo -Iquux as if written
369 -Ibar -I- -Ifoo -Iquux. */
371 remove_dup_dirs (pfile
, brack
);
372 qtail
= remove_dup_dirs (pfile
, quote
);
378 /* If brack == qtail, remove brack as it's simpler. */
379 if (brack
&& INO_T_EQ (qtail
->ino
, brack
->ino
)
380 && qtail
->dev
== brack
->dev
)
381 brack
= remove_dup_dir (pfile
, qtail
);
386 CPP_OPTION (pfile
, quote_include
) = quote
;
387 CPP_OPTION (pfile
, bracket_include
) = brack
;
390 /* A set of booleans indicating what CPP features each source language
397 char extended_numbers
;
399 char dollars_in_ident
;
400 char cplusplus_comments
;
404 /* ??? Enable $ in identifiers in assembly? */
405 static const struct lang_flags lang_defaults
[] =
406 { /* c99 objc c++ xnum trig dollar c++comm digr */
407 /* GNUC89 */ { 0, 0, 0, 1, 0, 1, 1, 1 },
408 /* GNUC99 */ { 1, 0, 0, 1, 0, 1, 1, 1 },
409 /* STDC89 */ { 0, 0, 0, 0, 1, 0, 0, 0 },
410 /* STDC94 */ { 0, 0, 0, 0, 1, 0, 0, 1 },
411 /* STDC99 */ { 1, 0, 0, 1, 1, 0, 1, 1 },
412 /* GNUCXX */ { 0, 0, 1, 1, 0, 1, 1, 1 },
413 /* CXX98 */ { 0, 0, 1, 1, 1, 0, 1, 1 },
414 /* OBJC */ { 0, 1, 0, 1, 0, 1, 1, 1 },
415 /* OBJCXX */ { 0, 1, 1, 1, 0, 1, 1, 1 },
416 /* ASM */ { 0, 0, 0, 1, 0, 0, 1, 0 }
419 /* Sets internal flags correctly for a given language. */
421 set_lang (pfile
, lang
)
425 const struct lang_flags
*l
= &lang_defaults
[(int) lang
];
427 CPP_OPTION (pfile
, lang
) = lang
;
429 CPP_OPTION (pfile
, c99
) = l
->c99
;
430 CPP_OPTION (pfile
, objc
) = l
->objc
;
431 CPP_OPTION (pfile
, cplusplus
) = l
->cplusplus
;
432 CPP_OPTION (pfile
, extended_numbers
) = l
->extended_numbers
;
433 CPP_OPTION (pfile
, trigraphs
) = l
->trigraphs
;
434 CPP_OPTION (pfile
, dollars_in_ident
) = l
->dollars_in_ident
;
435 CPP_OPTION (pfile
, cplusplus_comments
) = l
->cplusplus_comments
;
436 CPP_OPTION (pfile
, digraphs
) = l
->digraphs
;
440 static int opt_comp
PARAMS ((const void *, const void *));
442 /* Run-time sorting of options array. */
447 return strcmp (((struct cl_option
*) p1
)->opt_text
,
448 ((struct cl_option
*) p2
)->opt_text
);
452 /* init initializes library global state. It might not need to
453 do anything depending on the platform and compiler. */
457 static int initialized
= 0;
464 /* For non-ASCII hosts, the cl_options array needs to be sorted at
466 qsort (cl_options
, N_OPTS
, sizeof (struct cl_option
), opt_comp
);
469 /* Set up the trigraph map. This doesn't need to do anything if
470 we were compiled with a compiler that supports C99 designated
472 init_trigraph_map ();
476 /* Initialize a cpp_reader structure. */
478 cpp_create_reader (lang
)
483 /* Initialise this instance of the library if it hasn't been already. */
486 pfile
= (cpp_reader
*) xcalloc (1, sizeof (cpp_reader
));
488 set_lang (pfile
, lang
);
489 CPP_OPTION (pfile
, warn_import
) = 1;
490 CPP_OPTION (pfile
, warn_multichar
) = 1;
491 CPP_OPTION (pfile
, discard_comments
) = 1;
492 CPP_OPTION (pfile
, discard_comments_in_macro_exp
) = 1;
493 CPP_OPTION (pfile
, show_column
) = 1;
494 CPP_OPTION (pfile
, tabstop
) = 8;
495 CPP_OPTION (pfile
, operator_names
) = 1;
496 CPP_OPTION (pfile
, warn_endif_labels
) = 1;
498 CPP_OPTION (pfile
, pending
) =
499 (struct cpp_pending
*) xcalloc (1, sizeof (struct cpp_pending
));
501 /* Default CPP arithmetic to something sensible for the host for the
502 benefit of dumb users like fix-header. */
503 #define BITS_PER_HOST_WIDEST_INT (CHAR_BIT * sizeof (HOST_WIDEST_INT))
504 CPP_OPTION (pfile
, precision
) = BITS_PER_HOST_WIDEST_INT
;
505 CPP_OPTION (pfile
, char_precision
) = CHAR_BIT
;
506 CPP_OPTION (pfile
, wchar_precision
) = CHAR_BIT
* sizeof (int);
507 CPP_OPTION (pfile
, int_precision
) = CHAR_BIT
* sizeof (int);
508 CPP_OPTION (pfile
, unsigned_char
) = !DEFAULT_SIGNED_CHAR
;
509 CPP_OPTION (pfile
, unsigned_wchar
) = 1;
511 /* It's simplest to just create this struct whether or not it will
513 pfile
->deps
= deps_init ();
515 /* Initialise the line map. Start at logical line 1, so we can use
516 a line number of zero for special states. */
517 init_line_maps (&pfile
->line_maps
);
520 /* Initialize lexer state. */
521 pfile
->state
.save_comments
= ! CPP_OPTION (pfile
, discard_comments
);
523 /* Set up static tokens. */
524 pfile
->date
.type
= CPP_EOF
;
525 pfile
->avoid_paste
.type
= CPP_PADDING
;
526 pfile
->avoid_paste
.val
.source
= NULL
;
527 pfile
->eof
.type
= CPP_EOF
;
528 pfile
->eof
.flags
= 0;
530 /* Create a token buffer for the lexer. */
531 _cpp_init_tokenrun (&pfile
->base_run
, 250);
532 pfile
->cur_run
= &pfile
->base_run
;
533 pfile
->cur_token
= pfile
->base_run
.base
;
535 /* Initialise the base context. */
536 pfile
->context
= &pfile
->base_context
;
537 pfile
->base_context
.macro
= 0;
538 pfile
->base_context
.prev
= pfile
->base_context
.next
= 0;
540 /* Aligned and unaligned storage. */
541 pfile
->a_buff
= _cpp_get_buff (pfile
, 0);
542 pfile
->u_buff
= _cpp_get_buff (pfile
, 0);
544 /* The expression parser stack. */
545 _cpp_expand_op_stack (pfile
);
547 /* Initialise the buffer obstack. */
548 gcc_obstack_init (&pfile
->buffer_ob
);
550 _cpp_init_includes (pfile
);
555 /* Free resources used by PFILE. Accessing PFILE after this function
556 returns leads to undefined behaviour. Returns the error count. */
562 struct search_path
*dir
, *dirn
;
563 cpp_context
*context
, *contextn
;
564 tokenrun
*run
, *runn
;
566 free_chain (CPP_OPTION (pfile
, pending
)->include_head
);
567 free (CPP_OPTION (pfile
, pending
));
568 free (pfile
->op_stack
);
570 while (CPP_BUFFER (pfile
) != NULL
)
571 _cpp_pop_buffer (pfile
);
573 if (pfile
->macro_buffer
)
575 free ((PTR
) pfile
->macro_buffer
);
576 pfile
->macro_buffer
= NULL
;
577 pfile
->macro_buffer_len
= 0;
580 deps_free (pfile
->deps
);
581 obstack_free (&pfile
->buffer_ob
, 0);
583 _cpp_destroy_hashtable (pfile
);
584 _cpp_cleanup_includes (pfile
);
586 _cpp_free_buff (pfile
->a_buff
);
587 _cpp_free_buff (pfile
->u_buff
);
588 _cpp_free_buff (pfile
->free_buffs
);
590 for (run
= &pfile
->base_run
; run
; run
= runn
)
594 if (run
!= &pfile
->base_run
)
598 for (dir
= CPP_OPTION (pfile
, quote_include
); dir
; dir
= dirn
)
601 free ((PTR
) dir
->name
);
605 for (context
= pfile
->base_context
.next
; context
; context
= contextn
)
607 contextn
= context
->next
;
611 free_line_maps (&pfile
->line_maps
);
613 result
= pfile
->errors
;
620 /* This structure defines one built-in identifier. A node will be
621 entered in the hash table under the name NAME, with value VALUE (if
622 any). If flags has OPERATOR, the node's operator field is used; if
623 flags has BUILTIN the node's builtin field is used. Macros that are
624 known at build time should not be flagged BUILTIN, as then they do
625 not appear in macro dumps with e.g. -dM or -dD.
627 Two values are not compile time constants, so we tag
628 them in the FLAGS field instead:
629 VERS value is the global version_string, quoted
630 ULP value is the global user_label_prefix
632 Also, macros with CPLUS set in the flags field are entered only for C++. */
637 unsigned char builtin
;
638 unsigned char operator;
639 unsigned short flags
;
646 #define OPERATOR 0x10
648 #define B(n, t) { U n, 0, t, 0, BUILTIN, sizeof n - 1 }
649 #define C(n, v) { U n, v, 0, 0, 0, sizeof n - 1 }
650 #define X(n, f) { U n, 0, 0, 0, f, sizeof n - 1 }
651 #define O(n, c, f) { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 }
652 static const struct builtin builtin_array
[] =
654 B("__TIME__", BT_TIME
),
655 B("__DATE__", BT_DATE
),
656 B("__FILE__", BT_FILE
),
657 B("__BASE_FILE__", BT_BASE_FILE
),
658 B("__LINE__", BT_SPECLINE
),
659 B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL
),
660 B("_Pragma", BT_PRAGMA
),
662 X("__VERSION__", VERS
),
663 X("__USER_LABEL_PREFIX__", ULP
),
664 C("__REGISTER_PREFIX__", REGISTER_PREFIX
),
665 C("__HAVE_BUILTIN_SETJMP__", "1"),
666 #if USING_SJLJ_EXCEPTIONS
667 /* libgcc needs to know this. */
668 C("__USING_SJLJ_EXCEPTIONS__","1"),
670 #ifndef NO_BUILTIN_SIZE_TYPE
671 C("__SIZE_TYPE__", SIZE_TYPE
),
673 #ifndef NO_BUILTIN_PTRDIFF_TYPE
674 C("__PTRDIFF_TYPE__", PTRDIFF_TYPE
),
676 #ifndef NO_BUILTIN_WCHAR_TYPE
677 C("__WCHAR_TYPE__", WCHAR_TYPE
),
679 #ifndef NO_BUILTIN_WINT_TYPE
680 C("__WINT_TYPE__", WINT_TYPE
),
682 #ifdef STDC_0_IN_SYSTEM_HEADERS
683 B("__STDC__", BT_STDC
),
688 /* Named operators known to the preprocessor. These cannot be #defined
689 and always have their stated meaning. They are treated like normal
690 identifiers except for the type code and the meaning. Most of them
691 are only for C++ (but see iso646.h). */
692 O("and", CPP_AND_AND
, CPLUS
),
693 O("and_eq", CPP_AND_EQ
, CPLUS
),
694 O("bitand", CPP_AND
, CPLUS
),
695 O("bitor", CPP_OR
, CPLUS
),
696 O("compl", CPP_COMPL
, CPLUS
),
697 O("not", CPP_NOT
, CPLUS
),
698 O("not_eq", CPP_NOT_EQ
, CPLUS
),
699 O("or", CPP_OR_OR
, CPLUS
),
700 O("or_eq", CPP_OR_EQ
, CPLUS
),
701 O("xor", CPP_XOR
, CPLUS
),
702 O("xor_eq", CPP_XOR_EQ
, CPLUS
)
708 #define builtin_array_end (builtin_array + ARRAY_SIZE (builtin_array))
710 /* Subroutine of cpp_read_main_file; reads the builtins table above and
711 enters them, and language-specific macros, into the hash table. */
713 init_builtins (pfile
)
716 const struct builtin
*b
;
718 for(b
= builtin_array
; b
< builtin_array_end
; b
++)
720 if ((b
->flags
& CPLUS
) && ! CPP_OPTION (pfile
, cplusplus
))
723 if ((b
->flags
& OPERATOR
) && ! CPP_OPTION (pfile
, operator_names
))
726 if (b
->flags
& (OPERATOR
| BUILTIN
))
728 cpp_hashnode
*hp
= cpp_lookup (pfile
, b
->name
, b
->len
);
729 if (b
->flags
& OPERATOR
)
731 hp
->flags
|= NODE_OPERATOR
;
732 hp
->value
.operator = b
->operator;
737 hp
->flags
|= NODE_BUILTIN
| NODE_WARN
;
738 hp
->value
.builtin
= b
->builtin
;
741 else /* A standard macro of some kind. */
748 /* Allocate enough space for 'name "value"\n\0'. */
749 str
= alloca (b
->len
+ strlen (version_string
) + 5);
750 sprintf (str
, "%s \"%s\"\n", b
->name
, version_string
);
755 val
= CPP_OPTION (pfile
, user_label_prefix
);
759 /* Allocate enough space for "name value\n\0". */
760 str
= alloca (b
->len
+ strlen (val
) + 3);
761 sprintf(str
, "%s %s\n", b
->name
, val
);
764 _cpp_define_builtin (pfile
, str
);
768 if (CPP_OPTION (pfile
, cplusplus
))
769 _cpp_define_builtin (pfile
, "__cplusplus 1");
771 if (CPP_OPTION (pfile
, objc
))
772 _cpp_define_builtin (pfile
, "__OBJC__ 1");
774 if (CPP_OPTION (pfile
, lang
) == CLK_STDC94
)
775 _cpp_define_builtin (pfile
, "__STDC_VERSION__ 199409L");
776 else if (CPP_OPTION (pfile
, c99
))
777 _cpp_define_builtin (pfile
, "__STDC_VERSION__ 199901L");
779 if (CPP_OPTION (pfile
, unsigned_char
))
780 _cpp_define_builtin (pfile
, "__CHAR_UNSIGNED__ 1");
782 if (CPP_OPTION (pfile
, lang
) == CLK_STDC89
783 || CPP_OPTION (pfile
, lang
) == CLK_STDC94
784 || CPP_OPTION (pfile
, lang
) == CLK_STDC99
)
785 _cpp_define_builtin (pfile
, "__STRICT_ANSI__ 1");
786 else if (CPP_OPTION (pfile
, lang
) == CLK_ASM
)
787 _cpp_define_builtin (pfile
, "__ASSEMBLER__ 1");
789 if (pfile
->cb
.register_builtins
)
790 (*pfile
->cb
.register_builtins
) (pfile
);
797 #undef builtin_array_end
799 /* And another subroutine. This one sets up the standard include path. */
801 init_standard_includes (pfile
)
805 const struct default_include
*p
;
806 const char *specd_prefix
= CPP_OPTION (pfile
, include_prefix
);
808 /* Several environment variables may add to the include search path.
809 CPATH specifies an additional list of directories to be searched
810 as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
811 etc. specify an additional list of directories to be searched as
812 if specified with -isystem, for the language indicated. */
814 GET_ENV_PATH_LIST (path
, "CPATH");
815 if (path
!= 0 && *path
!= 0)
816 path_include (pfile
, path
, BRACKET
);
818 switch ((CPP_OPTION (pfile
, objc
) << 1) + CPP_OPTION (pfile
, cplusplus
))
821 GET_ENV_PATH_LIST (path
, "C_INCLUDE_PATH");
824 GET_ENV_PATH_LIST (path
, "CPLUS_INCLUDE_PATH");
827 GET_ENV_PATH_LIST (path
, "OBJC_INCLUDE_PATH");
830 GET_ENV_PATH_LIST (path
, "OBJCPLUS_INCLUDE_PATH");
833 if (path
!= 0 && *path
!= 0)
834 path_include (pfile
, path
, SYSTEM
);
836 /* Search "translated" versions of GNU directories.
837 These have /usr/local/lib/gcc... replaced by specd_prefix. */
838 if (specd_prefix
!= 0 && cpp_GCC_INCLUDE_DIR_len
)
840 /* Remove the `include' from /usr/local/lib/gcc.../include.
841 GCC_INCLUDE_DIR will always end in /include. */
842 int default_len
= cpp_GCC_INCLUDE_DIR_len
;
843 char *default_prefix
= (char *) alloca (default_len
+ 1);
844 int specd_len
= strlen (specd_prefix
);
846 memcpy (default_prefix
, cpp_GCC_INCLUDE_DIR
, default_len
);
847 default_prefix
[default_len
] = '\0';
849 for (p
= cpp_include_defaults
; p
->fname
; p
++)
851 /* Some standard dirs are only for C++. */
853 || (CPP_OPTION (pfile
, cplusplus
)
854 && !CPP_OPTION (pfile
, no_standard_cplusplus_includes
)))
856 /* Does this dir start with the prefix? */
857 if (!memcmp (p
->fname
, default_prefix
, default_len
))
859 /* Yes; change prefix and add to search list. */
860 int flen
= strlen (p
->fname
);
861 int this_len
= specd_len
+ flen
- default_len
;
862 char *str
= (char *) xmalloc (this_len
+ 1);
863 memcpy (str
, specd_prefix
, specd_len
);
864 memcpy (str
+ specd_len
,
865 p
->fname
+ default_len
,
866 flen
- default_len
+ 1);
868 append_include_chain (pfile
, str
, SYSTEM
, p
->cxx_aware
);
874 /* Search ordinary names for GNU include directories. */
875 for (p
= cpp_include_defaults
; p
->fname
; p
++)
877 /* Some standard dirs are only for C++. */
879 || (CPP_OPTION (pfile
, cplusplus
)
880 && !CPP_OPTION (pfile
, no_standard_cplusplus_includes
)))
882 char *str
= update_path (p
->fname
, p
->component
);
883 append_include_chain (pfile
, str
, SYSTEM
, p
->cxx_aware
);
888 /* Pushes a command line -imacro and -include file indicated by P onto
889 the buffer stack. Returns non-zero if successful. */
891 push_include (pfile
, p
)
893 struct pending_option
*p
;
897 /* Later: maybe update this to use the #include "" search path
898 if cpp_read_file fails. */
899 header
.type
= CPP_STRING
;
900 header
.val
.str
.text
= (const unsigned char *) p
->arg
;
901 header
.val
.str
.len
= strlen (p
->arg
);
902 /* Make the command line directive take up a line. */
905 return _cpp_execute_include (pfile
, &header
, IT_CMDLINE
);
908 /* Frees a pending_option chain. */
911 struct pending_option
*head
;
913 struct pending_option
*next
;
923 /* Sanity-checks are dependent on command-line options, so it is
924 called as a subroutine of cpp_read_main_file (). */
926 static void sanity_checks
PARAMS ((cpp_reader
*));
927 static void sanity_checks (pfile
)
932 /* Sanity checks for assumptions about CPP arithmetic and target
933 type precisions made by cpplib. */
936 cpp_error (pfile
, DL_FATAL
, "cppchar_t must be an unsigned type");
938 if (CPP_OPTION (pfile
, precision
) > BITS_PER_HOST_WIDEST_INT
)
939 cpp_error (pfile
, DL_FATAL
,
940 "preprocessor arithmetic has maximum precision of %u bits; target requires %u bits",
941 BITS_PER_HOST_WIDEST_INT
, CPP_OPTION (pfile
, precision
));
943 if (CPP_OPTION (pfile
, precision
) < CPP_OPTION (pfile
, int_precision
))
944 cpp_error (pfile
, DL_FATAL
,
945 "CPP arithmetic must be at least as precise as a target int");
947 if (CPP_OPTION (pfile
, char_precision
) < 8)
948 cpp_error (pfile
, DL_FATAL
, "target char is less than 8 bits wide");
950 if (CPP_OPTION (pfile
, wchar_precision
) < CPP_OPTION (pfile
, char_precision
))
951 cpp_error (pfile
, DL_FATAL
,
952 "target wchar_t is narrower than target char");
954 if (CPP_OPTION (pfile
, int_precision
) < CPP_OPTION (pfile
, char_precision
))
955 cpp_error (pfile
, DL_FATAL
,
956 "target int is narrower than target char");
958 if (CPP_OPTION (pfile
, wchar_precision
) > BITS_PER_CPPCHAR_T
)
959 cpp_error (pfile
, DL_FATAL
,
960 "CPP on this host cannot handle wide character constants over %u bits, but the target requires %u bits",
961 BITS_PER_CPPCHAR_T
, CPP_OPTION (pfile
, wchar_precision
));
964 # define sanity_checks(PFILE)
967 /* This is called after options have been parsed, and partially
968 processed. Setup for processing input from the file named FNAME,
969 or stdin if it is the empty string. Return the original filename
970 on success (e.g. foo.i->foo.c), or NULL on failure. */
972 cpp_read_main_file (pfile
, fname
, table
)
977 sanity_checks (pfile
);
979 /* The front ends don't set up the hash table until they have
980 finished processing the command line options, so initializing the
981 hashtable is deferred until now. */
982 _cpp_init_hashtable (pfile
, table
);
984 /* Set up the include search path now. */
985 if (! CPP_OPTION (pfile
, no_standard_includes
))
986 init_standard_includes (pfile
);
988 merge_include_chains (pfile
);
990 /* With -v, print the list of dirs to search. */
991 if (CPP_OPTION (pfile
, verbose
))
993 struct search_path
*l
;
994 fprintf (stderr
, _("#include \"...\" search starts here:\n"));
995 for (l
= CPP_OPTION (pfile
, quote_include
); l
; l
= l
->next
)
997 if (l
== CPP_OPTION (pfile
, bracket_include
))
998 fprintf (stderr
, _("#include <...> search starts here:\n"));
999 fprintf (stderr
, " %s\n", l
->name
);
1001 fprintf (stderr
, _("End of search list.\n"));
1004 if (CPP_OPTION (pfile
, print_deps
))
1005 /* Set the default target (if there is none already). */
1006 deps_add_default_target (pfile
->deps
, fname
);
1008 /* Open the main input file. */
1009 if (!_cpp_read_file (pfile
, fname
))
1012 /* Set this after cpp_post_options so the client can change the
1013 option if it wishes, and after stacking the main file so we don't
1014 trace the main file. */
1015 pfile
->line_maps
.trace_includes
= CPP_OPTION (pfile
, print_include_names
);
1017 /* For foo.i, read the original filename foo.c now, for the benefit
1018 of the front ends. */
1019 if (CPP_OPTION (pfile
, preprocessed
))
1020 read_original_filename (pfile
);
1022 return pfile
->map
->to_file
;
1025 /* For preprocessed files, if the first tokens are of the form # NUM.
1026 handle the directive so we know the original file name. This will
1027 generate file_change callbacks, which the front ends must handle
1028 appropriately given their state of initialization. */
1030 read_original_filename (pfile
)
1033 const cpp_token
*token
, *token1
;
1035 /* Lex ahead; if the first tokens are of the form # NUM, then
1036 process the directive, otherwise back up. */
1037 token
= _cpp_lex_direct (pfile
);
1038 if (token
->type
== CPP_HASH
)
1040 token1
= _cpp_lex_direct (pfile
);
1041 _cpp_backup_tokens (pfile
, 1);
1043 /* If it's a #line directive, handle it. */
1044 if (token1
->type
== CPP_NUMBER
)
1046 _cpp_handle_directive (pfile
, token
->flags
& PREV_WHITE
);
1051 /* Backup as if nothing happened. */
1052 _cpp_backup_tokens (pfile
, 1);
1055 /* Handle pending command line options: -D, -U, -A, -imacros and
1056 -include. This should be called after debugging has been properly
1057 set up in the front ends. */
1059 cpp_finish_options (pfile
)
1062 /* Install builtins and process command line macros etc. in the order
1063 they appeared, but only if not already preprocessed. */
1064 if (! CPP_OPTION (pfile
, preprocessed
))
1066 struct pending_option
*p
;
1068 _cpp_do_file_change (pfile
, LC_RENAME
, _("<built-in>"), 1, 0);
1069 init_builtins (pfile
);
1070 _cpp_do_file_change (pfile
, LC_RENAME
, _("<command line>"), 1, 0);
1071 for (p
= CPP_OPTION (pfile
, pending
)->directive_head
; p
; p
= p
->next
)
1072 (*p
->handler
) (pfile
, p
->arg
);
1074 /* Scan -imacros files after -D, -U, but before -include.
1075 pfile->next_include_file is NULL, so _cpp_pop_buffer does not
1076 push -include files. */
1077 for (p
= CPP_OPTION (pfile
, pending
)->imacros_head
; p
; p
= p
->next
)
1078 if (push_include (pfile
, p
))
1079 cpp_scan_nooutput (pfile
);
1081 pfile
->next_include_file
= &CPP_OPTION (pfile
, pending
)->include_head
;
1082 _cpp_maybe_push_include_file (pfile
);
1085 free_chain (CPP_OPTION (pfile
, pending
)->imacros_head
);
1086 free_chain (CPP_OPTION (pfile
, pending
)->directive_head
);
1089 /* Push the next buffer on the stack given by -include, if any. */
1091 _cpp_maybe_push_include_file (pfile
)
1094 if (pfile
->next_include_file
)
1096 struct pending_option
*head
= *pfile
->next_include_file
;
1098 while (head
&& !push_include (pfile
, head
))
1102 pfile
->next_include_file
= &head
->next
;
1105 /* All done; restore the line map from <command line>. */
1106 _cpp_do_file_change (pfile
, LC_RENAME
,
1107 pfile
->line_maps
.maps
[0].to_file
, 1, 0);
1108 /* Don't come back here again. */
1109 pfile
->next_include_file
= NULL
;
1114 /* Use mkdeps.c to output dependency information. */
1119 /* Stream on which to print the dependency information. */
1120 FILE *deps_stream
= 0;
1121 const char *const deps_mode
=
1122 CPP_OPTION (pfile
, print_deps_append
) ? "a" : "w";
1124 if (CPP_OPTION (pfile
, deps_file
)[0] == '\0')
1125 deps_stream
= stdout
;
1128 deps_stream
= fopen (CPP_OPTION (pfile
, deps_file
), deps_mode
);
1129 if (deps_stream
== 0)
1131 cpp_errno (pfile
, DL_ERROR
, CPP_OPTION (pfile
, deps_file
));
1136 deps_write (pfile
->deps
, deps_stream
, 72);
1138 if (CPP_OPTION (pfile
, deps_phony_targets
))
1139 deps_phony_targets (pfile
->deps
, deps_stream
);
1141 /* Don't close stdout. */
1142 if (deps_stream
!= stdout
)
1144 if (ferror (deps_stream
) || fclose (deps_stream
) != 0)
1145 cpp_error (pfile
, DL_FATAL
, "I/O error on output");
1149 /* This is called at the end of preprocessing. It pops the
1150 last buffer and writes dependency output. It should also
1151 clear macro definitions, such that you could call cpp_start_read
1152 with a new filename to restart processing. */
1157 /* cpplex.c leaves the final buffer on the stack. This it so that
1158 it returns an unending stream of CPP_EOFs to the client. If we
1159 popped the buffer, we'd dereference a NULL buffer pointer and
1160 segfault. It's nice to allow the client to do worry-free excess
1161 cpp_get_token calls. */
1162 while (pfile
->buffer
)
1163 _cpp_pop_buffer (pfile
);
1165 /* Don't write the deps file if preprocessing has failed. */
1166 if (CPP_OPTION (pfile
, print_deps
) && pfile
->errors
== 0)
1167 output_deps (pfile
);
1169 /* Report on headers that could use multiple include guards. */
1170 if (CPP_OPTION (pfile
, print_include_names
))
1171 _cpp_report_missing_guards (pfile
);
1174 /* Add a directive to be handled later in the initialization phase. */
1176 new_pending_directive (pend
, text
, handler
)
1177 struct cpp_pending
*pend
;
1179 cl_directive_handler handler
;
1181 struct pending_option
*o
= (struct pending_option
*)
1182 xmalloc (sizeof (struct pending_option
));
1186 o
->handler
= handler
;
1187 APPEND (pend
, directive
, o
);
1190 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
1191 I.e. a const string initializer with parens around it. That is
1192 what N_("string") resolves to, so we make no_* be macros instead. */
1193 #define no_arg N_("argument missing after %s")
1194 #define no_ass N_("assertion missing after %s")
1195 #define no_dir N_("directory name missing after %s")
1196 #define no_fil N_("file name missing after %s")
1197 #define no_mac N_("macro name missing after %s")
1198 #define no_pth N_("path name missing after %s")
1199 #define no_num N_("number missing after %s")
1200 #define no_tgt N_("target missing after %s")
1202 /* This is the list of all command line options, with the leading
1203 "-" removed. It must be sorted in ASCII collating order. */
1204 #define COMMAND_LINE_OPTIONS \
1205 DEF_OPT("$", 0, OPT_dollar) \
1206 DEF_OPT("+", 0, OPT_plus) \
1207 DEF_OPT("-help", 0, OPT__help) \
1208 DEF_OPT("-target-help", 0, OPT_target__help) \
1209 DEF_OPT("-version", 0, OPT__version) \
1210 DEF_OPT("A", no_ass, OPT_A) \
1211 DEF_OPT("C", 0, OPT_C) \
1212 DEF_OPT("CC", 0, OPT_CC) \
1213 DEF_OPT("D", no_mac, OPT_D) \
1214 DEF_OPT("H", 0, OPT_H) \
1215 DEF_OPT("I", no_dir, OPT_I) \
1216 DEF_OPT("M", 0, OPT_M) \
1217 DEF_OPT("MD", no_fil, OPT_MD) \
1218 DEF_OPT("MF", no_fil, OPT_MF) \
1219 DEF_OPT("MG", 0, OPT_MG) \
1220 DEF_OPT("MM", 0, OPT_MM) \
1221 DEF_OPT("MMD", no_fil, OPT_MMD) \
1222 DEF_OPT("MP", 0, OPT_MP) \
1223 DEF_OPT("MQ", no_tgt, OPT_MQ) \
1224 DEF_OPT("MT", no_tgt, OPT_MT) \
1225 DEF_OPT("P", 0, OPT_P) \
1226 DEF_OPT("U", no_mac, OPT_U) \
1227 DEF_OPT("W", no_arg, OPT_W) /* arg optional */ \
1228 DEF_OPT("d", no_arg, OPT_d) \
1229 DEF_OPT("fleading-underscore", 0, OPT_fleading_underscore) \
1230 DEF_OPT("fno-leading-underscore", 0, OPT_fno_leading_underscore) \
1231 DEF_OPT("fno-operator-names", 0, OPT_fno_operator_names) \
1232 DEF_OPT("fno-preprocessed", 0, OPT_fno_preprocessed) \
1233 DEF_OPT("fno-show-column", 0, OPT_fno_show_column) \
1234 DEF_OPT("fpreprocessed", 0, OPT_fpreprocessed) \
1235 DEF_OPT("fshow-column", 0, OPT_fshow_column) \
1236 DEF_OPT("fsigned-char", 0, OPT_fsigned_char) \
1237 DEF_OPT("ftabstop=", no_num, OPT_ftabstop) \
1238 DEF_OPT("funsigned-char", 0, OPT_funsigned_char) \
1239 DEF_OPT("h", 0, OPT_h) \
1240 DEF_OPT("idirafter", no_dir, OPT_idirafter) \
1241 DEF_OPT("imacros", no_fil, OPT_imacros) \
1242 DEF_OPT("include", no_fil, OPT_include) \
1243 DEF_OPT("iprefix", no_pth, OPT_iprefix) \
1244 DEF_OPT("isystem", no_dir, OPT_isystem) \
1245 DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
1246 DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
1247 DEF_OPT("lang-asm", 0, OPT_lang_asm) \
1248 DEF_OPT("lang-c", 0, OPT_lang_c) \
1249 DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
1250 DEF_OPT("lang-c89", 0, OPT_lang_c89) \
1251 DEF_OPT("lang-objc", 0, OPT_lang_objc) \
1252 DEF_OPT("lang-objc++", 0, OPT_lang_objcplusplus) \
1253 DEF_OPT("nostdinc", 0, OPT_nostdinc) \
1254 DEF_OPT("nostdinc++", 0, OPT_nostdincplusplus) \
1255 DEF_OPT("o", no_fil, OPT_o) \
1256 DEF_OPT("pedantic", 0, OPT_pedantic) \
1257 DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
1258 DEF_OPT("remap", 0, OPT_remap) \
1259 DEF_OPT("std=c++98", 0, OPT_std_cplusplus98) \
1260 DEF_OPT("std=c89", 0, OPT_std_c89) \
1261 DEF_OPT("std=c99", 0, OPT_std_c99) \
1262 DEF_OPT("std=c9x", 0, OPT_std_c9x) \
1263 DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
1264 DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
1265 DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
1266 DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
1267 DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
1268 DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
1269 DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x) \
1270 DEF_OPT("trigraphs", 0, OPT_trigraphs) \
1271 DEF_OPT("v", 0, OPT_v) \
1272 DEF_OPT("version", 0, OPT_version) \
1273 DEF_OPT("w", 0, OPT_w)
1275 #define DEF_OPT(text, msg, code) code,
1278 COMMAND_LINE_OPTIONS
1285 const char *opt_text
;
1288 enum opt_code opt_code
;
1291 #define DEF_OPT(text, msg, code) { text, msg, sizeof(text) - 1, code },
1293 static struct cl_option cl_options
[] =
1295 static const struct cl_option cl_options
[] =
1298 COMMAND_LINE_OPTIONS
1301 #undef COMMAND_LINE_OPTIONS
1303 /* Perform a binary search to find which, if any, option the given
1304 command-line matches. Returns its index in the option array,
1305 negative on failure. Complications arise since some options can be
1306 suffixed with an argument, and multiple complete matches can occur,
1307 e.g. -iwithprefix and -iwithprefixbefore. Moreover, we need to
1308 accept options beginning with -W that we do not recognise, but not
1309 to swallow any subsequent command line argument; this is handled as
1310 special cases in cpp_handle_option. */
1312 parse_option (input
)
1315 unsigned int md
, mn
, mx
;
1326 opt_len
= cl_options
[md
].opt_len
;
1327 comp
= memcmp (input
, cl_options
[md
].opt_text
, opt_len
);
1335 if (input
[opt_len
] == '\0')
1337 /* We were passed more text. If the option takes an argument,
1338 we may match a later option or we may have been passed the
1339 argument. The longest possible option match succeeds.
1340 If the option takes no arguments we have not matched and
1341 continue the search (e.g. input="stdc++" match was "stdc"). */
1343 if (cl_options
[md
].msg
)
1345 /* Scan forwards. If we get an exact match, return it.
1346 Otherwise, return the longest option-accepting match.
1347 This loops no more than twice with current options. */
1349 for (; mn
< (unsigned int) N_OPTS
; mn
++)
1351 opt_len
= cl_options
[mn
].opt_len
;
1352 if (memcmp (input
, cl_options
[mn
].opt_text
, opt_len
))
1354 if (input
[opt_len
] == '\0')
1356 if (cl_options
[mn
].msg
)
1367 /* Handle one command-line option in (argc, argv).
1368 Can be called multiple times, to handle multiple sets of options.
1369 If ignore is non-zero, this will ignore unrecognized -W* options.
1370 Returns number of strings consumed. */
1372 cpp_handle_option (pfile
, argc
, argv
, ignore
)
1379 struct cpp_pending
*pend
= CPP_OPTION (pfile
, pending
);
1381 /* Interpret "-" or a non-option as a file name. */
1382 if (argv
[i
][0] != '-' || argv
[i
][1] == '\0')
1384 if (CPP_OPTION (pfile
, in_fname
) == NULL
)
1385 CPP_OPTION (pfile
, in_fname
) = argv
[i
];
1386 else if (CPP_OPTION (pfile
, out_fname
) == NULL
)
1387 CPP_OPTION (pfile
, out_fname
) = argv
[i
];
1389 cpp_error (pfile
, DL_FATAL
,
1390 "too many filenames. Type %s --help for usage info",
1395 enum opt_code opt_code
;
1397 const char *arg
= 0;
1399 /* Skip over '-'. */
1400 opt_index
= parse_option (&argv
[i
][1]);
1404 opt_code
= cl_options
[opt_index
].opt_code
;
1405 if (cl_options
[opt_index
].msg
)
1407 arg
= &argv
[i
][cl_options
[opt_index
].opt_len
+ 1];
1409 /* Yuk. Special case for -W as it must not swallow
1410 up any following argument. If this becomes common, add
1411 another field to the cl_options table. */
1412 if (arg
[0] == '\0' && opt_code
!= OPT_W
)
1417 cpp_error (pfile
, DL_FATAL
,
1418 cl_options
[opt_index
].msg
, argv
[i
- 1]);
1426 case N_OPTS
: /* Shut GCC up. */
1428 case OPT_fleading_underscore
:
1429 CPP_OPTION (pfile
, user_label_prefix
) = "_";
1431 case OPT_fno_leading_underscore
:
1432 CPP_OPTION (pfile
, user_label_prefix
) = "";
1434 case OPT_fno_operator_names
:
1435 CPP_OPTION (pfile
, operator_names
) = 0;
1437 case OPT_fpreprocessed
:
1438 CPP_OPTION (pfile
, preprocessed
) = 1;
1440 case OPT_fno_preprocessed
:
1441 CPP_OPTION (pfile
, preprocessed
) = 0;
1443 case OPT_fshow_column
:
1444 CPP_OPTION (pfile
, show_column
) = 1;
1446 case OPT_fno_show_column
:
1447 CPP_OPTION (pfile
, show_column
) = 0;
1449 case OPT_fsigned_char
:
1450 CPP_OPTION (pfile
, unsigned_char
) = 0;
1452 case OPT_funsigned_char
:
1453 CPP_OPTION (pfile
, unsigned_char
) = 1;
1456 /* Silently ignore empty string, non-longs and silly values. */
1460 long tabstop
= strtol (arg
, &endptr
, 10);
1461 if (*endptr
== '\0' && tabstop
>= 1 && tabstop
<= 100)
1462 CPP_OPTION (pfile
, tabstop
) = tabstop
;
1466 CPP_OPTION (pfile
, inhibit_warnings
) = 1;
1471 CPP_OPTION (pfile
, help_only
) = 1;
1473 case OPT_target__help
:
1474 /* Print if any target specific options. cpplib has none, but
1475 make sure help_only gets set. */
1476 CPP_OPTION (pfile
, help_only
) = 1;
1479 /* --version inhibits compilation, -version doesn't. -v means
1480 verbose and -version. Historical reasons, don't ask. */
1482 CPP_OPTION (pfile
, help_only
) = 1;
1483 pfile
->print_version
= 1;
1486 CPP_OPTION (pfile
, verbose
) = 1;
1487 pfile
->print_version
= 1;
1490 pfile
->print_version
= 1;
1494 CPP_OPTION (pfile
, discard_comments
) = 0;
1497 CPP_OPTION (pfile
, discard_comments
) = 0;
1498 CPP_OPTION (pfile
, discard_comments_in_macro_exp
) = 0;
1501 CPP_OPTION (pfile
, no_line_commands
) = 1;
1503 case OPT_dollar
: /* Don't include $ in identifiers. */
1504 CPP_OPTION (pfile
, dollars_in_ident
) = 0;
1507 CPP_OPTION (pfile
, print_include_names
) = 1;
1510 new_pending_directive (pend
, arg
, cpp_define
);
1512 case OPT_pedantic_errors
:
1513 CPP_OPTION (pfile
, pedantic_errors
) = 1;
1516 CPP_OPTION (pfile
, pedantic
) = 1;
1517 CPP_OPTION (pfile
, warn_endif_labels
) = 1;
1520 CPP_OPTION (pfile
, trigraphs
) = 1;
1523 CPP_OPTION (pfile
, cplusplus
) = 1;
1524 CPP_OPTION (pfile
, cplusplus_comments
) = 1;
1527 CPP_OPTION (pfile
, remap
) = 1;
1530 CPP_OPTION (pfile
, include_prefix
) = arg
;
1531 CPP_OPTION (pfile
, include_prefix_len
) = strlen (arg
);
1534 set_lang (pfile
, CLK_GNUC89
);
1536 case OPT_lang_cplusplus
:
1537 set_lang (pfile
, CLK_GNUCXX
);
1540 set_lang (pfile
, CLK_OBJC
);
1542 case OPT_lang_objcplusplus
:
1543 set_lang (pfile
, CLK_OBJCXX
);
1546 set_lang (pfile
, CLK_ASM
);
1548 case OPT_std_cplusplus98
:
1549 set_lang (pfile
, CLK_CXX98
);
1552 set_lang (pfile
, CLK_GNUC89
);
1556 set_lang (pfile
, CLK_GNUC99
);
1558 case OPT_std_iso9899_199409
:
1559 set_lang (pfile
, CLK_STDC94
);
1561 case OPT_std_iso9899_1990
:
1564 set_lang (pfile
, CLK_STDC89
);
1566 case OPT_std_iso9899_199x
:
1567 case OPT_std_iso9899_1999
:
1570 set_lang (pfile
, CLK_STDC99
);
1573 /* -nostdinc causes no default include directories.
1574 You must specify all include-file directories with -I. */
1575 CPP_OPTION (pfile
, no_standard_includes
) = 1;
1577 case OPT_nostdincplusplus
:
1578 /* -nostdinc++ causes no default C++-specific include directories. */
1579 CPP_OPTION (pfile
, no_standard_cplusplus_includes
) = 1;
1582 if (CPP_OPTION (pfile
, out_fname
) == NULL
)
1583 CPP_OPTION (pfile
, out_fname
) = arg
;
1586 cpp_error (pfile
, DL_FATAL
, "output filename specified twice");
1591 /* Args to -d specify what parts of macros to dump.
1592 Silently ignore unrecognised options; they may
1593 be aimed at the compiler proper. */
1597 while ((c
= *arg
++) != '\0')
1601 CPP_OPTION (pfile
, dump_macros
) = dump_only
;
1604 CPP_OPTION (pfile
, dump_macros
) = dump_names
;
1607 CPP_OPTION (pfile
, dump_macros
) = dump_definitions
;
1610 CPP_OPTION (pfile
, dump_includes
) = 1;
1617 CPP_OPTION (pfile
, print_deps_missing_files
) = 1;
1620 /* When doing dependencies with -M or -MM, suppress normal
1621 preprocessed output, but still do -dM etc. as software
1622 depends on this. Preprocessed output occurs if -MD, -MMD
1623 or environment var dependency generation is used. */
1624 CPP_OPTION (pfile
, print_deps
) = 2;
1625 CPP_OPTION (pfile
, no_output
) = 1;
1628 CPP_OPTION (pfile
, print_deps
) = 1;
1629 CPP_OPTION (pfile
, no_output
) = 1;
1632 CPP_OPTION (pfile
, deps_file
) = arg
;
1635 CPP_OPTION (pfile
, deps_phony_targets
) = 1;
1639 /* Add a target. -MQ quotes for Make. */
1640 deps_add_target (pfile
->deps
, arg
, opt_code
== OPT_MQ
);
1644 CPP_OPTION (pfile
, print_deps
) = 2;
1645 CPP_OPTION (pfile
, deps_file
) = arg
;
1648 CPP_OPTION (pfile
, print_deps
) = 1;
1649 CPP_OPTION (pfile
, deps_file
) = arg
;
1655 /* -A with an argument beginning with '-' acts as
1656 #unassert on whatever immediately follows the '-'.
1657 If "-" is the whole argument, we eliminate all
1658 predefined macros and assertions, including those
1659 that were specified earlier on the command line.
1660 That way we can get rid of any that were passed
1661 automatically in from GCC. */
1665 free_chain (pend
->directive_head
);
1666 pend
->directive_head
= NULL
;
1667 pend
->directive_tail
= NULL
;
1670 new_pending_directive (pend
, arg
+ 1, cpp_unassert
);
1673 new_pending_directive (pend
, arg
, cpp_assert
);
1676 new_pending_directive (pend
, arg
, cpp_undef
);
1678 case OPT_I
: /* Add directory to path for includes. */
1679 if (!strcmp (arg
, "-"))
1682 Use the preceding -I directories for #include "..."
1683 but not #include <...>.
1684 Don't search the directory of the present file
1685 for #include "...". (Note that -I. -I- is not the same as
1686 the default setup; -I. uses the compiler's working dir.) */
1687 if (! CPP_OPTION (pfile
, ignore_srcdir
))
1689 pend
->quote_head
= pend
->brack_head
;
1690 pend
->quote_tail
= pend
->brack_tail
;
1691 pend
->brack_head
= 0;
1692 pend
->brack_tail
= 0;
1693 CPP_OPTION (pfile
, ignore_srcdir
) = 1;
1697 cpp_error (pfile
, DL_FATAL
, "-I- specified twice");
1702 append_include_chain (pfile
, xstrdup (arg
), BRACKET
, 0);
1705 /* Add directory to beginning of system include path, as a system
1706 include directory. */
1707 append_include_chain (pfile
, xstrdup (arg
), SYSTEM
, 0);
1712 struct pending_option
*o
= (struct pending_option
*)
1713 xmalloc (sizeof (struct pending_option
));
1717 if (opt_code
== OPT_include
)
1718 APPEND (pend
, include
, o
);
1720 APPEND (pend
, imacros
, o
);
1723 case OPT_iwithprefix
:
1724 /* Add directory to end of path for includes,
1725 with the default prefix at the front of its name. */
1727 case OPT_iwithprefixbefore
:
1728 /* Add directory to main path for includes,
1729 with the default prefix at the front of its name. */
1736 if (CPP_OPTION (pfile
, include_prefix
) != 0)
1738 size_t ipl
= CPP_OPTION (pfile
, include_prefix_len
);
1739 fname
= xmalloc (ipl
+ len
+ 1);
1740 memcpy (fname
, CPP_OPTION (pfile
, include_prefix
), ipl
);
1741 memcpy (fname
+ ipl
, arg
, len
+ 1);
1743 else if (cpp_GCC_INCLUDE_DIR_len
)
1745 fname
= xmalloc (cpp_GCC_INCLUDE_DIR_len
+ len
+ 1);
1746 memcpy (fname
, cpp_GCC_INCLUDE_DIR
, cpp_GCC_INCLUDE_DIR_len
);
1747 memcpy (fname
+ cpp_GCC_INCLUDE_DIR_len
, arg
, len
+ 1);
1750 fname
= xstrdup (arg
);
1752 append_include_chain (pfile
, fname
,
1753 opt_code
== OPT_iwithprefix
? SYSTEM
: BRACKET
, 0);
1757 /* Add directory to end of path for includes. */
1758 append_include_chain (pfile
, xstrdup (arg
), AFTER
, 0);
1761 /* Silently ignore unrecognised options. */
1762 if (!strcmp (argv
[i
], "-Wall"))
1764 CPP_OPTION (pfile
, warn_trigraphs
) = 1;
1765 CPP_OPTION (pfile
, warn_comments
) = 1;
1767 else if (!strcmp (argv
[i
], "-Wtraditional"))
1768 CPP_OPTION (pfile
, warn_traditional
) = 1;
1769 else if (!strcmp (argv
[i
], "-Wtrigraphs"))
1770 CPP_OPTION (pfile
, warn_trigraphs
) = 1;
1771 else if (!strcmp (argv
[i
], "-Wcomment"))
1772 CPP_OPTION (pfile
, warn_comments
) = 1;
1773 else if (!strcmp (argv
[i
], "-Wcomments"))
1774 CPP_OPTION (pfile
, warn_comments
) = 1;
1775 else if (!strcmp (argv
[i
], "-Wundef"))
1776 CPP_OPTION (pfile
, warn_undef
) = 1;
1777 else if (!strcmp (argv
[i
], "-Wimport"))
1778 CPP_OPTION (pfile
, warn_import
) = 1;
1779 else if (!strcmp (argv
[i
], "-Werror"))
1780 CPP_OPTION (pfile
, warnings_are_errors
) = 1;
1781 else if (!strcmp (argv
[i
], "-Wsystem-headers"))
1782 CPP_OPTION (pfile
, warn_system_headers
) = 1;
1783 else if (!strcmp (argv
[i
], "-Wendif-labels"))
1784 CPP_OPTION (pfile
, warn_endif_labels
) = 1;
1785 else if (!strcmp (argv
[i
], "-Wno-traditional"))
1786 CPP_OPTION (pfile
, warn_traditional
) = 0;
1787 else if (!strcmp (argv
[i
], "-Wno-trigraphs"))
1788 CPP_OPTION (pfile
, warn_trigraphs
) = 0;
1789 else if (!strcmp (argv
[i
], "-Wno-comment"))
1790 CPP_OPTION (pfile
, warn_comments
) = 0;
1791 else if (!strcmp (argv
[i
], "-Wno-comments"))
1792 CPP_OPTION (pfile
, warn_comments
) = 0;
1793 else if (!strcmp (argv
[i
], "-Wno-undef"))
1794 CPP_OPTION (pfile
, warn_undef
) = 0;
1795 else if (!strcmp (argv
[i
], "-Wno-import"))
1796 CPP_OPTION (pfile
, warn_import
) = 0;
1797 else if (!strcmp (argv
[i
], "-Wno-error"))
1798 CPP_OPTION (pfile
, warnings_are_errors
) = 0;
1799 else if (!strcmp (argv
[i
], "-Wno-system-headers"))
1800 CPP_OPTION (pfile
, warn_system_headers
) = 0;
1801 else if (!strcmp (argv
[i
], "-Wno-endif-labels"))
1802 CPP_OPTION (pfile
, warn_endif_labels
) = 0;
1811 /* Handle command-line options in (argc, argv).
1812 Can be called multiple times, to handle multiple sets of options.
1813 Returns if an unrecognized option is seen.
1814 Returns number of strings consumed. */
1816 cpp_handle_options (pfile
, argc
, argv
)
1822 int strings_processed
;
1824 for (i
= 0; i
< argc
; i
+= strings_processed
)
1826 strings_processed
= cpp_handle_option (pfile
, argc
- i
, argv
+ i
, 1);
1827 if (strings_processed
== 0)
1834 /* Extra processing when all options are parsed, after all calls to
1835 cpp_handle_option[s]. Consistency checks etc. */
1837 cpp_post_options (pfile
)
1840 if (pfile
->print_version
)
1842 fprintf (stderr
, _("GNU CPP version %s (cpplib)"), version_string
);
1843 #ifdef TARGET_VERSION
1846 fputc ('\n', stderr
);
1849 /* Canonicalize in_fname and out_fname. We guarantee they are not
1850 NULL, and that the empty string represents stdin / stdout. */
1851 if (CPP_OPTION (pfile
, in_fname
) == NULL
1852 || !strcmp (CPP_OPTION (pfile
, in_fname
), "-"))
1853 CPP_OPTION (pfile
, in_fname
) = "";
1855 if (CPP_OPTION (pfile
, out_fname
) == NULL
1856 || !strcmp (CPP_OPTION (pfile
, out_fname
), "-"))
1857 CPP_OPTION (pfile
, out_fname
) = "";
1859 /* -Wtraditional is not useful in C++ mode. */
1860 if (CPP_OPTION (pfile
, cplusplus
))
1861 CPP_OPTION (pfile
, warn_traditional
) = 0;
1863 /* Set this if it hasn't been set already. */
1864 if (CPP_OPTION (pfile
, user_label_prefix
) == NULL
)
1865 CPP_OPTION (pfile
, user_label_prefix
) = USER_LABEL_PREFIX
;
1867 /* Permanently disable macro expansion if we are rescanning
1868 preprocessed text. */
1869 if (CPP_OPTION (pfile
, preprocessed
))
1870 pfile
->state
.prevent_expansion
= 1;
1872 /* -dM makes no normal output. This is set here so that -dM -dD
1873 works as expected. */
1874 if (CPP_OPTION (pfile
, dump_macros
) == dump_only
)
1875 CPP_OPTION (pfile
, no_output
) = 1;
1877 /* Disable -dD, -dN and -dI if we should make no normal output
1878 (such as with -M). Allow -M -dM since some software relies on
1880 if (CPP_OPTION (pfile
, no_output
))
1882 if (CPP_OPTION (pfile
, dump_macros
) != dump_only
)
1883 CPP_OPTION (pfile
, dump_macros
) = dump_none
;
1884 CPP_OPTION (pfile
, dump_includes
) = 0;
1887 /* We need to do this after option processing and before
1888 cpp_start_read, as cppmain.c relies on the options->no_output to
1889 set its callbacks correctly before calling cpp_start_read. */
1890 init_dependency_output (pfile
);
1892 /* After checking the environment variables, check if -M or -MM has
1893 not been specified, but other -M options have. */
1894 if (CPP_OPTION (pfile
, print_deps
) == 0 &&
1895 (CPP_OPTION (pfile
, print_deps_missing_files
)
1896 || CPP_OPTION (pfile
, deps_file
)
1897 || CPP_OPTION (pfile
, deps_phony_targets
)))
1898 cpp_error (pfile
, DL_FATAL
,
1899 "you must additionally specify either -M or -MM");
1902 /* Set up dependency-file output. On exit, if print_deps is non-zero
1903 then deps_file is not NULL; stdout is the empty string. */
1905 init_dependency_output (pfile
)
1908 char *spec
, *s
, *output_file
;
1910 /* Either of two environment variables can specify output of deps.
1911 Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
1912 where OUTPUT_FILE is the file to write deps info to
1913 and DEPS_TARGET is the target to mention in the deps. */
1915 if (CPP_OPTION (pfile
, print_deps
) == 0)
1917 spec
= getenv ("DEPENDENCIES_OUTPUT");
1919 CPP_OPTION (pfile
, print_deps
) = 1;
1922 spec
= getenv ("SUNPRO_DEPENDENCIES");
1924 CPP_OPTION (pfile
, print_deps
) = 2;
1929 /* Find the space before the DEPS_TARGET, if there is one. */
1930 s
= strchr (spec
, ' ');
1933 /* Let the caller perform MAKE quoting. */
1934 deps_add_target (pfile
->deps
, s
+ 1, 0);
1935 output_file
= (char *) xmalloc (s
- spec
+ 1);
1936 memcpy (output_file
, spec
, s
- spec
);
1937 output_file
[s
- spec
] = 0;
1942 /* Command line -MF overrides environment variables and default. */
1943 if (CPP_OPTION (pfile
, deps_file
) == 0)
1944 CPP_OPTION (pfile
, deps_file
) = output_file
;
1946 CPP_OPTION (pfile
, print_deps_append
) = 1;
1948 else if (CPP_OPTION (pfile
, deps_file
) == 0)
1949 /* If -M or -MM was seen without -MF, default output to wherever
1950 was specified with -o. out_fname is non-NULL here. */
1951 CPP_OPTION (pfile
, deps_file
) = CPP_OPTION (pfile
, out_fname
);
1954 /* Handle --help output. */
1958 /* To keep the lines from getting too long for some compilers, limit
1959 to about 500 characters (6 lines) per chunk. */
1962 -include <file> Include the contents of <file> before other files\n\
1963 -imacros <file> Accept definition of macros in <file>\n\
1964 -iprefix <path> Specify <path> as a prefix for next two options\n\
1965 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
1966 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
1967 -isystem <dir> Add <dir> to the start of the system include path\n\
1970 -idirafter <dir> Add <dir> to the end of the system include path\n\
1971 -I <dir> Add <dir> to the end of the main include path\n\
1972 -I- Fine-grained include path control; see info docs\n\
1973 -nostdinc Do not search system include directories\n\
1974 (dirs specified with -isystem will still be used)\n\
1975 -nostdinc++ Do not search system include directories for C++\n\
1976 -o <file> Put output into <file>\n\
1979 -pedantic Issue all warnings demanded by strict ISO C\n\
1980 -pedantic-errors Issue -pedantic warnings as errors instead\n\
1981 -trigraphs Support ISO C trigraphs\n\
1982 -lang-c Assume that the input sources are in C\n\
1983 -lang-c89 Assume that the input sources are in C89\n\
1986 -lang-c++ Assume that the input sources are in C++\n\
1987 -lang-objc Assume that the input sources are in ObjectiveC\n\
1988 -lang-objc++ Assume that the input sources are in ObjectiveC++\n\
1989 -lang-asm Assume that the input sources are in assembler\n\
1992 -std=<std name> Specify the conformance standard; one of:\n\
1993 gnu89, gnu99, c89, c99, iso9899:1990,\n\
1994 iso9899:199409, iso9899:1999\n\
1995 -+ Allow parsing of C++ style features\n\
1996 -w Inhibit warning messages\n\
1997 -Wtrigraphs Warn if trigraphs are encountered\n\
1998 -Wno-trigraphs Do not warn about trigraphs\n\
1999 -Wcomment{s} Warn if one comment starts inside another\n\
2002 -Wno-comment{s} Do not warn about comments\n\
2003 -Wtraditional Warn about features not present in traditional C\n\
2004 -Wno-traditional Do not warn about traditional C\n\
2005 -Wundef Warn if an undefined macro is used by #if\n\
2006 -Wno-undef Do not warn about testing undefined macros\n\
2007 -Wimport Warn about the use of the #import directive\n\
2010 -Wno-import Do not warn about the use of #import\n\
2011 -Werror Treat all warnings as errors\n\
2012 -Wno-error Do not treat warnings as errors\n\
2013 -Wsystem-headers Do not suppress warnings from system headers\n\
2014 -Wno-system-headers Suppress warnings from system headers\n\
2015 -Wall Enable all preprocessor warnings\n\
2018 -M Generate make dependencies\n\
2019 -MM As -M, but ignore system header files\n\
2020 -MD Generate make dependencies and compile\n\
2021 -MMD As -MD, but ignore system header files\n\
2022 -MF <file> Write dependency output to the given file\n\
2023 -MG Treat missing header file as generated files\n\
2026 -MP Generate phony targets for all headers\n\
2027 -MQ <target> Add a MAKE-quoted target\n\
2028 -MT <target> Add an unquoted target\n\
2031 -D<macro> Define a <macro> with string '1' as its value\n\
2032 -D<macro>=<val> Define a <macro> with <val> as its value\n\
2033 -A<question>=<answer> Assert the <answer> to <question>\n\
2034 -A-<question>=<answer> Disable the <answer> to <question>\n\
2035 -U<macro> Undefine <macro> \n\
2036 -v Display the version number\n\
2039 -H Print the name of header files as they are used\n\
2040 -C Do not discard comments\n\
2041 -dM Display a list of macro definitions active at end\n\
2042 -dD Preserve macro definitions in output\n\
2043 -dN As -dD except that only the names are preserved\n\
2044 -dI Include #include directives in the output\n\
2047 -fpreprocessed Treat the input file as already preprocessed\n\
2048 -ftabstop=<number> Distance between tab stops for column reporting\n\
2049 -P Do not generate #line directives\n\
2050 -$ Do not allow '$' in identifiers\n\
2051 -remap Remap file names when including files\n\
2052 --version Display version information\n\
2053 -h or --help Display this information\n\