1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===--- DiagnosticIDs.h - Diagnostic IDs Handling --------------*- C++ -*-===//
2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//                     The LLVM Compiler Infrastructure
4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source
6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details.
7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot///
10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// \file
11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// \brief Defines the Diagnostic IDs-related interfaces.
12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot///
13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_CLANG_BASIC_DIAGNOSTICIDS_H
16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_CLANG_BASIC_DIAGNOSTICIDS_H
17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Basic/LLVM.h"
19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/IntrusiveRefCntPtr.h"
20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/StringRef.h"
21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace clang {
23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class DiagnosticsEngine;
24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class SourceLocation;
25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Import the diagnostic enums themselves.
27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  namespace diag {
28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // Start position for diagnostics.
29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    enum {
30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_COMMON        =                                 0,
31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_DRIVER        = DIAG_START_COMMON          +  300,
32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_FRONTEND      = DIAG_START_DRIVER          +  200,
33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_SERIALIZATION = DIAG_START_FRONTEND        +  100,
34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_LEX           = DIAG_START_SERIALIZATION   +  120,
35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_PARSE         = DIAG_START_LEX             +  400,
36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_AST           = DIAG_START_PARSE           +  500,
37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_COMMENT       = DIAG_START_AST             +  110,
38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_SEMA          = DIAG_START_COMMENT         +  100,
39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_START_ANALYSIS      = DIAG_START_SEMA            + 3500,
40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      DIAG_UPPER_LIMIT         = DIAG_START_ANALYSIS        +  100
41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    };
42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    class CustomDiagInfo;
44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief All of the diagnostics that can be emitted by the frontend.
46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    typedef unsigned kind;
47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    // Get typedefs for common diagnostics.
49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    enum {
50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\
51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot             SFINAE,CATEGORY,NOWERROR,SHOWINSYSHEADER) ENUM,
52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define COMMONSTART
53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Basic/DiagnosticCommonKinds.inc"
54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      NUM_BUILTIN_COMMON_DIAGNOSTICS
55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#undef DIAG
56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    };
57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// to either Ignore (nothing), Remark (emit a remark), Warning
60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// (emit a warning) or Error (emit as an error).  It allows clients to
61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// map ERRORs to Error or Fatal (stop emitting diagnostics after this one).
62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    enum class Severity {
63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      // NOTE: 0 means "uncomputed".
64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Ignored = 1, ///< Do not present this diagnostic, ignore it.
65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Remark = 2,  ///< Present this diagnostic as a remark.
66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Warning = 3, ///< Present this diagnostic as a warning.
67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Error = 4,   ///< Present this diagnostic as an error.
68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Fatal = 5    ///< Present this diagnostic as a fatal error.
69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    };
70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Flavors of diagnostics we can emit. Used to filter for a particular
72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// kind of diagnostic (for instance, for -W/-R flags).
73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    enum class Flavor {
74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      WarningOrError, ///< A diagnostic that indicates a problem or potential
75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                      ///< problem. Can be made fatal by -Werror.
76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Remark          ///< A diagnostic that indicates normal progress through
77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                      ///< compilation.
78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    };
79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass DiagnosticMapping {
82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned Severity : 3;
83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned IsUser : 1;
84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned IsPragma : 1;
85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned HasNoWarningAsError : 1;
86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned HasNoErrorAsFatal : 1;
87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned WasUpgradedFromWarning : 1;
88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static DiagnosticMapping Make(diag::Severity Severity, bool IsUser,
91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                bool IsPragma) {
92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DiagnosticMapping Result;
93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.Severity = (unsigned)Severity;
94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.IsUser = IsUser;
95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.IsPragma = IsPragma;
96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.HasNoWarningAsError = 0;
97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.HasNoErrorAsFatal = 0;
98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.WasUpgradedFromWarning = 0;
99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return Result;
100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  diag::Severity getSeverity() const { return (diag::Severity)Severity; }
103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setSeverity(diag::Severity Value) { Severity = (unsigned)Value; }
104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isUser() const { return IsUser; }
106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isPragma() const { return IsPragma; }
107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isErrorOrFatal() const {
109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return getSeverity() == diag::Severity::Error ||
110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           getSeverity() == diag::Severity::Fatal;
111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool hasNoWarningAsError() const { return HasNoWarningAsError; }
114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setNoWarningAsError(bool Value) { HasNoWarningAsError = Value; }
115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool hasNoErrorAsFatal() const { return HasNoErrorAsFatal; }
117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setNoErrorAsFatal(bool Value) { HasNoErrorAsFatal = Value; }
118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Whether this mapping attempted to map the diagnostic to a warning, but
120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// was overruled because the diagnostic was already mapped to an error or
121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// fatal error.
122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool wasUpgradedFromWarning() const { return WasUpgradedFromWarning; }
123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setUpgradedFromWarning(bool Value) { WasUpgradedFromWarning = Value; }
124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Serialize this mapping as a raw integer.
126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned serialize() const {
127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return (IsUser << 7) | (IsPragma << 6) | (HasNoWarningAsError << 5) |
128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot           (HasNoErrorAsFatal << 4) | (WasUpgradedFromWarning << 3) | Severity;
129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Deserialize a mapping.
131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static DiagnosticMapping deserialize(unsigned Bits) {
132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DiagnosticMapping Result;
133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.IsUser = (Bits >> 7) & 1;
134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.IsPragma = (Bits >> 6) & 1;
135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.HasNoWarningAsError = (Bits >> 5) & 1;
136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.HasNoErrorAsFatal = (Bits >> 4) & 1;
137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.WasUpgradedFromWarning = (Bits >> 3) & 1;
138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Result.Severity = Bits & 0x7;
139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return Result;
140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// \brief Used for handling and querying diagnostic IDs.
144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot///
145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// Can be used and shared by multiple Diagnostics for multiple translation units.
146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The level of the diagnostic, after it has been through mapping.
149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  enum Level {
150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    Ignored, Note, Remark, Warning, Error, Fatal
151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Information for uniquing and looking up custom diags.
155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  diag::CustomDiagInfo *CustomDiagInfo;
156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DiagnosticIDs();
159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ~DiagnosticIDs();
160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return an ID for a diagnostic with the specified format string and
162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// level.
163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// If this is the first request for this diagnostic, it is registered and
165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// created, otherwise the existing ID is returned.
166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: Replace this function with a create-only facilty like
168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // createCustomDiagIDFromFormatString() to enforce safe usage. At the time of
169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // writing, nearly all callers of this function were invalid.
170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned getCustomDiagID(Level L, StringRef FormatString);
171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  //===--------------------------------------------------------------------===//
173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Diagnostic classification and reporting interfaces.
174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  //
175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Given a diagnostic ID, return a description of the issue.
177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  StringRef getDescription(unsigned DiagID) const;
178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return true if the unmapped diagnostic levelof the specified
180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// diagnostic ID is a Warning or Extension.
181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This only works on builtin diagnostics, not custom ones, and is not
183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// legal to call on NOTEs.
184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool isBuiltinWarningOrExtension(unsigned DiagID);
185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return true if the specified diagnostic is mapped to errors by
187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// default.
188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool isDefaultMappingAsError(unsigned DiagID);
189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Determine whether the given built-in diagnostic ID is a Note.
191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool isBuiltinNote(unsigned DiagID);
192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Determine whether the given built-in diagnostic ID is for an
194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// extension of some sort.
195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool isBuiltinExtensionDiag(unsigned DiagID) {
196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool ignored;
197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return isBuiltinExtensionDiag(DiagID, ignored);
198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Determine whether the given built-in diagnostic ID is for an
201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// extension of some sort, and whether it is enabled by default.
202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This also returns EnabledByDefault, which is set to indicate whether the
204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// diagnostic is ignored by default (in which case -pedantic enables it) or
205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// treated as a warning/error by default.
206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool isBuiltinExtensionDiag(unsigned DiagID, bool &EnabledByDefault);
208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return the lowest-level warning option that enables the specified
211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// diagnostic.
212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// If there is no -Wfoo flag that controls the diagnostic, this returns null.
214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static StringRef getWarningOptionForDiag(unsigned DiagID);
215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return the category number that a specified \p DiagID belongs to,
217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// or 0 if no category.
218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static unsigned getCategoryNumberForDiag(unsigned DiagID);
219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return the number of diagnostic categories.
221f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static unsigned getNumberOfCategories();
222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Given a category ID, return the name of the category.
224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static StringRef getCategoryNameFromID(unsigned CategoryID);
225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
226f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Return true if a given diagnostic falls into an ARC diagnostic
227f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// category.
228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static bool isARCDiagnostic(unsigned DiagID);
229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Enumeration describing how the emission of a diagnostic should
231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// be treated when it occurs during C++ template argument deduction.
232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  enum SFINAEResponse {
233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The diagnostic should not be reported, but it should cause
234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// template argument deduction to fail.
235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// The vast majority of errors that occur during template argument
237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// deduction fall into this category.
238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SFINAE_SubstitutionFailure,
239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The diagnostic should be suppressed entirely.
241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Warnings generally fall into this category.
243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SFINAE_Suppress,
244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The diagnostic should be reported.
246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// The diagnostic should be reported. Various fatal errors (e.g.,
248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// template instantiation depth exceeded) fall into this category.
249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SFINAE_Report,
250f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The diagnostic is an access-control diagnostic, which will be
252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// substitution failures in some contexts and reported in others.
253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SFINAE_AccessControl
254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Determines whether the given built-in diagnostic ID is
257f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// for an error that is suppressed if it occurs during C++ template
258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// argument deduction.
259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// When an error is suppressed due to SFINAE, the template argument
261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// deduction fails but no diagnostic is emitted. Certain classes of
262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// errors, such as those errors that involve C++ access control,
263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// are not SFINAE errors.
264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the set of all diagnostic IDs in the group with the given name.
267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param[out] Diags - On return, the diagnostics in the group.
269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns \c true if the given group is unknown, \c false otherwise.
270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool getDiagnosticsInGroup(diag::Flavor Flavor, StringRef Group,
271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                             SmallVectorImpl<diag::kind> &Diags) const;
272f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the set of all diagnostic IDs.
274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void getAllDiagnostics(diag::Flavor Flavor,
275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                         SmallVectorImpl<diag::kind> &Diags) const;
276f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
277f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the diagnostic option with the closest edit distance to the
278f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// given group name.
279f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static StringRef getNearestOption(diag::Flavor Flavor, StringRef Group);
280f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
281f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
282f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Classify the specified diagnostic ID into a Level, consumable by
283f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the DiagnosticClient.
284f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
285f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// The classification is based on the way the client configured the
286f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// DiagnosticsEngine object.
287f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
288f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Loc The source location for which we are interested in finding out
289f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the diagnostic state. Can be null in order to query the latest state.
290f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DiagnosticIDs::Level
291f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
292f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                     const DiagnosticsEngine &Diag) const LLVM_READONLY;
293f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
294f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  diag::Severity
295f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getDiagnosticSeverity(unsigned DiagID, SourceLocation Loc,
296f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                        const DiagnosticsEngine &Diag) const LLVM_READONLY;
297f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
298f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Used to report a diagnostic that is finally fully formed.
299f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
300f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns \c true if the diagnostic was emitted, \c false if it was
301f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// suppressed.
302f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool ProcessDiag(DiagnosticsEngine &Diag) const;
303f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
304f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Used to emit a diagnostic that is finally fully formed,
305f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// ignoring suppression.
306f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void EmitDiag(DiagnosticsEngine &Diag, Level DiagLevel) const;
307f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
308f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether the diagnostic may leave the AST in a state where some
309f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// invariants can break.
310f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isUnrecoverable(unsigned DiagID) const;
311f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
312f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  friend class DiagnosticsEngine;
313f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
314f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
315f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}  // end namespace clang
316f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
317f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif
318