aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BugReporter.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
commit0a14eee528a901c16f0e288fbc10a3abc1660d87 (patch)
tree1c6a7acf8be19bebf1f390638bfa52045a7dcf97 /lib/Analysis/BugReporter.cpp
parent46bbacac37141ed9d01d5b6473e8211554b02710 (diff)
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?! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59502 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BugReporter.cpp')
-rw-r--r--lib/Analysis/BugReporter.cpp35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index bf99e6ba63..0074a93b5b 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -773,21 +773,26 @@ void BugReporter::EmitWarning(BugReport& R) {
D->push_back(piece);
PD->HandlePathDiagnostic(D.take());
+ return;
}
else {
- std::ostringstream os;
+ std::string str;
if (D->empty())
- os << R.getDescription();
+ str = R.getDescription();
else
- os << D->back()->getString();
-
+ str = D->back()->getString();
Diagnostic& Diag = getDiagnostic();
- unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
- os.str().c_str());
-
- Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
+ unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning, str.c_str());
+
+ switch (End-Beg) {
+ default: assert(0 && "Don't handle this many ranges yet!");
+ case 0: Diag.Report(L, ErrorDiag); break;
+ case 1: Diag.Report(L, ErrorDiag) << Beg[0]; break;
+ case 2: Diag.Report(L, ErrorDiag) << Beg[0] << Beg[1]; break;
+ case 3: Diag.Report(L, ErrorDiag) << Beg[0] << Beg[1] << Beg[2]; break;
+ }
}
}
@@ -807,9 +812,17 @@ void BugReporter::EmitBasicReport(const char* name, const char* category,
DiagnosticClient *OldClient = Diag.getClient();
Diag.setClient(&C);
- Diag.Report(getContext().getFullLoc(Loc),
- Diag.getCustomDiagID(Diagnostic::Warning, str),
- 0, 0, RBeg, NumRanges);
+ FullSourceLoc L = getContext().getFullLoc(Loc);
+ unsigned DiagID = Diag.getCustomDiagID(Diagnostic::Warning, str);
+
+ switch (NumRanges) {
+ default: assert(0 && "Don't handle this many ranges yet!");
+ case 0: Diag.Report(L, DiagID); break;
+ case 1: Diag.Report(L, DiagID) << RBeg[0]; break;
+ case 2: Diag.Report(L, DiagID) << RBeg[0] << RBeg[1]; break;
+ case 3: Diag.Report(L, DiagID) << RBeg[0] << RBeg[1] << RBeg[2]; break;
+ }
+
Diag.setClient(OldClient);
for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)