]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/opts.h
PR driver/69265 and 69453: improved suggestions for various misspelled options
[thirdparty/gcc.git] / gcc / opts.h
1 /* Command line option handling.
2 Copyright (C) 2002-2016 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
20 #ifndef GCC_OPTS_H
21 #define GCC_OPTS_H
22
23 #include "obstack.h"
24
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,
29
30 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
31 CLVC_EQUAL,
32
33 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
34 CLVC_BIT_CLEAR,
35
36 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
37 CLVC_BIT_SET,
38
39 /* The switch takes a string argument and FLAG_VAR points to that
40 argument. */
41 CLVC_STRING,
42
43 /* The switch takes an enumerated argument (VAR_ENUM says what
44 enumeration) and FLAG_VAR points to that argument. */
45 CLVC_ENUM,
46
47 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
48 later processing. */
49 CLVC_DEFER
50 };
51
52 struct cl_option
53 {
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 /* Offset of field for this option in struct gcc_options, or
104 (unsigned short) -1 if none. */
105 unsigned short flag_var_offset;
106 /* Index in cl_enums of enum used for this option's arguments, for
107 CLVC_ENUM options. */
108 unsigned short var_enum;
109 /* How this option's value is determined and sets a field. */
110 enum cl_var_type var_type;
111 /* Value or bit-mask with which to set a field. */
112 HOST_WIDE_INT var_value;
113 };
114
115 /* Records that the state of an option consists of SIZE bytes starting
116 at DATA. DATA might point to CH in some cases. */
117 struct cl_option_state {
118 const void *data;
119 size_t size;
120 char ch;
121 };
122
123 extern const struct cl_option cl_options[];
124 extern const unsigned int cl_options_count;
125 extern const char *const lang_names[];
126 extern const unsigned int cl_lang_count;
127
128 #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
129 #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
130 #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
131 #define CL_DRIVER (1U << 19) /* Driver option. */
132 #define CL_TARGET (1U << 20) /* Target-specific option. */
133 #define CL_COMMON (1U << 21) /* Language-independent. */
134
135 #define CL_MIN_OPTION_CLASS CL_PARAMS
136 #define CL_MAX_OPTION_CLASS CL_COMMON
137
138 /* From here on the bits describe attributes of the options.
139 Before this point the bits have described the class of the option.
140 This distinction is important because --help will not list options
141 which only have these higher bits set. */
142
143 #define CL_JOINED (1U << 22) /* If takes joined argument. */
144 #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
145 #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
146 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
147 #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
148
149 /* Flags for an enumerated option argument. */
150 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
151 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
152
153 /* Structure describing an enumerated option argument. */
154
155 struct cl_enum_arg
156 {
157 /* The argument text, or NULL at the end of the array. */
158 const char *arg;
159
160 /* The corresponding integer value. */
161 int value;
162
163 /* Flags associated with this argument. */
164 unsigned int flags;
165 };
166
167 /* Structure describing an enumerated set of option arguments. */
168
169 struct cl_enum
170 {
171 /* Help text, or NULL if the values should not be listed in --help
172 output. */
173 const char *help;
174
175 /* Error message for unknown arguments, or NULL to use a generic
176 error. */
177 const char *unknown_error;
178
179 /* Array of possible values. */
180 const struct cl_enum_arg *values;
181
182 /* The size of the type used to store a value. */
183 size_t var_size;
184
185 /* Function to set a variable of this type. */
186 void (*set) (void *var, int value);
187
188 /* Function to get the value of a variable of this type. */
189 int (*get) (const void *var);
190 };
191
192 extern const struct cl_enum cl_enums[];
193 extern const unsigned int cl_enums_count;
194
195 /* Possible ways in which a command-line option may be erroneous.
196 These do not include not being known at all; an option index of
197 OPT_SPECIAL_unknown is used for that. */
198
199 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
200 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
201 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
202 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
203 #define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
204 #define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
205 not permitted (together
206 with OPT_SPECIAL_unknown). */
207
208 /* Structure describing the result of decoding an option. */
209
210 struct cl_decoded_option
211 {
212 /* The index of this option, or an OPT_SPECIAL_* value for
213 non-options and unknown options. */
214 size_t opt_index;
215
216 /* Any warning to give for use of this option, or NULL if none. */
217 const char *warn_message;
218
219 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
220 the option or non-option command-line argument. */
221 const char *arg;
222
223 /* The original text of option plus arguments, with separate argv
224 elements concatenated into one string with spaces separating
225 them. This is for such uses as diagnostics and
226 -frecord-gcc-switches. */
227 const char *orig_option_with_args_text;
228
229 /* The canonical form of the option and its argument, for when it is
230 necessary to reconstruct argv elements (in particular, for
231 processing specs and passing options to subprocesses from the
232 driver). */
233 const char *canonical_option[4];
234
235 /* The number of elements in the canonical form of the option and
236 arguments; always at least 1. */
237 size_t canonical_option_num_elements;
238
239 /* For a boolean option, 1 for the true case and 0 for the "no-"
240 case. For an unsigned integer option, the value of the
241 argument. 1 in all other cases. */
242 int value;
243
244 /* Any flags describing errors detected in this option. */
245 int errors;
246 };
247
248 /* Structure describing an option deferred for handling after the main
249 option handlers. */
250
251 struct cl_deferred_option
252 {
253 /* Elements from struct cl_decoded_option used for deferred
254 options. */
255 size_t opt_index;
256 const char *arg;
257 int value;
258 };
259
260 /* Structure describing a single option-handling callback. */
261
262 struct cl_option_handler_func
263 {
264 /* The function called to handle the option. */
265 bool (*handler) (struct gcc_options *opts,
266 struct gcc_options *opts_set,
267 const struct cl_decoded_option *decoded,
268 unsigned int lang_mask, int kind, location_t loc,
269 const struct cl_option_handlers *handlers,
270 diagnostic_context *dc);
271
272 /* The mask that must have some bit in common with the flags for the
273 option for this particular handler to be used. */
274 unsigned int mask;
275 };
276
277 /* Structure describing the callbacks used in handling options. */
278
279 struct cl_option_handlers
280 {
281 /* Callback for an unknown option to determine whether to give an
282 error for it, and possibly store information to diagnose the
283 option at a later point. Return true if an error should be
284 given, false otherwise. */
285 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
286
287 /* Callback to handle, and possibly diagnose, an option for another
288 language. */
289 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
290 unsigned int lang_mask);
291
292 /* The number of individual handlers. */
293 size_t num_handlers;
294
295 /* The handlers themselves. */
296 struct cl_option_handler_func handlers[3];
297 };
298
299 /* Input file names. */
300
301 extern const char **in_fnames;
302
303 /* The count of input filenames. */
304
305 extern unsigned num_in_fnames;
306
307 extern char *opts_concat (const char *first, ...);
308
309 /* Obstack for option strings. */
310
311 extern struct obstack opts_obstack;
312
313 size_t find_opt (const char *input, unsigned int lang_mask);
314 extern int integral_argument (const char *arg);
315 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
316 const char **argp, int value,
317 unsigned int lang_mask);
318 extern void decode_cmdline_options_to_array (unsigned int argc,
319 const char **argv,
320 unsigned int lang_mask,
321 struct cl_decoded_option **decoded_options,
322 unsigned int *decoded_options_count);
323 extern void init_options_once (void);
324 extern void init_options_struct (struct gcc_options *opts,
325 struct gcc_options *opts_set);
326 extern void init_opts_obstack (void);
327 extern void finalize_options_struct (struct gcc_options *opts);
328 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
329 const char **argv,
330 struct cl_decoded_option **decoded_options,
331 unsigned int *decoded_options_count);
332 extern void set_default_handlers (struct cl_option_handlers *handlers);
333 extern void decode_options (struct gcc_options *opts,
334 struct gcc_options *opts_set,
335 struct cl_decoded_option *decoded_options,
336 unsigned int decoded_options_count,
337 location_t loc,
338 diagnostic_context *dc);
339 extern int option_enabled (int opt_idx, void *opts);
340 extern bool get_option_state (struct gcc_options *, int,
341 struct cl_option_state *);
342 extern void set_option (struct gcc_options *opts,
343 struct gcc_options *opts_set,
344 int opt_index, int value, const char *arg, int kind,
345 location_t loc, diagnostic_context *dc);
346 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
347 bool handle_generated_option (struct gcc_options *opts,
348 struct gcc_options *opts_set,
349 size_t opt_index, const char *arg, int value,
350 unsigned int lang_mask, int kind, location_t loc,
351 const struct cl_option_handlers *handlers,
352 diagnostic_context *dc);
353 void generate_option (size_t opt_index, const char *arg, int value,
354 unsigned int lang_mask,
355 struct cl_decoded_option *decoded);
356 void generate_option_input_file (const char *file,
357 struct cl_decoded_option *decoded);
358 extern void read_cmdline_option (struct gcc_options *opts,
359 struct gcc_options *opts_set,
360 struct cl_decoded_option *decoded,
361 location_t loc,
362 unsigned int lang_mask,
363 const struct cl_option_handlers *handlers,
364 diagnostic_context *dc);
365 extern void control_warning_option (unsigned int opt_index, int kind,
366 const char *arg, bool imply, location_t loc,
367 unsigned int lang_mask,
368 const struct cl_option_handlers *handlers,
369 struct gcc_options *opts,
370 struct gcc_options *opts_set,
371 diagnostic_context *dc);
372 extern char *write_langs (unsigned int mask);
373 extern void print_ignored_options (void);
374 extern void handle_common_deferred_options (void);
375 unsigned int parse_sanitizer_options (const char *, location_t, int,
376 unsigned int, int, bool);
377 extern bool common_handle_option (struct gcc_options *opts,
378 struct gcc_options *opts_set,
379 const struct cl_decoded_option *decoded,
380 unsigned int lang_mask, int kind,
381 location_t loc,
382 const struct cl_option_handlers *handlers,
383 diagnostic_context *dc);
384 extern bool target_handle_option (struct gcc_options *opts,
385 struct gcc_options *opts_set,
386 const struct cl_decoded_option *decoded,
387 unsigned int lang_mask, int kind,
388 location_t loc,
389 const struct cl_option_handlers *handlers,
390 diagnostic_context *dc);
391 extern void finish_options (struct gcc_options *opts,
392 struct gcc_options *opts_set,
393 location_t loc);
394 extern void default_options_optimization (struct gcc_options *opts,
395 struct gcc_options *opts_set,
396 struct cl_decoded_option *decoded_options,
397 unsigned int decoded_options_count,
398 location_t loc,
399 unsigned int lang_mask,
400 const struct cl_option_handlers *handlers,
401 diagnostic_context *dc);
402 extern void set_struct_debug_option (struct gcc_options *opts,
403 location_t loc,
404 const char *value);
405 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
406 int *value, unsigned int lang_mask);
407
408 extern const struct sanitizer_opts_s
409 {
410 const char *const name;
411 unsigned int flag;
412 size_t len;
413 } sanitizer_opts[];
414
415 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
416 const char *base_option);
417
418 #endif