]> granicus.if.org Git - clang/commitdiff
Improved TypeLoc::getSourceRange().
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Fri, 21 May 2010 21:12:12 +0000 (21:12 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Fri, 21 May 2010 21:12:12 +0000 (21:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104382 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/TypeLoc.h
lib/AST/TypeLoc.cpp

index 0a3a5d45a5615392359923d6334dc29aa193192e..f988f0e33b39a846342cccb83f5c98ae52415949 100644 (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.
index 678a0f047552d83d81d0d64f7cba41d505385795..4893b384dd101ae67d88c79df2eea963d664b841 100644 (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.