[cfe-commits] r140147 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Anna Zaks
ganna at apple.com
Tue Sep 20 09:37:36 PDT 2011
Author: zaks
Date: Tue Sep 20 11:37:36 2011
New Revision: 140147
URL: http://llvm.org/viewvc/llvm-project?rev=140147&view=rev
Log:
[analyzer] Refactor PathDiagnosticLocation: Lazily query LocationContext for a ParentMap as needed.
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=140147&r1=140146&r2=140147&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Tue Sep 20 11:37:36 2011
@@ -98,8 +98,8 @@
FullSourceLoc Loc;
PathDiagnosticRange Range;
- FullSourceLoc genLocation(const ParentMap *PM=0) const;
- PathDiagnosticRange genRange(const ParentMap *PM=0) const;
+ FullSourceLoc genLocation(const LocationContext *LC=0) const;
+ PathDiagnosticRange genRange(const LocationContext *LC=0) const;
public:
PathDiagnosticLocation()
@@ -119,7 +119,10 @@
PathDiagnosticLocation(const Stmt *s,
const SourceManager &sm,
- const LocationContext *lc);
+ const LocationContext *lc)
+ : K(StmtK), S(s), D(0), SM(&sm),
+ Loc(genLocation(lc)), Range(genRange(lc)) {}
+
PathDiagnosticLocation(const Decl *d, const SourceManager &sm)
: K(DeclK), S(0), D(d), SM(&sm),
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=140147&r1=140146&r2=140147&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Tue Sep 20 11:37:36 2011
@@ -131,37 +131,28 @@
//===----------------------------------------------------------------------===//
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 @@
}
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 @@
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 @@
}
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 @@
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ObjCForCollectionStmtClass: {
- SourceLocation L = getValidSourceLocation(S, *PM);
+ SourceLocation L = getValidSourceLocation(S, LC);
return SourceRange(L, L);
}
}
More information about the cfe-commits
mailing list