Mercurial > hg > CbC > CbC_gcc
comparison gcc/opt-suggestions.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Provide option suggestion for --complete option and a misspelled | 1 /* Provide option suggestion for --complete option and a misspelled |
2 used by a user. | 2 used by a user. |
3 Copyright (C) 2016-2018 Free Software Foundation, Inc. | 3 Copyright (C) 2016-2020 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify it under | 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 | 8 the terms of the GNU General Public License as published by the Free |
21 #include "config.h" | 21 #include "config.h" |
22 #include "system.h" | 22 #include "system.h" |
23 #include "coretypes.h" | 23 #include "coretypes.h" |
24 #include "tm.h" | 24 #include "tm.h" |
25 #include "opts.h" | 25 #include "opts.h" |
26 #include "params.h" | |
27 #include "spellcheck.h" | 26 #include "spellcheck.h" |
28 #include "opt-suggestions.h" | 27 #include "opt-suggestions.h" |
29 #include "common/common-target.h" | 28 #include "common/common-target.h" |
30 #include "selftest.h" | 29 #include "selftest.h" |
31 | 30 |
63 if (option_prefix[0] == '-') | 62 if (option_prefix[0] == '-') |
64 option_prefix++; | 63 option_prefix++; |
65 | 64 |
66 size_t length = strlen (option_prefix); | 65 size_t length = strlen (option_prefix); |
67 | 66 |
68 /* Handle OPTION_PREFIX starting with "-param". */ | 67 /* Lazily populate m_option_suggestions. */ |
69 const char *prefix = "-param"; | 68 if (!m_option_suggestions) |
70 if (length >= strlen (prefix) | 69 build_option_suggestions (option_prefix); |
71 && strstr (option_prefix, prefix) == option_prefix) | 70 gcc_assert (m_option_suggestions); |
71 | |
72 for (unsigned i = 0; i < m_option_suggestions->length (); i++) | |
72 { | 73 { |
73 /* We support both '-param-xyz=123' and '-param xyz=123' */ | 74 char *candidate = (*m_option_suggestions)[i]; |
74 option_prefix += strlen (prefix); | 75 if (strlen (candidate) >= length |
75 char separator = option_prefix[0]; | 76 && strstr (candidate, option_prefix) == candidate) |
76 option_prefix++; | 77 results.safe_push (concat ("-", candidate, NULL)); |
77 if (separator == ' ' || separator == '=') | |
78 find_param_completions (separator, option_prefix, results); | |
79 } | |
80 else | |
81 { | |
82 /* Lazily populate m_option_suggestions. */ | |
83 if (!m_option_suggestions) | |
84 build_option_suggestions (option_prefix); | |
85 gcc_assert (m_option_suggestions); | |
86 | |
87 for (unsigned i = 0; i < m_option_suggestions->length (); i++) | |
88 { | |
89 char *candidate = (*m_option_suggestions)[i]; | |
90 if (strlen (candidate) >= length | |
91 && strstr (candidate, option_prefix) == candidate) | |
92 results.safe_push (concat ("-", candidate, NULL)); | |
93 } | |
94 } | 78 } |
95 } | 79 } |
96 | 80 |
97 /* Print on stdout a list of valid options that begin with OPTION_PREFIX, | 81 /* Print on stdout a list of valid options that begin with OPTION_PREFIX, |
98 one per line, suitable for use by Bash completion. | 82 one per line, suitable for use by Bash completion. |
132 char *with_arg = concat (opt_text, e->values[j].arg, NULL); | 116 char *with_arg = concat (opt_text, e->values[j].arg, NULL); |
133 add_misspelling_candidates (m_option_suggestions, option, | 117 add_misspelling_candidates (m_option_suggestions, option, |
134 with_arg); | 118 with_arg); |
135 free (with_arg); | 119 free (with_arg); |
136 } | 120 } |
121 | |
122 /* Add also variant without an option argument. */ | |
123 add_misspelling_candidates (m_option_suggestions, option, | |
124 opt_text); | |
137 } | 125 } |
138 else | 126 else |
139 { | 127 { |
128 bool option_added = false; | |
140 if (option->flags & CL_TARGET) | 129 if (option->flags & CL_TARGET) |
141 { | 130 { |
142 vec<const char *> option_values | 131 vec<const char *> option_values |
143 = targetm_common.get_valid_option_values (i, prefix); | 132 = targetm_common.get_valid_option_values (i, prefix); |
144 if (!option_values.is_empty ()) | 133 if (!option_values.is_empty ()) |
145 { | 134 { |
135 option_added = true; | |
146 for (unsigned j = 0; j < option_values.length (); j++) | 136 for (unsigned j = 0; j < option_values.length (); j++) |
147 { | 137 { |
148 char *with_arg = concat (opt_text, option_values[j], | 138 char *with_arg = concat (opt_text, option_values[j], |
149 NULL); | 139 NULL); |
150 add_misspelling_candidates (m_option_suggestions, option, | 140 add_misspelling_candidates (m_option_suggestions, option, |
152 free (with_arg); | 142 free (with_arg); |
153 } | 143 } |
154 } | 144 } |
155 option_values.release (); | 145 option_values.release (); |
156 } | 146 } |
157 else | 147 |
148 if (!option_added) | |
158 add_misspelling_candidates (m_option_suggestions, option, | 149 add_misspelling_candidates (m_option_suggestions, option, |
159 opt_text); | 150 opt_text); |
160 } | 151 } |
161 break; | 152 break; |
162 | 153 |
170 "-sanitize=address" | 161 "-sanitize=address" |
171 to | 162 to |
172 "-fsanitize=address" | 163 "-fsanitize=address" |
173 rather than to "-Wframe-address" (PR driver/69265). */ | 164 rather than to "-Wframe-address" (PR driver/69265). */ |
174 { | 165 { |
166 /* Add also variant without an option argument. */ | |
167 add_misspelling_candidates (m_option_suggestions, option, | |
168 opt_text); | |
169 | |
175 for (int j = 0; sanitizer_opts[j].name != NULL; ++j) | 170 for (int j = 0; sanitizer_opts[j].name != NULL; ++j) |
176 { | 171 { |
177 struct cl_option optb; | 172 struct cl_option optb; |
178 /* -fsanitize=all is not valid, only -fno-sanitize=all. | 173 /* -fsanitize=all is not valid, only -fno-sanitize=all. |
179 So don't register the positive misspelling candidates | 174 So don't register the positive misspelling candidates |
197 free (with_arg); | 192 free (with_arg); |
198 } | 193 } |
199 } | 194 } |
200 break; | 195 break; |
201 } | 196 } |
202 } | |
203 } | |
204 | |
205 /* Find parameter completions for --param format with SEPARATOR. | |
206 Again, save the completions into results. */ | |
207 | |
208 void | |
209 option_proposer::find_param_completions (const char separator, | |
210 const char *param_prefix, | |
211 auto_string_vec &results) | |
212 { | |
213 char separator_str[] = {separator, '\0'}; | |
214 size_t length = strlen (param_prefix); | |
215 for (unsigned i = 0; i < get_num_compiler_params (); ++i) | |
216 { | |
217 const char *candidate = compiler_params[i].option; | |
218 if (strlen (candidate) >= length | |
219 && strstr (candidate, param_prefix) == candidate) | |
220 results.safe_push (concat ("--param", separator_str, candidate, NULL)); | |
221 } | 197 } |
222 } | 198 } |
223 | 199 |
224 #if CHECKING_P | 200 #if CHECKING_P |
225 | 201 |
294 "-Wmultiple-inheritance", | 270 "-Wmultiple-inheritance", |
295 "-fno-sel-sched-reschedule-pipelined", | 271 "-fno-sel-sched-reschedule-pipelined", |
296 "-Wassign-intercept", | 272 "-Wassign-intercept", |
297 "-Wno-format-security", | 273 "-Wno-format-security", |
298 "-fno-sched-stalled-insns", | 274 "-fno-sched-stalled-insns", |
299 "-fbtr-bb-exclusive", | |
300 "-fno-tree-tail-merge", | 275 "-fno-tree-tail-merge", |
301 "-Wlong-long", | 276 "-Wlong-long", |
302 "-Wno-unused-but-set-parameter", | 277 "-Wno-unused-but-set-parameter", |
303 NULL | 278 NULL |
304 }; | 279 }; |
389 ASSERT_TRUE (in_completion_p (proposer, "-fsani", | 364 ASSERT_TRUE (in_completion_p (proposer, "-fsani", |
390 "-fsanitize-address-use-after-scope")); | 365 "-fsanitize-address-use-after-scope")); |
391 ASSERT_TRUE (in_completion_p (proposer, "-fipa-icf", "-fipa-icf-functions")); | 366 ASSERT_TRUE (in_completion_p (proposer, "-fipa-icf", "-fipa-icf-functions")); |
392 ASSERT_TRUE (in_completion_p (proposer, "-fipa-icf", "-fipa-icf")); | 367 ASSERT_TRUE (in_completion_p (proposer, "-fipa-icf", "-fipa-icf")); |
393 ASSERT_TRUE (in_completion_p (proposer, "--param=", | 368 ASSERT_TRUE (in_completion_p (proposer, "--param=", |
394 "--param=max-vartrack-reverse-op-size")); | 369 "--param=max-vartrack-reverse-op-size=")); |
395 ASSERT_TRUE (in_completion_p (proposer, "--param ", | 370 ASSERT_TRUE (in_completion_p (proposer, "--param ", |
396 "--param max-vartrack-reverse-op-size")); | 371 "--param max-vartrack-reverse-op-size=")); |
397 | 372 |
398 ASSERT_FALSE (in_completion_p (proposer, "-fipa-icf", "-fipa")); | 373 ASSERT_FALSE (in_completion_p (proposer, "-fipa-icf", "-fipa")); |
399 ASSERT_FALSE (in_completion_p (proposer, "-fipa-icf-functions", "-fipa-icf")); | 374 ASSERT_FALSE (in_completion_p (proposer, "-fipa-icf-functions", "-fipa-icf")); |
400 | 375 |
401 ASSERT_FALSE (empty_completion_p (proposer, "-")); | 376 ASSERT_FALSE (empty_completion_p (proposer, "-")); |