Update UsingDecl, UnresolvedUsingTypenameDecl, and
UnresolvedUsingValueDecl to use NestedNameSpecifierLoc rather than the
extremely-lossy NestedNameSpecifier/SourceRange pair it used to use,
improving source-location information.

Various infrastructure updates to support NestedNameSpecifierLoc:
  - AST/PCH (de-)serialization
  - Recursive AST visitor
  - libclang traversal (including the first tests of this
    functionality)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126459 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/NestedNameSpecifier.cpp b/lib/AST/NestedNameSpecifier.cpp
index da12aa7..0689ae1 100644
--- a/lib/AST/NestedNameSpecifier.cpp
+++ b/lib/AST/NestedNameSpecifier.cpp
@@ -320,7 +320,7 @@
   }
 }
 
-SourceRange NestedNameSpecifierLoc::getSourceRange() {
+SourceRange NestedNameSpecifierLoc::getSourceRange() const {
   NestedNameSpecifierLoc First = *this;
   while (NestedNameSpecifierLoc Prefix= First.getPrefix())
     First = Prefix;
@@ -329,7 +329,7 @@
                      getLocalSourceRange().getEnd());
 }
 
-SourceRange NestedNameSpecifierLoc::getLocalSourceRange() {
+SourceRange NestedNameSpecifierLoc::getLocalSourceRange() const {
   unsigned Offset = getDataLength(Qualifier->getPrefix());
   switch (Qualifier->getKind()) {
   case NestedNameSpecifier::Global:
@@ -354,3 +354,14 @@
   
   return SourceRange();
 }
+
+TypeLoc NestedNameSpecifierLoc::getTypeLoc() const {
+  assert((Qualifier->getKind() == NestedNameSpecifier::TypeSpec ||
+          Qualifier->getKind() == NestedNameSpecifier::TypeSpecWithTemplate) &&
+         "Nested-name-specifier location is not a type");
+
+  // The "void*" that points at the TypeLoc data.
+  unsigned Offset = getDataLength(Qualifier->getPrefix());
+  void *TypeData = LoadPointer(Data, Offset);
+  return TypeLoc(Qualifier->getAsType(), TypeData);
+}