Line data Source code
1 : /* Provide suggestions to handle misspelled options, and implement the
2 : --complete option for auto-completing options from a prefix.
3 : Copyright (C) 2016-2026 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_OPT_PROPOSER_H
22 : #define GCC_OPT_PROPOSER_H
23 :
24 : /* Option proposer is class used by driver in order to provide hints
25 : for wrong options provided. And it's used by --complete option that's
26 : intended to be invoked by BASH in order to provide better option
27 : completion support. */
28 :
29 : class option_proposer
30 : {
31 : public:
32 : /* Default constructor. */
33 294002 : option_proposer (): m_option_suggestions (NULL)
34 : {}
35 :
36 : /* Default destructor. */
37 : ~option_proposer ();
38 :
39 : /* Helper function for driver::handle_unrecognized_options.
40 :
41 : Given an unrecognized option BAD_OPT (without the leading dash),
42 : locate the closest reasonable matching option (again, without the
43 : leading dash), or NULL.
44 :
45 : The returned string is owned by the option_proposer instance. */
46 : const char *suggest_option (const char *bad_opt);
47 :
48 : /* Print on stdout a list of valid options that begin with OPTION_PREFIX,
49 : one per line, suitable for use by Bash completion.
50 :
51 : Implementation of the "-completion=" option. */
52 : void suggest_completion (const char *option_prefix);
53 :
54 : /* Populate RESULTS with valid completions of options that begin
55 : with OPTION_PREFIX. */
56 : void get_completions (const char *option_prefix, auto_string_vec &results);
57 :
58 : private:
59 : /* Helper function for option_proposer::suggest_option. Populate
60 : m_option_suggestions with candidate strings for misspelled options.
61 : The strings will be freed by the option_proposer's dtor.
62 : PREFIX is used for bash completion suggestions, otherwise
63 : it's set to NULL. */
64 : void build_option_suggestions (const char *prefix);
65 :
66 : private:
67 : /* Cache with all suggestions. */
68 : auto_string_vec *m_option_suggestions;
69 : };
70 :
71 : #endif /* GCC_OPT_PROPOSER_H */
|