1 /* Provide suggestions to handle misspelled options, and implement the
2 --complete option for auto-completing options from a prefix.
3 Copyright (C) 2016-2023 Free Software Foundation, Inc.
5 This file is part of GCC.
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
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
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/>. */
21 #ifndef GCC_OPT_PROPOSER_H
22 #define GCC_OPT_PROPOSER_H
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. */
32 /* Default constructor. */
33 option_proposer (): m_option_suggestions (NULL
)
36 /* Default destructor. */
39 /* Helper function for driver::handle_unrecognized_options.
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.
45 The returned string is owned by the option_proposer instance. */
46 const char *suggest_option (const char *bad_opt
);
48 /* Print on stdout a list of valid options that begin with OPTION_PREFIX,
49 one per line, suitable for use by Bash completion.
51 Implementation of the "-completion=" option. */
52 void suggest_completion (const char *option_prefix
);
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
);
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
64 void build_option_suggestions (const char *prefix
);
67 /* Cache with all suggestions. */
68 auto_string_vec
*m_option_suggestions
;
71 #endif /* GCC_OPT_PROPOSER_H */