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