Improved TypeLoc::getSourceRange().

llvm-svn: 104382
This commit is contained in:
Abramo Bagnara 2010-05-21 21:12:12 +00:00
parent 3dca28d0e2
commit f7eba5091c
2 changed files with 43 additions and 8 deletions

View File

@ -85,16 +85,15 @@ public:
return Data;
}
/// \brief Get the begin source location.
SourceLocation getBeginLoc() const;
/// \brief Get the end source location.
SourceLocation getEndLoc() const;
/// \brief Get the full source range.
SourceRange getSourceRange() const {
SourceLocation End = getLocalSourceRange().getEnd();
TypeLoc Cur = *this;
while (true) {
TypeLoc Next = Cur.getNextTypeLoc();
if (Next.isNull()) break;
Cur = Next;
}
return SourceRange(Cur.getLocalSourceRange().getBegin(), End);
return SourceRange(getBeginLoc(), getEndLoc());
}
/// \brief Get the local source range.

View File

@ -108,6 +108,42 @@ void TypeLoc::initializeImpl(TypeLoc TL, SourceLocation Loc) {
}
}
SourceLocation TypeLoc::getBeginLoc() const {
TypeLoc Cur = *this;
while (true) {
switch (Cur.getTypeLocClass()) {
// FIXME: Currently QualifiedTypeLoc does not have a source range
// case Qualified:
case Elaborated:
break;
default:
TypeLoc Next = Cur.getNextTypeLoc();
if (Next.isNull()) break;
Cur = Next;
continue;
}
break;
}
return Cur.getLocalSourceRange().getBegin();
}
SourceLocation TypeLoc::getEndLoc() const {
TypeLoc Cur = *this;
while (true) {
switch (Cur.getTypeLocClass()) {
default:
break;
case Qualified:
case Elaborated:
Cur = Cur.getNextTypeLoc();
continue;
}
break;
}
return Cur.getLocalSourceRange().getEnd();
}
namespace {
struct TSTChecker : public TypeLocVisitor<TSTChecker, bool> {
// Overload resolution does the real work for us.