complain.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Declaration for error-reporting function for Bison.
  2. Copyright (C) 2000-2002, 2006, 2009-2015, 2018-2021 Free Software
  3. Foundation, Inc.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #ifndef COMPLAIN_H_
  15. # define COMPLAIN_H_ 1
  16. # include <attribute.h>
  17. # include "location.h"
  18. /*---------------.
  19. | Error stream. |
  20. `---------------*/
  21. /** Enable a style on \a out provided it's stderr. */
  22. void begin_use_class (const char *style, FILE *out);
  23. /** Disable a style on \a out provided it's stderr. */
  24. void end_use_class (const char *style, FILE *out);
  25. /** Flush \a out. */
  26. void flush (FILE *out);
  27. /** Whether there's styling on OUT. */
  28. bool is_styled (FILE *out);
  29. /*-------------.
  30. | --warnings. |
  31. `-------------*/
  32. /** The bits assigned to each warning type. */
  33. typedef enum
  34. {
  35. warning_conflicts_rr,
  36. warning_conflicts_sr,
  37. warning_counterexamples,
  38. warning_dangling_alias,
  39. warning_deprecated,
  40. warning_empty_rule,
  41. warning_midrule_values,
  42. warning_other,
  43. warning_precedence,
  44. warning_yacc, /**< POSIXME. */
  45. warnings_size /**< The number of warnings. Must be last. */
  46. } warning_bit;
  47. /** Whether -Werror was set. */
  48. extern bool warnings_are_errors;
  49. /** Document --warning arguments. */
  50. void warning_usage (FILE *out);
  51. /** Decode a single argument from -W.
  52. *
  53. * \param arg the subarguments to decode.
  54. * If null, then activate all the flags.
  55. * \param no length of the potential "no-" prefix.
  56. * Can be 0 or 3. If 3, negate the action of the subargument.
  57. * \param err length of a potential "error=".
  58. * Can be 0 or 6. If 6, treat the subargument as a CATEGORY.
  59. *
  60. * If VALUE != 0 then KEY sets flags and no-KEY clears them.
  61. * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
  62. * flags from \c all. Thus no-none = all and no-all = none.
  63. */
  64. void warning_argmatch (char const *arg, size_t no, size_t err);
  65. /** Decode a comma-separated list of arguments from -W.
  66. *
  67. * \param args comma separated list of effective subarguments to decode.
  68. * If 0, then activate all the flags.
  69. */
  70. void warnings_argmatch (char *args);
  71. /*-----------.
  72. | complain. |
  73. `-----------*/
  74. /** Initialize this module. */
  75. void complain_init (void);
  76. /** Reclaim resources. */
  77. void complain_free (void);
  78. /** Initialize support for colored messages. */
  79. void complain_init_color (void);
  80. /** Flags passed to diagnostics functions. */
  81. typedef enum
  82. {
  83. Wnone = 0, /**< Issue no warnings. */
  84. Wconflicts_rr = 1 << warning_conflicts_rr,
  85. Wconflicts_sr = 1 << warning_conflicts_sr,
  86. Wcounterexamples = 1 << warning_counterexamples,
  87. Wdangling_alias = 1 << warning_dangling_alias,
  88. Wdeprecated = 1 << warning_deprecated,
  89. Wempty_rule = 1 << warning_empty_rule,
  90. Wmidrule_values = 1 << warning_midrule_values,
  91. Wother = 1 << warning_other,
  92. Wprecedence = 1 << warning_precedence,
  93. Wyacc = 1 << warning_yacc,
  94. complaint = 1 << 11, /**< All complaints. */
  95. fatal = 1 << 12, /**< All fatal errors. */
  96. silent = 1 << 13, /**< Do not display the warning type. */
  97. no_caret = 1 << 14, /**< Do not display caret location. */
  98. note = 1 << 15, /**< Display as a note. */
  99. /**< All above warnings. */
  100. Weverything = ~complaint & ~fatal & ~silent,
  101. Wall = Weverything & ~Wcounterexamples & ~Wdangling_alias & ~Wyacc
  102. } warnings;
  103. /** Whether the warnings of \a flags are all unset.
  104. (Never enabled, never disabled). */
  105. bool warning_is_unset (warnings flags);
  106. /** Whether warnings of \a flags should be reported. */
  107. bool warning_is_enabled (warnings flags);
  108. /** Make a complaint, with maybe a location. */
  109. void complain (location const *loc, warnings flags, char const *message, ...)
  110. ATTRIBUTE_FORMAT ((__printf__, 3, 4));
  111. /** Likewise, but with an \a argc/argv interface. */
  112. void complain_args (location const *loc, warnings w,
  113. int argc, char *arg[]);
  114. /** Make a subcomplain with location and note. */
  115. void subcomplain (location const *loc, warnings flags,
  116. char const *message, ...)
  117. ATTRIBUTE_FORMAT ((__printf__, 3, 4));
  118. /** GNU Bison extension not valid with POSIX Yacc. */
  119. void bison_directive (location const *loc, char const *directive);
  120. /** Report an obsolete syntax, suggest the updated one. */
  121. void deprecated_directive (location const *loc,
  122. char const *obsolete, char const *updated);
  123. /** Report a repeated directive. */
  124. void duplicate_directive (char const *directive,
  125. location first, location second);
  126. /** Report a repeated directive for a rule. */
  127. void duplicate_rule_directive (char const *directive,
  128. location first, location second);
  129. /** Report a syntax error, where argv[0] is the unexpected
  130. token, and argv[1...argc] are the expected ones. */
  131. void syntax_error (location loc,
  132. int argc, const char* argv[]);
  133. /** Warnings treated as errors shouldn't stop the execution as regular
  134. errors should (because due to their nature, it is safe to go
  135. on). Thus, there are three possible execution statuses. */
  136. typedef enum
  137. {
  138. status_none, /**< No diagnostic issued so far. */
  139. status_warning_as_error, /**< A warning was issued (but no error). */
  140. status_complaint /**< An error was issued. */
  141. } err_status;
  142. /** Whether an error was reported. */
  143. extern err_status complaint_status;
  144. #endif /* !COMPLAIN_H_ */