aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2011-09-20 16:37:36 +0000
committerAnna Zaks <ganna@apple.com>2011-09-20 16:37:36 +0000
commite97436732c0f20aa15ecbf92a5f905eee888528f (patch)
tree1171f5c3e9d4999723c4f529a5cc4c7d2020ebcf /lib
parent23803374d8db054192ea6fcb766b87e04f26c8fb (diff)
[analyzer] Refactor PathDiagnosticLocation: Lazily query LocationContext for a ParentMap as needed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140147 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/StaticAnalyzer/Core/PathDiagnostic.cpp35
1 files changed, 13 insertions, 22 deletions
diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 6ef2b075b3..1d03b66997 100644
--- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -131,37 +131,28 @@ void PathDiagnosticClient::HandlePathDiagnostic(const PathDiagnostic *D) {
//===----------------------------------------------------------------------===//
static SourceLocation getValidSourceLocation(const Stmt* S,
- const ParentMap &PM) {
+ const LocationContext *LC) {
SourceLocation L = S->getLocStart();
// S might be a temporary statement that does not have a location in the
// source code, so find an enclosing statement and use it's location.
- while (!L.isValid()) {
- S = PM.getParent(S);
- L = S->getLocStart();
+ if (!L.isValid()) {
+ const ParentMap &PM = LC->getParentMap();
+
+ while (!L.isValid()) {
+ S = PM.getParent(S);
+ L = S->getLocStart();
+ }
}
return L;
}
-PathDiagnosticLocation::PathDiagnosticLocation(const Stmt *s,
- const SourceManager &sm,
- const LocationContext *lc)
- : K(StmtK), S(s), D(0), SM(&sm)
-{
- const ParentMap* PM = 0;
- if (lc)
- PM = &lc->getParentMap();
-
- Loc = genLocation(PM);
- Range = genRange(PM);
-}
-
PathDiagnosticLocation
PathDiagnosticLocation::createBeginStmt(const Stmt *S,
const SourceManager &SM,
const LocationContext *LC) {
- return PathDiagnosticLocation(getValidSourceLocation(S, LC->getParentMap()),
+ return PathDiagnosticLocation(getValidSourceLocation(S, LC),
SM, SingleLocK);
}
@@ -255,7 +246,7 @@ PathDiagnosticLocation PathDiagnosticLocation::createSingleLocation(
}
FullSourceLoc
- PathDiagnosticLocation::genLocation(const ParentMap *PM) const {
+ PathDiagnosticLocation::genLocation(const LocationContext *LC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
@@ -264,7 +255,7 @@ FullSourceLoc
case RangeK:
break;
case StmtK:
- return FullSourceLoc(getValidSourceLocation(S, *PM),
+ return FullSourceLoc(getValidSourceLocation(S, LC),
const_cast<SourceManager&>(*SM));
case DeclK:
return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
@@ -274,7 +265,7 @@ FullSourceLoc
}
PathDiagnosticRange
- PathDiagnosticLocation::genRange(const ParentMap *PM) const {
+ PathDiagnosticLocation::genRange(const LocationContext *LC) const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
// case we add more cases.
@@ -309,7 +300,7 @@ PathDiagnosticRange
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ObjCForCollectionStmtClass: {
- SourceLocation L = getValidSourceLocation(S, *PM);
+ SourceLocation L = getValidSourceLocation(S, LC);
return SourceRange(L, L);
}
}