Diagnostic.h revision 06265bd82073c06294a02a0bd891951fafb484a5
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Diagnostic.h - C Language Family Diagnostic Handling ---*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//  This file defines the Diagnostic-related interfaces.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_DIAGNOSTIC_H
155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_DIAGNOSTIC_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis#include "clang/Basic/DiagnosticIDs.h"
182eefd8657c233bc7c9330acfe475fc270bbe7cabTed Kremenek#include "clang/Basic/SourceLocation.h"
19f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include "llvm/ADT/ArrayRef.h"
200827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis#include "llvm/ADT/DenseMap.h"
2128019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h"
22bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor#include "llvm/ADT/OwningPtr.h"
233f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor#include "llvm/Support/type_traits.h"
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis#include <vector>
260827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis#include <list>
27f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner
285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
2978ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  class DiagnosticConsumer;
3033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  class DiagnosticBuilder;
31d42ffbd22fc7eb61321f6a88173ee424991f01c6Ted Kremenek  class IdentifierInfo;
3233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  class DeclContext;
3340469651a3f8379dc0f32df69e9bade06a2aad36Chris Lattner  class LangOptions;
347d90199f109290e9d587479a481a2850d390b552Daniel Dunbar  class Preprocessor;
359c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  class DiagnosticErrorTrap;
36e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis  class StoredDiagnostic;
371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
384b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// \brief Annotates a diagnostic with some code that should be
394b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// inserted, removed, or replaced to fix the problem.
404b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor///
414b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// This kind of hint should be used when we are certain that the
424b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// introduction, removal, or modification of a particular (small!)
434b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// amount of code will correct a compilation error. The compiler
444b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// should also provide full recovery from such errors, such that
45b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor/// suppressing the diagnostic output can still result in successful
464b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// compilation.
47849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregorclass FixItHint {
484b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregorpublic:
49783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor  /// \brief Code that should be replaced to correct the error. Empty for an
50783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor  /// insertion hint.
510a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  CharSourceRange RemoveRange;
524b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
5330660a898545416f0fea2d717f16f75640001e38Ted Kremenek  /// \brief Code in the specific range that should be inserted in the insertion
5430660a898545416f0fea2d717f16f75640001e38Ted Kremenek  /// location.
5530660a898545416f0fea2d717f16f75640001e38Ted Kremenek  CharSourceRange InsertFromRange;
5630660a898545416f0fea2d717f16f75640001e38Ted Kremenek
574b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// \brief The actual code to insert at the insertion location, as a
584b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// string.
594b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  std::string CodeToInsert;
604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
6130660a898545416f0fea2d717f16f75640001e38Ted Kremenek  bool BeforePreviousInsertions;
6230660a898545416f0fea2d717f16f75640001e38Ted Kremenek
634b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// \brief Empty code modification hint, indicating that no code
644b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// modification is known.
6530660a898545416f0fea2d717f16f75640001e38Ted Kremenek  FixItHint() : BeforePreviousInsertions(false) { }
664b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
672f019aadc96f8fa3185c684c7150bd596d045064Anders Carlsson  bool isNull() const {
68783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor    return !RemoveRange.isValid();
692f019aadc96f8fa3185c684c7150bd596d045064Anders Carlsson  }
702f019aadc96f8fa3185c684c7150bd596d045064Anders Carlsson
714b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// \brief Create a code modification hint that inserts the given
724b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// code string at a specific location.
73849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  static FixItHint CreateInsertion(SourceLocation InsertionLoc,
7430660a898545416f0fea2d717f16f75640001e38Ted Kremenek                                   StringRef Code,
7530660a898545416f0fea2d717f16f75640001e38Ted Kremenek                                   bool BeforePreviousInsertions = false) {
76849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor    FixItHint Hint;
77783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor    Hint.RemoveRange =
78783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor      CharSourceRange(SourceRange(InsertionLoc, InsertionLoc), false);
79b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    Hint.CodeToInsert = Code;
8030660a898545416f0fea2d717f16f75640001e38Ted Kremenek    Hint.BeforePreviousInsertions = BeforePreviousInsertions;
8130660a898545416f0fea2d717f16f75640001e38Ted Kremenek    return Hint;
8230660a898545416f0fea2d717f16f75640001e38Ted Kremenek  }
8330660a898545416f0fea2d717f16f75640001e38Ted Kremenek
8430660a898545416f0fea2d717f16f75640001e38Ted Kremenek  /// \brief Create a code modification hint that inserts the given
8530660a898545416f0fea2d717f16f75640001e38Ted Kremenek  /// code from \arg FromRange at a specific location.
8630660a898545416f0fea2d717f16f75640001e38Ted Kremenek  static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc,
8730660a898545416f0fea2d717f16f75640001e38Ted Kremenek                                            CharSourceRange FromRange,
8830660a898545416f0fea2d717f16f75640001e38Ted Kremenek                                        bool BeforePreviousInsertions = false) {
8930660a898545416f0fea2d717f16f75640001e38Ted Kremenek    FixItHint Hint;
9030660a898545416f0fea2d717f16f75640001e38Ted Kremenek    Hint.RemoveRange =
9130660a898545416f0fea2d717f16f75640001e38Ted Kremenek      CharSourceRange(SourceRange(InsertionLoc, InsertionLoc), false);
9230660a898545416f0fea2d717f16f75640001e38Ted Kremenek    Hint.InsertFromRange = FromRange;
9330660a898545416f0fea2d717f16f75640001e38Ted Kremenek    Hint.BeforePreviousInsertions = BeforePreviousInsertions;
94b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    return Hint;
95b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor  }
964b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
974b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// \brief Create a code modification hint that removes the given
984b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// source range.
990a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static FixItHint CreateRemoval(CharSourceRange RemoveRange) {
100849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor    FixItHint Hint;
101b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    Hint.RemoveRange = RemoveRange;
102b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    return Hint;
103b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor  }
1040a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static FixItHint CreateRemoval(SourceRange RemoveRange) {
1050a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return CreateRemoval(CharSourceRange::getTokenRange(RemoveRange));
1060a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
1070a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
1084b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// \brief Create a code modification hint that replaces the given
1094b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  /// source range with the given code string.
1100a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static FixItHint CreateReplacement(CharSourceRange RemoveRange,
111686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                     StringRef Code) {
112849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor    FixItHint Hint;
113b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    Hint.RemoveRange = RemoveRange;
114b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    Hint.CodeToInsert = Code;
115b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor    return Hint;
116b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor  }
1170a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
1180a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  static FixItHint CreateReplacement(SourceRange RemoveRange,
119686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                     StringRef Code) {
1200a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner    return CreateReplacement(CharSourceRange::getTokenRange(RemoveRange), Code);
1210a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  }
1224b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor};
1234b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
124d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// DiagnosticsEngine - This concrete class is used by the front-end to report
1255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// problems and issues.  It massages the diagnostics (e.g. handling things like
12678ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie/// "report warnings as errors" and passes them off to the DiagnosticConsumer
12778ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie/// for reporting to the user. DiagnosticsEngine is tied to one translation unit
12878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie/// and one SourceManager.
129c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmithclass DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
130182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattnerpublic:
131182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner  /// Level - The level of the diagnostic, after it has been through mapping.
132182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner  enum Level {
13333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Ignored = DiagnosticIDs::Ignored,
13433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Note = DiagnosticIDs::Note,
13533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Warning = DiagnosticIDs::Warning,
13633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Error = DiagnosticIDs::Error,
13733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    Fatal = DiagnosticIDs::Fatal
138182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner  };
1391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
140b54b276a920246c595a0498da281821eb9d22996Chris Lattner  /// ExtensionHandling - How do we handle otherwise-unmapped extension?  This
141b54b276a920246c595a0498da281821eb9d22996Chris Lattner  /// is controlled by -pedantic and -pedantic-errors.
142b54b276a920246c595a0498da281821eb9d22996Chris Lattner  enum ExtensionHandling {
143b54b276a920246c595a0498da281821eb9d22996Chris Lattner    Ext_Ignore, Ext_Warn, Ext_Error
144b54b276a920246c595a0498da281821eb9d22996Chris Lattner  };
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1463fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  enum ArgumentKind {
14747b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_std_string,      // std::string
14847b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_c_string,        // const char *
14947b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_sint,            // int
15047b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_uint,            // unsigned
15147b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_identifierinfo,  // IdentifierInfo
15247b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_qualtype,        // QualType
15347b9a1ca55e61e37f5a368740e29de190345acc6Douglas Gregor    ak_declarationname, // DeclarationName
154dacd434c49658286c380c7b4c357d76d53cb4aa1Douglas Gregor    ak_nameddecl,       // NamedDecl *
1553f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor    ak_nestednamespec,  // NestedNameSpecifier *
1563f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor    ak_declcontext      // DeclContext *
1573fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  };
1585edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin
1595edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  /// Specifies which overload candidates to display when overload resolution
1605edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  /// fails.
1615edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  enum OverloadsShown {
1625edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin    Ovl_All,  ///< Show all overloads.
1635edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin    Ovl_Best  ///< Show just the "best" overload candidates.
1645edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  };
1655edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin
166b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  /// ArgumentValue - This typedef represents on argument value, which is a
167b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  /// union discriminated by ArgumentKind, with a value.
168b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  typedef std::pair<ArgumentKind, intptr_t> ArgumentValue;
169ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor
1701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprivate:
17127ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  unsigned char AllExtensionsSilenced; // Used by __extension__
172b54b276a920246c595a0498da281821eb9d22996Chris Lattner  bool IgnoreAllWarnings;        // Ignore all warnings: -w
1731e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  bool WarningsAsErrors;         // Treat warnings like errors.
1741e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  bool EnableAllWarnings;        // Enable all warnings.
175e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner  bool ErrorsAsFatal;            // Treat errors like fatal errors.
176b54b276a920246c595a0498da281821eb9d22996Chris Lattner  bool SuppressSystemWarnings;   // Suppress warnings in system headers.
17781b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  bool SuppressAllDiagnostics;   // Suppress all diagnostics.
1785edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  OverloadsShown ShowOverloads;  // Which overload candidates to show.
179c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner  unsigned ErrorLimit;           // Cap of # errors emitted, 0 -> no limit.
180575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  unsigned TemplateBacktraceLimit; // Cap on depth of template backtrace stack,
181575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor                                   // 0 -> no limit.
18208d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  unsigned ConstexprBacktraceLimit; // Cap on depth of constexpr evaluation
18308d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith                                    // backtrace stack, 0 -> no limit.
184b54b276a920246c595a0498da281821eb9d22996Chris Lattner  ExtensionHandling ExtBehavior; // Map extensions onto warnings or errors?
185c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  IntrusiveRefCntPtr<DiagnosticIDs> Diags;
18678ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  DiagnosticConsumer *Client;
18733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  bool OwnsDiagClient;
18833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  SourceManager *SourceMgr;
1890827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
1900827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Mapping information for diagnostics.  Mapping info is
191691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// packed into four bits per diagnostic.  The low three bits are the mapping
192691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// (an instance of diag::Mapping), or zero if unset.  The high bit is set
193691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// when the mapping was established as a user mapping.  If the high bit is
194691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// clear, then the low bits are set to the default value, and should be
195691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// mapped with -pedantic, -Werror, etc.
1960827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
1973efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis  /// A new DiagState is created and kept around when diagnostic pragmas modify
1983efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis  /// the state so that we know what is the diagnostic state at any given
1993efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis  /// source location.
2000827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  class DiagState {
201b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar    llvm::DenseMap<unsigned, DiagnosticMappingInfo> DiagMap;
2023c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer
2033c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer  public:
204ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar    typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::iterator
205b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar      iterator;
206ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar    typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::const_iterator
207ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar      const_iterator;
2083efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis
209b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar    void setMappingInfo(diag::kind Diag, DiagnosticMappingInfo Info) {
210b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar      DiagMap[Diag] = Info;
211b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar    }
2123c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer
213ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar    DiagnosticMappingInfo &getOrAddMappingInfo(diag::kind Diag);
214ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar
215ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar    const_iterator begin() const { return DiagMap.begin(); }
216ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar    const_iterator end() const { return DiagMap.end(); }
2170827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  };
2183c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer
2190827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Keeps and automatically disposes all DiagStates that we create.
2200827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  std::list<DiagState> DiagStates;
2210827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
2220827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Represents a point in source where the diagnostic state was
2230827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// modified because of a pragma. 'Loc' can be null if the point represents
2240827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// the diagnostic state modifications done through the command-line.
2250827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  struct DiagStatePoint {
2260827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    DiagState *State;
2270827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    FullSourceLoc Loc;
2280827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    DiagStatePoint(DiagState *State, FullSourceLoc Loc)
2290827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      : State(State), Loc(Loc) { }
2300827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
2310827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    bool operator<(const DiagStatePoint &RHS) const {
2320827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      // If Loc is invalid it means it came from <command-line>, in which case
2330827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      // we regard it as coming before any valid source location.
2340827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      if (RHS.Loc.isInvalid())
2350827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis        return false;
2360827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      if (Loc.isInvalid())
2370827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis        return true;
2380827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis      return Loc.isBeforeInTranslationUnitThan(RHS.Loc);
2393c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer    }
2403c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer  };
24104ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner
2420827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief A vector of all DiagStatePoints representing changes in diagnostic
2430827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// state due to diagnostic pragmas. The vector is always sorted according to
2440827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// the SourceLocation of the DiagStatePoint.
2450827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  typedef std::vector<DiagStatePoint> DiagStatePointsTy;
2460827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  mutable DiagStatePointsTy DiagStatePoints;
2470827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
2480827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Keeps the DiagState that was active during each diagnostic 'push'
2490827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// so we can get back at it when we 'pop'.
2500827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  std::vector<DiagState *> DiagStateOnPushStack;
2510827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
2520827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  DiagState *GetCurDiagState() const {
2530827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert(!DiagStatePoints.empty());
2540827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    return DiagStatePoints.back().State;
2550827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  }
2560827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
2570827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  void PushDiagStatePoint(DiagState *State, SourceLocation L) {
2580827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    FullSourceLoc Loc(L, *SourceMgr);
2590827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    // Make sure that DiagStatePoints is always sorted according to Loc.
2600827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert((Loc.isValid() || DiagStatePoints.empty()) &&
2610827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis           "Adding invalid loc point after another point");
2620827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    assert((Loc.isInvalid() || DiagStatePoints.empty() ||
2630827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis            DiagStatePoints.back().Loc.isInvalid() ||
2640827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis            DiagStatePoints.back().Loc.isBeforeInTranslationUnitThan(Loc)) &&
2650827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis           "Previous point loc comes after or is the same as new one");
2660827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis    DiagStatePoints.push_back(DiagStatePoint(State,
2670827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis                                             FullSourceLoc(Loc, *SourceMgr)));
2680827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  }
2690827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis
2700827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief Finds the DiagStatePoint that contains the diagnostic state of
2710827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// the given source location.
2720827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  DiagStatePointsTy::iterator GetDiagStatePointForLoc(SourceLocation Loc) const;
27304ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner
27415221422eda7bac679e38b07512feda49715ef66Chris Lattner  /// ErrorOccurred / FatalErrorOccurred - This is set to true when an error or
27515221422eda7bac679e38b07512feda49715ef66Chris Lattner  /// fatal error is emitted, and is sticky.
2765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool ErrorOccurred;
27715221422eda7bac679e38b07512feda49715ef66Chris Lattner  bool FatalErrorOccurred;
2781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
27985bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor  /// \brief Indicates that an unrecoverable error has occurred.
28085bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor  bool UnrecoverableErrorOccurred;
28185bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor
282c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis  /// \brief Counts for DiagnosticErrorTrap to check whether an error occurred
283add80bb3957dba1d9389304453c0a4c975768bd7John McCall  /// during a parsing section, e.g. during parsing a function.
284c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis  unsigned TrapNumErrorsOccurred;
285c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis  unsigned TrapNumUnrecoverableErrorsOccurred;
286add80bb3957dba1d9389304453c0a4c975768bd7John McCall
287f5d2328fc849288c3a62e43d065685f516d57091Chris Lattner  /// LastDiagLevel - This is the level of the last diagnostic emitted.  This is
288f5d2328fc849288c3a62e43d065685f516d57091Chris Lattner  /// used to emit continuation diagnostics with the same level as the
289f5d2328fc849288c3a62e43d065685f516d57091Chris Lattner  /// diagnostic that they follow.
29033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  DiagnosticIDs::Level LastDiagLevel;
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
29253eee7ba970d21ff15bbd4334164037a3b4cc4b8Chris Lattner  unsigned NumWarnings;       // Number of warnings reported
29353eee7ba970d21ff15bbd4334164037a3b4cc4b8Chris Lattner  unsigned NumErrors;         // Number of errors reported
2941864f2eb59471d07db51adfc3e5b1a229eed631aDouglas Gregor  unsigned NumErrorsSuppressed; // Number of errors suppressed
2957bfaaaecb3113f955db31e8d8a51acffd1bc0c27Nico Weber
2963fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  /// ArgToStringFn - A function pointer that converts an opaque diagnostic
2973fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  /// argument to a strings.  This takes the modifiers and argument that was
2983fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  /// present in the diagnostic.
299b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  ///
300b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  /// The PrevArgs array (whose length is NumPrevArgs) indicates the previous
301b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  /// arguments formatted for this diagnostic.  Implementations of this function
302b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  /// can use this information to avoid redundancy across arguments.
303b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner  ///
30422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  /// This is a hack to avoid a layering violation between libbasic and libsema.
3050673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth  typedef void (*ArgToStringFnTy)(
3060673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth      ArgumentKind Kind, intptr_t Val,
3070673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth      const char *Modifier, unsigned ModifierLen,
3080673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth      const char *Argument, unsigned ArgumentLen,
3090673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth      const ArgumentValue *PrevArgs,
3100673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth      unsigned NumPrevArgs,
311686775deca8b8685eb90801495880e3abdd844c2Chris Lattner      SmallVectorImpl<char> &Output,
3120673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth      void *Cookie,
313341785ec52f87c0803ba52dc88faac4e136f8593Bill Wendling      ArrayRef<intptr_t> QualTypeVals);
31492dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner  void *ArgToStringCookie;
3153fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  ArgToStringFnTy ArgToStringFn;
31693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
31793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \brief ID of the "delayed" diagnostic, which is a (typically
31893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// fatal) diagnostic that had to be delayed because it was found
31993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// while emitting another diagnostic.
32093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  unsigned DelayedDiagID;
32193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
32293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \brief First string argument for the delayed diagnostic.
32393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  std::string DelayedDiagArg1;
32493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
32593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \brief Second string argument for the delayed diagnostic.
32693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  std::string DelayedDiagArg2;
32793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
329d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  explicit DiagnosticsEngine(
330c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith                      const IntrusiveRefCntPtr<DiagnosticIDs> &Diags,
33178ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie                      DiagnosticConsumer *client = 0,
33233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis                      bool ShouldOwnClient = true);
333d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  ~DiagnosticsEngine();
3341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
335c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  const IntrusiveRefCntPtr<DiagnosticIDs> &getDiagnosticIDs() const {
33633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    return Diags;
33733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  }
33833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis
33978ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  DiagnosticConsumer *getClient() { return Client; }
34078ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  const DiagnosticConsumer *getClient() const { return Client; }
3411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
342d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// \brief Determine whether this \c DiagnosticsEngine object own its client.
34378243658c533168d51fd076fba328437932ba6f1Douglas Gregor  bool ownsClient() const { return OwnsDiagClient; }
34478243658c533168d51fd076fba328437932ba6f1Douglas Gregor
345bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor  /// \brief Return the current diagnostic client along with ownership of that
346bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor  /// client.
34778ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  DiagnosticConsumer *takeClient() {
34833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    OwnsDiagClient = false;
34933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    return Client;
35033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  }
35133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis
35233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  bool hasSourceManager() const { return SourceMgr != 0; }
35333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  SourceManager &getSourceManager() const {
35433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    assert(SourceMgr && "SourceManager not set!");
35533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    return *SourceMgr;
35633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  }
35733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  void setSourceManager(SourceManager *SrcMgr) { SourceMgr = SrcMgr; }
35833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis
35933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  //===--------------------------------------------------------------------===//
360d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  //  DiagnosticsEngine characterization methods, used by a client to customize
361d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  //  how diagnostics are emitted.
36233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  //
36304ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner
3641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// pushMappings - Copies the current DiagMappings and pushes the new copy
36504ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner  /// onto the top of the stack.
3660827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  void pushMappings(SourceLocation Loc);
36704ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner
36804ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner  /// popMappings - Pops the current DiagMappings off the top of the stack
36904ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner  /// causing the new top of the stack to be the active mappings. Returns
37004ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner  /// true if the pop happens, false if there is only one DiagMapping on the
37104ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner  /// stack.
3720827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  bool popMappings(SourceLocation Loc);
37304ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner
374bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor  /// \brief Set the diagnostic client associated with this diagnostic object.
375bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor  ///
37633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  /// \param ShouldOwnClient true if the diagnostic object should take
37733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  /// ownership of \c client.
37878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  void setClient(DiagnosticConsumer *client, bool ShouldOwnClient = true);
3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
380c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner  /// setErrorLimit - Specify a limit for the number of errors we should
381b205ac9fcd22b87b41697172d1983c5ae9dabaafChris Lattner  /// emit before giving up.  Zero disables the limit.
382c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner  void setErrorLimit(unsigned Limit) { ErrorLimit = Limit; }
383b205ac9fcd22b87b41697172d1983c5ae9dabaafChris Lattner
384575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  /// \brief Specify the maximum number of template instantiation
385575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  /// notes to emit along with a given diagnostic.
386575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  void setTemplateBacktraceLimit(unsigned Limit) {
387575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor    TemplateBacktraceLimit = Limit;
388575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  }
38908d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith
390575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  /// \brief Retrieve the maximum number of template instantiation
39108d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  /// notes to emit along with a given diagnostic.
392575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  unsigned getTemplateBacktraceLimit() const {
393575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor    return TemplateBacktraceLimit;
394575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  }
39508d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith
39608d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  /// \brief Specify the maximum number of constexpr evaluation
39708d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  /// notes to emit along with a given diagnostic.
39808d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  void setConstexprBacktraceLimit(unsigned Limit) {
39908d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith    ConstexprBacktraceLimit = Limit;
40008d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  }
40108d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith
40208d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  /// \brief Retrieve the maximum number of constexpr evaluation
40308d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  /// notes to emit along with a given diagnostic.
40408d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  unsigned getConstexprBacktraceLimit() const {
40508d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith    return ConstexprBacktraceLimit;
40608d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  }
40708d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith
4085b4681c8ef65808ec4d72ab6081efd24d53d4969Chris Lattner  /// setIgnoreAllWarnings - When set to true, any unmapped warnings are
4095b4681c8ef65808ec4d72ab6081efd24d53d4969Chris Lattner  /// ignored.  If this and WarningsAsErrors are both set, then this one wins.
4105b4681c8ef65808ec4d72ab6081efd24d53d4969Chris Lattner  void setIgnoreAllWarnings(bool Val) { IgnoreAllWarnings = Val; }
4115b4681c8ef65808ec4d72ab6081efd24d53d4969Chris Lattner  bool getIgnoreAllWarnings() const { return IgnoreAllWarnings; }
4121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4131e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  /// setEnableAllWarnings - When set to true, any unmapped ignored warnings
4141e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  /// are no longer ignored.  If this and IgnoreAllWarnings are both set,
4151e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  /// then that one wins.
4161e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  void setEnableAllWarnings(bool Val) { EnableAllWarnings = Val; }
4171e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek  bool getEnableAllWarnngs() const { return EnableAllWarnings; }
4181e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// setWarningsAsErrors - When set to true, any warnings reported are issued
4205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// as errors.
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  void setWarningsAsErrors(bool Val) { WarningsAsErrors = Val; }
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool getWarningsAsErrors() const { return WarningsAsErrors; }
4231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
424e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner  /// setErrorsAsFatal - When set to true, any error reported is made a
425e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner  /// fatal error.
426e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner  void setErrorsAsFatal(bool Val) { ErrorsAsFatal = Val; }
427e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner  bool getErrorsAsFatal() const { return ErrorsAsFatal; }
428e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner
4292fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar  /// setSuppressSystemWarnings - When set to true mask warnings that
4302fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar  /// come from system headers.
4312fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar  void setSuppressSystemWarnings(bool Val) { SuppressSystemWarnings = Val; }
4322fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar  bool getSuppressSystemWarnings() const { return SuppressSystemWarnings; }
4332fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar
43481b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  /// \brief Suppress all diagnostics, to silence the front end when we
43581b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  /// know that we don't want any more diagnostics to be passed along to the
43681b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  /// client
43781b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  void setSuppressAllDiagnostics(bool Val = true) {
43881b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor    SuppressAllDiagnostics = Val;
43981b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  }
44081b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor  bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; }
44181b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor
4425edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  /// \brief Specify which overload candidates to show when overload resolution
4435edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  /// fails.  By default, we show all candidates.
4445edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  void setShowOverloads(OverloadsShown Val) {
4455edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin    ShowOverloads = Val;
4465edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  }
4475edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin  OverloadsShown getShowOverloads() const { return ShowOverloads; }
4485edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin
4490b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor  /// \brief Pretend that the last diagnostic issued was ignored. This can
4500b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor  /// be used by clients who suppress diagnostics themselves.
4510b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor  void setLastDiagnosticIgnored() {
45233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    LastDiagLevel = DiagnosticIDs::Ignored;
4530b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor  }
4540b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor
455b54b276a920246c595a0498da281821eb9d22996Chris Lattner  /// setExtensionHandlingBehavior - This controls whether otherwise-unmapped
456b54b276a920246c595a0498da281821eb9d22996Chris Lattner  /// extension diagnostics are mapped onto ignore/warning/error.  This
457b54b276a920246c595a0498da281821eb9d22996Chris Lattner  /// corresponds to the GCC -pedantic and -pedantic-errors option.
458b54b276a920246c595a0498da281821eb9d22996Chris Lattner  void setExtensionHandlingBehavior(ExtensionHandling H) {
459b54b276a920246c595a0498da281821eb9d22996Chris Lattner    ExtBehavior = H;
460b54b276a920246c595a0498da281821eb9d22996Chris Lattner  }
461c1b5fa41f09512c74030b9a2a0d1564535e22a76Peter Collingbourne  ExtensionHandling getExtensionHandlingBehavior() const { return ExtBehavior; }
4621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
46327ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  /// AllExtensionsSilenced - This is a counter bumped when an __extension__
46427ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  /// block is encountered.  When non-zero, all extension diagnostics are
46527ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  /// entirely silenced, no matter how they are mapped.
46627ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  void IncrementAllExtensionsSilenced() { ++AllExtensionsSilenced; }
46727ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  void DecrementAllExtensionsSilenced() { --AllExtensionsSilenced; }
46891a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor  bool hasAllExtensionsSilenced() { return AllExtensionsSilenced != 0; }
4691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4700827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \brief This allows the client to specify that certain
471691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// warnings are ignored.  Notes can never be mapped, errors can only be
472691f1ae7164ba78c3dd7ac20c487399935b9544bChris Lattner  /// mapped to fatal, and WARNINGs and EXTENSIONs can be mapped arbitrarily.
4730827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
4740827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \param Loc The source location that this change of diagnostic state should
4750827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// take affect. It can be null if we are setting the latest state.
4760827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  void setDiagnosticMapping(diag::kind Diag, diag::Mapping Map,
4770827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis                            SourceLocation Loc);
4781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
4793bc172bc6a787842db6fea351cf6929539fca70dChris Lattner  /// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g.
4803bc172bc6a787842db6fea351cf6929539fca70dChris Lattner  /// "unknown-pragmas" to have the specified mapping.  This returns true and
4813bc172bc6a787842db6fea351cf6929539fca70dChris Lattner  /// ignores the request if "Group" was unknown, false otherwise.
4820827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
4830827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// 'Loc' is the source location that this change of diagnostic state should
4840827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// take affect. It can be null if we are setting the state from command-line.
485686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool setDiagnosticGroupMapping(StringRef Group, diag::Mapping Map,
4863f8394669673451061f57ced81f0a2cae087f119Daniel Dunbar                                 SourceLocation Loc = SourceLocation());
4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4883f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier  /// \brief Set the warning-as-error flag for the given diagnostic. This
4893f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier  /// function always only operates on the current diagnostic state.
4903f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier  void setDiagnosticWarningAsError(diag::kind Diag, bool Enabled);
4913f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier
492aeacae523a1c6e5bb99d12754415bbbc3ccb86c9Daniel Dunbar  /// \brief Set the warning-as-error flag for the given diagnostic group. This
493aeacae523a1c6e5bb99d12754415bbbc3ccb86c9Daniel Dunbar  /// function always only operates on the current diagnostic state.
4944aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar  ///
4954aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar  /// \returns True if the given group is unknown, false otherwise.
4964aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar  bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled);
4974aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar
4983f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier  /// \brief Set the error-as-fatal flag for the given diagnostic. This function
4993f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier  /// always only operates on the current diagnostic state.
5003f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier  void setDiagnosticErrorAsFatal(diag::kind Diag, bool Enabled);
5013f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier
502aeacae523a1c6e5bb99d12754415bbbc3ccb86c9Daniel Dunbar  /// \brief Set the error-as-fatal flag for the given diagnostic group. This
503aeacae523a1c6e5bb99d12754415bbbc3ccb86c9Daniel Dunbar  /// function always only operates on the current diagnostic state.
5044aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar  ///
5054aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar  /// \returns True if the given group is unknown, false otherwise.
5064aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar  bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled);
5074aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar
50811583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis  /// \brief Add the specified mapping to all diagnostics. Mainly to be used
50911583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis  /// by -Wno-everything to disable all warnings but allow subsequent -W options
51011583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis  /// to enable specific warnings.
51182e6411d004064a29f03a3ea8b8919f297bfa843Argyrios Kyrtzidis  void setMappingToAllDiagnostics(diag::Mapping Map,
51211583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis                                  SourceLocation Loc = SourceLocation());
51311583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis
5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  bool hasErrorOccurred() const { return ErrorOccurred; }
51515221422eda7bac679e38b07512feda49715ef66Chris Lattner  bool hasFatalErrorOccurred() const { return FatalErrorOccurred; }
51685bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor
51785bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor  /// \brief Determine whether any kind of unrecoverable error has occurred.
51885bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor  bool hasUnrecoverableErrorOccurred() const {
51985bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor    return FatalErrorOccurred || UnrecoverableErrorOccurred;
52085bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor  }
52185bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor
52253eee7ba970d21ff15bbd4334164037a3b4cc4b8Chris Lattner  unsigned getNumWarnings() const { return NumWarnings; }
5231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
524c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor  void setNumWarnings(unsigned NumWarnings) {
525c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor    this->NumWarnings = NumWarnings;
526c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor  }
527c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor
528182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner  /// getCustomDiagID - Return an ID for a diagnostic with the specified message
529182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner  /// and level.  If this is the first request for this diagnosic, it is
530182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner  /// registered and created, otherwise the existing ID is returned.
531686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  unsigned getCustomDiagID(Level L, StringRef Message) {
53233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    return Diags->getCustomDiagID((DiagnosticIDs::Level)L, Message);
53333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  }
5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5353fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  /// ConvertArgToString - This method converts a diagnostic argument (as an
5363fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  /// intptr_t) into the string that represents it.
5373fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner  void ConvertArgToString(ArgumentKind Kind, intptr_t Val,
5383fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner                          const char *Modifier, unsigned ModLen,
5393fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner                          const char *Argument, unsigned ArgLen,
540b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner                          const ArgumentValue *PrevArgs, unsigned NumPrevArgs,
541686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                          SmallVectorImpl<char> &Output,
542686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                          SmallVectorImpl<intptr_t> &QualTypeVals) const {
543b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner    ArgToStringFn(Kind, Val, Modifier, ModLen, Argument, ArgLen,
5440673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth                  PrevArgs, NumPrevArgs, Output, ArgToStringCookie,
5450673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth                  QualTypeVals);
54622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  }
5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
54892dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner  void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie) {
5493fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner    ArgToStringFn = Fn;
55092dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner    ArgToStringCookie = Cookie;
55122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  }
5521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
553abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor  /// \brief Reset the state of the diagnostic object to its initial
554abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor  /// configuration.
555abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor  void Reset();
556abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor
5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //===--------------------------------------------------------------------===//
558d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  // DiagnosticsEngine classification and reporting interfaces.
5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  //
5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
561d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// \brief Based on the way the client configured the DiagnosticsEngine
5625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// object, classify the specified diagnostic ID into a Level, consumable by
56378ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  /// the DiagnosticConsumer.
5640827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  ///
5650827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// \param Loc The source location we are interested in finding out the
5660827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis  /// diagnostic state. Can be null in order to query the latest state.
5671656aaec223949245fdbebf306b719cba0b687caDaniel Dunbar  Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const {
5681656aaec223949245fdbebf306b719cba0b687caDaniel Dunbar    return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this);
56933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  }
5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
571509355e982d15da4f8f3939493516379665f6275Ted Kremenek  /// Report - Issue the message to the client.  @c DiagID is a member of the
572509355e982d15da4f8f3939493516379665f6275Ted Kremenek  /// @c diag::kind enum.  This actually returns aninstance of DiagnosticBuilder
573509355e982d15da4f8f3939493516379665f6275Ted Kremenek  /// which emits the diagnostics (through @c ProcessDiag) when it is destroyed.
574509355e982d15da4f8f3939493516379665f6275Ted Kremenek  /// @c Pos represents the source location associated with the diagnostic,
575509355e982d15da4f8f3939493516379665f6275Ted Kremenek  /// which can be an invalid location if no position information is available.
57633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  inline DiagnosticBuilder Report(SourceLocation Pos, unsigned DiagID);
5770f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar  inline DiagnosticBuilder Report(unsigned DiagID);
578de4bf6a63219c5b9d3bce1fed3dfe075568098a0Douglas Gregor
579e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis  void Report(const StoredDiagnostic &storedDiag);
580e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis
58193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \brief Determine whethere there is already a diagnostic in flight.
5825800f7ea9cf5621280089d690f677bd28064d6b5Ted Kremenek  bool isDiagnosticInFlight() const { return CurDiagID != ~0U; }
58393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
58493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \brief Set the "delayed" diagnostic that will be emitted once
58593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// the current diagnostic completes.
58693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///
58793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  If a diagnostic is already in-flight but the front end must
58893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  report a problem (e.g., with an inconsistent file system
58993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  state), this routine sets a "delayed" diagnostic that will be
59093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  emitted after the current diagnostic completes. This should
59193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  only be used for fatal errors detected at inconvenient
59293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  times. If emitting a delayed diagnostic causes a second delayed
59393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  diagnostic to be introduced, that second delayed diagnostic
59493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///  will be ignored.
59593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///
59693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \param DiagID The ID of the diagnostic being delayed.
59793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///
59893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \param Arg1 A string argument that will be provided to the
59993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// diagnostic. A copy of this string will be stored in the
600d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// DiagnosticsEngine object itself.
60193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  ///
60293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \param Arg2 A string argument that will be provided to the
60393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// diagnostic. A copy of this string will be stored in the
604d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// DiagnosticsEngine object itself.
605686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1 = "",
606686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                            StringRef Arg2 = "");
60793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
608de4bf6a63219c5b9d3bce1fed3dfe075568098a0Douglas Gregor  /// \brief Clear out the current diagnostic.
609de4bf6a63219c5b9d3bce1fed3dfe075568098a0Douglas Gregor  void Clear() { CurDiagID = ~0U; }
6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6110a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattnerprivate:
61293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  /// \brief Report the delayed diagnostic.
61393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  void ReportDelayed();
61493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor
6153cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  // This is private state used by DiagnosticBuilder.  We put it here instead of
6163cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  // in DiagnosticBuilder in order to keep DiagnosticBuilder a small lightweight
6170a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  // object.  This implementation choice means that we can only have one
6180a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  // diagnostic "in flight" at a time, but this seems to be a reasonable
6190a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  // tradeoff to keep these objects small.  Assertions verify that only one
6200a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  // diagnostic is in flight at a time.
62133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  friend class DiagnosticIDs;
6223cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  friend class DiagnosticBuilder;
62340847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie  friend class Diagnostic;
6249b623639378d53a675921ddfa7316034d571881eDouglas Gregor  friend class PartialDiagnostic;
6259c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  friend class DiagnosticErrorTrap;
6269b623639378d53a675921ddfa7316034d571881eDouglas Gregor
627b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner  /// CurDiagLoc - This is the location of the current diagnostic that is in
628b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner  /// flight.
62933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  SourceLocation CurDiagLoc;
6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
631b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner  /// CurDiagID - This is the ID of the current diagnostic that is in flight.
6323cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  /// This is set to ~0U when there is no diagnostic in flight.
633b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner  unsigned CurDiagID;
634b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner
63573d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  enum {
63673d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner    /// MaxArguments - The maximum number of arguments we can hold. We currently
63773d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner    /// only support up to 10 arguments (%0-%9).  A single diagnostic with more
63873d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner    /// than that almost certainly has to be simplified anyway.
639981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    MaxArguments = 10,
640981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar
641981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    /// MaxRanges - The maximum number of ranges we can hold.
642981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    MaxRanges = 10,
643981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar
644981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    /// MaxFixItHints - The maximum number of ranges we can hold.
645981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    MaxFixItHints = 10
64673d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  };
6471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6483cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  /// NumDiagArgs - This contains the number of entries in Arguments.
649730e0fdbbf9b315ef834074054ac55af3a4fcc0cChris Lattner  signed char NumDiagArgs;
650981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  /// NumDiagRanges - This is the number of ranges in the DiagRanges array.
651730e0fdbbf9b315ef834074054ac55af3a4fcc0cChris Lattner  unsigned char NumDiagRanges;
652981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  /// NumDiagFixItHints - This is the number of hints in the DiagFixItHints
653981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  /// array.
654981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  unsigned char NumDiagFixItHints;
655ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor
65673d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// DiagArgumentsKind - This is an array of ArgumentKind::ArgumentKind enum
65773d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// values, with one for each argument.  This specifies whether the argument
65873d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// is in DiagArgumentsStr or in DiagArguments.
65973d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  unsigned char DiagArgumentsKind[MaxArguments];
6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
66173d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// DiagArgumentsStr - This holds the values of each string argument for the
66273d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// current diagnostic.  This value is only used when the corresponding
66373d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// ArgumentKind is ak_std_string.
66473d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  std::string DiagArgumentsStr[MaxArguments];
66573d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner
66673d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// DiagArgumentsVal - The values for the various substitution positions. This
66773d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// is used when the argument is not an std::string.  The specific value is
668fc8f0e14ad142ed811e90fbd9a30e419e301c717Chris Lattner  /// mangled into an intptr_t and the interpretation depends on exactly what
66973d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// sort of argument kind it is.
67073d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  intptr_t DiagArgumentsVal[MaxArguments];
6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
672981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  /// DiagRanges - The list of ranges added to this diagnostic.
673981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  CharSourceRange DiagRanges[MaxRanges];
6741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
675981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  /// FixItHints - If valid, provides a hint with some code to insert, remove,
676981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  /// or modify at a particular position.
677981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  FixItHint DiagFixItHints[MaxFixItHints];
6784b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
67987429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis  DiagnosticMappingInfo makeMappingInfo(diag::Mapping Map, SourceLocation L) {
68087429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    bool isPragma = L.isValid();
68187429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    DiagnosticMappingInfo MappingInfo = DiagnosticMappingInfo::Make(
68287429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis      Map, /*IsUser=*/true, isPragma);
68387429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis
68487429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    // If this is a pragma mapping, then set the diagnostic mapping flags so
68587429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    // that we override command line options.
68687429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    if (isPragma) {
68787429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis      MappingInfo.setNoWarningAsError(true);
68887429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis      MappingInfo.setNoErrorAsFatal(true);
68987429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    }
69087429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis
69187429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis    return MappingInfo;
69287429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis  }
69387429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis
6940a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  /// ProcessDiag - This is the method used to report a diagnostic that is
6950a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  /// finally fully formed.
6965e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  ///
6975e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// \returns true if the diagnostic was emitted, false if it was
6985e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// suppressed.
69933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  bool ProcessDiag() {
70033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis    return Diags->ProcessDiag(*this);
70133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  }
702f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis
703f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis  friend class ASTReader;
704f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis  friend class ASTWriter;
7053cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner};
7063cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
7079c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis/// \brief RAII class that determines when any errors have occurred
7089c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis/// between the time the instance was created and the time it was
7099c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis/// queried.
7109c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidisclass DiagnosticErrorTrap {
711d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &Diag;
712c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis  unsigned NumErrors;
713c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis  unsigned NumUnrecoverableErrors;
7149c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis
7159c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidispublic:
716d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  explicit DiagnosticErrorTrap(DiagnosticsEngine &Diag)
717add80bb3957dba1d9389304453c0a4c975768bd7John McCall    : Diag(Diag) { reset(); }
7189c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis
7199c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  /// \brief Determine whether any errors have occurred since this
7209c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  /// object instance was created.
7219c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  bool hasErrorOccurred() const {
722c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis    return Diag.TrapNumErrorsOccurred > NumErrors;
723add80bb3957dba1d9389304453c0a4c975768bd7John McCall  }
724add80bb3957dba1d9389304453c0a4c975768bd7John McCall
725add80bb3957dba1d9389304453c0a4c975768bd7John McCall  /// \brief Determine whether any unrecoverable errors have occurred since this
726add80bb3957dba1d9389304453c0a4c975768bd7John McCall  /// object instance was created.
727add80bb3957dba1d9389304453c0a4c975768bd7John McCall  bool hasUnrecoverableErrorOccurred() const {
728c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis    return Diag.TrapNumUnrecoverableErrorsOccurred > NumUnrecoverableErrors;
7299c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  }
7309c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis
7319c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis  // Set to initial state of "no errors occurred".
732add80bb3957dba1d9389304453c0a4c975768bd7John McCall  void reset() {
733c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis    NumErrors = Diag.TrapNumErrorsOccurred;
734c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis    NumUnrecoverableErrors = Diag.TrapNumUnrecoverableErrorsOccurred;
735add80bb3957dba1d9389304453c0a4c975768bd7John McCall  }
7369c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis};
7379c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis
7383cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===//
7393cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner// DiagnosticBuilder
7403cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===//
7413cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
7423cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// DiagnosticBuilder - This is a little helper class used to produce
743d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// diagnostics.  This is constructed by the DiagnosticsEngine::Report method,
744d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// and allows insertion of extra information (arguments and source ranges) into
745d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// the currently "in flight" diagnostic.  When the temporary for the builder is
7463cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// destroyed, the diagnostic is issued.
7473cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner///
7483cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// Note that many of these will be created as temporary objects (many call
7493cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// sites), so we want them to be small and we never want their address taken.
7503cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// This ensures that compilers with somewhat reasonable optimizers will promote
7513cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// the common fields to registers, eliminating increments of the NumArgs field,
7523cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// for example.
7533cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerclass DiagnosticBuilder {
754d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  mutable DiagnosticsEngine *DiagObj;
755981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar  mutable unsigned NumArgs, NumRanges, NumFixits;
7561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
7573cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  void operator=(const DiagnosticBuilder&); // DO NOT IMPLEMENT
758d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  friend class DiagnosticsEngine;
759d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  explicit DiagnosticBuilder(DiagnosticsEngine *diagObj)
760981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0) {
761981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!");
762cbf46a0b2bb2b47d6e13437e0d52cc583c5ce539Argyrios Kyrtzidis  }
763ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor
7649b623639378d53a675921ddfa7316034d571881eDouglas Gregor  friend class PartialDiagnostic;
765b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor
766b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregorprotected:
767b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregor  void FlushCounts();
76806265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar
76906265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  /// isActive - Determine whether this diagnostic is still active.
77006265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  bool isActive() const { return DiagObj != 0; }
77106265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar
77206265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  /// \brief Retrieve the active diagnostic ID.
77306265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  ///
77406265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  /// \pre \c isActive()
77506265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  unsigned getDiagID() const {
77606265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar    assert(isActive() && "DiagnosticsEngine is inactive");
77706265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar    return DiagObj->CurDiagID;
77806265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  }
77906265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar
78006265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  /// \brief Retrieve the active diagnostic's location.
78106265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  ///
78206265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  /// \pre \c isActive()
78306265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar  SourceLocation getLocation() const { return DiagObj->CurDiagLoc; }
7849b623639378d53a675921ddfa7316034d571881eDouglas Gregor
7851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic:
7860a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  /// Copy constructor.  When copied, this "takes" the diagnostic info from the
7870a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  /// input and neuters it.
7883cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DiagnosticBuilder(const DiagnosticBuilder &D) {
7890a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner    DiagObj = D.DiagObj;
7900a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner    D.DiagObj = 0;
79125a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor    NumArgs = D.NumArgs;
79225a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor    NumRanges = D.NumRanges;
793981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    NumFixits = D.NumFixits;
7940a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  }
79525a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor
7965e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// \brief Simple enumeration value used to give a name to the
7975e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// suppress-diagnostic constructor.
7985e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  enum SuppressKind { Suppress };
7995e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor
8005e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// \brief Create an empty DiagnosticBuilder object that represents
8015e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// no actual diagnostic.
8021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  explicit DiagnosticBuilder(SuppressKind)
803981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    : DiagObj(0), NumArgs(0), NumRanges(0), NumFixits(0) { }
8045e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor
80525a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor  /// \brief Force the diagnostic builder to emit the diagnostic now.
80625a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor  ///
80725a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor  /// Once this function has been called, the DiagnosticBuilder object
80825a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor  /// should not be used again before it is destroyed.
8095e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  ///
8105e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// \returns true if a diagnostic was emitted, false if the
8115e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor  /// diagnostic was suppressed.
81293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor  bool Emit();
81325a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor
81425a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor  /// Destructor - The dtor emits the diagnostic if it hasn't already
81525a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor  /// been emitted.
81653c83b32550b3f29db2419160fa2e3684e420556Daniel Dunbar  ~DiagnosticBuilder() {
81753c83b32550b3f29db2419160fa2e3684e420556Daniel Dunbar    if (DiagObj)
81853c83b32550b3f29db2419160fa2e3684e420556Daniel Dunbar      Emit();
81953c83b32550b3f29db2419160fa2e3684e420556Daniel Dunbar  }
8209b623639378d53a675921ddfa7316034d571881eDouglas Gregor
8219b623639378d53a675921ddfa7316034d571881eDouglas Gregor  /// \brief Clear out the current diagnostic.
8229b623639378d53a675921ddfa7316034d571881eDouglas Gregor  void Clear() { DiagObj = 0; }
8239b623639378d53a675921ddfa7316034d571881eDouglas Gregor
8243cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  /// Operator bool: conversion of DiagnosticBuilder to bool always returns
8253cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  /// true.  This allows is to be used in boolean error contexts like:
8263cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  /// return Diag(...);
8273cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  operator bool() const { return true; }
8283cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
829686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void AddString(StringRef S) const {
830d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(NumArgs < DiagnosticsEngine::MaxArguments &&
8313cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "Too many arguments to diagnostic!");
8325e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor    if (DiagObj) {
833d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie      DiagObj->DiagArgumentsKind[NumArgs] = DiagnosticsEngine::ak_std_string;
8345e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor      DiagObj->DiagArgumentsStr[NumArgs++] = S;
8355e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor    }
8363cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  }
8371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
838d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const {
839d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(NumArgs < DiagnosticsEngine::MaxArguments &&
8403cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "Too many arguments to diagnostic!");
8415e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor    if (DiagObj) {
8425e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor      DiagObj->DiagArgumentsKind[NumArgs] = Kind;
8435e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor      DiagObj->DiagArgumentsVal[NumArgs++] = V;
8445e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor    }
8450a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  }
8461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8470a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  void AddSourceRange(const CharSourceRange &R) const {
848981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    assert(NumRanges < DiagnosticsEngine::MaxRanges &&
8493cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "Too many arguments to diagnostic!");
8505e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor    if (DiagObj)
85151c6d384551674facc19f745ecf6e289d28dc55fDouglas Gregor      DiagObj->DiagRanges[NumRanges++] = R;
8521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  }
8534b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
854849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  void AddFixItHint(const FixItHint &Hint) const {
855981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    assert(NumFixits < DiagnosticsEngine::MaxFixItHints &&
856981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar           "Too many arguments to diagnostic!");
8575e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor    if (DiagObj)
858981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar      DiagObj->DiagFixItHints[NumFixits++] = Hint;
8594b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  }
8603cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner};
8613cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
8623cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
863686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                           StringRef S) {
8643cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DB.AddString(S);
8653cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DB;
8663cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
8673cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
8683cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
8693cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner                                           const char *Str) {
8703cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(Str),
871d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                  DiagnosticsEngine::ak_c_string);
8723cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DB;
8733cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
8743cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
8753cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, int I) {
876d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
8773cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DB;
8783cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
8793cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
8803bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidisinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,bool I) {
881d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint);
8823bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidis  return DB;
8833bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidis}
8843bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidis
8853cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
8863cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner                                           unsigned I) {
887d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint);
8883cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DB;
8893cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
8903cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
8913cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
8923cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner                                           const IdentifierInfo *II) {
8933cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  DB.AddTaggedVal(reinterpret_cast<intptr_t>(II),
894d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                  DiagnosticsEngine::ak_identifierinfo);
8953cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DB;
8963cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
8971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8983f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// Adds a DeclContext to the diagnostic. The enable_if template magic is here
8993f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// so that we only match those arguments that are (statically) DeclContexts;
9003f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// other arguments that derive from DeclContext (e.g., RecordDecls) will not
9013f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// match.
9023f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregortemplate<typename T>
9033f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregorinline
9043f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregortypename llvm::enable_if<llvm::is_same<T, DeclContext>,
9053f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor                         const DiagnosticBuilder &>::type
9063f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregoroperator<<(const DiagnosticBuilder &DB, T *DC) {
9073f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor  DB.AddTaggedVal(reinterpret_cast<intptr_t>(DC),
908d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                  DiagnosticsEngine::ak_declcontext);
9093f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor  return DB;
9103f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor}
9113f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor
9123cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
9133cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner                                           const SourceRange &R) {
9140a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  DB.AddSourceRange(CharSourceRange::getTokenRange(R));
9153cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DB;
9163cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
9174b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
9184b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregorinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
9190a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner                                           const CharSourceRange &R) {
9200a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  DB.AddSourceRange(R);
9210a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  return DB;
9220a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner}
9230a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner
9240a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
925849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor                                           const FixItHint &Hint) {
926849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  DB.AddFixItHint(Hint);
9274b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  return DB;
9284b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor}
929ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor
9303cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// Report - Issue the message to the client.  DiagID is a member of the
9313cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// diag::kind enum.  This actually returns a new instance of DiagnosticBuilder
9323cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// which emits the diagnostics (through ProcessDiag) when it is destroyed.
933d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieinline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc,
93433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis                                            unsigned DiagID){
9353cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
9363cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  CurDiagLoc = Loc;
9373cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  CurDiagID = DiagID;
9383cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner  return DiagnosticBuilder(this);
9393cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}
940d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieinline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) {
94133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  return Report(SourceLocation(), DiagID);
9420f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar}
9433cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner
9443cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===//
94540847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie// Diagnostic
9463cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===//
9471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
94840847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie/// Diagnostic - This is a little helper class (which is basically a smart
949d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// pointer that forward info from DiagnosticsEngine) that allows clients to
950d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie/// enquire about the currently in-flight diagnostic.
95140847cfb58acc3cac7d68727df9455ac45f2e118David Blaikieclass Diagnostic {
952d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  const DiagnosticsEngine *DiagObj;
953686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef StoredDiagMessage;
9543cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerpublic:
95540847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie  explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {}
95640847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie  Diagnostic(const DiagnosticsEngine *DO, StringRef storedDiagMessage)
957e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis    : DiagObj(DO), StoredDiagMessage(storedDiagMessage) {}
9581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
959d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  const DiagnosticsEngine *getDiags() const { return DiagObj; }
960b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner  unsigned getID() const { return DiagObj->CurDiagID; }
96133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  const SourceLocation &getLocation() const { return DiagObj->CurDiagLoc; }
96233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  bool hasSourceManager() const { return DiagObj->hasSourceManager(); }
96333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis  SourceManager &getSourceManager() const { return DiagObj->getSourceManager();}
9641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9650a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  unsigned getNumArgs() const { return DiagObj->NumDiagArgs; }
9661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
96773d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// getArgKind - Return the kind of the specified index.  Based on the kind
96873d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// of argument, the accessors below can be used to get the value.
969d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const {
9703cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner    assert(Idx < getNumArgs() && "Argument index out of range!");
971d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    return (DiagnosticsEngine::ArgumentKind)DiagObj->DiagArgumentsKind[Idx];
97273d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  }
9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
97473d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// getArgStdStr - Return the provided argument string specified by Idx.
97573d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  const std::string &getArgStdStr(unsigned Idx) const {
976d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(getArgKind(Idx) == DiagnosticsEngine::ak_std_string &&
9773cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "invalid argument accessor!");
97873d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner    return DiagObj->DiagArgumentsStr[Idx];
97973d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  }
9801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98173d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  /// getArgCStr - Return the specified C string argument.
98273d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner  const char *getArgCStr(unsigned Idx) const {
983d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(getArgKind(Idx) == DiagnosticsEngine::ak_c_string &&
9843cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "invalid argument accessor!");
98573d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner    return reinterpret_cast<const char*>(DiagObj->DiagArgumentsVal[Idx]);
9860a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  }
9871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
98830bc96544346bea42921cf6837e66cef80d664b4Chris Lattner  /// getArgSInt - Return the specified signed integer argument.
98930bc96544346bea42921cf6837e66cef80d664b4Chris Lattner  int getArgSInt(unsigned Idx) const {
990d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(getArgKind(Idx) == DiagnosticsEngine::ak_sint &&
9913cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "invalid argument accessor!");
99230bc96544346bea42921cf6837e66cef80d664b4Chris Lattner    return (int)DiagObj->DiagArgumentsVal[Idx];
99330bc96544346bea42921cf6837e66cef80d664b4Chris Lattner  }
9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
99530bc96544346bea42921cf6837e66cef80d664b4Chris Lattner  /// getArgUInt - Return the specified unsigned integer argument.
99630bc96544346bea42921cf6837e66cef80d664b4Chris Lattner  unsigned getArgUInt(unsigned Idx) const {
997d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(getArgKind(Idx) == DiagnosticsEngine::ak_uint &&
9983cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "invalid argument accessor!");
99930bc96544346bea42921cf6837e66cef80d664b4Chris Lattner    return (unsigned)DiagObj->DiagArgumentsVal[Idx];
100030bc96544346bea42921cf6837e66cef80d664b4Chris Lattner  }
10011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100243b628cd47ecdc3caf640d79b3ad7ecef0f2c285Chris Lattner  /// getArgIdentifier - Return the specified IdentifierInfo argument.
100343b628cd47ecdc3caf640d79b3ad7ecef0f2c285Chris Lattner  const IdentifierInfo *getArgIdentifier(unsigned Idx) const {
1004d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(getArgKind(Idx) == DiagnosticsEngine::ak_identifierinfo &&
10053cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner           "invalid argument accessor!");
10069634379265855f1628190e926d9aaf1fb4a5d90eChris Lattner    return reinterpret_cast<IdentifierInfo*>(DiagObj->DiagArgumentsVal[Idx]);
100743b628cd47ecdc3caf640d79b3ad7ecef0f2c285Chris Lattner  }
10081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
100922caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  /// getRawArg - Return the specified non-string argument in an opaque form.
101022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  intptr_t getRawArg(unsigned Idx) const {
1011d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie    assert(getArgKind(Idx) != DiagnosticsEngine::ak_std_string &&
101222caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner           "invalid argument accessor!");
101322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner    return DiagObj->DiagArgumentsVal[Idx];
101422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner  }
10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10170a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  /// getNumRanges - Return the number of source ranges associated with this
10180a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  /// diagnostic.
10190a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  unsigned getNumRanges() const {
10200a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner    return DiagObj->NumDiagRanges;
10210a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  }
10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10230a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  const CharSourceRange &getRange(unsigned Idx) const {
10240a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner    assert(Idx < DiagObj->NumDiagRanges && "Invalid diagnostic range index!");
102551c6d384551674facc19f745ecf6e289d28dc55fDouglas Gregor    return DiagObj->DiagRanges[Idx];
10260a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner  }
10271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
102828409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth  /// \brief Return an array reference for this diagnostic's ranges.
102928409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth  ArrayRef<CharSourceRange> getRanges() const {
103028409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth    return llvm::makeArrayRef(DiagObj->DiagRanges, DiagObj->NumDiagRanges);
103128409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth  }
103228409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth
1033849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  unsigned getNumFixItHints() const {
1034981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    return DiagObj->NumDiagFixItHints;
10354b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  }
10364b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
1037849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  const FixItHint &getFixItHint(unsigned Idx) const {
1038981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    assert(Idx < getNumFixItHints() && "Invalid index!");
1039981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    return DiagObj->DiagFixItHints[Idx];
10404b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  }
10414b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
1042849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  const FixItHint *getFixItHints() const {
1043981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar    return getNumFixItHints()? DiagObj->DiagFixItHints : 0;
10444b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor  }
10454b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor
1046f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner  /// FormatDiagnostic - Format this diagnostic into a string, substituting the
1047f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner  /// formal arguments into the %0 slots.  The result is appended onto the Str
1048f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner  /// array.
1049686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void FormatDiagnostic(SmallVectorImpl<char> &OutStr) const;
10509f28614bf1a8387000d8df57a713fcf69e198145John McCall
10519f28614bf1a8387000d8df57a713fcf69e198145John McCall  /// FormatDiagnostic - Format the given format-string into the
10529f28614bf1a8387000d8df57a713fcf69e198145John McCall  /// output buffer using the arguments stored in this diagnostic.
10539f28614bf1a8387000d8df57a713fcf69e198145John McCall  void FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
1054686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                        SmallVectorImpl<char> &OutStr) const;
1055a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor};
1056a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1057a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/**
1058d3ab63e0f66429abf2a3e4cde889e420e41e8790Douglas Gregor * \brief Represents a diagnostic in a form that can be retained until its
1059d3ab63e0f66429abf2a3e4cde889e420e41e8790Douglas Gregor * corresponding source manager is destroyed.
1060a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */
1061a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorclass StoredDiagnostic {
1062aa5f135f8db82b5e5fb1640fd51f8078e0b2d82dDouglas Gregor  unsigned ID;
1063d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine::Level Level;
1064a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  FullSourceLoc Loc;
1065a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  std::string Message;
10660a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  std::vector<CharSourceRange> Ranges;
1067849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  std::vector<FixItHint> FixIts;
1068a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1069a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorpublic:
1070a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  StoredDiagnostic();
107140847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie  StoredDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info);
1072d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
1073686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                   StringRef Message);
1074d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID,
1075686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                   StringRef Message, FullSourceLoc Loc,
10762d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner                   ArrayRef<CharSourceRange> Ranges,
10772d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner                   ArrayRef<FixItHint> Fixits);
1078a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  ~StoredDiagnostic();
1079a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1080a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  /// \brief Evaluates true when this object stores a diagnostic.
1081a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  operator bool() const { return Message.size() > 0; }
1082a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1083aa5f135f8db82b5e5fb1640fd51f8078e0b2d82dDouglas Gregor  unsigned getID() const { return ID; }
1084d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine::Level getLevel() const { return Level; }
1085a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  const FullSourceLoc &getLocation() const { return Loc; }
1086686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef getMessage() const { return Message; }
1087c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor
1088c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor  void setLocation(FullSourceLoc Loc) { this->Loc = Loc; }
1089c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor
10900a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner  typedef std::vector<CharSourceRange>::const_iterator range_iterator;
1091a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  range_iterator range_begin() const { return Ranges.begin(); }
1092a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  range_iterator range_end() const { return Ranges.end(); }
1093a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  unsigned range_size() const { return Ranges.size(); }
10946700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek
10956700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek  ArrayRef<CharSourceRange> getRanges() const {
10966700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek    return llvm::makeArrayRef(Ranges);
10976700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek  }
10986700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek
1099a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor
1100849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor  typedef std::vector<FixItHint>::const_iterator fixit_iterator;
1101a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  fixit_iterator fixit_begin() const { return FixIts.begin(); }
1102a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  fixit_iterator fixit_end() const { return FixIts.end(); }
1103a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor  unsigned fixit_size() const { return FixIts.size(); }
11046700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek
11056700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek  ArrayRef<FixItHint> getFixIts() const {
11066700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek    return llvm::makeArrayRef(FixIts);
11076700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek  }
11085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111078ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie/// DiagnosticConsumer - This is an abstract interface implemented by clients of
11115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// the front-end, which formats and prints fully processed diagnostics.
111278ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikieclass DiagnosticConsumer {
1113ab41b97c3cddf1bcdd8bf82ab09ed3ceafcd05b1Argyrios Kyrtzidisprotected:
1114f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  unsigned NumWarnings;       // Number of warnings reported
1115f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  unsigned NumErrors;         // Number of errors reported
1116f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis
11175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
111878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  DiagnosticConsumer() : NumWarnings(0), NumErrors(0) { }
1119f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis
1120f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  unsigned getNumErrors() const { return NumErrors; }
1121f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  unsigned getNumWarnings() const { return NumWarnings; }
112261d679ab2831b161c857cf3f974312fbd4ef1efdArgyrios Kyrtzidis  virtual void clear() { NumWarnings = NumErrors = 0; }
1123f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis
112478ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  virtual ~DiagnosticConsumer();
11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1126efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// BeginSourceFile - Callback to inform the diagnostic client that processing
1127efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// of a source file is beginning.
1128efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  ///
1129efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// Note that diagnostics may be emitted outside the processing of a source
1130efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// file, for example during the parsing of command line options. However,
1131efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// diagnostics with source range information are required to only be emitted
1132efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// in between BeginSourceFile() and EndSourceFile().
1133efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  ///
1134efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// \arg LO - The language options for the source file being processed.
1135efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// \arg PP - The preprocessor object being used for the source; this optional
1136efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// and may not be present, for example when processing AST source files.
11377d90199f109290e9d587479a481a2850d390b552Daniel Dunbar  virtual void BeginSourceFile(const LangOptions &LangOpts,
11387d90199f109290e9d587479a481a2850d390b552Daniel Dunbar                               const Preprocessor *PP = 0) {}
1139efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar
1140efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// EndSourceFile - Callback to inform the diagnostic client that processing
1141efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// of a source file has ended. The diagnostic client should assume that any
1142efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// objects made available via \see BeginSourceFile() are inaccessible.
1143efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  virtual void EndSourceFile() {}
11441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
114529f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis  /// \brief Callback to inform the diagnostic client that processing of all
114629f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis  /// source files has ended.
114729f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis  virtual void finish() {}
114829f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis
1149cabe66811fe43835b8c5a0854552768fc53261e3Ted Kremenek  /// IncludeInDiagnosticCounts - This method (whose default implementation
1150efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar  /// returns true) indicates whether the diagnostics handled by this
115178ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  /// DiagnosticConsumer should be included in the number of diagnostics
115278ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie  /// reported by DiagnosticsEngine.
1153cabe66811fe43835b8c5a0854552768fc53261e3Ted Kremenek  virtual bool IncludeInDiagnosticCounts() const;
11545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
11565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  /// capturing it to a log as needed.
1157f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  ///
1158f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  /// Default implementation just keeps track of the total number of warnings
1159f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis  /// and errors.
1160d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
116140847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie                                const Diagnostic &Info);
1162aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor
1163aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  /// \brief Clone the diagnostic consumer, producing an equivalent consumer
1164aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  /// that can be used in a different context.
1165aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  virtual DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const = 0;
1166aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor};
1167aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor
1168aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor/// IgnoringDiagConsumer - This is a diagnostic client that just ignores all
1169aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor/// diags.
1170aee526e77657afd1600276450e9c346953ad51d7Douglas Gregorclass IgnoringDiagConsumer : public DiagnosticConsumer {
117199ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie  virtual void anchor();
1172aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
1173aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor                        const Diagnostic &Info) {
1174aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor    // Just ignore it.
1175aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  }
1176aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  DiagnosticConsumer *clone(DiagnosticsEngine &Diags) const {
1177aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor    return new IgnoringDiagConsumer();
1178aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor  }
11795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
11805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
11825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
11835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
1184