OSDN Git Service

* doc/options.texi (NegativeAlias): Document.
[pf3gnuchains/gcc-fork.git] / gcc / opts.h
1 /* Command line option handling.
2    Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #ifndef GCC_OPTS_H
22 #define GCC_OPTS_H
23
24 #include "input.h"
25 #include "vec.h"
26
27 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR.  */
28 enum cl_var_type {
29   /* The switch is enabled when FLAG_VAR is nonzero.  */
30   CLVC_BOOLEAN,
31
32   /* The switch is enabled when FLAG_VAR == VAR_VALUE.  */
33   CLVC_EQUAL,
34
35   /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR.  */
36   CLVC_BIT_CLEAR,
37
38   /* The switch is enabled when VAR_VALUE is set in FLAG_VAR.  */
39   CLVC_BIT_SET,
40
41   /* The switch takes a string argument and FLAG_VAR points to that
42      argument.  */
43   CLVC_STRING,
44
45   /* The switch takes an enumerated argument (VAR_ENUM says what
46      enumeration) and FLAG_VAR points to that argument.  */
47   CLVC_ENUM,
48
49   /* The switch should be stored in the VEC pointed to by FLAG_VAR for
50      later processing.  */
51   CLVC_DEFER
52 };
53
54 struct cl_option
55 {
56   const char *opt_text;
57   const char *help;
58   const char *missing_argument_error;
59   const char *warn_message;
60   const char *alias_arg;
61   const char *neg_alias_arg;
62   unsigned short alias_target;
63   unsigned short back_chain;
64   unsigned char opt_len;
65   int neg_index;
66   unsigned int flags;
67   unsigned short flag_var_offset;
68   unsigned short var_enum;
69   enum cl_var_type var_type;
70   int var_value;
71 };
72
73 /* Records that the state of an option consists of SIZE bytes starting
74    at DATA.  DATA might point to CH in some cases.  */
75 struct cl_option_state {
76   const void *data;
77   size_t size;
78   char ch;
79 };
80
81 extern const struct cl_option cl_options[];
82 extern const unsigned int cl_options_count;
83 extern const char *const lang_names[];
84 extern const unsigned int cl_lang_count;
85
86 #define CL_PARAMS               (1U << 11) /* Fake entry.  Used to display --param info with --help.  */
87 #define CL_WARNING              (1U << 12) /* Enables an (optional) warning message.  */
88 #define CL_OPTIMIZATION         (1U << 13) /* Enables an (optional) optimization.  */
89 #define CL_DRIVER               (1U << 14) /* Driver option.  */
90 #define CL_TARGET               (1U << 15) /* Target-specific option.  */
91 #define CL_COMMON               (1U << 16) /* Language-independent.  */
92
93 #define CL_MIN_OPTION_CLASS     CL_PARAMS
94 #define CL_MAX_OPTION_CLASS     CL_COMMON
95
96 /* From here on the bits describe attributes of the options.
97    Before this point the bits have described the class of the option.
98    This distinction is important because --help will not list options
99    which only have these higher bits set.  */
100
101 /* Options marked with CL_SEPARATE take a number of separate arguments
102    (1 to 4) that is one more than the number in this bit-field.  */
103 #define CL_SEPARATE_NARGS_SHIFT 17
104 #define CL_SEPARATE_NARGS_MASK  (3U << CL_SEPARATE_NARGS_SHIFT)
105
106 #define CL_SEPARATE_ALIAS       (1U << 19) /* Option is an alias when used with separate argument.  */
107 #define CL_NO_DRIVER_ARG        (1U << 20) /* Option takes no argument in the driver.  */
108 #define CL_REJECT_DRIVER        (1U << 21) /* Reject this option in the driver.  */
109 #define CL_SAVE                 (1U << 22) /* Target-specific option for attribute.  */
110 #define CL_DISABLED             (1U << 23) /* Disabled in this configuration.  */
111 #define CL_REPORT               (1U << 24) /* Report argument with -fverbose-asm  */
112 #define CL_JOINED               (1U << 25) /* If takes joined argument.  */
113 #define CL_SEPARATE             (1U << 26) /* If takes a separate argument.  */
114 #define CL_REJECT_NEGATIVE      (1U << 27) /* Reject no- form.  */
115 #define CL_MISSING_OK           (1U << 28) /* Missing argument OK (joined).  */
116 #define CL_UINTEGER             (1U << 29) /* Argument is an integer >=0.  */
117 #define CL_UNDOCUMENTED         (1U << 30) /* Do not output with --help.  */
118 #define CL_NEGATIVE_ALIAS       (1U << 31) /* Alias to negative form of option.  */
119
120 /* Flags for an enumerated option argument.  */
121 #define CL_ENUM_CANONICAL       (1 << 0) /* Canonical for this value.  */
122 #define CL_ENUM_DRIVER_ONLY     (1 << 1) /* Only accepted in the driver.  */
123
124 /* Structure describing an enumerated option argument.  */
125
126 struct cl_enum_arg
127 {
128   /* The argument text, or NULL at the end of the array.  */
129   const char *arg;
130
131   /* The corresponding integer value.  */
132   int value;
133
134   /* Flags associated with this argument.  */
135   unsigned int flags;
136 };
137
138 /* Structure describing an enumerated set of option arguments.  */
139
140 struct cl_enum
141 {
142   /* Help text, or NULL if the values should not be listed in --help
143      output.  */
144   const char *help;
145
146   /* Error message for unknown arguments, or NULL to use a generic
147      error.  */
148   const char *unknown_error;
149
150   /* Array of possible values.  */
151   const struct cl_enum_arg *values;
152
153   /* The size of the type used to store a value.  */
154   size_t var_size;
155
156   /* Function to set a variable of this type.  */
157   void (*set) (void *var, int value);
158
159   /* Function to get the value of a variable of this type.  */
160   int (*get) (const void *var);
161 };
162
163 extern const struct cl_enum cl_enums[];
164 extern const unsigned int cl_enums_count;
165
166 /* Possible ways in which a command-line option may be erroneous.
167    These do not include not being known at all; an option index of
168    OPT_SPECIAL_unknown is used for that.  */
169
170 #define CL_ERR_DISABLED         (1 << 0) /* Disabled in this configuration.  */
171 #define CL_ERR_MISSING_ARG      (1 << 1) /* Argument required but missing.  */
172 #define CL_ERR_WRONG_LANG       (1 << 2) /* Option for wrong language.  */
173 #define CL_ERR_UINT_ARG         (1 << 3) /* Bad unsigned integer argument.  */
174 #define CL_ERR_ENUM_ARG         (1 << 4) /* Bad enumerated argument.  */
175 #define CL_ERR_NEGATIVE         (1 << 5) /* Negative form of option
176                                             not permitted (together
177                                             with OPT_SPECIAL_unknown).  */
178
179 /* Structure describing the result of decoding an option.  */
180
181 struct cl_decoded_option
182 {
183   /* The index of this option, or an OPT_SPECIAL_* value for
184      non-options and unknown options.  */
185   size_t opt_index;
186
187   /* Any warning to give for use of this option, or NULL if none.  */
188   const char *warn_message;
189
190   /* The string argument, or NULL if none.  For OPT_SPECIAL_* cases,
191      the option or non-option command-line argument.  */
192   const char *arg;
193
194   /* The original text of option plus arguments, with separate argv
195      elements concatenated into one string with spaces separating
196      them.  This is for such uses as diagnostics and
197      -frecord-gcc-switches.  */
198   const char *orig_option_with_args_text;
199
200   /* The canonical form of the option and its argument, for when it is
201      necessary to reconstruct argv elements (in particular, for
202      processing specs and passing options to subprocesses from the
203      driver).  */
204   const char *canonical_option[4];
205
206   /* The number of elements in the canonical form of the option and
207      arguments; always at least 1.  */
208   size_t canonical_option_num_elements;
209
210   /* For a boolean option, 1 for the true case and 0 for the "no-"
211      case.  For an unsigned integer option, the value of the
212      argument.  1 in all other cases.  */
213   int value;
214
215   /* Any flags describing errors detected in this option.  */
216   int errors;
217 };
218
219 /* Structure describing an option deferred for handling after the main
220    option handlers.  */
221
222 typedef struct
223 {
224   /* Elements from struct cl_decoded_option used for deferred
225      options.  */
226   size_t opt_index;
227   const char *arg;
228   int value;
229 } cl_deferred_option;
230 DEF_VEC_O(cl_deferred_option);
231 DEF_VEC_ALLOC_O(cl_deferred_option,heap);
232
233 /* Structure describing a single option-handling callback.  */
234
235 struct cl_option_handler_func
236 {
237   /* The function called to handle the option.  */
238   bool (*handler) (struct gcc_options *opts,
239                    struct gcc_options *opts_set,
240                    const struct cl_decoded_option *decoded,
241                    unsigned int lang_mask, int kind, location_t loc,
242                    const struct cl_option_handlers *handlers,
243                    diagnostic_context *dc);
244
245   /* The mask that must have some bit in common with the flags for the
246      option for this particular handler to be used.  */
247   unsigned int mask;
248 };
249
250 /* Structure describing the callbacks used in handling options.  */
251
252 struct cl_option_handlers
253 {
254   /* Callback for an unknown option to determine whether to give an
255      error for it, and possibly store information to diagnose the
256      option at a later point.  Return true if an error should be
257      given, false otherwise.  */
258   bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
259
260   /* Callback to handle, and possibly diagnose, an option for another
261      language.  */
262   void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
263                                unsigned int lang_mask);
264
265   /* Callback to call after the successful handling of any option.  */
266   void (*post_handling_callback) (const struct cl_decoded_option *decoded,
267                                   unsigned int mask);
268
269   /* The number of individual handlers.  */
270   size_t num_handlers;
271
272   /* The handlers themselves.  */
273   struct cl_option_handler_func handlers[3];
274 };
275
276 /* Input file names.  */
277
278 extern const char **in_fnames;
279
280 /* The count of input filenames.  */
281
282 extern unsigned num_in_fnames;
283
284 size_t find_opt (const char *input, unsigned int lang_mask);
285 extern int integral_argument (const char *arg);
286 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
287                                const char **argp, int value,
288                                unsigned int lang_mask);
289 extern void decode_cmdline_options_to_array (unsigned int argc,
290                                              const char **argv, 
291                                              unsigned int lang_mask,
292                                              struct cl_decoded_option **decoded_options,
293                                              unsigned int *decoded_options_count);
294 extern void init_options_once (void);
295 extern void init_options_struct (struct gcc_options *opts,
296                                  struct gcc_options *opts_set);
297 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
298                                                           const char **argv, 
299                                                           struct cl_decoded_option **decoded_options,
300                                                           unsigned int *decoded_options_count);
301 extern void set_default_handlers (struct cl_option_handlers *handlers);
302 extern void decode_options (struct gcc_options *opts,
303                             struct gcc_options *opts_set,
304                             struct cl_decoded_option *decoded_options,
305                             unsigned int decoded_options_count,
306                             location_t loc,
307                             diagnostic_context *dc);
308 extern int option_enabled (int opt_idx, void *opts);
309 extern bool get_option_state (struct gcc_options *, int,
310                               struct cl_option_state *);
311 extern void set_option (struct gcc_options *opts,
312                         struct gcc_options *opts_set,
313                         int opt_index, int value, const char *arg, int kind,
314                         location_t loc, diagnostic_context *dc);
315 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
316 bool handle_generated_option (struct gcc_options *opts,
317                               struct gcc_options *opts_set,
318                               size_t opt_index, const char *arg, int value,
319                               unsigned int lang_mask, int kind, location_t loc,
320                               const struct cl_option_handlers *handlers,
321                               diagnostic_context *dc);
322 void generate_option (size_t opt_index, const char *arg, int value,
323                       unsigned int lang_mask,
324                       struct cl_decoded_option *decoded);
325 void generate_option_input_file (const char *file,
326                                  struct cl_decoded_option *decoded);
327 extern void read_cmdline_option (struct gcc_options *opts,
328                                  struct gcc_options *opts_set,
329                                  struct cl_decoded_option *decoded,
330                                  location_t loc,
331                                  unsigned int lang_mask,
332                                  const struct cl_option_handlers *handlers,
333                                  diagnostic_context *dc);
334 extern void control_warning_option (unsigned int opt_index, int kind,
335                                     bool imply, location_t loc,
336                                     unsigned int lang_mask,
337                                     const struct cl_option_handlers *handlers,
338                                     struct gcc_options *opts,
339                                     struct gcc_options *opts_set,
340                                     diagnostic_context *dc);
341 extern void print_ignored_options (void);
342 extern void handle_common_deferred_options (void);
343 extern bool common_handle_option (struct gcc_options *opts,
344                                   struct gcc_options *opts_set,
345                                   const struct cl_decoded_option *decoded,
346                                   unsigned int lang_mask, int kind,
347                                   location_t loc,
348                                   const struct cl_option_handlers *handlers,
349                                   diagnostic_context *dc);
350 extern bool target_handle_option (struct gcc_options *opts,
351                                   struct gcc_options *opts_set,
352                                   const struct cl_decoded_option *decoded,
353                                   unsigned int lang_mask, int kind,
354                                   location_t loc,
355                                   const struct cl_option_handlers *handlers,
356                                   diagnostic_context *dc);
357 extern void finish_options (struct gcc_options *opts,
358                             struct gcc_options *opts_set,
359                             location_t loc);
360 extern void default_options_optimization (struct gcc_options *opts,
361                                           struct gcc_options *opts_set,
362                                           struct cl_decoded_option *decoded_options,
363                                           unsigned int decoded_options_count,
364                                           location_t loc,
365                                           unsigned int lang_mask,
366                                           const struct cl_option_handlers *handlers,
367                                           diagnostic_context *dc);
368 extern void set_struct_debug_option (struct gcc_options *opts,
369                                      location_t loc,
370                                      const char *value);
371 #endif