[cfe-commits] r53560 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BugReporter.cpp lib/Analysis/CheckObjCDealloc.cpp lib/Analysis/CheckObjCInstMethSignature.cpp
Ted Kremenek
kremenek at apple.com
Mon Jul 14 10:40:50 PDT 2008
Author: kremenek
Date: Mon Jul 14 12:40:50 2008
New Revision: 53560
URL: http://llvm.org/viewvc/llvm-project?rev=53560&view=rev
Log:
Added method "EmitBasicReport" to BugReporter to simplify the emission of simple bug diagnostics.
Refactored error reporting in CheckObjCDealloc and CheckObjCInstMethSignature to use this new bug reporting interface (major code simplification).
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
cfe/trunk/lib/Analysis/BugReporter.cpp
cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=53560&r1=53559&r2=53560&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Mon Jul 14 12:40:50 2008
@@ -189,6 +189,9 @@
void EmitWarning(BugReport& R);
+ void EmitBasicReport(const char* BugName, const char* BugStr,
+ SourceLocation Loc);
+
static bool classof(const BugReporter* R) { return true; }
};
Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=53560&r1=53559&r2=53560&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Mon Jul 14 12:40:50 2008
@@ -731,12 +731,12 @@
// Determine the range.
const SourceRange *Beg, *End;
-
+
if (!D->empty()) {
Beg = D->back()->ranges_begin();
End = D->back()->ranges_end();
}
- else
+ else
R.getRanges(*this, Beg, End);
if (PD) {
@@ -745,18 +745,18 @@
for ( ; Beg != End; ++Beg)
piece->addRange(*Beg);
- D->push_back(piece);
+ D->push_back(piece);
PD->HandlePathDiagnostic(D.take());
}
else {
- std::ostringstream os;
-
+ std::ostringstream os;
+
if (D->empty())
os << R.getDescription();
else
os << D->back()->getString();
-
-
+
+
Diagnostic& Diag = getDiagnostic();
unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
os.str().c_str());
@@ -764,3 +764,19 @@
Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
}
}
+
+void
+BugReporter::EmitBasicReport(const char* name, const char* str,
+ SourceLocation Loc) {
+
+ SimpleBugType BT(name);
+ DiagCollector C(BT);
+ Diagnostic& Diag = getDiagnostic();
+ Diag.Report(&C, getContext().getFullLoc(Loc),
+ Diag.getCustomDiagID(Diagnostic::Warning, str),
+ 0, 0, 0, 0);
+
+ for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
+ EmitWarning(*I);
+}
+
Modified: cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp?rev=53560&r1=53559&r2=53560&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCDealloc.cpp Mon Jul 14 12:40:50 2008
@@ -83,8 +83,7 @@
// Get the "dealloc" selector.
IdentifierInfo* II = &Ctx.Idents.get("dealloc");
- Selector S = Ctx.Selectors.getSelector(0, &II);
-
+ Selector S = Ctx.Selectors.getSelector(0, &II);
ObjCMethodDecl* MD = 0;
// Scan the instance methods for "dealloc".
@@ -99,52 +98,32 @@
if (!MD) { // No dealloc found.
- // FIXME: This code should be reduced to three lines if possible (Refactor).
- SimpleBugType BT(LOpts.getGCMode() == LangOptions::NonGC
- ? "missing -dealloc"
- : "missing -dealloc (Hybrid MM, non-GC)");
-
- DiagCollector C(BT);
+ const char* name = LOpts.getGCMode() == LangOptions::NonGC
+ ? "missing -dealloc"
+ : "missing -dealloc (Hybrid MM, non-GC)";
std::ostringstream os;
os << "Objective-C class '" << D->getName()
<< "' lacks a 'dealloc' instance method";
- Diagnostic& Diag = BR.getDiagnostic();
- Diag.Report(&C,
- Ctx.getFullLoc(D->getLocStart()),
- Diag.getCustomDiagID(Diagnostic::Warning, os.str().c_str()),
- NULL, 0, NULL, 0);
-
- for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
- BR.EmitWarning(*I);
-
+ BR.EmitBasicReport(name, os.str().c_str(), D->getLocStart());
return;
}
// dealloc found. Scan for missing [super dealloc].
if (MD->getBody() && !scan_dealloc(MD->getBody(), S)) {
- // FIXME: This code should be reduced to three lines if possible (Refactor).
- SimpleBugType BT(LOpts.getGCMode() == LangOptions::NonGC
- ? "missing [super dealloc]"
- : "missing [super dealloc] (Hybrid MM, non-GC)");
-
- DiagCollector C(BT);
+ const char* name = LOpts.getGCMode() == LangOptions::NonGC
+ ? "missing [super dealloc]"
+ : "missing [super dealloc] (Hybrid MM, non-GC)";
std::ostringstream os;
os << "The 'dealloc' instance method in Objective-C class '" << D->getName()
<< "' does not send a 'dealloc' message to its super class"
" (missing [super dealloc])";
- Diagnostic& Diag = BR.getDiagnostic();
- Diag.Report(&C,
- Ctx.getFullLoc(MD->getLocStart()),
- Diag.getCustomDiagID(Diagnostic::Warning, os.str().c_str()),
- NULL, 0, NULL, 0);
-
- for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
- BR.EmitWarning(*I);
- }
+ BR.EmitBasicReport(name, os.str().c_str(), D->getLocStart());
+ return;
+ }
}
Modified: cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp?rev=53560&r1=53559&r2=53560&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckObjCInstMethSignature.cpp Mon Jul 14 12:40:50 2008
@@ -64,16 +64,8 @@
<< "'. These two types are incompatible, and may result in undefined "
"behavior for clients of these classes.";
- // Refactor.
- SimpleBugType BT("incompatible instance method return type");
- DiagCollector C(BT);
- Diagnostic& Diag = BR.getDiagnostic();
- Diag.Report(&C, Ctx.getFullLoc(MethDerived->getLocStart()),
- Diag.getCustomDiagID(Diagnostic::Warning, os.str().c_str()),
- NULL, 0, NULL, 0);
-
- for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
- BR.EmitWarning(*I);
+ BR.EmitBasicReport("incompatible instance method return type",
+ os.str().c_str(), MethDerived->getLocStart());
}
}
More information about the cfe-commits
mailing list