DiagnosticOptions.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- DiagnosticOptions.h --------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
  14. #define LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
  15. #include "clang/Basic/LLVM.h"
  16. #include "llvm/ADT/IntrusiveRefCntPtr.h"
  17. #include <string>
  18. #include <type_traits>
  19. #include <vector>
  20. namespace llvm {
  21. namespace opt {
  22. class ArgList;
  23. } // namespace opt
  24. } // namespace llvm
  25. namespace clang {
  26. class DiagnosticsEngine;
  27. /// Specifies which overload candidates to display when overload
  28. /// resolution fails.
  29. enum OverloadsShown : unsigned {
  30. /// Show all overloads.
  31. Ovl_All,
  32. /// Show just the "best" overload candidates.
  33. Ovl_Best
  34. };
  35. /// A bitmask representing the diagnostic levels used by
  36. /// VerifyDiagnosticConsumer.
  37. enum class DiagnosticLevelMask : unsigned {
  38. None = 0,
  39. Note = 1 << 0,
  40. Remark = 1 << 1,
  41. Warning = 1 << 2,
  42. Error = 1 << 3,
  43. All = Note | Remark | Warning | Error
  44. };
  45. inline DiagnosticLevelMask operator~(DiagnosticLevelMask M) {
  46. using UT = std::underlying_type<DiagnosticLevelMask>::type;
  47. return static_cast<DiagnosticLevelMask>(~static_cast<UT>(M));
  48. }
  49. inline DiagnosticLevelMask operator|(DiagnosticLevelMask LHS,
  50. DiagnosticLevelMask RHS) {
  51. using UT = std::underlying_type<DiagnosticLevelMask>::type;
  52. return static_cast<DiagnosticLevelMask>(
  53. static_cast<UT>(LHS) | static_cast<UT>(RHS));
  54. }
  55. inline DiagnosticLevelMask operator&(DiagnosticLevelMask LHS,
  56. DiagnosticLevelMask RHS) {
  57. using UT = std::underlying_type<DiagnosticLevelMask>::type;
  58. return static_cast<DiagnosticLevelMask>(
  59. static_cast<UT>(LHS) & static_cast<UT>(RHS));
  60. }
  61. raw_ostream& operator<<(raw_ostream& Out, DiagnosticLevelMask M);
  62. /// Options for controlling the compiler diagnostics engine.
  63. class DiagnosticOptions : public RefCountedBase<DiagnosticOptions>{
  64. friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
  65. clang::DiagnosticsEngine *, bool);
  66. friend class CompilerInvocation;
  67. public:
  68. enum TextDiagnosticFormat { Clang, MSVC, Vi };
  69. // Default values.
  70. enum {
  71. DefaultTabStop = 8,
  72. MaxTabStop = 100,
  73. DefaultMacroBacktraceLimit = 6,
  74. DefaultTemplateBacktraceLimit = 10,
  75. DefaultConstexprBacktraceLimit = 10,
  76. DefaultSpellCheckingLimit = 50,
  77. DefaultSnippetLineLimit = 1,
  78. };
  79. // Define simple diagnostic options (with no accessors).
  80. #define DIAGOPT(Name, Bits, Default) unsigned Name : Bits;
  81. #define ENUM_DIAGOPT(Name, Type, Bits, Default)
  82. #include "clang/Basic/DiagnosticOptions.def"
  83. protected:
  84. // Define diagnostic options of enumeration type. These are private, and will
  85. // have accessors (below).
  86. #define DIAGOPT(Name, Bits, Default)
  87. #define ENUM_DIAGOPT(Name, Type, Bits, Default) unsigned Name : Bits;
  88. #include "clang/Basic/DiagnosticOptions.def"
  89. public:
  90. /// The file to log diagnostic output to.
  91. std::string DiagnosticLogFile;
  92. /// The file to serialize diagnostics to (non-appending).
  93. std::string DiagnosticSerializationFile;
  94. /// The list of -W... options used to alter the diagnostic mappings, with the
  95. /// prefixes removed.
  96. std::vector<std::string> Warnings;
  97. /// The list of prefixes from -Wundef-prefix=... used to generate warnings
  98. /// for undefined macros.
  99. std::vector<std::string> UndefPrefixes;
  100. /// The list of -R... options used to alter the diagnostic mappings, with the
  101. /// prefixes removed.
  102. std::vector<std::string> Remarks;
  103. /// The prefixes for comment directives sought by -verify ("expected" by
  104. /// default).
  105. std::vector<std::string> VerifyPrefixes;
  106. public:
  107. // Define accessors/mutators for diagnostic options of enumeration type.
  108. #define DIAGOPT(Name, Bits, Default)
  109. #define ENUM_DIAGOPT(Name, Type, Bits, Default) \
  110. Type get##Name() const { return static_cast<Type>(Name); } \
  111. void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
  112. #include "clang/Basic/DiagnosticOptions.def"
  113. DiagnosticOptions() {
  114. #define DIAGOPT(Name, Bits, Default) Name = Default;
  115. #define ENUM_DIAGOPT(Name, Type, Bits, Default) set##Name(Default);
  116. #include "clang/Basic/DiagnosticOptions.def"
  117. }
  118. };
  119. using TextDiagnosticFormat = DiagnosticOptions::TextDiagnosticFormat;
  120. } // namespace clang
  121. #endif // LLVM_CLANG_BASIC_DIAGNOSTICOPTIONS_H
  122. #ifdef __GNUC__
  123. #pragma GCC diagnostic pop
  124. #endif