[cfe-commits] r44473 - in /cfe/trunk: Basic/Diagnostic.cpp Driver/DiagChecker.cpp Driver/RewriteTest.cpp Driver/TextDiagnosticBuffer.cpp Driver/TextDiagnosticBuffer.h Driver/TextDiagnosticPrinter.cpp Driver/TextDiagnosticPrinter.h Driver/TextDiagnostics.cpp Driver/TextDiagnostics.h Lex/Lexer.cpp include/clang/Basic/Diagnostic.h
Chris Lattner
sabre at nondot.org
Fri Nov 30 14:53:43 PST 2007
Author: lattner
Date: Fri Nov 30 16:53:43 2007
New Revision: 44473
URL: http://llvm.org/viewvc/llvm-project?rev=44473&view=rev
Log:
start partitioning the diagnostics into two classes: those
that are builtin and those that are aren't. This is a bunch
of API refactoring that will make this possible, but there is
no functionality change yet.
Modified:
cfe/trunk/Basic/Diagnostic.cpp
cfe/trunk/Driver/DiagChecker.cpp
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Driver/TextDiagnosticBuffer.cpp
cfe/trunk/Driver/TextDiagnosticBuffer.h
cfe/trunk/Driver/TextDiagnosticPrinter.cpp
cfe/trunk/Driver/TextDiagnosticPrinter.h
cfe/trunk/Driver/TextDiagnostics.cpp
cfe/trunk/Driver/TextDiagnostics.h
cfe/trunk/Lex/Lexer.cpp
cfe/trunk/include/clang/Basic/Diagnostic.h
Modified: cfe/trunk/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/Diagnostic.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/Basic/Diagnostic.cpp Fri Nov 30 16:53:43 2007
@@ -36,8 +36,9 @@
/// getDiagClass - Return the class field of the diagnostic.
///
-static unsigned getDiagClass(unsigned DiagID) {
- assert(DiagID < diag::NUM_DIAGNOSTICS && "Diagnostic ID out of range!");
+static unsigned getBuiltinDiagClass(unsigned DiagID) {
+ assert(DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
+ "Diagnostic ID out of range!");
return DiagnosticFlags[DiagID] & class_mask;
}
@@ -61,25 +62,34 @@
NumErrors = 0;
}
-/// isNoteWarningOrExtension - Return true if the unmapped diagnostic level of
-/// the specified diagnostic ID is a Note, Warning, or Extension.
-bool Diagnostic::isNoteWarningOrExtension(unsigned DiagID) {
- return getDiagClass(DiagID) < ERROR;
+/// isBuiltinNoteWarningOrExtension - Return true if the unmapped diagnostic
+/// level of the specified diagnostic ID is a Note, Warning, or Extension.
+/// Note that this only works on builtin diagnostics, not custom ones.
+bool Diagnostic::isBuiltinNoteWarningOrExtension(unsigned DiagID) {
+ return DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
+ getBuiltinDiagClass(DiagID) < ERROR;
}
/// getDescription - Given a diagnostic ID, return a description of the
/// issue.
const char *Diagnostic::getDescription(unsigned DiagID) {
- assert(DiagID < diag::NUM_DIAGNOSTICS && "Diagnostic ID out of range!");
- return DiagnosticText[DiagID];
+ if (DiagID < diag::NUM_BUILTIN_DIAGNOSTICS)
+ return DiagnosticText[DiagID];
+ else
+ assert(0 && "FIXME: IMPLEMENT");
}
/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
/// object, classify the specified diagnostic ID into a Level, consumable by
/// the DiagnosticClient.
Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
- unsigned DiagClass = getDiagClass(DiagID);
+ if (DiagID >= diag::NUM_BUILTIN_DIAGNOSTICS) {
+ // FIXME: HAndle custom here.
+ assert(0 && "unimp");
+ }
+
+ unsigned DiagClass = getBuiltinDiagClass(DiagID);
// Specific non-error diagnostics may be mapped to various levels from ignored
// to error.
@@ -137,8 +147,8 @@
return;
// Finally, report it.
- Client.HandleDiagnostic(DiagLevel, Pos, (diag::kind)DiagID, Strs, NumStrs,
- Ranges, NumRanges);
+ Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID,
+ Strs, NumStrs, Ranges, NumRanges);
++NumDiagnostics;
}
Modified: cfe/trunk/Driver/DiagChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/DiagChecker.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/DiagChecker.cpp (original)
+++ cfe/trunk/Driver/DiagChecker.cpp Fri Nov 30 16:53:43 2007
@@ -96,8 +96,8 @@
// Turn off all warnings from relexing or preprocessing.
PP.getDiagnostics().setWarnOnExtensions(false);
PP.getDiagnostics().setErrorOnExtensions(false);
- for (unsigned i = 0; i != diag::NUM_DIAGNOSTICS; ++i)
- if (PP.getDiagnostics().isNoteWarningOrExtension((diag::kind)i))
+ for (unsigned i = 0; i != diag::NUM_BUILTIN_DIAGNOSTICS; ++i)
+ if (PP.getDiagnostics().isBuiltinNoteWarningOrExtension((diag::kind)i))
PP.getDiagnostics().setDiagnosticMapping((diag::kind)i, diag::MAP_IGNORE);
Token Tok;
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Fri Nov 30 16:53:43 2007
@@ -17,6 +17,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "clang/Lex/Lexer.h"
@@ -869,6 +870,7 @@
return Exp;
}
+ // Replace this subexpr in the parent.
delete Exp;
return Replacement;
}
Modified: cfe/trunk/Driver/TextDiagnosticBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticBuffer.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticBuffer.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticBuffer.cpp Fri Nov 30 16:53:43 2007
@@ -17,7 +17,8 @@
/// HandleDiagnostic - Store the errors & warnings that are reported.
///
-void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic::Level Level,
+void TextDiagnosticBuffer::HandleDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level Level,
SourceLocation Pos,
diag::kind ID,
const std::string *Strs,
@@ -27,12 +28,12 @@
switch (Level) {
default: assert(0 && "Diagnostic not handled during diagnostic buffering!");
case Diagnostic::Warning:
- Warnings.push_back(std::make_pair(Pos, FormatDiagnostic(Level, ID, Strs,
- NumStrs)));
+ Warnings.push_back(std::make_pair(Pos, FormatDiagnostic(Diags, Level, ID,
+ Strs, NumStrs)));
break;
case Diagnostic::Error:
- Errors.push_back(std::make_pair(Pos, FormatDiagnostic(Level, ID, Strs,
- NumStrs)));
+ Errors.push_back(std::make_pair(Pos, FormatDiagnostic(Diags, Level, ID,
+ Strs, NumStrs)));
break;
}
}
Modified: cfe/trunk/Driver/TextDiagnosticBuffer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticBuffer.h?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticBuffer.h (original)
+++ cfe/trunk/Driver/TextDiagnosticBuffer.h Fri Nov 30 16:53:43 2007
@@ -38,7 +38,7 @@
const_iterator warn_begin() const { return Warnings.begin(); }
const_iterator warn_end() const { return Warnings.end(); }
- virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+ virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
SourceLocation Pos,
diag::kind ID, const std::string *Strs,
unsigned NumStrs,
Modified: cfe/trunk/Driver/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.cpp Fri Nov 30 16:53:43 2007
@@ -97,7 +97,8 @@
CaratLine[i] = '~';
}
-void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
+void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level Level,
SourceLocation Pos,
diag::kind ID,
const std::string *Strs,
@@ -149,7 +150,7 @@
break;
}
- std::cerr << FormatDiagnostic(Level, ID, Strs, NumStrs) << "\n";
+ std::cerr << FormatDiagnostic(Diags, Level, ID, Strs, NumStrs) << "\n";
if (!NoCaretDiagnostics && Pos.isValid()) {
// Get the line of the source file.
Modified: cfe/trunk/Driver/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnosticPrinter.h?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/Driver/TextDiagnosticPrinter.h Fri Nov 30 16:53:43 2007
@@ -32,7 +32,7 @@
std::string &CaratLine,
const std::string &SourceLine);
- virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+ virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
SourceLocation Pos,
diag::kind ID, const std::string *Strs,
unsigned NumStrs,
Modified: cfe/trunk/Driver/TextDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.cpp (original)
+++ cfe/trunk/Driver/TextDiagnostics.cpp Fri Nov 30 16:53:43 2007
@@ -19,11 +19,12 @@
TextDiagnostics:: ~TextDiagnostics() {}
-std::string TextDiagnostics::FormatDiagnostic(Diagnostic::Level Level,
+std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level Level,
diag::kind ID,
const std::string *Strs,
unsigned NumStrs) {
- std::string Msg = Diagnostic::getDescription(ID);
+ std::string Msg = Diags.getDescription(ID);
// Replace all instances of %0 in Msg with 'Extra'.
for (unsigned i = 0; i < Msg.size() - 1; ++i) {
@@ -43,8 +44,7 @@
if (Pos.isValid()) {
// If this is a warning or note, and if it a system header, suppress the
// diagnostic.
- if (Level == Diagnostic::Warning ||
- Level == Diagnostic::Note) {
+ if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
if (const FileEntry *F = SourceMgr.getFileEntryForLoc(Pos)) {
DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
if (DirInfo == DirectoryLookup::SystemHeaderDir ||
Modified: cfe/trunk/Driver/TextDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.h?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.h (original)
+++ cfe/trunk/Driver/TextDiagnostics.h Fri Nov 30 16:53:43 2007
@@ -26,7 +26,7 @@
protected:
SourceManager &SourceMgr;
- std::string FormatDiagnostic(Diagnostic::Level Level,
+ std::string FormatDiagnostic(Diagnostic &Diags, Diagnostic::Level Level,
diag::kind ID,
const std::string *Strs,
unsigned NumStrs);
@@ -38,7 +38,7 @@
virtual bool IgnoreDiagnostic(Diagnostic::Level Level,
SourceLocation Pos);
- virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+ virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
SourceLocation Pos,
diag::kind ID, const std::string *Strs,
unsigned NumStrs,
Modified: cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Lexer.cpp?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/trunk/Lex/Lexer.cpp Fri Nov 30 16:53:43 2007
@@ -304,13 +304,13 @@
/// position in the current buffer into a SourceLocation object for rendering.
void Lexer::Diag(const char *Loc, unsigned DiagID,
const std::string &Msg) const {
- if (LexingRawMode && Diagnostic::isNoteWarningOrExtension(DiagID))
+ if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
return;
PP->Diag(getSourceLocation(Loc), DiagID, Msg);
}
void Lexer::Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg) const {
- if (LexingRawMode && Diagnostic::isNoteWarningOrExtension(DiagID))
+ if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID))
return;
PP->Diag(Loc, DiagID, Msg);
}
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=44473&r1=44472&r2=44473&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Fri Nov 30 16:53:43 2007
@@ -28,7 +28,7 @@
enum kind {
#define DIAG(ENUM,FLAGS,DESC) ENUM,
#include "DiagnosticKinds.def"
- NUM_DIAGNOSTICS
+ NUM_BUILTIN_DIAGNOSTICS
};
/// Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs
@@ -54,7 +54,7 @@
/// DiagMappings - Mapping information for diagnostics. Mapping info is
/// packed into two bits per diagnostic.
- unsigned char DiagMappings[(diag::NUM_DIAGNOSTICS+3)/4];
+ unsigned char DiagMappings[(diag::NUM_BUILTIN_DIAGNOSTICS+3)/4];
/// ErrorOccurred - This is set to true when an error is emitted, and is
/// sticky.
@@ -88,7 +88,9 @@
/// setDiagnosticMapping - This allows the client to specify that certain
/// warnings are ignored. Only NOTEs, WARNINGs, and EXTENSIONs can be mapped.
void setDiagnosticMapping(diag::kind Diag, diag::Mapping Map) {
- assert(isNoteWarningOrExtension(Diag) && "Cannot map errors!");
+ assert(Diag < diag::NUM_BUILTIN_DIAGNOSTICS &&
+ "Can only map builtin diagnostics");
+ assert(isBuiltinNoteWarningOrExtension(Diag) && "Cannot map errors!");
unsigned char &Slot = DiagMappings[Diag/4];
unsigned Bits = (Diag & 3)*2;
Slot &= ~(3 << Bits);
@@ -112,16 +114,17 @@
/// getDescription - Given a diagnostic ID, return a description of the
/// issue.
- static const char *getDescription(unsigned DiagID);
+ const char *getDescription(unsigned DiagID);
- /// Level - The level of the diagnostic
+ /// Level - The level of the diagnostic, after it has been through mapping.
enum Level {
Ignored, Note, Warning, Error, Fatal
};
- /// isNoteWarningOrExtension - Return true if the unmapped diagnostic level of
- /// the specified diagnostic ID is a Note, Warning, or Extension.
- static bool isNoteWarningOrExtension(unsigned DiagID);
+ /// isBuiltinNoteWarningOrExtension - Return true if the unmapped diagnostic
+ /// level of the specified diagnostic ID is a Note, Warning, or Extension.
+ /// Note that this only works on builtin diagnostics, not custom ones.
+ static bool isBuiltinNoteWarningOrExtension(unsigned DiagID);
/// getDiagnosticLevel - Based on the way the client configured the Diagnostic
/// object, classify the specified diagnostic ID into a Level, consumable by
@@ -148,7 +151,8 @@
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
/// capturing it to a log as needed.
- virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, SourceLocation Pos,
+ virtual void HandleDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level DiagLevel, SourceLocation Pos,
diag::kind ID, const std::string *Strs,
unsigned NumStrs, const SourceRange *Ranges,
unsigned NumRanges) = 0;
More information about the cfe-commits
mailing list