summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-10-17 21:58:03 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-10-17 21:58:03 +0000
commit1bfb00dabf83d8c8b95b7276b4c0ae3fd64832c8 (patch)
tree6da011bab01450d4f467948bdc61b9c55b021ed8 /tools
parent20d928164a6263edb558fdccae6e73988cf4ae7d (diff)
downloadclang-1bfb00dabf83d8c8b95b7276b4c0ae3fd64832c8.tar.gz
[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
Diffstat (limited to 'tools')
-rw-r--r--tools/libclang/CXComment.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp
index 5b722a5a15..44b947379b 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 @@ void CommentASTToXMLConverter::visitVerbatimLineComment(
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 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
{
// 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 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
}
bool FirstParagraphIsBrief = false;
+ Result << "<Declaration>";
+ appendToResultWithXMLEscaping(getSourceTextOfDeclaration(DI));
+ Result << "</Declaration>";
+
if (Parts.Brief) {
Result << "<Abstract>";
visit(Parts.Brief);