summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/Diagnostic.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-11-18 07:04:44 +0000
committerChris Lattner <sabre@nondot.org>2008-11-18 07:04:44 +0000
commit8488c8297c24c294b52434460daddad16a9b203e (patch)
treecf5e4ca4323600f090fab703d2807ae6795e72c6 /clang/lib/Basic/Diagnostic.cpp
parent5fa5052d50968dbafc66b18c5c662733c59c8668 (diff)
downloadbcm5719-llvm-8488c8297c24c294b52434460daddad16a9b203e.tar.gz
bcm5719-llvm-8488c8297c24c294b52434460daddad16a9b203e.zip
This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed. In particular, a diagnostic with all its strings and ranges is now packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a ton of random stuff. This has the benefit of simplifying the interface, making it more extensible, and allowing us to do more checking for things like access past the end of the various arrays passed in. In addition to introducing DiagnosticInfo, this also substantially changes how Diagnostic::Report works. Instead of being passed in all of the info required to issue a diagnostic, Report now takes only the required info (a location and ID) and returns a fresh DiagnosticInfo *by value*. The caller is then free to stuff strings and ranges into the DiagnosticInfo with the << operator. When the dtor runs on the DiagnosticInfo object (which should happen at the end of the statement), the diagnostic is actually emitted with all of the accumulated information. This is a somewhat tricky dance, but it means that the accumulated DiagnosticInfo is allowed to keep pointers to other expression temporaries without those pointers getting invalidated. This is just the minimal change to get this stuff working, but this will allow us to eliminate the zillions of variant "Diag" methods scattered throughout (e.g.) sema. For example, instead of calling: Diag(BuiltinLoc, diag::err_overload_no_match, typeNames, SourceRange(BuiltinLoc, RParenLoc)); We will soon be able to just do: Diag(BuiltinLoc, diag::err_overload_no_match) << typeNames << SourceRange(BuiltinLoc, RParenLoc)); This scales better to support arbitrary types being passed in (not just strings) in a type-safe way. Go operator overloading?! llvm-svn: 59502
Diffstat (limited to 'clang/lib/Basic/Diagnostic.cpp')
-rw-r--r--clang/lib/Basic/Diagnostic.cpp52
1 files changed, 19 insertions, 33 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 2076b16db08..a202a55f268 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -127,6 +127,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
NumDiagnostics = 0;
NumErrors = 0;
CustomDiagInfo = 0;
+ NumDiagArgs = -1;
}
Diagnostic::~Diagnostic() {
@@ -154,7 +155,7 @@ bool Diagnostic::isBuiltinNoteWarningOrExtension(unsigned DiagID) {
/// getDescription - Given a diagnostic ID, return a description of the
/// issue.
-const char *Diagnostic::getDescription(unsigned DiagID) {
+const char *Diagnostic::getDescription(unsigned DiagID) const {
if (DiagID < diag::NUM_BUILTIN_DIAGNOSTICS)
return DiagnosticText[DiagID];
else
@@ -210,66 +211,51 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
}
}
-/// Report - Issue the message to the client.
-/// DiagID is a member of the diag::kind enum.
-void Diagnostic::Report(DiagnosticClient* C,
- FullSourceLoc Loc, unsigned DiagID,
- const std::string **Strs, unsigned NumStrs,
- const SourceRange *Ranges, unsigned NumRanges) {
-
+/// ProcessDiag - This is the method used to report a diagnostic that is
+/// finally fully formed.
+void Diagnostic::ProcessDiag(const DiagnosticInfo &Info) {
// Figure out the diagnostic level of this message.
- Diagnostic::Level DiagLevel = getDiagnosticLevel(DiagID);
+ Diagnostic::Level DiagLevel = getDiagnosticLevel(Info.getID());
// If the client doesn't care about this message, don't issue it.
if (DiagLevel == Diagnostic::Ignored)
return;
- // Set the diagnostic client if it isn't set already.
- if (!C) C = Client;
-
// If this is not an error and we are in a system header, ignore it. We
- // have to check on the original DiagID here, because we also want to
+ // have to check on the original Diag ID here, because we also want to
// ignore extensions and warnings in -Werror and -pedantic-errors modes,
// which *map* warnings/extensions to errors.
if (SuppressSystemWarnings &&
- DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
- getBuiltinDiagClass(DiagID) != ERROR &&
- Loc.isValid() && Loc.getPhysicalLoc().isInSystemHeader())
+ Info.getID() < diag::NUM_BUILTIN_DIAGNOSTICS &&
+ getBuiltinDiagClass(Info.getID()) != ERROR &&
+ Info.getLocation().isValid() &&
+ Info.getLocation().getPhysicalLoc().isInSystemHeader())
return;
if (DiagLevel >= Diagnostic::Error) {
ErrorOccurred = true;
- if (C != 0 && C == Client)
- ++NumErrors;
+ ++NumErrors;
}
// Finally, report it.
-
- if (C != 0)
- C->HandleDiagnostic(*this, DiagLevel, Loc, (diag::kind)DiagID,
- Strs, NumStrs, Ranges, NumRanges);
-
- if (C != 0 && C == Client)
- ++NumDiagnostics;
+ Client->HandleDiagnostic(DiagLevel, Info);
+ ++NumDiagnostics;
}
DiagnosticClient::~DiagnosticClient() {}
-std::string DiagnosticClient::FormatDiagnostic(Diagnostic &Diags,
- Diagnostic::Level Level,
- diag::kind ID,
- const std::string **Strs,
- unsigned NumStrs) {
- std::string Msg = Diags.getDescription(ID);
+std::string DiagnosticClient::FormatDiagnostic(const DiagnosticInfo &Info) {
+ std::string Msg = Info.getDiags()->getDescription(Info.getID());
- // Replace all instances of %0 in Msg with 'Extra'.
+ // Replace all instances of %0 in Msg with 'Extra'. This is a pretty horrible
+ // and inefficient way to do this, we could improve this a lot if we care.
for (unsigned i = 0; i < Msg.size() - 1; ++i) {
if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
unsigned StrNo = Msg[i + 1] - '0';
Msg = std::string(Msg.begin(), Msg.begin() + i) +
- (StrNo < NumStrs ? *Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
+ Info.getArgStr(StrNo) +
std::string(Msg.begin() + i + 2, Msg.end());
}
}
OpenPOWER on IntegriCloud