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()
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),
//===----------------------------------------------------------------------===//
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);
}
}
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.
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));
}
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.
case Stmt::BinaryConditionalOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ObjCForCollectionStmtClass: {
- SourceLocation L = getValidSourceLocation(S, *PM);
+ SourceLocation L = getValidSourceLocation(S, LC);
return SourceRange(L, L);
}
}