diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-08-11 00:51:43 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-08-11 00:51:43 +0000 |
commit | a43ec186a4a1351efd881a2c823773b6d437f9cb (patch) | |
tree | f94b7a8b2f6e866e3cedcfb2c4a58d2c16f5a437 /clang/lib/AST/RawCommentList.cpp | |
parent | 7f4c7430f7412a697caabf31815686eba1490afa (diff) | |
download | bcm5719-llvm-a43ec186a4a1351efd881a2c823773b6d437f9cb.tar.gz bcm5719-llvm-a43ec186a4a1351efd881a2c823773b6d437f9cb.zip |
Attaching comments to declarations: find comment attached to any redeclaration
Not only look for the comment near the declaration itself, but also walk the
redeclaration chain: the previous declaration might have had a documentation
comment.
llvm-svn: 161722
Diffstat (limited to 'clang/lib/AST/RawCommentList.cpp')
-rw-r--r-- | clang/lib/AST/RawCommentList.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp index 4f7165f0e4a..c704cabe69f 100644 --- a/clang/lib/AST/RawCommentList.cpp +++ b/clang/lib/AST/RawCommentList.cpp @@ -9,8 +9,11 @@ #include "clang/AST/RawCommentList.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/Comment.h" #include "clang/AST/CommentLexer.h" #include "clang/AST/CommentBriefParser.h" +#include "clang/AST/CommentSema.h" +#include "clang/AST/CommentParser.h" #include "clang/AST/CommentCommandTraits.h" #include "llvm/ADT/STLExtras.h" @@ -62,7 +65,7 @@ bool mergedCommentIsTrailingComment(StringRef Comment) { RawComment::RawComment(const SourceManager &SourceMgr, SourceRange SR, bool Merged) : Range(SR), RawTextValid(false), BriefTextValid(false), - IsAttached(false), IsAlmostTrailingComment(false), + IsAlmostTrailingComment(false), BeginLineValid(false), EndLineValid(false) { // Extract raw comment text, if possible. if (SR.getBegin() == SR.getEnd() || getRawText(SourceMgr).empty()) { @@ -84,6 +87,16 @@ RawComment::RawComment(const SourceManager &SourceMgr, SourceRange SR, } } +const Decl *RawComment::getDecl() const { + if (DeclOrParsedComment.isNull()) + return NULL; + + if (const Decl *D = DeclOrParsedComment.dyn_cast<const Decl *>()) + return D; + + return DeclOrParsedComment.get<comments::FullComment *>()->getDecl(); +} + unsigned RawComment::getBeginLine(const SourceManager &SM) const { if (BeginLineValid) return BeginLine; @@ -156,6 +169,25 @@ const char *RawComment::extractBriefText(const ASTContext &Context) const { return BriefTextPtr; } +comments::FullComment *RawComment::parse(const ASTContext &Context) const { + // Make sure that RawText is valid. + getRawText(Context.getSourceManager()); + + comments::CommandTraits Traits; + comments::Lexer L(Context.getAllocator(), Traits, + getSourceRange().getBegin(), comments::CommentOptions(), + RawText.begin(), RawText.end()); + comments::Sema S(Context.getAllocator(), Context.getSourceManager(), + Context.getDiagnostics(), Traits); + S.setDecl(getDecl()); + comments::Parser P(L, S, Context.getAllocator(), Context.getSourceManager(), + Context.getDiagnostics(), Traits); + + comments::FullComment *FC = P.parseFullComment(); + DeclOrParsedComment = FC; + return FC; +} + namespace { bool containsOnlyWhitespace(StringRef Str) { return Str.find_first_not_of(" \t\f\v\r\n") == StringRef::npos; |