diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-23 16:43:01 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-23 16:43:01 +0000 |
commit | d73e4ce992a9c17937c8d3d616ceb391e6e97538 (patch) | |
tree | 1e439ed861ff3eb9049992544f158cfbd15efe2e /clang/tools | |
parent | 9eedce1e7c9f8328df77637d29329919acb9c944 (diff) | |
download | bcm5719-llvm-d73e4ce992a9c17937c8d3d616ceb391e6e97538.tar.gz bcm5719-llvm-d73e4ce992a9c17937c8d3d616ceb391e6e97538.zip |
Comment AST: add InlineContentComment::RenderKind to specify a default
rendering mode for clients that don't want to interpret Doxygen commands.
Also add a libclang API to query this information.
llvm-svn: 160633
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 14 | ||||
-rw-r--r-- | clang/tools/libclang/CXComment.cpp | 64 | ||||
-rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
3 files changed, 58 insertions, 21 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 574c9f73833..df7c72a9d87 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -283,6 +283,20 @@ static void DumpCXCommentInternal(struct CommentASTDumpingContext *Ctx, PrintCXStringWithPrefixAndDispose( "CommandName", clang_InlineCommandComment_getCommandName(Comment)); + switch (clang_InlineCommandComment_getRenderKind(Comment)) { + case CXCommentInlineCommandRenderKind_Normal: + printf(" RenderNormal"); + break; + case CXCommentInlineCommandRenderKind_Bold: + printf(" RenderBold"); + break; + case CXCommentInlineCommandRenderKind_Monospaced: + printf(" RenderMonospaced"); + break; + case CXCommentInlineCommandRenderKind_Emphasized: + printf(" RenderEmphasized"); + break; + } for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment); i != e; ++i) { printf(" Arg[%u]=", i); diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp index b0ed9bcc00e..6cd92356fdf 100644 --- a/clang/tools/libclang/CXComment.cpp +++ b/clang/tools/libclang/CXComment.cpp @@ -126,6 +126,28 @@ CXString clang_InlineCommandComment_getCommandName(CXComment CXC) { return createCXString(ICC->getCommandName(), /*DupString=*/ false); } +enum CXCommentInlineCommandRenderKind +clang_InlineCommandComment_getRenderKind(CXComment CXC) { + const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC); + if (!ICC) + return CXCommentInlineCommandRenderKind_Normal; + + switch (ICC->getRenderKind()) { + case InlineCommandComment::RenderNormal: + return CXCommentInlineCommandRenderKind_Normal; + + case InlineCommandComment::RenderBold: + return CXCommentInlineCommandRenderKind_Bold; + + case InlineCommandComment::RenderMonospaced: + return CXCommentInlineCommandRenderKind_Monospaced; + + case InlineCommandComment::RenderEmphasized: + return CXCommentInlineCommandRenderKind_Emphasized; + } + llvm_unreachable("unknown InlineCommandComment::RenderKind"); +} + unsigned clang_InlineCommandComment_getNumArgs(CXComment CXC) { const InlineCommandComment *ICC = getASTNodeAs<InlineCommandComment>(CXC); if (!ICC) @@ -344,34 +366,34 @@ void CommentASTToHTMLConverter::visitTextComment(const TextComment *C) { void CommentASTToHTMLConverter::visitInlineCommandComment( const InlineCommandComment *C) { - StringRef CommandName = C->getCommandName(); - bool HasArg0 = C->getNumArgs() > 0 && !C->getArgText(0).empty(); - StringRef Arg0; - if (HasArg0) - Arg0 = C->getArgText(0); - - if (CommandName == "b") { - if (!HasArg0) - return; + // Nothing to render if no arguments supplied. + if (C->getNumArgs() == 0) + return; + + // Nothing to render if argument is empty. + StringRef Arg0 = C->getArgText(0); + if (Arg0.empty()) + return; + + switch (C->getRenderKind()) { + case InlineCommandComment::RenderNormal: + for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) + Result << C->getArgText(i) << " "; + return; + + case InlineCommandComment::RenderBold: + assert(C->getNumArgs() == 1); Result << "<b>" << Arg0 << "</b>"; return; - } - if (CommandName == "c" || CommandName == "p") { - if (!HasArg0) - return; + case InlineCommandComment::RenderMonospaced: + assert(C->getNumArgs() == 1); Result << "<tt>" << Arg0 << "</tt>"; return; - } - if (CommandName == "a" || CommandName == "e" || CommandName == "em") { - if (!HasArg0) - return; + case InlineCommandComment::RenderEmphasized: + assert(C->getNumArgs() == 1); Result << "<em>" << Arg0 << "</em>"; return; } - - // We don't recognize this command, so just print its arguments. - for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) - Result << C->getArgText(i) << " "; } void CommentASTToHTMLConverter::visitHTMLStartTagComment( diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 7d3b2a9c5d5..bc8c113fadd 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -25,6 +25,7 @@ clang_Comment_isWhitespace clang_InlineContentComment_hasTrailingNewline clang_TextComment_getText clang_InlineCommandComment_getCommandName +clang_InlineCommandComment_getRenderKind clang_InlineCommandComment_getNumArgs clang_InlineCommandComment_getArgText clang_HTMLTagComment_getTagName |