diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-26 20:39:18 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-06-26 20:39:18 +0000 |
commit | 5188c4b9cc063b1be5fbb4688711f91b7cadd62f (patch) | |
tree | 432598630731554a67aef1a0a821c83bdaf122b6 /clang/lib/AST/RawCommentList.cpp | |
parent | add5e9e289b0e0f5e46617219f076c39fecff2a3 (diff) | |
download | bcm5719-llvm-5188c4b9cc063b1be5fbb4688711f91b7cadd62f.tar.gz bcm5719-llvm-5188c4b9cc063b1be5fbb4688711f91b7cadd62f.zip |
Implement a lexer for structured comments.
llvm-svn: 159223
Diffstat (limited to 'clang/lib/AST/RawCommentList.cpp')
-rw-r--r-- | clang/lib/AST/RawCommentList.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp index 438fdcd24c7..ede47664d6b 100644 --- a/clang/lib/AST/RawCommentList.cpp +++ b/clang/lib/AST/RawCommentList.cpp @@ -8,6 +8,9 @@ //===----------------------------------------------------------------------===// #include "clang/AST/RawCommentList.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/CommentLexer.h" +#include "clang/AST/CommentBriefParser.h" #include "llvm/ADT/STLExtras.h" using namespace clang; @@ -126,6 +129,24 @@ StringRef RawComment::getRawTextSlow(const SourceManager &SourceMgr) const { return StringRef(BufferStart + BeginOffset, Length); } +StringRef RawComment::extractBriefText(const ASTContext &Context) const { + // Make sure that RawText is valid. + getRawText(Context.getSourceManager()); + + comments::Lexer L(Range.getBegin(), comments::CommentOptions(), + RawText.begin(), RawText.end()); + comments::BriefParser P(L); + + const std::string Result = P.Parse(); + const unsigned BriefTextLength = Result.size(); + char *BriefTextPtr = new (Context) char[BriefTextLength + 1]; + memcpy(BriefTextPtr, Result.c_str(), BriefTextLength + 1); + BriefText = StringRef(BriefTextPtr, BriefTextLength); + BriefTextValid = true; + + return BriefText; +} + namespace { bool containsOnlyWhitespace(StringRef Str) { return Str.find_first_not_of(" \t\f\v\r\n") == StringRef::npos; |