[cfe-commits] r66310 - in /cfe/trunk: include/clang/Analysis/PathDiagnostic.h lib/Analysis/BugReporter.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/PathDiagnostic.cpp
Ted Kremenek
kremenek at apple.com
Fri Mar 6 15:58:11 PST 2009
Author: kremenek
Date: Fri Mar 6 17:58:11 2009
New Revision: 66310
URL: http://llvm.org/viewvc/llvm-project?rev=66310&view=rev
Log:
Create PathDiagnosticPiece subclasses PathDiagnosticEventPiece and
PathDiagnosticControlFlowPiece to distinguish (in the class hierarchy) between
events and control-flow diagnostic pieces. Clients must now use these directly
when constructing PathDiagnosticPieces.
Modified:
cfe/trunk/include/clang/Analysis/PathDiagnostic.h
cfe/trunk/lib/Analysis/BugReporter.cpp
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/lib/Analysis/PathDiagnostic.cpp
Modified: cfe/trunk/include/clang/Analysis/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathDiagnostic.h?rev=66310&r1=66309&r2=66310&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/Analysis/PathDiagnostic.h Fri Mar 6 17:58:11 2009
@@ -190,14 +190,15 @@
PathDiagnosticPiece();
PathDiagnosticPiece(const PathDiagnosticPiece &P);
PathDiagnosticPiece& operator=(const PathDiagnosticPiece &P);
-
-public:
+
+protected:
PathDiagnosticPiece(FullSourceLoc pos, const std::string& s,
Kind k = Event, DisplayHint hint = Below);
PathDiagnosticPiece(FullSourceLoc pos, const char* s,
Kind k = Event, DisplayHint hint = Below);
+public:
virtual ~PathDiagnosticPiece();
const std::string& getString() const { return str; }
@@ -244,6 +245,40 @@
}
FullSourceLoc getLocation() const { return Pos; }
+
+ static inline bool classof(const PathDiagnosticPiece* P) {
+ return true;
+ }
+};
+
+class PathDiagnosticEventPiece : public PathDiagnosticPiece {
+public:
+ PathDiagnosticEventPiece(FullSourceLoc pos, const std::string& s)
+ : PathDiagnosticPiece(pos, s, Event) {}
+
+ PathDiagnosticEventPiece(FullSourceLoc pos, const char* s)
+ : PathDiagnosticPiece(pos, s, Event) {}
+
+ ~PathDiagnosticEventPiece();
+
+ static inline bool classof(const PathDiagnosticPiece* P) {
+ return P->getKind() == Event;
+ }
+};
+
+class PathDiagnosticControlFlowPiece : public PathDiagnosticPiece {
+public:
+ PathDiagnosticControlFlowPiece(FullSourceLoc pos, const std::string& s)
+ : PathDiagnosticPiece(pos, s, Event) {}
+
+ PathDiagnosticControlFlowPiece(FullSourceLoc pos, const char* s)
+ : PathDiagnosticPiece(pos, s, Event) {}
+
+ ~PathDiagnosticControlFlowPiece();
+
+ static inline bool classof(const PathDiagnosticPiece* P) {
+ return P->getKind() == ControlFlow;
+ }
};
class PathDiagnosticMacroPiece : public PathDiagnosticPiece {
@@ -262,6 +297,10 @@
typedef std::vector<PathDiagnosticPiece*>::iterator iterator;
iterator begin() { return SubPieces.begin(); }
iterator end() { return SubPieces.end(); }
+
+ static inline bool classof(const PathDiagnosticPiece* P) {
+ return P->getKind() == Macro;
+ }
};
} //end clang namespace
Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=66310&r1=66309&r2=66310&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Fri Mar 6 17:58:11 2009
@@ -135,7 +135,7 @@
return NULL;
FullSourceLoc L(S->getLocStart(), BR.getContext().getSourceManager());
- PathDiagnosticPiece* P = new PathDiagnosticPiece(L, getDescription());
+ PathDiagnosticPiece* P = new PathDiagnosticEventPiece(L, getDescription());
const SourceRange *Beg, *End;
getRanges(BR, Beg, End);
@@ -481,7 +481,7 @@
std::string msg = "'" + std::string(VD->getNameAsString()) +
"' now aliases '" + MostRecent->getNameAsString() + "'";
- PD.push_front(new PathDiagnosticPiece(L, msg));
+ PD.push_front(new PathDiagnosticEventPiece(L, msg));
}
return true;
@@ -643,8 +643,7 @@
os << "Control jumps to line "
<< SMgr.getInstantiationLineNumber(S->getLocStart()) << ".\n";
- PD.push_front(new PathDiagnosticPiece(L, os.str(),
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L, os.str()));
break;
}
@@ -712,8 +711,7 @@
ExecutionContinues(os, SMgr, N, getStateManager().getCodeDecl());
}
- PD.push_front(new PathDiagnosticPiece(L, os.str(),
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L, os.str()));
break;
}
@@ -722,8 +720,7 @@
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
ExecutionContinues(os, SMgr, N, getStateManager().getCodeDecl());
- PD.push_front(new PathDiagnosticPiece(L, os.str(),
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L, os.str()));
break;
}
@@ -737,8 +734,7 @@
else
os << "true.";
- PD.push_front(new PathDiagnosticPiece(L, os.str(),
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L, os.str()));
break;
}
@@ -751,13 +747,11 @@
os << "Loop condition is true. ";
ExecutionContinues(os, SMgr, N, getStateManager().getCodeDecl());
- PD.push_front(new PathDiagnosticPiece(L, os.str(),
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L, os.str()));
}
else
- PD.push_front(new PathDiagnosticPiece(L,
- "Loop condition is false. Exiting loop.",
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L,
+ "Loop condition is false. Exiting loop."));
break;
}
@@ -772,24 +766,22 @@
os << "Loop condition is false. ";
ExecutionContinues(os, SMgr, N, getStateManager().getCodeDecl());
- PD.push_front(new PathDiagnosticPiece(L, os.str(),
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L, os.str()));
}
else
- PD.push_front(new PathDiagnosticPiece(L,
- "Loop condition is true. Entering loop body.",
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L,
+ "Loop condition is true. Entering loop body."));
break;
}
case Stmt::IfStmtClass: {
if (*(Src->succ_begin()+1) == Dst)
- PD.push_front(new PathDiagnosticPiece(L, "Taking false branch.",
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L,
+ "Taking false branch."));
else
- PD.push_front(new PathDiagnosticPiece(L, "Taking true branch.",
- PathDiagnosticPiece::ControlFlow));
+ PD.push_front(new PathDiagnosticControlFlowPiece(L,
+ "Taking true branch."));
break;
}
@@ -872,7 +864,9 @@
return;
if (D->empty()) {
- PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription());
+ PathDiagnosticPiece* piece =
+ new PathDiagnosticEventPiece(L, R.getDescription());
+
for ( ; Beg != End; ++Beg) piece->addRange(*Beg);
D->push_back(piece);
}
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=66310&r1=66309&r2=66310&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Mar 6 17:58:11 2009
@@ -2506,7 +2506,7 @@
}
FullSourceLoc Pos(S->getLocStart(), BR.getContext().getSourceManager());
- PathDiagnosticPiece* P = new PathDiagnosticPiece(Pos, os.str());
+ PathDiagnosticPiece* P = new PathDiagnosticEventPiece(Pos, os.str());
if (Expr* Exp = dyn_cast<Expr>(S))
P->addRange(Exp->getSourceRange());
@@ -2655,7 +2655,7 @@
Stmt* S = cast<PostStmt>(N->getLocation()).getStmt();
FullSourceLoc Pos(S->getLocStart(), BR.getContext().getSourceManager());
- PathDiagnosticPiece* P = new PathDiagnosticPiece(Pos, os.str());
+ PathDiagnosticPiece* P = new PathDiagnosticEventPiece(Pos, os.str());
// Add the range by scanning the children of the statement for any bindings
// to Sym.
@@ -2844,7 +2844,7 @@
" +"
<< RV->getCount() << " (object leaked).";
- return new PathDiagnosticPiece(L, os.str());
+ return new PathDiagnosticEventPiece(L, os.str());
}
Modified: cfe/trunk/lib/Analysis/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PathDiagnostic.cpp?rev=66310&r1=66309&r2=66310&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/Analysis/PathDiagnostic.cpp Fri Mar 6 17:58:11 2009
@@ -50,6 +50,8 @@
}
PathDiagnosticPiece::~PathDiagnosticPiece() {}
+PathDiagnosticEventPiece::~PathDiagnosticEventPiece() {}
+PathDiagnosticControlFlowPiece::~PathDiagnosticControlFlowPiece() {}
PathDiagnosticMacroPiece::~PathDiagnosticMacroPiece() {
for (iterator I = begin(), E = end(); I != E; ++I) delete *I;
@@ -99,7 +101,7 @@
Info.FormatDiagnostic(StrC);
PathDiagnosticPiece *P =
- new PathDiagnosticPiece(Info.getLocation(),
+ new PathDiagnosticEventPiece(Info.getLocation(),
std::string(StrC.begin(), StrC.end()));
for (unsigned i = 0, e = Info.getNumRanges(); i != e; ++i)
More information about the cfe-commits
mailing list