diff options
Diffstat (limited to 'include/clang/Basic/Diagnostic.h')
-rw-r--r-- | include/clang/Basic/Diagnostic.h | 71 |
1 files changed, 49 insertions, 22 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 1fe0d81..37d2694 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -16,6 +16,7 @@ #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/type_traits.h" #include <string> @@ -95,23 +96,20 @@ namespace clang { /// compilation. class FixItHint { public: - /// \brief Code that should be removed to correct the error. + /// \brief Code that should be replaced to correct the error. Empty for an + /// insertion hint. CharSourceRange RemoveRange; - /// \brief The location at which we should insert code to correct - /// the error. - SourceLocation InsertionLoc; - /// \brief The actual code to insert at the insertion location, as a /// string. std::string CodeToInsert; /// \brief Empty code modification hint, indicating that no code /// modification is known. - FixItHint() : RemoveRange(), InsertionLoc() { } + FixItHint() : RemoveRange() { } bool isNull() const { - return !RemoveRange.isValid() && !InsertionLoc.isValid(); + return !RemoveRange.isValid(); } /// \brief Create a code modification hint that inserts the given @@ -119,7 +117,8 @@ public: static FixItHint CreateInsertion(SourceLocation InsertionLoc, llvm::StringRef Code) { FixItHint Hint; - Hint.InsertionLoc = InsertionLoc; + Hint.RemoveRange = + CharSourceRange(SourceRange(InsertionLoc, InsertionLoc), false); Hint.CodeToInsert = Code; return Hint; } @@ -141,7 +140,6 @@ public: llvm::StringRef Code) { FixItHint Hint; Hint.RemoveRange = RemoveRange; - Hint.InsertionLoc = RemoveRange.getBegin(); Hint.CodeToInsert = Code; return Hint; } @@ -205,16 +203,32 @@ private: unsigned TemplateBacktraceLimit; // Cap on depth of template backtrace stack, // 0 -> no limit. ExtensionHandling ExtBehavior; // Map extensions onto warnings or errors? - DiagnosticClient *Client; - + llvm::OwningPtr<DiagnosticClient> Client; + /// DiagMappings - Mapping information for diagnostics. Mapping info is /// packed into four bits per diagnostic. The low three bits are the mapping /// (an instance of diag::Mapping), or zero if unset. The high bit is set /// when the mapping was established as a user mapping. If the high bit is /// clear, then the low bits are set to the default value, and should be /// mapped with -pedantic, -Werror, etc. + class DiagMappings { + unsigned char Values[diag::DIAG_UPPER_LIMIT/2]; + + public: + DiagMappings() { + memset(Values, 0, diag::DIAG_UPPER_LIMIT/2); + } + + void setMapping(diag::kind Diag, unsigned Map) { + size_t Shift = (Diag & 1)*4; + Values[Diag/2] = (Values[Diag/2] & ~(15 << Shift)) | (Map << Shift); + } + + diag::Mapping getMapping(diag::kind Diag) const { + return (diag::Mapping)((Values[Diag/2] >> (Diag & 1)*4) & 15); + } + }; - typedef std::vector<unsigned char> DiagMappings; mutable std::vector<DiagMappings> DiagMappingsStack; /// ErrorOccurred / FatalErrorOccurred - This is set to true when an error or @@ -272,8 +286,12 @@ public: // Diagnostic characterization methods, used by a client to customize how // - DiagnosticClient *getClient() { return Client; } - const DiagnosticClient *getClient() const { return Client; } + DiagnosticClient *getClient() { return Client.get(); } + const DiagnosticClient *getClient() const { return Client.get(); } + + /// \brief Return the current diagnostic client along with ownership of that + /// client. + DiagnosticClient *takeClient() { return Client.take(); } /// pushMappings - Copies the current DiagMappings and pushes the new copy /// onto the top of the stack. @@ -285,7 +303,10 @@ public: /// stack. bool popMappings(); - void setClient(DiagnosticClient* client) { Client = client; } + /// \brief Set the diagnostic client associated with this diagnostic object. + /// + /// The diagnostic object takes ownership of \c client. + void setClient(DiagnosticClient* client) { Client.reset(client); } /// setErrorLimit - Specify a limit for the number of errors we should /// emit before giving up. Zero disables the limit. @@ -382,6 +403,10 @@ public: unsigned getNumErrorsSuppressed() const { return NumErrorsSuppressed; } unsigned getNumWarnings() const { return NumWarnings; } + void setNumWarnings(unsigned NumWarnings) { + this->NumWarnings = NumWarnings; + } + /// getCustomDiagID - Return an ID for a diagnostic with the specified message /// and level. If this is the first request for this diagnosic, it is /// registered and created, otherwise the existing ID is returned. @@ -404,6 +429,10 @@ public: ArgToStringCookie = Cookie; } + /// \brief Reset the state of the diagnostic object to its initial + /// configuration. + void Reset(); + //===--------------------------------------------------------------------===// // Diagnostic classification and reporting interfaces. // @@ -535,17 +564,13 @@ private: /// specified builtin diagnostic. This returns the high bit encoding, or zero /// if the field is completely uninitialized. diag::Mapping getDiagnosticMappingInfo(diag::kind Diag) const { - const DiagMappings ¤tMappings = DiagMappingsStack.back(); - return (diag::Mapping)((currentMappings[Diag/2] >> (Diag & 1)*4) & 15); + return DiagMappingsStack.back().getMapping(Diag); } void setDiagnosticMappingInternal(unsigned DiagId, unsigned Map, bool isUser) const { if (isUser) Map |= 8; // Set the high bit for user mappings. - unsigned char &Slot = DiagMappingsStack.back()[DiagId/2]; - unsigned Shift = (DiagId & 1)*4; - Slot &= ~(15 << Shift); - Slot |= Map << Shift; + DiagMappingsStack.back().setMapping((diag::kind)DiagId, Map); } /// getDiagnosticLevel - This is an internal implementation helper used when @@ -927,7 +952,9 @@ public: Diagnostic::Level getLevel() const { return Level; } const FullSourceLoc &getLocation() const { return Loc; } llvm::StringRef getMessage() const { return Message; } - + + void setLocation(FullSourceLoc Loc) { this->Loc = Loc; } + typedef std::vector<CharSourceRange>::const_iterator range_iterator; range_iterator range_begin() const { return Ranges.begin(); } range_iterator range_end() const { return Ranges.end(); } |