opt-suggestions.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Provide suggestions to handle misspelled options, and implement the
  2. --complete option for auto-completing options from a prefix.
  3. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_OPT_PROPOSER_H
  17. #define GCC_OPT_PROPOSER_H
  18. /* Option proposer is class used by driver in order to provide hints
  19. for wrong options provided. And it's used by --complete option that's
  20. intended to be invoked by BASH in order to provide better option
  21. completion support. */
  22. class option_proposer
  23. {
  24. public:
  25. /* Default constructor. */
  26. option_proposer (): m_option_suggestions (NULL)
  27. {}
  28. /* Default destructor. */
  29. ~option_proposer ();
  30. /* Helper function for driver::handle_unrecognized_options.
  31. Given an unrecognized option BAD_OPT (without the leading dash),
  32. locate the closest reasonable matching option (again, without the
  33. leading dash), or NULL.
  34. The returned string is owned by the option_proposer instance. */
  35. const char *suggest_option (const char *bad_opt);
  36. /* Print on stdout a list of valid options that begin with OPTION_PREFIX,
  37. one per line, suitable for use by Bash completion.
  38. Implementation of the "-completion=" option. */
  39. void suggest_completion (const char *option_prefix);
  40. /* Populate RESULTS with valid completions of options that begin
  41. with OPTION_PREFIX. */
  42. void get_completions (const char *option_prefix, auto_string_vec &results);
  43. private:
  44. /* Helper function for option_proposer::suggest_option. Populate
  45. m_option_suggestions with candidate strings for misspelled options.
  46. The strings will be freed by the option_proposer's dtor.
  47. PREFIX is used for bash completion suggestions, otherwise
  48. it's set to NULL. */
  49. void build_option_suggestions (const char *prefix);
  50. /* Find parameter completions for --param format with SEPARATOR.
  51. Again, save the completions into results. */
  52. void find_param_completions (const char separator, const char *param_prefix,
  53. auto_string_vec &results);
  54. private:
  55. /* Cache with all suggestions. */
  56. auto_string_vec *m_option_suggestions;
  57. };
  58. #endif /* GCC_OPT_PROPOSER_H */