[Doc parsing]: This patch adds <Declaration> tag to 
XML comment for declarations which pretty-prints
declaration. I had to XFAIL one test annotate-comments.cpp.
This test is currently unmaintainable as written.
Dmitri G., can you see what we can do about this test.
We should change this test such that adding a new tag does not wreck
havoc to the test.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166130 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp
index 5b722a5..44b9473 100644
--- a/tools/libclang/CXComment.cpp
+++ b/tools/libclang/CXComment.cpp
@@ -16,6 +16,7 @@
 #include "CXComment.h"
 #include "CXCursor.h"
 
+#include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/CommentVisitor.h"
 #include "clang/AST/CommentCommandTraits.h"
 #include "clang/AST/Decl.h"
@@ -1027,6 +1028,20 @@
   Result << "</Verbatim>";
 }
 
+static StringRef getSourceTextOfDeclaration(const DeclInfo *ThisDecl) {
+  
+  ASTContext &Context = ThisDecl->CurrentDecl->getASTContext();
+  const LangOptions &LangOpts = Context.getLangOpts();
+  std::string SStr;
+  llvm::raw_string_ostream S(SStr);
+  PrintingPolicy PPolicy(LangOpts);
+  PPolicy.SuppressAttributes = true;
+  PPolicy.TerseOutput = true;
+  ThisDecl->CurrentDecl->print(S, PPolicy,
+                               /*Indentation*/0, /*PrintInstantiation*/true);
+  return S.str();
+}
+
 void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
   FullCommentParts Parts(C, Traits);
 
@@ -1096,7 +1111,7 @@
 
     {
       // Print line and column number.
-      SourceLocation Loc = DI->Loc;
+      SourceLocation Loc = DI->CurrentDecl->getLocation();
       std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(Loc);
       FileID FID = LocInfo.first;
       unsigned FileOffset = LocInfo.second;
@@ -1146,6 +1161,10 @@
   }
 
   bool FirstParagraphIsBrief = false;
+  Result << "<Declaration>";
+  appendToResultWithXMLEscaping(getSourceTextOfDeclaration(DI));
+  Result << "</Declaration>";
+  
   if (Parts.Brief) {
     Result << "<Abstract>";
     visit(Parts.Brief);