Diagnostic.h revision cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540
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//===----------------------------------------------------------------------===// 92f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// 102f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \file 112f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// \brief Defines the Diagnostic-related interfaces. 122f7f5b1f5ff023cb8c4008ae53a12b09e3ea2622James Dennett/// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_DIAGNOSTIC_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_DIAGNOSTIC_H 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis#include "clang/Basic/DiagnosticIDs.h" 19dc7b641574a733624489bd87fc7061771edf2113Douglas Gregor#include "clang/Basic/DiagnosticOptions.h" 202eefd8657c233bc7c9330acfe475fc270bbe7cabTed Kremenek#include "clang/Basic/SourceLocation.h" 21f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include "llvm/ADT/ArrayRef.h" 220827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis#include "llvm/ADT/DenseMap.h" 2328019772db70d4547be05a042eb950bc910f134fDouglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 24bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor#include "llvm/ADT/OwningPtr.h" 253f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor#include "llvm/Support/type_traits.h" 260827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis#include <list> 2730a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include <vector> 28f4c839657742b823cea1a95b18422f1ba74d3dddChris Lattner 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 3078ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie class DiagnosticConsumer; 3133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis class DiagnosticBuilder; 3202c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor class DiagnosticOptions; 33d42ffbd22fc7eb61321f6a88173ee424991f01c6Ted Kremenek class IdentifierInfo; 3433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis class DeclContext; 3540469651a3f8379dc0f32df69e9bade06a2aad36Chris Lattner class LangOptions; 367d90199f109290e9d587479a481a2850d390b552Daniel Dunbar class Preprocessor; 379c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis class DiagnosticErrorTrap; 38e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis class StoredDiagnostic; 391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// \brief Annotates a diagnostic with some code that should be 414b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// inserted, removed, or replaced to fix the problem. 424b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// 434b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// This kind of hint should be used when we are certain that the 444b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// introduction, removal, or modification of a particular (small!) 454b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// amount of code will correct a compilation error. The compiler 464b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// should also provide full recovery from such errors, such that 47b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor/// suppressing the diagnostic output can still result in successful 484b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor/// compilation. 49849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregorclass FixItHint { 504b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregorpublic: 51783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor /// \brief Code that should be replaced to correct the error. Empty for an 52783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor /// insertion hint. 530a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner CharSourceRange RemoveRange; 544b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 5530660a898545416f0fea2d717f16f75640001e38Ted Kremenek /// \brief Code in the specific range that should be inserted in the insertion 5630660a898545416f0fea2d717f16f75640001e38Ted Kremenek /// location. 5730660a898545416f0fea2d717f16f75640001e38Ted Kremenek CharSourceRange InsertFromRange; 5830660a898545416f0fea2d717f16f75640001e38Ted Kremenek 594b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// \brief The actual code to insert at the insertion location, as a 604b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// string. 614b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor std::string CodeToInsert; 624b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 6330660a898545416f0fea2d717f16f75640001e38Ted Kremenek bool BeforePreviousInsertions; 6430660a898545416f0fea2d717f16f75640001e38Ted Kremenek 654b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// \brief Empty code modification hint, indicating that no code 664b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// modification is known. 6730660a898545416f0fea2d717f16f75640001e38Ted Kremenek FixItHint() : BeforePreviousInsertions(false) { } 684b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 692f019aadc96f8fa3185c684c7150bd596d045064Anders Carlsson bool isNull() const { 70783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor return !RemoveRange.isValid(); 712f019aadc96f8fa3185c684c7150bd596d045064Anders Carlsson } 722f019aadc96f8fa3185c684c7150bd596d045064Anders Carlsson 734b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// \brief Create a code modification hint that inserts the given 744b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// code string at a specific location. 75849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor static FixItHint CreateInsertion(SourceLocation InsertionLoc, 7630660a898545416f0fea2d717f16f75640001e38Ted Kremenek StringRef Code, 7730660a898545416f0fea2d717f16f75640001e38Ted Kremenek bool BeforePreviousInsertions = false) { 78849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor FixItHint Hint; 79783c56f47745f719590b17afd7ed937bf2407b53Douglas Gregor Hint.RemoveRange = 804a2ef80d896c1bac38ce113ec19a8d509a619288Nico Weber CharSourceRange::getCharRange(InsertionLoc, InsertionLoc); 81b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor Hint.CodeToInsert = Code; 8230660a898545416f0fea2d717f16f75640001e38Ted Kremenek Hint.BeforePreviousInsertions = BeforePreviousInsertions; 8330660a898545416f0fea2d717f16f75640001e38Ted Kremenek return Hint; 8430660a898545416f0fea2d717f16f75640001e38Ted Kremenek } 8530660a898545416f0fea2d717f16f75640001e38Ted Kremenek 8630660a898545416f0fea2d717f16f75640001e38Ted Kremenek /// \brief Create a code modification hint that inserts the given 87af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// code from \p FromRange at a specific location. 8830660a898545416f0fea2d717f16f75640001e38Ted Kremenek static FixItHint CreateInsertionFromRange(SourceLocation InsertionLoc, 8930660a898545416f0fea2d717f16f75640001e38Ted Kremenek CharSourceRange FromRange, 9030660a898545416f0fea2d717f16f75640001e38Ted Kremenek bool BeforePreviousInsertions = false) { 9130660a898545416f0fea2d717f16f75640001e38Ted Kremenek FixItHint Hint; 9230660a898545416f0fea2d717f16f75640001e38Ted Kremenek Hint.RemoveRange = 934a2ef80d896c1bac38ce113ec19a8d509a619288Nico Weber CharSourceRange::getCharRange(InsertionLoc, InsertionLoc); 9430660a898545416f0fea2d717f16f75640001e38Ted Kremenek Hint.InsertFromRange = FromRange; 9530660a898545416f0fea2d717f16f75640001e38Ted Kremenek Hint.BeforePreviousInsertions = BeforePreviousInsertions; 96b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor return Hint; 97b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor } 984b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 994b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// \brief Create a code modification hint that removes the given 1004b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// source range. 1010a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner static FixItHint CreateRemoval(CharSourceRange RemoveRange) { 102849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor FixItHint Hint; 103b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor Hint.RemoveRange = RemoveRange; 104b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor return Hint; 105b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor } 1060a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner static FixItHint CreateRemoval(SourceRange RemoveRange) { 1070a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner return CreateRemoval(CharSourceRange::getTokenRange(RemoveRange)); 1080a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner } 1090a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner 1104b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// \brief Create a code modification hint that replaces the given 1114b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor /// source range with the given code string. 1120a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner static FixItHint CreateReplacement(CharSourceRange RemoveRange, 113686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Code) { 114849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor FixItHint Hint; 115b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor Hint.RemoveRange = RemoveRange; 116b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor Hint.CodeToInsert = Code; 117b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor return Hint; 118b2fb6de9070fea9abc56c8e8d5469066e964cefeDouglas Gregor } 1190a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner 1200a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner static FixItHint CreateReplacement(SourceRange RemoveRange, 121686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Code) { 1220a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner return CreateReplacement(CharSourceRange::getTokenRange(RemoveRange), Code); 1230a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner } 1244b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor}; 1254b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 126af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief Concrete class used by the front-end to report problems and issues. 127af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// 128af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// This massages the diagnostics (e.g. handling things like "report warnings 129af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// as errors" and passes them off to the DiagnosticConsumer for reporting to 130af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// the user. DiagnosticsEngine is tied to one translation unit and one 131af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// SourceManager. 132c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmithclass DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> { 133182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattnerpublic: 134af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief The level of the diagnostic, after it has been through mapping. 135182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner enum Level { 13633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Ignored = DiagnosticIDs::Ignored, 13733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Note = DiagnosticIDs::Note, 13833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Warning = DiagnosticIDs::Warning, 13933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Error = DiagnosticIDs::Error, 14033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis Fatal = DiagnosticIDs::Fatal 141182745ae7892bca0842d9c023370ade5f8d1c6e8Chris Lattner }; 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 143af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief How do we handle otherwise-unmapped extension? 144af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 145af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This is controlled by -pedantic and -pedantic-errors. 146b54b276a920246c595a0498da281821eb9d22996Chris Lattner enum ExtensionHandling { 147b54b276a920246c595a0498da281821eb9d22996Chris Lattner Ext_Ignore, Ext_Warn, Ext_Error 148b54b276a920246c595a0498da281821eb9d22996Chris Lattner }; 1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1503fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner enum ArgumentKind { 151af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_std_string, ///< std::string 152af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_c_string, ///< const char * 153af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_sint, ///< int 154af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_uint, ///< unsigned 155af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_identifierinfo, ///< IdentifierInfo 156af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_qualtype, ///< QualType 157af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_declarationname, ///< DeclarationName 158af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_nameddecl, ///< NamedDecl * 159af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_nestednamespec, ///< NestedNameSpecifier * 160af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_declcontext, ///< DeclContext * 161af50aab0c317462129d73ae8000c6394c718598dJames Dennett ak_qualtype_pair ///< pair<QualType, QualType> 1623fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner }; 1635edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin 164af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Represents on argument value, which is a union discriminated 165af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// by ArgumentKind, with a value. 166b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner typedef std::pair<ArgumentKind, intptr_t> ArgumentValue; 167ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor 1681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumpprivate: 16927ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner unsigned char AllExtensionsSilenced; // Used by __extension__ 170b54b276a920246c595a0498da281821eb9d22996Chris Lattner bool IgnoreAllWarnings; // Ignore all warnings: -w 1711e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek bool WarningsAsErrors; // Treat warnings like errors. 1721e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek bool EnableAllWarnings; // Enable all warnings. 173e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner bool ErrorsAsFatal; // Treat errors like fatal errors. 174b54b276a920246c595a0498da281821eb9d22996Chris Lattner bool SuppressSystemWarnings; // Suppress warnings in system headers. 17581b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor bool SuppressAllDiagnostics; // Suppress all diagnostics. 176246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu bool ElideType; // Elide common types of templates. 177246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu bool PrintTemplateTree; // Print a tree when comparing templates. 178246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu bool ShowColors; // Color printing is enabled. 1795edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin OverloadsShown ShowOverloads; // Which overload candidates to show. 180c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner unsigned ErrorLimit; // Cap of # errors emitted, 0 -> no limit. 181575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor unsigned TemplateBacktraceLimit; // Cap on depth of template backtrace stack, 182575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor // 0 -> no limit. 18308d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith unsigned ConstexprBacktraceLimit; // Cap on depth of constexpr evaluation 18408d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith // backtrace stack, 0 -> no limit. 185b54b276a920246c595a0498da281821eb9d22996Chris Lattner ExtensionHandling ExtBehavior; // Map extensions onto warnings or errors? 186c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith IntrusiveRefCntPtr<DiagnosticIDs> Diags; 18702c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; 18878ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *Client; 18933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis bool OwnsDiagClient; 19033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis SourceManager *SourceMgr; 1910827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 192af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Mapping information for diagnostics. 193af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 194af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// Mapping info is packed into four bits per diagnostic. The low three 195af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// bits are the mapping (an instance of diag::Mapping), or zero if unset. 196af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// The high bit is set when the mapping was established as a user mapping. 197af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// If the high bit is clear, then the low bits are set to the default 198af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// value, and should be mapped with -pedantic, -Werror, etc. 1990827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// 2003efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis /// A new DiagState is created and kept around when diagnostic pragmas modify 2013efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis /// the state so that we know what is the diagnostic state at any given 2023efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis /// source location. 2030827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis class DiagState { 204b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar llvm::DenseMap<unsigned, DiagnosticMappingInfo> DiagMap; 2053c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer 2063c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer public: 207ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::iterator 208b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar iterator; 209ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar typedef llvm::DenseMap<unsigned, DiagnosticMappingInfo>::const_iterator 210ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar const_iterator; 2113efd52cf8f4e57c5571bd8cc3168264c3bc46a1eArgyrios Kyrtzidis 212b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar void setMappingInfo(diag::kind Diag, DiagnosticMappingInfo Info) { 213b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar DiagMap[Diag] = Info; 214b1c99c679adb53be8f478d08be83af6c9c22ae4bDaniel Dunbar } 2153c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer 216ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar DiagnosticMappingInfo &getOrAddMappingInfo(diag::kind Diag); 217ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar 218ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar const_iterator begin() const { return DiagMap.begin(); } 219ba494c64365d78b1cdb6baea4d1e79263389fda9Daniel Dunbar const_iterator end() const { return DiagMap.end(); } 2200827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis }; 2213c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer 2220827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief Keeps and automatically disposes all DiagStates that we create. 2230827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis std::list<DiagState> DiagStates; 2240827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2250827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief Represents a point in source where the diagnostic state was 226af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// modified because of a pragma. 227af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 228af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 'Loc' can be null if the point represents the diagnostic state 229af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// modifications done through the command-line. 2300827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis struct DiagStatePoint { 2310827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis DiagState *State; 2320827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis FullSourceLoc Loc; 2330827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis DiagStatePoint(DiagState *State, FullSourceLoc Loc) 2340827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis : State(State), Loc(Loc) { } 2350827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2360827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis bool operator<(const DiagStatePoint &RHS) const { 2370827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis // If Loc is invalid it means it came from <command-line>, in which case 2380827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis // we regard it as coming before any valid source location. 2390827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis if (RHS.Loc.isInvalid()) 2400827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return false; 2410827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis if (Loc.isInvalid()) 2420827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return true; 2430827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return Loc.isBeforeInTranslationUnitThan(RHS.Loc); 2443c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer } 2453c2d3016adec79c81c4efff64e208fd3ecdd92aeBenjamin Kramer }; 24604ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner 247af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief A sorted vector of all DiagStatePoints representing changes in 248af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// diagnostic state due to diagnostic pragmas. 249af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 250af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// The vector is always sorted according to the SourceLocation of the 251af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// DiagStatePoint. 2520827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis typedef std::vector<DiagStatePoint> DiagStatePointsTy; 2530827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis mutable DiagStatePointsTy DiagStatePoints; 2540827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2550827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief Keeps the DiagState that was active during each diagnostic 'push' 2560827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// so we can get back at it when we 'pop'. 2570827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis std::vector<DiagState *> DiagStateOnPushStack; 2580827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2590827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis DiagState *GetCurDiagState() const { 2600827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis assert(!DiagStatePoints.empty()); 2610827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis return DiagStatePoints.back().State; 2620827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 2630827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2640827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis void PushDiagStatePoint(DiagState *State, SourceLocation L) { 26500aae5243d965aa7bcee81a39ba0900c7869be21Richard Smith FullSourceLoc Loc(L, getSourceManager()); 2660827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis // Make sure that DiagStatePoints is always sorted according to Loc. 26700aae5243d965aa7bcee81a39ba0900c7869be21Richard Smith assert(Loc.isValid() && "Adding invalid loc point"); 26800aae5243d965aa7bcee81a39ba0900c7869be21Richard Smith assert(!DiagStatePoints.empty() && 26900aae5243d965aa7bcee81a39ba0900c7869be21Richard Smith (DiagStatePoints.back().Loc.isInvalid() || 2700827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis DiagStatePoints.back().Loc.isBeforeInTranslationUnitThan(Loc)) && 2710827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis "Previous point loc comes after or is the same as new one"); 27200aae5243d965aa7bcee81a39ba0900c7869be21Richard Smith DiagStatePoints.push_back(DiagStatePoint(State, Loc)); 2730827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis } 2740827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis 2750827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \brief Finds the DiagStatePoint that contains the diagnostic state of 2760827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// the given source location. 2770827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis DiagStatePointsTy::iterator GetDiagStatePointForLoc(SourceLocation Loc) const; 27804ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner 279af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Sticky flag set to \c true when an error is emitted. 2805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool ErrorOccurred; 281af50aab0c317462129d73ae8000c6394c718598dJames Dennett 28212f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins /// \brief Sticky flag set to \c true when an "uncompilable error" occurs. 28312f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins /// I.e. an error that was not upgraded from a warning by -Werror. 28412f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins bool UncompilableErrorOccurred; 28512f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins 286af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Sticky flag set to \c true when a fatal error is emitted. 28715221422eda7bac679e38b07512feda49715ef66Chris Lattner bool FatalErrorOccurred; 2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28985bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor /// \brief Indicates that an unrecoverable error has occurred. 29085bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor bool UnrecoverableErrorOccurred; 29185bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor 292c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis /// \brief Counts for DiagnosticErrorTrap to check whether an error occurred 293add80bb3957dba1d9389304453c0a4c975768bd7John McCall /// during a parsing section, e.g. during parsing a function. 294c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis unsigned TrapNumErrorsOccurred; 295c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis unsigned TrapNumUnrecoverableErrorsOccurred; 296add80bb3957dba1d9389304453c0a4c975768bd7John McCall 297af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief The level of the last diagnostic emitted. 298af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 299af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This is used to emit continuation diagnostics with the same level as the 300f5d2328fc849288c3a62e43d065685f516d57091Chris Lattner /// diagnostic that they follow. 30133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis DiagnosticIDs::Level LastDiagLevel; 3025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 303af50aab0c317462129d73ae8000c6394c718598dJames Dennett unsigned NumWarnings; ///< Number of warnings reported 304af50aab0c317462129d73ae8000c6394c718598dJames Dennett unsigned NumErrors; ///< Number of errors reported 305af50aab0c317462129d73ae8000c6394c718598dJames Dennett unsigned NumErrorsSuppressed; ///< Number of errors suppressed 3067bfaaaecb3113f955db31e8d8a51acffd1bc0c27Nico Weber 307af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief A function pointer that converts an opaque diagnostic 308af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// argument to a strings. 309af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 310af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This takes the modifiers and argument that was present in the diagnostic. 311b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner /// 312b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner /// The PrevArgs array (whose length is NumPrevArgs) indicates the previous 313b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner /// arguments formatted for this diagnostic. Implementations of this function 314b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner /// can use this information to avoid redundancy across arguments. 315b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner /// 31622caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner /// This is a hack to avoid a layering violation between libbasic and libsema. 3170673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth typedef void (*ArgToStringFnTy)( 3180673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth ArgumentKind Kind, intptr_t Val, 3190673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth const char *Modifier, unsigned ModifierLen, 3200673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth const char *Argument, unsigned ArgumentLen, 3210673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth const ArgumentValue *PrevArgs, 3220673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth unsigned NumPrevArgs, 323686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> &Output, 3240673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth void *Cookie, 325341785ec52f87c0803ba52dc88faac4e136f8593Bill Wendling ArrayRef<intptr_t> QualTypeVals); 32692dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner void *ArgToStringCookie; 3273fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner ArgToStringFnTy ArgToStringFn; 32893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 32993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief ID of the "delayed" diagnostic, which is a (typically 33093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// fatal) diagnostic that had to be delayed because it was found 33193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// while emitting another diagnostic. 33293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor unsigned DelayedDiagID; 33393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 33493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief First string argument for the delayed diagnostic. 33593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor std::string DelayedDiagArg1; 33693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 33793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Second string argument for the delayed diagnostic. 33893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor std::string DelayedDiagArg2; 33993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 341d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie explicit DiagnosticsEngine( 342c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith const IntrusiveRefCntPtr<DiagnosticIDs> &Diags, 34302c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor DiagnosticOptions *DiagOpts, 34478ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *client = 0, 34533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis bool ShouldOwnClient = true); 346d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie ~DiagnosticsEngine(); 3471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 348c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith const IntrusiveRefCntPtr<DiagnosticIDs> &getDiagnosticIDs() const { 34933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis return Diags; 35033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis } 35133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis 35202c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor /// \brief Retrieve the diagnostic options. 35302c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor DiagnosticOptions &getDiagnosticOptions() const { return *DiagOpts; } 35402c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor 35578ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *getClient() { return Client; } 35678ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie const DiagnosticConsumer *getClient() const { return Client; } 3571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 358d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// \brief Determine whether this \c DiagnosticsEngine object own its client. 35978243658c533168d51fd076fba328437932ba6f1Douglas Gregor bool ownsClient() const { return OwnsDiagClient; } 36078243658c533168d51fd076fba328437932ba6f1Douglas Gregor 361bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor /// \brief Return the current diagnostic client along with ownership of that 362bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor /// client. 36378ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer *takeClient() { 36433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis OwnsDiagClient = false; 36533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis return Client; 36633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis } 36733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis 36833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis bool hasSourceManager() const { return SourceMgr != 0; } 36933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis SourceManager &getSourceManager() const { 37033e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis assert(SourceMgr && "SourceManager not set!"); 37133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis return *SourceMgr; 37233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis } 37333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis void setSourceManager(SourceManager *SrcMgr) { SourceMgr = SrcMgr; } 37433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis 37533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis //===--------------------------------------------------------------------===// 376d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie // DiagnosticsEngine characterization methods, used by a client to customize 377d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie // how diagnostics are emitted. 37833e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis // 37904ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner 380af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Copies the current DiagMappings and pushes the new copy 38104ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner /// onto the top of the stack. 3820827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis void pushMappings(SourceLocation Loc); 38304ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner 384af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Pops the current DiagMappings off the top of the stack, 385af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// causing the new top of the stack to be the active mappings. 386af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 387af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \returns \c true if the pop happens, \c false if there is only one 388af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// DiagMapping on the stack. 3890827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis bool popMappings(SourceLocation Loc); 39004ae2df026b275aae5dddfc0db5ca55ff4e62179Chris Lattner 391bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor /// \brief Set the diagnostic client associated with this diagnostic object. 392bdbb004f38978da0c4a75af3294d1c7b5ff84af1Douglas Gregor /// 39333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis /// \param ShouldOwnClient true if the diagnostic object should take 39433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis /// ownership of \c client. 39578ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie void setClient(DiagnosticConsumer *client, bool ShouldOwnClient = true); 3965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 397af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Specify a limit for the number of errors we should 398af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// emit before giving up. 399af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 400af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// Zero disables the limit. 401c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner void setErrorLimit(unsigned Limit) { ErrorLimit = Limit; } 402b205ac9fcd22b87b41697172d1983c5ae9dabaafChris Lattner 403575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor /// \brief Specify the maximum number of template instantiation 404575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor /// notes to emit along with a given diagnostic. 405575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor void setTemplateBacktraceLimit(unsigned Limit) { 406575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor TemplateBacktraceLimit = Limit; 407575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor } 40808d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith 409575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor /// \brief Retrieve the maximum number of template instantiation 41008d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith /// notes to emit along with a given diagnostic. 411575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor unsigned getTemplateBacktraceLimit() const { 412575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor return TemplateBacktraceLimit; 413575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor } 41408d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith 41508d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith /// \brief Specify the maximum number of constexpr evaluation 41608d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith /// notes to emit along with a given diagnostic. 41708d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith void setConstexprBacktraceLimit(unsigned Limit) { 41808d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith ConstexprBacktraceLimit = Limit; 41908d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith } 42008d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith 42108d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith /// \brief Retrieve the maximum number of constexpr evaluation 42208d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith /// notes to emit along with a given diagnostic. 42308d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith unsigned getConstexprBacktraceLimit() const { 42408d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith return ConstexprBacktraceLimit; 42508d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith } 42608d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith 427af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief When set to true, any unmapped warnings are ignored. 428af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 429af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// If this and WarningsAsErrors are both set, then this one wins. 4305b4681c8ef65808ec4d72ab6081efd24d53d4969Chris Lattner void setIgnoreAllWarnings(bool Val) { IgnoreAllWarnings = Val; } 4315b4681c8ef65808ec4d72ab6081efd24d53d4969Chris Lattner bool getIgnoreAllWarnings() const { return IgnoreAllWarnings; } 4321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 433af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief When set to true, any unmapped ignored warnings are no longer 434af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// ignored. 435af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 436af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// If this and IgnoreAllWarnings are both set, then that one wins. 4371e473ccb0e0f6fd1954bef330f7193c1a3fb3ba1Ted Kremenek void setEnableAllWarnings(bool Val) { EnableAllWarnings = Val; } 43804863a86d15cb8de3361f8c77cedfd025819f174Benjamin Kramer bool getEnableAllWarnings() const { return EnableAllWarnings; } 43904863a86d15cb8de3361f8c77cedfd025819f174Benjamin Kramer 440af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief When set to true, any warnings reported are issued as errors. 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer void setWarningsAsErrors(bool Val) { WarningsAsErrors = Val; } 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool getWarningsAsErrors() const { return WarningsAsErrors; } 4431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 444af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief When set to true, any error reported is made a fatal error. 445e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner void setErrorsAsFatal(bool Val) { ErrorsAsFatal = Val; } 446e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner bool getErrorsAsFatal() const { return ErrorsAsFatal; } 447e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner 448af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief When set to true mask warnings that come from system headers. 4492fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar void setSuppressSystemWarnings(bool Val) { SuppressSystemWarnings = Val; } 4502fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar bool getSuppressSystemWarnings() const { return SuppressSystemWarnings; } 4512fe0997427d92388e66e7573f4b043e7ba285ef0Daniel Dunbar 45281b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor /// \brief Suppress all diagnostics, to silence the front end when we 45381b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor /// know that we don't want any more diagnostics to be passed along to the 45481b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor /// client 45581b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor void setSuppressAllDiagnostics(bool Val = true) { 45681b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor SuppressAllDiagnostics = Val; 45781b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor } 45881b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor bool getSuppressAllDiagnostics() const { return SuppressAllDiagnostics; } 459246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu 460246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu /// \brief Set type eliding, to skip outputting same types occurring in 461246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu /// template types. 462246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu void setElideType(bool Val = true) { ElideType = Val; } 463246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu bool getElideType() { return ElideType; } 464246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu 465246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu /// \brief Set tree printing, to outputting the template difference in a 466246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu /// tree format. 467246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu void setPrintTemplateTree(bool Val = false) { PrintTemplateTree = Val; } 468246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu bool getPrintTemplateTree() { return PrintTemplateTree; } 469246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu 470246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu /// \brief Set color printing, so the type diffing will inject color markers 471246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu /// into the output. 472246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu void setShowColors(bool Val = false) { ShowColors = Val; } 473246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu bool getShowColors() { return ShowColors; } 474246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu 4755edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin /// \brief Specify which overload candidates to show when overload resolution 476af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// fails. 477af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 478af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// By default, we show all candidates. 4795edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin void setShowOverloads(OverloadsShown Val) { 4805edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin ShowOverloads = Val; 4815edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin } 4825edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin OverloadsShown getShowOverloads() const { return ShowOverloads; } 4835edbdcc62098e305cd55654814dcf783a3f3c477Jeffrey Yasskin 4845d99a252c63a7745bcd71231ca5240d2a65e4f1dRichard Smith /// \brief Pretend that the last diagnostic issued was ignored, so any 4855d99a252c63a7745bcd71231ca5240d2a65e4f1dRichard Smith /// subsequent notes will be suppressed. 486af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 487af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This can be used by clients who suppress diagnostics themselves. 4880b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor void setLastDiagnosticIgnored() { 4895d99a252c63a7745bcd71231ca5240d2a65e4f1dRichard Smith if (LastDiagLevel == DiagnosticIDs::Fatal) 4905d99a252c63a7745bcd71231ca5240d2a65e4f1dRichard Smith FatalErrorOccurred = true; 49133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis LastDiagLevel = DiagnosticIDs::Ignored; 4920b60d9e0097e2d6a1a5e62396967e207c4a772f2Douglas Gregor } 493cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith 494cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith /// \brief Determine whether the previous diagnostic was ignored. This can 495cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith /// be used by clients that want to determine whether notes attached to a 496cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith /// diagnostic will be suppressed. 497cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith bool isLastDiagnosticIgnored() const { 498cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith return LastDiagLevel == DiagnosticIDs::Ignored; 499cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith } 500cbc820af7193e3ad9c71fbe6e3c8bd3c1166e540Richard Smith 501af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Controls whether otherwise-unmapped extension diagnostics are 502af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// mapped onto ignore/warning/error. 503af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 504af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This corresponds to the GCC -pedantic and -pedantic-errors option. 505b54b276a920246c595a0498da281821eb9d22996Chris Lattner void setExtensionHandlingBehavior(ExtensionHandling H) { 506b54b276a920246c595a0498da281821eb9d22996Chris Lattner ExtBehavior = H; 507b54b276a920246c595a0498da281821eb9d22996Chris Lattner } 508c1b5fa41f09512c74030b9a2a0d1564535e22a76Peter Collingbourne ExtensionHandling getExtensionHandlingBehavior() const { return ExtBehavior; } 5091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Counter bumped when an __extension__ block is/ encountered. 511af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 512af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// When non-zero, all extension diagnostics are entirely silenced, no 513af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// matter how they are mapped. 51427ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner void IncrementAllExtensionsSilenced() { ++AllExtensionsSilenced; } 51527ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner void DecrementAllExtensionsSilenced() { --AllExtensionsSilenced; } 51691a2886d558ea6ca7a0bed73ab5acea5ae78eac2Douglas Gregor bool hasAllExtensionsSilenced() { return AllExtensionsSilenced != 0; } 5171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 518697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief This allows the client to specify that certain warnings are 519697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// ignored. 520697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 521697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// Notes can never be mapped, errors can only be mapped to fatal, and 522697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// WARNINGs and EXTENSIONs can be mapped arbitrarily. 5230827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// 5240827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \param Loc The source location that this change of diagnostic state should 5250827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// take affect. It can be null if we are setting the latest state. 5260827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis void setDiagnosticMapping(diag::kind Diag, diag::Mapping Map, 5270827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis SourceLocation Loc); 5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 529697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Change an entire diagnostic group (e.g. "unknown-pragmas") to 530697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// have the specified mapping. 531697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 532697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \returns true (and ignores the request) if "Group" was unknown, false 533697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// otherwise. 5340827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// 535697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \param Loc The source location that this change of diagnostic state should 5360827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// take affect. It can be null if we are setting the state from command-line. 537686775deca8b8685eb90801495880e3abdd844c2Chris Lattner bool setDiagnosticGroupMapping(StringRef Group, diag::Mapping Map, 5383f8394669673451061f57ced81f0a2cae087f119Daniel Dunbar SourceLocation Loc = SourceLocation()); 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 540697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Set the warning-as-error flag for the given diagnostic. 541697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 542697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This function always only operates on the current diagnostic state. 5433f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier void setDiagnosticWarningAsError(diag::kind Diag, bool Enabled); 5443f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier 545697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Set the warning-as-error flag for the given diagnostic group. 546697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 547697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This function always only operates on the current diagnostic state. 5484aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar /// 5494aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar /// \returns True if the given group is unknown, false otherwise. 5504aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar bool setDiagnosticGroupWarningAsError(StringRef Group, bool Enabled); 5514aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar 552697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Set the error-as-fatal flag for the given diagnostic. 553697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 554697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This function always only operates on the current diagnostic state. 5553f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier void setDiagnosticErrorAsFatal(diag::kind Diag, bool Enabled); 5563f22509ebf91aa96658ca6e5c5c0b926d8d62e34Chad Rosier 557697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Set the error-as-fatal flag for the given diagnostic group. 558697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 559697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This function always only operates on the current diagnostic state. 5604aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar /// 5614aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar /// \returns True if the given group is unknown, false otherwise. 5624aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar bool setDiagnosticGroupErrorAsFatal(StringRef Group, bool Enabled); 5634aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar 564697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Add the specified mapping to all diagnostics. 565697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 566697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// Mainly to be used by -Wno-everything to disable all warnings but allow 567697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// subsequent -W options to enable specific warnings. 56882e6411d004064a29f03a3ea8b8919f297bfa843Argyrios Kyrtzidis void setMappingToAllDiagnostics(diag::Mapping Map, 56911583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis SourceLocation Loc = SourceLocation()); 57011583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool hasErrorOccurred() const { return ErrorOccurred; } 57212f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins 57312f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins /// \brief Errors that actually prevent compilation, not those that are 57412f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins /// upgraded from a warning by -Werror. 57512f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins bool hasUncompilableErrorOccurred() const { 57612f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins return UncompilableErrorOccurred; 57712f37e411462b8388eb1309357bd62257debacacDeLesley Hutchins } 57815221422eda7bac679e38b07512feda49715ef66Chris Lattner bool hasFatalErrorOccurred() const { return FatalErrorOccurred; } 57985bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor 58085bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor /// \brief Determine whether any kind of unrecoverable error has occurred. 58185bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor bool hasUnrecoverableErrorOccurred() const { 58285bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor return FatalErrorOccurred || UnrecoverableErrorOccurred; 58385bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor } 58485bea9777d444ccbcc086d98f075fe666c2e865dDouglas Gregor 58553eee7ba970d21ff15bbd4334164037a3b4cc4b8Chris Lattner unsigned getNumWarnings() const { return NumWarnings; } 5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 587c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor void setNumWarnings(unsigned NumWarnings) { 588c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor this->NumWarnings = NumWarnings; 589c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor } 590c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 591697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Return an ID for a diagnostic with the specified message and level. 592697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 593fc09336a5965040736f9bc63a70416003972364eStefanus Du Toit /// If this is the first request for this diagnostic, it is registered and 594697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// created, otherwise the existing ID is returned. 595686775deca8b8685eb90801495880e3abdd844c2Chris Lattner unsigned getCustomDiagID(Level L, StringRef Message) { 59633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis return Diags->getCustomDiagID((DiagnosticIDs::Level)L, Message); 59733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis } 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 599697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Converts a diagnostic argument (as an intptr_t) into the string 600697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// that represents it. 6013fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner void ConvertArgToString(ArgumentKind Kind, intptr_t Val, 6023fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner const char *Modifier, unsigned ModLen, 6033fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner const char *Argument, unsigned ArgLen, 604b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner const ArgumentValue *PrevArgs, unsigned NumPrevArgs, 605686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> &Output, 6064def70d3040e73707c738f7c366737a986135edfRichard Smith ArrayRef<intptr_t> QualTypeVals) const { 607b54d8af9a66cc20a6a9a9219c7eaea8df7ee7fd4Chris Lattner ArgToStringFn(Kind, Val, Modifier, ModLen, Argument, ArgLen, 6080673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth PrevArgs, NumPrevArgs, Output, ArgToStringCookie, 6090673cb30340aadaede7b795c763b00f6b64e611cChandler Carruth QualTypeVals); 61022caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner } 6111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61292dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner void SetArgToStringFn(ArgToStringFnTy Fn, void *Cookie) { 6133fdf4b071dc79fae778fb5f376485480756c76a3Chris Lattner ArgToStringFn = Fn; 61492dd386e3f05d176b45a638199d51f536bd9d1c4Chris Lattner ArgToStringCookie = Cookie; 61522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner } 6161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6175b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith /// \brief Note that the prior diagnostic was emitted by some other 6185b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith /// \c DiagnosticsEngine, and we may be attaching a note to that diagnostic. 6195b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith void notePriorDiagnosticFrom(const DiagnosticsEngine &Other) { 6205b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith LastDiagLevel = Other.LastDiagLevel; 6215b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith } 6225b9268f26ac53a74d2c504279fe577d988d5615dRichard Smith 623abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// \brief Reset the state of the diagnostic object to its initial 624abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor /// configuration. 625abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor void Reset(); 626abc563f554951259bbe0315055cad92ee14d87e4Douglas Gregor 6275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 628d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie // DiagnosticsEngine classification and reporting interfaces. 6295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 6305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 631d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// \brief Based on the way the client configured the DiagnosticsEngine 6325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// object, classify the specified diagnostic ID into a Level, consumable by 63378ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie /// the DiagnosticConsumer. 6340827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// 6350827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// \param Loc The source location we are interested in finding out the 6360827408865e32789e0ec4b8113a302ccdc531423Argyrios Kyrtzidis /// diagnostic state. Can be null in order to query the latest state. 6371656aaec223949245fdbebf306b719cba0b687caDaniel Dunbar Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const { 6381656aaec223949245fdbebf306b719cba0b687caDaniel Dunbar return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this); 63933e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis } 6401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 641697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Issue the message to the client. 642697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 643697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This actually returns an instance of DiagnosticBuilder which emits the 644697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// diagnostics (through @c ProcessDiag) when it is destroyed. 645697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 646697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \param DiagID A member of the @c diag::kind enum. 647efce31f51d6e7e31e125f96c20f6cdab3ead0a47James Dennett /// \param Loc Represents the source location associated with the diagnostic, 648509355e982d15da4f8f3939493516379665f6275Ted Kremenek /// which can be an invalid location if no position information is available. 649efce31f51d6e7e31e125f96c20f6cdab3ead0a47James Dennett inline DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID); 6500f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar inline DiagnosticBuilder Report(unsigned DiagID); 651de4bf6a63219c5b9d3bce1fed3dfe075568098a0Douglas Gregor 652e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis void Report(const StoredDiagnostic &storedDiag); 653e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis 65493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Determine whethere there is already a diagnostic in flight. 6555800f7ea9cf5621280089d690f677bd28064d6b5Ted Kremenek bool isDiagnosticInFlight() const { return CurDiagID != ~0U; } 65693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 65793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Set the "delayed" diagnostic that will be emitted once 65893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// the current diagnostic completes. 65993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// 66093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// If a diagnostic is already in-flight but the front end must 66193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// report a problem (e.g., with an inconsistent file system 66293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// state), this routine sets a "delayed" diagnostic that will be 66393ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// emitted after the current diagnostic completes. This should 66493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// only be used for fatal errors detected at inconvenient 66593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// times. If emitting a delayed diagnostic causes a second delayed 66693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// diagnostic to be introduced, that second delayed diagnostic 66793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// will be ignored. 66893ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// 66993ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \param DiagID The ID of the diagnostic being delayed. 67093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// 67193ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \param Arg1 A string argument that will be provided to the 67293ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// diagnostic. A copy of this string will be stored in the 673d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// DiagnosticsEngine object itself. 67493ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// 67593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \param Arg2 A string argument that will be provided to the 67693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// diagnostic. A copy of this string will be stored in the 677d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie /// DiagnosticsEngine object itself. 678686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1 = "", 679686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Arg2 = ""); 68093ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 681de4bf6a63219c5b9d3bce1fed3dfe075568098a0Douglas Gregor /// \brief Clear out the current diagnostic. 682de4bf6a63219c5b9d3bce1fed3dfe075568098a0Douglas Gregor void Clear() { CurDiagID = ~0U; } 6831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6840a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattnerprivate: 68593ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor /// \brief Report the delayed diagnostic. 68693ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor void ReportDelayed(); 68793ea5cb0edf8e509c5113e70cb05ee247c9bdf6bDouglas Gregor 6883cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner // This is private state used by DiagnosticBuilder. We put it here instead of 6893cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner // in DiagnosticBuilder in order to keep DiagnosticBuilder a small lightweight 6900a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner // object. This implementation choice means that we can only have one 6910a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner // diagnostic "in flight" at a time, but this seems to be a reasonable 6920a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner // tradeoff to keep these objects small. Assertions verify that only one 6930a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner // diagnostic is in flight at a time. 69433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis friend class DiagnosticIDs; 6953cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner friend class DiagnosticBuilder; 69640847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie friend class Diagnostic; 6979b623639378d53a675921ddfa7316034d571881eDouglas Gregor friend class PartialDiagnostic; 6989c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis friend class DiagnosticErrorTrap; 6999b623639378d53a675921ddfa7316034d571881eDouglas Gregor 700697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The location of the current diagnostic that is in flight. 70133e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis SourceLocation CurDiagLoc; 7021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 703697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The ID of the current diagnostic that is in flight. 704697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 7053cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner /// This is set to ~0U when there is no diagnostic in flight. 706b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner unsigned CurDiagID; 707b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner 70873d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner enum { 709697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The maximum number of arguments we can hold. 710697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 711af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// We currently only support up to 10 arguments (%0-%9). A single 712af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// diagnostic with more than that almost certainly has to be simplified 713af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// anyway. 714981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar MaxArguments = 10, 715981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar 716697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The maximum number of ranges we can hold. 717981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar MaxRanges = 10, 718981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar 719697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The maximum number of ranges we can hold. 720981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar MaxFixItHints = 10 72173d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner }; 7221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 723697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The number of entries in Arguments. 724730e0fdbbf9b315ef834074054ac55af3a4fcc0cChris Lattner signed char NumDiagArgs; 725697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The number of ranges in the DiagRanges array. 726730e0fdbbf9b315ef834074054ac55af3a4fcc0cChris Lattner unsigned char NumDiagRanges; 727697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The number of hints in the DiagFixItHints array. 728981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar unsigned char NumDiagFixItHints; 729ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor 730af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Specifies whether an argument is in DiagArgumentsStr or 731af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// in DiagArguments. 732af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 733af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This is an array of ArgumentKind::ArgumentKind enum values, one for each 734af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// argument. 73573d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner unsigned char DiagArgumentsKind[MaxArguments]; 7361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 737af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Holds the values of each string argument for the current 738697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// diagnostic. 739697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 740697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This is only used when the corresponding ArgumentKind is ak_std_string. 74173d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner std::string DiagArgumentsStr[MaxArguments]; 74273d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner 743697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The values for the various substitution positions. 744697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// 745697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// This is used when the argument is not an std::string. The specific 746697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// value is mangled into an intptr_t and the interpretation depends on 747697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// exactly what sort of argument kind it is. 74873d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner intptr_t DiagArgumentsVal[MaxArguments]; 7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 750697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief The list of ranges added to this diagnostic. 751981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar CharSourceRange DiagRanges[MaxRanges]; 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 753697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief If valid, provides a hint with some code to insert, remove, 754981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar /// or modify at a particular position. 755981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar FixItHint DiagFixItHints[MaxFixItHints]; 7564b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 75787429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis DiagnosticMappingInfo makeMappingInfo(diag::Mapping Map, SourceLocation L) { 75887429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis bool isPragma = L.isValid(); 75987429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis DiagnosticMappingInfo MappingInfo = DiagnosticMappingInfo::Make( 76087429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis Map, /*IsUser=*/true, isPragma); 76187429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis 76287429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis // If this is a pragma mapping, then set the diagnostic mapping flags so 76387429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis // that we override command line options. 76487429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis if (isPragma) { 76587429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis MappingInfo.setNoWarningAsError(true); 76687429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis MappingInfo.setNoErrorAsFatal(true); 76787429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis } 76887429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis 76987429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis return MappingInfo; 77087429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis } 77187429a05ff66fe6460eaa4855fd0da574e26bf7bArgyrios Kyrtzidis 772697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Used to report a diagnostic that is finally fully formed. 7735e9f35c7cb61aea46f56d46c77cbcf47c0cf28baDouglas Gregor /// 774697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \returns true if the diagnostic was emitted, false if it was suppressed. 77533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis bool ProcessDiag() { 77633e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis return Diags->ProcessDiag(*this); 77733e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis } 778f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis 779393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar /// @name Diagnostic Emission 780393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar /// @{ 781393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbarprotected: 782393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar // Sema requires access to the following functions because the current design 783393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar // of SFINAE requires it to use its own SemaDiagnosticBuilder, which needs to 784393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar // access us directly to ensure we minimize the emitted code for the common 785393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar // Sema::Diag() patterns. 786393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar friend class Sema; 787393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar 7883054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar /// \brief Emit the current diagnostic and clear the diagnostic state. 789c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose /// 790c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose /// \param Force Emit the diagnostic regardless of suppression settings. 791c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose bool EmitCurrentDiagnostic(bool Force = false); 7923054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar 793393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar unsigned getCurrentDiagID() const { return CurDiagID; } 794393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar 795393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar SourceLocation getCurrentDiagLoc() const { return CurDiagLoc; } 796393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar 797393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar /// @} 798393eed7fb901e49085c8583ff0439d1273b6f2feDaniel Dunbar 799f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis friend class ASTReader; 800f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis friend class ASTWriter; 8013cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}; 8023cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 8039c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis/// \brief RAII class that determines when any errors have occurred 8049c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis/// between the time the instance was created and the time it was 8059c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis/// queried. 8069c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidisclass DiagnosticErrorTrap { 807d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine &Diag; 808c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis unsigned NumErrors; 809c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis unsigned NumUnrecoverableErrors; 8109c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis 8119c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidispublic: 812d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie explicit DiagnosticErrorTrap(DiagnosticsEngine &Diag) 813add80bb3957dba1d9389304453c0a4c975768bd7John McCall : Diag(Diag) { reset(); } 8149c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis 8159c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis /// \brief Determine whether any errors have occurred since this 8169c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis /// object instance was created. 8179c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis bool hasErrorOccurred() const { 818c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis return Diag.TrapNumErrorsOccurred > NumErrors; 819add80bb3957dba1d9389304453c0a4c975768bd7John McCall } 820add80bb3957dba1d9389304453c0a4c975768bd7John McCall 821add80bb3957dba1d9389304453c0a4c975768bd7John McCall /// \brief Determine whether any unrecoverable errors have occurred since this 822add80bb3957dba1d9389304453c0a4c975768bd7John McCall /// object instance was created. 823add80bb3957dba1d9389304453c0a4c975768bd7John McCall bool hasUnrecoverableErrorOccurred() const { 824c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis return Diag.TrapNumUnrecoverableErrorsOccurred > NumUnrecoverableErrors; 8259c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis } 8269c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis 827af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Set to initial state of "no errors occurred". 828add80bb3957dba1d9389304453c0a4c975768bd7John McCall void reset() { 829c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis NumErrors = Diag.TrapNumErrorsOccurred; 830c0a575f9b791a25c94b1c3c832dd73ec564646bbArgyrios Kyrtzidis NumUnrecoverableErrors = Diag.TrapNumUnrecoverableErrorsOccurred; 831add80bb3957dba1d9389304453c0a4c975768bd7John McCall } 8329c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis}; 8339c4eb1f3438370355f51dc8c62f2ca4803e3338dArgyrios Kyrtzidis 8343cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===// 8353cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner// DiagnosticBuilder 8363cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===// 8373cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 838697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// \brief A little helper class used to produce diagnostics. 839697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// 840697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// This is constructed by the DiagnosticsEngine::Report method, and 841697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// allows insertion of extra information (arguments and source ranges) into 842697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// the currently "in flight" diagnostic. When the temporary for the builder 843697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// is destroyed, the diagnostic is issued. 8443cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// 8453cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// Note that many of these will be created as temporary objects (many call 8463cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// sites), so we want them to be small and we never want their address taken. 8473cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// This ensures that compilers with somewhat reasonable optimizers will promote 8483cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// the common fields to registers, eliminating increments of the NumArgs field, 8493cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner/// for example. 8503cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerclass DiagnosticBuilder { 851d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie mutable DiagnosticsEngine *DiagObj; 852981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar mutable unsigned NumArgs, NumRanges, NumFixits; 8531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8547059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar /// \brief Status variable indicating if this diagnostic is still active. 8557059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar /// 856f3477c13eeaf11b32a41f181398fb5deffd0dd73Sylvestre Ledru // NOTE: This field is redundant with DiagObj (IsActive iff (DiagObj == 0)), 8577059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar // but LLVM is not currently smart enough to eliminate the null check that 8587059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar // Emit() would end up with if we used that as our status variable. 8597059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar mutable bool IsActive; 8607059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar 861c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose /// \brief Flag indicating that this diagnostic is being emitted via a 862c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose /// call to ForceEmit. 863c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose mutable bool IsForceEmit; 864c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose 865f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const DiagnosticBuilder &) LLVM_DELETED_FUNCTION; 866d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie friend class DiagnosticsEngine; 867ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor 868ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor DiagnosticBuilder() 869c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose : DiagObj(0), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(false), 870c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose IsForceEmit(false) { } 871ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor 872d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie explicit DiagnosticBuilder(DiagnosticsEngine *diagObj) 873c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose : DiagObj(diagObj), NumArgs(0), NumRanges(0), NumFixits(0), IsActive(true), 874c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose IsForceEmit(false) { 875981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar assert(diagObj && "DiagnosticBuilder requires a valid DiagnosticsEngine!"); 876cbf46a0b2bb2b47d6e13437e0d52cc583c5ce539Argyrios Kyrtzidis } 877ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor 8789b623639378d53a675921ddfa7316034d571881eDouglas Gregor friend class PartialDiagnostic; 879ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor 880b535041ee33c5eff255832bc5541c8d52aae8254Douglas Gregorprotected: 8813054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar void FlushCounts() { 8823054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar DiagObj->NumDiagArgs = NumArgs; 8833054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar DiagObj->NumDiagRanges = NumRanges; 8843054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar DiagObj->NumDiagFixItHints = NumFixits; 8853054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar } 88606265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar 887cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// \brief Clear out the current diagnostic. 8887059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar void Clear() const { 8897059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar DiagObj = 0; 8907059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar IsActive = false; 891c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose IsForceEmit = false; 8927059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar } 893cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar 894697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Determine whether this diagnostic is still active. 8957059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar bool isActive() const { return IsActive; } 89606265bd82073c06294a02a0bd891951fafb484a5Daniel Dunbar 897cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// \brief Force the diagnostic builder to emit the diagnostic now. 898cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// 899cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// Once this function has been called, the DiagnosticBuilder object 900cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// should not be used again before it is destroyed. 901cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// 902cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// \returns true if a diagnostic was emitted, false if the 903cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar /// diagnostic was suppressed. 9043054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar bool Emit() { 9057059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar // If this diagnostic is inactive, then its soul was stolen by the copy ctor 9067059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar // (or by a subclass, as in SemaDiagnosticBuilder). 9077059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar if (!isActive()) return false; 9083054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar 9093054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar // When emitting diagnostics, we set the final argument count into 9103054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar // the DiagnosticsEngine object. 9113054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar FlushCounts(); 9123054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar 9133054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar // Process the diagnostic. 914c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose bool Result = DiagObj->EmitCurrentDiagnostic(IsForceEmit); 9153054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar 9163054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar // This diagnostic is dead. 9177059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar Clear(); 9183054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar 9193054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar return Result; 9203054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar } 9219b623639378d53a675921ddfa7316034d571881eDouglas Gregor 9221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 9230a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner /// Copy constructor. When copied, this "takes" the diagnostic info from the 9240a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner /// input and neuters it. 9253cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder(const DiagnosticBuilder &D) { 9260a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner DiagObj = D.DiagObj; 9277059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar IsActive = D.IsActive; 928c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose IsForceEmit = D.IsForceEmit; 9297059a1cbc29444bec19380059a62db085eb92964Daniel Dunbar D.Clear(); 93025a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor NumArgs = D.NumArgs; 93125a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor NumRanges = D.NumRanges; 932981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar NumFixits = D.NumFixits; 9330a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner } 93425a88bbf042317976f0d9cbfa87dfe89426e8393Douglas Gregor 935ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor /// \brief Retrieve an empty diagnostic builder. 936ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor static DiagnosticBuilder getEmpty() { 937ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor return DiagnosticBuilder(); 938ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor } 939ab41fe914f63bb470dfa7e400876ada72f57a931Douglas Gregor 940697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett /// \brief Emits the diagnostic. 94153c83b32550b3f29db2419160fa2e3684e420556Daniel Dunbar ~DiagnosticBuilder() { 9423054f097f813d19090bdb23645dcd48df71d1a89Daniel Dunbar Emit(); 94353c83b32550b3f29db2419160fa2e3684e420556Daniel Dunbar } 9449b623639378d53a675921ddfa7316034d571881eDouglas Gregor 945c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose /// \brief Forces the diagnostic to be emitted. 946c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose const DiagnosticBuilder &setForceEmit() const { 947c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose IsForceEmit = true; 948c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose return *this; 949c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose } 950c6d64a26c28bbeee50e06c94c4f4c08e610327b7Jordan Rose 951af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Conversion of DiagnosticBuilder to bool always returns \c true. 952af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 953af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// This allows is to be used in boolean error contexts (where \c true is 954af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// used to indicate that an error has occurred), like: 955af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \code 9563cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner /// return Diag(...); 957af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \endcode 9583cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner operator bool() const { return true; } 9593cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 960686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void AddString(StringRef S) const { 961cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar assert(isActive() && "Clients must not add to cleared diagnostic!"); 962d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(NumArgs < DiagnosticsEngine::MaxArguments && 9633cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "Too many arguments to diagnostic!"); 964cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar DiagObj->DiagArgumentsKind[NumArgs] = DiagnosticsEngine::ak_std_string; 965cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar DiagObj->DiagArgumentsStr[NumArgs++] = S; 9663cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner } 9671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 968d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie void AddTaggedVal(intptr_t V, DiagnosticsEngine::ArgumentKind Kind) const { 969cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar assert(isActive() && "Clients must not add to cleared diagnostic!"); 970d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(NumArgs < DiagnosticsEngine::MaxArguments && 9713cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "Too many arguments to diagnostic!"); 972cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar DiagObj->DiagArgumentsKind[NumArgs] = Kind; 973cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar DiagObj->DiagArgumentsVal[NumArgs++] = V; 9740a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner } 9751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9760a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner void AddSourceRange(const CharSourceRange &R) const { 977cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar assert(isActive() && "Clients must not add to cleared diagnostic!"); 978981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar assert(NumRanges < DiagnosticsEngine::MaxRanges && 9793cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "Too many arguments to diagnostic!"); 980cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar DiagObj->DiagRanges[NumRanges++] = R; 9811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 9824b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 983849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor void AddFixItHint(const FixItHint &Hint) const { 984cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar assert(isActive() && "Clients must not add to cleared diagnostic!"); 985981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar assert(NumFixits < DiagnosticsEngine::MaxFixItHints && 986981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar "Too many arguments to diagnostic!"); 987cefcbef6f3b1e34f31ce0e47214c8b90fedfb9acDaniel Dunbar DiagObj->DiagFixItHints[NumFixits++] = Hint; 9884b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor } 98982c6dc72adc30e785ce5bc6e8b43ae92070d2e08David Blaikie 99082c6dc72adc30e785ce5bc6e8b43ae92070d2e08David Blaikie bool hasMaxRanges() const { 99182c6dc72adc30e785ce5bc6e8b43ae92070d2e08David Blaikie return NumRanges == DiagnosticsEngine::MaxRanges; 99282c6dc72adc30e785ce5bc6e8b43ae92070d2e08David Blaikie } 9933cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner}; 9943cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 9953cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 996686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef S) { 9973cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DB.AddString(S); 9983cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DB; 9993cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 10003cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 10013cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 10023cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner const char *Str) { 10033cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(Str), 1004d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::ak_c_string); 10053cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DB; 10063cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 10073cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 10083cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, int I) { 1009d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint); 10103cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DB; 10113cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 10123cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 10133bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidisinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,bool I) { 1014d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DB.AddTaggedVal(I, DiagnosticsEngine::ak_sint); 10153bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidis return DB; 10163bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidis} 10173bf4a79712fb30dc27692ef2d4214ee7fa6681beArgyrios Kyrtzidis 10183cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 10193cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner unsigned I) { 1020d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DB.AddTaggedVal(I, DiagnosticsEngine::ak_uint); 10213cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DB; 10223cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 10233cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 10243cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 10253cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner const IdentifierInfo *II) { 10263cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DB.AddTaggedVal(reinterpret_cast<intptr_t>(II), 1027d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::ak_identifierinfo); 10283cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DB; 10293cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 10301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10313f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// Adds a DeclContext to the diagnostic. The enable_if template magic is here 10323f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// so that we only match those arguments that are (statically) DeclContexts; 10333f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// other arguments that derive from DeclContext (e.g., RecordDecls) will not 10343f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor// match. 10353f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregortemplate<typename T> 10363f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregorinline 10373f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregortypename llvm::enable_if<llvm::is_same<T, DeclContext>, 10383f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor const DiagnosticBuilder &>::type 10393f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregoroperator<<(const DiagnosticBuilder &DB, T *DC) { 10403f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor DB.AddTaggedVal(reinterpret_cast<intptr_t>(DC), 1041d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::ak_declcontext); 10423f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor return DB; 10433f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor} 10443f09327b26033d0a9676d52d80cf92c48f581affDouglas Gregor 10453cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 10463cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner const SourceRange &R) { 10470a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner DB.AddSourceRange(CharSourceRange::getTokenRange(R)); 10483cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DB; 10493cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 10504b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 10514b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregorinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 10520a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner const CharSourceRange &R) { 10530a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner DB.AddSourceRange(R); 10540a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner return DB; 10550a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner} 10560a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner 10570a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattnerinline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, 1058849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor const FixItHint &Hint) { 10593739b32a01b9778176757425e62252c288b85383Ted Kremenek if (!Hint.isNull()) 10603739b32a01b9778176757425e62252c288b85383Ted Kremenek DB.AddFixItHint(Hint); 10614b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor return DB; 10624b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor} 1063ee1828a6b5ae1bc4ea300e48f3840ac1ec5be295Douglas Gregor 1064d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieinline DiagnosticBuilder DiagnosticsEngine::Report(SourceLocation Loc, 106533e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis unsigned DiagID){ 10663cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!"); 10673cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner CurDiagLoc = Loc; 10683cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner CurDiagID = DiagID; 10693cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner return DiagnosticBuilder(this); 10703cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner} 1071d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieinline DiagnosticBuilder DiagnosticsEngine::Report(unsigned DiagID) { 107233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis return Report(SourceLocation(), DiagID); 10730f9fed70cea107b3f79df554e38bd8e98d48fe47Daniel Dunbar} 10743cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner 10753cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===// 107640847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie// Diagnostic 10773cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner//===----------------------------------------------------------------------===// 10781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1079697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// A little helper class (which is basically a smart pointer that forwards 1080697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// info from DiagnosticsEngine) that allows clients to enquire about the 1081697c7a8af6d090bff2b572553da0957de1724e1eJames Dennett/// currently in-flight diagnostic. 108240847cfb58acc3cac7d68727df9455ac45f2e118David Blaikieclass Diagnostic { 1083d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie const DiagnosticsEngine *DiagObj; 1084686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef StoredDiagMessage; 10853cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerpublic: 108640847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie explicit Diagnostic(const DiagnosticsEngine *DO) : DiagObj(DO) {} 108740847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie Diagnostic(const DiagnosticsEngine *DO, StringRef storedDiagMessage) 1088e59abb56ce0e1c206fb80bd945a0c358b0abe1efArgyrios Kyrtzidis : DiagObj(DO), StoredDiagMessage(storedDiagMessage) {} 10891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1090d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie const DiagnosticsEngine *getDiags() const { return DiagObj; } 1091b7fc3b87d065041a10eaa0603d738df21ff7af3aChris Lattner unsigned getID() const { return DiagObj->CurDiagID; } 109233e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis const SourceLocation &getLocation() const { return DiagObj->CurDiagLoc; } 109333e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis bool hasSourceManager() const { return DiagObj->hasSourceManager(); } 109433e4e70c8c0a17e0ccb7465d96556b077a68ecb1Argyrios Kyrtzidis SourceManager &getSourceManager() const { return DiagObj->getSourceManager();} 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 10960a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner unsigned getNumArgs() const { return DiagObj->NumDiagArgs; } 10971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1098af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the kind of the specified index. 1099af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 1100af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// Based on the kind of argument, the accessors below can be used to get 1101af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// the value. 1102af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 1103af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre Idx < getNumArgs() 1104d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::ArgumentKind getArgKind(unsigned Idx) const { 11053cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner assert(Idx < getNumArgs() && "Argument index out of range!"); 1106d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie return (DiagnosticsEngine::ArgumentKind)DiagObj->DiagArgumentsKind[Idx]; 110773d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner } 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1109af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the provided argument string specified by \p Idx. 1110af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_std_string 111173d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner const std::string &getArgStdStr(unsigned Idx) const { 1112d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(getArgKind(Idx) == DiagnosticsEngine::ak_std_string && 11133cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "invalid argument accessor!"); 111473d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner return DiagObj->DiagArgumentsStr[Idx]; 111573d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner } 11161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1117af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the specified C string argument. 1118af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_c_string 111973d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner const char *getArgCStr(unsigned Idx) const { 1120d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(getArgKind(Idx) == DiagnosticsEngine::ak_c_string && 11213cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "invalid argument accessor!"); 112273d2a1b05bb04ab0136af374ddaa5d4602d4c939Chris Lattner return reinterpret_cast<const char*>(DiagObj->DiagArgumentsVal[Idx]); 11230a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner } 11241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1125af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the specified signed integer argument. 1126af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_sint 112730bc96544346bea42921cf6837e66cef80d664b4Chris Lattner int getArgSInt(unsigned Idx) const { 1128d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(getArgKind(Idx) == DiagnosticsEngine::ak_sint && 11293cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "invalid argument accessor!"); 113030bc96544346bea42921cf6837e66cef80d664b4Chris Lattner return (int)DiagObj->DiagArgumentsVal[Idx]; 113130bc96544346bea42921cf6837e66cef80d664b4Chris Lattner } 11321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1133af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the specified unsigned integer argument. 1134af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_uint 113530bc96544346bea42921cf6837e66cef80d664b4Chris Lattner unsigned getArgUInt(unsigned Idx) const { 1136d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(getArgKind(Idx) == DiagnosticsEngine::ak_uint && 11373cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "invalid argument accessor!"); 113830bc96544346bea42921cf6837e66cef80d664b4Chris Lattner return (unsigned)DiagObj->DiagArgumentsVal[Idx]; 113930bc96544346bea42921cf6837e66cef80d664b4Chris Lattner } 11401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1141af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the specified IdentifierInfo argument. 1142af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre getArgKind(Idx) == DiagnosticsEngine::ak_identifierinfo 114343b628cd47ecdc3caf640d79b3ad7ecef0f2c285Chris Lattner const IdentifierInfo *getArgIdentifier(unsigned Idx) const { 1144d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(getArgKind(Idx) == DiagnosticsEngine::ak_identifierinfo && 11453cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner "invalid argument accessor!"); 11469634379265855f1628190e926d9aaf1fb4a5d90eChris Lattner return reinterpret_cast<IdentifierInfo*>(DiagObj->DiagArgumentsVal[Idx]); 114743b628cd47ecdc3caf640d79b3ad7ecef0f2c285Chris Lattner } 11481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1149af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the specified non-string argument in an opaque form. 1150af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre getArgKind(Idx) != DiagnosticsEngine::ak_std_string 115122caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner intptr_t getRawArg(unsigned Idx) const { 1152d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie assert(getArgKind(Idx) != DiagnosticsEngine::ak_std_string && 115322caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner "invalid argument accessor!"); 115422caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner return DiagObj->DiagArgumentsVal[Idx]; 115522caddc91d2f6186739c6b20ec58ed38cd68e595Chris Lattner } 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1157af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Return the number of source ranges associated with this diagnostic. 11580a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner unsigned getNumRanges() const { 11590a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner return DiagObj->NumDiagRanges; 11600a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner } 11611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1162af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \pre Idx < getNumRanges() 11630a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner const CharSourceRange &getRange(unsigned Idx) const { 11640a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner assert(Idx < DiagObj->NumDiagRanges && "Invalid diagnostic range index!"); 116551c6d384551674facc19f745ecf6e289d28dc55fDouglas Gregor return DiagObj->DiagRanges[Idx]; 11660a14eee528a901c16f0e288fbc10a3abc1660d87Chris Lattner } 11671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 116828409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth /// \brief Return an array reference for this diagnostic's ranges. 116928409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth ArrayRef<CharSourceRange> getRanges() const { 117028409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth return llvm::makeArrayRef(DiagObj->DiagRanges, DiagObj->NumDiagRanges); 117128409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth } 117228409289193afca1a3178a9796f8e8aebcb76896Chandler Carruth 1173849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor unsigned getNumFixItHints() const { 1174981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar return DiagObj->NumDiagFixItHints; 11754b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor } 11764b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 1177849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor const FixItHint &getFixItHint(unsigned Idx) const { 1178981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar assert(Idx < getNumFixItHints() && "Invalid index!"); 1179981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar return DiagObj->DiagFixItHints[Idx]; 11804b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor } 11814b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 1182849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor const FixItHint *getFixItHints() const { 1183981e279b95f3a71e2268124b1abaae050ec200dcDaniel Dunbar return getNumFixItHints()? DiagObj->DiagFixItHints : 0; 11844b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor } 11854b2d3f7bcc4df31157df443af1b80bcaa9b58bbaDouglas Gregor 1186af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Format this diagnostic into a string, substituting the 1187af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// formal arguments into the %0 slots. 1188af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 1189af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// The result is appended onto the \p OutStr array. 1190686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void FormatDiagnostic(SmallVectorImpl<char> &OutStr) const; 11919f28614bf1a8387000d8df57a713fcf69e198145John McCall 1192af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Format the given format-string into the output buffer using the 1193af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// arguments stored in this diagnostic. 11949f28614bf1a8387000d8df57a713fcf69e198145John McCall void FormatDiagnostic(const char *DiagStr, const char *DiagEnd, 1195686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> &OutStr) const; 1196a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor}; 1197a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 1198a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor/** 1199d3ab63e0f66429abf2a3e4cde889e420e41e8790Douglas Gregor * \brief Represents a diagnostic in a form that can be retained until its 1200d3ab63e0f66429abf2a3e4cde889e420e41e8790Douglas Gregor * corresponding source manager is destroyed. 1201a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor */ 1202a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorclass StoredDiagnostic { 1203aa5f135f8db82b5e5fb1640fd51f8078e0b2d82dDouglas Gregor unsigned ID; 1204d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::Level Level; 1205a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor FullSourceLoc Loc; 1206a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor std::string Message; 12070a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner std::vector<CharSourceRange> Ranges; 1208849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor std::vector<FixItHint> FixIts; 1209a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 1210a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregorpublic: 1211a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor StoredDiagnostic(); 121240847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie StoredDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info); 1213d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, 1214686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Message); 1215d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie StoredDiagnostic(DiagnosticsEngine::Level Level, unsigned ID, 1216686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef Message, FullSourceLoc Loc, 12172d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner ArrayRef<CharSourceRange> Ranges, 12182d3ba4f5a923a90c3fc290ddfba5e36c2d0a9b46Chris Lattner ArrayRef<FixItHint> Fixits); 1219a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor ~StoredDiagnostic(); 1220a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 1221a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor /// \brief Evaluates true when this object stores a diagnostic. 12227247c88d1e41514a41085f83ebf03dd5220e054aDavid Blaikie LLVM_EXPLICIT operator bool() const { return Message.size() > 0; } 1223a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 1224aa5f135f8db82b5e5fb1640fd51f8078e0b2d82dDouglas Gregor unsigned getID() const { return ID; } 1225d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie DiagnosticsEngine::Level getLevel() const { return Level; } 1226a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor const FullSourceLoc &getLocation() const { return Loc; } 1227686775deca8b8685eb90801495880e3abdd844c2Chris Lattner StringRef getMessage() const { return Message; } 1228c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 1229c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor void setLocation(FullSourceLoc Loc) { this->Loc = Loc; } 1230c0659ec614c428c7d15746fcad15d50a2703751dDouglas Gregor 12310a76aae8c03cb7dd7bdbe683485560afaf695959Chris Lattner typedef std::vector<CharSourceRange>::const_iterator range_iterator; 1232a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor range_iterator range_begin() const { return Ranges.begin(); } 1233a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor range_iterator range_end() const { return Ranges.end(); } 1234a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned range_size() const { return Ranges.size(); } 12356700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek 12366700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek ArrayRef<CharSourceRange> getRanges() const { 12376700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek return llvm::makeArrayRef(Ranges); 12386700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek } 12396700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek 1240a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor 1241849b243d4065f56742a4677d6dc8277609a151f8Douglas Gregor typedef std::vector<FixItHint>::const_iterator fixit_iterator; 1242a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor fixit_iterator fixit_begin() const { return FixIts.begin(); } 1243a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor fixit_iterator fixit_end() const { return FixIts.end(); } 1244a88084b78fd4ca5d3d858c14b02414f8cc399f02Douglas Gregor unsigned fixit_size() const { return FixIts.size(); } 12456700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek 12466700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek ArrayRef<FixItHint> getFixIts() const { 12476700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek return llvm::makeArrayRef(FixIts); 12486700d67925abd674ecddfc56948967f49b25bf39Ted Kremenek } 12495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1251af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief Abstract interface, implemented by clients of the front-end, which 1252af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// formats and prints fully processed diagnostics. 125378ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikieclass DiagnosticConsumer { 1254ab41b97c3cddf1bcdd8bf82ab09ed3ceafcd05b1Argyrios Kyrtzidisprotected: 1255af50aab0c317462129d73ae8000c6394c718598dJames Dennett unsigned NumWarnings; ///< Number of warnings reported 1256af50aab0c317462129d73ae8000c6394c718598dJames Dennett unsigned NumErrors; ///< Number of errors reported 1257f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis 12585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 125978ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie DiagnosticConsumer() : NumWarnings(0), NumErrors(0) { } 1260f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis 1261f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis unsigned getNumErrors() const { return NumErrors; } 1262f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis unsigned getNumWarnings() const { return NumWarnings; } 126361d679ab2831b161c857cf3f974312fbd4ef1efdArgyrios Kyrtzidis virtual void clear() { NumWarnings = NumErrors = 0; } 1264f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis 126578ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie virtual ~DiagnosticConsumer(); 12661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1267af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Callback to inform the diagnostic client that processing 1268efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// of a source file is beginning. 1269efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// 1270efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// Note that diagnostics may be emitted outside the processing of a source 1271efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// file, for example during the parsing of command line options. However, 1272efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// diagnostics with source range information are required to only be emitted 1273efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// in between BeginSourceFile() and EndSourceFile(). 1274efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar /// 1275af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \param LangOpts The language options for the source file being processed. 1276af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \param PP The preprocessor object being used for the source; this is 1277af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// optional, e.g., it may not be present when processing AST source files. 12787d90199f109290e9d587479a481a2850d390b552Daniel Dunbar virtual void BeginSourceFile(const LangOptions &LangOpts, 12797d90199f109290e9d587479a481a2850d390b552Daniel Dunbar const Preprocessor *PP = 0) {} 1280efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar 1281af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Callback to inform the diagnostic client that processing 1282af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// of a source file has ended. 1283af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 1284af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// The diagnostic client should assume that any objects made available via 1285af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// BeginSourceFile() are inaccessible. 1286efcbe9475348ecab6b85153baa21d0e894e39607Daniel Dunbar virtual void EndSourceFile() {} 12871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 128829f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis /// \brief Callback to inform the diagnostic client that processing of all 128929f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis /// source files has ended. 129029f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis virtual void finish() {} 129129f2787b6da552018a7716f18f5bd8f67bd6edb5Argyrios Kyrtzidis 1292af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Indicates whether the diagnostics handled by this 129378ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie /// DiagnosticConsumer should be included in the number of diagnostics 129478ad0b98848c17a0a11847fa1d456e2dfec8aa2fDavid Blaikie /// reported by DiagnosticsEngine. 1295af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// 1296af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// The default implementation returns true. 1297cabe66811fe43835b8c5a0854552768fc53261e3Ted Kremenek virtual bool IncludeInDiagnosticCounts() const; 12985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1299af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// \brief Handle this diagnostic, reporting it to the user or 13005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// capturing it to a log as needed. 1301f2224d89a6ae65a3839529e26d0f6d025d83d6bbArgyrios Kyrtzidis /// 1302af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// The default implementation just keeps track of the total number of 1303af50aab0c317462129d73ae8000c6394c718598dJames Dennett /// warnings and errors. 1304d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, 130540847cfb58acc3cac7d68727df9455ac45f2e118David Blaikie const Diagnostic &Info); 1306aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor}; 1307aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor 1308af50aab0c317462129d73ae8000c6394c718598dJames Dennett/// \brief A diagnostic client that ignores all diagnostics. 1309aee526e77657afd1600276450e9c346953ad51d7Douglas Gregorclass IgnoringDiagConsumer : public DiagnosticConsumer { 131099ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 1311aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, 1312aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor const Diagnostic &Info) { 1313aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor // Just ignore it. 1314aee526e77657afd1600276450e9c346953ad51d7Douglas Gregor } 13155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1317a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor/// \brief Diagnostic consumer that forwards diagnostics along to an 1318a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor/// existing, already-initialized diagnostic consumer. 1319a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor/// 1320a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregorclass ForwardingDiagnosticConsumer : public DiagnosticConsumer { 1321a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor DiagnosticConsumer &Target; 1322a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor 1323a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregorpublic: 1324a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor ForwardingDiagnosticConsumer(DiagnosticConsumer &Target) : Target(Target) {} 1325a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor 1326a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor virtual ~ForwardingDiagnosticConsumer(); 1327a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor 1328a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, 1329a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor const Diagnostic &Info); 1330a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor virtual void clear(); 1331a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor 1332a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor virtual bool IncludeInDiagnosticCounts() const; 1333a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor}; 1334a4a90cabfa15c900016a7cfaea51a6d4e8ebf4dbDouglas Gregor 1335246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu// Struct used for sending info about how a type should be printed. 1336246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieustruct TemplateDiffTypes { 1337246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu intptr_t FromType; 1338246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu intptr_t ToType; 1339246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu unsigned PrintTree : 1; 1340246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu unsigned PrintFromType : 1; 1341246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu unsigned ElideType : 1; 1342246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu unsigned ShowColors : 1; 13435409d28b6167032696f4915bb765a6f7db579f3fRichard Trieu // The printer sets this variable to true if the template diff was used. 13445409d28b6167032696f4915bb765a6f7db579f3fRichard Trieu unsigned TemplateDiffUsed : 1; 1345246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu}; 1346246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu 1347246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu/// Special character that the diagnostic printer will use to toggle the bold 1348246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu/// attribute. The character itself will be not be printed. 1349246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieuconst char ToggleHighlight = 127; 1350246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu 13515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 13525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 13535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 1354