PR c++/86342 - -Wdeprecated-copy and system headers.
[official-gcc.git] / gcc / opts.h
blob3c4065eae92b483b9ac2675de5189c6ea384879f
1 /* Command line option handling.
2 Copyright (C) 2002-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_OPTS_H
21 #define GCC_OPTS_H
23 #include "obstack.h"
25 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
26 enum cl_var_type {
27 /* The switch is enabled when FLAG_VAR is nonzero. */
28 CLVC_BOOLEAN,
30 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
31 CLVC_EQUAL,
33 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
34 CLVC_BIT_CLEAR,
36 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
37 CLVC_BIT_SET,
39 /* The switch takes a string argument and FLAG_VAR points to that
40 argument. */
41 CLVC_STRING,
43 /* The switch takes an enumerated argument (VAR_ENUM says what
44 enumeration) and FLAG_VAR points to that argument. */
45 CLVC_ENUM,
47 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
48 later processing. */
49 CLVC_DEFER
52 struct cl_option
54 /* Text of the option, including initial '-'. */
55 const char *opt_text;
56 /* Help text for --help, or NULL. */
57 const char *help;
58 /* Error message for missing argument, or NULL. */
59 const char *missing_argument_error;
60 /* Warning to give when this option is used, or NULL. */
61 const char *warn_message;
62 /* Argument of alias target when positive option given, or NULL. */
63 const char *alias_arg;
64 /* Argument of alias target when negative option given, or NULL. */
65 const char *neg_alias_arg;
66 /* Alias target, or N_OPTS if not an alias. */
67 unsigned short alias_target;
68 /* Previous option that is an initial substring of this one, or
69 N_OPTS if none. */
70 unsigned short back_chain;
71 /* Option length, not including initial '-'. */
72 unsigned char opt_len;
73 /* Next option in a sequence marked with Negative, or -1 if none. */
74 int neg_index;
75 /* CL_* flags for this option. */
76 unsigned int flags;
77 /* Disabled in this configuration. */
78 BOOL_BITFIELD cl_disabled : 1;
79 /* Options marked with CL_SEPARATE take a number of separate
80 arguments (1 to 4) that is one more than the number in this
81 bit-field. */
82 unsigned int cl_separate_nargs : 2;
83 /* Option is an alias when used with separate argument. */
84 BOOL_BITFIELD cl_separate_alias : 1;
85 /* Alias to negative form of option. */
86 BOOL_BITFIELD cl_negative_alias : 1;
87 /* Option takes no argument in the driver. */
88 BOOL_BITFIELD cl_no_driver_arg : 1;
89 /* Reject this option in the driver. */
90 BOOL_BITFIELD cl_reject_driver : 1;
91 /* Reject no- form. */
92 BOOL_BITFIELD cl_reject_negative : 1;
93 /* Missing argument OK (joined). */
94 BOOL_BITFIELD cl_missing_ok : 1;
95 /* Argument is an integer >=0. */
96 BOOL_BITFIELD cl_uinteger : 1;
97 /* Argument is a HOST_WIDE_INT. */
98 BOOL_BITFIELD cl_host_wide_int : 1;
99 /* Argument should be converted to lowercase. */
100 BOOL_BITFIELD cl_tolower : 1;
101 /* Report argument with -fverbose-asm */
102 BOOL_BITFIELD cl_report : 1;
103 /* Deprecated option */
104 BOOL_BITFIELD cl_deprecated: 1;
105 /* Offset of field for this option in struct gcc_options, or
106 (unsigned short) -1 if none. */
107 unsigned short flag_var_offset;
108 /* Index in cl_enums of enum used for this option's arguments, for
109 CLVC_ENUM options. */
110 unsigned short var_enum;
111 /* How this option's value is determined and sets a field. */
112 enum cl_var_type var_type;
113 /* Value or bit-mask with which to set a field. */
114 HOST_WIDE_INT var_value;
115 /* Range info minimum, or -1. */
116 int range_min;
117 /* Range info maximum, or -1. */
118 int range_max;
121 /* Records that the state of an option consists of SIZE bytes starting
122 at DATA. DATA might point to CH in some cases. */
123 struct cl_option_state {
124 const void *data;
125 size_t size;
126 char ch;
129 extern const struct cl_option cl_options[];
130 extern const unsigned int cl_options_count;
131 extern const char *const lang_names[];
132 extern const unsigned int cl_lang_count;
134 #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
135 #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
136 #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
137 #define CL_DRIVER (1U << 19) /* Driver option. */
138 #define CL_TARGET (1U << 20) /* Target-specific option. */
139 #define CL_COMMON (1U << 21) /* Language-independent. */
141 #define CL_MIN_OPTION_CLASS CL_PARAMS
142 #define CL_MAX_OPTION_CLASS CL_COMMON
144 /* From here on the bits describe attributes of the options.
145 Before this point the bits have described the class of the option.
146 This distinction is important because --help will not list options
147 which only have these higher bits set. */
149 #define CL_JOINED (1U << 22) /* If takes joined argument. */
150 #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
151 #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
152 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
153 #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
155 /* Flags for an enumerated option argument. */
156 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
157 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
159 /* Structure describing an enumerated option argument. */
161 struct cl_enum_arg
163 /* The argument text, or NULL at the end of the array. */
164 const char *arg;
166 /* The corresponding integer value. */
167 int value;
169 /* Flags associated with this argument. */
170 unsigned int flags;
173 /* Structure describing an enumerated set of option arguments. */
175 struct cl_enum
177 /* Help text, or NULL if the values should not be listed in --help
178 output. */
179 const char *help;
181 /* Error message for unknown arguments, or NULL to use a generic
182 error. */
183 const char *unknown_error;
185 /* Array of possible values. */
186 const struct cl_enum_arg *values;
188 /* The size of the type used to store a value. */
189 size_t var_size;
191 /* Function to set a variable of this type. */
192 void (*set) (void *var, int value);
194 /* Function to get the value of a variable of this type. */
195 int (*get) (const void *var);
198 extern const struct cl_enum cl_enums[];
199 extern const unsigned int cl_enums_count;
201 /* Possible ways in which a command-line option may be erroneous.
202 These do not include not being known at all; an option index of
203 OPT_SPECIAL_unknown is used for that. */
205 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
206 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
207 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
208 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
209 #define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
210 #define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
211 #define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
212 not permitted (together
213 with OPT_SPECIAL_unknown). */
214 #define CL_ERR_DEPRECATED (1 << 7) /* Deprecated option. */
216 /* Structure describing the result of decoding an option. */
218 struct cl_decoded_option
220 /* The index of this option, or an OPT_SPECIAL_* value for
221 non-options and unknown options. */
222 size_t opt_index;
224 /* Any warning to give for use of this option, or NULL if none. */
225 const char *warn_message;
227 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
228 the option or non-option command-line argument. */
229 const char *arg;
231 /* The original text of option plus arguments, with separate argv
232 elements concatenated into one string with spaces separating
233 them. This is for such uses as diagnostics and
234 -frecord-gcc-switches. */
235 const char *orig_option_with_args_text;
237 /* The canonical form of the option and its argument, for when it is
238 necessary to reconstruct argv elements (in particular, for
239 processing specs and passing options to subprocesses from the
240 driver). */
241 const char *canonical_option[4];
243 /* The number of elements in the canonical form of the option and
244 arguments; always at least 1. */
245 size_t canonical_option_num_elements;
247 /* For a boolean option, 1 for the true case and 0 for the "no-"
248 case. For an unsigned integer option, the value of the
249 argument. 1 in all other cases. */
250 int value;
252 /* Any flags describing errors detected in this option. */
253 int errors;
256 /* Structure describing an option deferred for handling after the main
257 option handlers. */
259 struct cl_deferred_option
261 /* Elements from struct cl_decoded_option used for deferred
262 options. */
263 size_t opt_index;
264 const char *arg;
265 int value;
268 /* Structure describing a single option-handling callback. */
270 struct cl_option_handler_func
272 /* The function called to handle the option. */
273 bool (*handler) (struct gcc_options *opts,
274 struct gcc_options *opts_set,
275 const struct cl_decoded_option *decoded,
276 unsigned int lang_mask, int kind, location_t loc,
277 const struct cl_option_handlers *handlers,
278 diagnostic_context *dc,
279 void (*target_option_override_hook) (void));
281 /* The mask that must have some bit in common with the flags for the
282 option for this particular handler to be used. */
283 unsigned int mask;
286 /* Structure describing the callbacks used in handling options. */
288 struct cl_option_handlers
290 /* Callback for an unknown option to determine whether to give an
291 error for it, and possibly store information to diagnose the
292 option at a later point. Return true if an error should be
293 given, false otherwise. */
294 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
296 /* Callback to handle, and possibly diagnose, an option for another
297 language. */
298 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
299 unsigned int lang_mask);
301 /* Target option override hook. */
302 void (*target_option_override_hook) (void);
304 /* The number of individual handlers. */
305 size_t num_handlers;
307 /* The handlers themselves. */
308 struct cl_option_handler_func handlers[3];
311 /* Hold command-line options associated with stack limitation. */
312 extern const char *opt_fstack_limit_symbol_arg;
313 extern int opt_fstack_limit_register_no;
315 /* Input file names. */
317 extern const char **in_fnames;
319 /* The count of input filenames. */
321 extern unsigned num_in_fnames;
323 extern char *opts_concat (const char *first, ...);
325 /* Obstack for option strings. */
327 extern struct obstack opts_obstack;
329 size_t find_opt (const char *input, unsigned int lang_mask);
330 extern int integral_argument (const char *arg);
331 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
332 const char **argp, int value,
333 unsigned int lang_mask);
334 extern void decode_cmdline_options_to_array (unsigned int argc,
335 const char **argv,
336 unsigned int lang_mask,
337 struct cl_decoded_option **decoded_options,
338 unsigned int *decoded_options_count);
339 extern void init_options_once (void);
340 extern void init_options_struct (struct gcc_options *opts,
341 struct gcc_options *opts_set);
342 extern void init_opts_obstack (void);
343 extern void finalize_options_struct (struct gcc_options *opts);
344 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
345 const char **argv,
346 struct cl_decoded_option **decoded_options,
347 unsigned int *decoded_options_count);
348 extern void set_default_handlers (struct cl_option_handlers *handlers,
349 void (*target_option_override_hook) (void));
350 extern void decode_options (struct gcc_options *opts,
351 struct gcc_options *opts_set,
352 struct cl_decoded_option *decoded_options,
353 unsigned int decoded_options_count,
354 location_t loc,
355 diagnostic_context *dc,
356 void (*target_option_override_hook) (void));
357 extern int option_enabled (int opt_idx, void *opts);
358 extern bool get_option_state (struct gcc_options *, int,
359 struct cl_option_state *);
360 extern void set_option (struct gcc_options *opts,
361 struct gcc_options *opts_set,
362 int opt_index, int value, const char *arg, int kind,
363 location_t loc, diagnostic_context *dc);
364 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
365 bool handle_generated_option (struct gcc_options *opts,
366 struct gcc_options *opts_set,
367 size_t opt_index, const char *arg, int value,
368 unsigned int lang_mask, int kind, location_t loc,
369 const struct cl_option_handlers *handlers,
370 bool generated_p, diagnostic_context *dc);
371 void generate_option (size_t opt_index, const char *arg, int value,
372 unsigned int lang_mask,
373 struct cl_decoded_option *decoded);
374 void generate_option_input_file (const char *file,
375 struct cl_decoded_option *decoded);
376 extern void read_cmdline_option (struct gcc_options *opts,
377 struct gcc_options *opts_set,
378 struct cl_decoded_option *decoded,
379 location_t loc,
380 unsigned int lang_mask,
381 const struct cl_option_handlers *handlers,
382 diagnostic_context *dc);
383 extern void control_warning_option (unsigned int opt_index, int kind,
384 const char *arg, bool imply, location_t loc,
385 unsigned int lang_mask,
386 const struct cl_option_handlers *handlers,
387 struct gcc_options *opts,
388 struct gcc_options *opts_set,
389 diagnostic_context *dc);
390 extern char *write_langs (unsigned int mask);
391 extern void print_ignored_options (void);
392 extern void handle_common_deferred_options (void);
393 unsigned int parse_sanitizer_options (const char *, location_t, int,
394 unsigned int, int, bool);
396 unsigned int parse_no_sanitize_attribute (char *value);
397 extern bool common_handle_option (struct gcc_options *opts,
398 struct gcc_options *opts_set,
399 const struct cl_decoded_option *decoded,
400 unsigned int lang_mask, int kind,
401 location_t loc,
402 const struct cl_option_handlers *handlers,
403 diagnostic_context *dc,
404 void (*target_option_override_hook) (void));
405 extern bool target_handle_option (struct gcc_options *opts,
406 struct gcc_options *opts_set,
407 const struct cl_decoded_option *decoded,
408 unsigned int lang_mask, int kind,
409 location_t loc,
410 const struct cl_option_handlers *handlers,
411 diagnostic_context *dc,
412 void (*target_option_override_hook) (void));
413 extern void finish_options (struct gcc_options *opts,
414 struct gcc_options *opts_set,
415 location_t loc);
416 extern void default_options_optimization (struct gcc_options *opts,
417 struct gcc_options *opts_set,
418 struct cl_decoded_option *decoded_options,
419 unsigned int decoded_options_count,
420 location_t loc,
421 unsigned int lang_mask,
422 const struct cl_option_handlers *handlers,
423 diagnostic_context *dc);
424 extern void set_struct_debug_option (struct gcc_options *opts,
425 location_t loc,
426 const char *value);
427 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
428 int *value, unsigned int lang_mask);
430 extern const struct sanitizer_opts_s
432 const char *const name;
433 unsigned int flag;
434 size_t len;
435 bool can_recover;
436 } sanitizer_opts[];
438 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
439 const struct cl_option *option,
440 const char *base_option);
441 extern const char *candidates_list_and_hint (const char *arg, char *&str,
442 const auto_vec <const char *> &
443 candidates);
445 #endif