summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang
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
commita7d76d267264ec8335a8fe472082aa2e32dd326b (patch)
tree7d69820cc9aa88b3731e481220f94d331bffa1e4 /clang/tools/libclang
parent639b40484e6fea68dbbd01b518877b408e7e6fd2 (diff)
downloadbcm5719-llvm-a7d76d267264ec8335a8fe472082aa2e32dd326b.tar.gz
bcm5719-llvm-a7d76d267264ec8335a8fe472082aa2e32dd326b.zip
[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. llvm-svn: 166130
Diffstat (limited to 'clang/tools/libclang')
-rw-r--r--clang/tools/libclang/CXComment.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp
index 5b722a5a155..44b947379be 100644
--- a/clang/tools/libclang/CXComment.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud