00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "system.h"
00024 #include "tree.h"
00025 #include "c-common.h"
00026 #include "c-pragma.h"
00027 #include "flags.h"
00028 #include "toplev.h"
00029 #include "langhooks.h"
00030 #include "tree-inline.h"
00031 #include "diagnostic.h"
00032 #include "intl.h"
00033
00034
00035 static cpp_options *cpp_opts;
00036
00037
00038 static const char *in_fname;
00039
00040
00041 static const char *out_fname;
00042 static FILE *out_stream;
00043
00044
00045 static bool deps_append;
00046
00047
00048 static bool deps_seen;
00049
00050
00051 static const char *deps_file;
00052
00053
00054 static size_t deferred_count, deferred_size;
00055
00056 static void missing_arg PARAMS ((size_t));
00057 static size_t find_opt PARAMS ((const char *, int));
00058 static void set_Wimplicit PARAMS ((int));
00059 static void complain_wrong_lang PARAMS ((size_t, int));
00060 static void write_langs PARAMS ((char *, int));
00061 static void print_help PARAMS ((void));
00062 static void handle_OPT_d PARAMS ((const char *));
00063 static void set_std_cxx98 PARAMS ((int));
00064 static void set_std_c89 PARAMS ((int, int));
00065 static void set_std_c99 PARAMS ((int));
00066 static void check_deps_environment_vars PARAMS ((void));
00067 static void preprocess_file PARAMS ((void));
00068 static void handle_deferred_opts PARAMS ((void));
00069 static void sanitize_cpp_opts PARAMS ((void));
00070
00071 #ifndef STDC_0_IN_SYSTEM_HEADERS
00072 #define STDC_0_IN_SYSTEM_HEADERS 0
00073 #endif
00074
00075 #define CL_C_ONLY (1 << 0)
00076 #define CL_OBJC_ONLY (1 << 1)
00077 #define CL_CXX_ONLY (1 << 2)
00078 #define CL_OBJCXX_ONLY (1 << 3)
00079 #define CL_JOINED (1 << 4)
00080 #define CL_SEPARATE (1 << 5)
00081
00082 #define CL_ARG (CL_JOINED | CL_SEPARATE)
00083 #define CL_C (CL_C_ONLY | CL_OBJC_ONLY)
00084 #define CL_OBJC (CL_OBJC_ONLY | CL_OBJCXX_ONLY)
00085 #define CL_CXX (CL_CXX_ONLY | CL_OBJCXX_ONLY)
00086 #define CL_ALL (CL_C | CL_CXX)
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 #define COMMAND_LINE_OPTIONS \
00112 OPT("-help", CL_ALL, OPT__help) \
00113 OPT("C", CL_ALL, OPT_C) \
00114 OPT("CC", CL_ALL, OPT_CC) \
00115 OPT("E", CL_ALL, OPT_E) \
00116 OPT("H", CL_ALL, OPT_H) \
00117 OPT("M", CL_ALL, OPT_M) \
00118 OPT("MD", CL_ALL | CL_SEPARATE, OPT_MD) \
00119 OPT("MF", CL_ALL | CL_ARG, OPT_MF) \
00120 OPT("MG", CL_ALL, OPT_MG) \
00121 OPT("MM", CL_ALL, OPT_MM) \
00122 OPT("MMD", CL_ALL | CL_SEPARATE, OPT_MMD) \
00123 OPT("MP", CL_ALL, OPT_MP) \
00124 OPT("MQ", CL_ALL | CL_ARG, OPT_MQ) \
00125 OPT("MT", CL_ALL | CL_ARG, OPT_MT) \
00126 OPT("P", CL_ALL, OPT_P) \
00127 OPT("Wabi", CL_CXX, OPT_Wabi) \
00128 OPT("Wall", CL_ALL, OPT_Wall) \
00129 OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
00130 OPT("Wcast-qual", CL_ALL, OPT_Wcast_qual) \
00131 OPT("Wchar-subscripts", CL_ALL, OPT_Wchar_subscripts) \
00132 OPT("Wcomment", CL_ALL, OPT_Wcomment) \
00133 OPT("Wcomments", CL_ALL, OPT_Wcomments) \
00134 OPT("Wconversion", CL_ALL, OPT_Wconversion) \
00135 OPT("Wctor-dtor-privacy", CL_CXX, OPT_Wctor_dtor_privacy) \
00136 OPT("Wdeclaration-after-statement", \
00137 CL_C, OPT_Wdeclaration_after_statement) \
00138 OPT("Wdeprecated", CL_CXX, OPT_Wdeprecated) \
00139 OPT("Wdiv-by-zero", CL_C, OPT_Wdiv_by_zero) \
00140 OPT("Weffc++", CL_CXX, OPT_Weffcxx) \
00141 OPT("Wendif-labels", CL_ALL, OPT_Wendif_labels) \
00142 OPT("Werror", CL_ALL, OPT_Werror) \
00143 OPT("Werror-implicit-function-declaration", \
00144 CL_C, OPT_Werror_implicit_function_decl) \
00145 OPT("Wfloat-equal", CL_ALL, OPT_Wfloat_equal) \
00146 OPT("Wformat", CL_ALL, OPT_Wformat) \
00147 OPT("Wformat-extra-args", CL_ALL, OPT_Wformat_extra_args) \
00148 OPT("Wformat-nonliteral", CL_ALL, OPT_Wformat_nonliteral) \
00149 OPT("Wformat-security", CL_ALL, OPT_Wformat_security) \
00150 OPT("Wformat-y2k", CL_ALL, OPT_Wformat_y2k) \
00151 OPT("Wformat-zero-length", CL_C, OPT_Wformat_zero_length) \
00152 OPT("Wformat=", CL_ALL | CL_JOINED, OPT_Wformat_eq) \
00153 OPT("Wimplicit", CL_ALL, OPT_Wimplicit) \
00154 OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
00155 OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
00156 OPT("Wimport", CL_ALL, OPT_Wimport) \
00157 OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
00158 OPT("Wmain", CL_C, OPT_Wmain) \
00159 OPT("Wmissing-braces", CL_ALL, OPT_Wmissing_braces) \
00160 OPT("Wmissing-declarations", CL_C, OPT_Wmissing_declarations) \
00161 OPT("Wmissing-format-attribute",CL_ALL, OPT_Wmissing_format_attribute) \
00162 OPT("Wmissing-prototypes", CL_ALL, OPT_Wmissing_prototypes) \
00163 OPT("Wmultichar", CL_ALL, OPT_Wmultichar) \
00164 OPT("Wnested-externs", CL_C, OPT_Wnested_externs) \
00165 OPT("Wnon-template-friend", CL_CXX, OPT_Wnon_template_friend) \
00166 OPT("Wnon-virtual-dtor", CL_CXX, OPT_Wnon_virtual_dtor) \
00167 OPT("Wnonnull", CL_C, OPT_Wnonnull) \
00168 OPT("Wold-style-cast", CL_CXX, OPT_Wold_style_cast) \
00169 OPT("Woverloaded-virtual", CL_CXX, OPT_Woverloaded_virtual) \
00170 OPT("Wparentheses", CL_ALL, OPT_Wparentheses) \
00171 OPT("Wpmf-conversions", CL_CXX, OPT_Wpmf_conversions) \
00172 OPT("Wpointer-arith", CL_ALL, OPT_Wpointer_arith) \
00173 OPT("Wprotocol", CL_OBJC, OPT_Wprotocol) \
00174 OPT("Wredundant-decls", CL_ALL, OPT_Wredundant_decls) \
00175 OPT("Wreorder", CL_CXX, OPT_Wreorder) \
00176 OPT("Wreturn-type", CL_ALL, OPT_Wreturn_type) \
00177 OPT("Wselector", CL_OBJC, OPT_Wselector) \
00178 OPT("Wsequence-point", CL_C, OPT_Wsequence_point) \
00179 OPT("Wsign-compare", CL_ALL, OPT_Wsign_compare) \
00180 OPT("Wsign-promo", CL_CXX, OPT_Wsign_promo) \
00181 OPT("Wstrict-prototypes", CL_ALL, OPT_Wstrict_prototypes) \
00182 OPT("Wsynth", CL_CXX, OPT_Wsynth) \
00183 OPT("Wsystem-headers", CL_ALL, OPT_Wsystem_headers) \
00184 OPT("Wtraditional", CL_C, OPT_Wtraditional) \
00185 OPT("Wtrigraphs", CL_ALL, OPT_Wtrigraphs) \
00186 OPT("Wundeclared-selector", CL_OBJC, OPT_Wundeclared_selector) \
00187 OPT("Wundef", CL_ALL, OPT_Wundef) \
00188 OPT("Wunknown-pragmas", CL_ALL, OPT_Wunknown_pragmas) \
00189 OPT("Wunused-macros", CL_ALL, OPT_Wunused_macros) \
00190 OPT("Wwrite-strings", CL_ALL, OPT_Wwrite_strings) \
00191 OPT("ansi", CL_ALL, OPT_ansi) \
00192 OPT("d", CL_ALL | CL_JOINED, OPT_d) \
00193 OPT("fabi-version=", CL_CXX | CL_JOINED, OPT_fabi_version) \
00194 OPT("faccess-control", CL_CXX, OPT_faccess_control) \
00195 OPT("fall-virtual", CL_CXX, OPT_fall_virtual) \
00196 OPT("falt-external-templates",CL_CXX, OPT_falt_external_templates) \
00197 OPT("fasm", CL_ALL, OPT_fasm) \
00198 OPT("fbuiltin", CL_ALL, OPT_fbuiltin) \
00199 OPT("fbuiltin-", CL_ALL | CL_JOINED, OPT_fbuiltin_) \
00200 OPT("fcheck-new", CL_CXX, OPT_fcheck_new) \
00201 OPT("fcond-mismatch", CL_ALL, OPT_fcond_mismatch) \
00202 OPT("fconserve-space", CL_CXX, OPT_fconserve_space) \
00203 OPT("fconst-strings", CL_CXX, OPT_fconst_strings) \
00204 OPT("fconstant-string-class=", CL_OBJC | CL_JOINED, \
00205 OPT_fconstant_string_class) \
00206 OPT("fdefault-inline", CL_CXX, OPT_fdefault_inline) \
00207 OPT("fdollars-in-identifiers",CL_ALL, OPT_fdollars_in_identifiers) \
00208 OPT("fdump-", CL_ALL | CL_JOINED, OPT_fdump) \
00209 OPT("felide-constructors", CL_CXX, OPT_felide_constructors) \
00210 OPT("fenforce-eh-specs", CL_CXX, OPT_fenforce_eh_specs) \
00211 OPT("fenum-int-equiv", CL_CXX, OPT_fenum_int_equiv) \
00212 OPT("fexternal-templates", CL_CXX, OPT_fexternal_templates) \
00213 OPT("ffixed-form", CL_C, OPT_ffixed_form) \
00214 OPT("ffixed-line-length-", CL_C | CL_JOINED, OPT_ffixed_line_length) \
00215 OPT("ffor-scope", CL_CXX, OPT_ffor_scope) \
00216 OPT("ffreestanding", CL_C, OPT_ffreestanding) \
00217 OPT("fgnu-keywords", CL_CXX, OPT_fgnu_keywords) \
00218 OPT("fgnu-runtime", CL_OBJC, OPT_fgnu_runtime) \
00219 OPT("fguiding-decls", CL_CXX, OPT_fguiding_decls) \
00220 OPT("fhandle-exceptions", CL_CXX, OPT_fhandle_exceptions) \
00221 OPT("fhonor-std", CL_CXX, OPT_fhonor_std) \
00222 OPT("fhosted", CL_C, OPT_fhosted) \
00223 OPT("fhuge-objects", CL_CXX, OPT_fhuge_objects) \
00224 OPT("fimplement-inlines", CL_CXX, OPT_fimplement_inlines) \
00225 OPT("fimplicit-inline-templates", CL_CXX, OPT_fimplicit_inline_templates) \
00226 OPT("fimplicit-templates", CL_CXX, OPT_fimplicit_templates) \
00227 OPT("flabels-ok", CL_CXX, OPT_flabels_ok) \
00228 OPT("fms-extensions", CL_ALL, OPT_fms_extensions) \
00229 OPT("fname-mangling-version-",CL_CXX | CL_JOINED, OPT_fname_mangling) \
00230 OPT("fnew-abi", CL_CXX, OPT_fnew_abi) \
00231 OPT("fnext-runtime", CL_OBJC, OPT_fnext_runtime) \
00232 OPT("fnonansi-builtins", CL_CXX, OPT_fnonansi_builtins) \
00233 OPT("fnonnull-objects", CL_CXX, OPT_fnonnull_objects) \
00234 OPT("foperator-names", CL_CXX, OPT_foperator_names) \
00235 OPT("foptional-diags", CL_CXX, OPT_foptional_diags) \
00236 OPT("fpermissive", CL_CXX, OPT_fpermissive) \
00237 OPT("fpreprocessed", CL_ALL, OPT_fpreprocessed) \
00238 OPT("frepo", CL_CXX, OPT_frepo) \
00239 OPT("frtti", CL_CXX, OPT_frtti) \
00240 OPT("fshort-double", CL_ALL, OPT_fshort_double) \
00241 OPT("fshort-enums", CL_ALL, OPT_fshort_enums) \
00242 OPT("fshort-wchar", CL_ALL, OPT_fshort_wchar) \
00243 OPT("fshow-column", CL_ALL, OPT_fshow_column) \
00244 OPT("fsigned-bitfields", CL_ALL, OPT_fsigned_bitfields) \
00245 OPT("fsigned-char", CL_ALL, OPT_fsigned_char) \
00246 OPT("fsquangle", CL_CXX, OPT_fsquangle) \
00247 OPT("fstats", CL_CXX, OPT_fstats) \
00248 OPT("fstrict-prototype", CL_CXX, OPT_fstrict_prototype) \
00249 OPT("ftabstop=", CL_ALL | CL_JOINED, OPT_ftabstop) \
00250 OPT("ftemplate-depth-", CL_CXX | CL_JOINED, OPT_ftemplate_depth) \
00251 OPT("fthis-is-variable", CL_CXX, OPT_fthis_is_variable) \
00252 OPT("funsigned-bitfields", CL_ALL, OPT_funsigned_bitfields) \
00253 OPT("funsigned-char", CL_ALL, OPT_funsigned_char) \
00254 OPT("fuse-cxa-atexit", CL_CXX, OPT_fuse_cxa_atexit) \
00255 OPT("fvtable-gc", CL_CXX, OPT_fvtable_gc) \
00256 OPT("fvtable-thunks", CL_CXX, OPT_fvtable_thunks) \
00257 OPT("fweak", CL_CXX, OPT_fweak) \
00258 OPT("fxref", CL_CXX, OPT_fxref) \
00259 OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
00260 OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
00261 OPT("lang-objc", CL_ALL, OPT_lang_objc) \
00262 OPT("nostdinc", CL_ALL, OPT_nostdinc) \
00263 OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
00264 OPT("o", CL_ALL | CL_ARG, OPT_o) \
00265 OPT("pedantic", CL_ALL, OPT_pedantic) \
00266 OPT("pedantic-errors", CL_ALL, OPT_pedantic_errors) \
00267 OPT("print-objc-runtime-info", CL_OBJC, OPT_print_objc_runtime_info) \
00268 OPT("remap", CL_ALL, OPT_remap) \
00269 OPT("std=c++98", CL_CXX, OPT_std_cplusplus98) \
00270 OPT("std=c89", CL_C, OPT_std_c89) \
00271 OPT("std=c99", CL_C, OPT_std_c99) \
00272 OPT("std=c9x", CL_C, OPT_std_c9x) \
00273 OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
00274 OPT("std=gnu89", CL_C, OPT_std_gnu89) \
00275 OPT("std=gnu99", CL_C, OPT_std_gnu99) \
00276 OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
00277 OPT("std=iso9899:1990", CL_C, OPT_std_iso9899_1990) \
00278 OPT("std=iso9899:199409", CL_C, OPT_std_iso9899_199409) \
00279 OPT("std=iso9899:1999", CL_C, OPT_std_iso9899_1999) \
00280 OPT("std=iso9899:199x", CL_C, OPT_std_iso9899_199x) \
00281 OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
00282 OPT("trigraphs", CL_ALL, OPT_trigraphs) \
00283 OPT("undef", CL_ALL, OPT_undef) \
00284 OPT("v", CL_ALL, OPT_v) \
00285 OPT("w", CL_ALL, OPT_w)
00286
00287 #define OPT(text, flags, code) code,
00288 enum opt_code
00289 {
00290 COMMAND_LINE_OPTIONS
00291 N_OPTS
00292 };
00293 #undef OPT
00294
00295 struct cl_option
00296 {
00297 const char *opt_text;
00298 unsigned char opt_len;
00299 unsigned char flags;
00300 ENUM_BITFIELD (opt_code) opt_code : 2 * CHAR_BIT;
00301 };
00302
00303 #define OPT(text, flags, code) { text, sizeof(text) - 1, flags, code },
00304 #ifdef HOST_EBCDIC
00305 static struct cl_option cl_options[] =
00306 #else
00307 static const struct cl_option cl_options[] =
00308 #endif
00309 {
00310 COMMAND_LINE_OPTIONS
00311 };
00312 #undef OPT
00313 #undef COMMAND_LINE_OPTIONS
00314
00315
00316
00317 static void defer_opt PARAMS ((enum opt_code, const char *));
00318 static struct deferred_opt
00319 {
00320 enum opt_code code;
00321 const char *arg;
00322 } *deferred_opts;
00323
00324
00325 #ifdef HOST_EBCDIC
00326 static int opt_comp PARAMS ((const void *, const void *));
00327
00328
00329 static int
00330 opt_comp (p1, p2)
00331 const void *p1, *p2;
00332 {
00333 return strcmp (((struct cl_option *) p1)->opt_text,
00334 ((struct cl_option *) p2)->opt_text);
00335 }
00336 #endif
00337
00338
00339
00340 static void
00341 missing_arg (opt_index)
00342 size_t opt_index;
00343 {
00344 const char *opt_text = cl_options[opt_index].opt_text;
00345
00346 switch (cl_options[opt_index].opt_code)
00347 {
00348 case OPT_Wformat_eq:
00349 case OPT_d:
00350 case OPT_fabi_version:
00351 case OPT_fbuiltin_:
00352 case OPT_fdump:
00353 case OPT_fname_mangling:
00354 case OPT_ftabstop:
00355 case OPT_ftemplate_depth:
00356 default:
00357 error ("missing argument to \"-%s\"", opt_text);
00358 break;
00359
00360 case OPT_fconstant_string_class:
00361 error ("no class name specified with \"-%s\"", opt_text);
00362 break;
00363
00364 case OPT_MF:
00365 case OPT_MD:
00366 case OPT_MMD:
00367 case OPT_o:
00368 error ("missing filename after \"-%s\"", opt_text);
00369 break;
00370
00371 case OPT_MQ:
00372 case OPT_MT:
00373 error ("missing target after \"-%s\"", opt_text);
00374 break;
00375 }
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 static size_t
00390 find_opt (input, lang_flag)
00391 const char *input;
00392 int lang_flag;
00393 {
00394 size_t md, mn, mx;
00395 size_t opt_len;
00396 size_t result = N_OPTS;
00397 int comp;
00398
00399 mn = 0;
00400 mx = N_OPTS;
00401
00402 while (mx > mn)
00403 {
00404 md = (mn + mx) / 2;
00405
00406 opt_len = cl_options[md].opt_len;
00407 comp = strncmp (input, cl_options[md].opt_text, opt_len);
00408
00409 if (comp < 0)
00410 mx = md;
00411 else if (comp > 0)
00412 mn = md + 1;
00413 else
00414 {
00415
00416 if (input[opt_len] == '\0')
00417 return md;
00418 else
00419 {
00420 mn = md + 1;
00421
00422
00423
00424
00425 if (!(cl_options[md].flags & CL_JOINED))
00426 continue;
00427
00428
00429 if (!(cl_options[md].flags & lang_flag))
00430 {
00431
00432
00433
00434 result = md;
00435 continue;
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 mx = md;
00447 for (md = md + 1; md < (size_t) N_OPTS; md++)
00448 {
00449 opt_len = cl_options[md].opt_len;
00450 if (strncmp (input, cl_options[md].opt_text, opt_len))
00451 break;
00452 if (input[opt_len] == '\0')
00453 return md;
00454 if (cl_options[md].flags & lang_flag
00455 && cl_options[md].flags & CL_JOINED)
00456 mx = md;
00457 }
00458
00459 return mx;
00460 }
00461 }
00462 }
00463
00464 return result;
00465 }
00466
00467
00468 static void
00469 defer_opt (code, arg)
00470 enum opt_code code;
00471 const char *arg;
00472 {
00473
00474
00475 if (!deferred_opts)
00476 {
00477 extern int save_argc;
00478 deferred_size = save_argc;
00479 deferred_opts = (struct deferred_opt *)
00480 xmalloc (deferred_size * sizeof (struct deferred_opt));
00481 }
00482
00483 if (deferred_count == deferred_size)
00484 abort ();
00485
00486 deferred_opts[deferred_count].code = code;
00487 deferred_opts[deferred_count].arg = arg;
00488 deferred_count++;
00489 }
00490
00491
00492 void
00493 c_common_init_options (lang)
00494 enum c_language_kind lang;
00495 {
00496 #ifdef HOST_EBCDIC
00497
00498
00499 qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp);
00500 #endif
00501 #if ENABLE_CHECKING
00502 {
00503 size_t i;
00504
00505 for (i = 1; i < N_OPTS; i++)
00506 if (strcmp (cl_options[i - 1].opt_text, cl_options[i].opt_text) >= 0)
00507 error ("options array incorrectly sorted: %s is before %s",
00508 cl_options[i - 1].opt_text, cl_options[i].opt_text);
00509 }
00510 #endif
00511
00512 c_language = lang;
00513 parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);
00514 cpp_opts = cpp_get_options (parse_in);
00515 if (flag_objc)
00516 cpp_opts->objc = 1;
00517
00518 flag_const_strings = (lang == clk_cplusplus);
00519 warn_pointer_arith = (lang == clk_cplusplus);
00520 if (lang == clk_c)
00521 warn_sign_compare = -1;
00522 }
00523
00524
00525
00526
00527 int
00528 c_common_decode_option (argc, argv)
00529 int argc;
00530 char **argv;
00531 {
00532 static const int lang_flags[] = {CL_C_ONLY, CL_C, CL_CXX_ONLY, CL_CXX};
00533 size_t opt_index;
00534 const char *opt, *arg = 0;
00535 char *dup = 0;
00536 bool on = true;
00537 int result, lang_flag;
00538 const struct cl_option *option;
00539 enum opt_code code;
00540
00541 opt = argv[0];
00542
00543
00544 if (opt[0] != '-' || opt[1] == '\0')
00545 {
00546 if (!in_fname)
00547 in_fname = opt;
00548 else if (!out_fname)
00549 out_fname = opt;
00550 else
00551 {
00552 error ("too many filenames given. Type %s --help for usage",
00553 progname);
00554 return argc;
00555 }
00556
00557 return 1;
00558 }
00559
00560
00561 if ((opt[1] == 'W' || opt[1] == 'f')
00562 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
00563 {
00564 size_t len = strlen (opt) - 3;
00565
00566 dup = xmalloc (len + 1);
00567 dup[0] = '-';
00568 dup[1] = opt[1];
00569 memcpy (dup + 2, opt + 5, len - 2 + 1);
00570 opt = dup;
00571 on = false;
00572 }
00573
00574 result = cpp_handle_option (parse_in, argc, argv);
00575
00576
00577 lang_flag = lang_flags[(c_language << 1) + flag_objc];
00578 opt_index = find_opt (opt + 1, lang_flag);
00579 if (opt_index == N_OPTS)
00580 goto done;
00581
00582 result = 1;
00583 option = &cl_options[opt_index];
00584
00585
00586 if (option->flags & CL_ARG)
00587 {
00588 if (option->flags & CL_JOINED)
00589 {
00590
00591
00592
00593 arg = argv[0] + cl_options[opt_index].opt_len + 1;
00594 if (!on)
00595 arg += strlen ("no-");
00596 }
00597
00598
00599
00600 if (!arg || (*arg == '\0' && option->flags & CL_SEPARATE))
00601 {
00602 arg = argv[1];
00603 result = 2;
00604 }
00605
00606 if (!arg || *arg == '\0')
00607 {
00608 missing_arg (opt_index);
00609 result = argc;
00610 goto done;
00611 }
00612 }
00613
00614
00615
00616
00617 if (!(cl_options[opt_index].flags & lang_flag))
00618 {
00619 complain_wrong_lang (opt_index, on);
00620 goto done;
00621 }
00622
00623 switch (code = option->opt_code)
00624 {
00625 case N_OPTS:
00626 break;
00627
00628 case OPT__help:
00629 print_help ();
00630 break;
00631
00632 case OPT_C:
00633 cpp_opts->discard_comments = 0;
00634 break;
00635
00636 case OPT_CC:
00637 cpp_opts->discard_comments = 0;
00638 cpp_opts->discard_comments_in_macro_exp = 0;
00639 break;
00640
00641 case OPT_E:
00642 flag_preprocess_only = 1;
00643 break;
00644
00645 case OPT_H:
00646 cpp_opts->print_include_names = 1;
00647 break;
00648
00649 case OPT_M:
00650 case OPT_MM:
00651
00652
00653
00654
00655 cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
00656 cpp_opts->no_output = 1;
00657 cpp_opts->inhibit_warnings = 1;
00658 break;
00659
00660 case OPT_MD:
00661 case OPT_MMD:
00662 cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
00663 deps_file = arg;
00664 break;
00665
00666 case OPT_MF:
00667 deps_seen = true;
00668 deps_file = arg;
00669 break;
00670
00671 case OPT_MG:
00672 deps_seen = true;
00673 cpp_opts->deps.missing_files = true;
00674 break;
00675
00676 case OPT_MP:
00677 deps_seen = true;
00678 cpp_opts->deps.phony_targets = true;
00679 break;
00680
00681 case OPT_MQ:
00682 case OPT_MT:
00683 deps_seen = true;
00684 defer_opt (code, arg);
00685 break;
00686
00687 case OPT_P:
00688 cpp_opts->no_line_commands = 1;
00689 break;
00690
00691 case OPT_Wabi:
00692 warn_abi = on;
00693 break;
00694
00695 case OPT_Wall:
00696 set_Wunused (on);
00697 set_Wformat (on);
00698 set_Wimplicit (on);
00699 warn_char_subscripts = on;
00700 warn_missing_braces = on;
00701 warn_parentheses = on;
00702 warn_return_type = on;
00703 warn_sequence_point = on;
00704 if (c_language == clk_cplusplus)
00705 warn_sign_compare = on;
00706 warn_switch = on;
00707 warn_strict_aliasing = on;
00708
00709
00710
00711 warn_unknown_pragmas = on;
00712
00713
00714
00715
00716 if (warn_uninitialized != 1)
00717 warn_uninitialized = (on ? 2 : 0);
00718
00719 if (c_language == clk_c)
00720
00721
00722 warn_main = on * 2;
00723 else
00724 {
00725
00726 warn_ctor_dtor_privacy = on;
00727 warn_nonvdtor = on;
00728 warn_reorder = on;
00729 warn_nontemplate_friend = on;
00730 }
00731
00732 cpp_opts->warn_trigraphs = on;
00733 cpp_opts->warn_comments = on;
00734 cpp_opts->warn_num_sign_change = on;
00735 cpp_opts->warn_multichar = on;
00736 break;
00737
00738 case OPT_Wbad_function_cast:
00739 warn_bad_function_cast = on;
00740 break;
00741
00742 case OPT_Wcast_qual:
00743 warn_cast_qual = on;
00744 break;
00745
00746 case OPT_Wchar_subscripts:
00747 warn_char_subscripts = on;
00748 break;
00749
00750 case OPT_Wcomment:
00751 case OPT_Wcomments:
00752 cpp_opts->warn_comments = on;
00753 break;
00754
00755 case OPT_Wconversion:
00756 warn_conversion = on;
00757 break;
00758
00759 case OPT_Wctor_dtor_privacy:
00760 warn_ctor_dtor_privacy = on;
00761 break;
00762
00763 case OPT_Wdeclaration_after_statement:
00764 warn_declaration_after_statement = on;
00765 break;
00766
00767 case OPT_Wdeprecated:
00768 warn_deprecated = on;
00769 cpp_opts->warn_deprecated = on;
00770 break;
00771
00772 case OPT_Wdiv_by_zero:
00773 warn_div_by_zero = on;
00774 break;
00775
00776 case OPT_Weffcxx:
00777 warn_ecpp = on;
00778 break;
00779
00780 case OPT_Wendif_labels:
00781 cpp_opts->warn_endif_labels = on;
00782 break;
00783
00784 case OPT_Werror:
00785 cpp_opts->warnings_are_errors = on;
00786 break;
00787
00788 case OPT_Werror_implicit_function_decl:
00789 if (!on)
00790 result = 0;
00791 else
00792 mesg_implicit_function_declaration = 2;
00793 break;
00794
00795 case OPT_Wfloat_equal:
00796 warn_float_equal = on;
00797 break;
00798
00799 case OPT_Wformat:
00800 set_Wformat (on);
00801 break;
00802
00803 case OPT_Wformat_eq:
00804 set_Wformat (atoi (arg));
00805 break;
00806
00807 case OPT_Wformat_extra_args:
00808 warn_format_extra_args = on;
00809 break;
00810
00811 case OPT_Wformat_nonliteral:
00812 warn_format_nonliteral = on;
00813 break;
00814
00815 case OPT_Wformat_security:
00816 warn_format_security = on;
00817 break;
00818
00819 case OPT_Wformat_y2k:
00820 warn_format_y2k = on;
00821 break;
00822
00823 case OPT_Wformat_zero_length:
00824 warn_format_zero_length = on;
00825 break;
00826
00827 case OPT_Wimplicit:
00828 set_Wimplicit (on);
00829 break;
00830
00831 case OPT_Wimplicit_function_decl:
00832 mesg_implicit_function_declaration = on;
00833 break;
00834
00835 case OPT_Wimplicit_int:
00836 warn_implicit_int = on;
00837 break;
00838
00839 case OPT_Wimport:
00840 cpp_opts->warn_import = on;
00841 break;
00842
00843 case OPT_Wlong_long:
00844 warn_long_long = on;
00845 break;
00846
00847 case OPT_Wmain:
00848 if (on)
00849 warn_main = 1;
00850 else
00851 warn_main = -1;
00852 break;
00853
00854 case OPT_Wmissing_braces:
00855 warn_missing_braces = on;
00856 break;
00857
00858 case OPT_Wmissing_declarations:
00859 warn_missing_declarations = on;
00860 break;
00861
00862 case OPT_Wmissing_format_attribute:
00863 warn_missing_format_attribute = on;
00864 break;
00865
00866 case OPT_Wmissing_prototypes:
00867 warn_missing_prototypes = on;
00868 break;
00869
00870 case OPT_Wmultichar:
00871 cpp_opts->warn_multichar = on;
00872 break;
00873
00874 case OPT_Wnested_externs:
00875 warn_nested_externs = on;
00876 break;
00877
00878 case OPT_Wnon_template_friend:
00879 warn_nontemplate_friend = on;
00880 break;
00881
00882 case OPT_Wnon_virtual_dtor:
00883 warn_nonvdtor = on;
00884 break;
00885
00886 case OPT_Wnonnull:
00887 warn_nonnull = on;
00888 break;
00889
00890 case OPT_Wold_style_cast:
00891 warn_old_style_cast = on;
00892 break;
00893
00894 case OPT_Woverloaded_virtual:
00895 warn_overloaded_virtual = on;
00896 break;
00897
00898 case OPT_Wparentheses:
00899 warn_parentheses = on;
00900 break;
00901
00902 case OPT_Wpmf_conversions:
00903 warn_pmf2ptr = on;
00904 break;
00905
00906 case OPT_Wpointer_arith:
00907 warn_pointer_arith = on;
00908 break;
00909
00910 case OPT_Wprotocol:
00911 warn_protocol = on;
00912 break;
00913
00914 case OPT_Wselector:
00915 warn_selector = on;
00916 break;
00917
00918 case OPT_Wredundant_decls:
00919 warn_redundant_decls = on;
00920 break;
00921
00922 case OPT_Wreorder:
00923 warn_reorder = on;
00924 break;
00925
00926 case OPT_Wreturn_type:
00927 warn_return_type = on;
00928 break;
00929
00930 case OPT_Wsequence_point:
00931 warn_sequence_point = on;
00932 break;
00933
00934 case OPT_Wsign_compare:
00935 warn_sign_compare = on;
00936 break;
00937
00938 case OPT_Wsign_promo:
00939 warn_sign_promo = on;
00940 break;
00941
00942 case OPT_Wstrict_prototypes:
00943 if (!on && c_language == clk_cplusplus)
00944 warning ("-Wno-strict-prototypes is not supported in C++");
00945 else
00946 warn_strict_prototypes = on;
00947 break;
00948
00949 case OPT_Wsynth:
00950 warn_synth = on;
00951 break;
00952
00953 case OPT_Wsystem_headers:
00954 cpp_opts->warn_system_headers = on;
00955 break;
00956
00957 case OPT_Wtraditional:
00958 warn_traditional = on;
00959 cpp_opts->warn_traditional = on;
00960 break;
00961
00962 case OPT_Wtrigraphs:
00963 cpp_opts->warn_trigraphs = on;
00964 break;
00965
00966 case OPT_Wundeclared_selector:
00967 warn_undeclared_selector = on;
00968 break;
00969
00970 case OPT_Wundef:
00971 cpp_opts->warn_undef = on;
00972 break;
00973
00974 case OPT_Wunknown_pragmas:
00975
00976
00977 warn_unknown_pragmas = on * 2;
00978 break;
00979
00980 case OPT_Wunused_macros:
00981 cpp_opts->warn_unused_macros = on;
00982 break;
00983
00984 case OPT_Wwrite_strings:
00985 if (c_language == clk_c)
00986 flag_const_strings = on;
00987 else
00988 warn_write_strings = on;
00989 break;
00990
00991 case OPT_ansi:
00992 if (c_language == clk_c)
00993 set_std_c89 (false, true);
00994 else
00995 set_std_cxx98 (true);
00996 break;
00997
00998 case OPT_d:
00999 handle_OPT_d (arg);
01000 break;
01001
01002 case OPT_fcond_mismatch:
01003 if (c_language == clk_c)
01004 {
01005 flag_cond_mismatch = on;
01006 break;
01007 }
01008
01009
01010 case OPT_fall_virtual:
01011 case OPT_fenum_int_equiv:
01012 case OPT_fguiding_decls:
01013 case OPT_fhonor_std:
01014 case OPT_fhuge_objects:
01015 case OPT_flabels_ok:
01016 case OPT_fname_mangling:
01017 case OPT_fnew_abi:
01018 case OPT_fnonnull_objects:
01019 case OPT_fsquangle:
01020 case OPT_fstrict_prototype:
01021 case OPT_fthis_is_variable:
01022 case OPT_fvtable_thunks:
01023 case OPT_fxref:
01024 warning ("switch \"%s\" is no longer supported", argv[0]);
01025 break;
01026
01027 case OPT_fabi_version:
01028 flag_abi_version = read_integral_parameter (arg, argv[0], 1);
01029 break;
01030
01031 case OPT_faccess_control:
01032 flag_access_control = on;
01033 break;
01034
01035 case OPT_falt_external_templates:
01036 flag_alt_external_templates = on;
01037 if (on)
01038 flag_external_templates = true;
01039 cp_deprecated:
01040 warning ("switch \"%s\" is deprecated, please see documentation for details", argv[0]);
01041 break;
01042
01043 case OPT_fasm:
01044 flag_no_asm = !on;
01045 break;
01046
01047 case OPT_fbuiltin:
01048 flag_no_builtin = !on;
01049 break;
01050
01051 case OPT_fbuiltin_:
01052 if (on)
01053 result = 0;
01054 else
01055 disable_builtin_function (arg);
01056 break;
01057
01058 case OPT_fdollars_in_identifiers:
01059 dollars_in_ident = on;
01060 break;
01061
01062 case OPT_fdump:
01063 if (!on || !dump_switch_p (argv[0] + strlen ("-f")))
01064 result = 0;
01065 break;
01066
01067 case OPT_ffreestanding:
01068 on = !on;
01069
01070 case OPT_fhosted:
01071 flag_hosted = on;
01072 flag_no_builtin = !on;
01073
01074 if (!on && warn_main == 2)
01075 warn_main = 0;
01076 break;
01077
01078 case OPT_fshort_double:
01079 flag_short_double = on;
01080 break;
01081
01082 case OPT_fshort_enums:
01083 flag_short_enums = on;
01084 break;
01085
01086 case OPT_fshort_wchar:
01087 flag_short_wchar = on;
01088 break;
01089
01090 case OPT_fsigned_bitfields:
01091 flag_signed_bitfields = on;
01092 explicit_flag_signed_bitfields = 1;
01093 break;
01094
01095 case OPT_fsigned_char:
01096 flag_signed_char = on;
01097 break;
01098
01099 case OPT_funsigned_bitfields:
01100 flag_signed_bitfields = !on;
01101 explicit_flag_signed_bitfields = 1;
01102 break;
01103
01104 case OPT_funsigned_char:
01105 flag_signed_char = !on;
01106 break;
01107
01108 case OPT_fcheck_new:
01109 flag_check_new = on;
01110 break;
01111
01112 case OPT_fconserve_space:
01113 flag_conserve_space = on;
01114 break;
01115
01116 case OPT_fconst_strings:
01117 flag_const_strings = on;
01118 break;
01119
01120 case OPT_fconstant_string_class:
01121 constant_string_class_name = arg;
01122 break;
01123
01124 case OPT_fdefault_inline:
01125 flag_default_inline = on;
01126 break;
01127
01128 case OPT_felide_constructors:
01129 flag_elide_constructors = on;
01130 break;
01131
01132 case OPT_fenforce_eh_specs:
01133 flag_enforce_eh_specs = on;
01134 break;
01135
01136 case OPT_fexternal_templates:
01137 flag_external_templates = on;
01138 goto cp_deprecated;
01139
01140 case OPT_ffixed_form:
01141 case OPT_ffixed_line_length:
01142
01143 if (flag_preprocess_only)
01144 result = -1;
01145 break;
01146
01147 case OPT_ffor_scope:
01148 flag_new_for_scope = on;
01149 break;
01150
01151 case OPT_fgnu_keywords:
01152 flag_no_gnu_keywords = !on;
01153 break;
01154
01155 case OPT_fgnu_runtime:
01156 flag_next_runtime = !on;
01157 break;
01158
01159 case OPT_fhandle_exceptions:
01160 warning ("-fhandle-exceptions has been renamed to -fexceptions (and is now on by default)");
01161 flag_exceptions = on;
01162 break;
01163
01164 case OPT_fimplement_inlines:
01165 flag_implement_inlines = on;
01166 break;
01167
01168 case OPT_fimplicit_inline_templates:
01169 flag_implicit_inline_templates = on;
01170 break;
01171
01172 case OPT_fimplicit_templates:
01173 flag_implicit_templates = on;
01174 break;
01175
01176 case OPT_fms_extensions:
01177 flag_ms_extensions = on;
01178 break;
01179
01180 case OPT_fnext_runtime:
01181 flag_next_runtime = on;
01182 break;
01183
01184 case OPT_fnonansi_builtins:
01185 flag_no_nonansi_builtin = !on;
01186 break;
01187
01188 case OPT_foperator_names:
01189 cpp_opts->operator_names = on;
01190 break;
01191
01192 case OPT_foptional_diags:
01193 flag_optional_diags = on;
01194 break;
01195
01196 case OPT_fpermissive:
01197 flag_permissive = on;
01198 break;
01199
01200 case OPT_fpreprocessed:
01201 cpp_opts->preprocessed = on;
01202 break;
01203
01204 case OPT_frepo:
01205 flag_use_repository = on;
01206 if (on)
01207 flag_implicit_templates = 0;
01208 break;
01209
01210 case OPT_frtti:
01211 flag_rtti = on;
01212 break;
01213
01214 case OPT_fshow_column:
01215 cpp_opts->show_column = on;
01216 break;
01217
01218 case OPT_fstats:
01219 flag_detailed_statistics = on;
01220 break;
01221
01222 case OPT_ftabstop:
01223
01224 if (!on)
01225 return 0;
01226
01227
01228 {
01229 char *endptr;
01230 long tabstop = strtol (arg, &endptr, 10);
01231 if (*endptr == '\0' && tabstop >= 1 && tabstop <= 100)
01232 cpp_opts->tabstop = tabstop;
01233 }
01234 break;
01235
01236 case OPT_ftemplate_depth:
01237 max_tinst_depth = read_integral_parameter (arg, argv[0], 0);
01238 break;
01239
01240 case OPT_fvtable_gc:
01241 flag_vtable_gc = on;
01242 break;
01243
01244 case OPT_fuse_cxa_atexit:
01245 flag_use_cxa_atexit = on;
01246 break;
01247
01248 case OPT_fweak:
01249 flag_weak = on;
01250 break;
01251
01252 case OPT_gen_decls:
01253 flag_gen_declaration = 1;
01254 break;
01255
01256 case OPT_lang_asm:
01257 cpp_set_lang (parse_in, CLK_ASM);
01258 break;
01259
01260 case OPT_lang_objc:
01261 cpp_opts->objc = 1;
01262 break;
01263
01264 case OPT_nostdinc:
01265
01266
01267 cpp_opts->no_standard_includes = 1;
01268 break;
01269
01270 case OPT_nostdincplusplus:
01271
01272 cpp_opts->no_standard_cplusplus_includes = 1;
01273 break;
01274
01275 case OPT_o:
01276 if (!out_fname)
01277 out_fname = arg;
01278 else
01279 {
01280 error ("output filename specified twice");
01281 result = argc;
01282 }
01283 break;
01284
01285
01286
01287
01288 case OPT_pedantic_errors:
01289 cpp_opts->pedantic_errors = 1;
01290
01291 case OPT_pedantic:
01292 cpp_opts->pedantic = 1;
01293 cpp_opts->warn_endif_labels = 1;
01294 break;
01295
01296 case OPT_print_objc_runtime_info:
01297 print_struct_values = 1;
01298 break;
01299
01300 case OPT_remap:
01301 cpp_opts->remap = 1;
01302 break;
01303
01304 case OPT_std_cplusplus98:
01305 case OPT_std_gnuplusplus98:
01306 set_std_cxx98 (code == OPT_std_cplusplus98 );
01307 break;
01308
01309 case OPT_std_c89:
01310 case OPT_std_iso9899_1990:
01311 case OPT_std_iso9899_199409:
01312 set_std_c89 (code == OPT_std_iso9899_199409 , true );
01313 break;
01314
01315 case OPT_std_gnu89:
01316 set_std_c89 (false , false );
01317 break;
01318
01319 case OPT_std_c99:
01320 case OPT_std_c9x:
01321 case OPT_std_iso9899_1999:
01322 case OPT_std_iso9899_199x:
01323 set_std_c99 (true );
01324 break;
01325
01326 case OPT_std_gnu99:
01327 case OPT_std_gnu9x:
01328 set_std_c99 (false );
01329 break;
01330
01331 case OPT_trigraphs:
01332 cpp_opts->trigraphs = 1;
01333 break;
01334
01335 case OPT_traditional_cpp:
01336 cpp_opts->traditional = 1;
01337 break;
01338
01339 case OPT_undef:
01340 flag_undef = 1;
01341 break;
01342
01343 case OPT_w:
01344 cpp_opts->inhibit_warnings = 1;
01345 break;
01346
01347 case OPT_v:
01348 cpp_opts->verbose = 1;
01349 break;
01350 }
01351
01352 done:
01353 if (dup)
01354 free (dup);
01355 return result;
01356 }
01357
01358
01359 bool
01360 c_common_post_options ()
01361 {
01362
01363 if (in_fname == NULL || !strcmp (in_fname, "-"))
01364 in_fname = "";
01365
01366 if (out_fname == NULL || !strcmp (out_fname, "-"))
01367 out_fname = "";
01368
01369 if (cpp_opts->deps.style == DEPS_NONE)
01370 check_deps_environment_vars ();
01371
01372 handle_deferred_opts ();
01373
01374 sanitize_cpp_opts ();
01375
01376 flag_inline_trees = 1;
01377
01378
01379
01380 if (! flag_instrument_function_entry_exit)
01381 {
01382 if (!flag_no_inline)
01383 flag_no_inline = 1;
01384 if (flag_inline_functions)
01385 {
01386 flag_inline_trees = 2;
01387 flag_inline_functions = 0;
01388 }
01389 }
01390
01391
01392
01393 if (warn_format_y2k && !warn_format)
01394 warning ("-Wformat-y2k ignored without -Wformat");
01395 if (warn_format_extra_args && !warn_format)
01396 warning ("-Wformat-extra-args ignored without -Wformat");
01397 if (warn_format_zero_length && !warn_format)
01398 warning ("-Wformat-zero-length ignored without -Wformat");
01399 if (warn_format_nonliteral && !warn_format)
01400 warning ("-Wformat-nonliteral ignored without -Wformat");
01401 if (warn_format_security && !warn_format)
01402 warning ("-Wformat-security ignored without -Wformat");
01403 if (warn_missing_format_attribute && !warn_format)
01404 warning ("-Wmissing-format-attribute ignored without -Wformat");
01405
01406
01407
01408 errorcount += cpp_errors (parse_in);
01409
01410 return flag_preprocess_only;
01411 }
01412
01413
01414 static void
01415 preprocess_file ()
01416 {
01417
01418
01419
01420 if (out_fname[0] == '\0')
01421 out_stream = stdout;
01422 else
01423 out_stream = fopen (out_fname, "w");
01424
01425 if (out_stream == NULL)
01426 fatal_io_error ("opening output file %s", out_fname);
01427 else
01428 cpp_preprocess_file (parse_in, in_fname, out_stream);
01429 }
01430
01431
01432 const char *
01433 c_common_init (filename)
01434 const char *filename;
01435 {
01436
01437
01438 cpp_opts->precision = TYPE_PRECISION (intmax_type_node);
01439 cpp_opts->char_precision = TYPE_PRECISION (char_type_node);
01440 cpp_opts->int_precision = TYPE_PRECISION (integer_type_node);
01441 cpp_opts->wchar_precision = TYPE_PRECISION (wchar_type_node);
01442 cpp_opts->unsigned_wchar = TREE_UNSIGNED (wchar_type_node);
01443
01444
01445
01446 cpp_get_callbacks (parse_in)->register_builtins = cb_register_builtins;
01447
01448
01449 if (flag_preprocess_only)
01450 {
01451 preprocess_file ();
01452 return NULL;
01453 }
01454
01455
01456
01457
01458 filename = init_c_lex (in_fname);
01459
01460 init_pragma ();
01461
01462 return filename;
01463 }
01464
01465
01466 void
01467 c_common_finish ()
01468 {
01469 FILE *deps_stream = NULL;
01470
01471 if (cpp_opts->deps.style != DEPS_NONE)
01472 {
01473
01474
01475 if (!deps_file)
01476 deps_stream = out_stream;
01477 else
01478 {
01479 deps_stream = fopen (deps_file, deps_append ? "a": "w");
01480 if (!deps_stream)
01481 fatal_io_error ("opening dependency file %s", deps_file);
01482 }
01483 }
01484
01485
01486
01487 errorcount += cpp_finish (parse_in, deps_stream);
01488
01489 if (deps_stream && deps_stream != out_stream
01490 && (ferror (deps_stream) || fclose (deps_stream)))
01491 fatal_io_error ("closing dependency file %s", deps_file);
01492
01493 if (out_stream && (ferror (out_stream) || fclose (out_stream)))
01494 fatal_io_error ("when writing output to %s", out_fname);
01495 }
01496
01497
01498
01499
01500
01501
01502
01503
01504 static void
01505 check_deps_environment_vars ()
01506 {
01507 char *spec;
01508
01509 GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
01510 if (spec)
01511 cpp_opts->deps.style = DEPS_USER;
01512 else
01513 {
01514 GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
01515 if (spec)
01516 {
01517 cpp_opts->deps.style = DEPS_SYSTEM;
01518 cpp_opts->deps.ignore_main_file = true;
01519 }
01520 }
01521
01522 if (spec)
01523 {
01524
01525 char *s = strchr (spec, ' ');
01526 if (s)
01527 {
01528
01529 defer_opt (OPT_MT, s + 1);
01530 *s = '\0';
01531 }
01532
01533
01534 if (!deps_file)
01535 deps_file = spec;
01536
01537 deps_append = 1;
01538 }
01539 }
01540
01541
01542 static void
01543 handle_deferred_opts ()
01544 {
01545 size_t i;
01546
01547 for (i = 0; i < deferred_count; i++)
01548 {
01549 struct deferred_opt *opt = &deferred_opts[i];
01550
01551 switch (opt->code)
01552 {
01553 case OPT_MT:
01554 case OPT_MQ:
01555 cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
01556 break;
01557
01558 default:
01559 abort ();
01560 }
01561 }
01562
01563 free (deferred_opts);
01564 }
01565
01566
01567
01568 static void
01569 sanitize_cpp_opts ()
01570 {
01571
01572
01573 if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
01574 error ("to generate dependencies you must specify either -M or -MM");
01575
01576
01577
01578 if (cpp_opts->dump_macros == dump_only)
01579 cpp_opts->no_output = 1;
01580
01581
01582
01583 if (cpp_opts->no_output)
01584 {
01585 if (cpp_opts->dump_macros != dump_only)
01586 cpp_opts->dump_macros = dump_none;
01587 cpp_opts->dump_includes = 0;
01588 }
01589
01590 cpp_opts->unsigned_char = !flag_signed_char;
01591 cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
01592
01593
01594
01595 cpp_opts->warn_long_long
01596 = warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
01597 }
01598
01599
01600
01601 static void
01602 set_std_c89 (c94, iso)
01603 int c94, iso;
01604 {
01605 cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
01606 flag_iso = iso;
01607 flag_no_asm = iso;
01608 flag_no_gnu_keywords = iso;
01609 flag_no_nonansi_builtin = iso;
01610 flag_noniso_default_format_attributes = !iso;
01611 flag_isoc94 = c94;
01612 flag_isoc99 = 0;
01613 flag_writable_strings = 0;
01614 }
01615
01616
01617 static void
01618 set_std_c99 (iso)
01619 int iso;
01620 {
01621 cpp_set_lang (parse_in, iso ? CLK_STDC99: CLK_GNUC99);
01622 flag_no_asm = iso;
01623 flag_no_nonansi_builtin = iso;
01624 flag_noniso_default_format_attributes = !iso;
01625 flag_iso = iso;
01626 flag_isoc99 = 1;
01627 flag_isoc94 = 1;
01628 flag_writable_strings = 0;
01629 }
01630
01631
01632 static void
01633 set_std_cxx98 (iso)
01634 int iso;
01635 {
01636 cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
01637 flag_no_gnu_keywords = iso;
01638 flag_no_nonansi_builtin = iso;
01639 flag_noniso_default_format_attributes = !iso;
01640 flag_iso = iso;
01641 }
01642
01643
01644 static void
01645 set_Wimplicit (on)
01646 int on;
01647 {
01648 warn_implicit = on;
01649 warn_implicit_int = on;
01650 if (on)
01651 {
01652 if (mesg_implicit_function_declaration != 2)
01653 mesg_implicit_function_declaration = 1;
01654 }
01655 else
01656 mesg_implicit_function_declaration = 0;
01657 }
01658
01659
01660
01661 static void
01662 handle_OPT_d (arg)
01663 const char *arg;
01664 {
01665 char c;
01666
01667 while ((c = *arg++) != '\0')
01668 switch (c)
01669 {
01670 case 'M':
01671 cpp_opts->dump_macros = dump_only;
01672 break;
01673
01674 case 'N':
01675 cpp_opts->dump_macros = dump_names;
01676 break;
01677
01678 case 'D':
01679 cpp_opts->dump_macros = dump_definitions;
01680 break;
01681
01682 case 'I':
01683 cpp_opts->dump_includes = 1;
01684 break;
01685 }
01686 }
01687
01688
01689 static void
01690 write_langs (buf, flags)
01691 char *buf;
01692 int flags;
01693 {
01694 *buf = '\0';
01695 if (flags & CL_C_ONLY)
01696 strcat (buf, "C");
01697 if (flags & CL_OBJC_ONLY)
01698 {
01699 if (*buf)
01700 strcat (buf, "/");
01701 strcat (buf, "ObjC");
01702 }
01703 if (flags & CL_CXX_ONLY)
01704 {
01705 if (*buf)
01706 strcat (buf, "/");
01707 strcat (buf, "C++");
01708 }
01709 }
01710
01711
01712 static void
01713 complain_wrong_lang (opt_index, on)
01714 size_t opt_index;
01715 int on;
01716 {
01717 char ok_langs[60], bad_langs[60];
01718 int ok_flags = cl_options[opt_index].flags;
01719
01720 write_langs (ok_langs, ok_flags);
01721 write_langs (bad_langs, ~ok_flags);
01722 warning ("\"-%c%s%s\" is valid for %s but not for %s",
01723 cl_options[opt_index].opt_text[0], on ? "" : "no-",
01724 cl_options[opt_index].opt_text + 1, ok_langs, bad_langs);
01725 }
01726
01727
01728 static void
01729 print_help ()
01730 {
01731
01732
01733 fputs (_("\
01734 Switches:\n\
01735 -include <file> Include the contents of <file> before other files\n\
01736 -imacros <file> Accept definition of macros in <file>\n\
01737 -iprefix <path> Specify <path> as a prefix for next two options\n\
01738 -iwithprefix <dir> Add <dir> to the end of the system include path\n\
01739 -iwithprefixbefore <dir> Add <dir> to the end of the main include path\n\
01740 -isystem <dir> Add <dir> to the start of the system include path\n\
01741 "), stdout);
01742 fputs (_("\
01743 -idirafter <dir> Add <dir> to the end of the system include path\n\
01744 -I <dir> Add <dir> to the end of the main include path\n\
01745 -I- Fine-grained include path control; see info docs\n\
01746 -nostdinc Do not search system include directories\n\
01747 (dirs specified with -isystem will still be used)\n\
01748 -nostdinc++ Do not search system include directories for C++\n\
01749 -o <file> Put output into <file>\n\
01750 "), stdout);
01751 fputs (_("\
01752 -trigraphs Support ISO C trigraphs\n\
01753 -std=<std name> Specify the conformance standard; one of:\n\
01754 gnu89, gnu99, c89, c99, iso9899:1990,\n\
01755 iso9899:199409, iso9899:1999, c++98\n\
01756 -w Inhibit warning messages\n\
01757 -W[no-]trigraphs Warn if trigraphs are encountered\n\
01758 -W[no-]comment{s} Warn if one comment starts inside another\n\
01759 "), stdout);
01760 fputs (_("\
01761 -W[no-]traditional Warn about features not present in traditional C\n\
01762 -W[no-]undef Warn if an undefined macro is used by #if\n\
01763 -W[no-]import Warn about the use of the #import directive\n\
01764 "), stdout);
01765 fputs (_("\
01766 -W[no-]error Treat all warnings as errors\n\
01767 -W[no-]system-headers Do not suppress warnings from system headers\n\
01768 -W[no-]all Enable most preprocessor warnings\n\
01769 "), stdout);
01770 fputs (_("\
01771 -M Generate make dependencies\n\
01772 -MM As -M, but ignore system header files\n\
01773 -MD Generate make dependencies and compile\n\
01774 -MMD As -MD, but ignore system header files\n\
01775 -MF <file> Write dependency output to the given file\n\
01776 -MG Treat missing header file as generated files\n\
01777 "), stdout);
01778 fputs (_("\
01779 -MP Generate phony targets for all headers\n\
01780 -MQ <target> Add a MAKE-quoted target\n\
01781 -MT <target> Add an unquoted target\n\
01782 "), stdout);
01783 fputs (_("\
01784 -D<macro> Define a <macro> with string '1' as its value\n\
01785 -D<macro>=<val> Define a <macro> with <val> as its value\n\
01786 -A<question>=<answer> Assert the <answer> to <question>\n\
01787 -A-<question>=<answer> Disable the <answer> to <question>\n\
01788 -U<macro> Undefine <macro> \n\
01789 -v Display the version number\n\
01790 "), stdout);
01791 fputs (_("\
01792 -H Print the name of header files as they are used\n\
01793 -C Do not discard comments\n\
01794 -dM Display a list of macro definitions active at end\n\
01795 -dD Preserve macro definitions in output\n\
01796 -dN As -dD except that only the names are preserved\n\
01797 -dI Include #include directives in the output\n\
01798 "), stdout);
01799 fputs (_("\
01800 -f[no-]preprocessed Treat the input file as already preprocessed\n\
01801 -ftabstop=<number> Distance between tab stops for column reporting\n\
01802 -P Do not generate #line directives\n\
01803 -remap Remap file names when including files\n\
01804 --help Display this information\n\
01805 "), stdout);
01806 }