diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-31 22:37:06 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-07-31 22:37:06 +0000 |
commit | 34df220410b36fd6643154d3d6071bac74403da0 (patch) | |
tree | 1f73381a70095ae60f5ab0c1da8d76659f53547f /clang/tools | |
parent | 708709c01502e55f6fb49ad45f2c9266fc5eac1b (diff) | |
download | bcm5719-llvm-34df220410b36fd6643154d3d6071bac74403da0.tar.gz bcm5719-llvm-34df220410b36fd6643154d3d6071bac74403da0.zip |
Comment parsing: add support for \tparam command on all levels.
The only caveat is renumbering CXCommentKind enum for aesthetic reasons -- this
breaks libclang binary compatibility, but should not be a problem since API is
so new.
This also fixes PR13372 as a side-effect.
llvm-svn: 161087
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 17 | ||||
-rw-r--r-- | clang/tools/libclang/CXComment.cpp | 112 | ||||
-rw-r--r-- | clang/tools/libclang/libclang.exports | 4 |
3 files changed, 133 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 9f270f0151c..4af25488953 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -378,6 +378,23 @@ static void DumpCXCommentInternal(struct CommentASTDumpingContext *Ctx, else printf(" ParamIndex=Invalid"); break; + case CXComment_TParamCommand: + printf("CXComment_TParamCommand"); + PrintCXStringWithPrefixAndDispose( + "ParamName", + clang_TParamCommandComment_getParamName(Comment)); + if (clang_TParamCommandComment_isParamPositionValid(Comment)) { + printf(" ParamPosition={"); + for (i = 0, e = clang_TParamCommandComment_getDepth(Comment); + i != e; ++i) { + printf("%u", clang_TParamCommandComment_getIndex(Comment, i)); + if (i != e - 1) + printf(", "); + } + printf("}"); + } else + printf(" ParamPosition=Invalid"); + break; case CXComment_VerbatimBlockCommand: printf("CXComment_VerbatimBlockCommand"); PrintCXStringWithPrefixAndDispose( diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp index f8e89f28773..9bdab619422 100644 --- a/clang/tools/libclang/CXComment.cpp +++ b/clang/tools/libclang/CXComment.cpp @@ -59,6 +59,9 @@ enum CXCommentKind clang_Comment_getKind(CXComment CXC) { case Comment::ParamCommandCommentKind: return CXComment_ParamCommand; + case Comment::TParamCommandCommentKind: + return CXComment_TParamCommand; + case Comment::VerbatimBlockCommentKind: return CXComment_VerbatimBlockCommand; @@ -291,6 +294,38 @@ enum CXCommentParamPassDirection clang_ParamCommandComment_getDirection( llvm_unreachable("unknown ParamCommandComment::PassDirection"); } +CXString clang_TParamCommandComment_getParamName(CXComment CXC) { + const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC); + if (!TPCC || !TPCC->hasParamName()) + return createCXString((const char *) 0); + + return createCXString(TPCC->getParamName(), /*DupString=*/ false); +} + +unsigned clang_TParamCommandComment_isParamPositionValid(CXComment CXC) { + const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC); + if (!TPCC) + return false; + + return TPCC->isPositionValid(); +} + +unsigned clang_TParamCommandComment_getDepth(CXComment CXC) { + const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC); + if (!TPCC || !TPCC->isPositionValid()) + return 0; + + return TPCC->getDepth(); +} + +unsigned clang_TParamCommandComment_getIndex(CXComment CXC, unsigned Depth) { + const TParamCommandComment *TPCC = getASTNodeAs<TParamCommandComment>(CXC); + if (!TPCC || !TPCC->isPositionValid() || Depth >= TPCC->getDepth()) + return 0; + + return TPCC->getIndex(Depth); +} + CXString clang_VerbatimBlockLineComment_getText(CXComment CXC) { const VerbatimBlockLineComment *VBL = getASTNodeAs<VerbatimBlockLineComment>(CXC); @@ -333,6 +368,34 @@ public: } }; +/// This comparison will sort template parameters in the following order: +/// \li real template parameters (depth = 1) in index order; +/// \li all other names (depth > 1); +/// \li unresolved names. +class TParamCommandCommentComparePosition { +public: + bool operator()(const TParamCommandComment *LHS, + const TParamCommandComment *RHS) const { + // Sort unresolved names last. + if (!LHS->isPositionValid()) + return false; + if (!RHS->isPositionValid()) + return true; + + if (LHS->getDepth() > 1) + return false; + if (RHS->getDepth() > 1) + return true; + + // Sort template parameters in index order. + if (LHS->getDepth() == 1 && RHS->getDepth() == 1) + return LHS->getIndex(0) < RHS->getIndex(0); + + // Leave all other names in source order. + return true; + } +}; + class CommentASTToHTMLConverter : public ConstCommentVisitor<CommentASTToHTMLConverter> { public: @@ -349,6 +412,7 @@ public: void visitParagraphComment(const ParagraphComment *C); void visitBlockCommandComment(const BlockCommandComment *C); void visitParamCommandComment(const ParamCommandComment *C); + void visitTParamCommandComment(const TParamCommandComment *C); void visitVerbatimBlockComment(const VerbatimBlockComment *C); void visitVerbatimBlockLineComment(const VerbatimBlockLineComment *C); void visitVerbatimLineComment(const VerbatimLineComment *C); @@ -486,6 +550,34 @@ void CommentASTToHTMLConverter::visitParamCommandComment( Result << "</dd>"; } +void CommentASTToHTMLConverter::visitTParamCommandComment( + const TParamCommandComment *C) { + if (C->isPositionValid()) { + if (C->getDepth() == 1) + Result << "<dt class=\"taram-name-index-" + << C->getIndex(0) + << "\">"; + else + Result << "<dt class=\"taram-name-index-other\">"; + } else + Result << "<dt class=\"tparam-name-index-invalid\">"; + + Result << C->getParamName() << "</dt>"; + + if (C->isPositionValid()) { + if (C->getDepth() == 1) + Result << "<dd class=\"tparam-descr-index-" + << C->getIndex(0) + << "\">"; + else + Result << "<dd class=\"tparam-descr-index-other\">"; + } else + Result << "<dd class=\"tparam-descr-index-invalid\">"; + + visitNonStandaloneParagraphComment(C->getParagraph()); + Result << "</dd>"; +} + void CommentASTToHTMLConverter::visitVerbatimBlockComment( const VerbatimBlockComment *C) { unsigned NumLines = C->getNumLines(); @@ -518,6 +610,7 @@ void CommentASTToHTMLConverter::visitFullComment(const FullComment *C) { const ParagraphComment *FirstParagraph = NULL; const BlockCommandComment *Returns = NULL; SmallVector<const ParamCommandComment *, 8> Params; + SmallVector<const TParamCommandComment *, 4> TParams; SmallVector<const BlockContentComment *, 8> MiscBlocks; // Extract various blocks into separate variables and vectors above. @@ -568,6 +661,15 @@ void CommentASTToHTMLConverter::visitFullComment(const FullComment *C) { break; } + case Comment::TParamCommandCommentKind: { + const TParamCommandComment *TPCC = cast<TParamCommandComment>(Child); + if (!TPCC->hasParamName()) + break; + + TParams.push_back(TPCC); + break; + } + case Comment::VerbatimBlockCommentKind: case Comment::VerbatimLineCommentKind: MiscBlocks.push_back(cast<BlockCommandComment>(Child)); @@ -590,6 +692,9 @@ void CommentASTToHTMLConverter::visitFullComment(const FullComment *C) { std::stable_sort(Params.begin(), Params.end(), ParamCommandCommentCompareIndex()); + std::stable_sort(TParams.begin(), TParams.end(), + TParamCommandCommentComparePosition()); + bool FirstParagraphIsBrief = false; if (Brief) visit(Brief); @@ -607,6 +712,13 @@ void CommentASTToHTMLConverter::visitFullComment(const FullComment *C) { visit(C); } + if (TParams.size() != 0) { + Result << "<dl>"; + for (unsigned i = 0, e = TParams.size(); i != e; ++i) + visit(TParams[i]); + Result << "</dl>"; + } + if (Params.size() != 0) { Result << "<dl>"; for (unsigned i = 0, e = Params.size(); i != e; ++i) diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index bc8c113fadd..d796b154ad2 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -42,6 +42,10 @@ clang_ParamCommandComment_isParamIndexValid clang_ParamCommandComment_getParamIndex clang_ParamCommandComment_isDirectionExplicit clang_ParamCommandComment_getDirection +clang_TParamCommandComment_getParamName +clang_TParamCommandComment_isParamPositionValid +clang_TParamCommandComment_getDepth +clang_TParamCommandComment_getIndex clang_VerbatimBlockLineComment_getText clang_VerbatimLineComment_getText clang_HTMLTagComment_getAsString |