]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/options.c
Merge tree-ssa-20020619-branch into mainline.
[thirdparty/gcc.git] / gcc / fortran / options.c
1 /* Parse and display command line options.
2 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
4
5 This file is part of GNU G95.
6
7 GNU G95 is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU G95 is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU G95; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tree.h"
29 #include "flags.h"
30 #include "intl.h"
31 #include "opts.h"
32 #include "options.h"
33 #include "tree-inline.h"
34
35 #include "gfortran.h"
36
37 gfc_option_t gfc_option;
38
39
40 /* Get ready for options handling. */
41
42 unsigned int
43 gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED,
44 const char **argv ATTRIBUTE_UNUSED)
45 {
46
47 gfc_option.source = NULL;
48 gfc_option.module_dir = NULL;
49 gfc_option.source_form = FORM_UNKNOWN;
50 gfc_option.fixed_line_length = 72;
51 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
52 gfc_option.verbose = 0;
53
54 gfc_option.warn_aliasing = 0;
55 gfc_option.warn_conversion = 0;
56 gfc_option.warn_implicit_interface = 0;
57 gfc_option.warn_line_truncation = 0;
58 gfc_option.warn_surprising = 0;
59 gfc_option.warn_unused_labels = 0;
60
61 gfc_option.flag_dollar_ok = 0;
62 gfc_option.flag_underscoring = 1;
63 gfc_option.flag_second_underscore = 1;
64 gfc_option.flag_implicit_none = 0;
65 gfc_option.flag_max_stack_var_size = 32768;
66 gfc_option.flag_module_access_private = 0;
67 gfc_option.flag_no_backend = 0;
68 gfc_option.flag_pack_derived = 0;
69 gfc_option.flag_repack_arrays = 0;
70
71 gfc_option.q_kind = gfc_default_double_kind ();
72 gfc_option.i8 = 0;
73 gfc_option.r8 = 0;
74 gfc_option.d8 = 0;
75
76 flag_argument_noalias = 2;
77
78 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
79 | GFC_STD_F2003_OBS | GFC_STD_F2003_DEL | GFC_STD_F2003 | GFC_STD_GNU;
80 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
81 | GFC_STD_F2003 | GFC_STD_GNU;
82
83 return CL_F95;
84 }
85
86
87 /* Finalize commandline options. */
88
89 bool
90 gfc_post_options (const char **pfilename)
91 {
92 const char *filename = *pfilename;
93
94 /* Verify the input file name. */
95 if (!filename || strcmp (filename, "-") == 0)
96 {
97 filename = "";
98 }
99
100 gfc_option.source = filename;
101
102 flag_inline_trees = 1;
103
104 /* Use tree inlining. */
105 if (!flag_no_inline)
106 flag_no_inline = 1;
107 if (flag_inline_functions)
108 {
109 flag_inline_trees = 2;
110 flag_inline_functions = 0;
111 }
112
113 return false;
114 }
115
116
117 /* Set the options for -Wall. */
118
119 static void
120 set_Wall (void)
121 {
122
123 gfc_option.warn_aliasing = 1;
124 gfc_option.warn_line_truncation = 1;
125 gfc_option.warn_surprising = 1;
126 gfc_option.warn_unused_labels = 1;
127
128 set_Wunused (1);
129 warn_return_type = 1;
130 warn_switch = 1;
131
132 /* We save the value of warn_uninitialized, since if they put
133 -Wuninitialized on the command line, we need to generate a
134 warning about not using it without also specifying -O. */
135
136 if (warn_uninitialized != 1)
137 warn_uninitialized = 2;
138 }
139
140
141 static void
142 gfc_handle_module_path_options (const char *arg)
143 {
144
145 if (gfc_option.module_dir != NULL)
146 {
147 gfc_status ("gfortran: Only one -M option allowed\n");
148 exit (3);
149 }
150
151 if (arg == NULL)
152 {
153 gfc_status ("gfortran: Directory required after -M\n");
154 exit (3);
155 }
156
157 gfc_option.module_dir = (char *) gfc_getmem (strlen (arg));
158 strcpy (gfc_option.module_dir, arg);
159 strcat (gfc_option.module_dir, "/");
160 }
161
162 /* Handle command-line options. Returns 0 if unrecognized, 1 if
163 recognized and handled. */
164 int
165 gfc_handle_option (size_t scode, const char *arg, int value)
166 {
167 int result = 1;
168 enum opt_code code = (enum opt_code) scode;
169
170 /* Ignore file names. */
171 if (code == N_OPTS)
172 return 1;
173
174 switch (code)
175 {
176 default:
177 result = 0;
178 break;
179
180 case OPT_Wall:
181 set_Wall ();
182 break;
183
184 case OPT_Waliasing:
185 gfc_option.warn_aliasing = value;
186 break;
187
188 case OPT_Wconversion:
189 gfc_option.warn_conversion = value;
190 break;
191
192 case OPT_Wimplicit_interface:
193 gfc_option.warn_implicit_interface = value;
194 break;
195
196 case OPT_Wline_truncation:
197 gfc_option.warn_line_truncation = value;
198 break;
199
200 case OPT_Wsurprising:
201 gfc_option.warn_surprising = value;
202 break;
203
204 case OPT_Wunused_labels:
205 gfc_option.warn_unused_labels = value;
206 break;
207
208 case OPT_fdollar_ok:
209 gfc_option.flag_dollar_ok = value;
210 break;
211
212 case OPT_fdump_parse_tree:
213 gfc_option.verbose = value;
214 break;
215
216 case OPT_ffixed_form:
217 gfc_option.source_form = FORM_FIXED;
218 break;
219
220 case OPT_ffree_form:
221 gfc_option.source_form = FORM_FREE;
222 break;
223
224 case OPT_funderscoring:
225 gfc_option.flag_underscoring = value;
226 break;
227
228 case OPT_fsecond_underscore:
229 gfc_option.flag_second_underscore = value;
230 break;
231
232 case OPT_fimplicit_none:
233 gfc_option.flag_implicit_none = value;
234 break;
235
236 case OPT_fmax_stack_var_size_:
237 gfc_option.flag_max_stack_var_size = value;
238 break;
239
240 case OPT_fmodule_private:
241 gfc_option.flag_module_access_private = value;
242 break;
243
244 case OPT_fno_backend:
245 gfc_option.flag_no_backend = value;
246 break;
247
248 case OPT_fpack_derived:
249 gfc_option.flag_pack_derived = value;
250 break;
251
252 case OPT_frepack_arrays:
253 gfc_option.flag_repack_arrays = value;
254 break;
255
256 case OPT_ffixed_line_length_80:
257 gfc_option.fixed_line_length = 80;
258 break;
259
260 case OPT_ffixed_line_length_132:
261 gfc_option.fixed_line_length = 132;
262 break;
263
264 case OPT_fmax_identifier_length_:
265 if (value > GFC_MAX_SYMBOL_LEN)
266 gfc_fatal_error ("Maximum supported idenitifier length is %d",
267 GFC_MAX_SYMBOL_LEN);
268 gfc_option.max_identifier_length = value;
269 break;
270
271 case OPT_qkind_:
272 if (gfc_validate_kind (BT_REAL, value) < 0)
273 gfc_fatal_error ("Argument to -fqkind isn't a valid real kind");
274 gfc_option.q_kind = value;
275 break;
276
277 case OPT_i8:
278 gfc_option.i8 = value;
279 break;
280
281 case OPT_r8:
282 gfc_option.r8 = value;
283 break;
284
285 case OPT_d8:
286 gfc_option.d8 = value;
287 break;
288
289 case OPT_I:
290 gfc_add_include_path (arg);
291 break;
292
293 case OPT_J:
294 case OPT_M:
295 gfc_handle_module_path_options (arg);
296
297 case OPT_std_f95:
298 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F2003_OBS
299 | GFC_STD_F2003_DEL;
300 gfc_option.warn_std = GFC_STD_F95_OBS;
301 gfc_option.max_identifier_length = 31;
302 break;
303
304 case OPT_std_f2003:
305 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F2003_OBS
306 | GFC_STD_F2003;
307 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2003_OBS;
308 gfc_option.max_identifier_length = 63;
309 break;
310
311 case OPT_std_gnu:
312 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
313 | GFC_STD_F2003_OBS | GFC_STD_F2003_DEL | GFC_STD_F2003 | GFC_STD_GNU;
314 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
315 | GFC_STD_F2003_OBS | GFC_STD_F2003_DEL | GFC_STD_GNU;
316 break;
317 }
318
319 return result;
320 }