[clang-doc] Refactoring mapper to map by scope

The result of this adjusted mapper pass is that all Function and Enum
infos are absorbed into the info of their enclosing scope (i.e. the
class or namespace in which they are defined). Namespace and Record
infos are passed along to the final output, but the second pass creates
a reference to each in its parent scope. As a result, the top-level final
outputs are Namespaces and Records.

llvm-svn: 338738
diff --git a/clang-tools-extra/clang-doc/Mapper.cpp b/clang-tools-extra/clang-doc/Mapper.cpp
index fb0b42a..4456c1e 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/Comment.h"
 #include "clang/Index/USRGeneration.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Error.h"
 
 using clang::comments::FullComment;
 
@@ -33,14 +34,15 @@
   if (index::generateUSRForDecl(D, USR))
     return true;
 
-  std::string info = serialize::emitInfo(
+  auto I = serialize::emitInfo(
       D, getComment(D, D->getASTContext()), getLine(D, D->getASTContext()),
       getFile(D, D->getASTContext()), CDCtx.PublicOnly);
 
-  if (info != "")
-    CDCtx.ECtx->reportResult(
-        llvm::toHex(llvm::toStringRef(serialize::hashUSR(USR))), info);
-
+  // A null in place of I indicates that the serializer is skipping this decl
+  // for some reason (e.g. we're only reporting public decls).
+  if (I)
+    CDCtx.ECtx->reportResult(llvm::toHex(llvm::toStringRef(I->USR)),
+                       serialize::serialize(I));
   return true;
 }